Statistics
| Revision:

root / branches / v2_0_0_prep / libraries / libCorePlugin / src / org / gvsig / coreplugin / preferences / general / SkinPreferences.java @ 38608

History | View | Annotate | Download (4.05 KB)

1
package org.gvsig.coreplugin.preferences.general;
2

    
3

    
4
import java.awt.event.ActionEvent;
5
import java.awt.event.ActionListener;
6
import java.util.HashMap;
7
import java.util.Iterator;
8
import java.util.Vector;
9
import java.util.prefs.Preferences;
10

    
11
import javax.swing.ImageIcon;
12
import javax.swing.JLabel;
13
import javax.swing.JOptionPane;
14
import javax.swing.JPanel;
15

    
16
import org.gvsig.andami.Launcher;
17
import org.gvsig.andami.PluginServices;
18
import org.gvsig.andami.plugins.config.generate.PluginConfig;
19
import org.gvsig.andami.plugins.config.generate.SkinExtension;
20
import org.gvsig.andami.preferences.AbstractPreferencePage;
21
import org.gvsig.andami.preferences.StoreException;
22
import org.gvsig.andami.ui.mdiManager.MDIManagerFactory;
23
import org.gvsig.utils.XMLEntity;
24
import org.gvsig.utils.swing.JComboBox;
25
import org.slf4j.Logger;
26
import org.slf4j.LoggerFactory;
27

    
28

    
29
public class SkinPreferences extends AbstractPreferencePage {
30

    
31
        private static final Logger logger = LoggerFactory.getLogger(SkinPreferences.class);
32
        private String id;
33
        private ImageIcon icon;
34
        private Vector listSkinsPlugins;
35
        private JComboBox comboBox;
36
        private String skinName = "org.gvsig.coreplugin.mdiManager.NewSkin";
37
        private static Preferences prefs = Preferences.userRoot().node(
38
                        "gvsig.configuration.3D");
39

    
40
        public SkinPreferences() {
41
                super();
42
                // TODO Auto-generated constructor stub
43
                id = this.getClass().getName();
44
                setParentID(GeneralPage.id);
45
                icon = PluginServices.getIconTheme().get("edit-setup-skin");
46
        }
47

    
48
        public void setChangesApplied() {
49
                // System.out.println("ESTOY LLAMANDO A setChangesApplied()");
50

    
51
        }
52

    
53
        public void storeValues() throws StoreException {
54
                // System.out.println("ESTOY LLAMANDO A storeValues()");
55
                PluginServices ps = PluginServices.getPluginServices("org.gvsig.coreplugin");
56
                XMLEntity xml = ps.getPersistentXML();
57
                xml.putProperty("Skin-Selected", skinName);
58
        }
59

    
60
        public String getID() {
61
                return id;
62
        }
63

    
64
        public ImageIcon getIcon() {
65
                return icon;
66
        }
67

    
68
        public JPanel getPanel() {
69

    
70
                if (comboBox == null) {
71
                        comboBox = getComboBox();
72

    
73
                        addComponent(new JLabel(PluginServices.getText(this, "skin_label")));
74

    
75
                        addComponent(comboBox);
76
                }
77

    
78
                return this;
79
        }
80

    
81
        private JComboBox getComboBox() {
82
                comboBox = new JComboBox(listSkinsPlugins);
83

    
84
                comboBox.addActionListener(new ActionListener() {
85
                        public void actionPerformed(ActionEvent e) {
86
                                JComboBox cb = (JComboBox) e.getSource();
87
                                String newSkinName = (String) cb.getSelectedItem();
88
                                if (newSkinName != null)
89
                                        if (!newSkinName.equals(skinName)) {
90
                                                skinName = newSkinName;
91
                                                JOptionPane.showMessageDialog(null, PluginServices
92
                                                                .getText(this, "skin_message"));
93
                                        }
94
                        }
95

    
96
                });
97

    
98
                comboBox.setSelectedItem(skinName);
99
                return comboBox;
100
        }
101

    
102
        public String getTitle() {
103
                // TODO Auto-generated method stub
104
                return PluginServices.getText(this, "skin");
105
        }
106

    
107
        public void initializeDefaults() {
108
                // TODO Auto-generated method stub
109
                // System.out.println("inicialize Defaults");
110

    
111
        }
112

    
113
        public void initializeValues() {
114
                listSkinsPlugins = new Vector();
115

    
116
                HashMap pluginsConfig = Launcher.getPluginConfig();
117
                Iterator i = pluginsConfig.keySet().iterator();
118

    
119
                while (i.hasNext()) {
120
                        String name = (String) i.next();
121
                        PluginConfig pc = (PluginConfig) pluginsConfig.get(name);
122

    
123
                        if (pc.getExtensions().getSkinExtension() != null) {
124
                                SkinExtension[] se = pc.getExtensions().getSkinExtension();
125
                                for (int j=0;j<se.length;j++){
126
                                        String extensionName = se[j].getClassName();
127
                                        listSkinsPlugins.add(extensionName );
128
                                        logger.info("Skin plugin '"+name + "', extension '"+ extensionName +".");
129
                                }
130
                        }
131
                }
132

    
133

    
134
                PluginServices ps = PluginServices.getPluginServices("org.gvsig.coreplugin");
135
                XMLEntity xml = ps.getPersistentXML();
136
                if (xml.contains("Skin-Selected")) {
137
                        skinName = xml.getStringProperty("Skin-Selected");
138

    
139
                }
140

    
141

    
142

    
143
        }
144

    
145
        public boolean isValueChanged() {
146
                // TODO Auto-generated method stub
147
                // System.out.println("is value changed");
148
                return true;
149
        }
150

    
151
}