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/style/ArrowDecoratorStyle.java

View differences:

ArrowDecoratorStyle.java
27 27
import java.awt.Rectangle;
28 28
import java.awt.geom.AffineTransform;
29 29
import java.awt.geom.Point2D;
30

  
31 30
import org.apache.batik.ext.awt.geom.DefaultPathLength;
32 31
import org.gvsig.fmap.dal.feature.Feature;
33 32
import org.gvsig.fmap.geom.Geometry;
......
36 35
import org.gvsig.fmap.geom.GeometryManager;
37 36
import org.gvsig.fmap.geom.exception.CreateGeometryException;
38 37
import org.gvsig.fmap.geom.primitive.Point;
38
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport;
39 39
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
40
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol_v2;
40 41
import org.gvsig.symbology.PathLength;
41 42
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
42 43
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IArrowMarkerSymbol;
......
84 85
	 * Obtains the number of arrows that the user wants to draw in the same line.
85 86
	 * @return
86 87
	 */
88
        @Override
87 89
	public int getArrowMarkerCount() {
88 90
		return arrowMarkerCount;
89 91
	}
......
92 94
	 * Defines the number of arrows that the user wants to draw in the same line.
93 95
	 * @return
94 96
	 */
97
        @Override
95 98
	public void setArrowMarkerCount(int arrowMarkerCount) {
96 99
		this.arrowMarkerCount = arrowMarkerCount;
97 100
	}
......
101 104
	 * arrows that we had drawn in the same line will be flipped.
102 105
	 * @return
103 106
	 */
107
        @Override
104 108
	public boolean isFlipAll() {
105 109
		return flipAll;
106 110
	}
......
110 114
	 * arrows that we had drawn in the same line will be flipped.
111 115
	 * @return
112 116
	 */
117
        @Override
113 118
	public void setFlipAll(boolean flipAll) {
114 119
		this.flipAll = flipAll;
115 120
	}
......
119 124
	 * will be flipped.The rest will keep the same orientation.
120 125
	 * @return
121 126
	 */
127
        @Override
122 128
	public boolean isFlipFirst() {
123 129
		return flipFirst;
124 130
	}
......
128 134
	 * will be flipped.The rest will keep the same orientation.
129 135
	 * @return
130 136
	 */
137
        @Override
131 138
	public void setFlipFirst(boolean flipFirst) {
132 139
		this.flipFirst = flipFirst;
133 140
	}
......
137 144
	 * going to draw to be more or less aligned with the line where it will be included (depending on the angle) .
138 145
	 * @return
139 146
	 */
147
        @Override
140 148
	public boolean isFollowLineAngle() {
141 149
		return followLineAngle;
142 150
	}
......
148 156
	 * @param followingLineAngle
149 157
	 * @return
150 158
	 */
159
        @Override
151 160
	public void setFollowLineAngle(boolean followLineAngle) {
152 161
		this.followLineAngle = followLineAngle;
153 162
	}
......
162 171
	 * @param shp
163 172
	 * @throws CreateGeometryException 
164 173
	 */
174
        @Override
