Revision 17491 trunk/extensions/extRasterTools-SE/src/org/gvsig/fmap/raster/util/Configuration.java

View differences:

Configuration.java
19 19
package org.gvsig.fmap.raster.util;
20 20

  
21 21
import java.util.ArrayList;
22
import java.util.EventObject;
22
import java.util.HashMap;
23 23
import java.util.Iterator;
24 24

  
25
import org.gvsig.raster.util.ConfigurationListener;
26 25

  
27 26
import com.iver.andami.PluginServices;
28 27
import com.iver.utiles.XMLEntity;
......
55 54
	static private Configuration singleton              = new Configuration();
56 55
	private ArrayList            actionCommandListeners = new ArrayList();
57 56
	private XMLEntity            xml                    = null;
57
	private HashMap              hashMap                = new HashMap();
58 58

  
59 59
	/**
60 60
	 * Constructor privado. Nos aseguramos de que nadie pueda crear una instancia
......
72 72
	 * @return
73 73
	 */
74 74
	static public Boolean getValue(String key, Boolean defaultValue) {
75
		if (singleton.hashMap.get(key) == null)
76
			singleton.hashMap.put(key, defaultValue);
75 77
		try {
76 78
			return Boolean.valueOf(getXMLEntity().getStringProperty(key));
77 79
		} catch (Exception e) {
......
87 89
	 * @return
88 90
	 */
89 91
	static public Double getValue(String key, Double defaultValue) {
92
		if (singleton.hashMap.get(key) == null)
93
			singleton.hashMap.put(key, defaultValue);
90 94
		try {
91 95
			return Double.valueOf(getXMLEntity().getStringProperty(key));
92 96
		} catch (Exception e) {
......
102 106
	 * @return
103 107
	 */
104 108
	static public Float getValue(String key, Float defaultValue) {
109
		if (singleton.hashMap.get(key) == null)
110
			singleton.hashMap.put(key, defaultValue);
105 111
		try {
106 112
			return Float.valueOf(getXMLEntity().getStringProperty(key));
107 113
		} catch (Exception e) {
......
117 123
	 * @return
118 124
	 */
119 125
	static public Integer getValue(String key, Integer defaultValue) {
126
		if (singleton.hashMap.get(key) == null)
127
			singleton.hashMap.put(key, defaultValue);
120 128
		try {
121 129
			return Integer.valueOf(getXMLEntity().getStringProperty(key));
122 130
		} catch (Exception e) {
......
132 140
	 * @return
133 141
	 */
134 142
	static public Long getValue(String key, Long defaultValue) {
143
		if (singleton.hashMap.get(key) == null)
144
			singleton.hashMap.put(key, defaultValue);
135 145
		try {
136 146
			return Long.valueOf(getXMLEntity().getStringProperty(key));
137 147
		} catch (Exception e) {
......
147 157
	 * @return
148 158
	 */
149 159
	static public String getValue(String key, String defaultValue) {
160
		if (singleton.hashMap.get(key) == null)
161
			singleton.hashMap.put(key, defaultValue);
150 162
		try {
151 163
			return getXMLEntity().getStringProperty(key);
152 164
		} catch (Exception e) {
......
156 168
	}
157 169

  
158 170
	/**
171
	 * Devuelve el valor por defecto de un key
172
	 * @param key
173
	 * @return
174
	 */
175
	static public Object getDefaultValue(String key) {
176
		return singleton.hashMap.get(key);
177
	}
178

  
179
	/**
159 180
	 * Guarda en la configuracion el Objeto pasado por parametro asociado a dicho
160 181
	 * key
161 182
	 * @param key
......
197 218
	static public void setValue(String key, Object value) {
198 219
		if (value == null) {
199 220
			getXMLEntity().remove(key);
200
			singleton.callConfigurationChanged();
221
			singleton.callConfigurationChanged(key, value);
201 222
			return;
202 223
		}
203 224

  
......
205 226

  
206 227
		singleton.putProperty(key, value);
207 228

  
208
		if (!oldValue.equals(value))
209
			singleton.callConfigurationChanged();
229
		if (!oldValue.equals(value.toString()))
230
			singleton.callConfigurationChanged(key, value);
210 231
	}
211 232

  
212 233
	/**
......
229 250
	/**
230 251
	 * Invocar a los eventos asociados al componente
231 252
	 */
232
	private void callConfigurationChanged() {
253
	private void callConfigurationChanged(String key, Object value) {
233 254
		Iterator iterator = actionCommandListeners.iterator();
234 255
		while (iterator.hasNext()) {
235 256
			ConfigurationListener listener = (ConfigurationListener) iterator.next();
236
			listener.actionConfigurationChanged(new EventObject(this));
257
			listener.actionConfigurationChanged(new ConfigurationEvent(this, key, value));
237 258
		}
238 259
	}
239 260

  

Also available in: Unified diff