svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.coreplugin.app / org.gvsig.coreplugin.app.mainplugin / src / main / java / org / gvsig / coreplugin / preferences / general / AppearancePage.java @ 40558
History | View | Annotate | Download (7.7 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
/* CVS MESSAGES:
|
25 |
*
|
26 |
* $Id: AppearancePage.java 38635 2012-08-06 09:34:12Z jldominguez $
|
27 |
* $Log$
|
28 |
* Revision 1.11 2006-09-12 12:09:51 jaume
|
29 |
* *** empty log message ***
|
30 |
*
|
31 |
* Revision 1.10 2006/09/12 11:49:04 jaume
|
32 |
* *** empty log message ***
|
33 |
*
|
34 |
* Revision 1.9 2006/09/12 10:11:25 jaume
|
35 |
* *** empty log message ***
|
36 |
*
|
37 |
* Revision 1.7.4.1 2006/09/08 11:56:24 jaume
|
38 |
* *** empty log message ***
|
39 |
*
|
40 |
* Revision 1.7 2006/08/22 12:23:05 jaume
|
41 |
* improved perfomance when saving changes
|
42 |
*
|
43 |
* Revision 1.6 2006/08/22 07:37:17 jaume
|
44 |
* *** empty log message ***
|
45 |
*
|
46 |
* Revision 1.5 2006/08/04 11:44:55 caballero
|
47 |
* lanzo una excepci?n cuando falla el m?todo storeValues
|
48 |
*
|
49 |
* Revision 1.4 2006/08/04 11:03:43 cesar
|
50 |
* Set the selected appearance after the combo box is filled (it had no effect otherwise)
|
51 |
*
|
52 |
* Revision 1.3 2006/08/02 12:49:07 cesar
|
53 |
* Install Plastic look and feel before getting the LAF-combo. Hide installed but non-supported themes from the list.
|
54 |
*
|
55 |
* Revision 1.2 2006/07/31 10:02:31 jaume
|
56 |
* *** empty log message ***
|
57 |
*
|
58 |
* Revision 1.1 2006/06/29 16:15:06 jaume
|
59 |
* Appearance now configurable
|
60 |
*
|
61 |
*
|
62 |
*/
|
63 |
package org.gvsig.coreplugin.preferences.general; |
64 |
|
65 |
import java.awt.Component; |
66 |
import java.awt.event.ActionEvent; |
67 |
import java.awt.event.ActionListener; |
68 |
import java.util.ArrayList; |
69 |
|
70 |
import javax.swing.ImageIcon; |
71 |
import javax.swing.JComboBox; |
72 |
import javax.swing.JPanel; |
73 |
import javax.swing.LookAndFeel; |
74 |
import javax.swing.SwingUtilities; |
75 |
import javax.swing.UIManager; |
76 |
import javax.swing.UIManager.LookAndFeelInfo; |
77 |
|
78 |
import org.slf4j.Logger; |
79 |
import org.slf4j.LoggerFactory; |
80 |
|
81 |
import org.gvsig.andami.Launcher; |
82 |
import org.gvsig.andami.PluginServices; |
83 |
import org.gvsig.andami.messages.Messages; |
84 |
import org.gvsig.andami.preferences.AbstractPreferencePage; |
85 |
|
86 |
/**
|
87 |
* Appearance page. Where the user can choose Look&Feels and maybe some more stuff.
|
88 |
*
|
89 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
90 |
*
|
91 |
*/
|
92 |
public class AppearancePage extends AbstractPreferencePage{ |
93 |
private JComboBox lookAndFeelCombo; |
94 |
private String id; |
95 |
private ImageIcon icon; |
96 |
private String lookAndFeel; |
97 |
private boolean changed = false; |
98 |
private Logger logger = LoggerFactory.getLogger(this.getClass()); |
99 |
private PluginServices ps = PluginServices.getPluginServices(this); |
100 |
private ActionListener myAction; |
101 |
|
102 |
public AppearancePage() {
|
103 |
super();
|
104 |
id = this.getClass().getName();
|
105 |
icon = PluginServices.getIconTheme().get("edit-setup-appearance");
|
106 |
setParentID(GeneralPage.id); |
107 |
// install the plastic look and feel before getting the laf combobox
|
108 |
UIManager.installLookAndFeel("Plastic XP", "com.jgoodies.looks.plastic.PlasticXPLookAndFeel"); |
109 |
// install the extra LAF's before getting the LAF combobox
|
110 |
String osName = System.getProperty("os.name"); |
111 |
if (osName.toLowerCase().startsWith("mac os x")) { |
112 |
UIManager.installLookAndFeel("Quaqua", "ch.randelshofer.quaqua.QuaquaLookAndFeel"); |
113 |
} |
114 |
addComponent(PluginServices.getText(this, "options.general.select_theme"), getLookAndFeelComboBox()); |
115 |
myAction = new ActionListener() { |
116 |
public void actionPerformed(ActionEvent e) { |
117 |
lookAndFeel = ((LF) lookAndFeelCombo.getSelectedItem()).getClassName(); |
118 |
changed = true;
|
119 |
|
120 |
/* Changing it on the fly can cause rendering issues
|
121 |
try {
|
122 |
UIManager.setLookAndFeel(lookAndFeel);
|
123 |
SwingUtilities
|
124 |
.updateComponentTreeUI((Component) PluginServices
|
125 |
.getMainFrame());
|
126 |
} catch (Exception ex) {
|
127 |
logger.warn(Messages.getString("Launcher.look_and_feel"),
|
128 |
ex);
|
129 |
}
|
130 |
*/
|
131 |
} |
132 |
}; |
133 |
|
134 |
} |
135 |
|
136 |
public String getID() { |
137 |
return id;
|
138 |
} |
139 |
|
140 |
public String getTitle() { |
141 |
return PluginServices.getText(this, "pref.appearance"); |
142 |
} |
143 |
|
144 |
public JPanel getPanel() { |
145 |
return this; |
146 |
} |
147 |
|
148 |
public void initializeValues() { |
149 |
getLookAndFeelComboBox().removeActionListener(myAction); |
150 |
lookAndFeel = Launcher.getAndamiConfig().getLookAndFeel(); |
151 |
if (lookAndFeel == null) { |
152 |
lookAndFeel = Launcher.getDefaultLookAndFeel(); |
153 |
} |
154 |
|
155 |
for (int i=0; i<getLookAndFeelComboBox().getModel().getSize(); i++) { |
156 |
LF element = (LF) getLookAndFeelComboBox().getModel().getElementAt(i); |
157 |
if (element.getClassName().equals(lookAndFeel)) {
|
158 |
getLookAndFeelComboBox().setSelectedIndex(i); |
159 |
break;
|
160 |
} |
161 |
} |
162 |
getLookAndFeelComboBox().addActionListener(myAction); |
163 |
} |
164 |
|
165 |
|
166 |
public void storeValues() { |
167 |
Launcher.getAndamiConfig().setLookAndFeel(lookAndFeel); |
168 |
} |
169 |
|
170 |
public void initializeDefaults() { |
171 |
// getLookAndFeelComboBox().removeActionListener(myAction);
|
172 |
|
173 |
final String defaultLookAndFeel = Launcher.getDefaultLookAndFeel(); |
174 |
for (int i = 0; i < getLookAndFeelComboBox().getModel().getSize(); i++) { |
175 |
LF lf = (LF) getLookAndFeelComboBox().getModel().getElementAt(i); |
176 |
if (defaultLookAndFeel.equals(lf.getClassName())) {
|
177 |
getLookAndFeelComboBox().setSelectedIndex(i); |
178 |
break;
|
179 |
} |
180 |
} |
181 |
// getLookAndFeelComboBox().addActionListener(myAction);
|
182 |
} |
183 |
|
184 |
public ImageIcon getIcon() { |
185 |
return icon;
|
186 |
} |
187 |
|
188 |
private JComboBox getLookAndFeelComboBox() { |
189 |
if (lookAndFeelCombo==null) { |
190 |
LookAndFeelInfo[] lfs = UIManager.getInstalledLookAndFeels(); |
191 |
ArrayList a = new ArrayList(); |
192 |
for (int i = 0; i < lfs.length; i++) { |
193 |
LF lf = new LF(lfs[i]);
|
194 |
|
195 |
// test if the look and feel is supported in this platform before adding it to the list
|
196 |
Class lafClassDef;
|
197 |
try {
|
198 |
lafClassDef = Class.forName(lfs[i].getClassName());
|
199 |
LookAndFeel laf;
|
200 |
laf = (LookAndFeel) lafClassDef.newInstance();
|
201 |
|
202 |
if (laf.isSupportedLookAndFeel()) {
|
203 |
a.add(lf); |
204 |
} |
205 |
|
206 |
} catch (ClassNotFoundException e2) { |
207 |
logger.error(ps.getText("error_loading_look_and_feel_"+lfs[i].getName()), e2);
|
208 |
} catch (InstantiationException e1) { |
209 |
logger.error(ps.getText("error_loading_look_and_feel_"+lfs[i].getName()), e1);
|
210 |
} catch (IllegalAccessException e1) { |
211 |
logger.error(ps.getText("error_loading_look_and_feel_"+lfs[i].getName()), e1);
|
212 |
} |
213 |
} |
214 |
lookAndFeelCombo = new JComboBox(a.toArray(new LF[a.size()])); |
215 |
|
216 |
} |
217 |
return lookAndFeelCombo;
|
218 |
} |
219 |
|
220 |
private class LF { |
221 |
LookAndFeelInfo lfi; |
222 |
|
223 |
public LF(LookAndFeelInfo lfi) {
|
224 |
this.lfi = lfi;
|
225 |
} |
226 |
|
227 |
public String getClassName() { |
228 |
return lfi.getClassName();
|
229 |
} |
230 |
|
231 |
public String toString() { |
232 |
return lfi.getName();
|
233 |
} |
234 |
} |
235 |
|
236 |
public boolean isValueChanged() { |
237 |
return changed;
|
238 |
} |
239 |
|
240 |
public void setChangesApplied() { |
241 |
changed = false;
|
242 |
} |
243 |
} |