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