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/SimpleLineStyle.java

View differences:

SimpleLineStyle.java
28 28
import java.awt.Graphics2D;
29 29
import java.awt.Rectangle;
30 30
import java.awt.Stroke;
31

  
32
import org.gvsig.fmap.geom.Geometry;
33
import org.gvsig.fmap.mapcontext.ViewPort;
34 31
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport;
35 32
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
36
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl.CartographicSupportToolkit;
37 33
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.line.ILineSymbol;
38 34
import org.gvsig.tools.ToolsLocator;
39 35
import org.gvsig.tools.dynobject.DynStruct;
......
71 67
	private int lineJoin;
72 68
	private float miterlimit;
73 69
	private float lineWidth = 1f;
74
	private int measureUnit;// for the offset distance
75
	private double offset = 0, csOffset = 0;
76
	private int referenceSystem;
70
	private double offset = 0;
77 71
	private IArrowDecoratorStyle arrowDecorator;
78 72
	/**
79 73
	 * Constructor method
......
110 104
		this.dashPhase = dash_phase;
111 105
	}
112 106

  
107
        @Override
113 108
	public void drawInsideRectangle(Graphics2D g, Rectangle r) {
114 109
		Stroke oldStroke = g.getStroke();
115 110
		int h = (int) (r.getHeight() / 2);
......
132 127
		return getClass().getName();
133 128
	}
134 129

  
130
        @Override
135 131
	public Stroke getStroke() {
136 132
		return new BasicStroke((float) lineWidth, endCap, lineJoin, miterlimit, tempDashArray, dashPhase);
137 133
	}
138 134

  
135
        @Override
136
    public Stroke getCartographicStroke() {
137
        if (dashArray != null) {
138
            for (int i = 0; i < dashArray.length; i++) {
139
                tempDashArray[i] = (float) (toCartographicUnits(dashArray[i]));
140
            }
141
        }
142
        return new BasicStroke((float) (toCartographicUnits(lineWidth)), endCap, lineJoin, miterlimit, tempDashArray, dashPhase);
143
    }
144

  
145
        @Override
139 146
	public float getLineWidth() {
140 147
		return lineWidth;
141 148
	}
142 149

  
143 150

  
151
        @Override
144 152
	public void setLineWidth(float width) {
145
		if (lineWidth != 0) {
146
			double scale = width / this.lineWidth;
147
			if (dashArray != null) {
148
				for (int i = 0; scale > 0 && i < dashArray.length; i++) {
149
					tempDashArray[i] = (float) (dashArray[i] * scale);
150
				}
151
			}
152
			this.csOffset = offset * scale;
153
		}
154 153
		this.lineWidth = width;
155 154

  
156 155
	}
157 156

  
157
        @Override
158 158
	public boolean isSuitableFor(ISymbol symbol) {
159 159
		return symbol instanceof ILineSymbol;
160 160
	}
161 161

  
162
        @Override
162 163
	public void setStroke(Stroke stroke) {
163 164
		if (stroke != null) {
164 165
			BasicStroke dummy = (BasicStroke) stroke;
165 166
			dashArray = dummy.getDashArray();
166 167
			if (dashArray != null) {
167 168
				tempDashArray = new float[dashArray.length];
168
				for (int i = 0; i < dashArray.length; i++) {
169
					tempDashArray[i] = dashArray[i];
170
				}
169
                            System.arraycopy(dashArray, 0, tempDashArray, 0, dashArray.length);
171 170
			} else
172 171
				tempDashArray = null;
173 172

  
......
178 177
			miterlimit = dummy.getMiterLimit();
179 178
			lineWidth = dummy.getLineWidth();
180 179
			offset = getOffset();
181
			csOffset = offset;
182 180
		}
183 181
	}
184 182

  
183
        @Override
185 184
	public void drawOutline(Graphics2D g, Rectangle r) {
186 185
		drawInsideRectangle(g, r);
187 186
	}
188 187

  
188
        @Override
189 189
	public double getOffset() {
190
		return csOffset;
190
		return offset;
191 191
	}
192 192

  
193
        @Override
194
	public double getCartographicOffset() {
195
		return toCartographicUnits(offset);
196
	}
197

  
198
        @Override
193 199
	public void setOffset(double offset) {
194 200
		this.offset = offset;
195
		this.csOffset = offset;
196 201
	}
197 202

  
203
        @Override
198 204
	public IArrowDecoratorStyle getArrowDecorator() {
199 205
		return arrowDecorator;
200 206

  
201 207
	}
202 208

  
209
        @Override
203 210
	public void setArrowDecorator(IArrowDecoratorStyle arrowDecoratorStyle) {
204 211
		this.arrowDecorator = arrowDecoratorStyle;
205 212
	}
206 213

  
207
	public void setUnit(int unitIndex) {
208
		this.measureUnit = unitIndex;
209
	}
210

  
211
	public int getUnit() {
212
		return measureUnit;
213
	}
214

  
215
	public int getReferenceSystem() {
216
		return referenceSystem;
217
	}
218

  
219
	public void setReferenceSystem(int referenceSystem) {
220
		this.referenceSystem = referenceSystem;
221
	}
222

  
223
	public double toCartographicSize(ViewPort viewPort, double dpi, Geometry geom) {
224
		double oldWidth = getLineWidth();
225
		setCartographicSize(getCartographicSize(viewPort, dpi, geom), geom);
226
		return oldWidth;
227
	}
228

  
229
	public void setCartographicSize(double cartographicSize, Geometry geom) {
230
		setLineWidth((float) cartographicSize);
231

  
232
	}
233

  
234
	public double getCartographicSize(ViewPort viewPort, double dpi, Geometry geom) {
235
		return CartographicSupportToolkit.
236
		getCartographicLength(this,
237
				getOffset(),
238
				viewPort,
239
				dpi);
240

  
241
	}
242
	
243

  
214
        @Override
244 215
	public Object clone() throws CloneNotSupportedException {
245 216
		SimpleLineStyle copy = (SimpleLineStyle) super.clone();
246 217
		if (arrowDecorator != null) {
......
335 306
		this.miterlimit = miterlimit;
336 307
	}
337 308

  
309
        @Override
338 310
	public void loadFromState(PersistentState state)
339 311
			throws PersistenceException {
340 312
		// Set parent style properties
......
354 326
		setUnit(state.getInt(FIELD_UNIT));
355 327
	}
356 328

  
329
        @Override
357 330
	public void saveToState(PersistentState state) throws PersistenceException {
358 331
		// Save parent fill symbol properties
359 332
		super.saveToState(state);
......
373 346

  
374 347
	public static class RegisterPersistence implements Callable {
375 348

  
349
                @Override
376 350
		public Object call() throws Exception {
377 351
			PersistenceManager manager = ToolsLocator.getPersistenceManager();
378 352
			if( manager.getDefinition(SIMPLE_LINE_STYLE_PERSISTENCE_DEFINITION_NAME)==null ) {
......
415 389
		}
416 390
		
417 391
	}
392

  
393
    @Override
394
    public void setCartographicContext(CartographicContext ctx) {
395
        super.setCartographicContext(ctx);
396
        if(arrowDecorator instanceof CartographicSupport){
397
            ((CartographicSupport)arrowDecorator).setCartographicContext(ctx);
398
        }
399
    }
400
        
401
        
418 402
}

Also available in: Unified diff