Revision 27785

View differences:

tags/tmp_build/frameworks/_fwAndami/log4j.properties
1
log4j.rootLogger=DEBUG, stdout
2

  
3
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
4
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
5

  
6
# Pattern to output the caller's file name and line number.
7
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
8

  
0 9

  
tags/tmp_build/frameworks/_fwAndami/.cvsignore
1
bin
2
gvsig.log
3
gvSIG
4
web
5
andami.jar
6
keystore
7
java.hprof.txt
8
build-doc
9
*.log
10
cachedir
11
bin-test
0 12

  
tags/tmp_build/frameworks/_fwAndami/schemas/sample-plugins-persistence.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<plugins-status>
3
	<plugin name="gvsig" lastUpdate="237628686">
4
		<xml-entity name="config">
5
			<property name="dataDirectory" value="c:\"/>
6
			<xml-entity>
7
				<property name="dataDirectory" value="c:\"/>
8
				<property name="dataDirectory" value="c:\"/>
9
				<property name="dataDirectory" value="c:\"/>
10
			</xml-entity>
11
		</xml-entity>
12
		<bookmarks>
13
			<bookmark text="Recientes/raster">
14
				<xml-entity>
15
					<property name="projection" value="EPSG:3403"/>
16
					<property name="boundinBox" value="12,12,115,115"/>
17
				</xml-entity>
18
			</bookmark>
19
		</bookmarks>
20
		<windows>
21
			<window id="0" rectangle="0,0,150,150"/>
22
			<window id="2" rectangle="50,50,150,150"/>
23
			<window id="8" rectangle="100,100,150,150"/>
24
			<window id="12" rectangle="150,150,150,150"/>
25
		</windows>
26
	</plugin>
27
	<tool-bars>
28
		<tool-bar name="gvsig.herramientas" x-position="0" y-position="1"/>
29
		<tool-bar name="gvsig.herramientas" x-position="0" y-position="0"/>
30
	</tool-bars>
31
</plugins-status>
0 32

  
tags/tmp_build/frameworks/_fwAndami/schemas/sample-config.xml
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<plugin-config>
3
	<icon src="images/logoGVA.gif" text="gvSIG"/>
4
	<resourceBundle name="text"/>
5
	<import plugin-name="com.iver.cit.gvsig" />
6
	<labelSet class="com.iver.cit.gvsig.gui.View">
7
		<label id="1" size="100"/>
8
		<label id="2" size="230"/>
9
	</labelSet>
10
	<libraries>
11
		<library file="com.iver.cit.gvsig.jar"/>
12
		<library file="wmsclient.jar"/>	
13
	</libraries>
14
	<extensions>
15
		<extension>
16
			<class name="com.iver.cit.gvsig.ProjectExtension"/>
17
			<menu text="Archivo/nuevo_proyecto" 
18
				key="n" mnemonic="n" 
19
				tooltip="nuevo_tooltip"
20
				action-command="NUEVO" icon="images/new.png"/>
21
			<menu text="Archivo/abrir_proyecto" 
22
				key="a" mnemonic="a" 
23
				tooltip="abrir_tooltip"
24
				action-command="ABRIR" icon="images/open.png"/>
25
			<menu text="Archivo/guardar_proyecto" 
26
				key="g" mnemonic="g" 
27
				tooltip="guardar_tooltip"
28
				action-command="GUARDAR" icon="images/save.png"/>
29

  
30
			<toolBar>
31
				<tool icon="images/new.png" tooltip="nuevo_tooltip"
32
					action-command="NUEVO"/>
33
				<tool icon="images/open.png" tooltip="abrir_tooltip"
34
					action-command="ABRIR"/>
35
				<tool icon="images/save.png" tooltip="guardar_tooltip"
36
					action-command="GUARDAR"/>
37

  
38
				<!-- these will be added to the containing toolbar -->
39
				<combo-scale
40
					name="JPEG Quality"
41
					elements="15;30;60;70;80;90;100"
42
					value="80"
43
					action-command="JPEG_QUALITY" />
44

  
45
				<combo-button
46
					name="Copy/paste tools">
47
				  <combo-button-element icon="images/scissor.png" action-command="CUT" />
48
				  <combo-button-element icon="images/paste.png" action-command="PASTE" />
49
				  <combo-button-element icon="images/copy.png" action-command="COPY" />
50
				</combo-button>
51
			</toolBar>
52

  
53
		</extension>
54

  
55
		<extension>
56
			<class name="com.iver.cit.gvsig.ZoomPrev"/>
57
			<menu text="Vista/Zoom_Previo" icon="images/ZoomPrevio.png"/>
58
			<tool-bar name="Herramientas">
59
				<action-tool icon="images/ZoomPrevio.png" action-command="ZOOM_PREV" tooltip="Zoom_Previo" position="11"/>
60
			</tool-bar>
61
			
62
			<!-- these will be added to the status-bar (because they are not contained in any toolbar) -->					
63
			<combo-scale 
64
		  		name="Scale"
65
		  		label="Scale:"
66
		  		elements="1000;2000;5000;10000;25000;50000;100000;200000;500000;1000000;2000000;5000000"
67
	  			value="10000"
68
	  			action-command="CHANGE_SCALE" />
69

  
70
			<combo-button
71
				name="Tool Mode">
72
			  <combo-button-element icon="images/once.png" action-command="USE_ONCE" />
73
			  <combo-button-element icon="images/sticky-tool.png" action-command="UNTIL_CHANGED" />
