Statistics
| Revision:

root / branches / piloto3d / libraries / libCorePlugin / src / com / iver / core / preferences / general / AppearancePage.java @ 9535

History | View | Annotate | Download (7.21 KB)

1
/* 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: AppearancePage.java 9535 2007-01-04 09:55:25Z jcampos $
45
* $Log$
46
* Revision 1.7.2.2  2007-01-04 09:52:40  jcampos
47
* Upgrade new version
48
*
49
* Revision 1.7.4.2  2006/11/15 00:08:23  jjdelcerro
50
* *** empty log message ***
51
*
52
* Revision 1.11  2006/09/12 12:09:51  jaume
53
* *** empty log message ***
54
*
55
* Revision 1.10  2006/09/12 11:49:04  jaume
56
* *** empty log message ***
57
*
58
* Revision 1.9  2006/09/12 10:11:25  jaume
59
* *** empty log message ***
60
*
61
* Revision 1.7.4.1  2006/09/08 11:56:24  jaume
62
* *** empty log message ***
63
*
64
* Revision 1.7  2006/08/22 12:23:05  jaume
65
* improved perfomance when saving changes
66
*
67
* Revision 1.6  2006/08/22 07:37:17  jaume
68
* *** empty log message ***
69
*
70
* Revision 1.5  2006/08/04 11:44:55  caballero
71
* lanzo una excepci?n cuando falla el m?todo storeValues
72
*
73
* Revision 1.4  2006/08/04 11:03:43  cesar
74
* Set the selected appearance after the combo box is filled (it had no effect otherwise)
75
*
76
* Revision 1.3  2006/08/02 12:49:07  cesar
77
* Install Plastic look and feel before getting the LAF-combo. Hide installed but non-supported themes from the list.
78
*
79
* Revision 1.2  2006/07/31 10:02:31  jaume
80
* *** empty log message ***
81
*
82
* Revision 1.1  2006/06/29 16:15:06  jaume
83
* Appearance now configurable
84
*
85
*
86
*/
87
package com.iver.core.preferences.general;
88

    
89
import java.awt.event.ActionEvent;
90
import java.awt.event.ActionListener;
91
import java.util.ArrayList;
92

    
93
import javax.swing.ImageIcon;
94
import javax.swing.JComboBox;
95
import javax.swing.JPanel;
96
import javax.swing.LookAndFeel;
97
import javax.swing.UIManager;
98
import javax.swing.UIManager.LookAndFeelInfo;
99

    
100
import org.apache.log4j.Logger;
101

    
102
import com.iver.andami.Launcher;
103
import com.iver.andami.PluginServices;
104
import com.iver.andami.preferences.AbstractPreferencePage;
105
/**
106
 * Appearance page. Where the user can choose Look&Feels and maybe some more stuff.
107
 *
108
 * @author jaume dominguez faus - jaume.dominguez@iver.es
109
 *
110
 */
