Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.coreplugin.app / org.gvsig.coreplugin.app.mainplugin / src / main / java / org / gvsig / coreplugin / preferences / general / IconThemePage.java @ 40558

History | View | Annotate | Download (4.78 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
import java.awt.BorderLayout;
27
import java.awt.event.ActionEvent;
28
import java.awt.event.ActionListener;
29
import java.io.File;
30
import java.util.prefs.Preferences;
31

    
32
import javax.swing.ComboBoxModel;
33
import javax.swing.ImageIcon;
34
import javax.swing.JPanel;
35
import javax.swing.event.ListDataListener;
36

    
37
import org.gvsig.andami.PluginServices;
38
import org.gvsig.andami.PluginsLocator;
39
import org.gvsig.andami.PluginsManager;
40
import org.gvsig.andami.preferences.AbstractPreferencePage;
41
import org.gvsig.andami.preferences.StoreException;
42
import org.gvsig.tools.swing.api.ToolsSwingLocator;
43
import org.gvsig.tools.swing.icontheme.IconTheme;
44
import org.gvsig.tools.swing.icontheme.IconThemeManager;
45
import org.slf4j.Logger;
46
import org.slf4j.LoggerFactory;
47

    
48
public class IconThemePage extends AbstractPreferencePage {
49

    
50
        /**
51
         * 
52
         */
53
        private static final long serialVersionUID = 4369071892027860769L;
54

    
55
        private static Logger logger = LoggerFactory.getLogger(IconThemePage.class);
56
        
57
        private String id;
58
        private boolean changed = false;
59
        private IconThemePageLayout panel = null;
60

    
61
        public IconThemePage() {
62
                super();
63
                initialize();
64
                id = this.getClass().getName();
65
                setParentID(GeneralPage.class.getName());
66
        }
67

    
68
        public String getID() {
69
                return id;
70
        }
71

    
72
        public String getTitle() {
73
                return PluginServices.getText(this, "_Icon_theme");
74
        }
75

    
76
        public JPanel getPanel() {
77
                return this;
78
        }
79

    
80
        public void initializeValues() {
81
        }
82

    
83
        public void storeValues() throws StoreException {
84
                IconTheme iconTheme = (IconTheme) panel.combo_selection.getSelectedItem();
85
                if(iconTheme != null && iconTheme != iconTheme.getDefault() ) {
86
                        Preferences prefs = Preferences.userRoot().node("gvsig.icontheme");
87
                        prefs.put("default-theme", iconTheme.getID());
88
                }
89
        }
90

    
91
        public void initializeDefaults() {
92

    
93
        }
94

    
95
        public ImageIcon getIcon() {
96
                return PluginServices.getIconTheme().get("edit-setup-icontheme");
97
        }
98

    
99
        public boolean isValueChanged() {
100
                if( panel.combo_selection.getSelectedIndex()>=0 ) {
101
                        return true;
102
                }
103
                return changed;
104
        }
105

    
106
        public void setChangesApplied() {
107
                changed = false;
108
        }
109

    
110
        private void initialize() {
111
                final IconThemeManager iconManager = ToolsSwingLocator.getIconThemeManager();
112
                this.setLayout(new BorderLayout());
113
                
114
                this.panel = new IconThemePageLayout();
115

    
116
                panel.combo_selection.setModel(new ComboBoxModel() {
117
                        IconTheme selected = null;
118
                        public void removeListDataListener(ListDataListener arg0) {
119
                                // Do nothing
120
                        }
121
                        public int getSize() {
122
                                return iconManager.getCount();
123
                        }
124
                        public Object getElementAt(int arg0) {
125
                                return iconManager.get(arg0);
126
                        }
127
                        public void addListDataListener(ListDataListener arg0) {
128
                                // Do nothing
129
                        }
130
                        public void setSelectedItem(Object arg0) {
131
                                this.selected = (IconTheme) arg0;
132
                        }
133
                        public Object getSelectedItem() {
134
                                return this.selected;
135
                        }
136
                });
137
                
138
                panel.button_export.addActionListener(new ActionListener() {
139
                        public void actionPerformed(ActionEvent arg0) {
140
                                createDefaultIconTheme();
141
                        }
142
                });
143
                
144
                // Traducir las etiquetas del panel
145
                panel.label_title.setText(translate(panel.label_title.getText()));
146
                panel.label_selection.setText(translate(panel.label_selection.getText()));
147
                panel.button_export.setText(translate(panel.button_export.getText()));
148
                
149
                this.add(panel, BorderLayout.CENTER);
150
        }
151
        
152
        private String translate(String s) {
153
                return PluginServices.getText(this,s);
154
        }
155
        
156
        private void createDefaultIconTheme() {
157
                PluginsManager pluginsManager = PluginsLocator.getManager();
158
                IconThemeManager iconManager = ToolsSwingLocator.getIconThemeManager();
159
                
160
                File f = new File(pluginsManager.getApplicationHomeFolder(),"icon-theme");
161
                if( !f.exists() ) {
162
                        f.mkdir();
163
                }
164
                IconTheme theme = iconManager.getDefault();
165
                File f2 = new File(f,theme.getID()) ;
166
                if( !f2.exists() ) {
167
                        logger.info("Creating default icon theme in "+f.getAbsolutePath());
168
                        theme.export(f);
169
                }
170
        }
171
} 
172