Statistics
| Revision:

svn-gvsig-desktop / tags / v10_RC2c / libraries / libCorePlugin / src / com / iver / core / preferences / general / AppearancePage.java @ 8745

History | View | Annotate | Download (6.84 KB)

1 6102 jaume
/* 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$
45
* $Log$
46 7143 jaume
* Revision 1.7.4.1  2006-09-08 11:56:24  jaume
47
* *** empty log message ***
48
*
49
* Revision 1.7  2006/08/22 12:23:05  jaume
50 6810 jaume
* improved perfomance when saving changes
51
*
52
* Revision 1.6  2006/08/22 07:37:17  jaume
53 6805 jaume
* *** empty log message ***
54
*
55
* Revision 1.5  2006/08/04 11:44:55  caballero
56 6662 caballero
* lanzo una excepci?n cuando falla el m?todo storeValues
57
*
58
* Revision 1.4  2006/08/04 11:03:43  cesar
59 6656 cesar
* Set the selected appearance after the combo box is filled (it had no effect otherwise)
60
*
61
* Revision 1.3  2006/08/02 12:49:07  cesar
62 6627 cesar
* Install Plastic look and feel before getting the LAF-combo. Hide installed but non-supported themes from the list.
63
*
64
* Revision 1.2  2006/07/31 10:02:31  jaume
65 6575 jaume
* *** empty log message ***
66
*
67
* Revision 1.1  2006/06/29 16:15:06  jaume
68 6102 jaume
* Appearance now configurable
69
*
70
*
71
*/
72
package com.iver.core.preferences.general;
73
74
import java.awt.event.ActionEvent;
75
import java.awt.event.ActionListener;
76
import java.util.ArrayList;
77
78
import javax.swing.ImageIcon;
79
import javax.swing.JComboBox;
80
import javax.swing.JPanel;
81 6627 cesar
import javax.swing.LookAndFeel;
82 6102 jaume
import javax.swing.UIManager;
83
import javax.swing.UIManager.LookAndFeelInfo;
84
85 6627 cesar
import org.apache.log4j.Logger;
86
87 6102 jaume
import com.iver.andami.Launcher;
88
import com.iver.andami.PluginServices;
89
import com.iver.andami.preferences.AbstractPreferencePage;
90 7143 jaume
/**
91
 * Appearance page. Where the user can choose Look&Feels and maybe some more stuff.
92
 *
93
 * @author jaume dominguez faus - jaume.dominguez@iver.es
94
 *
95
 */
