Revision 25107 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/rendering/ZSort.java

View differences:

ZSort.java
52 52
 * Class ZSort is used in order to store information about the symbols
53 53
 * which are placed in the Z axis (because a level of symbols has been
54 54
 * used).
55
 * 
55
 *
56 56
 * @author jaume dominguez faus - jaume.dominguez@iver.es
57 57
 */
58 58
public class ZSort implements IPersistence, LegendContentsChangedListener {
......
60 60
	private static final String ROW_SEPARATOR = ";";
61 61
	private int[][] matrix;
62 62
	private boolean usingZSort;
63
	private Hashtable<ISymbol, Integer> symbols = new Hashtable<ISymbol, Integer>(); 
63
	private Hashtable<ISymbol, Integer> symbols = new Hashtable<ISymbol, Integer>();
64 64

  
65 65
	public ZSort(ILegend legend) {
66 66
		initialize(legend);
......
70 70
		ISymbol[] symbols;
71 71
		if (legend instanceof IClassifiedLegend) {
72 72
			symbols = ((IClassifiedLegend) legend).getSymbols();
73
			
73

  
74 74
		} else {
75 75
			symbols = new ISymbol[] {legend.getDefaultSymbol()};
76 76
		}
77 77
		matrix = new int[symbols.length][];
78
		
78

  
79 79
		for (int i = 0; i < symbols.length; i++) {
80 80
			this.symbols.put(symbols[i], i);
81
			int rowLength =  symbols[i] instanceof IMultiLayerSymbol ? 
82
                  	 ((IMultiLayerSymbol) symbols[i]).getLayerCount() : 
81
			int rowLength =  symbols[i] instanceof IMultiLayerSymbol ?
82
                  	 ((IMultiLayerSymbol) symbols[i]).getLayerCount() :
83 83
	                 1;
84 84
			matrix[i] = new int[rowLength];
85 85
		}
......
90 90
		symbols.clear();
91 91
		usingZSort = false;
92 92
		initialize(e.getNewLegend());
93
		
93

  
94 94
	}
95 95

  
96 96
	public String getClassName() {
......
101 101
		XMLEntity xml = new XMLEntity();
102 102
		xml.putProperty("className", getClassName());
103 103

  
104
		/* 
105
		 * ADVICE: 
106
		 * don't try to persist symbols!! 
104
		/*
105
		 * ADVICE:
106
		 * don't try to persist symbols!!
107 107
		 * they are already persisted by the legend!!!
108 108
		 */
109
		
109

  
110 110
		xml.putProperty("usingZSort", isUsingZSort());
111 111

  
112
		
112

  
113 113
		String strMatrix = "";
114 114
		for (int i = 0; i < matrix.length; i++) {
115 115
			int[] row = matrix[i];
......
119 119
			}
120 120
			strMatrix += strRow + ROW_SEPARATOR;
121 121
		}
122
		
122

  
123 123
		xml.putProperty("matrix", strMatrix);
124 124
		return xml;
125 125
	}
126
	
126

  
127 127
	public void setXMLEntity(XMLEntity xml) {
128 128
		setUsingZSort(xml.getBooleanProperty("usingZSort"));
129 129

  
130
		/* 
131
		 * ADVICE: 
132
		 * don't try to initialize the symbols!! 
130
		/*
131
		 * ADVICE:
132
		 * don't try to initialize the symbols!!
133 133
		 * they must be initialized by the legend!!!
134 134
		 */
135 135

  
136 136
		String strMatrix = xml.getStringProperty("matrix");
137 137
		String[] strRows = strMatrix.split(ROW_SEPARATOR);
138
		
138

  
139 139
		matrix = new int[strRows.length][];
140 140
		for (int i = 0; i < strRows.length; i++) {
141 141
			String[] strColumns = strRows[i].split(COLUMN_SEPARATOR);
......
194 194

  
195 195
	public int getSymbolLevel(ISymbol layer) {
196 196
		ISymbol[] theSymbols = getSymbols();
197
		
197

  
198 198
		for (int i = 0; i < theSymbols.length; i++) {
199 199
			ISymbol mySymbol = theSymbols[i];
200
			
200

  
201 201
			if (mySymbol instanceof IMultiLayerSymbol) {
202 202
				IMultiLayerSymbol multiSym = (IMultiLayerSymbol) mySymbol;
203 203
				for (int j = 0; j < multiSym.getLayerCount(); j++) {
......
208 208
					}
209 209
				}
210 210
			} else {
211
				if (mySymbol.equals(layer)) {
212
					return matrix[symbols.get(layer)][0];
211
//				if (mySymbol.equals(layer)) {
212
//					return matrix[symbols.get(layer)][0];
213
				 //Cuando la leyenda ha sufrido una clonaci?n, la comparaci?n de arriba no sirve.
214
				//FIXME: Pero esto no es del todo bueno.
215
				if (mySymbol.getDescription().equals(layer.getDescription())){
216
					return matrix[symbols.get(mySymbol)][0];
213 217
				}
214 218
			}
215 219
		}
216
		
220

  
217 221
//		return 0;
218 222
		return -1;
219 223
	}
220
	
224

  
221 225
	public int getTopLevelIndexAllowed() {
222 226
		ISymbol[] symbols = getSymbols();
223 227
		int count=0;
......
230 234
		}
231 235
		return count;
232 236
	}
233
	
237

  
234 238
	@Override
235 239
	public String toString() {
236 240
		String out = "Symbols:\n---------\n\n";
......
252 256
			out += "\n";
253 257
		}
254 258
		return out;
255
	} 	
256
	
259
	}
260

  
257 261
	private void replaceSymbol(ISymbol oldSymbol, ISymbol newSymbol) {
258 262
		if (oldSymbol == newSymbol) return;
259 263
		Integer value = symbols.get(oldSymbol);
260
		
264

  
261 265
		if (newSymbol == null) {
262 266
			// emptying
263 267
			symbols.remove(oldSymbol);
264 268
			matrix[value] = new int[1];
265 269
		} else {
266 270
			symbols.remove(oldSymbol);
267
			
271

  
268 272
			symbols.put(newSymbol, value);
269 273

  
270 274
			// update matrix values if need
......
275 279
			if (matrix[value].length == newArrayLength) {
276 280
				/*
277 281
				 * the new row is exactly the same long than the
278
				 * old one. Will use the old values 
282
				 * old one. Will use the old values
279 283
				 */
280 284
				newRow = matrix[value];
281 285
			} else	if (matrix[value].length < newArrayLength) {
......
283 287
				 * the new row is larger than the old one,
284 288
				 * let's copy all the first values and fill
285 289
				 * the rest with the last copied value
286
				 */ 
290
				 */
287 291
				int val=0;
288 292
				for (int i = 0; i < newRow.length; i++) {
289 293
					if (i<matrix[value].length) {
290 294
						val = matrix[value][i];
291 295
					}
292 296

  
293
					newRow[i] = val; 
297
					newRow[i] = val;
294 298
				}
295 299
			} else if (matrix[value].length > newArrayLength) {
296 300
				/*
297
				 * the new row is smaller than the old one, 
298
				 * let's copy the first values 
301
				 * the new row is smaller than the old one,
302
				 * let's copy the first values
299 303
				 */
300 304
				for (int i = 0; i < newRow.length; i++) {
301 305
					newRow[i] = matrix[value][i];

Also available in: Unified diff