Revision 47476 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.symbology/org.gvsig.symbology.lib/org.gvsig.symbology.lib.impl/src/main/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/fill/impl/MultiLayerFillSymbol.java

View differences:

MultiLayerFillSymbol.java
28 28
import java.awt.Rectangle;
29 29
import java.awt.geom.AffineTransform;
30 30
import java.util.ArrayList;
31
import java.util.Arrays;
31 32
import java.util.List;
32

  
33
import org.gvsig.compat.print.PrintAttributes;
34 33
import org.gvsig.fmap.dal.feature.Feature;
35 34
import org.gvsig.fmap.geom.Geometry;
36 35
import org.gvsig.fmap.geom.type.GeometryType;
37
import org.gvsig.fmap.mapcontext.MapContext;
38 36
import org.gvsig.fmap.mapcontext.MapContextLocator;
39 37
import org.gvsig.fmap.mapcontext.ViewPort;
38
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport;
40 39
import org.gvsig.fmap.mapcontext.rendering.symbols.IMultiLayerSymbol;
41 40
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
42
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException;
41
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol_v2;
43 42
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager;
44 43
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
45 44
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IMultiLayerFillSymbol;
......
70 69
	private static final double OPACITY_SELECTION_FACTOR = .8;
71 70
	private IFillSymbol[] layers = new IFillSymbol[0];
72 71
	private MultiLayerFillSymbol selectionSymbol;
73

  
72
    private double[] sizes;
73
        
74
        @Override
