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 @ 42968
History | View | Annotate | Download (7.33 KB)
1 | 40558 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40558 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
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 | 40558 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * 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 | 40558 | jjdelcerro | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | * MA 02110-1301, USA.
|
||
20 | 40435 | jjdelcerro | *
|
21 | 40558 | jjdelcerro | * For any additional information, do not hesitate to contact us
|
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40435 | jjdelcerro | */
|
24 | 41281 | jjdelcerro | |
25 | 40435 | jjdelcerro | package org.gvsig.coreplugin.preferences.general; |
26 | |||
27 | import java.awt.event.ActionEvent; |
||
28 | import java.awt.event.ActionListener; |
||
29 | import java.util.ArrayList; |
||
30 | |||
31 | import javax.swing.ImageIcon; |
||
32 | import javax.swing.JComboBox; |
||
33 | import javax.swing.JPanel; |
||
34 | import javax.swing.LookAndFeel; |
||
35 | import javax.swing.UIManager; |
||
36 | import javax.swing.UIManager.LookAndFeelInfo; |
||
37 | 42968 | jjdelcerro | import org.apache.commons.lang3.BooleanUtils; |
38 | 40435 | jjdelcerro | |
39 | import org.slf4j.Logger; |
||
40 | import org.slf4j.LoggerFactory; |
||
41 | |||
42 | import org.gvsig.andami.Launcher; |
||
43 | import org.gvsig.andami.PluginServices; |
||
44 | 42968 | jjdelcerro | import org.gvsig.andami.PluginsLocator; |
45 | 40435 | jjdelcerro | import org.gvsig.andami.preferences.AbstractPreferencePage; |
46 | |||
47 | /**
|
||
48 | * Appearance page. Where the user can choose Look&Feels and maybe some more stuff.
|
||
49 | *
|
||
50 | * @author jaume dominguez faus - jaume.dominguez@iver.es
|
||
51 | *
|
||
52 | */
|
||
53 | public class AppearancePage extends AbstractPreferencePage{ |
||
54 | private JComboBox lookAndFeelCombo; |
||
55 | private String id; |
||
56 | private ImageIcon icon; |
||
57 | private String lookAndFeel; |
||
58 | private boolean changed = false; |
||
59 | private Logger logger = LoggerFactory.getLogger(this.getClass()); |
||
60 | private PluginServices ps = PluginServices.getPluginServices(this); |
||
61 | private ActionListener myAction; |
||
62 | |||
63 | public AppearancePage() {
|
||
64 | super();
|
||
65 | id = this.getClass().getName();
|
||
66 | icon = PluginServices.getIconTheme().get("edit-setup-appearance");
|
||
67 | setParentID(GeneralPage.id); |
||
68 | // install the plastic look and feel before getting the laf combobox
|
||
69 | UIManager.installLookAndFeel("Plastic XP", "com.jgoodies.looks.plastic.PlasticXPLookAndFeel"); |
||
70 | // install the extra LAF's before getting the LAF combobox
|
||
71 | String osName = System.getProperty("os.name"); |
||
72 | if (osName.toLowerCase().startsWith("mac os x")) { |
||
73 | UIManager.installLookAndFeel("Quaqua", "ch.randelshofer.quaqua.QuaquaLookAndFeel"); |
||
74 | } |
||
75 | addComponent(PluginServices.getText(this, "options.general.select_theme"), getLookAndFeelComboBox()); |
||
76 | myAction = new ActionListener() { |
||
77 | public void actionPerformed(ActionEvent e) { |
||
78 | lookAndFeel = ((LF) lookAndFeelCombo.getSelectedItem()).getClassName(); |
||
79 | changed = true;
|
||
80 | |||
81 | /* Changing it on the fly can cause rendering issues
|
||
82 | try {
|
||
83 | UIManager.setLookAndFeel(lookAndFeel);
|
||
84 | SwingUtilities
|
||
85 | .updateComponentTreeUI((Component) PluginServices
|
||
86 | .getMainFrame());
|
||
87 | } catch (Exception ex) {
|
||
88 | logger.warn(Messages.getString("Launcher.look_and_feel"),
|
||
89 | ex);
|
||
90 | }
|
||
91 | */
|
||
92 | } |
||
93 | }; |
||
94 | |||
95 | } |
||
96 | |||
97 | public String getID() { |
||
98 | return id;
|
||
99 | } |
||
100 | |||
101 | public String getTitle() { |
||
102 | return PluginServices.getText(this, "pref.appearance"); |
||
103 | } |
||
104 | |||
105 | public JPanel getPanel() { |
||
106 | return this; |
||
107 | } |
||
108 | |||
109 | public void initializeValues() { |
||
110 | getLookAndFeelComboBox().removeActionListener(myAction); |
||
111 | lookAndFeel = Launcher.getAndamiConfig().getLookAndFeel(); |
||
112 | if (lookAndFeel == null) { |
||
113 | lookAndFeel = Launcher.getDefaultLookAndFeel(); |
||
114 | } |
||
115 | |||
116 | for (int i=0; i<getLookAndFeelComboBox().getModel().getSize(); i++) { |
||
117 | LF element = (LF) getLookAndFeelComboBox().getModel().getElementAt(i); |
||
118 | if (element.getClassName().equals(lookAndFeel)) {
|
||
119 | getLookAndFeelComboBox().setSelectedIndex(i); |
||
120 | break;
|
||
121 | } |
||
122 | } |
||
123 | getLookAndFeelComboBox().addActionListener(myAction); |
||
124 | } |
||
125 | |||
126 | |||
127 | public void storeValues() { |
||
128 | Launcher.getAndamiConfig().setLookAndFeel(lookAndFeel); |
||
129 | } |
||
130 | |||
131 | public void initializeDefaults() { |
||
132 | // getLookAndFeelComboBox().removeActionListener(myAction);
|
||
133 | |||
134 | final String defaultLookAndFeel = Launcher.getDefaultLookAndFeel(); |
||
135 | for (int i = 0; i < getLookAndFeelComboBox().getModel().getSize(); i++) { |
||
136 | LF lf = (LF) getLookAndFeelComboBox().getModel().getElementAt(i); |
||
137 | if (defaultLookAndFeel.equals(lf.getClassName())) {
|
||
138 | getLookAndFeelComboBox().setSelectedIndex(i); |
||
139 | break;
|
||
140 | } |
||
141 | } |
||
142 | // getLookAndFeelComboBox().addActionListener(myAction);
|
||
143 | } |
||
144 | |||
145 | public ImageIcon getIcon() { |
||
146 | return icon;
|
||
147 | } |
||
148 | |||
149 | private JComboBox getLookAndFeelComboBox() { |
||
150 | if (lookAndFeelCombo==null) { |
||
151 | 42968 | jjdelcerro | boolean enablelaf = BooleanUtils.toBoolean(PluginServices.getArgumentByName("enablelaf")); |
152 | if( enablelaf ) {
|
||
153 | LookAndFeelInfo[] lfs = UIManager.getInstalledLookAndFeels(); |
||
154 | ArrayList a = new ArrayList(); |
||
155 | for (int i = 0; i < lfs.length; i++) { |
||
156 | LF lf = new LF(lfs[i]);
|
||
157 | 40435 | jjdelcerro | |
158 | 42968 | jjdelcerro | // test if the look and feel is supported in this platform before adding it to the list
|
159 | Class lafClassDef;
|
||
160 | try {
|
||
161 | lafClassDef = Class.forName(lfs[i].getClassName());
|
||
162 | LookAndFeel laf;
|
||
163 | laf = (LookAndFeel) lafClassDef.newInstance();
|
||
164 | 40435 | jjdelcerro | |
165 | 42968 | jjdelcerro | if (laf.isSupportedLookAndFeel()) {
|
166 | a.add(lf); |
||
167 | } |
||
168 | 40435 | jjdelcerro | |
169 | 42968 | jjdelcerro | } catch (ClassNotFoundException e2) { |
170 | logger.error(ps.getText("error_loading_look_and_feel_"+lfs[i].getName()), e2);
|
||
171 | } catch (InstantiationException e1) { |
||
172 | logger.error(ps.getText("error_loading_look_and_feel_"+lfs[i].getName()), e1);
|
||
173 | } catch (IllegalAccessException e1) { |
||
174 | logger.error(ps.getText("error_loading_look_and_feel_"+lfs[i].getName()), e1);
|
||
175 | } |
||
176 | } |
||
177 | lookAndFeelCombo = new JComboBox(a.toArray(new LF[a.size()])); |
||
178 | } else {
|
||
179 | lookAndFeelCombo = new JComboBox(); |
||
180 | 40435 | jjdelcerro | } |
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 | |||
201 | public boolean isValueChanged() { |
||
202 | return changed;
|
||
203 | } |
||
204 | |||
205 | public void setChangesApplied() { |
||
206 | changed = false;
|
||
207 | } |
||
208 | } |