Revision 2796 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/rendering/VectorialIntervalLegend.java

View differences:

VectorialIntervalLegend.java
42 42

  
43 43
import com.hardcode.gdbms.engine.data.DataSource;
44 44
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException;
45
import com.hardcode.gdbms.engine.values.DoubleValue;
46
import com.hardcode.gdbms.engine.values.FloatValue;
47
import com.hardcode.gdbms.engine.values.IntValue;
48
import com.hardcode.gdbms.engine.values.LongValue;
49
import com.hardcode.gdbms.engine.values.NullValue;
50 45
import com.hardcode.gdbms.engine.values.Value;
51 46

  
52 47
import com.iver.cit.gvsig.fmap.DriverException;
......
72 67
 * @author Vicente Caballero Navarro
73 68
 */
74 69
public class VectorialIntervalLegend implements IntervalLegend, VectorialLegend {
75
	public final static int EQUAL_INTERVALS = 0;
76
	public final static int NATURAL_INTERVALS = 1;
77
	public final static int QUANTILE_INTERVALS = 2;
78
	private TreeMap symbols = new TreeMap(new Comparator() {
79
				public int compare(Object o1, Object o2) {
80
					if ((o1 != null) && (o2 != null)) {
81
						if (o1 instanceof NullInterval && o2 instanceof NullInterval)return 0;
82
						if (o2 instanceof NullInterval) return 1;
83
						if (o1 instanceof NullInterval) return -1;
84
						FInterval i2 = (FInterval) o2;
85
						FInterval i1 = (FInterval) o1;
70
    public final static int EQUAL_INTERVALS = 0;
71
    public final static int NATURAL_INTERVALS = 1;
72
    public final static int QUANTILE_INTERVALS = 2;
73
    private TreeMap symbols = new TreeMap(new Comparator() {
74
                public int compare(Object o1, Object o2) {
75
                    if ((o1 != null) && (o2 != null)) {
76
                       if (o1 instanceof NullIntervalValue &&
77
                                o2 instanceof NullIntervalValue) {
78
                            return 0;
79
                        }
86 80

  
87
						if (i1.getMin() > i2.getMin()) {
88
							return 1;
89
						}
81
                        if (o2 instanceof NullIntervalValue) {
82
                            return 1;
83
                        }
90 84

  
91
						if (i1.getMin() < i2.getMin()) {
92
							return -1;
93
						}
94
					}
85
                        if (o1 instanceof NullIntervalValue) {
86
                            return -1;
87
                        }
95 88

  
96
					return 0;
97
				}
98
			}); // Para poder ordenar
99
	private ArrayList keys = new ArrayList(); // En lugar de un HashSet, para tener acceso por ?ndice
100
	private int index = 0;
101
	private String fieldName;
102
	private int fieldId;
103
	private String labelFieldName;
104
	private String labelFieldHeight;
105
	private String labelFieldRotation;
106
	private FSymbol defaultSymbol;
107
	private DataSource dataSource;
108
	private Color startColor = Color.red;
109
	private Color endColor = Color.blue;
110
	private int shapeType;
111
	private int intervalType = NATURAL_INTERVALS;
112
	private boolean useDefaultSymbol=false;
113
	private boolean bWithHeightText;
89
                        FInterval i2 = (FInterval) o2;
90
                        FInterval i1 = (FInterval) o1;
114 91

  
115
	/**
116
	 * Crea un nuevo VectorialIntervalLegend.
117
	 */
118
	public VectorialIntervalLegend() {
119
		//defaultSymbol = LegendFactory.DEFAULT_POLYGON_SYMBOL;
120
	}
92
                        if (i1.getMin() > i2.getMin()) {
93
                            return 1;
94
                        }
121 95

  
122
	/**
123
	 * Crea un nuevo VectorialIntervalLegend.
124
	 *
125
	 * @param type tipo de shape.
126
	 */
127
	public VectorialIntervalLegend(int type) {
128
		setShapeType(type);
129
	}
96
                        if (i1.getMin() < i2.getMin()) {
97
                            return -1;
98
                        }
99
                    }
130 100

  
131
	/**
132
	 * @see com.iver.cit.gvsig.fmap.rendering.UniqueValueLegend#addSymbol(java.lang.Object,
133
	 * 		FSymbol)
134
	 */
135
	public void addSymbol(Object key, FSymbol symbol) {
136
		//TODO guardar los intervalos.
137
		Object resul;
138
		resul = symbols.put(key, symbol);
101
                    return 0;
102
                }
103
            }); // Para poder ordenar
104
    private ArrayList keys = new ArrayList(); // En lugar de un HashSet, para tener acceso por ?ndice
105
    private int index = 0;
106
    private String fieldName;
107
    private int fieldId;
108
    private String labelFieldName;
109
    private String labelFieldHeight;
110
    private String labelFieldRotation;
111
    private FSymbol defaultSymbol;
112
    private DataSource dataSource;
113
    private Color startColor = Color.red;
114
    private Color endColor = Color.blue;
115
    private int shapeType;
116
    private int intervalType = NATURAL_INTERVALS;
117
    private boolean useDefaultSymbol = false;
118
    private boolean bWithHeightText;
139 119

  
140
		/*if (resul != null) {
141
		   System.err.println("Error: la clave " + key +
142
		           " ya exist?a. Resul = " + resul);
143
		   System.err.println("symbol nuevo:" + symbol.m_Descrip +
144
		           " Sviejo= " + ((FSymbol) resul).m_Descrip);
145
		   } else {
146
		 */
147
		keys.add(key);
120
    /**
121
     * Crea un nuevo VectorialIntervalLegend.
122
     */
123
    public VectorialIntervalLegend() {
124
        //defaultSymbol = LegendFactory.DEFAULT_POLYGON_SYMBOL;
125
    }
148 126

  
149
		//}
150
	}
127
    /**
128
     * Crea un nuevo VectorialIntervalLegend.
129
     *
130
     * @param type tipo de shape.
131
     */
132
    public VectorialIntervalLegend(int type) {
133
        setShapeType(type);
134
    }
151 135

  
152
	/*
153
	 * @see com.iver.cit.gvsig.fmap.rendering.Legend#getSymbol(java.lang.Object)
154
	 *
155
	           public FStyle2D getSymbol(Object value) {
156
	               return (FStyle2D) symbols.get(value);
157
	           }
158
	           // TODO transformar la funci?n anterior en la siguiente
159
	 *
160
	 */
136
    /**
137
     * @see com.iver.cit.gvsig.fmap.rendering.UniqueValueLegend#addSymbol(java.lang.Object,
138
     *      FSymbol)
139
     */
140
    public void addSymbol(Object key, FSymbol symbol) {
141
        //TODO guardar los intervalos.
142
        Object resul;
143
        resul = symbols.put(key, symbol);
161 144

  
162
	/**
163
	 * @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#getSymbol(int)
164
	 */
165
	public FSymbol getSymbol(int recordIndex) throws DriverException {
166
		try {
167
			Value val = dataSource.getFieldValue(recordIndex, fieldId);
168
			IInterval interval = getInterval(val);
169
			FSymbol theSymbol = getSymbolByInterval(interval);
170
			
171
			if (theSymbol != null) {
172
				return theSymbol;
173
			} else if (useDefaultSymbol){
174
				return getDefaultSymbol();
175
			}
176
			return null;
177
		} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
178
			throw new DriverException(e);
179
		}
180
	}
181
/**
182
	 * DOCUMENT ME!
183
	 *
184
	 * @param feat DOCUMENT ME!
185
	 *
186
	 * @return DOCUMENT ME!
187
	 */
188
	public FSymbol getSymbolByFeature(IFeature feat) {
189
		Value val = feat.getAttribute(fieldId);
190
		IInterval interval = getInterval(val);
191
		FSymbol theSymbol = getSymbolByInterval(interval);
145
        /*if (resul != null) {
146
           System.err.println("Error: la clave " + key +
147
                   " ya exist?a. Resul = " + resul);
148
           System.err.println("symbol nuevo:" + symbol.m_Descrip +
149
                   " Sviejo= " + ((FSymbol) resul).m_Descrip);
150
           } else {
151
         */
152
        keys.add(key);
192 153

  
193
		if (theSymbol != null) {
194
			return theSymbol;
195
		} else {
196
			return getDefaultSymbol();
197
		}
198
	}
154
        //}
155
    }
