Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libCorePlugin / src / com / iver / core / preferences / general / AppearancePage.java @ 39576

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

    
83
import java.awt.event.ActionEvent;
84
import java.awt.event.ActionListener;
85
import java.util.ArrayList;
86

    
87
import javax.swing.ImageIcon;
88
import javax.swing.JComboBox;
89
import javax.swing.JPanel;
90
import javax.swing.LookAndFeel;
91
import javax.swing.UIManager;
92
import javax.swing.UIManager.LookAndFeelInfo;
93

    
94
import org.apache.log4j.Logger;
95
import org.gvsig.tools.OsUtils;
96

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

    
116
        public AppearancePage() {
117
        super();
118
        id = this.getClass().getName();
119
        icon = PluginServices.getIconTheme().get("gnome-settings-theme");
120
        setParentID(GeneralPage.id);
121
        // install the plastic look and feel before getting the laf combobox
122
            UIManager.installLookAndFeel("Plastic XP", "com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
123
            // install the extra LAF's before getting the LAF combobox
124
            if (OsUtils.isMac()){
125
                UIManager.installLookAndFeel("Quaqua", "ch.randelshofer.quaqua.QuaquaLookAndFeel");
126
            }
127

    
128

    
129
            addComponent(PluginServices.getText(this, "options.general.select_theme"), getLookAndFeelComboBox());
130
        myAction = new ActionListener() {
131
            public void actionPerformed(ActionEvent e) {
132
                lookAndFeel = ((LF) lookAndFeelCombo.getSelectedItem()).getClassName();
133
                changed = true;
134
            }
135
        };
136

    
137
    }
138

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

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

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

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

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

    
168

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

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

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

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

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

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

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

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

    
218
        }
219
        return lookAndFeelCombo;
220
    }
221

    
222
    private class LF {
223
        LookAndFeelInfo lfi;
224

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

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

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

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

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