Statistics
| Revision:

root / tags / v2_0_0_Build_2050 / libraries / libCorePlugin / src / org / gvsig / coreplugin / preferences / general / AppearancePage.java @ 38668

History | View | Annotate | Download (7.9 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 38668 2012-08-09 12:24:53Z jldominguez $
45
* $Log$
46
* Revision 1.11  2006-09-12 12:09:51  jaume
47
* *** empty log message ***
48
*
49
* Revision 1.10  2006/09/12 11:49:04  jaume
50
* *** empty log message ***
51
*
52
* Revision 1.9  2006/09/12 10:11:25  jaume
53
* *** empty log message ***
54
*
55
* Revision 1.7.4.1  2006/09/08 11:56:24  jaume
56
* *** empty log message ***
57
*
58
* Revision 1.7  2006/08/22 12:23:05  jaume
59
* improved perfomance when saving changes
60
*
61
* Revision 1.6  2006/08/22 07:37:17  jaume
62
* *** empty log message ***
63
*
64
* Revision 1.5  2006/08/04 11:44:55  caballero
65
* lanzo una excepci?n cuando falla el m?todo storeValues
66
*
67
* Revision 1.4  2006/08/04 11:03:43  cesar
68
* Set the selected appearance after the combo box is filled (it had no effect otherwise)
69
*
70
* Revision 1.3  2006/08/02 12:49:07  cesar
71
* Install Plastic look and feel before getting the LAF-combo. Hide installed but non-supported themes from the list.
72
*
73
* Revision 1.2  2006/07/31 10:02:31  jaume
74
* *** empty log message ***
75
*
76
* Revision 1.1  2006/06/29 16:15:06  jaume
77
* Appearance now configurable
78
*
79
*
80
*/
81
package org.gvsig.coreplugin.preferences.general;
82

    
83
import java.awt.Component;
84
import java.awt.event.ActionEvent;
85
import java.awt.event.ActionListener;
86
import java.util.ArrayList;
87

    
88
import javax.swing.ImageIcon;
89
import javax.swing.JComboBox;
90
import javax.swing.JPanel;
91
import javax.swing.LookAndFeel;
92
import javax.swing.SwingUtilities;
93
import javax.swing.UIManager;
94
import javax.swing.UIManager.LookAndFeelInfo;
95

    
96
import org.slf4j.Logger;
97
import org.slf4j.LoggerFactory;
98

    
99
import org.gvsig.andami.Launcher;
100
import org.gvsig.andami.PluginServices;
101
import org.gvsig.andami.messages.Messages;
102
import org.gvsig.andami.preferences.AbstractPreferencePage;
103

    
104
/**
105
 * Appearance page. Where the user can choose Look&Feels and maybe some more stuff.
106
 *
107
 * @author jaume dominguez faus - jaume.dominguez@iver.es
108
 *
109
 */
110
public class AppearancePage extends AbstractPreferencePage{
111
    private JComboBox lookAndFeelCombo;
112
    private String id;
113
    private ImageIcon icon;
114
    private String lookAndFeel;
115
    private boolean changed = false;
116
        private Logger logger = LoggerFactory.getLogger(this.getClass());
117
        private PluginServices ps = PluginServices.getPluginServices(this);
118
        private ActionListener myAction;
119

    
120
        public AppearancePage() {
121
        super();
122
        id = this.getClass().getName();
123
        icon = PluginServices.getIconTheme().get("edit-setup-appearance");
124
        setParentID(GeneralPage.id);
125
        // install the plastic look and feel before getting the laf combobox
126
            UIManager.installLookAndFeel("Plastic XP", "com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
127
            // install the extra LAF's before getting the LAF combobox
128
            String osName = System.getProperty("os.name");
129
                if (osName.toLowerCase().startsWith("mac os x")) {
130
                        UIManager.installLookAndFeel("Quaqua", "ch.randelshofer.quaqua.QuaquaLookAndFeel");
131
                }
132
            addComponent(PluginServices.getText(this, "options.general.select_theme"), getLookAndFeelComboBox());
133
        myAction = new ActionListener() {
134
            public void actionPerformed(ActionEvent e) {
135
                lookAndFeel = ((LF) lookAndFeelCombo.getSelectedItem()).getClassName();
136
                changed = true;
137

    
138
                /* Changing it on the fly can cause rendering issues
139
                try {
140
                    UIManager.setLookAndFeel(lookAndFeel);
141
                    SwingUtilities
142
                        .updateComponentTreeUI((Component) PluginServices
143
                            .getMainFrame());
144
                } catch (Exception ex) {
145
                    logger.warn(Messages.getString("Launcher.look_and_feel"),
146
                        ex);
147
                }
148
                */
149
            }
150
        };
151

    
152
    }
153

    
154
    public String getID() {
155
        return id;
156
    }
157

    
158
    public String getTitle() {
159
        return PluginServices.getText(this, "pref.appearance");
160
    }
161

    
162
    public JPanel getPanel() {
163
        return this;
164
    }
165

    
166
    public void initializeValues() {
167
            getLookAndFeelComboBox().removeActionListener(myAction);
168
            lookAndFeel = Launcher.getAndamiConfig().getLookAndFeel();
169
            if (lookAndFeel == null) {
170
                    lookAndFeel = Launcher.getDefaultLookAndFeel();
171
            }
172

    
173
            for (int i=0; i<getLookAndFeelComboBox().getModel().getSize(); i++) {
174
                    LF element = (LF) getLookAndFeelComboBox().getModel().getElementAt(i);
175
                    if (element.getClassName().equals(lookAndFeel)) {
176
                            getLookAndFeelComboBox().setSelectedIndex(i);
177
                            break;
178
                    }
179
            }
180
            getLookAndFeelComboBox().addActionListener(myAction);
181
    }
182

    
183

    
184
        public void storeValues() {
185
                Launcher.getAndamiConfig().setLookAndFeel(lookAndFeel);
186
    }
187

    
188
    public void initializeDefaults() {
189
//            getLookAndFeelComboBox().removeActionListener(myAction);
190

    
191
            final String defaultLookAndFeel = Launcher.getDefaultLookAndFeel();
192
        for (int i = 0; i < getLookAndFeelComboBox().getModel().getSize(); i++) {
193
                LF lf = (LF) getLookAndFeelComboBox().getModel().getElementAt(i);
194
                if (defaultLookAndFeel.equals(lf.getClassName())) {
195
                        getLookAndFeelComboBox().setSelectedIndex(i);
196
                        break;
197
                }
198
        }
199
//        getLookAndFeelComboBox().addActionListener(myAction);
200
    }
201

    
202
    public ImageIcon getIcon() {
203
        return icon;
204
    }
205

    
206
    private JComboBox getLookAndFeelComboBox() {
207
        if (lookAndFeelCombo==null) {
208
            LookAndFeelInfo[] lfs = UIManager.getInstalledLookAndFeels();
209
            ArrayList a = new ArrayList();
210
            for (int i = 0; i < lfs.length; i++) {
211
                LF lf = new LF(lfs[i]);
212

    
213
                // test if the look and feel is supported in this platform before adding it to the list
214
                Class lafClassDef;
215
                                try {
216
                                        lafClassDef = Class.forName(lfs[i].getClassName());
217
                                        LookAndFeel laf;
218
                                        laf = (LookAndFeel) lafClassDef.newInstance();
219

    
220
                            if (laf.isSupportedLookAndFeel()) {
221
                                                a.add(lf);
222
                                        }
223

    
224
                                } catch (ClassNotFoundException e2) {
225
                                        logger.error(ps.getText("error_loading_look_and_feel_"+lfs[i].getName()), e2);
226
                                } catch (InstantiationException e1) {
227
                                        logger.error(ps.getText("error_loading_look_and_feel_"+lfs[i].getName()), e1);
228
                                } catch (IllegalAccessException e1) {
229
                                        logger.error(ps.getText("error_loading_look_and_feel_"+lfs[i].getName()), e1);
230
                                }
231
            }
232
            lookAndFeelCombo = new JComboBox(a.toArray(new LF[a.size()]));
233

    
234
        }
235
        return lookAndFeelCombo;
236
    }
237

    
238
    private class LF {
239
        LookAndFeelInfo lfi;
240

    
241
        public LF(LookAndFeelInfo lfi) {
242
            this.lfi = lfi;
243
        }
244

    
245
        public String getClassName() {
246
            return lfi.getClassName();
247
        }
248

    
249
        public String toString() {
250
            return lfi.getName();
251
        }
252
    }
253

    
254
        public boolean isValueChanged() {
255
                return changed;
256
        }
257

    
258
        public void setChangesApplied() {
259
                changed = false;
260
        }
261
}