root / branches / v2_0_0_prep / frameworks / _fwAndami / src / org / gvsig / tools / swing / icontheme / impl / DefaultIconThemeManager.java @ 38564
History | View | Annotate | Download (2.6 KB)
1 |
package org.gvsig.tools.swing.icontheme.impl; |
---|---|
2 |
|
3 |
import java.io.File; |
4 |
import java.util.HashMap; |
5 |
import java.util.Iterator; |
6 |
import java.util.Map; |
7 |
|
8 |
import org.gvsig.tools.observer.ComplexObserver; |
9 |
import org.gvsig.tools.observer.Observable; |
10 |
import org.gvsig.tools.swing.icontheme.IconTheme; |
11 |
import org.gvsig.tools.swing.icontheme.IconThemeManager; |
12 |
import org.gvsig.tools.util.FolderSet; |
13 |
import org.gvsig.tools.util.impl.DefaultFolderSet; |
14 |
|
15 |
public class DefaultIconThemeManager implements IconThemeManager , ComplexObserver{ |
16 |
private static IconThemeManager iconThemeManager = null; |
17 |
|
18 |
private IconTheme defaultTheme = null; |
19 |
private IconTheme currentTheme = null; |
20 |
private Map<String, IconTheme> themes = null; |
21 |
private FolderSet repository = null; |
22 |
|
23 |
public static IconThemeManager getIconThemeManager(){ |
24 |
if (iconThemeManager == null){ |
25 |
iconThemeManager = new DefaultIconThemeManager();
|
26 |
} |
27 |
return iconThemeManager;
|
28 |
} |
29 |
|
30 |
public DefaultIconThemeManager() {
|
31 |
this.defaultTheme = new BaseIconTheme(); |
32 |
this.currentTheme = this.defaultTheme; |
33 |
this.themes = null; |
34 |
this.repository = new DefaultFolderSet(); |
35 |
this.repository.addObserver(this); |
36 |
} |
37 |
|
38 |
public IconTheme getDefault() {
|
39 |
return this.defaultTheme; |
40 |
} |
41 |
|
42 |
public void setCurrent(IconTheme iconTheme) { |
43 |
this.defaultTheme = iconTheme;
|
44 |
} |
45 |
|
46 |
public IconTheme getCurrent() {
|
47 |
return this.currentTheme; |
48 |
} |
49 |
|
50 |
public IconTheme get(String themeID) { |
51 |
return this.get(themeID); |
52 |
} |
53 |
|
54 |
public Iterator<IconTheme> iterator() { |
55 |
return this.getThemes().values().iterator(); |
56 |
} |
57 |
|
58 |
public boolean contains(IconTheme theme) { |
59 |
return this.getThemes().containsValue(theme); |
60 |
} |
61 |
|
62 |
public boolean add(IconTheme theme) { |
63 |
this.getThemes().put(theme.getID(), theme);
|
64 |
return true; |
65 |
} |
66 |
|
67 |
public boolean remove(IconTheme theme) { |
68 |
return this.getThemes().remove(theme)==null ? false: true; |
69 |
} |
70 |
|
71 |
public void clear() { |
72 |
this.themes = null; |
73 |
} |
74 |
|
75 |
public FolderSet getRepository() {
|
76 |
return this.repository; |
77 |
} |
78 |
|
79 |
public void update(Observable observable, Object notification) { |
80 |
if( observable != this.repository ) { |
81 |
return;
|
82 |
} |
83 |
this.themes = null; |
84 |
} |
85 |
|
86 |
private Map<String, IconTheme> getThemes() { |
87 |
if( this.themes != null ) { |
88 |
return this.themes; |
89 |
} |
90 |
Map<String, IconTheme> themes = new HashMap<String, IconTheme>(); |
91 |
File[] folders = this.repository.listFiles(); |
92 |
for( int i=0; i<folders.length; i++ ) { |
93 |
if( folders[i].isDirectory() ) {
|
94 |
FolderIconTheme theme = new FolderIconTheme(this.getDefault()); |
95 |
try {
|
96 |
theme.load(folders[i]); |
97 |
themes.put(theme.getID(), theme); |
98 |
} catch( IllegalArgumentException ex) { |
99 |
// Do nothing
|
100 |
} |
101 |
} |
102 |
} |
103 |
this.themes = themes;
|
104 |
return themes;
|
105 |
} |
106 |
} |