Revision 15633
trunk/frameworks/_fwAndami/src/com/iver/andami/ui/mdiFrame/MDIFrame.java | ||
---|---|---|
254 | 254 |
PluginServices ps = PluginServices.getPluginServices(loader.getPluginName()); |
255 | 255 |
|
256 | 256 |
JToolBarToggleButton btn; |
257 |
ImageIcon image = PluginServices.getIconTheme().get(selectableTool.getIcon(), loader.getResource(selectableTool.getIcon()));
|
|
257 |
ImageIcon image = PluginServices.getIconTheme().get(selectableTool.getIcon()); |
|
258 | 258 |
|
259 | 259 |
if (image != null) { |
260 | 260 |
btn = new JToolBarToggleButton(selectableTool.getText(), image); |
... | ... | |
343 | 343 |
PluginServices ps = PluginServices.getPluginServices(loader.getPluginName()); |
344 | 344 |
|
345 | 345 |
JToolBarButton btn; |
346 |
ImageIcon image = PluginServices.getIconTheme().get(actionTool.getIcon(), loader.getResource(actionTool.getIcon()));
|
|
346 |
ImageIcon image = PluginServices.getIconTheme().get(actionTool.getIcon()); |
|
347 | 347 |
|
348 | 348 |
if (image != null) { |
349 | 349 |
btn = new JToolBarButton(actionTool.getText(), image); |
... | ... | |
761 | 761 |
String translatedText = ps.getText(text); |
762 | 762 |
|
763 | 763 |
if (menu.getIcon() != null) { |
764 |
ImageIcon image = PluginServices.getIconTheme().get(menu.getIcon(), loader.getResource(menu.getIcon()));
|
|
764 |
ImageIcon image = PluginServices.getIconTheme().get(menu.getIcon()); |
|
765 | 765 |
if (image != null) { |
766 | 766 |
nuevoMenu = new JMenuItem(translatedText, image); |
767 | 767 |
} else { |
trunk/frameworks/_fwAndami/src/com/iver/andami/iconthemes2/IconThemeManager.java | ||
---|---|---|
1 |
package com.iver.andami.iconthemes2; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.FileInputStream; |
|
5 |
import java.io.FileNotFoundException; |
|
6 |
import java.io.IOException; |
|
7 |
import java.io.InputStream; |
|
8 |
import java.util.ArrayList; |
|
9 |
import java.util.Collection; |
|
10 |
import java.util.Enumeration; |
|
11 |
import java.util.Iterator; |
|
12 |
import java.util.zip.ZipEntry; |
|
13 |
import java.util.zip.ZipException; |
|
14 |
import java.util.zip.ZipFile; |
|
15 |
|
|
16 |
import org.kxml2.io.KXmlParser; |
|
17 |
import org.xmlpull.v1.XmlPullParserException; |
|
18 |
|
|
19 |
import com.iver.andami.Launcher; |
|
20 |
import com.iver.andami.PluginServices; |
|
21 |
|
|
22 |
/** |
|
23 |
* This class controls the icon theme. Contains two themes, the first is a default |
|
24 |
* theme and the second is the current theme. When it creates the class the default and |
|
25 |
* the current theme are the same. Allows change the current theme, register a new theme, |
|
26 |
* delete one,... and all the methods that the <code>Collection</code> interface contains. |
|
27 |
* The themes are stored in an ArrayList. |
|
28 |
* |
|
29 |
* @author eustaquio |
|
30 |
*/ |
|
31 |
public class IconThemeManager implements Collection{ |
|
32 |
|
|
33 |
private AbstractIconTheme def; |
|
34 |
private AbstractIconTheme current; |
|
35 |
private File themesDir = null; |
|
36 |
ArrayList<AbstractIconTheme> themes=new ArrayList<AbstractIconTheme>(); |
|
37 |
private final String themeDefinitionFile = "theme.xml"; |
|
38 |
|
|
39 |
|
|
40 |
/** |
|
41 |
* Default constructor. Creates a iconThemeMemory by default and assigns it |
|
42 |
* like default and current. The default theme is add to the themes ArrayList. |
|
43 |
*/ |
|
44 |
public IconThemeManager(){ |
|
45 |
IconThemeMemory aux = new IconThemeMemory(null); |
|
46 |
def = aux; |
|
47 |
def.setName("Default"); |
|
48 |
current = aux; |
|
49 |
themes.add(def); |
|
50 |
|
|
51 |
} |
|
52 |
|
|
53 |
/** |
|
54 |
* Gets the default theme |
|
55 |
* @return the default theme. |
|
56 |
*/ |
|
57 |
public AbstractIconTheme getDefault(){ |
|
58 |
return def; |
|
59 |
} |
|
60 |
|
|
61 |
/** |
|
62 |
* Sets the iconTheme like current theme |
|
63 |
* @param iconTheme |
|
64 |
*/ |
|
65 |
public void setCurrent(AbstractIconTheme iconTheme){ |
|
66 |
if(themes.contains(iconTheme)){ |
|
67 |
current = iconTheme; |
|
68 |
//saveConfig(current); |
|
69 |
}else{ |
|
70 |
register(iconTheme); |
|
71 |
current = iconTheme; |
|
72 |
//saveConfig(current); |
|
73 |
} |
|
74 |
} |
|
75 |
|
|
76 |
/** |
|
77 |
* Gets the current theme |
|
78 |
* @return current the current theme |
|
79 |
*/ |
|
80 |
public AbstractIconTheme getCurrent(){ |
|
81 |
return current; |
|
82 |
} |
|
83 |
|
|
84 |
/** |
|
85 |
* Stores a icon theme that receives like a parametre |
|
86 |
* @param iconTheme |
|
87 |
*/ |
|
88 |
public void register(AbstractIconTheme iconTheme){ |
|
89 |
themes.add(iconTheme); |
|
90 |
iconTheme.setDefault(def); |
|
91 |
} |
|
92 |
|
|
93 |
/** |
|
94 |
* Returns the theme that has been registered with the name that receives like |
|
95 |
* parameter |
|
96 |
* @param themeName |
|
97 |
* @return the theme that contains like name in its properties the parameter |
|
98 |
*/ |
|
99 |
public AbstractIconTheme getTheme(String themeName){ |
|
100 |
for(int i = 0; i<themes.size();i++){ |
|
101 |
if(themes.get(i).getName().equals(themeName)) return themes.get(i); |
|
102 |
} |
|
103 |
return null; |
|
104 |
} |
|
105 |
|
|
106 |
/** |
|
107 |
* Set the directory to read the icon themes. |
|
108 |
* |
|
109 |
* @param themesDir The directory in which the icon themes |
|
110 |
* are stored |
|
111 |
* |
|
112 |
* @throws FileNotFoundException If the provided directory does not |
|
113 |
* exist or is not a directory |
|
114 |
*/ |
|
115 |
public void setThemesDir(File themesDir) throws FileNotFoundException { |
|
116 |
if (!themesDir.exists() || !themesDir.isDirectory()) |
|
117 |
throw new FileNotFoundException(); |
|
118 |
this.themesDir = themesDir; |
|
119 |
} |
|
120 |
|
|
121 |
/** |
|
122 |
* Gets the themes directory |
|
123 |
* @return |
|
124 |
*/ |
|
125 |
public File getThemesDir() { |
|
126 |
return themesDir; |
|
127 |
} |
|
128 |
|
|
129 |
/** |
|
130 |
* |
|
131 |
* Save the provided theme as default in the configuration file. |
|
132 |
* This will not change the default theme for this session, it will |
|
133 |
* just write the new selection in the configuration file (for |
|
134 |
* the next session). |
|
135 |
* |
|
136 |
* @param info The theme to be set as default for next session. |
|
137 |
*/ |
|
138 |
private void saveConfig(AbstractIconTheme info) { |
|
139 |
if (getThemesDir()==null || info==null || info.getResource()==null) |
|
140 |
return; |
|
141 |
com.iver.andami.config.generate.AndamiOptions options = Launcher.getAndamiConfig().getAndamiOptions(); |
|
142 |
if (options==null) { |
|
143 |
options = new com.iver.andami.config.generate.AndamiOptions(); |
|
144 |
Launcher.getAndamiConfig().setAndamiOptions(options); |
|
145 |
} |
|
146 |
com.iver.andami.config.generate.IconTheme themeConfig = options.getIconTheme(); |
|
147 |
if (themeConfig==null) { |
|
148 |
themeConfig = new com.iver.andami.config.generate.IconTheme(); |
|
149 |
options.setIconTheme(themeConfig); |
|
150 |
} |
|
151 |
themeConfig.setBasedir(getThemesDir().getPath()); |
|
152 |
themeConfig.setName(info.getName()); |
|
153 |
themeConfig.setDescription(info.getDescription()); |
|
154 |
themeConfig.setVersion(info.getVersion()); |
|
155 |
if (info.getResource()!=null) { |
|
156 |
if (info.getResource() instanceof File) { |
|
157 |
File resource = (File) info.getResource(); |
|
158 |
themeConfig.setResource(resource.getName()); |
|
159 |
} |
|
160 |
else if (info.getResource() instanceof ZipFile) { |
|
161 |
ZipFile resource = (ZipFile) info.getResource(); |
|
162 |
themeConfig.setResource(resource.getName()); |
|
163 |
} |
|
164 |
} |
|
165 |
} |
|
166 |
|
|
167 |
/** |
|
168 |
* Gets the Icon theme stored in the configuration |
|
169 |
* @return AbstractIconTheme |
|
170 |
*/ |
|
171 |
public AbstractIconTheme readConfig() { |
|
172 |
if (Launcher.getAndamiConfig().getAndamiOptions()==null |
|
173 |
|| Launcher.getAndamiConfig().getAndamiOptions().getIconTheme()==null |
|
174 |
|| Launcher.getAndamiConfig().getAndamiOptions().getIconTheme().getResource()==null) |
|
175 |
return null; |
|
176 |
|
|
177 |
com.iver.andami.config.generate.IconTheme selectedTheme = Launcher.getAndamiConfig().getAndamiOptions().getIconTheme(); |
|
178 |
|
|
179 |
try { |
|
180 |
setThemesDir(new File(selectedTheme.getBasedir())); |
|
181 |
File themeFile = new File(selectedTheme.getBasedir()+File.separator+selectedTheme.getResource()); |
|
182 |
if (themeFile.exists()) { |
|
183 |
AbstractIconTheme info; |
|
184 |
try { |
|
185 |
// try to load a ZIPPED theme |
|
186 |
ZipFile zipfile = new ZipFile(selectedTheme.getResource()); |
|
187 |
info = readInfoFromZip(zipfile); |
|
188 |
return info; |
|
189 |
} catch (ZipException e) { |
|
190 |
// ZIPPED theme failed, try to load from directory |
|
191 |
if (themeFile.isFile() && themeFile.canRead()) { |
|
192 |
info = readInfoFromDir(new File(selectedTheme.getResource())); |
|
193 |
return info; |
|
194 |
} |
|
195 |
} catch (IOException e) {} |
|
196 |
} |
|
197 |
} catch (FileNotFoundException e1) {} |
|
198 |
return null; |
|
199 |
} |
|
200 |
|
|
201 |
/** |
|
202 |
* Gets the base name of a entry |
|
203 |
* @param fullname |
|
204 |
* @return |
|
205 |
*/ |
|
206 |
private String basename(String fullname) { |
|
207 |
String[] parts = fullname.split(File.separator+"|/"); |
|
208 |
return parts[parts.length-1]; |
|
209 |
} |
|
210 |
|
|
211 |
/** |
|
212 |
* Returns an icon theme from a file that receives like a parameter |
|
213 |
* @param zipFile |
|
214 |
* @return |
|
215 |
* @throws ZipException |
|
216 |
* @throws IOException |
|
217 |
*/ |
|
218 |
private IconThemeZip readInfoFromZip(File zipFile) throws ZipException, IOException { |
|
219 |
return readInfoFromZip(new ZipFile(zipFile)); |
|
220 |
} |
|
221 |
|
|
222 |
/** |
|
223 |
* Returns an icon theme from a zip file that receives like a parameter |
|
224 |
* @param zipFile |
|
225 |
* @return IconThemeZip |
|
226 |
* @throws IOException |
|
227 |
*/ |
|
228 |
private IconThemeZip readInfoFromZip(ZipFile zipFile) throws IOException { |
|
229 |
IconThemeZip themeInfo; |
|
230 |
Enumeration entries = zipFile.entries(); |
|
231 |
ZipEntry xmlEntry=null, dirEntry=null; |
|
232 |
// search for theme.xml and the directory names |
|
233 |
while (entries.hasMoreElements() && (xmlEntry==null||dirEntry==null)) { |
|
234 |
ZipEntry entry = (ZipEntry) entries.nextElement(); |
|
235 |
if (entry.isDirectory()) { |
|
236 |
dirEntry = entry; |
|
237 |
} |
|
238 |
if (basename(entry.getName()).equals(themeDefinitionFile)) { |
|
239 |
xmlEntry = entry; |
|
240 |
} |
|
241 |
} |
|
242 |
|
|
243 |
try { |
|
244 |
// try with the XML file |
|
245 |
if (xmlEntry!=null) { |
|
246 |
themeInfo = readXML(zipFile.getInputStream(xmlEntry)); |
|
247 |
if (themeInfo.getDescription()==null) |
|
248 |
themeInfo.setDescription(zipFile.getName()); |
|
249 |
if (themeInfo.getName()==null) |
|
250 |
themeInfo.setName(themeInfo.getDescription()); |
|
251 |
themeInfo.setResource(zipFile); |
|
252 |
return themeInfo; |
|
253 |
} |
|
254 |
} catch (XmlPullParserException e) { |
|
255 |
PluginServices.getLogger().error("Error loading theme "+zipFile.getName()+". ", e); |
|
256 |
} |
|
257 |
|
|
258 |
themeInfo = new IconThemeZip(def); |
|
259 |
themeInfo.setResource(zipFile); |
|
260 |
// now try with the directory |
|
261 |
if (dirEntry!=null) { |
|
262 |
themeInfo.setName(dirEntry.getName()); |
|
263 |
themeInfo.setDescription(dirEntry.getName()); |
|
264 |
return themeInfo; |
|
265 |
} |
|
266 |
else { // otherwise just use the zipName |
|
267 |
themeInfo.setName(zipFile.getName()); |
|
268 |
themeInfo.setDescription(zipFile.getName()); |
|
269 |
return themeInfo; |
|
270 |
} |
|
271 |
} |
|
272 |
|
|
273 |
/** |
|
274 |
* Read the properties of IconThemeZip from a XML |
|
275 |
* @param xmlStream |
|
276 |
* @return IconThemeZip |
|
277 |
* @throws XmlPullParserException |
|
278 |
* @throws IOException |
|
279 |
*/ |
|
280 |
private IconThemeZip readXML(InputStream xmlStream) throws XmlPullParserException, IOException { |
|
281 |
KXmlParser parser = new KXmlParser(); |
|
282 |
// we use null encoding, in this way kxml2 tries to detect the encoding |
|
283 |
parser.setInput(xmlStream, null); |
|
284 |
IconThemeZip themeInfo=new IconThemeZip(def); |
|
285 |
for (parser.next(); parser.getEventType()!=KXmlParser.END_DOCUMENT; parser.next()) { |
|
286 |
// este bucle externo recorre las etiquetas de primer y segundo nivel |
|
287 |
if (parser.getEventType()==KXmlParser.START_TAG) { |
|
288 |
if (parser.getName().equals("name")) { |
|
289 |
themeInfo.setName(parser.nextText()); |
|
290 |
} |
|
291 |
else if (parser.getName().equals("description")) { |
|
292 |
themeInfo.setDescription(parser.nextText()); |
|
293 |
} |
|
294 |
else if (parser.getName().equals("version")) { |
|
295 |
themeInfo.setVersion(parser.nextText()); |
|
296 |
} |
|
297 |
} |
|
298 |
} |
|
299 |
return themeInfo; |
|
300 |
} |
|
301 |
|
|
302 |
/** |
|
303 |
* Returns a IconThemeDir from a directory |
|
304 |
* @param dir |
|
305 |
* @return |
|
306 |
*/ |
|
307 |
private IconThemeDir readInfoFromDir(File dir){ |
|
308 |
File themeDefinition = new File(dir + File.separator + themeDefinitionFile); |
|
309 |
IconThemeDir themeInfo; |
|
310 |
try { |
|
311 |
// try reading the XML file |
|
312 |
if (themeDefinition.exists() && themeDefinition.isFile()) { |
|
313 |
themeInfo = readXMLDir(new FileInputStream(themeDefinition)); |
|
314 |
if (themeInfo.getDescription()==null) |
|
315 |
themeInfo.setDescription(dir.getName()); |
|
316 |
if (themeInfo.getName()==null) |
|
317 |
themeInfo.setName(themeInfo.getDescription()); |
|
318 |
themeInfo.setResource(dir); |
|
319 |
return themeInfo; |
|
320 |
} |
|
321 |
} catch (IOException e) {} |
|
322 |
catch (XmlPullParserException e) { |
|
323 |
e.printStackTrace(); |
|
324 |
} |
|
325 |
// the XML parsing failed, just show the dir name |
|
326 |
themeInfo = new IconThemeDir(def); |
|
327 |
themeInfo.setName(dir.getName()); |
|
328 |
themeInfo.setDescription(dir.getName()); |
|
329 |
themeInfo.setResource(dir); |
|
330 |
return themeInfo; |
|
331 |
} |
|
332 |
|
|
333 |
/** |
|
334 |
* Read the properties of IconThemeDir from a XML |
|
335 |
* @param xmlStream |
|
336 |
* @return |
|
337 |
* @throws XmlPullParserException |
|
338 |
* @throws IOException |
|
339 |
*/ |
|
340 |
private IconThemeDir readXMLDir(InputStream xmlStream) throws XmlPullParserException, IOException { |
|
341 |
KXmlParser parser = new KXmlParser(); |
|
342 |
// we use null encoding, in this way kxml2 tries to detect the encoding |
|
343 |
parser.setInput(xmlStream, null); |
|
344 |
IconThemeDir themeInfo=new IconThemeDir(def); |
|
345 |
for (parser.next(); parser.getEventType()!=KXmlParser.END_DOCUMENT; parser.next()) { |
|
346 |
// este bucle externo recorre las etiquetas de primer y segundo nivel |
|
347 |
if (parser.getEventType()==KXmlParser.START_TAG) { |
|
348 |
if (parser.getName().equals("name")) { |
|
349 |
themeInfo.setName(parser.nextText()); |
|
350 |
} |
|
351 |
else if (parser.getName().equals("description")) { |
|
352 |
themeInfo.setDescription(parser.nextText()); |
|
353 |
} |
|
354 |
else if (parser.getName().equals("version")) { |
|
355 |
themeInfo.setVersion(parser.nextText()); |
|
356 |
} |
|
357 |
} |
|
358 |
} |
|
359 |
return themeInfo; |
|
360 |
} |
|
361 |
|
|
362 |
/* |
|
363 |
* (non-Javadoc) |
|
364 |
* @see java.util.Collection#size() |
|
365 |
*/ |
|
366 |
public int size() { |
|
367 |
return themes.size(); |
|
368 |
} |
|
369 |
/* |
|
370 |
* (non-Javadoc) |
|
371 |
* @see java.util.Collection#isEmpty() |
|
372 |
*/ |
|
373 |
public boolean isEmpty() { |
|
374 |
if (themes.size()==0)return true; |
|
375 |
else return false; |
|
376 |
} |
|
377 |
|
|
378 |
/* |
|
379 |
* (non-Javadoc) |
|
380 |
* @see java.util.Collection#contains(java.lang.Object) |
|
381 |
*/ |
|
382 |
public boolean contains(Object o) { |
|
383 |
return themes.contains(o); |
|
384 |
} |
|
385 |
|
|
386 |
/* |
|
387 |
* (non-Javadoc) |
|
388 |
* @see java.lang.Iterable#iterator() |
|
389 |
*/ |
|
390 |
public Iterator iterator() { |
|
391 |
return themes.iterator(); |
|
392 |
} |
|
393 |
|
|
394 |
/* |
|
395 |
* (non-Javadoc) |
|
396 |
* @see java.util.Collection#toArray() |
|
397 |
*/ |
|
398 |
public Object[] toArray() { |
|
399 |
return themes.toArray(); |
|
400 |
} |
|
401 |
|
|
402 |
/* |
|
403 |
* (non-Javadoc) |
|
404 |
* @see java.util.Collection#toArray(Object[] a) |
|
405 |
*/ |
|
406 |
public Object[] toArray(Object[] a) { |
|
407 |
return themes.toArray(a); |
|
408 |
} |
|
409 |
|
|
410 |
/* |
|
411 |
* (non-Javadoc) |
|
412 |
* @see java.util.Collection#remove(java.lang.Object) |
|
413 |
*/ |
|
414 |
public boolean add(Object o) { |
|
415 |
return themes.add((AbstractIconTheme) o); |
|
416 |
} |
|
417 |
|
|
418 |
/* |
|
419 |
* (non-Javadoc) |
|
420 |
* @see java.util.Collection#remove(java.lang.Object) |
|
421 |
*/ |
|
422 |
public boolean remove(Object o) { |
|
423 |
return themes.remove(o); |
|
424 |
} |
|
425 |
|
|
426 |
/* |
|
427 |
* (non-Javadoc) |
|
428 |
* @see java.util.Collection#containsAll(Collection) |
|
429 |
*/ |
|
430 |
public boolean containsAll(Collection c) { |
|
431 |
return themes.containsAll(c); |
|
432 |
} |
|
433 |
|
|
434 |
/* |
|
435 |
* (non-Javadoc) |
|
436 |
* @see java.util.Collection#addAll(Collection) |
|
437 |
*/ |
|
438 |
public boolean addAll(Collection c) { |
|
439 |
return themes.addAll(c); |
|
440 |
} |
|
441 |
|
|
442 |
/* |
|
443 |
* (non-Javadoc) |
|
444 |
* @see java.util.Collection#removeAll(Collection) |
|
445 |
*/ |
|
446 |
public boolean removeAll(Collection c) { |
|
447 |
return themes.removeAll(c); |
|
448 |
} |
|
449 |
|
|
450 |
/* |
|
451 |
* (non-Javadoc) |
|
452 |
* @see java.util.Collection#retainAll(Collection) |
|
453 |
*/ |
|
454 |
public boolean retainAll(Collection c) { |
|
455 |
return themes.retainAll(c); |
|
456 |
} |
|
457 |
|
|
458 |
/* |
|
459 |
* (non-Javadoc) |
|
460 |
* @see java.util.Collection#clear() |
|
461 |
*/ |
|
462 |
public void clear() { |
|
463 |
themes.clear(); |
|
464 |
} |
|
465 |
|
|
466 |
} |
|
0 | 467 |
trunk/frameworks/_fwAndami/src/com/iver/andami/iconthemes2/IconThemeDir.java | ||
---|---|---|
1 |
package com.iver.andami.iconthemes2; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.FilenameFilter; |
|
5 |
import java.net.MalformedURLException; |
|
6 |
import java.net.URL; |
|
7 |
|
|
8 |
import javax.swing.ImageIcon; |
|
9 |
|
|
10 |
|
|
11 |
/** |
|
12 |
* This class extends AbstractIconTheme and implements the abstract methods of this |
|
13 |
* class. This methods are <code>loadIcon</code> and <code>load</code>. This methods |
|
14 |
* allows load one icon or all icons in the resource. |
|
15 |
*/ |
|
16 |
public class IconThemeDir extends AbstractIconTheme{ |
|
17 |
|
|
18 |
/** |
|
19 |
* Constructor.Constructs an Icon Theme with a default one. |
|
20 |
* @param def. The default icon theme |
|
21 |
*/ |
|
22 |
public IconThemeDir(AbstractIconTheme def) { |
|
23 |
setDefault(def); |
|
24 |
} |
|
25 |
|
|
26 |
/** |
|
27 |
* Allows load a icon when this is inside in a directoyr. IconName is the name or |
|
28 |
* key of the icon and "resource" is the URL or the icon |
|
29 |
*/ |
|
30 |
@Override |
|
31 |
protected ImageIcon loadIcon(String iconName,Object resource) { |
|
32 |
if (resource instanceof URL) { |
|
33 |
// ok, we got an imagePath, let's see if it's valid |
|
34 |
ImageIcon icon = new ImageIcon((URL)resource); |
|
35 |
if (icon.getImage()!=null) { |
|
36 |
// the icon was successfully created from the imagePath |
|
37 |
return icon; |
|
38 |
} |
|
39 |
else { |
|
40 |
log().error("Registered icon does not map to a valid image -- key: "+iconName+" -- URL: "+resource.toString()); |
|
41 |
return null; |
|
42 |
} |
|
43 |
|
|
44 |
} |
|
45 |
return null; |
|
46 |
} |
|
47 |
|
|
48 |
/** |
|
49 |
* Allows to load all icons in the directory. |
|
50 |
*/ |
|
51 |
@Override |
|
52 |
public void load() { |
|
53 |
if (getResource() instanceof File) { |
|
54 |
File basedir = (File) getResource(); |
|
55 |
if (basedir.isDirectory()) { |
|
56 |
File[] imageList = basedir.listFiles(new ImageFileFilter()); |
|
57 |
String name; |
|
58 |
for (int i=imageList.length-1; i>=0; i--) { |
|
59 |
name = computeKey(imageList[i].getName()); |
|
60 |
try { |
|
61 |
register(name, imageList[i].toURL()); |
|
62 |
} catch (MalformedURLException e) {} |
|
63 |
} |
|
64 |
} |
|
65 |
|
|
66 |
} |
|
67 |
|
|
68 |
} |
|
69 |
|
|
70 |
/** |
|
71 |
* This class allows filter the images in the directory. Allows to load the images |
|
72 |
* with a apropiate extension. |
|
73 |
*/ |
|
74 |
class ImageFileFilter implements FilenameFilter { |
|
75 |
public boolean accept(File dir, String fileName) { |
|
76 |
String extension = ""; |
|
77 |
int pointPos = fileName.lastIndexOf("."); |
|
78 |
if (pointPos>0 && pointPos < (fileName.length()-1) ) |
|
79 |
extension = fileName.substring(pointPos+1).toLowerCase(); |
|
80 |
if ( extension.equals("jpg") || extension.equals("jpeg") |
|
81 |
|| extension.equals("png") |
|
82 |
|| extension.equals("gif") |
|
83 |
|
|
84 |
) |
|
85 |
return true; |
|
86 |
else |
|
87 |
return false; |
|
88 |
} |
|
89 |
} |
|
90 |
|
|
91 |
/** |
|
92 |
* Returns the key of the image without extension |
|
93 |
* @param fileName |
|
94 |
* @return string |
|
95 |
*/ |
|
96 |
private String computeKey(String fileName) { |
|
97 |
int pointPos = fileName.lastIndexOf("."); |
|
98 |
if (pointPos!=-1) |
|
99 |
return fileName.substring(0, pointPos); |
|
100 |
else |
|
101 |
return fileName; |
|
102 |
} |
|
103 |
|
|
104 |
} |
|
105 |
|
|
0 | 106 |
trunk/frameworks/_fwAndami/src/com/iver/andami/iconthemes2/IconThemeZip.java | ||
---|---|---|
1 |
package com.iver.andami.iconthemes2; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.FilenameFilter; |
|
5 |
import java.io.IOException; |
|
6 |
import java.io.InputStream; |
|
7 |
import java.util.Enumeration; |
|
8 |
import java.util.zip.ZipEntry; |
|
9 |
import java.util.zip.ZipFile; |
|
10 |
|
|
11 |
import javax.swing.ImageIcon; |
|
12 |
|
|
13 |
/** |
|
14 |
* This class extends AbstractIconTheme and implements the abstract methods of this |
|
15 |
* class. This methods are <code>loadIcon</code> and <code>load</code>. This methods |
|
16 |
* allows load one icon or all icons in the resource. |
|
17 |
*/ |
|
18 |
public class IconThemeZip extends AbstractIconTheme{ |
|
19 |
|
|
20 |
/** |
|
21 |
* Constructor.Constructs an Icon Theme with a default one. |
|
22 |
* @param def. The default icon theme |
|
23 |
*/ |
|
24 |
public IconThemeZip(AbstractIconTheme def) { |
|
25 |
setDefault(def); |
|
26 |
} |
|
27 |
|
|
28 |
/** |
|
29 |
* Allows load a icon when this is inside in a Zip file. IconName is the name or |
|
30 |
* key of the icon and "resource" |
|
31 |
*/ |
|
32 |
@Override |
|
33 |
protected ImageIcon loadIcon(String iconName, Object resource) { |
|
34 |
if (resource instanceof ZipEntry && getResource() instanceof ZipFile) { |
|
35 |
ZipEntry entry = (ZipEntry) resource; |
|
36 |
ZipFile file = (ZipFile) getResource(); |
|
37 |
try { |
|
38 |
InputStream is = file.getInputStream(entry); |
|
39 |
int size=(int)entry.getSize(); |
|
40 |
if (size==-1) return null; |
|
41 |
byte[] b=new byte[size]; |
|
42 |
int offset=0; |
|
43 |
int chunk=0; |
|
44 |
while ((size - offset) > 0) { |
|
45 |
chunk=is.read(b, offset, size - offset); |
|
46 |
if (chunk==-1) { |
|
47 |
break; |
|
48 |
} |
|
49 |
offset+=chunk; |
|
50 |
} |
|
51 |
return new ImageIcon(b); |
|
52 |
} catch (IOException e) { |
|
53 |
} |
|
54 |
} |
|
55 |
return null; |
|
56 |
} |
|
57 |
|
|
58 |
/** |
|
59 |
* Allows load all icons in the zip file. |
|
60 |
*/ |
|
61 |
@Override |
|
62 |
public void load() { |
|
63 |
if (getResource() instanceof ZipFile) { |
|
64 |
ZipFile zipFile = (ZipFile) getResource(); |
|
65 |
ImageFileFilter filter = new ImageFileFilter(); |
|
66 |
Enumeration entries = zipFile.entries(); |
|
67 |
while (entries.hasMoreElements()) { |
|
68 |
ZipEntry entry = (ZipEntry) entries.nextElement(); |
|
69 |
if (!entry.isDirectory() ) { |
|
70 |
if (filter.accept(new File(zipFile.getName()), entry.getName())) { |
|
71 |
register(computeKey(entry.getName()), entry); |
|
72 |
} |
|
73 |
} |
|
74 |
} |
|
75 |
|
|
76 |
} |
|
77 |
} |
|
78 |
|
|
79 |
/** |
|
80 |
* This class allows filter the images in the zip file. Allows to load the images |
|
81 |
* with a apropiate extension. |
|
82 |
*/ |
|
83 |
class ImageFileFilter implements FilenameFilter { |
|
84 |
public boolean accept(File dir, String fileName) { |
|
85 |
String extension = ""; |
|
86 |
int pointPos = fileName.lastIndexOf("."); |
|
87 |
if (pointPos>0 && pointPos < (fileName.length()-1) ) |
|
88 |
extension = fileName.substring(pointPos+1).toLowerCase(); |
|
89 |
if ( extension.equals("jpg") || extension.equals("jpeg") |
|
90 |
|| extension.equals("png") |
|
91 |
|| extension.equals("gif")) |
|
92 |
return true; |
|
93 |
else |
|
94 |
return false; |
|
95 |
} |
|
96 |
} |
|
97 |
|
|
98 |
/** |
|
99 |
* Returns the key of the image without extension |
|
100 |
* @param fileName |
|
101 |
* @return string |
|
102 |
*/ |
|
103 |
private String computeKey(String fileName) { |
|
104 |
int pointPos = fileName.lastIndexOf("."); |
|
105 |
if (pointPos!=-1) |
|
106 |
return fileName.substring(0, pointPos); |
|
107 |
else |
|
108 |
return fileName; |
|
109 |
} |
|
110 |
} |
|
0 | 111 |
trunk/frameworks/_fwAndami/src/com/iver/andami/iconthemes2/AbstractIconTheme.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2007 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
* |
|
19 |
* For more information, contact: |
|
20 |
* |
|
21 |
* Generalitat Valenciana |
|
22 |
* Conselleria d'Infraestructures i Transport |
|
23 |
* Av. Blasco Ib��ez, 50 |
|
24 |
* 46010 VALENCIA |
|
25 |
* SPAIN |
|
26 |
* |
|
27 |
* +34 963862235 |
|
28 |
* gvsig@gva.es |
|
29 |
* www.gvsig.gva.es |
|
30 |
* |
|
31 |
* or |
|
32 |
* |
|
33 |
* IVER T.I. S.A |
|
34 |
* Salamanca 50 |
|
35 |
* 46005 Valencia |
|
36 |
* Spain |
|
37 |
* |
|
38 |
* +34 963163400 |
|
39 |
* dac@iver.es |
|
40 |
*/ |
|
41 |
|
|
42 |
package com.iver.andami.iconthemes2; |
|
43 |
|
|
44 |
|
|
45 |
import java.net.URL; |
|
46 |
import java.util.HashMap; |
|
47 |
|
|
48 |
import javax.swing.ImageIcon; |
|
49 |
|
|
50 |
import org.apache.log4j.Logger; |
|
51 |
|
|
52 |
import com.iver.andami.PluginServices; |
|
53 |
|
|
54 |
|
|
55 |
/** |
|
56 |
* <p>This class represents an icon theme, which is basically a mapping of |
|
57 |
* symbolic icon names, and real icons (or icon paths). This is useful to |
|
58 |
* change an application's icons in an easy way. An icon theme |
|
59 |
* is usually read from disk on start up, but can also be created or |
|
60 |
* modified on a later time.</p> |
|
61 |
* |
|
62 |
* <p>Developers are encouraged to always use the |
|
63 |
* <code>get(iconName, fallbackImage)</code> methods to get icons, |
|
64 |
* as they ensure that the icons are not overwritten in the theme, but it |
|
65 |
* also ensures than an image is got in case the icon was still not |
|
66 |
* registered. Note that in this case, the iconName gets registered |
|
67 |
* (it is associated with the provided fallbackImage). |
|
68 |
* </p> |
|
69 |
* |
|
70 |
* <p>Developers are encouraged to NOT override icons which are |
|
71 |
* present in the theme, as this defeats the purpose of IconThemes.</p> |
|
72 |
* |
|
73 |
* @author Cesar Martinez Izquierdo <cesar.martinez@iver.es> |
|
74 |
*/ |
|
75 |
public abstract class AbstractIconTheme { |
|
76 |
private HashMap iconList = new HashMap(); |
|
77 |
private String name=null; |
|
78 |
private String description=null; |
|
79 |
private String version="1.0"; |
|
80 |
private Object resource=null; |
|
81 |
private AbstractIconTheme defaultTheme = null; |
|
82 |
|
|
83 |
|
|
84 |
/** |
|
85 |
* Abstract method that allows load an a icon. This method will be reimplemented by |
|
86 |
* inherit classes. |
|
87 |
* @param iconName |
|
88 |
* @param resource |
|
89 |
* @return |
|
90 |
*/ |
|
91 |
protected abstract ImageIcon loadIcon(String iconName,Object resource) ; |
|
92 |
|
|
93 |
/** |
|
94 |
* Load all icons from the IconTheme |
|
95 |
*/ |
|
96 |
public abstract void load() ; |
|
97 |
|
|
98 |
/** |
|
99 |
* Returns the logger |
|
100 |
* @return |
|
101 |
*/ |
|
102 |
protected Logger log() { |
|
103 |
return Logger.getLogger(this.getClass()); |
|
104 |
} |
|
105 |
|
|
106 |
public void setDefault(AbstractIconTheme def){ |
|
107 |
defaultTheme = def; |
|
108 |
} |
|
109 |
|
|
110 |
public AbstractIconTheme getDefault(){ |
|
111 |
return defaultTheme; |
|
112 |
} |
|
113 |
|
|
114 |
/** |
|
115 |
* Returns <code>true</code> if the icon theme contains a mapping for the |
|
116 |
* specified iconName. |
|
117 |
* |
|
118 |
* @param iconName The key to check if it has been registered in this |
|
119 |
* IconTheme |
|
120 |
* |
|
121 |
* @return <code>true</code> if this IconTheme contains |
|
122 |
* <code>iconName</code>, <code>false</code> otherwise. |
|
123 |
*/ |
|
124 |
public boolean exists(String iconName) { |
|
125 |
if (iconList.containsKey(iconName))return true; |
|
126 |
if (defaultTheme.exists(iconName))return true; |
|
127 |
return false; |
|
128 |
} |
|
129 |
|
|
130 |
/** |
|
131 |
* Gets the ImageIcon associated with the provided key, if the key |
|
132 |
* is present in the theme, or returns <code>null</code> otherwise. |
|
133 |
* |
|
134 |
* @param iconName |
|
135 |
* The key whose associated icon is to be retrieved |
|
136 |
* |
|
137 |
* @return |
|
138 |
* The icon associated with the provided key, or |
|
139 |
* <code>null</code> otherwise. |
|
140 |
*/ |
|
141 |
public ImageIcon get(String iconName) { |
|
142 |
Object object = iconList.get(iconName); |
|
143 |
if (object!=null) { |
|
144 |
if( object instanceof URL ) { |
|
145 |
return new ImageIcon((URL)object); |
|
146 |
} |
|
147 |
ImageIcon icon = loadIcon(iconName,object); |
|
148 |
if( icon != null ) { |
|
149 |
return icon; |
|
150 |
} |
|
151 |
} |
|
152 |
if (defaultTheme!=null){ |
|
153 |
object = defaultTheme.get(iconName); |
|
154 |
if (object!=null){ |
|
155 |
if( object instanceof ImageIcon ) |
|
156 |
return (ImageIcon) object; |
|
157 |
return loadIcon(iconName,object); |
|
158 |
} |
|
159 |
} |
|
160 |
if(get("no-icon")!=null)return get("no-icon"); |
|
161 |
else return null; |
|
162 |
} |
|
163 |
|
|
164 |
/** |
|
165 |
* <p>Register in this theme the provided iconName and the associated |
|
166 |
* image. Developers |
|
167 |
* must not override icons already registered, as this defeats the |
|
168 |
* purpose of the IconTheme. Therefore, use the <code>exists</code> |
|
169 |
* method before using <code>register</code>, to ensure the icon |
|
170 |
* is not previously registered.</p> |
|
171 |
* |
|
172 |
* @param iconName The name of the icon to register. It is the name |
|
173 |
* that will be used later to retrieve the icon. |
|
174 |
* |
|
175 |
* @param image The image that is going to be associated with the |
|
176 |
* provided icon name. |
|
177 |
*/ |
|
178 |
public void registerDefault(String iconName, ImageIcon image) { |
|
179 |
if (defaultTheme!=null) defaultTheme.register(iconName, image); |
|
180 |
else register(iconName, image); |
|
181 |
} |
|
182 |
|
|
183 |
/** |
|
184 |
* <p>Register in this theme the provided iconName and the associated |
|
185 |
* resource. Developers must not override icons already registered, |
|
186 |
* as this defeats the purpose of the IconTheme. Therefore, use the |
|
187 |
* <code>exists</code> method before using <code>register</code>, to |
|
188 |
* ensure the icon is not previously registered.</p> |
|
189 |
* |
|
190 |
* @param iconName The name of the icon to register. It is the name |
|
191 |
* that will be used later to retrieve the icon. |
|
192 |
* @param resource The resource that is going to be asssocioated with the providad |
|
193 |
* icon name |
|
194 |
*/ |
|
195 |
public void registerDefault(String iconName, Object resource) { |
|
196 |
if (defaultTheme!=null)defaultTheme.register(iconName, resource); |
|
197 |
else register(iconName, resource); |
|
198 |
} |
|
199 |
|
|
200 |
/** |
|
201 |
* <p>Register in this theme the provided iconName and the associated |
|
202 |
* image. Developers |
|
203 |
* must not override icons already registered, as this defeats the |
|
204 |
* purpose of the IconTheme. Therefore, use the <code>exists</code> |
|
205 |
* method before using <code>register</code>, to ensure the icon |
|
206 |
* is not previously registered.</p> |
|
207 |
* |
|
208 |
* @param iconName The name of the icon to register. It is the name |
|
209 |
* that will be used later to retrieve the icon. |
|
210 |
* |
|
211 |
* @param image The image that is going to be associated with the |
|
212 |
* provided icon name. |
|
213 |
*/ |
|
214 |
public void register(String iconName, ImageIcon image) { |
|
215 |
iconList.put(iconName, image); |
|
216 |
} |
|
217 |
|
|
218 |
/** |
|
219 |
* <p>Register in this theme the provided iconName and the associated |
|
220 |
* resource. Developers must not override icons already registered, |
|
221 |
* as this defeats the purpose of the IconTheme. Therefore, use the |
|
222 |
* <code>exists</code> method before using <code>register</code>, to |
|
223 |
* ensure the icon is not previously registered.</p> |
|
224 |
* |
|
225 |
* @param iconName The name of the icon to register. It is the name |
|
226 |
* that will be used later to retrieve the icon. |
|
227 |
* @param resource The resource that is going to be asssocioated with the providad |
|
228 |
* icon name |
|
229 |
*/ |
|
230 |
public void register(String iconName, Object resource) { |
|
231 |
iconList.put(iconName, resource); |
|
232 |
} |
|
233 |
|
|
234 |
/** |
|
235 |
* Gets the theme name. |
|
236 |
* @return theme name |
|
237 |
*/ |
|
238 |
public String getName() { |
|
239 |
return name; |
|
240 |
} |
|
241 |
|
|
242 |
/** |
|
243 |
* Sets the theme name. |
|
244 |
* |
|
245 |
* @param themeName |
|
246 |
*/ |
|
247 |
public void setName(String themeName) { |
|
248 |
name = themeName; |
|
249 |
} |
|
250 |
|
|
251 |
/** |
|
252 |
* Gets the theme description. |
|
253 |
* |
|
254 |
* @return The description of this theme. |
|
255 |
*/ |
|
256 |
public String getDescription() { |
|
257 |
return description; |
|
258 |
} |
|
259 |
|
|
260 |
/** |
|
261 |
* Sets the theme description. It should be a short description |
|
262 |
* (around 20-30 words), including the highlights of the theme, |
|
263 |
* the author and maybe its email address or a link the the theme's |
|
264 |
* homepage. |
|
265 |
* |
|
266 |
* @param description |
|
267 |
*/ |
|
268 |
public void setDescription(String description) { |
|
269 |
this.description = description; |
|
270 |
} |
|
271 |
|
|
272 |
/** |
|
273 |
* Returns the theme version. It defaults to "1.0". |
|
274 |
* |
|
275 |
* @return The version of this theme. |
|
276 |
*/ |
|
277 |
public String getVersion() { |
|
278 |
return version; |
|
279 |
} |
|
280 |
|
|
281 |
/** |
|
282 |
* Set the theme version. |
|
283 |
* |
|
284 |
* @param version |
|
285 |
*/ |
|
286 |
public void setVersion(String version) { |
|
287 |
this.version = version; |
|
288 |
} |
|
289 |
|
|
290 |
/** |
|
291 |
* Gets the Object which contains physically contains this theme on disk. |
|
292 |
* It may be a ZipFile or JarFile, or a directory. |
|
293 |
* |
|
294 |
* @return |
|
295 |
*/ |
|
296 |
public Object getResource() { |
|
297 |
return resource; |
|
298 |
} |
|
299 |
/** |
|
300 |
* Sets the file which contains physically contains this theme on disk. |
|
301 |
* It may be a ZipFile or JarFile, or a directory. |
|
302 |
* |
|
303 |
* @return |
|
304 |
*/ |
|
305 |
public void setResource(Object resource) { |
|
306 |
this.resource = resource; |
|
307 |
} |
|
308 |
|
|
309 |
/** |
|
310 |
* Returns the name of the icon theme |
|
311 |
*/ |
|
312 |
public String toString() { |
|
313 |
return getName(); |
|
314 |
} |
|
315 |
|
|
316 |
/** |
|
317 |
* Return the URL which is currently associated with the |
|
318 |
* provided icon name, if this icon was registered as an |
|
319 |
* URL, or <code>null</code> if it is not present in the theme |
|
320 |
* or it was registered as an IconImage. |
|
321 |
* |
|
322 |
* @param iconName |
|
323 |
* @return The URL which is currently associated with the |
|
324 |
* provided icon name, if this icon was registered as an |
|
325 |
* URL, or <code>null</code> if it is not present in the theme |
|
326 |
* or it was registered as an IconImage. |
|
327 |
*/ |
|
328 |
public URL getURL(String iconName) { |
|
329 |
Object object = defaultTheme.get(iconName); |
|
330 |
if (object !=null && object instanceof URL) |
|
331 |
return (URL) object; |
|
332 |
return null; |
|
333 |
} |
|
334 |
|
|
335 |
|
|
336 |
} |
|
0 | 337 |
trunk/frameworks/_fwAndami/src/com/iver/andami/iconthemes2/IconThemeMemory.java | ||
---|---|---|
1 |
package com.iver.andami.iconthemes2; |
|
2 |
|
|
3 |
import java.net.URL; |
|
4 |
|
|
5 |
import javax.swing.ImageIcon; |
|
6 |
|
|
7 |
/** |
|
8 |
* This class is used by the default theme and don�t load icons because they are already |
|
9 |
* in memory. |
|
10 |
*/ |
|
11 |
public class IconThemeMemory extends AbstractIconTheme{ |
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
/** |
|
17 |
* Constructor |
|
18 |
* @param def. The default icon theme |
|
19 |
*/ |
|
20 |
public IconThemeMemory(AbstractIconTheme def) { |
|
21 |
setDefault(def); |
|
22 |
} |
|
23 |
|
|
24 |
/** |
|
25 |
* Return null, don�t load the icon |
|
26 |
*/ |
|
27 |
@Override |
|
28 |
protected ImageIcon loadIcon(String iconName,Object resource) { |
|
29 |
return null; |
|
30 |
} |
|
31 |
|
|
32 |
/** |
|
33 |
* Don�t load any icon. They are already in memory |
|
34 |
*/ |
|
35 |
@Override |
|
36 |
public void load() { |
|
37 |
|
|
38 |
|
|
39 |
} |
|
40 |
|
|
41 |
} |
|
0 | 42 |
trunk/frameworks/_fwAndami/src/com/iver/andami/Launcher.java | ||
---|---|---|
81 | 81 |
import java.util.Properties; |
82 | 82 |
import java.util.TreeMap; |
83 | 83 |
import java.util.prefs.Preferences; |
84 |
import java.util.zip.ZipFile; |
|
84 | 85 |
|
85 | 86 |
import javax.jnlp.BasicService; |
86 | 87 |
import javax.jnlp.ServiceManager; |
... | ... | |
105 | 106 |
import com.iver.andami.config.generate.Andami; |
106 | 107 |
import com.iver.andami.config.generate.AndamiConfig; |
107 | 108 |
import com.iver.andami.config.generate.Plugin; |
108 |
import com.iver.andami.iconthemes.IconTheme; |
|
109 |
import com.iver.andami.iconthemes.IconThemeInfo; |
|
110 |
import com.iver.andami.iconthemes.IconThemeManager; |
|
109 |
import com.iver.andami.iconthemes2.AbstractIconTheme; |
|
110 |
import com.iver.andami.iconthemes2.IconThemeZip; |
|
111 | 111 |
import com.iver.andami.messages.Messages; |
112 | 112 |
import com.iver.andami.messages.NotificationManager; |
113 | 113 |
import com.iver.andami.plugins.ExclusiveUIExtension; |
... | ... | |
348 | 348 |
PluginServices.getText(Launcher.class, "SplashWindow.loading_plugin_settings")); |
349 | 349 |
loadPluginsPersistence(); |
350 | 350 |
|
351 |
registerIcons(); |
|
352 | 351 |
|
352 |
|
|
353 | 353 |
// Se instalan los controles del skin |
354 | 354 |
// 11. Se inicializan todas las extensiones de todos los plugins |
355 | 355 |
splashWindow.process(110, |
... | ... | |
445 | 445 |
} |
446 | 446 |
|
447 | 447 |
private static void registerIcons(){ |
448 |
PluginServices.getIconTheme().register( |
|
448 |
PluginServices.getIconTheme().registerDefault(
|
|
449 | 449 |
"login-gvsig", |
450 | 450 |
LoginUI.class.getClassLoader().getResource("images/login_gvsig.png") |
451 | 451 |
); |
452 |
PluginServices.getIconTheme().register( |
|
452 |
PluginServices.getIconTheme().registerDefault(
|
|
453 | 453 |
"splash-gvsig", |
454 | 454 |
MultiSplashWindow.class.getClassLoader().getResource("images/splash.png") |
455 | 455 |
); |
456 |
PluginServices.getIconTheme().register( |
|
456 |
PluginServices.getIconTheme().registerDefault(
|
|
457 | 457 |
"info-icon", |
458 | 458 |
NewStatusBar.class.getClassLoader().getResource("images/info.gif") |
459 | 459 |
); |
460 |
PluginServices.getIconTheme().register( |
|
460 |
PluginServices.getIconTheme().registerDefault(
|
|
461 | 461 |
"error-icon", |
462 | 462 |
NewStatusBar.class.getClassLoader().getResource("images/error.gif") |
463 | 463 |
); |
464 |
PluginServices.getIconTheme().register( |
|
464 |
PluginServices.getIconTheme().registerDefault(
|
|
465 | 465 |
"warning-icon", |
466 | 466 |
NewStatusBar.class.getClassLoader().getResource("images/warning.gif") |
467 | 467 |
); |
468 |
PluginServices.getIconTheme().register( |
|
468 |
PluginServices.getIconTheme().registerDefault(
|
|
469 | 469 |
"no-icon", |
470 | 470 |
NewStatusBar.class.getClassLoader().getResource("images/no_icon.png") |
471 | 471 |
); |
... | ... | |
2073 | 2073 |
} |
2074 | 2074 |
|
2075 | 2075 |
|
2076 |
public static void initIconThemes() { |
|
2077 |
// load the iconTheme |
|
2078 |
IconThemeManager iconManager = new IconThemeManager(); |
|
2076 |
// public static void initIconThemes() { |
|
2077 |
// // load the iconTheme |
|
2078 |
// IconThemeManager iconManager = new IconThemeManager(); |
|
2079 |
// PluginServices.setIconThemeManager(iconManager); |
|
2080 |
// IconThemeInfo selectedTheme = iconManager.readConfig(); |
|
2081 |
// if (selectedTheme!=null) { |
|
2082 |
// iconManager.setDefault(selectedTheme); |
|
2083 |
// logger.info("Setting the icon theme: "+selectedTheme.toVerboseString()); |
|
2084 |
// } |
|
2085 |
// else { |
|
2086 |
// // set the default dir and try to load the default theme |
|
2087 |
// try { |
|
2088 |
// iconManager.setThemesDir(new File("iconThemes")); |
|
2089 |
// IconThemeInfo[] list = iconManager.list(); |
|
2090 |
// |
|
2091 |
// for (int i=0; i<list.length; i++) { |
|
2092 |
// if (list[i].getResourceName().equals("iconThemes/icons")) { |
|
2093 |
// iconManager.setDefault(list[i]); |
|
2094 |
// logger.info("Setting the default icon theme: "+list[i].toVerboseString()); |
|
2095 |
// return; |
|
2096 |
// } |
|
2097 |
// } |
|
2098 |
// } catch (FileNotFoundException e) { |
|
2099 |
// logger.info("IconTheme basedir does not exist"); |
|
2100 |
// } |
|
2101 |
// // create an empty theme |
|
2102 |
// IconThemeInfo info = new IconThemeInfo(); |
|
2103 |
// info.setName("No theme loaded"); |
|
2104 |
// info.setResource(null); // null resource means that no real theme is loaded |
|
2105 |
// info.setDescription("No theme loaded"); |
|
2106 |
// info.setVersion("0"); |
|
2107 |
// iconManager.setDefault(new IconTheme(info)); |
|
2108 |
// logger.info("Setting an empty icon theme"); |
|
2109 |
// |
|
2110 |
// } |
|
2111 |
// } |
|
2112 |
|
|
2113 |
public static void initIconThemes(){ |
|
2114 |
com.iver.andami.iconthemes2.IconThemeManager iconManager = |
|
2115 |
new com.iver.andami.iconthemes2.IconThemeManager(); |
|
2116 |
AbstractIconTheme icontheme= iconManager.readConfig(); |
|
2079 | 2117 |
PluginServices.setIconThemeManager(iconManager); |
2080 |
IconThemeInfo selectedTheme = iconManager.readConfig(); |
|
2081 |
if (selectedTheme!=null) { |
|
2082 |
iconManager.setDefault(selectedTheme); |
|
2083 |
logger.info("Setting the icon theme: "+selectedTheme.toVerboseString()); |
|
2118 |
if (icontheme!=null){ |
|
2119 |
iconManager.setCurrent(icontheme); |
|
2084 | 2120 |
} |
2085 |
else { |
|
2086 |
// set the default dir and try to load the default theme |
|
2087 |
try { |
|
2088 |
iconManager.setThemesDir(new File("iconThemes")); |
|
2089 |
IconThemeInfo[] list = iconManager.list(); |
|
2121 |
|
|
2090 | 2122 |
|
2091 |
for (int i=0; i<list.length; i++) { |
|
2092 |
if (list[i].getResourceName().equals("iconThemes/icons")) { |
|
2093 |
iconManager.setDefault(list[i]); |
|
2094 |
logger.info("Setting the default icon theme: "+list[i].toVerboseString()); |
|
2095 |
return; |
|
2096 |
} |
|
2097 |
} |
|
2098 |
} catch (FileNotFoundException e) { |
|
2099 |
logger.info("IconTheme basedir does not exist"); |
|
2100 |
} |
|
2101 |
// create an empty theme |
|
2102 |
IconThemeInfo info = new IconThemeInfo(); |
|
2103 |
info.setName("No theme loaded"); |
|
2104 |
info.setResource(null); // null resource means that no real theme is loaded |
|
2105 |
info.setDescription("No theme loaded"); |
|
2106 |
info.setVersion("0"); |
|
2107 |
iconManager.setDefault(new IconTheme(info)); |
|
2108 |
logger.info("Setting an empty icon theme"); |
|
2109 |
|
|
2110 |
} |
|
2111 | 2123 |
} |
2112 | 2124 |
|
2113 | 2125 |
/** |
trunk/frameworks/_fwAndami/src/com/iver/andami/PluginServices.java | ||
---|---|---|
62 | 62 |
import org.apache.log4j.Logger; |
63 | 63 |
|
64 | 64 |
import com.iver.andami.authentication.IAuthentication; |
65 |
import com.iver.andami.iconthemes.IconTheme;
|
|
66 |
import com.iver.andami.iconthemes.IconThemeManager; |
|
65 |
import com.iver.andami.iconthemes2.AbstractIconTheme;
|
|
66 |
import com.iver.andami.iconthemes2.IconThemeManager;
|
|
67 | 67 |
import com.iver.andami.messages.Messages; |
68 | 68 |
import com.iver.andami.messages.NotificationManager; |
69 | 69 |
import com.iver.andami.plugins.ExclusiveUIExtension; |
... | ... | |
659 | 659 |
return iconManager; |
660 | 660 |
} |
661 | 661 |
|
662 |
public static IconTheme getIconTheme() { |
|
663 |
return iconManager.getDefault();
|
|
662 |
public static AbstractIconTheme getIconTheme() {
|
|
663 |
return iconManager.getCurrent();
|
|
664 | 664 |
} |
665 | 665 |
} |
Also available in: Unified diff