Revision 1845
org.gvsig.tools/library/trunk/org.gvsig.tools/org.gvsig.tools.swing/org.gvsig.tools.swing.impl/src/main/java/org/gvsig/tools/swing/impl/icontheme/BaseIconTheme.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.tools.swing.impl.icontheme; |
25 | 25 |
|
26 |
|
|
27 | 26 |
import java.awt.Image; |
28 | 27 |
import java.io.File; |
29 | 28 |
import java.io.IOException; |
... | ... | |
47 | 46 |
|
48 | 47 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
49 | 48 |
|
50 |
|
|
51 | 49 |
/** |
52 |
* <p>This class represents an icon theme, which is basically a mapping of
|
|
53 |
* symbolic icon names, and real icons (or icon paths). This is useful to
|
|
54 |
* change an application's icons in an easy way. An icon theme
|
|
55 |
* is usually read from disk on start up, but can also be created or
|
|
56 |
* modified on a later time.</p> |
|
50 |
* <p> |
|
51 |
* This class represents an icon theme, which is basically a mapping of symbolic
|
|
52 |
* icon names, and real icons (or icon paths). This is useful to change an
|
|
53 |
* application's icons in an easy way. An icon theme is usually read from disk
|
|
54 |
* on start up, but can also be created or modified on a later time.</p>
|
|
57 | 55 |
* |
58 | 56 |
*/ |
59 | 57 |
public class BaseIconTheme implements IconTheme { |
60 |
protected static Logger logger = LoggerFactory.getLogger(BaseIconTheme.class); |
|
61 | 58 |
|
62 |
protected String id = null; |
|
63 |
protected String name=null; |
|
64 |
protected String description=null; |
|
65 |
protected Map<String, Icon> iconList = null; |
|
66 |
protected IconTheme defaultTheme = null; |
|
67 |
protected String defaultIconName = null; |
|
59 |
protected static Logger logger = LoggerFactory.getLogger(BaseIconTheme.class); |
|
68 | 60 |
|
69 |
class DefaultIcon implements Icon { |
|
70 |
private ImageIcon image; |
|
71 |
private final URL resource; |
|
72 |
private final String name; |
|
73 |
private final String group; |
|
74 |
private final String provider; |
|
75 |
|
|
76 |
DefaultIcon(String provider, String group, String name, ImageIcon image,URL resource) { |
|
77 |
this.image = image; |
|
78 |
this.resource = resource; |
|
79 |
this.group = group; |
|
80 |
this.name = name; |
|
81 |
this.provider = provider; |
|
82 |
} |
|
83 |
|
|
84 |
public boolean existsIcon() { |
|
85 |
if (image != null) { |
|
86 |
return true; |
|
87 |
} |
|
88 |
|
|
89 |
InputStream ist = null; |
|
90 |
boolean resp; |
|
91 |
|
|
92 |
try { |
|
93 |
ist = resource.openStream(); |
|
94 |
resp = true; |
|
95 |
} catch (Exception ex) { |
|
96 |
resp = false; |
|
97 |
} |
|
61 |
protected String id = null; |
|
62 |
protected String name = null; |
|
63 |
protected String description = null; |
|
64 |
protected Map<String, Icon> iconList = null; |
|
65 |
protected IconTheme defaultTheme = null; |
|
66 |
protected String defaultIconName = null; |
|
67 |
|
|
68 |
class DefaultIcon implements Icon { |
|
69 |
|
|
70 |
private ImageIcon image; |
|
71 |
private final URL resource; |
|
72 |
private final String name; |
|
73 |
private final String group; |
|
74 |
private final String provider; |
|
75 |
|
|
76 |
DefaultIcon(String provider, String group, String name, ImageIcon image, URL resource) { |
|
77 |
this.image = image; |
|
78 |
this.resource = resource; |
|
79 |
this.group = group; |
|
80 |
this.name = name; |
|
81 |
this.provider = provider; |
|
82 |
} |
|
83 |
|
|
84 |
public boolean existsIcon() { |
|
85 |
if (image != null) { |
|
86 |
return true; |
|
87 |
} |
|
88 |
|
|
89 |
InputStream ist = null; |
|
90 |
boolean resp; |
|
91 |
|
|
98 | 92 |
try { |
99 |
if( ist!=null ) { |
|
93 |
ist = resource.openStream(); |
|
94 |
resp = true; |
|
95 |
} catch (Exception ex) { |
|
96 |
resp = false; |
|
97 |
} |
|
98 |
try { |
|
99 |
if (ist != null) { |
|
100 | 100 |
ist.close(); |
101 | 101 |
} |
102 | 102 |
} catch (Exception ex) { |
103 | 103 |
} |
104 |
return resp;
|
|
105 |
}
|
|
106 |
|
|
104 |
return resp;
|
|
105 |
}
|
|
106 |
|
|
107 | 107 |
@Override |
108 |
public ImageIcon getImageIcon() {
|
|
109 |
if (this.image != null){
|
|
110 |
return this.image;
|
|
111 |
}
|
|
112 |
try {
|
|
113 |
this.image = new ImageIcon((URL)this.resource);
|
|
114 |
} catch(Exception ex) {
|
|
115 |
return null;
|
|
116 |
}
|
|
117 |
return this.image;
|
|
118 |
}
|
|
119 |
|
|
108 |
public ImageIcon getImageIcon() {
|
|
109 |
if (this.image != null) {
|
|
110 |
return this.image;
|
|
111 |
}
|
|
112 |
try {
|
|
113 |
this.image = new ImageIcon((URL) this.resource);
|
|
114 |
} catch (Exception ex) {
|
|
115 |
return null;
|
|
116 |
}
|
|
117 |
return this.image;
|
|
118 |
}
|
|
119 |
|
|
120 | 120 |
@Override |
121 |
public Image getImage() {
|
|
122 |
ImageIcon icon = this.getImageIcon();
|
|
123 |
if( icon == null ) {
|
|
124 |
return null;
|
|
125 |
}
|
|
126 |
return icon.getImage();
|
|
127 |
}
|
|
128 |
|
|
121 |
public Image getImage() {
|
|
122 |
ImageIcon icon = this.getImageIcon();
|
|
123 |
if (icon == null) {
|
|
124 |
return null;
|
|
125 |
}
|
|
126 |
return icon.getImage();
|
|
127 |
}
|
|
128 |
|
|
129 | 129 |
@Override |
130 |
public String getName() {
|
|
131 |
return name;
|
|
132 |
}
|
|
133 |
|
|
130 |
public String getName() {
|
|
131 |
return name;
|
|
132 |
}
|
|
133 |
|
|
134 | 134 |
@Override |
135 |
public String getGroup() {
|
|
136 |
return group;
|
|
137 |
}
|
|
138 |
|
|
135 |
public String getGroup() {
|
|
136 |
return group;
|
|
137 |
}
|
|
138 |
|
|
139 | 139 |
@Override |
140 |
public Object getResource() {
|
|
141 |
return resource;
|
|
142 |
}
|
|
140 |
public Object getResource() {
|
|
141 |
return resource;
|
|
142 |
}
|
|
143 | 143 |
|
144 | 144 |
@Override |
145 |
public URL getURL() {
|
|
146 |
if( resource instanceof URL ) {
|
|
147 |
return (URL) this.resource;
|
|
148 |
}
|
|
149 |
return null;
|
|
150 |
}
|
|
145 |
public URL getURL() {
|
|
146 |
if (resource instanceof URL) {
|
|
147 |
return (URL) this.resource;
|
|
148 |
}
|
|
149 |
return null;
|
|
150 |
}
|
|
151 | 151 |
|
152 | 152 |
@Override |
153 |
public String getLabel() {
|
|
154 |
if( resource != null ) {
|
|
155 |
return resource.toString();
|
|
156 |
}
|
|
157 |
if( image != null ) {
|
|
158 |
return image.toString();
|
|
159 |
}
|
|
160 |
return "";
|
|
161 |
}
|
|
162 |
|
|
153 |
public String getLabel() {
|
|
154 |
if (resource != null) {
|
|
155 |
return resource.toString();
|
|
156 |
}
|
|
157 |
if (image != null) {
|
|
158 |
return image.toString();
|
|
159 |
}
|
|
160 |
return "";
|
|
161 |
}
|
|
162 |
|
|
163 | 163 |
@Override |
164 |
public int compareTo(Icon other) {
|
|
165 |
String this_id = this.getProviderName() + "/" + this.getGroup() + "/" + this.getName();
|
|
166 |
String other_id = other.getProviderName() + "/" + other.getGroup() + "/" + other.getName();
|
|
167 |
return this_id.compareTo(other_id);
|
|
168 |
}
|
|
164 |
public int compareTo(Icon other) {
|
|
165 |
String this_id = this.getProviderName() + "/" + this.getGroup() + "/" + this.getName();
|
|
166 |
String other_id = other.getProviderName() + "/" + other.getGroup() + "/" + other.getName();
|
|
167 |
return this_id.compareTo(other_id);
|
|
168 |
}
|
|
169 | 169 |
|
170 | 170 |
@Override |
171 |
public String getProviderName() {
|
|
172 |
return provider;
|
|
173 |
}
|
|
171 |
public String getProviderName() {
|
|
172 |
return provider;
|
|
173 |
}
|
|
174 | 174 |
|
175 |
} |
|
176 |
|
|
177 |
public BaseIconTheme() { |
|
178 |
this(null); |
|
179 |
} |
|
180 |
|
|
181 |
public BaseIconTheme(IconTheme defaultIconTheme) { |
|
182 |
this.setDefault(defaultIconTheme); |
|
183 |
this.id = "default"; // El id no traducirlo |
|
184 |
this.name = "default"; |
|
185 |
this.description = "Default icon theme"; |
|
186 |
this.iconList = new HashMap<>(); |
|
187 |
} |
|
188 |
|
|
189 |
/** |
|
190 |
* Load the icons of the theme |
|
175 |
} |
|
176 |
|
|
177 |
public BaseIconTheme() { |
|
178 |
this(null); |
|
179 |
} |
|
180 |
|
|
181 |
public BaseIconTheme(IconTheme defaultIconTheme) { |
|
182 |
this.setDefault(defaultIconTheme); |
|
183 |
this.id = "default"; // El id no traducirlo |
|
184 |
this.name = "default"; |
|
185 |
this.description = "Default icon theme"; |
|
186 |
this.iconList = new HashMap<>(); |
|
187 |
} |
|
188 |
|
|
189 |
/** |
|
190 |
* Load the icons of the theme |
|
191 |
* |
|
191 | 192 |
* @param resource |
192 |
*/
|
|
193 |
*/
|
|
193 | 194 |
@Override |
194 |
public void load(Object resource) { |
|
195 |
// Do nothing. |
|
196 |
} |
|
197 |
|
|
198 |
/** |
|
199 |
* Override this to load icons on demand instead of |
|
200 |
* load on the creation of the theme. |
|
201 |
*/ |
|
202 |
protected void deferredLoad() { |
|
203 |
// Do nothing |
|
204 |
} |
|
205 |
|
|
195 |
public void load(Object resource) { |
|
196 |
// Do nothing. |
|
197 |
} |
|
206 | 198 |
|
207 |
|
|
208 |
private void logstack(String msg) { |
|
209 |
try { |
|
210 |
throw new IllegalArgumentException(); |
|
211 |
} catch (IllegalArgumentException e) { |
|
212 |
logger.debug(msg,e); |
|
213 |
} |
|
214 |
} |
|
199 |
/** |
|
200 |
* Override this to load icons on demand instead of load on the creation of |
|
201 |
* the theme. |
|
202 |
*/ |
|
203 |
protected void deferredLoad() { |
|
204 |
// Do nothing |
|
205 |
} |
|
215 | 206 |
|
207 |
private void logstack(String msg) { |
|
208 |
try { |
|
209 |
throw new IllegalArgumentException(); |
|
210 |
} catch (IllegalArgumentException e) { |
|
211 |
logger.debug(msg, e); |
|
212 |
} |
|
213 |
} |
|
214 |
|
|
216 | 215 |
@Override |
217 |
public void setDefault(IconTheme def){
|
|
218 |
if( def == this ) {
|
|
219 |
defaultTheme = null;
|
|
220 |
} else {
|
|
221 |
defaultTheme = def;
|
|
222 |
}
|
|
216 |
public void setDefault(IconTheme def) {
|
|
217 |
if (def == this) {
|
|
218 |
defaultTheme = null;
|
|
219 |
} else {
|
|
220 |
defaultTheme = def;
|
|
221 |
}
|
|
223 | 222 |
} |
224 | 223 |
|
225 | 224 |
@Override |
226 |
public IconTheme getDefault(){ |
|
227 |
return defaultTheme;
|
|
225 |
public IconTheme getDefault() {
|
|
226 |
return defaultTheme;
|
|
228 | 227 |
} |
229 | 228 |
|
230 | 229 |
@Override |
231 |
public boolean exists(String iconName) { |
|
232 |
if( StringUtils.isEmpty(iconName) ) { |
|
233 |
return false; |
|
234 |
} |
|
235 |
deferredLoad(); |
|
236 |
|
|
237 |
if (iconList.containsKey(iconName)) { |
|
238 |
return true; |
|
239 |
} |
|
240 |
return defaultTheme !=null && defaultTheme.exists(iconName); |
|
241 |
} |
|
230 |
public boolean exists(String iconName) { |
|
231 |
if (StringUtils.isEmpty(iconName)) { |
|
232 |
return false; |
|
233 |
} |
|
234 |
deferredLoad(); |
|
242 | 235 |
|
236 |
if (iconList.containsKey(iconName)) { |
|
237 |
return true; |
|
238 |
} |
|
239 |
return defaultTheme != null && defaultTheme.exists(iconName); |
|
240 |
} |
|
241 |
|
|
243 | 242 |
@Override |
244 |
public Iterator<String> iterator() { |
|
245 |
Set<String> names = new HashSet<>(); |
|
246 |
|
|
247 |
deferredLoad(); |
|
243 |
public Iterator<String> iterator() { |
|
244 |
Set<String> names = new HashSet<>(); |
|
248 | 245 |
|
249 |
if( defaultTheme !=null ) { |
|
250 |
Iterator<String> it = defaultTheme.iterator(); |
|
251 |
while( it.hasNext() ) { |
|
252 |
names.add(it.next()); |
|
253 |
} |
|
254 |
} |
|
255 |
Iterator<String> it = iconList.keySet().iterator(); |
|
256 |
while( it.hasNext() ) { |
|
257 |
names.add(it.next()); |
|
258 |
} |
|
259 |
List<String> names2 = new ArrayList<>(names); |
|
260 |
Collections.sort(names2); |
|
261 |
return names2.iterator(); |
|
262 |
} |
|
263 |
|
|
246 |
deferredLoad(); |
|
247 |
|
|
248 |
if (defaultTheme != null) { |
|
249 |
Iterator<String> it = defaultTheme.iterator(); |
|
250 |
while (it.hasNext()) { |
|
251 |
names.add(it.next()); |
|
252 |
} |
|
253 |
} |
|
254 |
Iterator<String> it = iconList.keySet().iterator(); |
|
255 |
while (it.hasNext()) { |
|
256 |
names.add(it.next()); |
|
257 |
} |
|
258 |
List<String> names2 = new ArrayList<>(names); |
|
259 |
Collections.sort(names2); |
|
260 |
return names2.iterator(); |
|
261 |
} |
|
262 |
|
|
264 | 263 |
@Override |
265 |
public Iterator<Icon> getThemeIcons() {
|
|
266 |
Map<String,Icon> themeIcons = new HashMap<>(); |
|
267 |
|
|
268 |
deferredLoad();
|
|
269 |
if( defaultTheme !=null ) {
|
|
270 |
Iterator<Icon> it = defaultTheme.getThemeIcons();
|
|
271 |
while( it.hasNext() ) {
|
|
264 |
public Iterator<Icon> getThemeIcons() {
|
|
265 |
Map<String, Icon> themeIcons = new HashMap<>();
|
|
266 |
|
|
267 |
deferredLoad();
|
|
268 |
if (defaultTheme != null) {
|
|
269 |
Iterator<Icon> it = defaultTheme.getThemeIcons();
|
|
270 |
while (it.hasNext()) {
|
|
272 | 271 |
Icon icon = it.next(); |
273 | 272 |
themeIcons.put(icon.getName(), icon); |
274 |
}
|
|
275 |
}
|
|
276 |
Iterator<Icon> it = iconList.values().iterator();
|
|
277 |
while( it.hasNext() ) {
|
|
273 |
}
|
|
274 |
}
|
|
275 |
Iterator<Icon> it = iconList.values().iterator();
|
|
276 |
while (it.hasNext()) {
|
|
278 | 277 |
Icon icon = it.next(); |
279 | 278 |
themeIcons.put(icon.getName(), icon); |
280 |
}
|
|
281 |
List<Icon> themeIcons2 = new ArrayList<>(themeIcons.values());
|
|
282 |
Collections.sort(themeIcons2);
|
|
283 |
return themeIcons2.iterator();
|
|
284 |
}
|
|
285 |
|
|
279 |
}
|
|
280 |
List<Icon> themeIcons2 = new ArrayList<>(themeIcons.values());
|
|
281 |
Collections.sort(themeIcons2);
|
|
282 |
return themeIcons2.iterator();
|
|
283 |
}
|
|
284 |
|
|
286 | 285 |
@Override |
287 |
public Icon getThemeIcon(String name) {
|
|
288 |
if( StringUtils.isEmpty(name) ) {
|
|
289 |
return null;
|
|
290 |
}
|
|
291 |
deferredLoad();
|
|
292 |
Icon themeIcon = (Icon) iconList.get(name);
|
|
293 |
if( themeIcon!=null ) {
|
|
294 |
return themeIcon;
|
|
295 |
}
|
|
296 |
if( defaultTheme!=null && defaultTheme.exists(name)) {
|
|
297 |
return defaultTheme.getThemeIcon(name);
|
|
298 |
}
|
|
299 |
return null;
|
|
300 |
}
|
|
286 |
public Icon getThemeIcon(String name) {
|
|
287 |
if (StringUtils.isEmpty(name)) {
|
|
288 |
return null;
|
|
289 |
}
|
|
290 |
deferredLoad();
|
|
291 |
Icon themeIcon = (Icon) iconList.get(name);
|
|
292 |
if (themeIcon != null) {
|
|
293 |
return themeIcon;
|
|
294 |
}
|
|
295 |
if (defaultTheme != null && defaultTheme.exists(name)) {
|
|
296 |
return defaultTheme.getThemeIcon(name);
|
|
297 |
}
|
|
298 |
return null;
|
|
299 |
}
|
|
301 | 300 |
|
302 | 301 |
@Override |
303 |
public ImageIcon get(String name) { |
|
304 |
ImageIcon icon; |
|
305 |
|
|
306 |
if( ! StringUtils.isEmpty(name) ) { |
|
307 |
deferredLoad(); |
|
308 |
Icon themeIcon = (Icon) iconList.get(name); |
|
309 |
if( themeIcon != null ) { |
|
310 |
icon = themeIcon.getImageIcon(); |
|
311 |
if( icon != null ) { |
|
312 |
return icon; |
|
313 |
} |
|
314 |
} |
|
315 |
if( defaultTheme!=null && defaultTheme.exists(name)) { |
|
316 |
return defaultTheme.get(name); |
|
317 |
} |
|
318 |
} |
|
319 |
logger.info("get('"+name+"') icon not found"); |
|
320 |
logstack("get('"+name+"') icon not found"); |
|
321 |
return getNoIcon(); |
|
322 |
} |
|
302 |
public ImageIcon get(String name) { |
|
303 |
ImageIcon icon; |
|
323 | 304 |
|
305 |
if (!StringUtils.isEmpty(name)) { |
|
306 |
deferredLoad(); |
|
307 |
Icon themeIcon = (Icon) iconList.get(name); |
|
308 |
if (themeIcon != null) { |
|
309 |
icon = themeIcon.getImageIcon(); |
|
310 |
if (icon != null) { |
|
311 |
return icon; |
|
312 |
} |
|
313 |
} |
|
314 |
if (defaultTheme != null && defaultTheme.exists(name)) { |
|
315 |
return defaultTheme.get(name); |
|
316 |
} |
|
317 |
} |
|
318 |
logger.info("get('" + name + "') icon not found"); |
|
319 |
logstack("get('" + name + "') icon not found"); |
|
320 |
return getNoIcon(); |
|
321 |
} |
|
324 | 322 |
|
325 | 323 |
@Override |
326 |
public String getName() {
|
|
327 |
return name;
|
|
328 |
}
|
|
324 |
public String getName() {
|
|
325 |
return name;
|
|
326 |
}
|
|
329 | 327 |
|
330 | 328 |
@Override |
331 |
public void setName(String themeName) {
|
|
332 |
name = themeName;
|
|
333 |
}
|
|
329 |
public void setName(String themeName) {
|
|
330 |
name = themeName;
|
|
331 |
}
|
|
334 | 332 |
|
335 | 333 |
@Override |
336 |
public String getID() {
|
|
337 |
return this.id;
|
|
338 |
}
|
|
339 |
|
|
334 |
public String getID() {
|
|
335 |
return this.id;
|
|
336 |
}
|
|
337 |
|
|
340 | 338 |
@Override |
341 |
public void setID(String id) {
|
|
342 |
this.id = id;
|
|
343 |
}
|
|
344 |
|
|
339 |
public void setID(String id) {
|
|
340 |
this.id = id;
|
|
341 |
}
|
|
342 |
|
|
345 | 343 |
@Override |
346 |
public String getDescription() {
|
|
347 |
return description;
|
|
348 |
}
|
|
344 |
public String getDescription() {
|
|
345 |
return description;
|
|
346 |
}
|
|
349 | 347 |
|
350 | 348 |
@Override |
351 |
public void setDescription(String description) {
|
|
352 |
this.description = description;
|
|
353 |
}
|
|
349 |
public void setDescription(String description) {
|
|
350 |
this.description = description;
|
|
351 |
}
|
|
354 | 352 |
|
355 |
/**
|
|
356 |
* Returns the name of the icon theme
|
|
357 |
*/
|
|
353 |
/**
|
|
354 |
* Returns the name of the icon theme
|
|
355 |
*/
|
|
358 | 356 |
@Override |
359 |
public String toString() {
|
|
360 |
String s = this.getName();
|
|
361 |
if( StringUtils.isEmpty(s) ) {
|
|
362 |
s = this.getID();
|
|
363 |
}
|
|
364 |
return s;
|
|
357 |
public String toString() {
|
|
358 |
String s = this.getName();
|
|
359 |
if (StringUtils.isEmpty(s)) {
|
|
360 |
s = this.getID();
|
|
361 |
}
|
|
362 |
return s; |
|
365 | 363 |
// if( StringUtils.isEmpty(this.getDescription()) ) { |
366 | 364 |
// return s; |
367 | 365 |
// } |
368 | 366 |
// return s + " - " + this.getDescription(); |
369 |
}
|
|
367 |
}
|
|
370 | 368 |
|
371 | 369 |
@Override |
372 |
public ImageIcon getDefaultIcon() { |
|
373 |
ImageIcon imageIcon; |
|
374 |
Icon icon; |
|
375 |
|
|
376 |
icon = this.getThemeIcon(defaultIconName); |
|
377 |
if( icon != null ) { |
|
378 |
imageIcon = icon.getImageIcon(); |
|
379 |
if( imageIcon != null ) { |
|
380 |
return imageIcon; |
|
381 |
} |
|
382 |
} |
|
383 |
icon = this.getThemeIcon(NO_ICON_NAME); |
|
384 |
if( icon != null ) { |
|
385 |
imageIcon = icon.getImageIcon(); |
|
386 |
if( imageIcon != null ) { |
|
387 |
return imageIcon; |
|
388 |
} |
|
389 |
} |
|
390 |
return new ImageIcon(); |
|
391 |
} |
|
370 |
public ImageIcon getDefaultIcon() { |
|
371 |
ImageIcon imageIcon; |
|
372 |
Icon icon; |
|
392 | 373 |
|
374 |
icon = this.getThemeIcon(defaultIconName); |
|
375 |
if (icon != null) { |
|
376 |
imageIcon = icon.getImageIcon(); |
|
377 |
if (imageIcon != null) { |
|
378 |
return imageIcon; |
|
379 |
} |
|
380 |
} |
|
381 |
icon = this.getThemeIcon(NO_ICON_NAME); |
|
382 |
if (icon != null) { |
|
383 |
imageIcon = icon.getImageIcon(); |
|
384 |
if (imageIcon != null) { |
|
385 |
return imageIcon; |
|
386 |
} |
|
387 |
} |
|
388 |
return new ImageIcon(); |
|
389 |
} |
|
390 |
|
|
393 | 391 |
@Override |
394 |
public void setDefaultIcon(ImageIcon icon) {
|
|
395 |
this.defaultIconName = null;
|
|
396 |
this.register(null, null, NO_ICON_NAME, icon, null);
|
|
397 |
}
|
|
392 |
public void setDefaultIcon(ImageIcon icon) {
|
|
393 |
this.defaultIconName = null;
|
|
394 |
this.register(null, null, NO_ICON_NAME, icon, null);
|
|
395 |
}
|
|
398 | 396 |
|
399 | 397 |
@Override |
400 |
public void setDefaultIcon(URL resource) {
|
|
401 |
this.defaultIconName = null;
|
|
402 |
this.register(null, null, NO_ICON_NAME, null, resource);
|
|
403 |
}
|
|
404 |
|
|
398 |
public void setDefaultIcon(URL resource) {
|
|
399 |
this.defaultIconName = null;
|
|
400 |
this.register(null, null, NO_ICON_NAME, null, resource);
|
|
401 |
}
|
|
402 |
|
|
405 | 403 |
@Override |
406 |
public void setDefaultIcon(String name) {
|
|
407 |
this.defaultIconName = name;
|
|
408 |
}
|
|
404 |
public void setDefaultIcon(String name) {
|
|
405 |
this.defaultIconName = name;
|
|
406 |
}
|
|
409 | 407 |
|
410 | 408 |
@Override |
411 |
public void register(String provider, String group, String name, |
|
412 |
ImageIcon icon, URL resource) { |
|
413 |
if( StringUtils.isEmpty(name) ) { |
|
414 |
throw new IllegalArgumentException("name is empty"); |
|
415 |
} |
|
416 |
deferredLoad(); |
|
417 |
if( icon == null && resource == null ) { |
|
418 |
Icon themeIcon = new DefaultIcon(provider, group, name, null, null); |
|
419 |
iconList.put(name, themeIcon); |
|
420 |
throw new IllegalArgumentException("icon and resource for '"+getIconIdentifier(provider,group, name)+"' are null"); |
|
421 |
} |
|
422 |
DefaultIcon themeIcon = new DefaultIcon(provider, group, name, icon, resource); |
|
423 |
|
|
424 |
iconList.put(name, themeIcon); |
|
425 |
if (!themeIcon.existsIcon()) { |
|
426 |
throw new IllegalArgumentException("Resource not found for icon '"+getIconIdentifier(provider,group, name) + "'"); |
|
427 |
} |
|
428 |
} |
|
409 |
public void register(String provider, String group, String name, |
|
410 |
ImageIcon icon, URL resource) { |
|
411 |
if (StringUtils.isEmpty(name)) { |
|
412 |
throw new IllegalArgumentException("name is empty"); |
|
413 |
} |
|
414 |
deferredLoad(); |
|
415 |
if (icon == null && resource == null) { |
|
416 |
Icon themeIcon = new DefaultIcon(provider, group, name, null, null); |
|
417 |
iconList.put(name, themeIcon); |
|
418 |
throw new IllegalArgumentException("icon and resource for '" + getIconIdentifier(provider, group, name) + "' are null"); |
|
419 |
} |
|
420 |
DefaultIcon themeIcon = new DefaultIcon(provider, group, name, icon, resource); |
|
429 | 421 |
|
430 |
private String getIconIdentifier(String provider, String group, String name) { |
|
431 |
deferredLoad(); |
|
432 |
String identifier = null; |
|
433 |
if( !StringUtils.isEmpty(provider) ) { |
|
434 |
identifier = provider ; |
|
435 |
} |
|
436 |
if( group!= null ) { |
|
437 |
identifier = identifier + "/" + group; |
|
438 |
} |
|
439 |
if( name == null ) { |
|
440 |
identifier = identifier + "/unknow"; |
|
441 |
} else { |
|
442 |
identifier = identifier + "/" + name; |
|
443 |
} |
|
444 |
return identifier; |
|
445 |
} |
|
422 |
iconList.put(name, themeIcon); |
|
423 |
if (!themeIcon.existsIcon()) { |
|
424 |
throw new IllegalArgumentException("Resource not found for icon '" + getIconIdentifier(provider, group, name) + "'"); |
|
425 |
} |
|
426 |
} |
|
446 | 427 |
|
428 |
private String getIconIdentifier(String provider, String group, String name) { |
|
429 |
deferredLoad(); |
|
430 |
String identifier = null; |
|
431 |
if (!StringUtils.isEmpty(provider)) { |
|
432 |
identifier = provider; |
|
433 |
} |
|
434 |
if (group != null) { |
|
435 |
identifier = identifier + "/" + group; |
|
436 |
} |
|
437 |
if (name == null) { |
|
438 |
identifier = identifier + "/unknow"; |
|
439 |
} else { |
|
440 |
identifier = identifier + "/" + name; |
|
441 |
} |
|
442 |
return identifier; |
|
443 |
} |
|
444 |
|
|
447 | 445 |
@Override |
448 |
public void registerDefault(String provider, String group,
|
|
449 |
String name, ImageIcon icon, URL resource) {
|
|
450 |
deferredLoad();
|
|
451 |
if (defaultTheme!=null){
|
|
452 |
if( !defaultTheme.exists(name)) {
|
|
453 |
defaultTheme.register(provider, group, name, icon, resource);
|
|
454 |
}
|
|
455 |
} else {
|
|
456 |
this.register(provider, group, name, icon, resource);
|
|
457 |
}
|
|
458 |
}
|
|
446 |
public void registerDefault(String provider, String group,
|
|
447 |
String name, ImageIcon icon, URL resource) {
|
|
448 |
deferredLoad();
|
|
449 |
if (defaultTheme != null) {
|
|
450 |
if (!defaultTheme.exists(name)) {
|
|
451 |
defaultTheme.register(provider, group, name, icon, resource);
|
|
452 |
}
|
|
453 |
} else {
|
|
454 |
this.register(provider, group, name, icon, resource);
|
|
455 |
}
|
|
456 |
}
|
|
459 | 457 |
|
458 |
@Override |
|
459 |
public void export(File folder) { |
|
460 |
if (!folder.exists()) { |
|
461 |
folder.mkdir(); |
|
462 |
} |
|
463 |
folder = new File(folder, this.getID()); |
|
464 |
if (!folder.exists()) { |
|
465 |
folder.mkdir(); |
|
466 |
} |
|
467 |
URL url_no_icon = this.getThemeIcon(NO_ICON_NAME).getURL(); |
|
460 | 468 |
|
469 |
Iterator<Icon> themeIcons = this.getThemeIcons(); |
|
470 |
while (themeIcons.hasNext()) { |
|
471 |
Icon themeIcon = themeIcons.next(); |
|
472 |
URL url_src = themeIcon.getURL(); |
|
473 |
if (url_src == null) { |
|
474 |
url_src = url_no_icon; |
|
475 |
} |
|
476 |
File target; |
|
477 |
if (themeIcon.getGroup() != null) { |
|
478 |
target = new File(folder, themeIcon.getGroup()); |
|
479 |
target.mkdir(); |
|
480 |
} else { |
|
481 |
target = new File(folder.getAbsolutePath()); |
|
482 |
} |
|
483 |
target = new File(target, themeIcon.getName() + ".png"); |
|
484 |
try { |
|
485 |
FileUtils.copyURLToFile(url_src, target); |
|
486 |
} catch (IOException e) { |
|
487 |
// TODO |
|
488 |
} |
|
489 |
} |
|
490 |
} |
|
491 |
|
|
492 |
// =================================================================== |
|
493 |
/** |
|
494 |
* @deprecated use getDefaultIcon |
|
495 |
*/ |
|
461 | 496 |
@Override |
462 |
public void export(File folder) { |
|
463 |
if( !folder.exists() ) { |
|
464 |
folder.mkdir(); |
|
465 |
} |
|
466 |
folder = new File(folder, this.getID()); |
|
467 |
if( !folder.exists() ) { |
|
468 |
folder.mkdir(); |
|
469 |
} |
|
470 |
URL url_no_icon = this.getThemeIcon(NO_ICON_NAME).getURL(); |
|
471 |
|
|
472 |
Iterator<Icon> themeIcons = this.getThemeIcons(); |
|
473 |
while (themeIcons.hasNext()) { |
|
474 |
Icon themeIcon = themeIcons.next(); |
|
475 |
URL url_src = themeIcon.getURL(); |
|
476 |
if( url_src == null ) { |
|
477 |
url_src = url_no_icon; |
|
478 |
} |
|
479 |
File target; |
|
480 |
if( themeIcon.getGroup()!=null ) { |
|
481 |
target = new File(folder, themeIcon.getGroup()); |
|
482 |
target.mkdir(); |
|
483 |
} else { |
|
484 |
target = new File(folder.getAbsolutePath()); |
|
485 |
} |
|
486 |
target = new File(target,themeIcon.getName()+".png"); |
|
487 |
try { |
|
488 |
FileUtils.copyURLToFile(url_src,target); |
|
489 |
} catch (IOException e) { |
|
490 |
// TODO |
|
491 |
} |
|
492 |
} |
|
493 |
} |
|
494 |
|
|
495 |
// =================================================================== |
|
496 |
|
|
497 |
/** |
|
498 |
* @deprecated use getDefaultIcon |
|
499 |
*/ |
|
500 |
@Override |
|
501 |
public ImageIcon getNoIcon() { |
|
502 |
return this.getDefaultIcon(); |
|
503 |
} |
|
497 |
public ImageIcon getNoIcon() { |
|
498 |
return this.getDefaultIcon(); |
|
499 |
} |
|
504 | 500 |
|
505 |
|
|
506 |
/** |
|
501 |
/** |
|
507 | 502 |
* @param name |
508 | 503 |
* @param image |
509 |
* @deprecated use {@link #registerDefault(PluginServices, String, String, ImageIcon, Object)} |
|
510 |
*/ |
|
504 |
* @deprecated use |
|
505 |
* {@link #registerDefault(PluginServices, String, String, ImageIcon, Object)} |
|
506 |
*/ |
|
511 | 507 |
@Override |
512 |
public void registerDefault(String name, ImageIcon image) {
|
|
513 |
logstack("registerDefault('"+name+"'), deprecated method.");
|
|
514 |
try {
|
|
515 |
registerDefault(null, null, name, image, null);
|
|
516 |
} catch(IllegalArgumentException e) {
|
|
517 |
logger.info(e.getLocalizedMessage(), e);
|
|
518 |
}
|
|
519 |
}
|
|
508 |
public void registerDefault(String name, ImageIcon image) {
|
|
509 |
logstack("registerDefault('" + name + "'), deprecated method.");
|
|
510 |
try {
|
|
511 |
registerDefault(null, null, name, image, null);
|
|
512 |
} catch (IllegalArgumentException e) {
|
|
513 |
logger.info(e.getLocalizedMessage(), e);
|
|
514 |
}
|
|
515 |
}
|
|
520 | 516 |
|
521 |
/**
|
|
517 |
/**
|
|
522 | 518 |
* @param name |
523 | 519 |
* @param resource |
524 |
* @deprecated use {@link #registerDefault(PluginServices, String, String, ImageIcon, Object)} |
|
525 |
*/ |
|
520 |
* @deprecated use |
|
521 |
* {@link #registerDefault(PluginServices, String, String, ImageIcon, Object)} |
|
522 |
*/ |
|
526 | 523 |
@Override |
527 |
public void registerDefault(String name, Object resource) {
|
|
528 |
logstack("registerDefault('"+name+"'), deprecated method.");
|
|
529 |
try {
|
|
530 |
registerDefault(null, null, name, null, (URL)resource);
|
|
531 |
} catch(IllegalArgumentException e) {
|
|
532 |
logger.info(e.getLocalizedMessage(), e);
|
|
533 |
}
|
|
534 |
}
|
|
524 |
public void registerDefault(String name, Object resource) {
|
|
525 |
logstack("registerDefault('" + name + "'), deprecated method.");
|
|
526 |
try {
|
|
527 |
registerDefault(null, null, name, null, (URL) resource);
|
|
528 |
} catch (IllegalArgumentException e) {
|
|
529 |
logger.info(e.getLocalizedMessage(), e);
|
|
530 |
}
|
|
531 |
}
|
|
535 | 532 |
|
536 |
/**
|
|
533 |
/**
|
|
537 | 534 |
* @param name |
538 | 535 |
* @param image |
539 |
* @deprecated use {@link #registerDefault(PluginServices, String, String, ImageIcon, Object)} |
|
540 |
*/ |
|
536 |
* @deprecated use |
|
537 |
* {@link #registerDefault(PluginServices, String, String, ImageIcon, Object)} |
|
538 |
*/ |
|
541 | 539 |
@Override |
542 |
public void register(String name, ImageIcon image) {
|
|
543 |
logstack("register('"+name+"'), deprecated method.");
|
|
544 |
try {
|
|
545 |
register(null, null, name, image, null);
|
|
546 |
} catch(IllegalArgumentException e) {
|
|
547 |
logger.info(e.getLocalizedMessage(), e);
|
|
548 |
}
|
|
549 |
}
|
|
550 |
|
|
551 |
/**
|
|
540 |
public void register(String name, ImageIcon image) {
|
|
541 |
logstack("register('" + name + "'), deprecated method.");
|
|
542 |
try {
|
|
543 |
register(null, null, name, image, null);
|
|
544 |
} catch (IllegalArgumentException e) {
|
|
545 |
logger.info(e.getLocalizedMessage(), e);
|
|
546 |
}
|
|
547 |
}
|
|
548 |
|
|
549 |
/**
|
|
552 | 550 |
* @param name |
553 | 551 |
* @param resource |
554 |
* @deprecated use {@link #registerDefault(PluginServices, String, String, ImageIcon, Object)} |
|
555 |
*/ |
|
552 |
* @deprecated use |
|
553 |
* {@link #registerDefault(PluginServices, String, String, ImageIcon, Object)} |
|
554 |
*/ |
|
556 | 555 |
@Override |
557 |
public void register(String name, Object resource) {
|
|
558 |
logstack("register('"+name+"'), deprecated method.");
|
|
559 |
try {
|
|
560 |
register(null, null, name, null, (URL)resource);
|
|
561 |
} catch(IllegalArgumentException e) {
|
|
562 |
logger.info(e.getLocalizedMessage(), e);
|
|
563 |
}
|
|
564 |
}
|
|
565 |
|
|
566 |
/**
|
|
556 |
public void register(String name, Object resource) {
|
|
557 |
logstack("register('" + name + "'), deprecated method.");
|
|
558 |
try {
|
|
559 |
register(null, null, name, null, (URL) resource);
|
|
560 |
} catch (IllegalArgumentException e) {
|
|
561 |
logger.info(e.getLocalizedMessage(), e);
|
|
562 |
}
|
|
563 |
}
|
|
564 |
|
|
565 |
/**
|
|
567 | 566 |
* @param iconName |
568 | 567 |
* @param loader |
569 |
* @return
|
|
570 |
* @deprecated use get(String iconName) instead.
|
|
571 |
*/
|
|
568 |
* @return |
|
569 |
* @deprecated use get(String iconName) instead.
|
|
570 |
*/
|
|
572 | 571 |
@Override |
573 |
public ImageIcon get(String iconName, ClassLoader loader) {
|
|
574 |
logstack("get('"+iconName+"', loader), deprecated method.");
|
|
575 |
return this.get(iconName);
|
|
576 |
}
|
|
572 |
public ImageIcon get(String iconName, ClassLoader loader) {
|
|
573 |
logstack("get('" + iconName + "', loader), deprecated method.");
|
|
574 |
return this.get(iconName);
|
|
575 |
}
|
|
577 | 576 |
|
578 | 577 |
} |
Also available in: Unified diff