Statistics
| Revision:

gvsig-projects-pool / org.gvsig.winmgr / trunk / org.gvsig.winmgr.app / org.gvsig.winmgr.app.mainplugin / src / main / java / org / gvsig / coreplugin / preferences / general / SkinPreferences.java @ 682

History | View | Annotate | Download (4.91 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
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
 * as published by the Free Software Foundation; either version 3
9
 * 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
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
package org.gvsig.coreplugin.preferences.general;
25

    
26

    
27
import java.awt.event.ActionEvent;
28
import java.awt.event.ActionListener;
29
import java.util.HashMap;
30
import java.util.Iterator;
31
import java.util.Vector;
32
import java.util.prefs.Preferences;
33

    
34
import javax.swing.ImageIcon;
35
import javax.swing.JLabel;
36
import javax.swing.JOptionPane;
37
import javax.swing.JPanel;
38

    
39
import org.gvsig.andami.Launcher;
40
import org.gvsig.andami.PluginServices;
41
import org.gvsig.andami.plugins.config.generate.PluginConfig;
42
import org.gvsig.andami.plugins.config.generate.SkinExtension;
43
import org.gvsig.andami.preferences.AbstractPreferencePage;
44
import org.gvsig.andami.preferences.StoreException;
45
import org.gvsig.andami.ui.mdiManager.MDIManagerFactory;
46
import org.gvsig.utils.XMLEntity;
47
import org.gvsig.utils.swing.JComboBox;
48
import org.slf4j.Logger;
49
import org.slf4j.LoggerFactory;
50

    
51

    
52
public class SkinPreferences extends AbstractPreferencePage {
53

    
54
        private static final Logger logger = LoggerFactory.getLogger(SkinPreferences.class);
55
        private String id;
56
        private ImageIcon icon;
57
        private Vector listSkinsPlugins;
58
        private JComboBox comboBox;
59
        private String skinName = "org.gvsig.coreplugin.mdiManager.NewSkin";
60

    
61
        public SkinPreferences() {
62
                super();
63
                // TODO Auto-generated constructor stub
64
                id = this.getClass().getName();
65
                setParentID(GeneralPage.id);
66
                icon = PluginServices.getIconTheme().get("edit-setup-skin");
67
        }
68

    
69
        public void setChangesApplied() {
70
                // System.out.println("ESTOY LLAMANDO A setChangesApplied()");
71

    
72
        }
73

    
74
        public void storeValues() throws StoreException {
75
                // System.out.println("ESTOY LLAMANDO A storeValues()");
76
                PluginServices ps = PluginServices.getPluginServices("org.gvsig.coreplugin");
77
                XMLEntity xml = ps.getPersistentXML();
78
                xml.putProperty("Skin-Selected", skinName);
79
        }
80

    
81
        public String getID() {
82
                return id;
83
        }
84

    
85
        public ImageIcon getIcon() {
86
                return icon;
87
        }
88

    
89
        public JPanel getPanel() {
90

    
91
                if (comboBox == null) {
92
                        comboBox = getComboBox();
93

    
94
                        addComponent(new JLabel(PluginServices.getText(this, "skin_label")));
95

    
96
                        addComponent(comboBox);
97
                }
98

    
99
                return this;
100
        }
101

    
102
        private JComboBox getComboBox() {
103
                comboBox = new JComboBox(listSkinsPlugins);
104

    
105
                comboBox.addActionListener(new ActionListener() {
106
                        public void actionPerformed(ActionEvent e) {
107
                                JComboBox cb = (JComboBox) e.getSource();
108
                                String newSkinName = (String) cb.getSelectedItem();
109
                                if (newSkinName != null)
110
                                        if (!newSkinName.equals(skinName)) {
111
                                                skinName = newSkinName;
112
                                                JOptionPane.showMessageDialog(null, PluginServices
113
                                                                .getText(this, "skin_message"));
114
                                        }
115
                        }
116

    
117
                });
118

    
119
                comboBox.setSelectedItem(skinName);
120
                return comboBox;
121
        }
122

    
123
        public String getTitle() {
124
                // TODO Auto-generated method stub
125
                return PluginServices.getText(this, "skin");
126
        }
127

    
128
        public void initializeDefaults() {
129
                // TODO Auto-generated method stub
130
                // System.out.println("inicialize Defaults");
131

    
132
        }
133

    
134
        public void initializeValues() {
135
                listSkinsPlugins = new Vector();
136

    
137
                HashMap pluginsConfig = Launcher.getPluginConfig();
138
                Iterator i = pluginsConfig.keySet().iterator();
139

    
140
                while (i.hasNext()) {
141
                        String name = (String) i.next();
142
                        PluginConfig pc = (PluginConfig) pluginsConfig.get(name);
143

    
144
                        if (pc.getExtensions().getSkinExtension() != null) {
145
                                SkinExtension[] se = pc.getExtensions().getSkinExtension();
146
                                for (int j=0;j<se.length;j++){
147
                                        String extensionName = se[j].getClassName();
148
                                        listSkinsPlugins.add(extensionName );
149
                                        logger.info("Skin plugin '"+name + "', extension '"+ extensionName +".");
150
                                }
151
                        }
152
                }
153

    
154

    
155
                PluginServices ps = PluginServices.getPluginServices("org.gvsig.coreplugin");
156
                XMLEntity xml = ps.getPersistentXML();
157
                if (xml.contains("Skin-Selected")) {
158
                        skinName = xml.getStringProperty("Skin-Selected");
159

    
160
                }
161

    
162

    
163

    
164
        }
165

    
166
        public boolean isValueChanged() {
167
                // TODO Auto-generated method stub
168
                // System.out.println("is value changed");
169
                return true;
170
        }
171

    
172
}