Revision 12988 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/symbols/PictureLineSymbol.java

View differences:

PictureLineSymbol.java
67 67
import com.iver.utiles.XMLEntity;
68 68

  
69 69
/**
70
 * PictureLineSymbol allows to use any symbol defined as an image (by an image file)
71
 * supported  by gvSIG.This symbol will be used as an initial object.The line will be
72
 * painted as a succession of puntual symbols through the path defined by it(the line).
73
 *
70 74
 * @author jaume dominguez faus - jaume.dominguez@iver.es
71 75
 */
72 76
public class PictureLineSymbol extends AbstractLineSymbol  {
......
79 83
	private boolean selected;
80 84
	private double xScale = 1;
81 85
	private double yScale = 1;
82

  
86
	/**
87
	 * Constructor method
88
	 *
89
	 */
83 90
	public PictureLineSymbol() {
84 91
		super();
85 92
	}
93
	/**
94
	 * Constructor method
95
	 * @param imageURL, URL of the normal image
96
	 * @param selImageURL, URL of the image when it is selected in the map
97
	 * @throws IOException
98
	 */
86 99

  
87 100
	public PictureLineSymbol(URL imageURL, URL selImageURL) throws IOException {
88 101
		this(new File(imageURL.getFile()), selImageURL !=null ? new File(selImageURL.getFile()) : null);
89 102
	}
90

  
103
	/**
104
	 * Constructor method
105
	 * @param imageFile, File of the normal image
106
	 * @param selImageFile, File of the image when it is selected in the map
107
	 * @throws IOException
108
	 */
91 109
	public PictureLineSymbol(File imageFile, File selImageFile) throws IOException {
92 110
		setImage(imageFile);
93 111
		if (selImageFile!=null)
94 112
			setSelImage(selImageFile);
95 113
	}
96

  
114
	/**
115
	 * Sets the file for the image to be used as a picture line symbol
116
	 * @param imageFile, File
117
	 * @throws IOException
118
	 */
97 119
	public void setImage(File imageFile) throws IOException{
98 120
		img = ImageIO.read(imageFile);
99 121
		imagePath = imageFile.getAbsolutePath();
100 122
//		imageOutline = null;
101 123
	}
102

  
124
	/**
125
	 * Sets the file for the image to be used as a picture line symbol (when it is selected in the map)
126
	 * @param imageFile, File
127
	 * @throws IOException
128
	 */
103 129
	public void setSelImage(File imageFile) throws IOException{
104 130
		if (imageFile!=null && imageFile.exists()) {
105 131
			selImg = ImageIO.read(imageFile);
......
131 157
		return selectionSym;
132 158

  
133 159
	}
134

  
160
	/**
161
	 * Returns the image that will substitute the picture line symbol when it is selected
162
	 * in the map
163
	 * @return img, BufferedImage
164
	 * @throws IOException
165
	 */
135 166
	private BufferedImage getImg() throws IOException {
136 167
		if (img == null) {
137 168
			img = ImageIO.read(new File(imagePath));
138 169
		}
139 170
		return img;
140 171
	}
141
	
172
	/**
173
	 * Returns the image that will substitute the picture line symbol when it is selected
174
	 * in the map
175
	 * @return selImg, BufferedImage
176
	 * @throws IOException
177
	 */
142 178
	private BufferedImage getSelImg() throws IOException {
143 179
		if (selImg == null) {
144 180
			if (selImagePath!= null) {
......
156 192
			if (xScale<=0 &&  yScale<=0)
157 193
				return;
158 194
			AffineTransform scaleInstance = AffineTransform.getScaleInstance(xScale, yScale);
159
			
195

  
160 196
			final double imageWidth  = img.getWidth()  * xScale;
161 197
			final double imageHeight = img.getHeight() * yScale;
162
			
198

  
163 199
			if (imageWidth==0 || imageHeight==0) return;
164 200
			double halfImageHeight = imageHeight*.5;
165
			
201

  
166 202
			PathLength pl = new PathLength(shp);
167 203
			PathIterator iterator = ((FPolyline2D) shp).getPathIterator(null, 0.8);
168 204
			double[] theData = new double[6];
......
173 209
				}
174 210
			}
175 211
			float currentPathLength = 1;
176
			
212

  
177 213
			while (!iterator.isDone()) {
178 214

  
179 215
				int theType = iterator.currentSegment(theData);
......
201 237
				double a = endPoint.getX() - startPoint.getX();
202 238
				double b = endPoint.getY() - startPoint.getY();
203 239
				double theta = pl.angleAtLength(currentPathLength);
204
				
240

  
205 241
				double x = startPoint.getX();
206 242
				double y = startPoint.getY();
207 243

  
208 244
				// Theorem of Pythagoras
209 245
				float segmentLength = (float) Math.sqrt(a*a + b*b);
210
				
246

  
211 247
				// compute how many times the image has to be drawn
212 248
				// to completely cover this segment's length
213 249
				int count = (int) Math.ceil(segmentLength/imageWidth);
214
				
250

  
215 251
				for (int i = 0; i < count; i++) {
216 252
					g.translate(x, y);
217 253
					g.rotate(theta);
218
					
254

  
219 255
					double xOffsetTranslation = imageWidth*i;
220 256

  
221 257
						g.translate(xOffsetTranslation, -halfImageHeight);
222 258
						g.drawImage(img, scaleInstance, null);
223 259
						g.translate(-xOffsetTranslation, halfImageHeight);
224
					
260

  
225 261
					g.rotate(-theta);
226 262
					g.translate(-x, -y);
227 263
				}
228
			
264

  
229 265
				startPoint = endPoint;
230
				currentPathLength += segmentLength;		
266
				currentPathLength += segmentLength;
231 267
				iterator.next();
232 268
			}
233 269

  
......
277 313
		setUnit(xml.getIntProperty("unit"));
278 314

  
279 315
	}
280

  
316
	/**
317
	 * Sets the yscale for the picture line symbol
318
	 * @param yScale
319
	 */
281 320
	public void setYScale(double yScale) {
282 321
		this.yScale = yScale;
283 322

  
284 323
	}
285

  
324
	/**
325
	 * Sets the xscale for the picture line symbol
326
	 * @param xScale
327
	 */
286 328
	public void setXScale(double xScale) {
287 329
		this.xScale = xScale;
288 330
	}
......
297 339
		throw new Error("Not yet implemented!");
298 340

  
299 341
	}
300

  
342
	/**
343
	 * Return the path of the image that is used as a picture line symbol (when it
344
	 * is selected in the map)
345
	 * @return selimagePath,String
346
	 */
301 347
	public String getSelImagePath() {
302 348
		return selImagePath;
303 349
	}
304

  
350
	/**
351
	 * Return the path of the image that is used as a picture line symbol
352
	 * @return imagePath,String
353
	 */
305 354
	public String getImagePath() {
306 355
		return imagePath;
307 356
	}
308

  
357
	/**
358
	 * Returns the xscale for the picture line symbol
359
	 * @param xScale
360
	 */
309 361
	public double getXScale() {
310 362
		return xScale;
311 363
	}
312

  
364
	/**
365
	 * Returns the yscale for the picture line symbol
366
	 * @param yScale
367
	 */
313 368
	public double getYScale() {
314 369
		return yScale;
315 370
	}
316
	
371

  
317 372
}

Also available in: Unified diff