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 @ 43323
History | View | Annotate | Download (5.59 KB)
1 | 40558 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | *
|
||
4 | * Copyright (C) 2007-2013 gvSIG Association.
|
||
5 | *
|
||
6 | 43068 | jjdelcerro | * 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 | 40558 | jjdelcerro | *
|
11 | 43068 | jjdelcerro | * 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 | 40558 | jjdelcerro | *
|
16 | 43068 | jjdelcerro | * 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 | 40558 | jjdelcerro | *
|
20 | 43068 | jjdelcerro | * For any additional information, do not hesitate to contact us at info AT
|
21 | * gvsig.com, or visit our website www.gvsig.com.
|
||
22 | 40558 | jjdelcerro | */
|
23 | 40435 | jjdelcerro | package org.gvsig.coreplugin.preferences.general; |
24 | |||
25 | import java.awt.BorderLayout; |
||
26 | import java.util.prefs.Preferences; |
||
27 | |||
28 | import javax.swing.ComboBoxModel; |
||
29 | import javax.swing.ImageIcon; |
||
30 | import javax.swing.JPanel; |
||
31 | import javax.swing.event.ListDataListener; |
||
32 | |||
33 | 40723 | jldominguez | import org.gvsig.andami.IconThemeHelper; |
34 | 40435 | jjdelcerro | import org.gvsig.andami.preferences.AbstractPreferencePage; |
35 | import org.gvsig.andami.preferences.StoreException; |
||
36 | 40723 | jldominguez | import org.gvsig.i18n.Messages; |
37 | 40435 | jjdelcerro | import org.gvsig.tools.swing.api.ToolsSwingLocator; |
38 | import org.gvsig.tools.swing.icontheme.IconTheme; |
||
39 | import org.gvsig.tools.swing.icontheme.IconThemeManager; |
||
40 | import org.slf4j.Logger; |
||
41 | import org.slf4j.LoggerFactory; |
||
42 | |||
43 | public class IconThemePage extends AbstractPreferencePage { |
||
44 | |||
45 | 43068 | jjdelcerro | /**
|
46 | *
|
||
47 | */
|
||
48 | private static final long serialVersionUID = 4369071892027860769L; |
||
49 | 40435 | jjdelcerro | |
50 | 43068 | jjdelcerro | private static final Logger logger = LoggerFactory.getLogger(IconThemePage.class); |
51 | 40435 | jjdelcerro | |
52 | 43068 | jjdelcerro | private final String id; |
53 | private boolean changed = false; |
||
54 | private IconThemePageLayout panel = null; |
||
55 | private ImageIcon icon = null; |
||
56 | 40435 | jjdelcerro | |
57 | 43068 | jjdelcerro | public IconThemePage() {
|
58 | super();
|
||
59 | initialize(); |
||
60 | id = this.getClass().getName();
|
||
61 | setParentID(GeneralPage.class.getName()); |
||
62 | } |
||
63 | 40435 | jjdelcerro | |
64 | 43068 | jjdelcerro | @Override
|
65 | public String getID() { |
||
66 | return id;
|
||
67 | } |
||
68 | 40435 | jjdelcerro | |
69 | 43068 | jjdelcerro | @Override
|
70 | public String getTitle() { |
||
71 | return Messages.getText("_Icon_theme"); |
||
72 | } |
||
73 | 40435 | jjdelcerro | |
74 | 43068 | jjdelcerro | @Override
|
75 | public JPanel getPanel() { |
||
76 | return this; |
||
77 | } |
||
78 | 40435 | jjdelcerro | |
79 | 43068 | jjdelcerro | @Override
|
80 | public void initializeValues() { |
||
81 | 43323 | jjdelcerro | final IconThemeManager iconManager = ToolsSwingLocator.getIconThemeManager();
|
82 | Preferences prefs = Preferences.userRoot().node("gvsig.icontheme"); |
||
83 | String themeId = prefs.get("default-theme",null); |
||
84 | panel.combo_selection.setSelectedItem(iconManager.get(themeId)); |
||
85 | 43068 | jjdelcerro | } |
86 | 40435 | jjdelcerro | |
87 | 43068 | jjdelcerro | @Override
|
88 | public void storeValues() throws StoreException { |
||
89 | IconTheme iconTheme = (IconTheme) panel.combo_selection.getSelectedItem(); |
||
90 | if (iconTheme != null && iconTheme != iconTheme.getDefault()) { |
||
91 | Preferences prefs = Preferences.userRoot().node("gvsig.icontheme"); |
||
92 | prefs.put("default-theme", iconTheme.getID());
|
||
93 | } |
||
94 | } |
||
95 | 40435 | jjdelcerro | |
96 | 43068 | jjdelcerro | @Override
|
97 | public void initializeDefaults() { |
||
98 | 40435 | jjdelcerro | |
99 | 43068 | jjdelcerro | } |
100 | 40435 | jjdelcerro | |
101 | 43068 | jjdelcerro | @Override
|
102 | public ImageIcon getIcon() { |
||
103 | if (icon == null) { |
||
104 | icon = IconThemeHelper.getImageIcon("edit-setup-icontheme");
|
||
105 | } |
||
106 | return icon;
|
||
107 | } |
||
108 | 40435 | jjdelcerro | |
109 | 43068 | jjdelcerro | @Override
|
110 | public boolean isValueChanged() { |
||
111 | if (panel.combo_selection.getSelectedIndex() >= 0) { |
||
112 | return true; |
||
113 | } |
||
114 | return changed;
|
||
115 | } |
||
116 | 40435 | jjdelcerro | |
117 | 43068 | jjdelcerro | @Override
|
118 | public void setChangesApplied() { |
||
119 | changed = false;
|
||
120 | } |
||
121 | 40435 | jjdelcerro | |
122 | 43068 | jjdelcerro | private void initialize() { |
123 | final IconThemeManager iconManager = ToolsSwingLocator.getIconThemeManager();
|
||
124 | this.setLayout(new BorderLayout()); |
||
125 | 40435 | jjdelcerro | |
126 | 43068 | jjdelcerro | this.panel = new IconThemePageLayout(); |
127 | |||
128 | panel.combo_selection.setModel(new ComboBoxModel() { |
||
129 | IconTheme selected = null;
|
||
130 | |||
131 | @Override
|
||
132 | public void removeListDataListener(ListDataListener arg0) { |
||
133 | // Do nothing
|
||
134 | } |
||
135 | |||
136 | @Override
|
||
137 | public int getSize() { |
||
138 | return iconManager.getCount();
|
||
139 | } |
||
140 | |||
141 | @Override
|
||
142 | public Object getElementAt(int arg0) { |
||
143 | return iconManager.get(arg0);
|
||
144 | } |
||
145 | |||
146 | @Override
|
||
147 | public void addListDataListener(ListDataListener arg0) { |
||
148 | // Do nothing
|
||
149 | } |
||
150 | |||
151 | @Override
|
||
152 | public void setSelectedItem(Object arg0) { |
||
153 | this.selected = (IconTheme) arg0;
|
||
154 | } |
||
155 | |||
156 | @Override
|
||
157 | public Object getSelectedItem() { |
||
158 | return this.selected; |
||
159 | } |
||
160 | }); |
||
161 | |||
162 | // Traducir las etiquetas del panel
|
||
163 | panel.label_title.setText(translate(panel.label_title.getText())); |
||
164 | panel.label_selection.setText(translate(panel.label_selection.getText())); |
||
165 | |||
166 | this.add(panel, BorderLayout.CENTER); |
||
167 | } |
||
168 | |||
169 | private String translate(String s) { |
||
170 | return Messages.getText(s);
|
||
171 | } |
||
172 | |||
173 | // private void createDefaultIconTheme() {
|
||
174 | // PluginsManager pluginsManager = PluginsLocator.getManager();
|
||
175 | // IconThemeManager iconManager = ToolsSwingLocator.getIconThemeManager();
|
||
176 | //
|
||
177 | // File f = new File(pluginsManager.getApplicationHomeFolder(), "icon-theme");
|
||
178 | // if (!f.exists()) {
|
||
179 | // f.mkdir();
|
||
180 | // }
|
||
181 | // IconTheme theme = iconManager.getDefault();
|
||
182 | // File f2 = new File(f, theme.getID());
|
||
183 | // if (!f2.exists()) {
|
||
184 | // logger.info("Creating default icon theme in " + f.getAbsolutePath());
|
||
185 | // theme.export(f);
|
||
186 | // }
|
||
187 | // }
|
||
188 | } |