root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / rendering / ZSort.java @ 13927
History | View | Annotate | Download (11.7 KB)
1 | 11741 | jaume | /* 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 | package com.iver.cit.gvsig.fmap.rendering; |
||
42 | |||
43 | import java.util.Hashtable; |
||
44 | 11808 | jaume | import java.util.Iterator; |
45 | 11741 | jaume | |
46 | import com.iver.cit.gvsig.fmap.core.IFeature; |
||
47 | import com.iver.cit.gvsig.fmap.core.symbols.IMultiLayerSymbol; |
||
48 | import com.iver.cit.gvsig.fmap.core.symbols.ISymbol; |
||
49 | 13913 | jaume | import com.iver.utiles.IPersistence; |
50 | 12786 | jaume | import com.iver.utiles.XMLEntity; |
51 | 11741 | jaume | |
52 | /**
|
||
53 | 13913 | jaume | * Class ZSort is used in order to store information about the symbols
|
54 | * which are placed in the Z axis (because a level of symbols has been
|
||
55 | * used).
|
||
56 | *
|
||
57 | 11741 | jaume | * @author jaume dominguez faus - jaume.dominguez@iver.es
|
58 | */
|
||
59 | 13913 | jaume | public class ZSort implements IPersistence { |
60 | 13927 | jaume | private int[][] matrix; |
61 | private boolean usingZSort; |
||
62 | private Hashtable<ISymbol, Integer> symbols = new Hashtable<ISymbol, Integer>(); |
||
63 | 11741 | jaume | |
64 | 13927 | jaume | public ZSort(ILegend legend) {
|
65 | ISymbol[] symbols;
|
||
66 | if (legend instanceof IClassifiedLegend) { |
||
67 | symbols = ((IClassifiedLegend) legend).getSymbols(); |
||
68 | |||
69 | } else {
|
||
70 | symbols = new ISymbol[] {legend.getDefaultSymbol()}; |
||
71 | } |
||
72 | matrix = new int[symbols.length][]; |
||
73 | |||
74 | for (int i = 0; i < symbols.length; i++) { |
||
75 | this.symbols.put(symbols[i], i);
|
||
76 | matrix[i] = new int[ |
||
77 | symbols[i] instanceof IMultiLayerSymbol ?
|
||
78 | ((IMultiLayerSymbol) symbols[i]).getLayerCount() : |
||
79 | 1
|
||
80 | ]; |
||
81 | } |
||
82 | System.err.println(this); |
||
83 | } |
||
84 | 11741 | jaume | |
85 | |||
86 | 13927 | jaume | public String getClassName() { |
87 | return getClass().getName();
|
||
88 | } |
||
89 | 11741 | jaume | |
90 | 13927 | jaume | public XMLEntity getXMLEntity() {
|
91 | // TODO Auto-generated method stub
|
||
92 | throw new Error("Not yet implemented!"); |
||
93 | } |
||
94 | |||
95 | public void setXMLEntity(XMLEntity xml) { |
||
96 | // TODO Auto-generated method stub
|
||
97 | throw new Error("Not yet implemented!"); |
||
98 | } |
||
99 | 11741 | jaume | |
100 | |||
101 | 13927 | jaume | public int getLevelCount() { |
102 | int count = -1; |
||
103 | for (int i = 0; i < matrix.length; i++) { |
||
104 | for (int j = 0; j < matrix[i].length; j++) { |
||
105 | count = Math.max(count, matrix[i][j]);
|
||
106 | } |
||
107 | } |
||
108 | return count + 1; |
||
109 | } |
||
110 | 11741 | jaume | |
111 | |||
112 | 13927 | jaume | public void setUsingZSort(boolean usingZSort) { |
113 | this.usingZSort = usingZSort;
|
||
114 | } |
||
115 | 11741 | jaume | |
116 | 13927 | jaume | public void setLevels(ISymbol sym, int[] values) { |
117 | setLevels(symbols.get(sym), values); |
||
118 | } |
||
119 | 11741 | jaume | |
120 | |||
121 | 13927 | jaume | public void setLevels(int row, int[] values) { |
122 | matrix[row] = values; |
||
123 | } |
||
124 | 11741 | jaume | |
125 | 11808 | jaume | |
126 | 13927 | jaume | public boolean isUsingZSort() { |
127 | return usingZSort;
|
||
128 | } |
||
129 | 11808 | jaume | |
130 | 11741 | jaume | |
131 | 13927 | jaume | public ISymbol[] getSymbols() { |
132 | return symbols.keySet().toArray(new ISymbol[0]); |
||
133 | } |
||
134 | 11808 | jaume | |
135 | |||
136 | 13927 | jaume | public String[] getDescriptions() { |
137 | ISymbol[] symbols = getSymbols();
|
||
138 | String[] descs = new String[symbols.length]; |
||
139 | for (int i = 0; i < descs.length; i++) { |
||
140 | descs[i] = symbols[i].getDescription(); |
||
141 | } |
||
142 | return descs;
|
||
143 | } |
||
144 | 11808 | jaume | |
145 | 11741 | jaume | |
146 | 13927 | jaume | public int getSymbolLevel(ISymbol layer) { |
147 | ISymbol[] theSymbols = getSymbols();
|
||
148 | |||
149 | for (int i = 0; i < theSymbols.length; i++) { |
||
150 | ISymbol mySymbol = theSymbols[i]; |
||
151 | |||
152 | if (mySymbol instanceof IMultiLayerSymbol) { |
||
153 | IMultiLayerSymbol multiSym = (IMultiLayerSymbol) mySymbol; |
||
154 | for (int j = 0; j < multiSym.getLayerCount(); j++) { |
||
155 | ISymbol myInnerSymbol = multiSym.getLayer(j); |
||
156 | if (myInnerSymbol.equals(layer)) {
|
||
157 | int row = symbols.get(multiSym);
|
||
158 | return matrix[row][j];
|
||
159 | } |
||
160 | } |
||
161 | } else {
|
||
162 | if (mySymbol.equals(layer)) {
|
||
163 | return matrix[symbols.get(layer)][i];
|
||
164 | } |
||
165 | } |
||
166 | } |
||
167 | |||
168 | System.err.println("did not find symbol: '"+layer.getDescription()+"' in zSort"); |
||
169 | return 0; |
||
170 | } |
||
171 | |||
172 | public int getTopLevelIndexAllowed() { |
||
173 | ISymbol[] symbols = getSymbols();
|
||
174 | int count=0; |
||
175 | for (int i = 0; i < symbols.length; i++) { |
||
176 | if (symbols[i] instanceof IMultiLayerSymbol) { |
||
177 | IMultiLayerSymbol mSymbol = (IMultiLayerSymbol) symbols[i]; |
||
178 | count = Math.max(count, mSymbol.getLayerCount());
|
||
179 | } else
|
||
180 | count = Math.max(count, 1); |
||
181 | } |
||
182 | return count;
|
||
183 | } |
||
184 | |||
185 | @Override
|
||
186 | public String toString() { |
||
187 | String out = "Symbols:\n---------\n\n"; |
||
188 | ISymbol[] syms = getSymbols();
|
||
189 | for (int i = 0; i < syms.length; i++) { |
||
190 | out += syms.getClass()+":\t"+syms[i].getDescription();
|
||
191 | } |
||
192 | out += "\nMatrix:\n--------\n\n";
|
||
193 | out += " \t";
|
||
194 | for (int i = 0; i < getTopLevelIndexAllowed(); i++) { |
||
195 | out += "column"+i+"\t\t"; |
||
196 | } |
||
197 | out += "\n";
|
||
198 | for (int i = 0; i < matrix.length; i++) { |
||
199 | out += "row "+i+":\t"; |
||
200 | for (int j = 0; j < matrix[i].length; j++) { |
||
201 | out += matrix[i][j]+"\t\t";
|
||
202 | } |
||
203 | out += "\n";
|
||
204 | } |
||
205 | return out;
|
||
206 | } |
||
207 | |||
208 | // private final ISymbol[] symbols;
|
||
209 | // private boolean usingSymbolLevels;
|
||
210 | // private Hashtable<ISymbol, int[]> table = new Hashtable<ISymbol, int[]>();
|
||
211 | // /**
|
||
212 | // * Constructor Method
|
||
213 | // * @param legend
|
||
214 | // */
|
||
215 | // public ZSort(ILegend legend) {
|
||
216 | // if (legend instanceof IClassifiedLegend) {
|
||
217 | // ISymbol[] ss = ((IClassifiedLegend) legend).getSymbols();
|
||
218 | // symbols = new ISymbol[ss.length];
|
||
219 | // System.arraycopy(
|
||
220 | // ss, 0,
|
||
221 | // symbols, 0, ss.length);
|
||
222 | // } else {
|
||
223 | // symbols = new ISymbol[] {legend.getDefaultSymbol()};
|
||
224 | // }
|
||
225 | // }
|
||
226 | // /**
|
||
227 | // * Ok if it is being used symbol levels, false on the contrary.
|
||
228 | // * @return usingSymbolLevels, boolean;
|
||
229 | // */
|
||
230 | // public boolean isUsingZSort() {
|
||
231 | // return usingSymbolLevels;
|
||
232 | // }
|
||
233 | // /**
|
||
234 | // * Stablishes if the Symbol Levels is going to be used or not.
|
||
235 | // * @param b
|
||
236 | // */
|
||
237 | //
|
||
238 | // public void setUsingZSort(boolean b) {
|
||
239 | // usingSymbolLevels = b;
|
||
240 | // }
|
||
241 | // /**
|
||
242 | // * Returns the number of layers that has the symbol which is an instance of
|
||
243 | // * IMultiLayerSymbol and has the maximum number of layers.
|
||
244 | // * @return
|
||
245 | // */
|
||
246 | // public int getMaxSymbolLayerCount() {
|
||
247 | // int count = 0;
|
||
248 | // for (int i = 0; i < symbols.length; i++) {
|
||
249 | // int levels = (symbols[i] instanceof IMultiLayerSymbol) ?
|
||
250 | // ((IMultiLayerSymbol) symbols[i]).getLayerCount() : 1;
|
||
251 | // count = Math.max(count, levels);
|
||
252 | // }
|
||
253 | // return count;
|
||
254 | //
|
||
255 | // }
|
||
256 | //
|
||
257 | // public ISymbol getSymbolByFeatureAndLevel(IFeature feat, int level) {
|
||
258 | // // TODO Implement it
|
||
259 | // throw new Error("Not yet implemented!");
|
||
260 | //
|
||
261 | // }
|
||
262 | // /**
|
||
263 | // * Returns an array composed by all the symbols.
|
||
264 | // * @return symbols, ISymbol[]
|
||
265 | // */
|
||
266 | // public ISymbol[] getSymbols() {
|
||
267 | // return symbols;
|
||
268 | // }
|
||
269 | // /**
|
||
270 | // * Returns an array composed by all the descriptions of the symbols.
|
||
271 | // *
|
||
272 | // * @return desc, String[]
|
||
273 | // */
|
||
274 | // public String[] getDescriptions() {
|
||
275 | // String[] desc = new String[symbols.length];
|
||
276 | // for (int i = 0; i < desc.length; i++) {
|
||
277 | // desc[i] = symbols[i].getDescription();
|
||
278 | // }
|
||
279 | // return desc;
|
||
280 | // }
|
||
281 | //
|
||
282 | // /**
|
||
283 | // * Obtains the level of a symbol.The method to obtain this value will be different
|
||
284 | // * depending on the type of the symbol (if the symbol is multilayer we have
|
||
285 | // * to check all the layers).
|
||
286 | // *
|
||
287 | // * @param layer
|
||
288 | // * @return int
|
||
289 | // */
|
||
290 | // public int getSymbolLevel(ISymbol layer) {
|
||
291 | // Iterator<ISymbol> it = table.keySet().iterator();
|
||
292 | // while (it.hasNext()) {
|
||
293 | //
|
||
294 | // ISymbol sym = it.next();
|
||
295 | // int[] levels = table.get(sym);
|
||
296 | //
|
||
297 | // if (sym instanceof IMultiLayerSymbol) {
|
||
298 | // IMultiLayerSymbol mlSym = (IMultiLayerSymbol) sym;
|
||
299 | // for (int i = 0; i < mlSym.getLayerCount(); i++) {
|
||
300 | // if (mlSym.getLayer(i).equals(layer))
|
||
301 | // return levels[i];
|
||
302 | // }
|
||
303 | // } else {
|
||
304 | // if (sym.equals(layer)) return levels[0];
|
||
305 | // }
|
||
306 | //
|
||
307 | // }
|
||
308 | // return 0; // symbol does not exist yet in the ZSort
|
||
309 | // }
|
||
310 | // /**
|
||
311 | // * Returns the maximum level of all the symbols contained in the hash table
|
||
312 | // * @return int
|
||
313 | // */
|
||
314 | // public int getLevelCount() {
|
||
315 | // int level = 0;
|
||
316 | // Iterator<ISymbol> it = table.keySet().iterator();
|
||
317 | // while (it.hasNext()) {
|
||
318 | //
|
||
319 | // ISymbol sym = it.next();
|
||
320 | // int[] levels = table.get(sym);
|
||
321 | // for (int i = 0; i < levels.length; i++) {
|
||
322 | // level = Math.max(level, levels[i]);
|
||
323 | // }
|
||
324 | //
|
||
325 | //
|
||
326 | // }
|
||
327 | // return level + 1;
|
||
328 | // }
|
||
329 | //
|
||
330 | //
|
||
331 | // /**
|
||
332 | // * Sets the levels associated with the symbols. The length of the
|
||
333 | // * argument levels must match the number of layers of the symbol in
|
||
334 | // * case the symbol is an {@link IMultiLayerSymbol}, or 1 otherwise
|
||
335 | // * @param sym
|
||
336 | // * @param levels
|
||
337 | // */
|
||
338 | // public void setLevelsToSymbol(ISymbol sym, int[] levels) {
|
||
339 | // table.put(sym, levels);
|
||
340 | // removeEmptyGaps();
|
||
341 | //
|
||
342 | // }
|
||
343 | //
|
||
344 | // /**
|
||
345 | // * Ensures that the table does not contain map levels with no symbols by
|
||
346 | // * updating the map level index to the next immediate map level to the
|
||
347 | // * previous non-empty one.
|
||
348 | // */
|
||
349 | // private void removeEmptyGaps() {
|
||
350 | // if (table.isEmpty()) return;
|
||
351 | //
|
||
352 | // ISymbol[] syms = table.keySet().toArray(new ISymbol[0]);
|
||
353 | // int[][] aux = new int[syms.length][];
|
||
354 | // Iterator<ISymbol> it = table.keySet().iterator();
|
||
355 | // int i = 0;
|
||
356 | // while (it.hasNext()) {
|
||
357 | // aux[i] = table.get(it.next());
|
||
358 | // i++;
|
||
359 | // }
|
||
360 | //
|
||
361 | // boolean[] isUsedLevel = new boolean[getLevelCount()];
|
||
362 | // for (i = 0; i < aux.length; i++) {
|
||
363 | // int[] thisLevels = aux[i];
|
||
364 | // for (int j = 0; j < thisLevels.length; j++) {
|
||
365 | // isUsedLevel[thisLevels[j]] = true;
|
||
366 | // }
|
||
367 | // }
|
||
368 | //
|
||
369 | // for (i = 0; i < isUsedLevel.length; i++) {
|
||
370 | // if (!isUsedLevel[i]) {
|
||
371 | // for (int j = 0; j < aux.length; j++) {
|
||
372 | // int[] thisLevels = aux[i];
|
||
373 | // for (int k = 0; j < thisLevels.length; k++) {
|
||
374 | // if (thisLevels[j]>i)
|
||
375 | // thisLevels[j]--;
|
||
376 | // }
|
||
377 | //
|
||
378 | // }
|
||
379 | // }
|
||
380 | // }
|
||
381 | //
|
||
382 | // }
|
||
383 | //
|
||
384 | // public String toString() {
|
||
385 | // String out = super.toString();
|
||
386 | // Iterator<ISymbol> it = table.keySet().iterator();
|
||
387 | // while (it.hasNext()) {
|
||
388 | // ISymbol sym = it.next();
|
||
389 | // int[] levels = table.get(sym);
|
||
390 | // out += "\n"+sym.getDescription();
|
||
391 | // for (int i = 0; i < levels.length; i++) {
|
||
392 | // out += "\t"+levels[i];
|
||
393 | // }
|
||
394 | // }
|
||
395 | // return out;
|
||
396 | // }
|
||
397 | //
|
||
398 | // public String getClassName() {
|
||
399 | // return getClass().getName();
|
||
400 | // }
|
||
401 | //
|
||
402 | // public XMLEntity getXMLEntity() {
|
||
403 | // // TODO Auto-generated method stub
|
||
404 | // throw new Error("Not yet implemented!");
|
||
405 | // }
|
||
406 | //
|
||
407 | // public void setXMLEntity(XMLEntity xml) {
|
||
408 | // // TODO Auto-generated method stub
|
||
409 | // throw new Error("Not yet implemented!");
|
||
410 | // }
|
||
411 | 12786 | jaume | |
412 | 11741 | jaume | } |