Revision 18621 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/symbols/AbstractLineSymbol.java

View differences:

AbstractLineSymbol.java
99 99
import java.awt.Graphics2D;
100 100
import java.awt.Rectangle;
101 101
import java.awt.geom.AffineTransform;
102
import java.awt.geom.PathIterator;
102 103
import java.awt.geom.Point2D;
104
import java.util.ArrayList;
103 105

  
104 106
import com.iver.cit.gvsig.fmap.ViewPort;
105 107
import com.iver.cit.gvsig.fmap.core.CartographicSupportToolkit;
......
123 125
public abstract class AbstractLineSymbol extends AbstractSymbol implements ILineSymbol {
124 126
	private Color color = SymbologyFactory.DefaultSymbolColor;
125 127
	private ILineStyle lineStyle;
126
	private int unit;
127
	private int referenceSystem;
128 128

  
129 129

  
130 130
	public Color getColor() {
......
143 143
		return FShape.LINE;
144 144
	}
145 145

  
146
	public void getPixExtentPlus(FShape shp, float[] distances, ViewPort viewPort, int dpi) {
147
		float cs = (float) getCartographicSize(viewPort, dpi, shp);
148
		// TODO and add the line offset
149
		distances[0] = cs;
150
		distances[1] = cs;
151
	}
152

  
146 153
	public boolean isSuitableFor(IGeometry geom) {
147 154
		switch(geom.getGeometryType()) {
148 155
		// pasted from FSymbol
......
173 180
		color = new Color(color.getRed(), color.getGreen(), color.getBlue(), outlineAlpha);
174 181
	}
175 182

  
176
	public void setUnit(int unitIndex) {
177
		this.unit = unitIndex;
178
	}
179

  
180
	public int getUnit() {
181
		return this.unit;
182
	}
183

  
184
	public void drawInsideRectangle(Graphics2D g, AffineTransform scaleInstance, Rectangle r) {
183
	public void drawInsideRectangle(Graphics2D g, AffineTransform scaleInstance, Rectangle r) throws SymbolDrawingException {
185 184
		final int hGap = (int) (r.getWidth() * 0.1); // the left and right margins
186 185
		final int vPos = 1; 						 // the top and bottom margins
187 186
		final int splitCount = 3; 					 // number of lines
188 187
		final int splitHSize = (r.width - hGap - hGap) / splitCount;
189 188
		int hPos = hGap;
190 189
		boolean swap = false;
191
		int offset = 0;
192
		ILineStyle iStyle = getLineStyle();
193
		if (iStyle != null) {
194
			offset = (int) iStyle.getOffset();
195
		}
190
		
196 191
		GeneralPathX gpx = new GeneralPathX();
197
		gpx.moveTo(r.x + hPos, r.y + r.height-vPos + offset);
192
		gpx.moveTo(r.x + hPos, r.y + r.height-vPos);
198 193

  
199 194
		for (int i = 0; i < splitCount; i++) {
200 195
			swap = !swap;
201
			gpx.lineTo(r.x + hPos + splitHSize, (swap ? vPos : r.height-vPos) + r.y + offset);
196
			gpx.lineTo(r.x + hPos + splitHSize, (swap ? vPos : r.height-vPos) + r.y);
202 197
			hPos += splitHSize;
203 198
		}
204 199

  
200
		
205 201
		draw(g, new AffineTransform(), new FPolygon2D(gpx), null);
206 202
	}
207 203

  
208 204

  
209 205

  
210 206
	public void setCartographicSize(double cartographicSize, FShape shp) {
211
		setLineWidth(cartographicSize);
207
		getLineStyle().setLineWidth((float) cartographicSize);
212 208
	}
213 209

  
214 210
	public double toCartographicSize(ViewPort viewPort, double dpi, FShape shp) {
......
229 225
										  dpi);
230 226
	}
231 227

  
228
	public static FShape offsetFShape(FShape shp, double offset) {
229
		FShape offsetFShape = null;
230
		if (shp != null) {
231
			if (offset == 0)
232
				return shp;
233
			
234
			ArrayList<Point2D[]> segments = new ArrayList<Point2D[]>();
235
			GeneralPathX gpx = new GeneralPathX(shp);
236
			PathIterator it = gpx.getPathIterator(null);
237
			double[] data = new double[6];
238
			Point2D segmentIni = null;
239
			Point2D segmentEnd = null;
240
			while (!it.isDone()) {
241
				switch (it.currentSegment(data)) {
242
				case PathIterator.SEG_MOVETO:
243
					segmentEnd = new Point2D.Double(
244
							data[0], data[1]);
245
					break;
232 246

  
247
				case PathIterator.SEG_LINETO:
248
					segmentEnd = segmentIni;
249
					segmentIni = new Point2D.Double(
250
							data[0], data[1]);
251
					
252
					segments.add(getParallel(segmentIni, segmentEnd, offset));
253
					break;
233 254

  
255
				case PathIterator.SEG_QUADTO:
256
					break;
234 257

  
235
	public int getReferenceSystem() {
236
		return this.referenceSystem;
237
	}
258
				case PathIterator.SEG_CUBICTO:
259
					break;
238 260

  
239
	public void setReferenceSystem(int system) {
240
		this.referenceSystem = system;
241

  
261
				case PathIterator.SEG_CLOSE:
262
					break;
263
				}
264
			}
265
			
266
		}
267
		
268
		
269
		return offsetFShape;
242 270
	}
243 271
	
244
	private static Point2D[] getParallel(Point2D p1,Point2D p2,double distance) {
272
	private static Point2D[] getParallel(Point2D p1, Point2D p2, double distance) {
245 273
		Point2D[] pParallel=new Point2D[2];
246 274
		pParallel[0]=getPerpendicularPoint(p1,p2,p1,distance);
247 275
		pParallel[1]=getPerpendicularPoint(p1,p2,p2,distance);

Also available in: Unified diff