root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / extension / develtools / IconThemeDevelTool.java @ 38564
History | View | Annotate | Download (14.1 KB)
1 | 38564 | jjdelcerro | package org.gvsig.app.extension.develtools; |
---|---|---|---|
2 | |||
3 | import java.util.ArrayList; |
||
4 | import java.util.Collections; |
||
5 | import java.util.Comparator; |
||
6 | import java.util.HashSet; |
||
7 | import java.util.Iterator; |
||
8 | import java.util.List; |
||
9 | import java.util.Set; |
||
10 | |||
11 | import javax.swing.ImageIcon; |
||
12 | |||
13 | import org.gvsig.andami.PluginsLocator; |
||
14 | import org.gvsig.andami.actioninfo.ActionInfo; |
||
15 | import org.gvsig.tools.swing.api.ToolsSwingLocator; |
||
16 | import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
||
17 | import org.gvsig.tools.swing.icontheme.IconTheme; |
||
18 | import org.gvsig.tools.swing.icontheme.IconThemeManager; |
||
19 | |||
20 | public class IconThemeDevelTool { |
||
21 | |||
22 | public void showDefaultIconTheme() { |
||
23 | String html = this.getIconThemeInformationByGroup(); |
||
24 | InfoPanel.save2file("iconthemeinfo", html);
|
||
25 | InfoPanel.showPanel("Icon theme information", WindowManager.MODE.WINDOW, html);
|
||
26 | } |
||
27 | |||
28 | public void showDefaultIconThemeByPlugin() { |
||
29 | String html = this.getIconThemeInformationByPlugin(); |
||
30 | InfoPanel.save2file("iconthemeinfo", html);
|
||
31 | InfoPanel.showPanel("Icon theme information", WindowManager.MODE.WINDOW, html);
|
||
32 | } |
||
33 | |||
34 | private String getIconThemeInformationByPlugin() { |
||
35 | IconThemeManager manager = ToolsSwingLocator.getIconThemeManager(); |
||
36 | IconTheme theme = manager.getDefault(); |
||
37 | |||
38 | List<IconTheme.Icon>themeIcons = new ArrayList<IconTheme.Icon>(); |
||
39 | Iterator<IconTheme.Icon> themeIconsIt = theme.getThemeIcons();
|
||
40 | while (themeIconsIt.hasNext()) {
|
||
41 | themeIcons.add(themeIconsIt.next()); |
||
42 | } |
||
43 | Collections.sort(themeIcons, new Comparator<IconTheme.Icon>() { |
||
44 | public int compare(IconTheme.Icon o1, IconTheme.Icon o2) { |
||
45 | String s1 = String.format("%s:%s:%s", o1.getProviderName(), o1.getGroup(), o1.getName()); |
||
46 | String s2 = String.format("%s:%s:%s", o2.getProviderName(), o2.getGroup(), o2.getName()); |
||
47 | return s1.compareTo(s2);
|
||
48 | } |
||
49 | }); |
||
50 | themeIconsIt = themeIcons.iterator(); |
||
51 | return getIconThemeInformation(theme, themeIconsIt);
|
||
52 | } |
||
53 | |||
54 | private String getIconThemeInformationByGroup() { |
||
55 | IconThemeManager manager = ToolsSwingLocator.getIconThemeManager(); |
||
56 | IconTheme theme = manager.getDefault(); |
||
57 | |||
58 | List<IconTheme.Icon>themeIcons = new ArrayList<IconTheme.Icon>(); |
||
59 | Iterator<IconTheme.Icon> themeIconsIt = theme.getThemeIcons();
|
||
60 | while (themeIconsIt.hasNext()) {
|
||
61 | themeIcons.add(themeIconsIt.next()); |
||
62 | } |
||
63 | Collections.sort(themeIcons, new Comparator<IconTheme.Icon>() { |
||
64 | public int compare(IconTheme.Icon o1, IconTheme.Icon o2) { |
||
65 | String s1 = String.format("%s:%s:%s", o1.getGroup(), o1.getName(), o1.getProviderName()); |
||
66 | String s2 = String.format("%s:%s:%s", o2.getGroup(), o2.getName(), o2.getProviderName()); |
||
67 | return s1.compareTo(s2);
|
||
68 | } |
||
69 | }); |
||
70 | themeIconsIt = themeIcons.iterator(); |
||
71 | return getIconThemeInformation(theme,themeIconsIt);
|
||
72 | } |
||
73 | |||
74 | private String getIconThemeInformation(IconTheme theme, Iterator<IconTheme.Icon> themeIconsIt) { |
||
75 | Set<String> actionIcons = new HashSet<String>(); |
||
76 | Iterator<ActionInfo> actions = PluginsLocator.getActionInfoManager().getActions();
|
||
77 | while (actions.hasNext()) {
|
||
78 | ActionInfo action = actions.next(); |
||
79 | if( action.getIconName()!=null ) { |
||
80 | actionIcons.add(action.getIconName()); |
||
81 | } |
||
82 | } |
||
83 | Set<String> tangoIconNames = getTangoIconNames(); |
||
84 | |||
85 | StringBuffer buffer = new StringBuffer(); |
||
86 | |||
87 | String warning_open = "<b>"; |
||
88 | String warning_close = "</b>"; |
||
89 | |||
90 | String error_open = "<b><font color=\"red\">"; |
||
91 | String error_close = "</font></b>"; |
||
92 | |||
93 | String tangoicon_open = "<b><font color=\"green\">"; |
||
94 | String tangoicon_close = "</font></b>"; |
||
95 | |||
96 | String previousPluginName = null; |
||
97 | |||
98 | buffer.append("<html>\n");
|
||
99 | buffer.append("<body>\n");
|
||
100 | buffer.append("<h2>Icon theme information</h2>\n");
|
||
101 | buffer.append("<br>\n");
|
||
102 | buffer.append("Theme: ");
|
||
103 | buffer.append(theme.getName()); |
||
104 | buffer.append("<br>\n");
|
||
105 | buffer.append("Description: ");
|
||
106 | buffer.append(theme.getDescription()); |
||
107 | buffer.append("<br>\n");
|
||
108 | |||
109 | buffer.append("<table border=\"0\">\n");
|
||
110 | buffer.append(" <tr>\n");
|
||
111 | buffer.append(" <td>Preview</td>\n");
|
||
112 | buffer.append(" <td>Group</td>\n");
|
||
113 | buffer.append(" <td>Name</td>\n");
|
||
114 | buffer.append(" <td>Plugin</td>\n");
|
||
115 | buffer.append(" <td>Resource</td>\n");
|
||
116 | buffer.append(" </tr>\n");
|
||
117 | |||
118 | |||
119 | while (themeIconsIt.hasNext()) {
|
||
120 | IconTheme.Icon themeIcon = themeIconsIt.next(); |
||
121 | if( previousPluginName!=null && !themeIcon.getProviderName().equals(previousPluginName) ) { |
||
122 | buffer |
||
123 | .append(" <tr>\n")
|
||
124 | .append(" <td colspan=\"4\"><hr></td>\n")
|
||
125 | .append(" </tr>\n");
|
||
126 | previousPluginName = themeIcon.getProviderName(); |
||
127 | } |
||
128 | |||
129 | buffer.append(" <tr valign=\"top\">\n");
|
||
130 | |||
131 | // Preview
|
||
132 | if( themeIcon.getLabel().length()>0 && themeIcon.getImageIcon()!=null ) { |
||
133 | try {
|
||
134 | ImageIcon img = themeIcon.getImageIcon();
|
||
135 | if( img.getIconHeight() > 48 || img.getIconWidth() > 48 ) { |
||
136 | buffer |
||
137 | .append(" <td nowrap>")
|
||
138 | .append("<img width=\"48\" height=\"48\" src=\"")
|
||
139 | .append(themeIcon.getLabel()) |
||
140 | .append("\">(*)</td>");
|
||
141 | } else {
|
||
142 | buffer |
||
143 | .append(" <td>")
|
||
144 | .append("<img src=\"")
|
||
145 | .append(themeIcon.getLabel()) |
||
146 | .append("\"></td>");
|
||
147 | } |
||
148 | } catch(Exception ex) { |
||
149 | buffer |
||
150 | .append(" <td>")
|
||
151 | .append("<img src=\"")
|
||
152 | .append(themeIcon.getLabel()) |
||
153 | .append("\"></td>");
|
||
154 | } |
||
155 | } else {
|
||
156 | buffer.append(" <td></td>");
|
||
157 | } |
||
158 | |||
159 | // Group
|
||
160 | if( themeIcon.getGroup()==null ) { |
||
161 | buffer.append(" <td title=\"missing recomended group\">")
|
||
162 | .append(warning_open) |
||
163 | .append(themeIcon.getGroup()) |
||
164 | .append(warning_close) |
||
165 | .append("</td>\n");
|
||
166 | } else {
|
||
167 | buffer.append(" <td>")
|
||
168 | .append(themeIcon.getGroup()) |
||
169 | .append("</td>\n");
|
||
170 | } |
||
171 | |||
172 | // Name
|
||
173 | if( "action".equals(themeIcon.getGroup()) && !actionIcons.contains(themeIcon.getName())) { |
||
174 | buffer.append(" <td title=\"Don't exists an action associated to this icon\">")
|
||
175 | .append(error_open) |
||
176 | .append(themeIcon.getName()) |
||
177 | .append(error_close) |
||
178 | .append("</td>\n");
|
||
179 | } else if( !themeIcon.getName().contains("-") ) { |
||
180 | buffer.append(" <td title=\"Name don't have recomended format\">")
|
||
181 | .append(warning_open) |
||
182 | .append(themeIcon.getName()) |
||
183 | .append(warning_close) |
||
184 | .append("</td>\n");
|
||
185 | } else if( tangoIconNames.contains(themeIcon.getName()) ){ |
||
186 | buffer.append(" <td>")
|
||
187 | .append(tangoicon_open) |
||
188 | .append(themeIcon.getName()) |
||
189 | .append(tangoicon_close) |
||
190 | .append("</td>\n");
|
||
191 | } else {
|
||
192 | buffer.append(" <td>")
|
||
193 | .append(themeIcon.getName()) |
||
194 | .append("</td>\n");
|
||
195 | } |
||
196 | |||
197 | // Plugin
|
||
198 | if( themeIcon.getProviderName()== null ) { |
||
199 | buffer.append(" <td title=\"missing recomended associated plugin\">")
|
||
200 | .append(warning_open) |
||
201 | .append(themeIcon.getProviderName()) |
||
202 | .append(warning_close) |
||
203 | .append("</td>\n");
|
||
204 | |||
205 | } else {
|
||
206 | buffer.append(" <td>")
|
||
207 | .append(themeIcon.getProviderName()) |
||
208 | .append("</td>\n");
|
||
209 | } |
||
210 | |||
211 | // Resource
|
||
212 | if( themeIcon.getLabel().length()<1 ) { |
||
213 | buffer.append(" <td title=\"Resource icon not specified\">")
|
||
214 | .append(error_open) |
||
215 | .append("(missing)")
|
||
216 | .append(error_close) |
||
217 | .append("</td>\n");
|
||
218 | } else if( themeIcon.getImageIcon()==null ) { |
||
219 | buffer.append(" <td title=\"Can't locate icon\">")
|
||
220 | .append(error_open) |
||
221 | .append(themeIcon.getLabel()) |
||
222 | .append(error_close) |
||
223 | .append("</td>\n");
|
||
224 | } else {
|
||
225 | buffer.append(" <td>")
|
||
226 | .append(themeIcon.getLabel()) |
||
227 | .append("</td>\n");
|
||
228 | |||
229 | } |
||
230 | buffer.append(" </tr>\n");
|
||
231 | } |
||
232 | buffer.append("</table>\n");
|
||
233 | buffer.append("</body>\n");
|
||
234 | buffer.append("</html>\n");
|
||
235 | |||
236 | return buffer.toString();
|
||
237 | } |
||
238 | |||
239 | private Set<String> getTangoIconNames() { |
||
240 | String[] iconNames = new String[] { |
||
241 | "address-book-new",
|
||
242 | "application-exit",
|
||
243 | "appointment-new",
|
||
244 | "call-start",
|
||
245 | "call-stop",
|
||
246 | "contact-new",
|
||
247 | "document-new",
|
||
248 | "document-open",
|
||
249 | "document-open-recent",
|
||
250 | "document-page-setup",
|
||
251 | "document-print",
|
||
252 | "document-print-preview",
|
||
253 | "document-properties",
|
||
254 | "document-revert",
|
||
255 | "document-save",
|
||
256 | "document-save-as",
|
||
257 | "document-send",
|
||
258 | "edit-clear",
|
||
259 | "edit-copy",
|
||
260 | "edit-cut",
|
||
261 | "edit-delete",
|
||
262 | "edit-find",
|
||
263 | "edit-find-replace",
|
||
264 | "edit-paste",
|
||
265 | "edit-redo",
|
||
266 | "edit-select-all",
|
||
267 | "edit-undo",
|
||
268 | "folder-new",
|
||
269 | "format-indent-less",
|
||
270 | "format-indent-more",
|
||
271 | "format-justify-center",
|
||
272 | "format-justify-fill",
|
||
273 | "format-justify-left",
|
||
274 | "format-justify-right",
|
||
275 | "format-text-direction-ltr",
|
||
276 | "format-text-direction-rtl",
|
||
277 | "format-text-bold",
|
||
278 | "format-text-italic",
|
||
279 | "format-text-underline",
|
||
280 | "format-text-strikethrough",
|
||
281 | "go-bottom",
|
||
282 | "go-down",
|
||
283 | "go-first",
|
||
284 | "go-home",
|
||
285 | "go-jump",
|
||
286 | "go-last",
|
||
287 | "go-next",
|
||
288 | "go-previous",
|
||
289 | "go-top",
|
||
290 | "go-up",
|
||
291 | "help-about",
|
||
292 | "help-contents",
|
||
293 | "help-faq",
|
||
294 | "insert-image",
|
||
295 | "insert-link",
|
||
296 | "insert-object",
|
||
297 | "insert-text",
|
||
298 | "list-add",
|
||
299 | "list-remove",
|
||
300 | "mail-forward",
|
||
301 | "mail-mark-important",
|
||
302 | "mail-mark-junk",
|
||
303 | "mail-mark-notjunk",
|
||
304 | "mail-mark-read",
|
||
305 | "mail-mark-unread",
|
||
306 | "mail-message-new",
|
||
307 | "mail-reply-all",
|
||
308 | "mail-reply-sender",
|
||
309 | "mail-send",
|
||
310 | "mail-send-receive",
|
||
311 | "media-eject",
|
||
312 | "media-playback-pause",
|
||
313 | "media-playback-start",
|
||
314 | "media-playback-stop",
|
||
315 | "media-record",
|
||
316 | "media-seek-backward",
|
||
317 | "media-seek-forward",
|
||
318 | "media-skip-backward",
|
||
319 | "media-skip-forward",
|
||
320 | "object-flip-horizontal",
|
||
321 | "object-flip-vertical",
|
||
322 | "object-rotate-left",
|
||
323 | "object-rotate-right",
|
||
324 | "process-stop",
|
||
325 | "system-lock-screen",
|
||
326 | "system-log-out",
|
||
327 | "system-run",
|
||
328 | "system-search",
|
||
329 | "system-reboot",
|
||
330 | "system-shutdown",
|
||
331 | "tools-check-spelling",
|
||
332 | "view-fullscreen",
|
||
333 | "view-refresh",
|
||
334 | "view-restore",
|
||
335 | "view-sort-ascending",
|
||
336 | "view-sort-descending",
|
||
337 | "window-close",
|
||
338 | "window-new",
|
||
339 | "zoom-fit-best",
|
||
340 | "zoom-in",
|
||
341 | "zoom-original",
|
||
342 | "zoom-out",
|
||
343 | "process-working",
|
||
344 | "accessories-calculator",
|
||
345 | "accessories-character-map",
|
||
346 | "accessories-dictionary",
|
||
347 | "accessories-text-editor",
|
||
348 | "help-browser",
|
||
349 | "multimedia-volume-control",
|
||
350 | "preferences-desktop-accessibility",
|
||
351 | "preferences-desktop-font",
|
||
352 | "preferences-desktop-keyboard",
|
||
353 | "preferences-desktop-locale",
|
||
354 | "preferences-desktop-multimedia",
|
||
355 | "preferences-desktop-screensaver",
|
||
356 | "preferences-desktop-theme",
|
||
357 | "preferences-desktop-wallpaper",
|
||
358 | "system-file-manager",
|
||
359 | "system-software-install",
|
||
360 | "system-software-update",
|
||
361 | "utilities-system-monitor",
|
||
362 | "utilities-terminal",
|
||
363 | "applications-accessories",
|
||
364 | "applications-development",
|
||
365 | "applications-engineering",
|
||
366 | "applications-games",
|
||
367 | "applications-graphics",
|
||
368 | "applications-internet",
|
||
369 | "applications-multimedia",
|
||
370 | "applications-office",
|
||
371 | "applications-other",
|
||
372 | "applications-science",
|
||
373 | "applications-system",
|
||
374 | "applications-utilities",
|
||
375 | "preferences-desktop",
|
||
376 | "preferences-desktop-peripherals",
|
||
377 | "preferences-desktop-personal",
|
||
378 | "preferences-other",
|
||
379 | "preferences-system",
|
||
380 | "preferences-system-network",
|
||
381 | "system-help",
|
||
382 | "audio-card",
|
||
383 | "audio-input-microphone",
|
||
384 | "battery",
|
||
385 | "camera-photo",
|
||
386 | "camera-video",
|
||
387 | "camera-web",
|
||
388 | "computer",
|
||
389 | "drive-harddisk",
|
||
390 | "drive-optical",
|
||
391 | "drive-removable-media",
|
||
392 | "input-gaming",
|
||
393 | "input-keyboard",
|
||
394 | "input-mouse",
|
||
395 | "input-tablet",
|
||
396 | "media-flash",
|
||
397 | "media-floppy",
|
||
398 | "media-optical",
|
||
399 | "media-tape",
|
||
400 | "modem",
|
||
401 | "multimedia-player",
|
||
402 | "network-wired",
|
||
403 | "network-wireless",
|
||
404 | "pda",
|
||
405 | "phone",
|
||
406 | "printer",
|
||
407 | "scanner",
|
||
408 | "video-display",
|
||
409 | "emblem-default",
|
||
410 | "emblem-documents",
|
||
411 | "emblem-downloads",
|
||
412 | "emblem-favorite",
|
||
413 | "emblem-important",
|
||
414 | "emblem-mail",
|
||
415 | "emblem-photos",
|
||
416 | "emblem-readonly",
|
||
417 | "emblem-shared",
|
||
418 | "emblem-symbolic-link",
|
||
419 | "emblem-synchronized",
|
||
420 | "emblem-system",
|
||
421 | "emblem-unreadable",
|
||
422 | "face-angel",
|
||
423 | "face-angry",
|
||
424 | "face-cool",
|
||
425 | "face-crying",
|
||
426 | "face-devilish",
|
||
427 | "face-embarrassed",
|
||
428 | "face-kiss",
|
||
429 | "face-laugh",
|
||
430 | "face-monkey",
|
||
431 | "face-plain",
|
||
432 | "face-raspberry",
|
||
433 | "face-sad",
|
||
434 | "face-sick",
|
||
435 | "face-smile",
|
||
436 | "face-smile-big",
|
||
437 | "face-smirk",
|
||
438 | "face-surprise",
|
||
439 | "face-tired",
|
||
440 | "face-uncertain",
|
||
441 | "face-wink",
|
||
442 | "face-worried",
|
||
443 | "flag-aa",
|
||
444 | "application-x-executable",
|
||
445 | "audio-x-generic",
|
||
446 | "font-x-generic",
|
||
447 | "image-x-generic",
|
||
448 | "package-x-generic",
|
||
449 | "text-html",
|
||
450 | "text-x-generic",
|
||
451 | "text-x-generic-template",
|
||
452 | "text-x-script",
|
||
453 | "video-x-generic",
|
||
454 | "x-office-address-book",
|
||
455 | "x-office-calendar",
|
||
456 | "x-office-document",
|
||
457 | "x-office-presentation",
|
||
458 | "x-office-spreadsheet",
|
||
459 | "folder",
|
||
460 | "folder-remote",
|
||
461 | "network-server",
|
||
462 | "network-workgroup",
|
||
463 | "start-here",
|
||
464 | "user-bookmarks",
|
||
465 | "user-desktop",
|
||
466 | "user-home",
|
||
467 | "user-trash",
|
||
468 | "appointment-missed",
|
||
469 | "appointment-soon",
|
||
470 | "audio-volume-high",
|
||
471 | "audio-volume-low",
|
||
472 | "audio-volume-medium",
|
||
473 | "audio-volume-muted",
|
||
474 | "battery-caution",
|
||
475 | "battery-low",
|
||
476 | "dialog-error",
|
||
477 | "dialog-information",
|
||
478 | "dialog-password",
|
||
479 | "dialog-question",
|
||
480 | "dialog-warning",
|
||
481 | "folder-drag-accept",
|
||
482 | "folder-open",
|
||
483 | "folder-visiting",
|
||
484 | "image-loading",
|
||
485 | "image-missing",
|
||
486 | "mail-attachment",
|
||
487 | "mail-unread",
|
||
488 | "mail-read",
|
||
489 | "mail-replied",
|
||
490 | "mail-signed",
|
||
491 | "mail-signed-verified",
|
||
492 | "media-playlist-repeat",
|
||
493 | "media-playlist-shuffle",
|
||
494 | "network-error",
|
||
495 | "network-idle",
|
||
496 | "network-offline",
|
||
497 | "network-receive",
|
||
498 | "network-transmit",
|
||
499 | "network-transmit-receive",
|
||
500 | "printer-error",
|
||
501 | "printer-printing",
|
||
502 | "security-high",
|
||
503 | "security-medium",
|
||
504 | "security-low",
|
||
505 | "software-update-available",
|
||
506 | "software-update-urgent",
|
||
507 | "sync-error",
|
||
508 | "sync-synchronizing",
|
||
509 | "task-due",
|
||
510 | "task-past-due",
|
||
511 | "user-available",
|
||
512 | "user-away",
|
||
513 | "user-idle",
|
||
514 | "user-offline",
|
||
515 | "user-trash-full",
|
||
516 | "weather-clear",
|
||
517 | "weather-clear-night",
|
||
518 | "weather-few-clouds",
|
||
519 | "weather-few-clouds-night",
|
||
520 | "weather-fog",
|
||
521 | "weather-overcast",
|
||
522 | "weather-severe-alert",
|
||
523 | "weather-showers",
|
||
524 | "weather-showers-scattered",
|
||
525 | "weather-snow",
|
||
526 | "weather-storm"
|
||
527 | }; |
||
528 | Set<String> icons = new HashSet<String>(); |
||
529 | for (int i = 0; i < iconNames.length; i++) { |
||
530 | icons.add(iconNames[i]); |
||
531 | } |
||
532 | return icons;
|
||
533 | } |
||
534 | |||
535 | } |