165 175
	public void draw(Graphics2D g, AffineTransform affineTransform,
166 176
			Geometry geom, Feature feature) throws CreateGeometryException {
167
		if (arrowMarkerCount <= 0) return;
177
		if (arrowMarkerCount <= 0) {
178
                    return;
179
                }
168 180

  
169
		Geometry geomToDraw = geom.cloneGeometry();
170
		geomToDraw.transform(affineTransform);
181
		Geometry geomToDraw = geom;
182
                if(affineTransform != null){
183
                    geomToDraw = geom.cloneGeometry();
184
                    geomToDraw.transform(affineTransform);
185
                }
171 186
		PathLength pl = new DefaultPathLength(geomToDraw.getShape());
172
		float size = (float) marker.getSize();
187
                float size = (float) marker.getSize();
188
                if(marker instanceof CartographicSupport){
189
                    ((CartographicSupport)marker).setCartographicContext(this.getCartographicContext());
190
                    size = (float) ((CartographicSupport)marker).toCartographicUnits(size);
191
                }
192
                
173 193
		marker.setRotation(0.0);
174 194
		float myLineLength = pl.lengthOfPath();
175 195
		if (size > myLineLength){
......
183 203

  
184 204
		// the first arrow at the end of the line
185 205
		float theLength = pl.lengthOfPath();
186
		{
187 206

  
188
			if ((flipFirst || flipAll) && (flipFirst != flipAll) && followLineAngle) { // logical XOR
189
				Point2D p = pl.pointAtLength(theLength-size);
190
				if (p!=null){
191
					startP = geomManager.createPoint(p.getX(), p.getY(), SUBTYPES.GEOM2D);
192
					if(followLineAngle){
193
						rotation1 = pl.angleAtLength(theLength-size);
194
						rotation2 = pl.angleAtLength(theLength);
195
						marker.setRotation(rotation1);
196
					}
197
					marker.draw(g, new AffineTransform(), startP, feature, null);
198
				}
199
			} else {
200
				Point2D p = pl.pointAtLength(theLength);
201
				if (p!=null){
202
					startP = geomManager.createPoint(p.getX(), p.getY(), SUBTYPES.GEOM2D);
203
					if(followLineAngle){
204
						rotation1 = pl.angleAtLength(theLength-size)+(float) Math.PI;
205
						rotation2 = pl.angleAtLength(theLength)+(float) Math.PI;
206
						marker.setRotation(rotation2);
207
					}
208
					marker.draw(g, new AffineTransform(), startP, feature, null);
209
				}
210
			}
211
		}
212
		// the other arrows but the first and the last
207
                if ((flipFirst || flipAll) && (flipFirst != flipAll) && followLineAngle) { // logical XOR
208
                    Point2D p = pl.pointAtLength(theLength-size);
209
                    if (p!=null){
210
                            startP = geomManager.createPoint(p.getX(), p.getY(), SUBTYPES.GEOM2D);
211
                            if(followLineAngle){
212
                                    rotation1 = pl.angleAtLength(theLength-size);
213
                                    rotation2 = pl.angleAtLength(theLength);
214
                                    marker.setRotation(rotation1);
215
                            }
216
                            if(marker instanceof ISymbol_v2){
217
                                ((ISymbol_v2)marker).draw(g, new AffineTransform(), startP, feature, null, null);
218
                            } else {
219
                                marker.draw(g, new AffineTransform(), startP, feature, null);
220
                            }
221
                    }
222
                } else {
223
                        Point2D p = pl.pointAtLength(theLength);
224
                        if (p!=null){
225
                                startP = geomManager.createPoint(p.getX(), p.getY(), SUBTYPES.GEOM2D);
226
                                if(followLineAngle){
227
                                        rotation1 = pl.angleAtLength(theLength-size)+(float) Math.PI;
228
                                        rotation2 = pl.angleAtLength(theLength)+(float) Math.PI;
229
                                        marker.setRotation(rotation2);
230
                                }
231
                                if(marker instanceof ISymbol_v2){
232
                                    ((ISymbol_v2)marker).draw(g, new AffineTransform(), startP, feature, null, null);
233
                                } else {
234
                                    marker.draw(g, new AffineTransform(), startP, feature, null);
235
                                }
236
                        }
237
                }
238

  
239
                // the other arrows but the first and the last
213 240
		float aLength;
214 241
		for (int i = 1; i < arrowMarkerCount-1; i++) {
215 242
			aLength = (float) (step*i);
216 243

  
217 244
			if (flipAll && followLineAngle) {
218
				Point2D p = pl.pointAtLength(aLength);
245
				Point2D p = pl.pointAtLength(aLength-size);
219 246
				if (p==null){
220 247
					p = pl.pointAtLength(theLength);
221 248
				}
......
225 252
					rotation2 = (float) pl.angleAtLength((float)(aLength+size));
226 253
					marker.setRotation(rotation1);
227 254
				}
228
					marker.draw(g, new AffineTransform(), startP, feature, null);
255
                                        if(marker instanceof ISymbol_v2){
256
                                            ((ISymbol_v2)marker).draw(g, new AffineTransform(), startP, feature, null, null);
257
                                        } else {
258
                                            marker.draw(g, new AffineTransform(), startP, feature, null);
259
                                        }
229 260
			} else {
230 261
				Point2D p = pl.pointAtLength(aLength+size);
231 262
				if (p==null){
......
238 269
					rotation2 = (float) (pl.angleAtLength((float)(aLength+size)) + Math.PI);
239 270
					marker.setRotation(rotation2);
240 271
				}
241
				marker.draw(g, new AffineTransform(), startP, feature, null);
272
                                        if(marker instanceof ISymbol_v2){
273
                                            ((ISymbol_v2)marker).draw(g, new AffineTransform(), startP, feature, null, null);
274
                                        } else {
275
                                            marker.draw(g, new AffineTransform(), startP, feature, null);
276
                                        }
242 277
			}
243 278
		}
244 279

  
......
255 290
						rotation2 = (float) pl.angleAtLength(0);
256 291
						marker.setRotation(rotation2);
257 292
					}
