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 @ 44864
History | View | Annotate | Download (11.1 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 |
!StringUtils.equalsIgnoreCase(lookAndFeel.getID(),"motif") ) {
|
135 |
supporteds.add(lookAndfeelInfo); |
136 |
} |
137 |
} catch (Throwable th) { |
138 |
|
139 |
} |
140 |
} |
141 |
} catch (Throwable th) { |
142 |
return null; |
143 |
} |
144 |
if( supporteds.isEmpty() ) {
|
145 |
return null; |
146 |
} |
147 |
Collections.sort(supporteds, new Comparator<LookAndFeelInfo>() { |
148 |
@Override
|
149 |
public int compare(LookAndFeelInfo o1, LookAndFeelInfo o2) { |
150 |
return StringUtils.compare(o1.getName(),o2.getName());
|
151 |
} |
152 |
}); |
153 |
return supporteds.toArray(new LookAndFeelInfo[supporteds.size()]); |
154 |
} |
155 |
|
156 |
private void initComponents() { |
157 |
icon = IconThemeHelper.getImageIcon("edit-setup-appearance");
|
158 |
LookAndFeelInfo[] lafs = this.getSupportedsLookAndFeels(); |
159 |
if( lafs == null ) { |
160 |
this.cboLookAndFeel.setEnabled(false); |
161 |
} else {
|
162 |
DefaultComboBoxModel model = new DefaultComboBoxModel(); |
163 |
for( LookAndFeelInfo laf : lafs ) {
|
164 |
model.addElement(new ListElement<>(laf.getName(), laf.getClassName()));
|
165 |
} |
166 |
this.cboLookAndFeel.setModel(model);
|
167 |
this.cboLookAndFeel.setEnabled(true); |
168 |
ListElement.setSelected(cboLookAndFeel, Launcher.getAndamiConfig().getLookAndFeel()); |
169 |
|
170 |
} |
171 |
this.translateAll();
|
172 |
} |
173 |
|
174 |
private void translateAll() { |
175 |
I18nManager i18n = ToolsLocator.getI18nManager(); |
176 |
this.lblNeedRestart.setText("("+i18n.getTranslation("Los_cambios_efectuados_sobre_estos_valores_se_aplicaran_al_reiniciar_la_aplicacion")+")"); |
177 |
this.lbllookAndFeel.setText(i18n.getTranslation("options.general.select_theme")); |
178 |
this.chkUseNativeFileChooser.setText(i18n.getTranslation("_use_native_file_dialog_chooser")); |
179 |
} |
180 |
|
181 |
@Override
|
182 |
public boolean isResizeable() { |
183 |
return true; |
184 |
} |
185 |
|
186 |
@Override
|
187 |
public void initializeValues() { |
188 |
this.initializeDefaults();
|
189 |
this.chkUseNativeFileChooser.setSelected(ToolsUtilLocator.getFileDialogChooserManager().useNativeFileChooser());
|
190 |
} |
191 |
|
192 |
@Override
|
193 |
public void initializeDefaults() { |
194 |
PluginsManager pluginsManager = PluginsLocator.getManager(); |
195 |
PluginServices plugin = pluginsManager.getPlugin(PreferencesExtension.class); |
196 |
|
197 |
DynObject pluginProperties = plugin.getPluginProperties(); |
198 |
|
199 |
this.chkUseNativeFileChooser.setSelected((Boolean) pluginProperties.getDynValue("useNativeFileChooser")); |
200 |
|
201 |
if( this.cboLookAndFeel.getModel().getSize()>0 ) { |
202 |
this.cboLookAndFeel.setSelectedIndex(0); |
203 |
String currentLaF = getCurrentLookAndFeel();
|
204 |
if( !StringUtils.isEmpty(currentLaF) ) {
|
205 |
ListElement.setSelected(cboLookAndFeel, currentLaF); |
206 |
} else {
|
207 |
this.cboLookAndFeel.setSelectedIndex(-1); |
208 |
} |
209 |
this.cboLookAndFeel.setEnabled(true); |
210 |
} else {
|
211 |
this.cboLookAndFeel.setEnabled(false); |
212 |
} |
213 |
} |
214 |
|
215 |
private String getCurrentLookAndFeel() { |
216 |
String s = Launcher.getAndamiConfig().getLookAndFeel();
|
217 |
if( StringUtils.isBlank(s) ) {
|
218 |
s = defaultLookAndFeel; |
219 |
} |
220 |
return s;
|
221 |
} |
222 |
|
223 |
@Override
|
224 |
public String getID() { |
225 |
return id;
|
226 |
} |
227 |
|
228 |
@Override
|
229 |
public String getTitle() { |
230 |
I18nManager i18nManager = ToolsLocator.getI18nManager(); |
231 |
return i18nManager.getTranslation("pref.appearance"); |
232 |
} |
233 |
|
234 |
@Override
|
235 |
public JPanel getPanel() { |
236 |
return this; |
237 |
} |
238 |
|
239 |
@Override
|
240 |
public void storeValues() throws StoreException { |
241 |
PluginsManager pluginsManager = PluginsLocator.getManager(); |
242 |
PluginServices plugin = pluginsManager.getPlugin(PreferencesExtension.class); |
243 |
|
244 |
DynObject pluginProperties = plugin.getPluginProperties(); |
245 |
|
246 |
pluginProperties.setDynValue("useNativeFileChooser", this.chkUseNativeFileChooser.isSelected()); |
247 |
ToolsUtilLocator.getFileDialogChooserManager().setUseNativeFileChooser(this.chkUseNativeFileChooser.isSelected());
|
248 |
|
249 |
if( this.cboLookAndFeel.isEnabled() ) { |
250 |
String lookAndFeel = (String) ListElement.getSelected(cboLookAndFeel); |
251 |
if( lookAndFeel!=null ) { |
252 |
Launcher.getAndamiConfig().setLookAndFeel(lookAndFeel); |
253 |
} |
254 |
} |
255 |
} |
256 |
|
257 |
@Override
|
258 |
public ImageIcon getIcon() { |
259 |
return icon;
|
260 |
} |
261 |
|
262 |
@Override
|
263 |
public boolean isValueChanged() { |
264 |
boolean changed = false; |
265 |
|
266 |
if( !changed ) {
|
267 |
changed = this.chkUseNativeFileChooser.isSelected() != ToolsUtilLocator.getFileDialogChooserManager().useNativeFileChooser();
|
268 |
} |
269 |
if( !changed ) {
|
270 |
if( this.cboLookAndFeel.isEnabled() ) { |
271 |
String lookAndFeel = (String) ListElement.getSelected(cboLookAndFeel); |
272 |
if( lookAndFeel!=null ) { |
273 |
changed = !lookAndFeel.equalsIgnoreCase(getCurrentLookAndFeel()); |
274 |
} |
275 |
} |
276 |
} |
277 |
return changed;
|
278 |
} |
279 |
|
280 |
@Override
|
281 |
public void setChangesApplied() { |
282 |
// Do nothing
|
283 |
} |
284 |
|
285 |
} |