199 156

  
200
	/**
201
	 * Devuelve el s?mbolo a partir del intervalo.
202
	 *
203
	 * @param key intervalo.
204
	 *
205
	 * @return s?mbolo.
206
	 */
207
	public FSymbol getSymbolByInterval(IInterval key) {
208
		if (key == null) {
209
			return null;
210
		}
157
    /*
158
     * @see com.iver.cit.gvsig.fmap.rendering.Legend#getSymbol(java.lang.Object)
159
     *
160
                   public FStyle2D getSymbol(Object value) {
161
                       return (FStyle2D) symbols.get(value);
162
                   }
163
                   // TODO transformar la funci?n anterior en la siguiente
164
     *
165
     */
211 166

  
212
		if (symbols.containsKey(key)) {
213
			return (FSymbol) symbols.get(key);
214
		}
167
    /**
168
     * @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#getSymbol(int)
169
     */
170
    public FSymbol getSymbol(int recordIndex) throws DriverException {
171
        try {
172
            Value val = dataSource.getFieldValue(recordIndex, fieldId);
173
            IInterval interval = getInterval(val);
174
            FSymbol theSymbol = getSymbolByInterval(interval);
215 175

  
216
		return null;
217
	}
176
            if (theSymbol != null) {
177
                return theSymbol;
178
            } else if (useDefaultSymbol) {
179
                return getDefaultSymbol();
180
            }
218 181

  
219
	/**
220
	 * @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegendInfo#getDescriptions()
221
	 */
222
	public String[] getDescriptions() {
223
		String[] descriptions = new String[symbols.size()];
224
		FSymbol[] auxSym = getSymbols();
182
            return null;
183
        } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
184
            throw new DriverException(e);
185
        }
186
    }