74 75
	public Color getFillColor() {
75 76
		/*
76 77
		 * a multilayer symbol does not define any color, the color
......
79 80
		return null;
80 81
	}
81 82

  
82
	public int getOnePointRgb() {
83
		// will paint only the last layer pixel
84
		return layers[layers.length-1].getOnePointRgb();
85
	}
83
//        @Override
84
//	public int getOnePointRgb() {
85
//		// will paint only the last layer pixel
86
//		return layers[layers.length-1].getOnePointRgb();
87
//	}
86 88

  
89
        @Override
87 90
	public ILineSymbol getOutline() {
88 91
		/*
89 92
		 * a multilayer symbol does not define any outline, the outline
......
95 98
    @Override
96 99
	public boolean isSuitableFor(Geometry geom) {
97 100
        GeometryType gt = geom.getGeometryType();
98
        if( gt.isTypeOf(Geometry.TYPES.SURFACE) ) {
99
            return true;
100
        }
101
        return false;
101
        return gt.isTypeOf(Geometry.TYPES.SURFACE);
102 102
	}
103 103

  
104 104
    @Override
......
111 111
		}
112 112
	}
113 113

  
114
        @Override
114 115
	public void setOutline(ILineSymbol outline) {
115 116
		if (layers != null && layers.length > 0) {
116 117
			for (int i = 0; i < layers.length - 1; i++) {
......
120 121
		}
121 122
	}
122 123

  
123
	public void draw(Graphics2D g, AffineTransform affineTransform,
124
			Geometry geom, Feature feature, Cancellable cancel) {
125
		for (int i = 0; (cancel == null || !cancel.isCanceled())
126
				&& layers != null && i < layers.length; i++) {
127
			layers[i].draw(g, affineTransform, geom, feature, cancel);
128
		}
129
	}
124
    @Override
125
    public void draw(Graphics2D g, AffineTransform affineTransform, Geometry geom, Feature f, Cancellable cancel, Rectangle r) {
126
        for (int i = 0; (cancel == null || !cancel.isCanceled())
127
                && layers != null && i < layers.length; i++) {
128
            ISymbol layer = layers[i];
129
            if (layer == null) {
130
                continue;
131
            }
132
            if(layer instanceof CartographicSupport){
133
                ((CartographicSupport)layer).setCartographicContext(this.getCartographicContext());
134
            }
135
            if(layer instanceof ISymbol_v2){
136
                ((ISymbol_v2)layer).draw(g, affineTransform, geom, f, cancel, r);
137
            } else {
138
                layer.draw(g, affineTransform, geom, f, cancel);
139
            }
140
        }
141
    }
130 142

  
131
	public void drawInsideRectangle(Graphics2D g,
132
			AffineTransform scaleInstance, Rectangle r, PrintAttributes properties) throws SymbolDrawingException {
133
		for (int i = 0; layers != null && i < layers.length; i++) {
134
			layers[i].drawInsideRectangle(g, scaleInstance, r, properties);
135
		}
136
	}
143
//	public void getPixExtentPlus(Geometry geom, float[] distances,
144
//			ViewPort viewPort, int dpi) {
145
//		float[] myDistances = new float[] {0,0};
146
//		distances[0] = 0;
147
//		distances[1] = 0;
148
//		for (int i = 0; layers != null && i < layers.length; i++) {
149
//			layers[i].getPixExtentPlus(geom, myDistances, viewPort, dpi);
150
//			distances[0] = Math.max(myDistances[0], distances[0]);
151
//			distances[1] = Math.max(myDistances[1], distances[1]);
152
//		}
153
//	}
137 154

  
138
	public void getPixExtentPlus(Geometry geom, float[] distances,
139
			ViewPort viewPort, int dpi) {
140
		float[] myDistances = new float[] {0,0};
141
		distances[0] = 0;
142
		distances[1] = 0;
143
		for (int i = 0; layers != null && i < layers.length; i++) {
144
			layers[i].getPixExtentPlus(geom, myDistances, viewPort, dpi);
145
			distances[0] = Math.max(myDistances[0], distances[0]);
146
			distances[1] = Math.max(myDistances[1], distances[1]);
147
		}
148
	}
149

  
155
        @Override
150 156
	public ISymbol getSymbolForSelection() {
151
	    // TODO: revisar
152
        Color c = MapContext.getSelectionColor();
153
        c = new Color(
154
                c.getRed(),
155
                c.getGreen(),
156
                c.getBlue(),
157
                (int) (c.getAlpha()));//*OPACITY_SELECTION_FACTOR));
158 157
        if (selectionSymbol == null) {
159 158
		    	MultiLayerFillSymbol selectionSymbol =
160 159
		    	    new MultiLayerFillSymbol();
......
162 161
			for (int i = 0; layers != null && i < layers.length; i++) {
163 162
				selectionSymbol.addLayer(layers[i].getSymbolForSelection());
164 163
			}
165
//			SimpleFillSymbol selLayer = new SimpleFillSymbol();
166
//
167
//			selLayer.setFillColor(c);
168
//			selLayer.setOutline(getOutline());
169
//			selectionSymbol.addLayer(selLayer);
170 164
			setSymbolForSelection(selectionSymbol);
171 165
		} else {
172 166
          for (int i = 0; i < selectionSymbol.getLayerCount(); i++) {
173 167
                selectionSymbol.setLayer(i, selectionSymbol.getLayer(i).getSymbolForSelection());
174
//                if (i==selectionSymbol.getLayerCount()-1){
175
//                    ((SimpleFillSymbol)selectionSymbol.getLayer(i)).setFillColor(c);
176
//                }
177 168
            }
178 169
        }
170
        if (selectionSymbol instanceof CartographicSupport) {
171
            ((CartographicSupport) selectionSymbol).setUnit(this.getUnit());
172
        }
173
        
179 174
		return selectionSymbol;
180 175

  
181 176
	}
182 177

  
178
        @Override
183 179
	public int getSymbolType() {
184 180
		return Geometry.TYPES.SURFACE;
185 181
	}
186 182

  
187
//	public void setPrintingProperties(PrintAttributes printProperties) {
188
//		// TODO Implement it
189
//		throw new Error("Not yet implemented!");
190
//
191
//	}
192

  
193
//	public String getClassName() {
194
//		return getClass().getName();
195
//	}
196

  
197
	public void print(Graphics2D g, AffineTransform at, Geometry geom, PrintAttributes properties) {
198
		for (int i = 0; layers != null && i < layers.length; i++) {
199
			layers[i].print(g, at, geom, properties);
200
		}
201
	}
202

  
183
        @Override
203 184
	public void setLayer(int index, ISymbol layer) throws IndexOutOfBoundsException {
204 185
		layers[index] = (IFillSymbol) layer;
205 186
	}
206 187

  
188
        @Override
207 189
	public void swapLayers(int index1, int index2) {
208 190
		ISymbol aux1 = getLayer(index1), aux2 = getLayer(index2);
209 191
		layers[index2] = (IFillSymbol) aux1;
210 192
		layers[index1] = (IFillSymbol) aux2;
211 193
	}
212 194

  
213
	public ISymbol getLayer(int layerIndex) {
214
//		try{
215
			return layers[layerIndex];
216
//		} catch (Exception e) {
217
//			return null;
218
//		}
219
	}
195
        @Override
196
        public ISymbol getLayer(int layerIndex) {
197
            return layers[layerIndex];
198
        }
220 199

  
200
        @Override
221 201
	public int getLayerCount() {
222 202
		return layers.length;
223 203
	}
224 204

  
205
        @Override
225 206
	public void addLayer(ISymbol newLayer) {
226 207
		addLayer(newLayer, layers.length);
227 208
	}
228 209

  
210
        @Override
229 211
	public void addLayer(ISymbol newLayer, int layerIndex) throws IndexOutOfBoundsException {
230 212
		if (newLayer == null ) {
231 213
			/*|| newLayer instanceof ILabelStyle)*/ return; // null or symbols that are styles are not allowed
......
237 219
		if (layerIndex < 0 || layers.length < layerIndex) {
238 220
			throw new IndexOutOfBoundsException(layerIndex+" < 0 or "+layerIndex+" > "+layers.length);
239 221
		}
240
		List<ISymbol> newLayers = new ArrayList<ISymbol>();
241
		for (int i = 0; i < layers.length; i++) {
242
			newLayers.add(layers[i]);
243
		}
222
		List<ISymbol> newLayers = new ArrayList<>();
223
                newLayers.addAll(Arrays.asList(layers));
244 224
		try {
245 225
			newLayers.add(layerIndex, newLayer);
246 226
			layers = (IFillSymbol[]) newLayers.toArray(new IFillSymbol[0]);
......
249 229
		}
250 230
	}