96 6102 jaume
public class AppearancePage extends AbstractPreferencePage{
97
    private JComboBox lookAndFeelCombo;
98
    private String id;
99
    private ImageIcon icon;
100
    private String lookAndFeel;
101 6810 jaume
    private boolean changed = false;
102 6627 cesar
        private Logger logger = PluginServices.getLogger();
103
        private PluginServices ps = PluginServices.getPluginServices(this);
104 6805 jaume
        private ActionListener myAction;
105 6662 caballero
106 6805 jaume
        public AppearancePage() {
107 6102 jaume
        super();
108
        id = this.getClass().getName();
109
        icon = new ImageIcon(this.getClass().getClassLoader().getResource("images/gnome-settings-theme.png"));
110
        setParentID(GeneralPage.id);
111 6627 cesar
        // install the plastic look and feel before getting the laf combobox
112
            UIManager.installLookAndFeel("Plastic XP", "com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
113 6575 jaume
        addComponent(PluginServices.getText(this, "options.general.select_theme"), getLookAndFeelComboBox());
114 6805 jaume
        myAction = new ActionListener() {
115
            public void actionPerformed(ActionEvent e) {
116
                lookAndFeel = ((LF) lookAndFeelCombo.getSelectedItem()).getClassName();
117
                changed = true;
118
            }
119
        };
120 6810 jaume
121 6102 jaume
    }
122
123
    public String getID() {
124
        return id;
125
    }
126
127
    public String getTitle() {
128
        return PluginServices.getText(this, "pref.appearance");
129
    }
130
131
    public JPanel getPanel() {
132
        return this;
133
    }
134
135
    public void initializeValues() {
136 6805 jaume
            getLookAndFeelComboBox().removeActionListener(myAction);
137 6102 jaume
            lookAndFeel = Launcher.getAndamiConfig().getLookAndFeel();
138
            if (lookAndFeel == null) {
139
                    lookAndFeel = Launcher.getDefaultLookAndFeel();
140
            }
141 6805 jaume
142
            for (int i=0; i<getLookAndFeelComboBox().getModel().getSize(); i++) {
143
                    LF element = (LF) getLookAndFeelComboBox().getModel().getElementAt(i);
144 6656 cesar
                    if (element.getClassName().equals(lookAndFeel)) {
145 6805 jaume
                            getLookAndFeelComboBox().setSelectedIndex(i);
146 6656 cesar
                            break;
147
                    }
148
            }
149 6805 jaume
            getLookAndFeelComboBox().addActionListener(myAction);
150 6102 jaume
    }
151
152
153 6662 caballero
        public void storeValues() {
154
                Launcher.getAndamiConfig().setLookAndFeel(lookAndFeel);
155 6102 jaume
    }
156
157
    public void initializeDefaults() {
158 6805 jaume
            getLookAndFeelComboBox().removeActionListener(myAction);
159
160 6102 jaume
            final String defaultLookAndFeel = Launcher.getDefaultLookAndFeel();
161
        for (int i = 0; i < getLookAndFeelComboBox().getModel().getSize(); i++) {
162
                LF lf = (LF) getLookAndFeelComboBox().getModel().getElementAt(i);
163
                if (defaultLookAndFeel.equals(lf.getClassName())) {
164
                        getLookAndFeelComboBox().setSelectedIndex(i);
165
                        break;
166
                }
167
        }
168 6805 jaume
        getLookAndFeelComboBox().addActionListener(myAction);
169 6102 jaume
    }
170
171
    public ImageIcon getIcon() {
172
        return icon;
173
    }
174
175
    private JComboBox getLookAndFeelComboBox() {
176
        if (lookAndFeelCombo==null) {
177
            LookAndFeelInfo[] lfs = UIManager.getInstalledLookAndFeels();
178
            ArrayList a = new ArrayList();
179
            for (int i = 0; i < lfs.length; i++) {
180
                LF lf = new LF(lfs[i]);
181 6805 jaume
182 6627 cesar
                // test if the look and feel is supported in this platform before adding it to the list
183
                Class lafClassDef;
184
                                try {
185
                                        lafClassDef = Class.forName(lfs[i].getClassName());
186
                                        LookAndFeel laf;
187
                                        laf = (LookAndFeel) lafClassDef.newInstance();
188 6662 caballero
189 6627 cesar
                            if (laf.isSupportedLookAndFeel())
190
                                    a.add(lf);
191
192
                                } catch (ClassNotFoundException e2) {
193
                                        logger.error(ps.getText("error_loading_look_and_feel_"+lfs[i].getName()), e2);
194
                                } catch (InstantiationException e1) {
195
                                        logger.error(ps.getText("error_loading_look_and_feel_"+lfs[i].getName()), e1);
196
                                } catch (IllegalAccessException e1) {
197
                                        logger.error(ps.getText("error_loading_look_and_feel_"+lfs[i].getName()), e1);
198
                                }
199 6102 jaume
            }
200
            lookAndFeelCombo = new JComboBox((LF[]) a.toArray(new LF[a.size()]));
201 6805 jaume
202 6102 jaume
        }
203
        return lookAndFeelCombo;
204
    }
205
206
    private class LF {
207
        LookAndFeelInfo lfi;
208
209
        public LF(LookAndFeelInfo lfi) {
210
            this.lfi = lfi;
211
        }
212
213
        public String getClassName() {
214
            return lfi.getClassName();
215
        }
216
217
        public String toString() {
218
            return lfi.getName();
219
        }
220
    }
221 6805 jaume
222
        public boolean isValueChanged() {
223
                return changed;
224
        }
225 6810 jaume
226
        public void setChangesApplied() {
227
                changed = false;
228
        }
229 6102 jaume
}