Revision 11026 trunk/frameworks/_fwAndami/src/com/iver/andami/iconthemes/IconThemeManager.java

View differences:

IconThemeManager.java
44 44
import java.io.File;
45 45
import java.io.FileInputStream;
46 46
import java.io.FileNotFoundException;
47
import java.io.FilenameFilter;
47 48
import java.io.IOException;
48 49
import java.io.InputStream;
50
import java.net.MalformedURLException;
49 51
import java.util.ArrayList;
50 52
import java.util.Enumeration;
51 53
import java.util.zip.ZipEntry;
......
55 57
import org.kxml2.io.KXmlParser;
56 58
import org.xmlpull.v1.XmlPullParserException;
57 59

  
60
import sun.security.action.GetIntegerAction;
61

  
58 62
/**
59 63
 * <p>This class deals with icon themes, it understands the on-disk theme
60 64
 * format, it is able to list the availabe themes, to get the default
......
75 79
 *
76 80
 */
77 81
public class IconThemeManager {
78
	protected File themesDir = null;
79
	protected final String themeDefinitionFile = "theme.xml";
82
	private File themesDir = null;
83
	private final String themeDefinitionFile = "theme.xml";
80 84

  
81 85
	/**
82 86
	 * 
......
88 92
		this.themesDir = themesDir;	
89 93
	}
90 94
	
95
	
96
	public IconTheme get(String themeName) {
97
		IconThemeInfo[] themeList = list();
98
		for (int i=0; i<themeList.length; i++) {
99
			if (themeList[i].getName().equals(themeName)) {
100
				return get(themeList[i]);
101
			}
102
		}
103
		return null;
104
	}
105
	
106
	public IconTheme get(IconThemeInfo themeInfo) {
107
		IconTheme theme = new IconTheme(themeInfo);
108
		if (themeInfo.getResource().isDirectory()) {
109
			File basedir = themeInfo.getResource();
110

  
111
			//TODO: crear el filtro de im?genes
112
			File[] imageList = basedir.listFiles(new FilenameFilter() {
113
				public boolean accept(File dir, String fileName) {
114
					String extension = "";
115
					int pointPos = fileName.lastIndexOf(".");
116
					if (pointPos>0 && pointPos < (fileName.length()-1) )
117
						extension = fileName.substring(pointPos+1).toLowerCase();
118
					if ( extension.equals("jpg") || extension.equals("jpeg")
119
							|| extension.equals("png")
120
							|| extension.equals("gif")
121
							
122
							)
123
						return true;
124
					else
125
						return false;
126
				}
127
			});
128
			
129
			int pointPos;
130
			String name;
131
			for (int i=imageList.length-1; i>=0; i--) {
132
				pointPos = imageList[i].getName().lastIndexOf(".");
133
				name = imageList[i].getName().substring(0, pointPos);
134
				try {
135
					theme.register(name, imageList[i].toURL());
136
					System.out.println("registerning "+name+": "+imageList[i].toURL());
137
				} catch (MalformedURLException e) {}
138
			}
139
		}
140
		else {
141
			
142
		}
143
		return theme;
144
	}
145
	
91 146
	/**
92 147
	 * 
93 148
	 * @return
......
217 272
		return parts[parts.length-1];
218 273
	}
219 274
	
275
	public File getThemesPath() {
276
		return themesDir;
277
	}
220 278
	
279
	public void setThemesPath(File themesDir) {
280
		this.themesDir = themesDir;
281
	}
282
	
283
	public IconTheme getDefault() {
284
		return new IconTheme(new IconThemeInfo());
285
		// TODO
286
	}
287
	
288
	public void setDefault(IconThemeInfo iconTheme) {
289
		// TODO
290
	}
291
	
292
public void setDefault(IconTheme iconTheme) {
293
		setDefault(iconTheme.getInfo());
294
	}
221 295
}

Also available in: Unified diff