Statistics
| Revision:

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

History | View | Annotate | Download (6.14 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 6656 2006-08-04 11:03:43Z cesar $
45
* $Log$
46
* Revision 1.4  2006-08-04 11:03:43  cesar
47
* Set the selected appearance after the combo box is filled (it had no effect otherwise)
48
*
49
* Revision 1.3  2006/08/02 12:49:07  cesar
50
* Install Plastic look and feel before getting the LAF-combo. Hide installed but non-supported themes from the list.
51
*
52
* Revision 1.2  2006/07/31 10:02:31  jaume
53
* *** empty log message ***
54
*
55
* Revision 1.1  2006/06/29 16:15:06  jaume
56
* Appearance now configurable
57
*
58
*
59
*/
60
package com.iver.core.preferences.general;
61

    
62
import java.awt.event.ActionEvent;
63
import java.awt.event.ActionListener;
64
import java.util.ArrayList;
65

    
66
import javax.swing.ImageIcon;
67
import javax.swing.JComboBox;
68
import javax.swing.JPanel;
69
import javax.swing.LookAndFeel;
70
import javax.swing.UIManager;
71
import javax.swing.UIManager.LookAndFeelInfo;
72

    
73
import org.apache.log4j.Logger;
74

    
75
import com.iver.andami.Launcher;
76
import com.iver.andami.PluginServices;
77
import com.iver.andami.preferences.AbstractPreferencePage;
78

    
79
public class AppearancePage extends AbstractPreferencePage{
80
    private JComboBox lookAndFeelCombo;
81
    private String id;
82
    private ImageIcon icon;
83
    private String lookAndFeel;
84
        private int lookAndFeelIndex;
85
        private Logger logger = PluginServices.getLogger();
86
        private PluginServices ps = PluginServices.getPluginServices(this);
87
        
88
    public AppearancePage() {
89
        super();
90
        id = this.getClass().getName();
91
        icon = new ImageIcon(this.getClass().getClassLoader().getResource("images/gnome-settings-theme.png"));
92
        setParentID(GeneralPage.id);
93
        // install the plastic look and feel before getting the laf combobox
94
            UIManager.installLookAndFeel("Plastic XP", "com.jgoodies.looks.plastic.PlasticXPLookAndFeel");
95
        addComponent(PluginServices.getText(this, "options.general.select_theme"), getLookAndFeelComboBox());
96
    }
97

    
98
    public String getID() {
99
        return id;
100
    }
101

    
102
    public String getTitle() {
103
        return PluginServices.getText(this, "pref.appearance");
104
    }
105

    
106
    public JPanel getPanel() {
107
        return this;
108
    }
109

    
110
    public void initializeValues() {
111
            lookAndFeel = Launcher.getAndamiConfig().getLookAndFeel();
112
            if (lookAndFeel == null) {
113
                    lookAndFeel = Launcher.getDefaultLookAndFeel();
114
            }
115
            
116
            for (int i=0; i<lookAndFeelCombo.getModel().getSize(); i++) {
117
                    LF element = (LF) lookAndFeelCombo.getModel().getElementAt(i);
118
                    if (element.getClassName().equals(lookAndFeel)) {
119
                            lookAndFeelCombo.setSelectedIndex(i);
120
                            lookAndFeelIndex = i;
121
                            break;
122
                    }
123
            }
124
    }
125

    
126

    
127
        public boolean storeValues() {
128
            Launcher.getAndamiConfig().setLookAndFeel(lookAndFeel);
129
        return true;
130
    }
131

    
132
    public void initializeDefaults() {
133
            final String defaultLookAndFeel = Launcher.getDefaultLookAndFeel();
134
        for (int i = 0; i < getLookAndFeelComboBox().getModel().getSize(); i++) {
135
                LF lf = (LF) getLookAndFeelComboBox().getModel().getElementAt(i);
136
                if (defaultLookAndFeel.equals(lf.getClassName())) {
137
                        getLookAndFeelComboBox().setSelectedIndex(i);
138
                        break;
139
                }
140
        }
141
    }
142

    
143
    public void cancelAction() {
144
            getLookAndFeelComboBox().setSelectedIndex(lookAndFeelIndex);
145
    }
146

    
147
    public ImageIcon getIcon() {
148
        return icon;
149
    }
150

    
151
    private JComboBox getLookAndFeelComboBox() {
152
        if (lookAndFeelCombo==null) {
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
                
158
                // 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
                                        
165
                            if (laf.isSupportedLookAndFeel())
166
                                    a.add(lf);
167

    
168
                                } catch (ClassNotFoundException e2) {
169
                                        logger.error(ps.getText("error_loading_look_and_feel_"+lfs[i].getName()), e2);
170
                                } catch (InstantiationException e1) {
171
                                        logger.error(ps.getText("error_loading_look_and_feel_"+lfs[i].getName()), e1);
172
                                } catch (IllegalAccessException e1) {
173
                                        logger.error(ps.getText("error_loading_look_and_feel_"+lfs[i].getName()), e1);
174
                                }
175
            }
176
            lookAndFeelCombo = new JComboBox((LF[]) a.toArray(new LF[a.size()]));
177
            lookAndFeelCombo.addActionListener(new ActionListener() {
178
                public void actionPerformed(ActionEvent e) {
179
                    lookAndFeel = ((LF) lookAndFeelCombo.getSelectedItem()).getClassName();
180
                }
181
            });
182
        }
183
        return lookAndFeelCombo;
184
    }
185

    
186
    private class LF {
187
        LookAndFeelInfo lfi;
188

    
189
        public LF(LookAndFeelInfo lfi) {
190
            this.lfi = lfi;
191
        }
192

    
193
        public String getClassName() {
194
            return lfi.getClassName();
195
        }
196

    
197
        public String toString() {
198
            return lfi.getName();
199
        }
200
    }
201
}