Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libCorePlugin / src / com / iver / core / preferences / general / AppearancePage.java @ 6627

History | View | Annotate | Download (6.05 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 *
19
 * For more information, contact:
20
 *
21
 *  Generalitat Valenciana
22
 *   Conselleria d'Infraestructures i Transport
23
 *   Av. Blasco Ib??ez, 50
24
 *   46010 VALENCIA
25
 *   SPAIN
26
 *
27
 *      +34 963862235
28
 *   gvsig@gva.es
29
 *      www.gvsig.gva.es
30
 *
31
 *    or
32
 *
33
 *   IVER T.I. S.A
34
 *   Salamanca 50
35
 *   46005 Valencia
36
 *   Spain
37
 *
38
 *   +34 963163400
39
 *   dac@iver.es
40
 */
41

    
42
/* CVS MESSAGES:
43
*
44
* $Id: AppearancePage.java 6627 2006-08-02 12:49:07Z cesar $
45
* $Log$
46
* Revision 1.3  2006-08-02 12:49:07  cesar
47
* Install Plastic look and feel before getting the LAF-combo. Hide installed but non-supported themes from the list.
48
*
49
* Revision 1.2  2006/07/31 10:02:31  jaume
50
* *** empty log message ***
51
*
52
* Revision 1.1  2006/06/29 16:15:06  jaume
53
* Appearance now configurable
54
*
55
*
56
*/
57
package com.iver.core.preferences.general;
58

    
59
import java.awt.event.ActionEvent;
60
import java.awt.event.ActionListener;
61
import java.util.ArrayList;
62

    
63
import javax.swing.ImageIcon;
64
import javax.swing.JComboBox;
65
import javax.swing.JPanel;
66
import javax.swing.LookAndFeel;
67
import javax.swing.UIManager;
68
import javax.swing.UIManager.LookAndFeelInfo;
69

    
70
import org.apache.log4j.Logger;
71

    
72
import com.iver.andami.Launcher;
73
import com.iver.andami.PluginServices;
74
import com.iver.andami.preferences.AbstractPreferencePage;
75

    
76
public class AppearancePage extends AbstractPreferencePage{
77
    private JComboBox lookAndFeelCombo;
78
    private String id;
79
    private ImageIcon icon;
80
    private String lookAndFeel;
81
        private int lookAndFeelIndex;
82
        private Logger logger = PluginServices.getLogger();
83
        private PluginServices ps = PluginServices.getPluginServices(this);
84
        
85
    public AppearancePage() {
86
        super();
87
        id = this.getClass().getName();
88
        icon = new ImageIcon(this.getClass().getClassLoader().getResource("images/gnome-settings-theme.png"));
89
        setParentID(GeneralPage.id);
90
        // install the plastic look and feel before getting the laf combobox
91
            UIManager.installLookAndFeel("Plastic XP", "com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
92
        addComponent(PluginServices.getText(this, "options.general.select_theme"), getLookAndFeelComboBox());
93
    }
94

    
95
    public String getID() {
96
        return id;
97
    }
98

    
99
    public String getTitle() {
100
        return PluginServices.getText(this, "pref.appearance");
101
    }
102

    
103
    public JPanel getPanel() {
104
        return this;
105
    }
106

    
107
    public void initializeValues() {
108
            lookAndFeel = Launcher.getAndamiConfig().getLookAndFeel();
109
            if (lookAndFeel == null) {
110
                    lookAndFeel = Launcher.getDefaultLookAndFeel();
111
            }
112

    
113
    }
114

    
115

    
116

    
117
        public boolean storeValues() {
118
            Launcher.getAndamiConfig().setLookAndFeel(lookAndFeel);
119
        return true;
120
    }
121

    
122
    public void initializeDefaults() {
123
            final String defaultLookAndFeel = Launcher.getDefaultLookAndFeel();
124
        for (int i = 0; i < getLookAndFeelComboBox().getModel().getSize(); i++) {
125
                LF lf = (LF) getLookAndFeelComboBox().getModel().getElementAt(i);
126
                if (defaultLookAndFeel.equals(lf.getClassName())) {
127
                        getLookAndFeelComboBox().setSelectedIndex(i);
128
                        break;
129
                }
130
        }
131
    }
132

    
133
    public void cancelAction() {
134
            getLookAndFeelComboBox().setSelectedIndex(lookAndFeelIndex);
135
    }
136

    
137
    public ImageIcon getIcon() {
138
        return icon;
139
    }
140

    
141
    private JComboBox getLookAndFeelComboBox() {
142
        if (lookAndFeelCombo==null) {
143
            LookAndFeelInfo[] lfs = UIManager.getInstalledLookAndFeels();
144
            LF selectedLookAndFeel = null;
145
            ArrayList a = new ArrayList();
146
            for (int i = 0; i < lfs.length; i++) {
147
                LF lf = new LF(lfs[i]);
148
                if (lf.getClassName().equals(lookAndFeel))
149
                        selectedLookAndFeel = lf;
150
                
151
                // test if the look and feel is supported in this platform before adding it to the list
152
                Class lafClassDef;
153
                                try {
154
                                        lafClassDef = Class.forName(lfs[i].getClassName());
155
                                        LookAndFeel laf;
156
                                        laf = (LookAndFeel) lafClassDef.newInstance();
157
                                        
158
                            if (laf.isSupportedLookAndFeel())
159
                                    a.add(lf);
160

    
161
                                } catch (ClassNotFoundException e2) {
162
                                        logger.error(ps.getText("error_loading_look_and_feel_"+lfs[i].getName()), e2);
163
                                } catch (InstantiationException e1) {
164
                                        logger.error(ps.getText("error_loading_look_and_feel_"+lfs[i].getName()), e1);
165
                                } catch (IllegalAccessException e1) {
166
                                        logger.error(ps.getText("error_loading_look_and_feel_"+lfs[i].getName()), e1);
167
                                }
168
            }
169
            lookAndFeelCombo = new JComboBox((LF[]) a.toArray(new LF[a.size()]));
170

    
171
            if (selectedLookAndFeel!=null) {
172
                lookAndFeelCombo.setSelectedItem(selectedLookAndFeel);
173
                lookAndFeelIndex = lookAndFeelCombo.getSelectedIndex();
174
            }
175

    
176
            lookAndFeelCombo.addActionListener(new ActionListener() {
177
                public void actionPerformed(ActionEvent e) {
178
                    lookAndFeel = ((LF) lookAndFeelCombo.getSelectedItem()).getClassName();
179
                }
180
            });
181
        }
182
        return lookAndFeelCombo;
183
    }
184

    
185
    private class LF {
186
        LookAndFeelInfo lfi;
187

    
188
        public LF(LookAndFeelInfo lfi) {
189
            this.lfi = lfi;
190
        }
191

    
192
        public String getClassName() {
193
            return lfi.getClassName();
194
        }
195

    
196
        public String toString() {
197
            return lfi.getName();
198
        }
199
    }
200
}