258
					marker.draw(g, new AffineTransform(), startP, feature, null);
293
                                        if(marker instanceof ISymbol_v2){
294
                                            ((ISymbol_v2)marker).draw(g, new AffineTransform(), startP, feature, null, null);
295
                                        } else {
296
                                            marker.draw(g, new AffineTransform(), startP, feature, null);
297
                                        }
259 298
				}				
260 299
			} else {
261 300
				Point2D p = null;
......
271 310
						rotation2 = (float) (pl.angleAtLength(0) + Math.PI);
272 311
						marker.setRotation(rotation1);
273 312
					}
274
					marker.draw(g, new AffineTransform(), startP, feature, null);
313
                                        if(marker instanceof ISymbol_v2){
314
                                            ((ISymbol_v2)marker).draw(g, new AffineTransform(), startP, feature, null, null);
315
                                        } else {
316
                                            marker.draw(g, new AffineTransform(), startP, feature, null);
317
                                        }
275 318
				}
276 319
			}
277 320
		}
278 321
	}
279 322

  
323
        @Override
280 324
	public void drawInsideRectangle(Graphics2D g, Rectangle r) {
281 325
		// TODO Auto-generated method stub
282 326
		throw new Error("Not yet implemented!");
283 327
	}
284 328

  
329
        @Override
285 330
	public void drawOutline(Graphics2D g, Rectangle r) {
286 331
		// TODO Auto-generated method stub
287 332
		throw new Error("Not yet implemented!");
288 333
	}
289 334

  
335
        @Override
290 336
	public boolean isSuitableFor(ISymbol symbol) {
291 337
		return symbol instanceof ILineSymbol;
292 338
	}
......
295 341
		return getClass().getName();
296 342
	}
297 343

  
344
        @Override
298 345
	public IMarkerSymbol getMarker() {
299 346
		if(marker == null){
300 347
			marker = getDefaultMarker();
......
302 349
		return marker;
303 350
	}
304 351

  
352
        @Override
305 353
	public void setMarker(IMarkerSymbol marker) {
306 354
		this.marker = marker;
307 355
	}
308 356
	
357
        @Override
309 358
	public Object clone() throws CloneNotSupportedException {
310 359
		ArrowDecoratorStyle copy  = (ArrowDecoratorStyle) super.clone();
311 360
		if (marker != null) {
......
314 363
		return copy;
315 364
	}
316 365

  
366
        @Override
317 367
	public void loadFromState(PersistentState state)
318 368
			throws PersistenceException {
319 369
		// Set parent style properties
......
327 377
		setMarker((IMarkerSymbol) state.get(FIELD_MARKER));
328 378
	}
329 379

  
380
        @Override
330 381
	public void saveToState(PersistentState state) throws PersistenceException {
331 382
		// Save parent fill symbol properties
332 383
		super.saveToState(state);
......
341 392
	
342 393
	public static class RegisterPersistence implements Callable {
343 394

  
395
                @Override
344 396
		public Object call() throws Exception {
345 397
			PersistenceManager manager = ToolsLocator.getPersistenceManager();
346 398
			if( manager.getDefinition(ARROR_DECORATOR_STYLE_PERSISTENCE_DEFINITION_NAME)==null ) {
......
374 426
		
375 427
	}
376 428

  
429
    @Override
430
    public void setCartographicContext(CartographicContext ctx) {
431
        super.setCartographicContext(ctx);
432
        if(this.marker instanceof CartographicContext){
433
            ((CartographicSupport)marker).setCartographicContext(ctx);
434
        }
435
    }
436
        
437
        
438

  
377 439
}

Also available in: Unified diff