74
			</combo-button>
75
		</extension>
76
		<extension processing-position="2">
77
			<class name="com.iver.cit.gvsig.ViewControls"/>
78
			<menus>
79
				<menu text="Vista/Zoom_Completo" action-command="FULL" icon="images/MapContents.png" tooltip="Zoom completo a la v?sta"/>
80
				<menu text="Vista/Zoom_Select" action-command="ZOOM_SELECT" icon="image/Select.png"/>
81
				<menu text="Vista/Encuadre" action-command="ENCUADRE" icon="images/encuadre.png"/>
82
				<menu text="Vista/Seleccion_por_tema" action-command="SELECTIONBYSHAPE"/>
83
				<menu text="Vista/configurar_localizador" action-command="CONFIG_LOCATOR"/>		
84
				<menu text="Vista/propiedades" action-command="PROPERTIES"/>
85
			</menus>
86
			<tool-bar name="Herramientas" y-position="1">
87
				<action-tool icon="images/MapContents.png" action-command="FULL" tooltip="Zoom_Completo" position="1"/>
88
				<action-tool icon="images/encuadre.png" action-command="ENCUADRE" tooltip="gestion_encuadre" last="true" position="2"/>			
89
				<selectable-tool group="grupo1" default="true" icon="images/ZoomIn.png" action-command="ZOOM_IN" tooltip="Zoom_M?s" position="3"/>
90
				<selectable-tool group="grupo1" icon="images/ZoomOut.png" action-command="ZOOM_OUT" position="4"/>
91
				<selectable-tool group="grupo1" icon="images/Pan.png" action-command="PAN"  tooltip="Encuadre" position="5"/>
92
				<selectable-tool group="grupo1" icon="images/Identify.png" action-command="INFO"  tooltip="informacion" position="6" />
93
				<selectable-tool group="grupo2" icon="images/Distancia.png" action-command="MEDICION"  tooltip="medir_distancias" position="7"/>
94
				<selectable-tool group="grupo2" icon="images/Poligono16.png" action-command="AREA"  tooltip="medir_area" position="8"/>
95
				<selectable-tool group="grupo2" default="true" icon="images/Select.png" action-command="SELPOINT"  tooltip="seleccionar_por_punto" position="9"/>
96
				<selectable-tool group="grupo2" icon="images/SelEspacial2b.png" action-command="SELRECT"  tooltip="seleccionar_por_rectangulo" position="10"/>
97
			</tool-bar>
98
		</extension>
99
		<extension>
100
			<class name="com.iver.cit.gvsig.ThemeControls"/>
101
			<menu text="Tema/propiedades"/>
102
		</extension>
103
	</extensions>
104

  
105
	<file-extensions>
106
		<file-extension description="DGNfiles" ends-with="dgn" dialog="openLayer">
107
			<class name="com.iver.cit.gvsig.DGNFileExtension"/>
108
		</file-extension>
109
		<file-extension description="Rasterfiles" ends-with="ecw,tif,tiff,jpg,png" dialog="openLayer">
110
			<class name="com.iver.cit.gvsig.RasterFileExtension"/>
111
		</file-extension>
112
	</file-extensions>
113
</plugin-config>
0 114

  
tags/tmp_build/frameworks/_fwAndami/schemas/andami-config.xml
1
<andami-config locale-language="es" locale-country="ES" locale-variant="es" pluginsDirectory="c:\tirar">
2
	<andami update="yes"/>
3
	<plugin name="com.iver.cit.gvsig" update="yes"/>
4
	<plugin name="com.iver.core" update="no"/>
5
	<andami-options>
6
	  <option name="CustomOption1" value="customValue1"/>
7
	  <icon-theme name="DefaultTheme" resource="iconThemes/default" basedir="iconThemes" />
8
	</andami-options>
9
</andami-config>
0 10

  
tags/tmp_build/frameworks/_fwAndami/.project
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>_fwAndami</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
		<buildCommand>
9
			<name>org.eclipse.jdt.core.javabuilder</name>
10
			<arguments>
11
			</arguments>
12
		</buildCommand>
13
		<buildCommand>
14
			<name>org.eclipse.ui.externaltools.ExternalToolBuilder</name>
15
			<triggers>full,incremental,</triggers>
16
			<arguments>
17
				<dictionary>
18
					<key>LaunchConfigHandle</key>
19
					<value>&lt;project&gt;/.externalToolBuilders/Ant.launch</value>
20
				</dictionary>
21
			</arguments>
22
		</buildCommand>
23
		<buildCommand>
24
			<name>de.loskutov.FileSync.FSBuilder</name>
25
			<arguments>
26
			</arguments>
27
		</buildCommand>
28
	</buildSpec>
29
	<natures>
30
		<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
31
		<nature>org.eclipse.jdt.core.javanature</nature>
32
		<nature>org.eclipse.jem.beaninfo.BeanInfoNature</nature>
33
	</natures>
