root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / rendering / AbstractIntervalLegend.java @ 10679
History | View | Annotate | Download (7.92 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
|
42 |
/* CVS MESSAGES:
|
43 |
*
|
44 |
* $Id: AbstractIntervalLegend.java 10679 2007-03-09 11:25:01Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.2 2007-03-09 11:20:56 jaume
|
47 |
* Advanced symbology (start committing)
|
48 |
*
|
49 |
* Revision 1.1.2.2 2007/02/15 16:23:44 jaume
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
* Revision 1.1.2.1 2007/02/13 16:19:19 jaume
|
53 |
* graduated symbol legends (start commiting)
|
54 |
*
|
55 |
*
|
56 |
*/
|
57 |
package com.iver.cit.gvsig.fmap.rendering; |
58 |
|
59 |
import java.util.ArrayList; |
60 |
import java.util.Comparator; |
61 |
import java.util.TreeMap; |
62 |
|
63 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
64 |
import com.hardcode.gdbms.engine.data.DataSource; |
65 |
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
66 |
import com.hardcode.gdbms.engine.values.Value; |
67 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
68 |
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
69 |
|
70 |
public abstract class AbstractIntervalLegend implements IntervalLegend{ |
71 |
|
72 |
public static final int EQUAL_INTERVALS = 0; |
73 |
public static final int NATURAL_INTERVALS = 1; |
74 |
public static final int QUANTILE_INTERVALS = 2; |
75 |
protected TreeMap symbols = new TreeMap(new Comparator() { |
76 |
public int compare(Object o1, Object o2) { |
77 |
if ((o1 != null) && (o2 != null)) { |
78 |
if (o1 instanceof NullIntervalValue && |
79 |
o2 instanceof NullIntervalValue) {
|
80 |
return 0; |
81 |
} |
82 |
|
83 |
if (o2 instanceof NullIntervalValue) { |
84 |
return 1; |
85 |
} |
86 |
|
87 |
if (o1 instanceof NullIntervalValue) { |
88 |
return -1; |
89 |
} |
90 |
|
91 |
FInterval i2 = (FInterval) o2; |
92 |
FInterval i1 = (FInterval) o1; |
93 |
|
94 |
if (i1.getMin() > i2.getMin()) {
|
95 |
return 1; |
96 |
} |
97 |
|
98 |
if (i1.getMin() < i2.getMin()) {
|
99 |
return -1; |
100 |
} |
101 |
if (i1.getMax() < i2.getMax()) {
|
102 |
return -1; |
103 |
} |
104 |
if (i1.getMax() > i2.getMax()) {
|
105 |
return 1; |
106 |
} |
107 |
} |
108 |
|
109 |
return 0; |
110 |
} |
111 |
}); |
112 |
protected ArrayList keys = new ArrayList(); |
113 |
protected int index = 0; |
114 |
protected String fieldName; |
115 |
private int fieldId; |
116 |
private ISymbol defaultSymbol;
|
117 |
private DataSource dataSource; |
118 |
protected int intervalType = NATURAL_INTERVALS; |
119 |
protected boolean useDefaultSymbol = false; |
120 |
protected String labelFieldName; |
121 |
protected String labelFieldHeight; |
122 |
protected String labelFieldRotation; |
123 |
|
124 |
public void addSymbol(Object key, ISymbol symbol) { |
125 |
//TODO guardar los intervalos.
|
126 |
Object resul;
|
127 |
resul = symbols.put(key, symbol); |
128 |
|
129 |
/*if (resul != null) {
|
130 |
System.err.println("Error: la clave " + key +
|
131 |
" ya exist?a. Resul = " + resul);
|
132 |
System.err.println("symbol nuevo:" + symbol.m_Descrip +
|
133 |
" Sviejo= " + ((FSymbol) resul).m_Descrip);
|
134 |
} else {
|
135 |
*/
|
136 |
keys.add(key); |
137 |
|
138 |
//}
|
139 |
} |
140 |
|
141 |
/**
|
142 |
* @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#getSymbol(int)
|
143 |
*/
|
144 |
public ISymbol getSymbol(int recordIndex) throws ReadDriverException { |
145 |
Value val = dataSource.getFieldValue(recordIndex, fieldId); |
146 |
IInterval interval = getInterval(val); |
147 |
ISymbol theSymbol = getSymbolByInterval(interval); |
148 |
|
149 |
if (theSymbol != null) { |
150 |
return theSymbol;
|
151 |
} else if (useDefaultSymbol) { |
152 |
return getDefaultSymbol();
|
153 |
} |
154 |
|
155 |
return null; |
156 |
} |
157 |
|
158 |
|
159 |
public ISymbol getSymbolByFeature(IFeature feat) {
|
160 |
Value val = feat.getAttribute(fieldId); |
161 |
IInterval interval = getInterval(val); |
162 |
ISymbol theSymbol = getSymbolByInterval(interval); |
163 |
|
164 |
if (theSymbol != null) { |
165 |
return theSymbol;
|
166 |
} else {
|
167 |
return getDefaultSymbol();
|
168 |
} |
169 |
} |
170 |
|
171 |
|
172 |
public ISymbol getSymbolByInterval(IInterval key) {
|
173 |
if (key == null) { |
174 |
return null; |
175 |
} |
176 |
|
177 |
if (symbols.containsKey(key)) {
|
178 |
return (ISymbol) symbols.get(key);
|
179 |
} |
180 |
|
181 |
return null; |
182 |
} |
183 |
|
184 |
public String[] getDescriptions() { |
185 |
String[] descriptions = new String[symbols.size()]; |
186 |
ISymbol[] auxSym = getSymbols();
|
187 |
|
188 |
for (int i = 0; i < descriptions.length; i++) |
189 |
descriptions[i] = auxSym[i].getDescription(); |
190 |
|
191 |
return descriptions;
|
192 |
} |
193 |
|
194 |
|
195 |
public Object[] getValues() { |
196 |
return symbols.keySet().toArray();
|
197 |
} |
198 |
|
199 |
public void clear() { |
200 |
index = 0;
|
201 |
keys.clear(); |
202 |
symbols.clear(); |
203 |
} |
204 |
|
205 |
public ISymbol[] getSymbols() { |
206 |
return (ISymbol[]) symbols.values().toArray(new ISymbol[0]); |
207 |
} |
208 |
|
209 |
public String getFieldName() { |
210 |
return fieldName;
|
211 |
} |
212 |
|
213 |
public void setDefaultSymbol(ISymbol s) { |
214 |
defaultSymbol = s; |
215 |
} |
216 |
|
217 |
public void setFieldName(String str) { |
218 |
fieldName = str; |
219 |
} |
220 |
|
221 |
/**
|
222 |
* @deprecated
|
223 |
*/
|
224 |
public void setLabelField(String fieldName) { |
225 |
labelFieldName = fieldName; |
226 |
} |
227 |
|
228 |
/**
|
229 |
* @deprecated
|
230 |
*/
|
231 |
public String getLabelField() { |
232 |
return labelFieldName;
|
233 |
} |
234 |
|
235 |
public ISymbol getDefaultSymbol() {
|
236 |
NullIntervalValue niv=new NullIntervalValue();
|
237 |
if (symbols.containsKey(niv))
|
238 |
return (ISymbol)symbols.get(niv);
|
239 |
return defaultSymbol;
|
240 |
} |
241 |
|
242 |
/* (non-Javadoc)
|
243 |
* @see com.iver.cit.gvsig.fmap.rendering.VectorialLegend#setDataSource(com.hardcode.gdbms.engine.data.DataSource)
|
244 |
*/
|
245 |
public void setDataSource(DataSource ds) |
246 |
throws FieldNotFoundException, ReadDriverException {
|
247 |
dataSource = ds; |
248 |
ds.start(); |
249 |
fieldId = ds.getFieldIndexByName(fieldName); |
250 |
ds.stop(); |
251 |
} |
252 |
|
253 |
/**
|
254 |
* Devuelve el intervalo a partir del valor.
|
255 |
*
|
256 |
* @param v valor.
|
257 |
*
|
258 |
* @return intervalo.
|
259 |
*/
|
260 |
public IInterval getInterval(Value v) {
|
261 |
/*if (v instanceof NullValue){
|
262 |
System.out.println("Si");
|
263 |
}*/
|
264 |
for (int i = 0; i < keys.size(); i++) { |
265 |
if (((IInterval) keys.get(i)).isInInterval(v)) {
|
266 |
return (IInterval) keys.get(i);
|
267 |
} |
268 |
} |
269 |
|
270 |
return null; |
271 |
} |
272 |
|
273 |
public void setIntervalType(int tipoClasificacion) { |
274 |
intervalType = tipoClasificacion; |
275 |
} |
276 |
|
277 |
/**
|
278 |
* Devuelve el tipo de clasificaci?n de los intervalos.
|
279 |
*
|
280 |
* @return Tipo de clasificaci?n.
|
281 |
*/
|
282 |
public int getIntervalType() { |
283 |
return intervalType;
|
284 |
} |
285 |
|
286 |
public void useDefaultSymbol(boolean b) { |
287 |
useDefaultSymbol = b; |
288 |
} |
289 |
|
290 |
|
291 |
public boolean isUseDefaultSymbol() { |
292 |
return useDefaultSymbol;
|
293 |
} |
294 |
|
295 |
/**
|
296 |
* Elimina un s?mbolo a partir de su clave.
|
297 |
*
|
298 |
* @param obj clave.
|
299 |
*/
|
300 |
public void delSymbol(Object obj) { |
301 |
keys.remove(obj); |
302 |
symbols.remove(obj); |
303 |
} |
304 |
|
305 |
/**
|
306 |
* @deprecated
|
307 |
* @return
|
308 |
*/
|
309 |
public String[] getUsedFields() { |
310 |
ArrayList usedFields = new ArrayList(); |
311 |
if (getFieldName() != null) |
312 |
usedFields.add(getFieldName()); |
313 |
if (getLabelField() != null) |
314 |
usedFields.add(getLabelField()); |
315 |
if (getLabelHeightField() != null) |
316 |
usedFields.add(getLabelHeightField()); |
317 |
if (getLabelRotationField() != null) |
318 |
usedFields.add(getLabelRotationField()); |
319 |
|
320 |
return (String[]) usedFields.toArray(new String[0]); |
321 |
|
322 |
} |
323 |
|
324 |
/**
|
325 |
* @deprecated
|
326 |
* @return
|
327 |
*/
|
328 |
public String getLabelHeightField() { |
329 |
return labelFieldHeight;
|
330 |
} |
331 |
|
332 |
/**
|
333 |
* Inserta el alto del campo.
|
334 |
*
|
335 |
* @param str alto.
|
336 |
* @deprecated
|
337 |
*/
|
338 |
public void setLabelHeightField(String str) { |
339 |
labelFieldHeight = str; |
340 |
} |
341 |
|
342 |
/**
|
343 |
* @deprecated
|
344 |
* @return
|
345 |
*/
|
346 |
public String getLabelRotationField() { |
347 |
return labelFieldRotation;
|
348 |
} |
349 |
|
350 |
/**
|
351 |
* @deprecated
|
352 |
* Inserta la rotaci?n del campo.
|
353 |
*
|
354 |
* @param str Rotaci?n.
|
355 |
*/
|
356 |
public void setLabelRotationField(String str) { |
357 |
labelFieldRotation = str; |
358 |
} |
359 |
|
360 |
} |