225 187

  
226
		for (int i = 0; i < descriptions.length; i++)
227
			descriptions[i] = auxSym[i].getDescription();
188
    /**
189
     * Devuelve un s?mbolo a partir de una IFeature.
190
     *
191
     * @param feat IFeature.
192
     *
193
     * @return S?mbolo.
194
     */
195
    public FSymbol getSymbolByFeature(IFeature feat) {
196
        Value val = feat.getAttribute(fieldId);
197
        IInterval interval = getInterval(val);
198
        FSymbol theSymbol = getSymbolByInterval(interval);
228 199

  
229
		return descriptions;
230
	}
200
        if (theSymbol != null) {
201
            return theSymbol;
202
        } else {
203
            return getDefaultSymbol();
204
        }
205
    }
231 206

  
232
	/**
233
	 * @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegendInfo#getValues()
234
	 */
235
	public Object[] getValues() {
236
		return (Object[]) symbols.keySet().toArray(new Object[0]);
237
	}
207
    /**
208
     * Devuelve el s?mbolo a partir del intervalo.
209
     *
210
     * @param key intervalo.
211
     *
212
     * @return s?mbolo.
213
     */
214
    public FSymbol getSymbolByInterval(IInterval key) {
215
        if (key == null) {
216
            return null;
217
        }
238 218

  
239
	/**
240
	 * @see com.iver.cit.gvsig.fmap.rendering.IntervalLegend#setIntervalSymbol(com.iver.cit.gvsig.fmap.rendering.FInterval,
241
	 * 		org.geotools.renderer.style.Style2D)
242
	 */
243
	public void setIntervalSymbol(IInterval interval, FSymbol symbol) {
244
		/*symbols.put(interval, symbol);
245
		   values.put(new Integer(index), interval);
246
		   index++;
247
		 */
248
	}
219
        if (symbols.containsKey(key)) {
220
            return (FSymbol) symbols.get(key);
221
        }
249 222

  
250
	/**
251
	 * @see com.iver.cit.gvsig.fmap.rendering.IntervalLegend#changeInterval(int,
252
	 * 		com.iver.cit.gvsig.fmap.rendering.FInterval)
253
	 */
254
	public void changeInterval(int index, IInterval newInterval) {
255
		/*Object value = values.remove(new Integer(index));
256
		   Object symbol = symbols.remove(value);
257
		   values.put(new Integer(index), newInterval);
258
		   symbols.put(newInterval, symbol);
259
		 */
260
	}
223
        return null;
224
    }
261 225

  
262
	/**
263
	 * @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegend#clear()
264
	 */
265
	public void clear() {
266
		index = 0;
267
		keys.clear();
268
		symbols.clear();
269
	}
226
    /**
227
     * @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegendInfo#getDescriptions()
228
     */
229
    public String[] getDescriptions() {
230
        String[] descriptions = new String[symbols.size()];
231
        FSymbol[] auxSym = getSymbols();
270 232

  
271
	/**
272
	 * @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegend#getSymbols()
273
	 */
274
	public FSymbol[] getSymbols() {
275
		return (FSymbol[]) symbols.values().toArray(new FSymbol[0]);
276
	}
233
        for (int i = 0; i < descriptions.length; i++)
234
            descriptions[i] = auxSym[i].getDescription();
277 235

  
278
	/**
279
	 * @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegend#getFieldName()
280
	 */
281
	public String getFieldName() {
282
		return fieldName;
283
	}
236
        return descriptions;
237
    }
284 238

  
285
	/**
286
	 * @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#setDefaultSymbol(com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D)
287
	 */
288
	public void setDefaultSymbol(FSymbol s) {
289
		defaultSymbol = s;
290
	}
239
    /**
240
     * @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegendInfo#getValues()
241
     */
242
    public Object[] getValues() {
243
        return (Object[]) symbols.keySet().toArray(new Object[0]);
244
    }
291 245

  
292
	/**
293
	 * @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegend#setFieldName(String)
294
	 */
295
	public void setFieldName(String str) {
296
		fieldName = str;
297
	}
246
    /**
247
     * @see com.iver.cit.gvsig.fmap.rendering.IntervalLegend#setIntervalSymbol(com.iver.cit.gvsig.fmap.rendering.FInterval,
248
     *      org.geotools.renderer.style.Style2D)
249
     */
250
    public void setIntervalSymbol(IInterval interval, FSymbol symbol) {
251
        /*symbols.put(interval, symbol);
252
           values.put(new Integer(index), interval);
253
           index++;
254
         */
255
    }
298 256

  
299
	/**
300
	 * @see com.iver.cit.gvsig.fmap.rendering.Legend#setLabelField(int)
301
	 */
302
	public void setLabelField(String fieldName) {
303
		labelFieldName = fieldName;
304
	}
257
    /**
258
     * @see com.iver.cit.gvsig.fmap.rendering.IntervalLegend#changeInterval(int,
259
     *      com.iver.cit.gvsig.fmap.rendering.FInterval)
260
     */
261
    public void changeInterval(int index, IInterval newInterval) {
262
        /*Object value = values.remove(new Integer(index));
263
           Object symbol = symbols.remove(value);
264
           values.put(new Integer(index), newInterval);
265
           symbols.put(newInterval, symbol);
266
         */
267
    }
305 268

  
306
	/**
307
	 * @see com.iver.cit.gvsig.fmap.rendering.Legend#getLabelField()
308
	 */
309
	public String getLabelField() {
310
		return labelFieldName;
311
	}
269
    /**
270
     * @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegend#clear()
271
     */
272
    public void clear() {
273
        index = 0;
274
        keys.clear();
275
        symbols.clear();
276
    }
312 277

  
313
	/**
314
	 * @see com.iver.cit.gvsig.fmap.rendering.Legend#getDefaultSymbol()
315
	 */
316
	public FSymbol getDefaultSymbol() {
317
		return defaultSymbol;
318
	}
278
    /**
279
     * @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegend#getSymbols()
280
     */
281
    public FSymbol[] getSymbols() {
282
        return (FSymbol[]) symbols.values().toArray(new FSymbol[0]);
283
    }
319 284

  
320
	/**
321
	 * DOCUMENT ME!
322
	 *
323
	 * @return DOCUMENT ME!
324
	 *
325
	 * @see com.iver.cit.gvsig.fmap.rendering.Legend#getXMLEntity()
326
	 */
327
	public XMLEntity getXMLEntity() {
328
		XMLEntity xml = new XMLEntity();
329
		xml.putProperty("className",this.getClass().getName());
285
    /**
286
     * @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegend#getFieldName()
287
     */
288
    public String getFieldName() {
289
        return fieldName;
290
    }
330 291

  
331
		if (getDefaultSymbol() == null) {
332
			xml.putProperty("useDefaultSymbol", 0);
333
		} else {
334
			xml.putProperty("useDefaultSymbol", 1);
335
			xml.addChild(getDefaultSymbol().getXMLEntity());
336
		}
292
    /**
293
     * @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#setDefaultSymbol(com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D)
294
     */
295
    public void setDefaultSymbol(FSymbol s) {
296
        defaultSymbol = s;
297
    }
337 298

  
338
		xml.putProperty("fieldName", fieldName);
339
		xml.putProperty("index", index);
340
		xml.putProperty("labelfield", labelFieldName);
341
		xml.putProperty("intervalType",intervalType);
342
		xml.putProperty("numKeys", keys.size());
299
    /**
300
     * @see com.iver.cit.gvsig.fmap.rendering.ClassifiedLegend#setFieldName(String)
301
     */
302
    public void setFieldName(String str) {
303
        fieldName = str;
304
    }
343 305

  
344
		if (keys.size() > 0) {
345
			xml.putProperty("tipoValueKeys", keys.get(0).getClass().getName());
306
    /**
307
     * @see com.iver.cit.gvsig.fmap.rendering.Legend#setLabelField(int)
308
     */
309
    public void setLabelField(String fieldName) {
310
        labelFieldName = fieldName;
311
    }
346 312

  
347
			String[] sk = new String[keys.size()];
313
    /**
314
     * @see com.iver.cit.gvsig.fmap.rendering.Legend#getLabelField()
315
     */
316
    public String getLabelField() {
317
        return labelFieldName;
318
    }
348 319

  
349
			for (int i = 0; i < keys.size(); i++) {
350
				sk[i] = ((IInterval) keys.get(i)).toString();
351
			}
320
    /**
321
     * @see com.iver.cit.gvsig.fmap.rendering.Legend#getDefaultSymbol()
322
     */
323
    public FSymbol getDefaultSymbol() {
324
        return defaultSymbol;
325
    }
352 326

  
353
			xml.putProperty("keys", sk);
327
    /**
328
     * DOCUMENT ME!
329
     *
330
     * @return DOCUMENT ME!
331
     *
332
     * @see com.iver.cit.gvsig.fmap.rendering.Legend#getXMLEntity()
333
     */
334
    public XMLEntity getXMLEntity() {
335
        XMLEntity xml = new XMLEntity();
336
        xml.putProperty("className", this.getClass().getName());
354 337

  
355
			for (int i = 0; i < keys.size(); i++) {
356
				xml.addChild(getSymbols()[i].getXMLEntity());
357
			}
358
		}
338
        if (getDefaultSymbol() == null) {
339
            xml.putProperty("useDefaultSymbol", 0);
340
        } else {
341
            xml.putProperty("useDefaultSymbol", 1);
342
            xml.addChild(getDefaultSymbol().getXMLEntity());
343
        }
359 344

  
360
		xml.putProperty("startColor", StringUtilities.color2String(startColor));
361
		xml.putProperty("endColor", StringUtilities.color2String(endColor));
345
        xml.putProperty("fieldName", fieldName);
346
        xml.putProperty("index", index);
347
        xml.putProperty("labelfield", labelFieldName);
348
        xml.putProperty("intervalType", intervalType);
349
        xml.putProperty("numKeys", keys.size());
362 350

  
363
		///xml.putProperty("numSymbols", symbols.size());
364
		///xml.putProperty("indexs", getIndexs());
365
		///xml.putProperty("values", getValues());
366
		return xml;
367
	}
351
        if (keys.size() > 0) {
352
            xml.putProperty("tipoValueKeys", keys.get(0).getClass().getName());
368 353

  
369
	/**
370
	 * Inserta los atributos del XMLEntity.
371
	 *
372
	 * @param xml XMLEntity.
373
	 */
374
	public void setXMLEntity03(XMLEntity xml) {
375
		fieldName = xml.getStringProperty("fieldName");
376
		index = xml.getIntProperty("index");
377
		labelFieldName = xml.getStringProperty("labelfield");
378
		if (xml.contains("intervalType")){//TODO Esta condici?n es para poder cargar la versi?n 0.3, se puede eliminar cuando ya no queramos soportar esta versi?n.
379
			intervalType=xml.getIntProperty("intervalType");
380
		}
381
		int useDefaultSymbol = xml.getIntProperty("useDefaultSymbol");
354
            String[] sk = new String[keys.size()];
382 355

  
383
		if (useDefaultSymbol == 1) {
384
			setDefaultSymbol(FSymbol.createFromXML03(xml.getChild(0)));
385
		} else {
386
			setDefaultSymbol(null);
387
		}
356
            for (int i = 0; i < keys.size(); i++) {
357
                sk[i] = ((IInterval) keys.get(i)).toString();
358
            }
388 359

  
389
		int numKeys = xml.getIntProperty("numKeys");
360
            xml.putProperty("keys", getValues());
390 361

  
391
		if (numKeys > 0) {
392
			String className = xml.getStringProperty("tipoValueKeys");
393
			String[] sk = xml.getStringArrayProperty("keys");
394
			IInterval auxInterval;
362
            for (int i = 0; i < keys.size(); i++) {
363
                xml.addChild(getSymbols()[i].getXMLEntity());
364
            }
365
        }
395 366

  
396
			for (int i = 0; i < numKeys; i++) {
397
				auxInterval = FInterval.create(sk[i]);
398
				symbols.put(auxInterval,
399
					FSymbol.createFromXML03(xml.getChild(i + useDefaultSymbol)));
400
				keys.add(auxInterval);
401
				System.out.println("auxInterval =" + auxInterval + "Symbol =" +
402
					FSymbol.createFromXML03(xml.getChild(i + useDefaultSymbol))
403
						   .getDescription());
404
			}
405
		}
367
        xml.putProperty("startColor", StringUtilities.color2String(startColor));
368
        xml.putProperty("endColor", StringUtilities.color2String(endColor));
406 369

  
407
		startColor = StringUtilities.string2Color(xml.getStringProperty(
408
					"startColor"));
409
		endColor = StringUtilities.string2Color(xml.getStringProperty(
410
					"endColor"));
411
	}
370
        ///xml.putProperty("numSymbols", symbols.size());
371
        ///xml.putProperty("indexs", getIndexs());
372
        ///xml.putProperty("values", getValues());
373
        return xml;
374
    }
412 375

  
413
	/**
414
	 * Inserta los atributos del XMLEntity.
415
	 *
416
	 * @param xml XMLEntity.
417
	 */
418
	public void setXMLEntity(XMLEntity xml) {
419
		fieldName = xml.getStringProperty("fieldName");
420
		index = xml.getIntProperty("index");
421
		labelFieldName = xml.getStringProperty("labelfield");
422
		if (xml.contains("intervalType")){//TODO Esta condici?n es para poder cargar la versi?n 0.3, se puede eliminar cuando ya no queramos soportar esta versi?n.
423
			intervalType=xml.getIntProperty("intervalType");
424
		}
425
		int useDefaultSymbol = xml.getIntProperty("useDefaultSymbol");
376
    /**
377
     * Inserta los atributos del XMLEntity.
378
     *
379
     * @param xml XMLEntity.
380
     */
381
    public void setXMLEntity03(XMLEntity xml) {
382
        fieldName = xml.getStringProperty("fieldName");
383
        index = xml.getIntProperty("index");
384
        labelFieldName = xml.getStringProperty("labelfield");
426 385

  
427
		if (useDefaultSymbol == 1) {
428
			setDefaultSymbol(FSymbol.createFromXML(xml.getChild(0)));
429
		} else {
430
			setDefaultSymbol(null);
431
		}
386
        if (xml.contains("intervalType")) { //TODO Esta condici?n es para poder cargar la versi?n 0.3, se puede eliminar cuando ya no queramos soportar esta versi?n.
387
            intervalType = xml.getIntProperty("intervalType");
388
        }
432 389

  
433
		int numKeys = xml.getIntProperty("numKeys");
390
        int useDefaultSymbol = xml.getIntProperty("useDefaultSymbol");
434 391

  
435
		if (numKeys > 0) {
436
			String className = xml.getStringProperty("tipoValueKeys");
437
			String[] sk = xml.getStringArrayProperty("keys");
438
			IInterval auxInterval;
392
        if (useDefaultSymbol == 1) {
393
            setDefaultSymbol(FSymbol.createFromXML03(xml.getChild(0)));
394
        } else {
395
            setDefaultSymbol(null);
396
        }
439 397

  
440
			for (int i = 0; i < numKeys; i++) {
441
				auxInterval = FInterval.create(sk[i]);
442
				symbols.put(auxInterval,
443
					FSymbol.createFromXML(xml.getChild(i + useDefaultSymbol)));
444
				keys.add(auxInterval);
445
				System.out.println("auxInterval =" + auxInterval + "Symbol =" +
446
					FSymbol.createFromXML(xml.getChild(i + useDefaultSymbol))
447
						   .getDescription());
448
			}
449
		}
398
        int numKeys = xml.getIntProperty("numKeys");
450 399

  
451
		startColor = StringUtilities.string2Color(xml.getStringProperty(
452
					"startColor"));
453
		endColor = StringUtilities.string2Color(xml.getStringProperty(
454
					"endColor"));
455
	}
400
        if (numKeys > 0) {
401
            String className = xml.getStringProperty("tipoValueKeys");
402
            String[] sk = xml.getStringArrayProperty("keys");
403
            IInterval auxInterval;
456 404

  
457
	/**
458
	 * @see com.iver.cit.gvsig.fmap.rendering.Legend#cloneLegend()
459
	 */
460
	public Legend cloneLegend() throws XMLException {
461
		return (Legend) LegendFactory.createFromXML(getXMLEntity());
462
	}
405
            for (int i = 0; i < numKeys; i++) {
406
                auxInterval = FInterval.create(sk[i]);
407
                symbols.put(auxInterval,
408
                    FSymbol.createFromXML03(xml.getChild(i + useDefaultSymbol)));
409
                keys.add(auxInterval);
410
                System.out.println("auxInterval =" + auxInterval + "Symbol =" +
411
                    FSymbol.createFromXML03(xml.getChild(i + useDefaultSymbol))
412
                           .getDescription());
413
            }
414
        }
463 415

  
464
	/* (non-Javadoc)
465
	 * @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#setDataSource(com.hardcode.gdbms.engine.data.DataSource)
466
	 */
467
	public void setDataSource(DataSource ds)
468
		throws FieldNotFoundException, DriverException {
469
		try {
470
			dataSource = ds;
471
			ds.start();
472
			fieldId = ds.getFieldIndexByName(fieldName);
473
			ds.stop();
474
		} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
475
			throw new DriverException(e);
476
		}
477
	}
416
        startColor = StringUtilities.string2Color(xml.getStringProperty(
417
                    "startColor"));
418
        endColor = StringUtilities.string2Color(xml.getStringProperty(
419
                    "endColor"));
420
    }
478 421

  
479
	/**
480
	 * Devuelve el intervalo a partir del valor.
481
	 *
482
	 * @param v valor.
483
	 *
484
	 * @return intervalo.
485
	 */
486
	public IInterval getInterval(Value v) {
487
		/*if (v instanceof NullValue){
488
			System.out.println("Si");
489
		}*/
490
		for (int i = 0; i < keys.size(); i++) {
491
			if (((IInterval) keys.get(i)).isInInterval(v)) {
492
				return (IInterval) keys.get(i);
493
			}
494
		}
422
    /**
423
     * Inserta los atributos del XMLEntity.
424
     *
425
     * @param xml XMLEntity.
426
     */
427
    public void setXMLEntity(XMLEntity xml) {
428
        fieldName = xml.getStringProperty("fieldName");
429
        index = xml.getIntProperty("index");
430
        labelFieldName = xml.getStringProperty("labelfield");
495 431

  
496
		return null;
497
	}
432
        if (xml.contains("intervalType")) { //TODO Esta condici?n es para poder cargar la versi?n 0.3, se puede eliminar cuando ya no queramos soportar esta versi?n.
433
            intervalType = xml.getIntProperty("intervalType");
434
        }
498 435

  
499
	/**
500
	 * Devuelve el color final.
501
	 *
502
	 * @return color final.
503
	 */
504
	public Color getEndColor() {
505
		return endColor;
506
	}
436
        int useDefaultSymbol = xml.getIntProperty("useDefaultSymbol");
507 437

  
508
	/**
509
	 * Inserta el color final.
510
	 *
511
	 * @param endColor Color final.
512
	 */
513
	public void setEndColor(Color endColor) {
514
		this.endColor = endColor;
515
	}
438
        if (useDefaultSymbol == 1) {
439
            setDefaultSymbol(FSymbol.createFromXML(xml.getChild(0)));
440
            this.useDefaultSymbol=true;
441
        } else {
442
            setDefaultSymbol(null);
443
            this.useDefaultSymbol=false;
444
        }
516 445

  
517
	/**
518
	 * Devuelve el color inicial.
519
	 *
520
	 * @return Color inicial.
521
	 */
522
	public Color getStartColor() {
523
		return startColor;
524
	}
446
        int numKeys = xml.getIntProperty("numKeys");
525 447

  
526
	/**
527
	 * Inserta el color inicial.
528
	 *
529
	 * @param startColor Color inicial.
530
	 */
531
	public void setStartColor(Color startColor) {
532
		this.startColor = startColor;
533
	}
448
        if (numKeys > 0) {
449
            String className = xml.getStringProperty("tipoValueKeys");
450
            String[] sk = xml.getStringArrayProperty("keys");
451
            IInterval auxInterval;
534 452

  
535
	/* (non-Javadoc)
536
	 * @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#getShapeType()
537
	 */
538
	public int getShapeType() {
539
		return shapeType;
540
	}
453
            for (int i = 0; i < numKeys; i++) {
454
                auxInterval = FInterval.create(sk[i]);
455
                symbols.put(auxInterval,
456
                    FSymbol.createFromXML(xml.getChild(i + useDefaultSymbol)));
457
                keys.add(auxInterval);
458
                System.out.println("auxInterval =" + auxInterval + "Symbol =" +
459
                    FSymbol.createFromXML(xml.getChild(i + useDefaultSymbol))
460
                           .getDescription());
461
            }
462
        }
541 463

  
542
	/* (non-Javadoc)
543
	 * @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#setShapeType(int)
544
	 */
545
	public void setShapeType(int shapeType) {
546
		if (this.shapeType != shapeType) {
547
			switch (shapeType) {
548
			case FShape.POINT:
549
				defaultSymbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT);
464
        startColor = StringUtilities.string2Color(xml.getStringProperty(
465
                    "startColor"));
466
        endColor = StringUtilities.string2Color(xml.getStringProperty(
467
                    "endColor"));
468
    }
550 469

  
551
				break;
470
    /**
471
     * @see com.iver.cit.gvsig.fmap.rendering.Legend#cloneLegend()
472
     */
473
    public Legend cloneLegend() throws XMLException {
474
        return (Legend) LegendFactory.createFromXML(getXMLEntity());
475
    }
552 476

  
553
			case FShape.LINE:
554
				defaultSymbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE);
477
    /* (non-Javadoc)
478
     * @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#setDataSource(com.hardcode.gdbms.engine.data.DataSource)
479
     */
480
    public void setDataSource(DataSource ds)
481
        throws FieldNotFoundException, DriverException {
482
        try {
483
            dataSource = ds;
484
            ds.start();
485
            fieldId = ds.getFieldIndexByName(fieldName);
486
            ds.stop();
487
        } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
488
            throw new DriverException(e);
489
        }
490
    }
555 491

  
556
				break;
492
    /**
493
     * Devuelve el intervalo a partir del valor.
494
     *
495
     * @param v valor.
496
     *
497
     * @return intervalo.
498
     */
499
    public IInterval getInterval(Value v) {
500
        /*if (v instanceof NullValue){
501
           System.out.println("Si");
502
           }*/
503
        for (int i = 0; i < keys.size(); i++) {
504
            if (((IInterval) keys.get(i)).isInInterval(v)) {
505
                return (IInterval) keys.get(i);
506
            }
507
        }
557 508

  
558
			case FShape.POLYGON:
559
				defaultSymbol = new FSymbol(FConstant.SYMBOL_TYPE_FILL);
509
        return null;
510
    }
560 511

  
561
				break;
562
				default:
563
					defaultSymbol= new FSymbol(shapeType);
564
		}
565
			this.shapeType = shapeType;
566
		}
567
	}
512
    /**
513
     * Devuelve el color final.
514
     *
515
     * @return color final.
516
     */
517
    public Color getEndColor() {
518
        return endColor;
519
    }
568 520

  
569
	/* (non-Javadoc)
570
	 * @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#getLabelHeightField()
571
	 */
572
	public String getLabelHeightField() {
573
		return labelFieldHeight;
574
	}
521
    /**
522
     * Inserta el color final.
523
     *
524
     * @param endColor Color final.
525
     */
526
    public void setEndColor(Color endColor) {
527
        this.endColor = endColor;
528
    }
575 529

  
576
	/**
577
	 * Inserta el alto del campo.
578
	 *
579
	 * @param str alto.
580
	 */
581
	public void setLabelHeightField(String str) {
582
		labelFieldHeight = str;
583
	}
530
    /**
531
     * Devuelve el color inicial.
532
     *
533
     * @return Color inicial.
534
     */
535
    public Color getStartColor() {
536
        return startColor;
537
    }
584 538

  
585
	/* (non-Javadoc)
586
	 * @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#getLabelRotationField()
587
	 */
588
	public String getLabelRotationField() {
589
		return labelFieldRotation;
590
	}
539
    /**
540
     * Inserta el color inicial.
541
     *
542
     * @param startColor Color inicial.
543
     */
544
    public void setStartColor(Color startColor) {
545
        this.startColor = startColor;
546
    }
591 547

  
592
	/**
593
	 * Inserta la rotaci?n del campo.
594
	 *
595
	 * @param str Rotaci?n.
596
	 */
597
	public void setLabelRotationField(String str) {
598
		labelFieldRotation = str;
599
	}
548
    /* (non-Javadoc)
549
     * @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#getShapeType()
550
     */
551
    public int getShapeType() {
552
        return shapeType;
553
    }
600 554

  
555
    /* (non-Javadoc)
556
     * @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#setShapeType(int)
557
     */
558
    public void setShapeType(int shapeType) {
559
        if (this.shapeType != shapeType) {
560
            switch (shapeType) {
561
                case FShape.POINT:
562
                    defaultSymbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT);
601 563

  
602
	/**
603
	 * Inserta el tipo de clasificaci?n de los intervalos.
604
	 *
605
	 * @param tipoClasificacion Tipo de clasificaci?n.
606
	 */
607
	public void setIntervalType(int tipoClasificacion) {
608
		intervalType = tipoClasificacion;
609
	}
564
                    break;
610 565

  
611
	/**
612
	 * Devuelve el tipo de clasificaci?n de los intervalos.
613
	 *
614
	 * @return Tipo de clasificaci?n.
615
	 */
616
	public int getIntervalType() {
617
		return intervalType;
618
	}
566
                case FShape.LINE:
567
                    defaultSymbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE);
619 568

  
620
	public void useDefaultSymbol(boolean b) {
621
		useDefaultSymbol=b;
622
	}
569
                    break;
623 570

  
624
	public boolean isBWithHeightText() {
625
		return bWithHeightText;
626
	}
571
                case FShape.POLYGON:
572
                    defaultSymbol = new FSymbol(FConstant.SYMBOL_TYPE_FILL);
627 573

  
628
	public void setBWithHeightText(boolean withHeightText) {
629
		bWithHeightText = withHeightText;
630
	}
574
                    break;
575

  
576
                default:
577
                    defaultSymbol = new FSymbol(shapeType);
578
            }
579

  
580
            this.shapeType = shapeType;
581
        }
582
    }
583

  
584
    /* (non-Javadoc)
585
     * @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#getLabelHeightField()
586
     */
587
    public String getLabelHeightField() {
588
        return labelFieldHeight;
589
    }
590

  
591
    /**
592
     * Inserta el alto del campo.
593
     *
594
     * @param str alto.
595
     */
596
    public void setLabelHeightField(String str) {
597
        labelFieldHeight = str;
598
    }
599

  
600
    /* (non-Javadoc)
601
     * @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#getLabelRotationField()
602
     */
603
    public String getLabelRotationField() {
604
        return labelFieldRotation;
605
    }
606

  
607
    /**
608
     * Inserta la rotaci?n del campo.
609
     *
610
     * @param str Rotaci?n.
611
     */
612
    public void setLabelRotationField(String str) {
613
        labelFieldRotation = str;
614
    }
615

  
616
    /**
617
     * Inserta el tipo de clasificaci?n de los intervalos.
618
     *
619
     * @param tipoClasificacion Tipo de clasificaci?n.
620
     */
621
    public void setIntervalType(int tipoClasificacion) {
622
        intervalType = tipoClasificacion;
623
    }
624

  
625
    /**
626
     * Devuelve el tipo de clasificaci?n de los intervalos.
627
     *
628
     * @return Tipo de clasificaci?n.
629
     */
630
    public int getIntervalType() {
631
        return intervalType;
632
    }
633

  
634
    /**
635
     * Inserta si se representan el resto de valores o no.
636
     *
637
     * @param b True si se tienen que representar el resto de valores.
638
     */
639
    public void useDefaultSymbol(boolean b) {
640
        useDefaultSymbol = b;
641
    }
642

  
643
    /**
644
     * Devuelve si se utiliza o no el resto de valores para representarse.
645
     *
646
     * @return True si se utiliza el resto de valores.
647
     */
648
    public boolean isUseDefaultSymbol() {
649
        return useDefaultSymbol;
650
    }
651

  
652
    /**
653
     * Devuelve si ha sido modificado el etiquetado de la capa.
654
     *
655
     * @return True si el etiquetado de la capa ha sido modificado.
656
     */
657
    public boolean isBWithHeightText() {
658
        return bWithHeightText;
659
    }
660

  
661
    /**
662
     * Introduce si el etiquetado de la capa ha sido modificado.
663
     *
664
     * @param withHeightText Boolean que indica si el etiquetado de la capa ha
665
     *        sido modificado.
666
     */
667
    public void setBWithHeightText(boolean withHeightText) {
668
        bWithHeightText = withHeightText;
669
    }
670

  
671
    /**
672
     * Elimina un s?mbolo a partir de su clave.
673
     *
674
     * @param obj clave.
675
     */
676
    public void delSymbol(Object obj) {
677
        keys.remove(obj);
678
        symbols.remove(obj);
679
    }
631 680
}

Also available in: Unified diff