251 231

  
232
        @Override
252 233
	public boolean removeLayer(ISymbol layer) {
253 234

  
254
		int capacity = 0;
255
		capacity = layers.length;
235
		int capacity = layers.length;
256 236
		List<IFillSymbol> lst = new ArrayList<IFillSymbol>(capacity);
257 237
		for (int i = 0; layers != null && i < capacity; i++) {
258 238
			lst.add(layers[i]);
......
262 242
		return contains;
263 243
	}
264 244

  
245
        @Override
265 246
	public void setUnit(int unitIndex) {
266 247
		super.setUnit(unitIndex);
267 248
		for (int i = 0; layers != null && i < layers.length; i++) {
......
269 250
		}
270 251
	}
271 252

  
253
        @Override
272 254
	public void setReferenceSystem(int system) {
273 255
		super.setReferenceSystem(system);
274 256
		for (int i = 0; layers != null && i < layers.length; i++) {
......
279 261
	/**
280 262
	 *Returns the transparency of the multi layer fill symbol created
281 263
	 */
264
        @Override
282 265
	public int getFillAlpha() {
283 266
		// will compute the acumulated opacity
284 267
		double myAlpha = 0;
......
290 273
		return (result>255) ? 255 : result;
291 274
	}
292 275

  
293
        public void setCartographicSize(double cartographicSize, Geometry geom) {
294
		for (int i = 0; layers != null && i < layers.length; i++) {
295
                    ILineSymbol outlineLayer = layers[i].getOutline();
296
                    if(outlineLayer != null){
297
                        outlineLayer.setLineWidth(cartographicSize);
298
                    }
299
		}
300
	}
301
        
302
	public double toCartographicSize(ViewPort viewPort, double dpi, Geometry geom) {
303
		double size = 0;
304
		for (int i = 0; layers != null && i < layers.length; i++) {
305
			size = Math.max(size, layers[i].toCartographicSize(viewPort, dpi, geom));
306
		}
307
		return size;
308
	}
309

  
310 276
	public Object clone() throws CloneNotSupportedException {
311 277
		MultiLayerFillSymbol copy = (MultiLayerFillSymbol) super.clone();
312 278

  
......
333 299
	}
334 300

  
335 301
	@SuppressWarnings("unchecked")
302
        @Override
336 303
	public void loadFromState(PersistentState state)
337 304
			throws PersistenceException {
338 305
		// Set parent fill symbol properties
......
341 308
		// Set own properties
342 309
		// setSymbolForSelection((MultiLayerFillSymbol)
343 310
		// state.get(FIELD_SYMBOL_FOR_SELECTION));
344
		List layers = state.getList(FIELD_LAYERS);
345
		if (layers != null) {
346
			for (int i = 0; i < layers.size(); i++) {
347
				addLayer((ISymbol) layers.get(i));
311
		List theLayers = state.getList(FIELD_LAYERS);
312
		if (theLayers != null) {
313
			for (int i = 0; i < theLayers.size(); i++) {
314
				addLayer((ISymbol) theLayers.get(i));
348 315
			}
349 316
		}
350 317

  
351 318
	}
352 319

  
320
        @Override
353 321
	public void saveToState(PersistentState state) throws PersistenceException {
354 322
		// Save parent fill symbol properties
355 323
		super.saveToState(state);
......
364 332

  
365 333
	public static class RegisterPersistence implements Callable {
366 334

  
335
                @Override
367 336
		public Object call() throws Exception {
368 337
			PersistenceManager manager = ToolsLocator.getPersistenceManager();
369 338
			if( manager.getDefinition(MULTILAYER_FILL_SYMBOL_PERSISTENCE_DEFINITION_NAME)==null ) {
......
392 361

  
393 362
	public static class RegisterSymbol implements Callable {
394 363

  
364
                @Override
395 365
		public Object call() throws Exception {
396 366
			int[] shapeTypes;
397 367
			SymbolManager manager = MapContextLocator.getSymbolManager();

Also available in: Unified diff