Revision 2413

View differences:

trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/rendering/FInterval.java
40 40
 */
41 41
package com.iver.cit.gvsig.fmap.rendering;
42 42

  
43
import com.hardcode.gdbms.engine.values.DateValue;
44
import com.hardcode.gdbms.engine.values.DoubleValue;
45
import com.hardcode.gdbms.engine.values.FloatValue;
46
import com.hardcode.gdbms.engine.values.IntValue;
47
import com.hardcode.gdbms.engine.values.LongValue;
48
import com.hardcode.gdbms.engine.values.NullValue;
49
import com.hardcode.gdbms.engine.values.Value;
50

  
43 51
/**
44 52
 * Clase intervalo.
45 53
 *
46 54
 * @author Vicente Caballero Navarro
47 55
 */
48
public class FInterval {
56
public class FInterval implements IInterval {
49 57
	private double from;
50 58
	private double to;
51

  
59
	public FInterval(){
60
	}
52 61
	/**
53 62
	 * Crea un nuevo FInterval.
54 63
	 *
......
60 69
		this.to = to;
61 70
	}
62 71

  
63
	/**
64
	 * Devuelve "true" si el double que se pasa como par?metro esta dentro del
65
	 * intervalo.
66
	 *
67
	 * @param check double a comprobar.
68
	 *
69
	 * @return "true" si est? dentro del intervalo.
72
	/* (non-Javadoc)
73
	 * @see com.iver.cit.gvsig.fmap.rendering.IInterval#isInInterval(com.hardcode.gdbms.engine.values.Value)
70 74
	 */
71
	public boolean isInInterval(double check) {
72
		return ((check >= from) && (check <= to));
75
	public boolean isInInterval(Value v) {
76
		double valor=0;
77
		if (v instanceof IntValue) {
78
			valor = ((IntValue) v).getValue();
79
		} else if (v instanceof DoubleValue) {
80
			valor = ((DoubleValue) v).getValue();
81
		} else if (v instanceof FloatValue) {
82
			valor = ((FloatValue) v).getValue();
83
		} else if (v instanceof LongValue) {
84
			valor = ((LongValue) v).getValue();
85
		} else if (v instanceof DateValue) {
86
			//TODO POR IMPLEMENTAR
87
		} else if (v instanceof NullValue){
88
			return false;
89
		}
90
		return ((valor >= from) && (valor <= to));
73 91
	}
74 92

  
75 93
	/**
......
90 108
		return to;
91 109
	}
92 110

  
93
	/**
94
	 * Devuelve un string con la informaci?n de inicio y final.
95
	 *
96
	 * @return String.
111
	/* (non-Javadoc)
112
	 * @see com.iver.cit.gvsig.fmap.rendering.IInterval#toString()
97 113
	 */
98 114
	public String toString() {
99 115
		return from + "-" + to;
......
107 123
	 *
108 124
	 * @return FInterval nuevo.
109 125
	 */
110
	public static FInterval create(String s) {
126
	public static IInterval create(String s) {
111 127
		String[] str = s.split("-");
112
		FInterval inter = new FInterval(Double.parseDouble(str[0]),
128
		IInterval inter=null;
129
		try{
130
		inter = new FInterval(Double.parseDouble(str[0]),
113 131
				Double.parseDouble(str[1]));
114

  
132
		}catch (NumberFormatException e) {
133
			return new NullInterval();
134
		}
115 135
		return inter;
116 136
	}
117 137
}
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/rendering/IInterval.java
1
package com.iver.cit.gvsig.fmap.rendering;
2

  
3
import com.hardcode.gdbms.engine.values.Value;
4

  
5
public interface IInterval {
6

  
7
	/**
8
	 * Devuelve "true" si el double que se pasa como par?metro esta dentro del
9
	 * intervalo.
10
	 *
11
	 * @param check double a comprobar.
12
	 *
13
	 * @return "true" si est? dentro del intervalo.
14
	 */
15
	public abstract boolean isInInterval(Value v);
16

  
17
	/**
18
	 * Devuelve un string con la informaci?n de inicio y final.
19
	 *
20
	 * @return String.
21
	 */
22
	public abstract String toString();
23

  
24
}
0 25

  
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/rendering/IntervalLegend.java
53 53
	 * @param i Intervalo.
54 54
	 * @param value S?mbolo.
55 55
	 */
56
	void setIntervalSymbol(FInterval i, FSymbol value);
56
	void setIntervalSymbol(IInterval i, FSymbol value);
57 57

  
58 58
	/**
59 59
	 * Cambia el intervalo index-?simo del array de intervalos
......
61 61
	 * @param index ?ndice.
62 62
	 * @param newInterval nuevo intervalo.
63 63
	 */
64
	void changeInterval(int index, FInterval newInterval);
64
	void changeInterval(int index, IInterval newInterval);
65 65
}
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/rendering/IntervalLegendEvent.java
44 44
 * Evento de cambio de un intervalo
45 45
 */
46 46
public class IntervalLegendEvent extends ClassificationLegendEvent {
47
	private FInterval oldInterval;
48
	private FInterval newInterval;
47
	private IInterval oldInterval;
48
	private IInterval newInterval;
49 49

  
50 50
	/**
51 51
	 * Crea un nuevo IntervalLegendEvent.
......
53 53
	 * @param oldInterval Antiguo intervalo.
54 54
	 * @param newInterval Nuevo intervalo.
55 55
	 */
56
	public IntervalLegendEvent(FInterval oldInterval, FInterval newInterval) {
56
	public IntervalLegendEvent(IInterval oldInterval, IInterval newInterval) {
57 57
		this.oldInterval = oldInterval;
58 58
		this.newInterval = newInterval;
59 59
	}
......
63 63
	 *
64 64
	 * @return Intervalo anterior.
65 65
	 */
66
	public FInterval getOldInterval() {
66
	public IInterval getOldInterval() {
67 67
		return oldInterval;
68 68
	}
69 69

  
......
72 72
	 *
73 73
	 * @return Intervalo nuevo.
74 74
	 */
75
	public FInterval getNewInterval() {
75
	public IInterval getNewInterval() {
76 76
		return newInterval;
77 77
	}
78 78
}
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/rendering/VectorialIntervalLegend.java
46 46
import com.hardcode.gdbms.engine.values.FloatValue;
47 47
import com.hardcode.gdbms.engine.values.IntValue;
48 48
import com.hardcode.gdbms.engine.values.LongValue;
49
import com.hardcode.gdbms.engine.values.NullValue;
49 50
import com.hardcode.gdbms.engine.values.Value;
50 51

  
51 52
import com.iver.cit.gvsig.fmap.DriverException;
......
77 78
	private TreeMap symbols = new TreeMap(new Comparator() {
78 79
				public int compare(Object o1, Object o2) {
79 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;
80 84
						FInterval i2 = (FInterval) o2;
81 85
						FInterval i1 = (FInterval) o1;
82 86

  
......
105 109
	private Color endColor = Color.blue;
106 110
	private int shapeType;
107 111
	private int intervalType = NATURAL_INTERVALS;
112
	private boolean useDefaultSymbol=false;
108 113

  
109 114
	/**
110 115
	 * Crea un nuevo VectorialIntervalLegend.
......
119 124
	 * @param type tipo de shape.
120 125
	 */
121 126
	public VectorialIntervalLegend(int type) {
122
		defaultSymbol = LegendFactory.DEFAULT_POLYGON_SYMBOL;
127
		setShapeType(type);
123 128
	}
124 129

  
125 130
	/**
......
159 164
	public FSymbol getSymbol(int recordIndex) throws DriverException {
160 165
		try {
161 166
			Value val = dataSource.getFieldValue(recordIndex, fieldId);
162
			FInterval interval = getInterval(val);
167
			IInterval interval = getInterval(val);
163 168
			FSymbol theSymbol = getSymbolByInterval(interval);
164

  
169
			
165 170
			if (theSymbol != null) {
166 171
				return theSymbol;
167
			} else {
172
			} else if (useDefaultSymbol){
168 173
				return getDefaultSymbol();
169 174
			}
175
			return null;
170 176
		} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
171 177
			throw new DriverException(e);
172 178
		}
......
180 186
	 */
181 187
	public FSymbol getSymbolByFeature(IFeature feat) {
182 188
		Value val = feat.getAttribute(fieldId);
183
		FInterval interval = getInterval(val);
189
		IInterval interval = getInterval(val);
184 190
		FSymbol theSymbol = getSymbolByInterval(interval);
185 191

  
186 192
		if (theSymbol != null) {
......
197 203
	 *
198 204
	 * @return s?mbolo.
199 205
	 */
200
	public FSymbol getSymbolByInterval(FInterval key) {
206
	public FSymbol getSymbolByInterval(IInterval key) {
201 207
		if (key == null) {
202 208
			return null;
203 209
		}
......
233 239
	 * @see com.iver.cit.gvsig.fmap.rendering.IntervalLegend#setIntervalSymbol(com.iver.cit.gvsig.fmap.rendering.FInterval,
234 240
	 * 		org.geotools.renderer.style.Style2D)
235 241
	 */
236
	public void setIntervalSymbol(FInterval interval, FSymbol symbol) {
242
	public void setIntervalSymbol(IInterval interval, FSymbol symbol) {
237 243
		/*symbols.put(interval, symbol);
238 244
		   values.put(new Integer(index), interval);
239 245
		   index++;
......
244 250
	 * @see com.iver.cit.gvsig.fmap.rendering.IntervalLegend#changeInterval(int,
245 251
	 * 		com.iver.cit.gvsig.fmap.rendering.FInterval)
246 252
	 */
247
	public void changeInterval(int index, FInterval newInterval) {
253
	public void changeInterval(int index, IInterval newInterval) {
248 254
		/*Object value = values.remove(new Integer(index));
249 255
		   Object symbol = symbols.remove(value);
250 256
		   values.put(new Integer(index), newInterval);
......
340 346
			String[] sk = new String[keys.size()];
341 347

  
342 348
			for (int i = 0; i < keys.size(); i++) {
343
				sk[i] = ((FInterval) keys.get(i)).toString();
349
				sk[i] = ((IInterval) keys.get(i)).toString();
344 350
			}
345 351

  
346 352
			xml.putProperty("keys", sk);
......
384 390
		if (numKeys > 0) {
385 391
			String className = xml.getStringProperty("tipoValueKeys");
386 392
			String[] sk = xml.getStringArrayProperty("keys");
387
			FInterval auxInterval;
393
			IInterval auxInterval;
388 394

  
389 395
			for (int i = 0; i < numKeys; i++) {
390 396
				auxInterval = FInterval.create(sk[i]);
......
428 434
		if (numKeys > 0) {
429 435
			String className = xml.getStringProperty("tipoValueKeys");
430 436
			String[] sk = xml.getStringArrayProperty("keys");
431
			FInterval auxInterval;
437
			IInterval auxInterval;
432 438

  
433 439
			for (int i = 0; i < numKeys; i++) {
434 440
				auxInterval = FInterval.create(sk[i]);
......
476 482
	 *
477 483
	 * @return intervalo.
478 484
	 */
479
	public FInterval getInterval(Value v) {
480
		double valor = 0;
481

  
482
		if (v.getClass().getName() == "com.hardcode.gdbms.engine.values.IntValue") {
483
			valor = ((IntValue) v).getValue();
484
		} else if (v.getClass().getName() == "com.hardcode.gdbms.engine.values.DoubleValue") {
485
			valor = ((DoubleValue) v).getValue();
486
		} else if (v.getClass().getName() == "com.hardcode.gdbms.engine.values.FloatValue") {
487
			valor = ((FloatValue) v).getValue();
488
		} else if (v.getClass().getName() == "com.hardcode.gdbms.engine.values.LongValue") {
489
			valor = ((LongValue) v).getValue();
490
		} else if (v.getClass().getName() == "com.hardcode.gdbms.engine.values.DateValue") {
491
			//TODO POR IMPLEMENTAR
492
		}
493

  
485
	public IInterval getInterval(Value v) {
486
		/*if (v instanceof NullValue){
487
			System.out.println("Si");
488
		}*/
494 489
		for (int i = 0; i < keys.size(); i++) {
495
			if (((FInterval) keys.get(i)).isInInterval(valor)) {
496
				return (FInterval) keys.get(i);
490
			if (((IInterval) keys.get(i)).isInInterval(v)) {
491
				return (IInterval) keys.get(i);
497 492
			}
498 493
		}
499 494

  
......
549 544
	public void setShapeType(int shapeType) {
550 545
		if (this.shapeType != shapeType) {
551 546
			switch (shapeType) {
552
				case FShape.POINT:
553
					defaultSymbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT);
547
			case FShape.POINT:
548
				defaultSymbol = new FSymbol(FConstant.SYMBOL_TYPE_POINT);
554 549

  
555
					break;
550
				break;
556 551

  
557
				case FShape.LINE:
558
					defaultSymbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE);
552
			case FShape.LINE:
553
				defaultSymbol = new FSymbol(FConstant.SYMBOL_TYPE_LINE);
559 554

  
560
					break;
555
				break;
561 556

  
562
				case FShape.POLYGON:
563
					defaultSymbol = new FSymbol(FConstant.SYMBOL_TYPE_FILL);
557
			case FShape.POLYGON:
558
				defaultSymbol = new FSymbol(FConstant.SYMBOL_TYPE_FILL);
564 559

  
565
					break;
566
			}
567

  
560
				break;
561
		}
568 562
			this.shapeType = shapeType;
569 563
		}
570 564
	}
......
619 613
	public int getIntervalType() {
620 614
		return intervalType;
621 615
	}
616

  
617
	public void useDefaultSymbol(boolean b) {
618
		useDefaultSymbol=b;
619
	}
622 620
}
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/rendering/NullInterval.java
1
package com.iver.cit.gvsig.fmap.rendering;
2

  
3
import com.hardcode.gdbms.engine.values.NullValue;
4
import com.hardcode.gdbms.engine.values.Value;
5

  
6
/**
7
 * DOCUMENT ME!
8
 *
9
 * @author Vicente Caballero Navarro
10
 */
11
public class NullInterval implements IInterval {
12
	
13
	public boolean isInInterval(Value v) {
14
		return (v instanceof NullValue);
15
	}
16

  
17
	/**
18
	 * Crea un nuevo NullInterval.
19
	 */
20
	public NullInterval() {
21
	}
22
	/* (non-Javadoc)
23
	 * @see com.iver.cit.gvsig.fmap.rendering.IInterval#toString()
24
	 */
25
	public String toString() {
26
		return "Resto de Valores";
27
	}
28
}
0 29

  
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/rendering/RasterIntervalLegend.java
58 58
	 * @see com.iver.cit.gvsig.fmap.rendering.IntervalLegend#setIntervalSymbol(com.iver.cit.gvsig.fmap.rendering.FInterval,
59 59
	 * 		com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D)
60 60
	 */
61
	public void setIntervalSymbol(FInterval i, FStyle2D value) {
61
	public void setIntervalSymbol(IInterval i, FStyle2D value) {
62 62
	}
63 63

  
64 64
	/**
65 65
	 * @see com.iver.cit.gvsig.fmap.rendering.IntervalLegend#changeInterval(int,
66 66
	 * 		com.iver.cit.gvsig.fmap.rendering.FInterval)
67 67
	 */
68
	public void changeInterval(int index, FInterval newInterval) {
68
	public void changeInterval(int index, IInterval newInterval) {
69 69
	}
70 70

  
71 71
	/**
......
165 165
	 * @see com.iver.cit.gvsig.fmap.rendering.IntervalLegend#setIntervalSymbol(com.iver.cit.gvsig.fmap.rendering.FInterval,
166 166
	 * 		com.iver.cit.gvsig.fmap.core.v02.FSymbol)
167 167
	 */
168
	public void setIntervalSymbol(FInterval i, FSymbol value) {
168
	public void setIntervalSymbol(IInterval i, FSymbol value) {
169 169
	}
170 170
}

Also available in: Unified diff