34
</projectDescription>
0 35

  
tags/tmp_build/frameworks/_fwAndami/gvSIG.bat
1
d:
2
cd d:\eclipse\workspace\fwAndami
3
java -cp andami.jar;lib/beans.jar;./lib/castor-0.9.5.3-xml.jar;./lib/crimson.jar;./lib/gvsig-i18n.jar;./lib/iver-utiles.jar;./lib/javaws.jar;lib/JWizardComponent.jar;./lib/log4j-1.2.8.jar;lib/looks-2.0.2.jar;./lib/xerces_2_5_0.jar;./lib/xml-apis.jar -Xmx500M com.iver.andami.Launcher gvSIG gvSIG/extensiones %1
0 4

  
tags/tmp_build/frameworks/_fwAndami/castor.properties
1
org.exolab.castor.indent=true
0 2

  
tags/tmp_build/frameworks/_fwAndami/src/log4j.properties
1
log4j.rootLogger=debug, stdout
2

  
3
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
4
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
5

  
6
# Pattern to output the caller's file name and line number.
7
log4j.appender.stdout.layout.ConversionPattern=%5p [%t] (%F:%L) - %m%n
8

  
0 9

  
tags/tmp_build/frameworks/_fwAndami/src/com/iver/andami/iconthemes/IconThemeZip.java
1
package com.iver.andami.iconthemes;
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(IIconTheme 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

  
tags/tmp_build/frameworks/_fwAndami/src/com/iver/andami/iconthemes/AbstractIconTheme.java
1
/*
2
 * Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
3
 *
4
 * This program is free software; you can redistribute it and/or
5
 * modify it under the terms of the GNU General Public License
6
 * as published by the Free Software Foundation; either version 2
7
 * of the License, or (at your option) any later version.
8
 *
9
 * This program is distributed in the hope that it will be useful,
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * GNU General Public License for more details.
13
 *
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program; if not, write to the Free Software
16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
17
 *
18
 * For more information, contact:
19
 *
20
 *  Generalitat Valenciana
21
 *   Conselleria d'Infraestructures i Transport
22
 *   Av. Blasco Ib��ez, 50
23
 *   46010 VALENCIA
24
 *   SPAIN
25
 *
26
 *      +34 963862235
27
 *   gvsig@gva.es
28
 *      www.gvsig.gva.es
29
 *
30
 *    or
31
 *
32
 *   IVER T.I. S.A
33
 *   Salamanca 50
34
 *   46005 Valencia
35
 *   Spain
36
 *
37
 *   +34 963163400
38
 *   dac@iver.es
39
 */
40

  
41
package com.iver.andami.iconthemes;
42

  
43

  
44
import java.net.URL;
45
import java.util.HashMap;
46

  
47
import javax.swing.ImageIcon;
48

  
49
import org.apache.log4j.Logger;
50

  
51

  
52
/**
53
 * <p>This class represents an icon theme, which is basically a mapping of
54
 * symbolic icon names, and real icons (or icon paths). This is useful to
55
 * change an application's icons in an easy way. An icon theme
56
 * is usually read from disk on start up, but can also be created or
57
 * modified on a later time.</p>
58
 *
59
 * <p>Developers are encouraged to always use the
60
 * <code>get(iconName, fallbackImage)</code> methods to get icons,
61
 * as they ensure that the icons are not overwritten in the theme, but it
62
 * also ensures than an image is got in case the icon was still not
63
 * registered. Note that in this case, the iconName gets registered
64
 * (it is associated with the provided fallbackImage).
65
 * </p>
66
 *
67
 * <p>Developers are encouraged to NOT override icons which are
68
 * present in the theme, as this defeats the purpose of IconThemes.</p>
69
 *
70
 * @author Cesar Martinez Izquierdo <cesar.martinez@iver.es>
71
 */
72
public abstract class AbstractIconTheme implements IIconTheme {
73
	HashMap<String, Object> iconList = new HashMap<String, Object>();
74
	private String name=null;
75
	private String description=null;
76
	private String version="1.0";
77
	private Object resource=null;
78
	IIconTheme defaultTheme = null;
79

  
80

  
81
	/**
82
	 * Abstract method that allows load an a icon. This method will be reimplemented by
83
	 * inherit classes.
84
	 * @param iconName
85
	 * @param resource
86
	 * @return
87
	 */
88
	protected abstract ImageIcon loadIcon(String iconName,Object resource) ;
89

  
90
	/* (non-Javadoc)
91
	 * @see com.iver.andami.iconthemes.IIconTheme#load()
92
	 */
93
	public abstract void load() ;
94

  
95
	/**
96
	 * Returns the logger
97
	 * @return
98
	 */
99
    protected Logger log() {
100
      return Logger.getLogger(this.getClass());
101
    }
102

  
103
    /* (non-Javadoc)
104
	 * @see com.iver.andami.iconthemes.IIconTheme#setDefault(com.iver.andami.iconthemes.AbstractIconTheme)
105
	 */
106
    public void setDefault(IIconTheme def){
107
    	if( def == this ) {
108
    		defaultTheme = null;
109
    	} else {
110
    		defaultTheme = def;
111
    	}
112
    }
113

  
114
    /* (non-Javadoc)
115
	 * @see com.iver.andami.iconthemes.IIconTheme#getDefault()
116
	 */
117
    public IIconTheme getDefault(){
118
    	return defaultTheme;
119
    }
120

  
121
	/* (non-Javadoc)
122
	 * @see com.iver.andami.iconthemes.IIconTheme#exists(java.lang.String)
123
	 */
124
	public boolean exists(String iconName) {
125
		if (iconList.containsKey(iconName)) {
126
			return true;
127
		}
128
		if (defaultTheme !=null && defaultTheme.exists(iconName)){
129
			return true;
130
		}
131
		return false;
132
	}
133

  
134
	/* (non-Javadoc)
135
	 * @see com.iver.andami.iconthemes.IIconTheme#get(java.lang.String)
136
	 */
137
	public ImageIcon get(String iconName) {
138
		return get(iconName,null);
139
	}
140

  
141
	/* (non-Javadoc)
142
	 * @see com.iver.andami.iconthemes.IIconTheme#get(java.lang.String, java.lang.ClassLoader)
143
	 */
144
	public ImageIcon get(String iconName, ClassLoader loader) {
145

  
146
		if( loader != null && iconName.contains(".") ) {
147
			Logger.getLogger(this.getClass()).warn("Loading icon from resource: '"+ iconName+"'");
148
			return toImageIcon(loader.getResource(iconName),iconName);
149
		}
150

  
151
		if (defaultTheme==null ){
152
			Object object = iconList.get(iconName);
153
			if (object!=null) {
154
				return toImageIcon(object,iconName);
155
			}
156
			return getNoIcon();
157
		}
158
		Object object = iconList.get(iconName);
159
		if (object!=null) {
160
			return toImageIcon(object,iconName);
161
		}
162
		if( defaultTheme.exists(iconName)) {
163
			return  defaultTheme.get(iconName, null);
164
		}
165
		return getNoIcon();
166
	}
167

  
168
	public ImageIcon getNoIcon() {
169
		Object object = iconList.get("no-icon");
170
		if (object!=null){
171
			return toImageIcon(object,"no-icon");
172
		}
173
		if (defaultTheme==null ){
174
			return null;
175
		}
176
		return defaultTheme.getNoIcon();
177
	}
178

  
179

  
180
	protected ImageIcon toImageIcon(Object object,String iconName){
181
		if (object == null){
182
			return null;
183
		}
184
		if( object instanceof URL ) {
185
			return new ImageIcon((URL)object);
186
		}
187
		ImageIcon icon = loadIcon(iconName,object);
188
		return icon;
189
	}
190

  
191
	/* (non-Javadoc)
192
	 * @see com.iver.andami.iconthemes.IIconTheme#registerDefault(java.lang.String, javax.swing.ImageIcon)
193
	 */
194
	public void registerDefault(String iconName, ImageIcon image) {
195
		if (defaultTheme!=null)	defaultTheme.register(iconName, image);
196
		else register(iconName, image);
197
	}
198

  
199
	/* (non-Javadoc)
200
	 * @see com.iver.andami.iconthemes.IIconTheme#registerDefault(java.lang.String, java.lang.Object)
201
	 */
202
	public void registerDefault(String iconName, Object resource) {
203
		if (defaultTheme!=null)defaultTheme.register(iconName, resource);
204
		else register(iconName, resource);
205
	}
206

  
207
	/* (non-Javadoc)
208
	 * @see com.iver.andami.iconthemes.IIconTheme#register(java.lang.String, javax.swing.ImageIcon)
209
	 */
210
	public void register(String iconName, ImageIcon image) {
211
		iconList.put(iconName, image);
212
	}
213

  
214
	/* (non-Javadoc)
215
	 * @see com.iver.andami.iconthemes.IIconTheme#register(java.lang.String, java.lang.Object)
216
	 */
217
	public void register(String iconName, Object resource) {
218
		iconList.put(iconName, resource);
219
	}
220

  
221
	/* (non-Javadoc)
222
	 * @see com.iver.andami.iconthemes.IIconTheme#getName()
223
	 */
224
	public String getName() {
225
		return name;
226
	}
227

  
228
	/* (non-Javadoc)
229
	 * @see com.iver.andami.iconthemes.IIconTheme#setName(java.lang.String)
230
	 */
231
	public void setName(String themeName) {
232
		name = themeName;
233
	}
234

  
235
	/* (non-Javadoc)
236
	 * @see com.iver.andami.iconthemes.IIconTheme#getDescription()
237
	 */
238
	public String getDescription() {
239
		return description;
240
	}
241

  
242
	/* (non-Javadoc)
243
	 * @see com.iver.andami.iconthemes.IIconTheme#setDescription(java.lang.String)
244
	 */
245
	public void setDescription(String description) {
246
		this.description = description;
247
	}
248

  
249
	/* (non-Javadoc)
250
	 * @see com.iver.andami.iconthemes.IIconTheme#getVersion()
251
	 */
252
	public String getVersion() {
253
		return version;
254
	}
255

  
256
	/* (non-Javadoc)
257
	 * @see com.iver.andami.iconthemes.IIconTheme#setVersion(java.lang.String)
258
	 */
259
	public void setVersion(String version) {
260
		this.version = version;
261
	}
262

  
263
	/* (non-Javadoc)
264
	 * @see com.iver.andami.iconthemes.IIconTheme#getResource()
265
	 */
266
	public Object getResource() {
267
		return resource;
268
	}
269
	/* (non-Javadoc)
270
	 * @see com.iver.andami.iconthemes.IIconTheme#setResource(java.lang.Object)
271
	 */
272
	public void setResource(Object resource) {
273
		this.resource = resource;
274
	}
275

  
276
	/**
277
	 * Returns the name of the icon theme
278
	 */
279
	public String toString() {
280
		return getName();
281
	}
282

  
283
	/* (non-Javadoc)
284
	 * @see com.iver.andami.iconthemes.IIconTheme#getURL(java.lang.String)
285
	 *
286
	 */
287
	public URL getURL(String iconName) {
288
		Object object = defaultTheme.get(iconName);
289
		if (object !=null && object instanceof URL)
290
			return (URL) object;
291
		return null;
292
	}
293

  
294

  
295
}
0 296

  
tags/tmp_build/frameworks/_fwAndami/src/com/iver/andami/iconthemes/IIconTheme.java
1
package com.iver.andami.iconthemes;
2

  
3
import java.net.URL;
4

  
5
import javax.swing.ImageIcon;
6

  
7
public interface IIconTheme {
8

  
9
	/**
10
	 * Load all icons from the IconTheme
11
	 */
12
	public abstract void load();
13

  
14
	public abstract void setDefault(IIconTheme def);
15

  
16
	public abstract IIconTheme getDefault();
17

  
18
	/**
19
	 * Returns <code>true</code> if the icon theme contains a mapping for the
20
	 * specified iconName.
21
	 *
22
	 * @param iconName The key to check if it has been registered in this
23
	 * IconTheme
24
	 *
25
	 * @return <code>true</code> if this IconTheme contains
26
	 * <code>iconName</code>, <code>false</code> otherwise.
27
	 */
28
	public abstract boolean exists(String iconName);
29

  
30
	/**
31
	 * Gets the ImageIcon associated with the provided key, if the key
32
	 * is present in the theme, or returns <code>null</code> otherwise.
33
	 *
34
	 * @param iconName
35
	 * 			The key whose associated icon is to be retrieved
36
	 *
37
	 * @return
38
	 * 			The icon associated with the provided key, or
39
	 * <code>null</code> otherwise.
40
	 */
41
	public abstract ImageIcon get(String iconName);
42

  
43
	/**
44
	 * Gets the ImageIcon associated with the provided key, if the key
45
	 * is present in the theme, or returns <code>null</code> otherwise.
46
	 *
47
	 * @param iconName
48
	 * 			The key whose associated icon is to be retrieved
49
	 *
50
	 * @param loader
51
	 * 			Class loader for localice icons when iconName is a
52
	 * 			resource name.
53
	 *
54
	 * @return
55
	 * 			The icon associated with the provided key, or
56
	 * <code>no-icon</code> otherwise.
57
	 */
58
	public abstract ImageIcon get(String iconName, ClassLoader loader);
59

  
60
	/**
61
	 * <p>Register in this theme the provided iconName and the associated
62
	 * image. Developers
63
	 * must not override icons already registered, as this defeats the
64
	 * purpose of the IconTheme. Therefore, use the <code>exists</code>
65
	 * method before using <code>register</code>, to ensure the icon
66
	 * is not previously registered.</p>
67
	 *
68
	 * @param iconName The name of the icon to register. It is the name
69
	 * that will be used later to retrieve the icon.
70
	 *
71
	 * @param image The image that is going to be associated with the
72
	 * provided icon name.
73
	 */
74
	public abstract void registerDefault(String iconName, ImageIcon image);
75

  
76
	/**
77
	 * <p>Register in this theme the provided iconName and the associated
78
	 * resource. Developers must not override icons already registered,
79
	 * as this defeats the purpose of the IconTheme. Therefore, use the
80
	 * <code>exists</code> method before using <code>register</code>, to
81
	 * ensure the icon is not previously registered.</p>
82
	 *
83
	 * @param iconName The name of the icon to register. It is the name
84
	 * 	that will be used later to retrieve the icon.
85
	 * @param resource The resource that is going to be asssocioated with the providad
86
	 * 	icon name
87
	 */
88
	public abstract void registerDefault(String iconName, Object resource);
89

  
90
	/**
91
	 * <p>Register in this theme the provided iconName and the associated
92
	 * image. Developers
93
	 * must not override icons already registered, as this defeats the
94
	 * purpose of the IconTheme. Therefore, use the <code>exists</code>
95
	 * method before using <code>register</code>, to ensure the icon
96
	 * is not previously registered.</p>
97
	 *
98
	 * @param iconName The name of the icon to register. It is the name
99
	 * that will be used later to retrieve the icon.
100
	 *
101
	 * @param image The image that is going to be associated with the
102
	 * provided icon name.
103
	 */
104
	public abstract void register(String iconName, ImageIcon image);
105

  
106
	/**
107
	 * <p>Register in this theme the provided iconName and the associated
108
	 * resource. Developers must not override icons already registered,
109
	 * as this defeats the purpose of the IconTheme. Therefore, use the
110
	 * <code>exists</code> method before using <code>register</code>, to
111
	 * ensure the icon is not previously registered.</p>
112
	 *
113
	 * @param iconName The name of the icon to register. It is the name
114
	 * 	that will be used later to retrieve the icon.
115
	 * @param resource The resource that is going to be asssocioated with the providad
116
	 * 	icon name
117
	 */
118
	public abstract void register(String iconName, Object resource);
119

  
120
	/**
121
	 * Gets the theme name.
122
	 * @return theme name
123
	 */
124
	public abstract String getName();
125

  
126
	/**
127
	 * Sets the theme name.
128
	 *
129
	 * @param themeName
130
	 */
131
	public abstract void setName(String themeName);
132

  
133
	/**
134
	 * Gets the theme description.
135
	 *
136
	 * @return The description of this theme.
137
	 */
138
	public abstract String getDescription();
139

  
140
	/**
141
	 * Sets the theme description. It should be a short description
142
	 * (around 20-30 words), including the highlights of the theme,
143
	 * the author and maybe its email address or a link the the theme's
144
	 * homepage.
145
	 *
146
	 * @param description
147
	 */
148
	public abstract void setDescription(String description);
149

  
150
	/**
151
	 * Returns the theme version. It defaults to "1.0".
152
	 *
153
	 * @return The version of this theme.
154
	 */
155
	public abstract String getVersion();
156

  
157
	/**
158
	 * Set the theme version.
159
	 *
160
	 * @param version
161
	 */
162
	public abstract void setVersion(String version);
163

  
164
	/**
165
	 * Gets the Object which contains physically contains this theme on disk.
166
	 * It may be a ZipFile or JarFile, or a directory.
167
	 *
168
	 * @return
169
	 */
170
	public abstract Object getResource();
171

  
172
	/**
173
	 * Sets the file which contains physically contains this theme on disk.
174
	 * It may be a ZipFile or JarFile, or a directory.
175
	 *
176
	 * @return
177
	 */
178
	public abstract void setResource(Object resource);
179

  
180
	/**
181
	 * Return the URL which is currently associated with the
182
	 * provided icon name, if this icon was registered as an
183
	 * URL, or <code>null</code> if it is not present in the theme
184
	 * or it was registered as an IconImage.
185
	 *
186
	 * @param iconName
187
	 * @return The URL which is currently associated with the
188
	 * provided icon name, if this icon was registered as an
189
	 * URL, or <code>null</code> if it is not present in the theme
190
	 * or it was registered as an IconImage.
191
	 *
192
	 * @deprecated
193
	 */
194
	public abstract URL getURL(String iconName);
195

  
196
	public ImageIcon getNoIcon();
197

  
198
}
0 199

  
tags/tmp_build/frameworks/_fwAndami/src/com/iver/andami/iconthemes/IconThemeMemory.java
1
package com.iver.andami.iconthemes;
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(IIconTheme 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

  
tags/tmp_build/frameworks/_fwAndami/src/com/iver/andami/iconthemes/IconThemeManager.java
1
package com.iver.andami.iconthemes;
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 IIconTheme def;
34
	private IIconTheme current;
35
	private File themesDir = null;
36
	ArrayList<IIconTheme> themes=new ArrayList<IIconTheme>();
37
	private final String themeDefinitionFile = "theme.xml";
38
	private static IconThemeManager iconThemeManager = null;
39

  
40
	public static IconThemeManager getIconThemeManager(){
41
		if (iconThemeManager == null){
42
			iconThemeManager = new IconThemeManager();
43
		}
44
		return iconThemeManager;
45
	}
46

  
47

  
48

  
49

  
50
	/**
51
	 * Default constructor. Creates a iconThemeMemory by default and assigns it
52
	 * like default and current. The default theme is add to the themes ArrayList.
53
	 */
54
	public IconThemeManager(){
55
		IconThemeMemory aux = new IconThemeMemory(null);
56
		def = aux;
57
		def.setName("Default");
58
		current = aux;
59
		themes.add(def);
60

  
61
	}
62

  
63
	/**
64
	 * Gets the default theme
65
	 * @return the default theme.
66
	 */
67
	public IIconTheme getDefault(){
68
		return def;
69
	}
70

  
71
	/**
72
	 * Sets the iconTheme like current theme
73
	 * @param iconTheme
74
	 */
75
	public void setCurrent(IIconTheme iconTheme){
76
		if(themes.contains(iconTheme)){
77
			current = iconTheme;
78
			//saveConfig(current);
79
		}else{
80
			register(iconTheme);
81
			current = iconTheme;
82
			//saveConfig(current);
83
		}
84
	}
85

  
86
	/**
87
	 * Gets the current theme
88
	 * @return current the current theme
89
	 */
90
	public IIconTheme getCurrent(){
91
		return current;
92
	}
93

  
94
	/**
95
	 * Stores a icon theme that receives like a parametre
96
	 * @param iconTheme
97
	 */
98
	public void register(IIconTheme iconTheme){
99
		themes.add(iconTheme);
100
		iconTheme.setDefault(def);
101
	}
102

  
103
	/**
104
	 * Returns the theme that has been registered with the name that receives like
105
	 * parameter
106
	 * @param themeName
107
	 * @return the theme that contains like name in its properties the parameter
108
	 */
109
	public IIconTheme getTheme(String themeName){
110
		for(int i = 0; i<themes.size();i++){
111
			if(themes.get(i).getName().equals(themeName)) return themes.get(i);
112
		}
113
		return null;
114
	}
115

  
116
	/**
117
	 * Set the directory to read the icon themes.
118
	 *
119
	 * @param themesDir The directory in which the icon themes
120
	 * are stored
121
	 *
122
	 * @throws FileNotFoundException If the provided directory does not
123
	 * exist or is not a directory
124
	 */
125
	public void setThemesDir(File themesDir) throws FileNotFoundException {
126
		if (!themesDir.exists() || !themesDir.isDirectory())
127
			throw new FileNotFoundException();
128
		this.themesDir = themesDir;
129
	}
130

  
131
	/**
132
	 * Gets the themes directory
133
	 * @return
134
	 */
135
	public File getThemesDir() {
136
		return themesDir;
137
	}
138

  
139
	/**
140
	 *
141
	 * Save the provided theme as default in the configuration file.
142
	 * This will not change the default theme for this session, it will
143
	 * just write the new selection in the configuration file (for
144
	 * the next session).
145
	 *
146
	 * @param info The theme to be set as default for next session.
147
	 */
148
	private void saveConfig(IIconTheme info) {
149
		if (getThemesDir()==null || info==null || info.getResource()==null)
150
			return;
151
		com.iver.andami.config.generate.AndamiOptions options = Launcher.getAndamiConfig().getAndamiOptions();
152
		if (options==null) {
153
			options = new com.iver.andami.config.generate.AndamiOptions();
154
			Launcher.getAndamiConfig().setAndamiOptions(options);
155
		}
156
		com.iver.andami.config.generate.IconTheme themeConfig = options.getIconTheme();
157
		if (themeConfig==null) {
158
			themeConfig = new com.iver.andami.config.generate.IconTheme();
159
			options.setIconTheme(themeConfig);
160
		}
161
		themeConfig.setBasedir(getThemesDir().getPath());
162
		themeConfig.setName(info.getName());
163
		themeConfig.setDescription(info.getDescription());
164
		themeConfig.setVersion(info.getVersion());
165
		if (info.getResource()!=null) {
166
			if (info.getResource() instanceof File) {
167
				File resource = (File) info.getResource();
168
				themeConfig.setResource(resource.getName());
169
			}
170
			else if (info.getResource() instanceof ZipFile) {
171
				ZipFile resource = (ZipFile) info.getResource();
172
				themeConfig.setResource(resource.getName());
173
			}
174
		}
175
	}
176

  
177
	/**
178
	 * Gets the Icon theme stored in the configuration
179
	 * @return IIconTheme
180
	 */
181
	public IIconTheme getIconThemeFromConfig() {
182
		if (Launcher.getAndamiConfig().getAndamiOptions()==null
183
				|| Launcher.getAndamiConfig().getAndamiOptions().getIconTheme()==null
184
				|| Launcher.getAndamiConfig().getAndamiOptions().getIconTheme().getResource()==null)
185
			return null;
186

  
187
		com.iver.andami.config.generate.IconTheme selectedTheme = Launcher.getAndamiConfig().getAndamiOptions().getIconTheme();
188

  
189
		try {
190
			setThemesDir(new File(selectedTheme.getBasedir()));
191
			File themeFile = new File(selectedTheme.getBasedir()+File.separator+selectedTheme.getResource());
192
			if (themeFile.exists()) {
193
				IIconTheme info;
194
				try {
195
					// try to load a ZIPPED theme
196
					ZipFile zipfile = new ZipFile(selectedTheme.getResource());
197
					info = readInfoFromZip(zipfile);
198
					return info;
199
				} catch (ZipException e) {
200
					// ZIPPED theme failed, try to load from directory
201
					if (themeFile.isFile() && themeFile.canRead()) {
202
						info = readInfoFromDir(new File(selectedTheme.getResource()));
203
						return info;
204
					}
205
				} catch (IOException e) {}
206
			}
207
		} catch (FileNotFoundException e1) {}
208
		return null;
209
	}
210

  
211
	/**
212
	 * Gets the base name of a entry
213
	 * @param fullname
214
	 * @return
215
	 */
216
	private String basename(String fullname) {
217
		String[] parts = fullname.split(File.separator+"|/");
218
		return parts[parts.length-1];
219
	}
220

  
221
	/**
222
	 * Returns an icon theme from a file that receives like a parameter
223
	 * @param zipFile
224
	 * @return
225
	 * @throws ZipException
226
	 * @throws IOException
227
	 */
228
	private IconThemeZip readInfoFromZip(File zipFile) throws ZipException, IOException {
229
		return readInfoFromZip(new ZipFile(zipFile));
230
	}
231

  
232
	/**
233
	 * Returns an icon theme from a zip file that receives like a parameter
234
	 * @param zipFile
235
	 * @return IconThemeZip
236
	 * @throws IOException
237
	 */
238
	private IconThemeZip readInfoFromZip(ZipFile zipFile) throws IOException {
239
		IconThemeZip themeInfo;
240
		Enumeration entries = zipFile.entries();
241
		ZipEntry xmlEntry=null, dirEntry=null;
242
		// search for theme.xml and the directory names
243
		while (entries.hasMoreElements() && (xmlEntry==null||dirEntry==null)) {
244
			ZipEntry entry = (ZipEntry) entries.nextElement();
245
			if (entry.isDirectory()) {
246
				dirEntry = entry;
247
			}
248
			if (basename(entry.getName()).equals(themeDefinitionFile)) {
249
				xmlEntry = entry;
250
			}
251
		}
252

  
253
		try {
254
			// try with the XML file
255
			if (xmlEntry!=null) {
256
				themeInfo = readXML(zipFile.getInputStream(xmlEntry));
257
				if (themeInfo.getDescription()==null)
258
					themeInfo.setDescription(zipFile.getName());
259
				if (themeInfo.getName()==null)
260
					themeInfo.setName(themeInfo.getDescription());
261
				themeInfo.setResource(zipFile);
262
				return themeInfo;
263
			}
264
		} catch (XmlPullParserException e) {
265
			PluginServices.getLogger().error("Error loading theme "+zipFile.getName()+". ", e);
266
		}
267

  
268
		themeInfo = new IconThemeZip(def);
269
		themeInfo.setResource(zipFile);
270
		// now try with the directory
271
		if (dirEntry!=null) {
272
			themeInfo.setName(dirEntry.getName());
273
			themeInfo.setDescription(dirEntry.getName());
274
			return themeInfo;
275
		}
276
		else { // otherwise just use the zipName
277
			themeInfo.setName(zipFile.getName());
278
			themeInfo.setDescription(zipFile.getName());
279
			return themeInfo;
280
		}
281
	}
282

  
283
	/**
284
	 * Read the properties of IconThemeZip from a XML
285
	 * @param xmlStream
286
	 * @return IconThemeZip
287
	 * @throws XmlPullParserException
288
	 * @throws IOException
289
	 */
290
	private IconThemeZip readXML(InputStream xmlStream) throws XmlPullParserException, IOException {
291
		KXmlParser parser = new KXmlParser();
292
		// we use null encoding, in this way kxml2 tries to detect the encoding
293
		parser.setInput(xmlStream, null);
294
		IconThemeZip themeInfo=new IconThemeZip(def);
295
		for (parser.next(); parser.getEventType()!=KXmlParser.END_DOCUMENT; parser.next()) {
296
			// este bucle externo recorre las etiquetas de primer y segundo nivel
297
			if (parser.getEventType()==KXmlParser.START_TAG) {
298
				if (parser.getName().equals("name")) {
299
					themeInfo.setName(parser.nextText());
300
				}
301
				else if (parser.getName().equals("description")) {
302
					themeInfo.setDescription(parser.nextText());
303
				}
304
				else if (parser.getName().equals("version")) {
305
					themeInfo.setVersion(parser.nextText());
306
				}
307
			}
308
		}
309
		return themeInfo;
310
	}
311

  
312
	/**
313
	 * Returns a IconThemeDir from a directory
314
	 * @param dir
315
	 * @return
316
	 */
317
	private IconThemeDir readInfoFromDir(File dir){
318
		File themeDefinition = new File(dir + File.separator + themeDefinitionFile);
319
		IconThemeDir themeInfo;
320
		try {
321
			// try reading the XML file
322
			if (themeDefinition.exists() && themeDefinition.isFile()) {
323
				themeInfo = readXMLDir(new FileInputStream(themeDefinition));
324
				if (themeInfo.getDescription()==null)
325
					themeInfo.setDescription(dir.getName());
326
				if (themeInfo.getName()==null)
327
					themeInfo.setName(themeInfo.getDescription());
328
				themeInfo.setResource(dir);
329
				return themeInfo;
330
			}
331
		} catch (IOException e) {}
332
		catch (XmlPullParserException e) {
333
			e.printStackTrace();
334
		}
335
		// the XML parsing failed, just show the dir name
336
		themeInfo = new IconThemeDir(def);
337
		themeInfo.setName(dir.getName());
338
		themeInfo.setDescription(dir.getName());
339
		themeInfo.setResource(dir);
340
		return themeInfo;
341
	}
342

  
343
	/**
344
	 * Read the properties of IconThemeDir from a XML
345
	 * @param xmlStream
346
	 * @return
347
	 * @throws XmlPullParserException
348
	 * @throws IOException
349
	 */
350
	private IconThemeDir readXMLDir(InputStream xmlStream) throws XmlPullParserException, IOException {
351
		KXmlParser parser = new KXmlParser();
352
		// we use null encoding, in this way kxml2 tries to detect the encoding
353
		parser.setInput(xmlStream, null);
354
		IconThemeDir themeInfo=new IconThemeDir(def);
355
		for (parser.next(); parser.getEventType()!=KXmlParser.END_DOCUMENT; parser.next()) {
356
			// este bucle externo recorre las etiquetas de primer y segundo nivel
357
			if (parser.getEventType()==KXmlParser.START_TAG) {
358
				if (parser.getName().equals("name")) {
359
					themeInfo.setName(parser.nextText());
360
				}
361
				else if (parser.getName().equals("description")) {
362
					themeInfo.setDescription(parser.nextText());
363
				}
364
				else if (parser.getName().equals("version")) {
365
					themeInfo.setVersion(parser.nextText());
366
				}
367
			}
368
		}
369
		return themeInfo;
370
	}
371

  
372
	/*
373
	 *  (non-Javadoc)
374
	 * @see java.util.Collection#size()
375
	 */
376
	public int size() {
377
		return themes.size();
378
	}
379
	/*
380
	 *  (non-Javadoc)
381
	 * @see java.util.Collection#isEmpty()
382
	 */
383
	public boolean isEmpty() {
384
		if (themes.size()==0)return true;
385
		else return false;
386
	}
387

  
388
	/*
389
	 *  (non-Javadoc)
390
	 * @see java.util.Collection#contains(java.lang.Object)
391
	 */
392
	public boolean contains(Object o) {
393
		return themes.contains(o);
394
	}
395

  
396
	/*
397
	 *  (non-Javadoc)
398
	 * @see java.lang.Iterable#iterator()
399
	 */
400
	public Iterator iterator() {
401
		return themes.iterator();
402
	}
403

  
404
	/*
405
	 *  (non-Javadoc)
406
	 * @see java.util.Collection#toArray()
407
	 */
408
	public Object[] toArray() {
409
		return themes.toArray();
410
	}
411

  
412
	/*
413
	 *  (non-Javadoc)
414
	 * @see java.util.Collection#toArray(Object[] a)
415
	 */
416
	public Object[] toArray(Object[] a) {
417
		return themes.toArray(a);
418
	}
419

  
420
	/*
421
	 *  (non-Javadoc)
422
	 * @see java.util.Collection#remove(java.lang.Object)
423
	 */
424
	public boolean add(Object o) {
425
		return themes.add((IIconTheme) o);
426
	}
427

  
428
	/*
429
	 *  (non-Javadoc)
430
	 * @see java.util.Collection#remove(java.lang.Object)
431
	 */
432
	public boolean remove(Object o) {
433
		return themes.remove(o);
434
	}
435

  
436
	/*
437
	 *  (non-Javadoc)
438
	 * @see java.util.Collection#containsAll(Collection)
439
	 */
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff