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

History | View | Annotate | Download (6.63 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 javax.swing.text.DocumentFilter;
33
import org.apache.commons.lang3.StringUtils;
34

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

    
47
public class IconThemePage extends AbstractPreferencePage {
48

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

    
54
    private static final Logger logger = LoggerFactory.getLogger(IconThemePage.class);
55

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

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

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

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

    
78
    @Override
79
    public JPanel getPanel() {
80
        return this;
81
    }
82

    
83
    @Override
84
    public void initializeValues() {
85
        final IconThemeManager iconManager = ToolsSwingLocator.getIconThemeManager();
86
        Preferences prefs = Preferences.userRoot().node("gvsig.icontheme");
87
        String themeId = prefs.get("default-theme",null);
88
        double scaleFactor;
89
        try {
90
            scaleFactor = prefs.getDouble("scaleFactor",1.0);
91
        } catch(Throwable th) {
92
            scaleFactor = 1.0;
93
        }
94
        ListElement.setSelected(panel.combo_selection, iconManager.get(themeId));
95
        DoubleDocumentFilter.install(panel.txtScaleFactor);
96
    }
97

    
98
    @Override
99
    public void storeValues() throws StoreException {
100
        Preferences prefs = Preferences.userRoot().node("gvsig.icontheme");
101
        IconTheme iconTheme = (IconTheme) ListElement.getSelected(panel.combo_selection);
102
        if (iconTheme != null && iconTheme != iconTheme.getDefault()) {
103
            prefs.put("default-theme", iconTheme.getID());
104
        }
105
        if( DoubleDocumentFilter.isValid(panel.txtScaleFactor) ) {
106
            double scaleFactor = DoubleDocumentFilter.getValue(panel.txtScaleFactor);
107
            prefs.putDouble("scaleFactor", scaleFactor);
108
        }
109

    
110
    }
111

    
112
    @Override
113
    public void initializeDefaults() {
114

    
115
    }
116

    
117
    @Override
118
    public ImageIcon getIcon() {
119
        if (icon == null) {
120
            icon = IconThemeHelper.getImageIcon("edit-setup-icontheme");
121
        }
122
        return icon;
123
    }
124

    
125
    @Override
126
    public boolean isValueChanged() {
127
        if (panel.combo_selection.getSelectedIndex() >= 0) {
128
            return true;
129
        }
130
        if( DoubleDocumentFilter.isValid(panel.txtScaleFactor) ) {
131
            double scaleFactor = DoubleDocumentFilter.getValue(panel.txtScaleFactor);
132
            Preferences prefs = Preferences.userRoot().node("gvsig.icontheme");
133
            try {
134
                if( scaleFactor != prefs.getDouble("scaleFactor",1.0) ) {
135
                    return true;
136
                }
137
            } catch(Throwable th) {
138
            }
139
        }
140
        return changed;
141
    }
142

    
143
    @Override
144
    public void setChangesApplied() {
145
        changed = false;
146
    }
147

    
148
    private void initialize() {
149
        final IconThemeManager iconManager = ToolsSwingLocator.getIconThemeManager();
150
        this.setLayout(new BorderLayout());
151

    
152
        this.panel = new IconThemePageLayout();
153

    
154
        DefaultComboBoxModel<ListElement<IconTheme>> model = new DefaultComboBoxModel<>();
155
        for (int i = 0; i < iconManager.getCount(); i++) {
156
            IconTheme iconTheme = iconManager.get(i);
157
            model.addElement(new ListElement<>(
158
                    StringUtils.abbreviate(iconTheme.toString(), 60),
159
                    iconTheme
160
                )
161
            );
162
        }
163
        this.panel.combo_selection.setModel(model);
164

    
165
        Preferences prefs = Preferences.userRoot().node("gvsig.icontheme");
166
        double scaleFactor;
167
        try {
168
            scaleFactor = prefs.getDouble("scaleFactor",1.0);
169
        } catch(Throwable th) {
170
            scaleFactor = 1.0;
171
        }
172
        this.panel.txtScaleFactor.setText(String.format("%f", scaleFactor));
173

    
174
        // Traducir las etiquetas del panel
175
        panel.label_title.setText(translate(panel.label_title.getText()));
176
        panel.label_selection.setText(translate(panel.label_selection.getText()));
177

    
178
        this.add(panel, BorderLayout.CENTER);
179
    }
180

    
181
    private String translate(String s) {
182
        return Messages.getText(s);
183
    }
184

    
185
//    private void createDefaultIconTheme() {
186
//        PluginsManager pluginsManager = PluginsLocator.getManager();
187
//        IconThemeManager iconManager = ToolsSwingLocator.getIconThemeManager();
188
//
189
//        File f = new File(pluginsManager.getApplicationHomeFolder(), "icon-theme");
190
//        if (!f.exists()) {
191
//            f.mkdir();
192
//        }
193
//        IconTheme theme = iconManager.getDefault();
194
//        File f2 = new File(f, theme.getID());
195
//        if (!f2.exists()) {
196
//            logger.info("Creating default icon theme in " + f.getAbsolutePath());
197
//            theme.export(f);
198
//        }
199
//    }
200

    
201

    
202
    @Override
203
    public boolean isResizeable() {
204
        return true;
205
    }
206
   
207
}