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 / appearance / AppearancePage.java @ 43592
History | View | Annotate | Download (11.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 |
package org.gvsig.coreplugin.preferences.general.appearance; |
25 |
|
26 |
import java.util.ArrayList; |
27 |
import java.util.Collections; |
28 |
import java.util.Comparator; |
29 |
import java.util.List; |
30 |
import javax.swing.DefaultComboBoxModel; |
31 |
import javax.swing.ImageIcon; |
32 |
import javax.swing.JPanel; |
33 |
import javax.swing.LookAndFeel; |
34 |
import javax.swing.UIManager; |
35 |
import javax.swing.UIManager.LookAndFeelInfo; |
36 |
import org.apache.commons.lang3.BooleanUtils; |
37 |
import org.apache.commons.lang3.StringUtils; |
38 |
import org.gvsig.andami.IconThemeHelper; |
39 |
import org.gvsig.andami.Launcher; |
40 |
import org.gvsig.andami.PluginServices; |
41 |
import org.gvsig.andami.PluginsLocator; |
42 |
import org.gvsig.andami.PluginsManager; |
43 |
import org.gvsig.andami.preferences.IPreference; |
44 |
import org.gvsig.andami.preferences.StoreException; |
45 |
import org.gvsig.coreplugin.PreferencesExtension; |
46 |
import org.gvsig.coreplugin.preferences.general.GeneralPage; |
47 |
import org.gvsig.tools.ToolsLocator; |
48 |
import org.gvsig.tools.dynobject.DynObject; |
49 |
import org.gvsig.tools.i18n.I18nManager; |
50 |
import org.gvsig.tools.swing.api.ListElement; |
51 |
import org.gvsig.tools.util.ToolsUtilLocator; |
52 |
import org.slf4j.Logger; |
53 |
import org.slf4j.LoggerFactory; |
54 |
|
55 |
/**
|
56 |
* Appearance page. Where the user can choose Look&Feels and maybe some more
|
57 |
* stuff.
|
58 |
*/
|
59 |
public class AppearancePage extends AppearancePageView implements IPreference { |
60 |
//
|
61 |
// The class AppearancePageView can extend from AbstractPreferencePage, not JPanel,
|
62 |
// if rereate it from the GUI builder change te class declaration to:
|
63 |
// public abstract class AppearancePageView extends AbstractPreferencePage
|
64 |
|
65 |
private static final long serialVersionUID = 9004756473020260443L; |
66 |
|
67 |
private static final Logger logger = LoggerFactory.getLogger(AppearancePage.class); |
68 |
|
69 |
public static String id = AppearancePage.class.getName(); |
70 |
private ImageIcon icon; |
71 |
private boolean enableLookAndFeel = true; |
72 |
private final String defaultLookAndFeel; |
73 |
|
74 |
public AppearancePage() {
|
75 |
setParentID(GeneralPage.id); |
76 |
installDefaultLookAndFeel(); |
77 |
this.defaultLookAndFeel = Launcher.getDefaultLookAndFeel();
|
78 |
String x = PluginServices.getArgumentByName("enablelaf"); |
79 |
if( x == null ) { |
80 |
this.enableLookAndFeel = true; |
81 |
} else {
|
82 |
this.enableLookAndFeel = BooleanUtils.toBoolean(x);
|
83 |
} |
84 |
this.initComponents();
|
85 |
} |
86 |
|
87 |
private void installDefaultLookAndFeel() { |
88 |
String[][] lafs = { |
89 |
{ "Plastic XP", "com.jgoodies.looks.plastic.PlasticXPLookAndFeel" }, |
90 |
{ "Quaqua", "ch.randelshofer.quaqua.QuaquaLookAndFeel" }, |
91 |
{ "Web", "com.alee.laf.WebLookAndFeel" }, |
92 |
{ "Sea Glass", "com.seaglasslookandfeel.SeaGlassLookAndFeel" }, |
93 |
// Substance da errores en la carga de gvSIG y el L&F no funciona
|
94 |
// { "Substance", "org.pushingpixels.substance.api.SubstanceLookAndFeel" },
|
95 |
// { "SubstanceAutumn", "org.pushingpixels.substance.api.skin.SubstanceAutumnLookAndFeel" },
|
96 |
// { "SubstanceOfficeBlue2007", "org.pushingpixels.substance.api.skin.SubstanceOfficeBlue2007LookAndFeel" },
|
97 |
// { "SubstanceBusiness", "org.pushingpixels.substance.api.skin.SubstanceBusinessLookAndFeel" },
|
98 |
// { "SubstanceMistAqua", "org.pushingpixels.substance.api.skin.SubstanceMistAquaLookAndFeel" },
|
99 |
{ "Acryl", "com.jtattoo.plaf.acryl.AcrylLookAndFeel" }, |
100 |
{ "Fast", "com.jtattoo.plaf.fast.FastLookAndFeel" }, |
101 |
{ "Bernstein", "com.jtattoo.plaf.bernstein.BernsteinLookAndFeel" }, |
102 |
{ "Aluminium", "com.jtattoo.plaf.aluminium.AluminiumLookAndFeel" }, |
103 |
{ "Aero", "com.jtattoo.plaf.aero.AeroLookAndFeel" }, |
104 |
{ "HiFi", "com.jtattoo.plaf.hifi.HiFiLookAndFeel" }, |
105 |
{ "McWin", "com.jtattoo.plaf.mcwin.McWinLookAndFeel" }, |
106 |
{ "Mint", "com.jtattoo.plaf.mint.MintLookAndFeel" }, |
107 |
{ "Noire", "com.jtattoo.plaf.noire.NoireLookAndFeel" }, |
108 |
{ "Smart", "com.jtattoo.plaf.smart.SmartLookAndFeel" }, |
109 |
{ "Luna", "com.jtattoo.plaf.luna.LunaLookAndFeel" }, |
110 |
{ "Texture", "com.jtattoo.plaf.texture.TextureLookAndFeel" } |
111 |
}; |
112 |
|
113 |
for( String[] laf : lafs ) { |
114 |
try {
|
115 |
UIManager.installLookAndFeel(laf[0], laf[1]); |
116 |
} catch (Throwable th) { |
117 |
logger.info("Problems installing look and feel '"+laf[1]+"'", th); |
118 |
} |
119 |
} |
120 |
} |
121 |
|
122 |
private LookAndFeelInfo[] getSupportedsLookAndFeels() { |
123 |
if( !this.enableLookAndFeel ) { |
124 |
return null; |
125 |
} |
126 |
List<LookAndFeelInfo> supporteds = new ArrayList(); |
127 |
try {
|
128 |
LookAndFeelInfo[] installedLookAndFeels = UIManager.getInstalledLookAndFeels(); |
129 |
for( LookAndFeelInfo lookAndfeelInfo : installedLookAndFeels ) {
|
130 |
try {
|
131 |
Class<?> lookAndFeelClass = Class.forName(lookAndfeelInfo.getClassName()); |
132 |
LookAndFeel lookAndFeel = (LookAndFeel) lookAndFeelClass.newInstance(); |
133 |
if( lookAndFeel.isSupportedLookAndFeel() ) {
|
134 |
supporteds.add(lookAndfeelInfo); |
135 |
} |
136 |
} catch (Throwable th) { |
137 |
|
138 |
} |
139 |
} |
140 |
} catch (Throwable th) { |
141 |
return null; |
142 |
} |
143 |
if( supporteds.isEmpty() ) {
|
144 |
return null; |
145 |
} |
146 |
Collections.sort(supporteds, new Comparator<LookAndFeelInfo>() { |
147 |
@Override
|
148 |
public int compare(LookAndFeelInfo o1, LookAndFeelInfo o2) { |
149 |
return StringUtils.compare(o1.getName(),o2.getName());
|
150 |
} |
151 |
}); |
152 |
return supporteds.toArray(new LookAndFeelInfo[supporteds.size()]); |
153 |
} |
154 |
|
155 |
private void initComponents() { |
156 |
icon = IconThemeHelper.getImageIcon("edit-setup-appearance");
|
157 |
LookAndFeelInfo[] lafs = this.getSupportedsLookAndFeels(); |
158 |
if( lafs == null ) { |
159 |
this.cboLookAndFeel.setEnabled(false); |
160 |
} else {
|
161 |
DefaultComboBoxModel model = new DefaultComboBoxModel(); |
162 |
for( LookAndFeelInfo laf : lafs ) {
|
163 |
model.addElement(new ListElement<>(laf.getName(), laf));
|
164 |
} |
165 |
this.cboLookAndFeel.setModel(model);
|
166 |
this.cboLookAndFeel.setEnabled(true); |
167 |
this.cboLookAndFeel.setSelectedItem(Launcher.getAndamiConfig().getLookAndFeel());
|
168 |
} |
169 |
this.translateAll();
|
170 |
} |
171 |
|
172 |
private void translateAll() { |
173 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
174 |
this.lblNeedRestart.setText("("+i18n.getTranslation("Los_cambios_efectuados_sobre_estos_valores_se_aplicaran_al_reiniciar_la_aplicacion")+")"); |
175 |
this.lbllookAndFeel.setText(i18n.getTranslation("options.general.select_theme")); |
176 |
this.chkUseNativeFileChooser.setText(i18n.getTranslation("_use_native_file_dialog_chooser")); |
177 |
} |
178 |
|
179 |
@Override
|
180 |
public boolean isResizeable() { |
181 |
return true; |
182 |
} |
183 |
|
184 |
@Override
|
185 |
public void initializeValues() { |
186 |
this.initializeDefaults();
|
187 |
this.chkUseNativeFileChooser.setSelected(ToolsUtilLocator.getFileDialogChooserManager().useNativeFileChooser());
|
188 |
} |
189 |
|
190 |
@Override
|
191 |
public void initializeDefaults() { |
192 |
PluginsManager pluginsManager = PluginsLocator.getManager(); |
193 |
PluginServices plugin = pluginsManager.getPlugin(PreferencesExtension.class); |
194 |
|
195 |
DynObject pluginProperties = plugin.getPluginProperties(); |
196 |
|
197 |
this.chkUseNativeFileChooser.setSelected((Boolean) pluginProperties.getDynValue("useNativeFileChooser")); |
198 |
|
199 |
if( this.cboLookAndFeel.getModel().getSize()>0 ) { |
200 |
this.cboLookAndFeel.setSelectedIndex(0); |
201 |
String currentLaF = getCurrentLookAndFeel();
|
202 |
if( !StringUtils.isEmpty(currentLaF) ) {
|
203 |
DefaultComboBoxModel<ListElement<LookAndFeelInfo>> model = (DefaultComboBoxModel<ListElement<LookAndFeelInfo>>) this.cboLookAndFeel.getModel(); |
204 |
for( int i=0; i<model.getSize() ; i++ ) { |
205 |
ListElement<LookAndFeelInfo> element = model.getElementAt(i); |
206 |
if( currentLaF.equals(element.getValue().getClassName()) ) {
|
207 |
this.cboLookAndFeel.setSelectedIndex(i);
|
208 |
break;
|
209 |
} |
210 |
} |
211 |
} |
212 |
this.cboLookAndFeel.setEnabled(true); |
213 |
} else {
|
214 |
this.cboLookAndFeel.setEnabled(false); |
215 |
} |
216 |
} |
217 |
|
218 |
private String getCurrentLookAndFeel() { |
219 |
String s = Launcher.getAndamiConfig().getLookAndFeel();
|
220 |
if( StringUtils.isBlank(s) ) {
|
221 |
s = defaultLookAndFeel; |
222 |
} |
223 |
return s;
|
224 |
} |
225 |
|
226 |
@Override
|
227 |
public String getID() { |
228 |
return id;
|
229 |
} |
230 |
|
231 |
@Override
|
232 |
public String getTitle() { |
233 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
234 |
return i18nManager.getTranslation("pref.appearance"); |
235 |
} |
236 |
|
237 |
@Override
|
238 |
public JPanel getPanel() { |
239 |
return this; |
240 |
} |
241 |
|
242 |
@Override
|
243 |
public void storeValues() throws StoreException { |
244 |
PluginsManager pluginsManager = PluginsLocator.getManager(); |
245 |
PluginServices plugin = pluginsManager.getPlugin(PreferencesExtension.class); |
246 |
|
247 |
DynObject pluginProperties = plugin.getPluginProperties(); |
248 |
|
249 |
pluginProperties.setDynValue("useNativeFileChooser", this.chkUseNativeFileChooser.isSelected()); |
250 |
ToolsUtilLocator.getFileDialogChooserManager().setUseNativeFileChooser(this.chkUseNativeFileChooser.isSelected());
|
251 |
|
252 |
if( this.cboLookAndFeel.isEnabled() ) { |
253 |
ListElement<LookAndFeelInfo> element = (ListElement<LookAndFeelInfo>) this.cboLookAndFeel.getSelectedItem();
|
254 |
if( element!=null ) { |
255 |
String lookAndFeel = element.getValue().getClassName();
|
256 |
Launcher.getAndamiConfig().setLookAndFeel(lookAndFeel); |
257 |
} |
258 |
} |
259 |
} |
260 |
|
261 |
@Override
|
262 |
public ImageIcon getIcon() { |
263 |
return icon;
|
264 |
} |
265 |
|
266 |
@Override
|
267 |
public boolean isValueChanged() { |
268 |
PluginsManager pluginsManager = PluginsLocator.getManager(); |
269 |
PluginServices plugin = pluginsManager.getPlugin(PreferencesExtension.class); |
270 |
|
271 |
DynObject pluginProperties = plugin.getPluginProperties(); |
272 |
|
273 |
boolean changed = false; |
274 |
|
275 |
if( !changed ) {
|
276 |
changed = this.chkUseNativeFileChooser.isSelected() != ToolsUtilLocator.getFileDialogChooserManager().useNativeFileChooser();
|
277 |
} |
278 |
if( !changed ) {
|
279 |
if( this.cboLookAndFeel.isEnabled() ) { |
280 |
ListElement<LookAndFeelInfo> element = (ListElement<LookAndFeelInfo>) this.cboLookAndFeel.getSelectedItem();
|
281 |
if( element!=null ) { |
282 |
changed = !element.getValue().getClassName().equalsIgnoreCase(getCurrentLookAndFeel()); |
283 |
} |
284 |
} |
285 |
} |
286 |
return changed;
|
287 |
} |
288 |
|
289 |
@Override
|
290 |
public void setChangesApplied() { |
291 |
// Do nothing
|
292 |
} |
293 |
|
294 |
} |