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 @ 43913

History | View | Annotate | Download (5.33 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 modify it under
7
 * the terms of the GNU General Public License as published by the Free Software
8
 * Foundation; either version 3 of the License, or (at your option) any later
9
 * version.
10
 *
11
 * This program is distributed in the hope that it will be useful, but WITHOUT
12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14
 * details.
15
 *
16
 * You should have received a copy of the GNU General Public License along with
17
 * this program; if not, write to the Free Software Foundation, Inc., 51
18
 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
 *
20
 * For any additional information, do not hesitate to contact us at info AT
21
 * gvsig.com, or visit our website www.gvsig.com.
22
 */
23
package org.gvsig.coreplugin.preferences.general;
24

    
25
import com.lowagie.text.ListItem;
26
import java.awt.BorderLayout;
27
import java.util.prefs.Preferences;
28

    
29
import javax.swing.DefaultComboBoxModel;
30
import javax.swing.ImageIcon;
31
import javax.swing.JPanel;
32
import org.apache.commons.lang3.StringUtils;
33

    
34
import org.gvsig.andami.IconThemeHelper;
35
import org.gvsig.andami.preferences.AbstractPreferencePage;
36
import org.gvsig.andami.preferences.StoreException;
37
import org.gvsig.i18n.Messages;
38
import org.gvsig.tools.swing.api.ListElement;
39
import org.gvsig.tools.swing.api.ToolsSwingLocator;
40
import org.gvsig.tools.swing.icontheme.IconTheme;
41
import org.gvsig.tools.swing.icontheme.IconThemeManager;
42
import org.slf4j.Logger;
43
import org.slf4j.LoggerFactory;
44

    
45
public class IconThemePage extends AbstractPreferencePage {
46

    
47
    /**
48
     *
49
     */
50
    private static final long serialVersionUID = 4369071892027860769L;
51

    
52
    private static final Logger logger = LoggerFactory.getLogger(IconThemePage.class);
53

    
54
    private final String id;
55
    private boolean changed = false;
56
    private IconThemePageLayout panel = null;
57
    private ImageIcon icon = null;
58

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

    
66
    @Override
67
    public String getID() {
68
        return id;
69
    }
70

    
71
    @Override
72
    public String getTitle() {
73
        return Messages.getText("_Icon_theme");
74
    }
75

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

    
81
    @Override
82
    public void initializeValues() {
83
        final IconThemeManager iconManager = ToolsSwingLocator.getIconThemeManager();
84
        Preferences prefs = Preferences.userRoot().node("gvsig.icontheme");
85
        String themeId = prefs.get("default-theme",null);
86
        ListElement.setSelected(panel.combo_selection, iconManager.get(themeId));
87
    }
88

    
89
    @Override
90
    public void storeValues() throws StoreException {
91
        IconTheme iconTheme = (IconTheme) ListElement.getSelected(panel.combo_selection);
92
        if (iconTheme != null && iconTheme != iconTheme.getDefault()) {
93
            Preferences prefs = Preferences.userRoot().node("gvsig.icontheme");
94
            prefs.put("default-theme", iconTheme.getID());
95
        }
96
    }
97

    
98
    @Override
99
    public void initializeDefaults() {
100

    
101
    }
102

    
103
    @Override
104
    public ImageIcon getIcon() {
105
        if (icon == null) {
106
            icon = IconThemeHelper.getImageIcon("edit-setup-icontheme");
107
        }
108
        return icon;
109
    }
110

    
111
    @Override
112
    public boolean isValueChanged() {
113
        if (panel.combo_selection.getSelectedIndex() >= 0) {
114
            return true;
115
        }
116
        return changed;
117
    }
118

    
119
    @Override
120
    public void setChangesApplied() {
121
        changed = false;
122
    }
123

    
124
    private void initialize() {
125
        final IconThemeManager iconManager = ToolsSwingLocator.getIconThemeManager();
126
        this.setLayout(new BorderLayout());
127

    
128
        this.panel = new IconThemePageLayout();
129

    
130
        DefaultComboBoxModel<ListElement<IconTheme>> model = new DefaultComboBoxModel<>();
131
        for (int i = 0; i < iconManager.getCount(); i++) {
132
            IconTheme iconTheme = iconManager.get(i);
133
            model.addElement(new ListElement<>(
134
                    StringUtils.abbreviate(iconTheme.toString(), 60),
135
                    iconTheme
136
                )
137
            );
138
        }
139
        this.panel.combo_selection.setModel(model);
140

    
141
        // Traducir las etiquetas del panel
142
        panel.label_title.setText(translate(panel.label_title.getText()));
143
        panel.label_selection.setText(translate(panel.label_selection.getText()));
144

    
145
        this.add(panel, BorderLayout.CENTER);
146
    }
147

    
148
    private String translate(String s) {
149
        return Messages.getText(s);
150
    }
151

    
152
//    private void createDefaultIconTheme() {
153
//        PluginsManager pluginsManager = PluginsLocator.getManager();
154
//        IconThemeManager iconManager = ToolsSwingLocator.getIconThemeManager();
155
//
156
//        File f = new File(pluginsManager.getApplicationHomeFolder(), "icon-theme");
157
//        if (!f.exists()) {
158
//            f.mkdir();
159
//        }
160
//        IconTheme theme = iconManager.getDefault();
161
//        File f2 = new File(f, theme.getID());
162
//        if (!f2.exists()) {
163
//            logger.info("Creating default icon theme in " + f.getAbsolutePath());
164
//            theme.export(f);
165
//        }
166
//    }
167

    
168

    
169
    @Override
170
    public boolean isResizeable() {
171
        return true;
172
    }
173
   
174
}