111
public class AppearancePage extends AbstractPreferencePage{
112
    private JComboBox lookAndFeelCombo;
113
    private String id;
114
    private ImageIcon icon;
115
    private String lookAndFeel;
116
    private boolean changed = false;
117
        private Logger logger = PluginServices.getLogger();
118
        private PluginServices ps = PluginServices.getPluginServices(this);
119
        private ActionListener myAction;
120

    
121
        public AppearancePage() {
122
        super();
123
        id = this.getClass().getName();
124
        icon = new ImageIcon(this.getClass().getClassLoader().getResource("images/gnome-settings-theme.png"));
125
        setParentID(GeneralPage.id);
126
        // install the plastic look and feel before getting the laf combobox
127
            UIManager.installLookAndFeel("Plastic XP", "com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
128
        addComponent(PluginServices.getText(this, "options.general.select_theme"), getLookAndFeelComboBox());
129
        myAction = new ActionListener() {
130
            public void actionPerformed(ActionEvent e) {
131
                lookAndFeel = ((LF) lookAndFeelCombo.getSelectedItem()).getClassName();
132
                changed = true;
133
            }
134
        };
135

    
136
    }
137

    
138
    public String getID() {
139
        return id;
140
    }
141

    
142
    public String getTitle() {
143
        return PluginServices.getText(this, "pref.appearance");
144
    }
145

    
146
    public JPanel getPanel() {
147
        return this;
148
    }
149

    
150
    public void initializeValues() {
151
            getLookAndFeelComboBox().removeActionListener(myAction);
152
            lookAndFeel = Launcher.getAndamiConfig().getLookAndFeel();
153
            if (lookAndFeel == null) {
154
                    lookAndFeel = Launcher.getDefaultLookAndFeel();
155
            }
156

    
157
            for (int i=0; i<getLookAndFeelComboBox().getModel().getSize(); i++) {
158
                    LF element = (LF) getLookAndFeelComboBox().getModel().getElementAt(i);
159
                    if (element.getClassName().equals(lookAndFeel)) {
160
                            getLookAndFeelComboBox().setSelectedIndex(i);
161
                            break;
162
                    }
163
            }
164
            getLookAndFeelComboBox().addActionListener(myAction);
165
    }
166

    
167

    
168
        public void storeValues() {
169
                Launcher.getAndamiConfig().setLookAndFeel(lookAndFeel);
170
    }
171

    
172
    public void initializeDefaults() {
173
            getLookAndFeelComboBox().removeActionListener(myAction);
174

    
175
            final String defaultLookAndFeel = Launcher.getDefaultLookAndFeel();
176
        for (int i = 0; i < getLookAndFeelComboBox().getModel().getSize(); i++) {
177
                LF lf = (LF) getLookAndFeelComboBox().getModel().getElementAt(i);
178
                if (defaultLookAndFeel.equals(lf.getClassName())) {
179
                        getLookAndFeelComboBox().setSelectedIndex(i);
180
                        break;
181
                }
182
        }
183
        getLookAndFeelComboBox().addActionListener(myAction);
184
    }
185

    
186
    public ImageIcon getIcon() {
187
        return icon;
188
    }
189

    
190
    private JComboBox getLookAndFeelComboBox() {
191
        if (lookAndFeelCombo==null) {
192
            LookAndFeelInfo[] lfs = UIManager.getInstalledLookAndFeels();
193
            ArrayList a = new ArrayList();
194
            for (int i = 0; i < lfs.length; i++) {
195
                LF lf = new LF(lfs[i]);
196

    
197
                // test if the look and feel is supported in this platform before adding it to the list
198
                Class lafClassDef;
199
                                try {
200
                                        lafClassDef = Class.forName(lfs[i].getClassName());
201
                                        LookAndFeel laf;
202
                                        laf = (LookAndFeel) lafClassDef.newInstance();
203

    
204
                            if (laf.isSupportedLookAndFeel())
205
                                    a.add(lf);
206

    
207
                                } catch (ClassNotFoundException e2) {
208
                                        logger.error(ps.getText("error_loading_look_and_feel_"+lfs[i].getName()), e2);
209
                                } catch (InstantiationException e1) {
210
                                        logger.error(ps.getText("error_loading_look_and_feel_"+lfs[i].getName()), e1);
211
                                } catch (IllegalAccessException e1) {
212
                                        logger.error(ps.getText("error_loading_look_and_feel_"+lfs[i].getName()), e1);
213
                                }
214
            }
215
            lookAndFeelCombo = new JComboBox((LF[]) a.toArray(new LF[a.size()]));
216

    
217
        }
218
        return lookAndFeelCombo;
219
    }
220

    
221
    private class LF {
222
        LookAndFeelInfo lfi;
223

    
224
        public LF(LookAndFeelInfo lfi) {
225
            this.lfi = lfi;
226
        }
227

    
228
        public String getClassName() {
229
            return lfi.getClassName();
230
        }
231

    
232
        public String toString() {
233
            return lfi.getName();
234
        }
235
    }
236

    
237
        public boolean isValueChanged() {
238
                return changed;
239
        }
240

    
241
        public void setChangesApplied() {
242
                changed = false;
243
        }
244
}