Revision 12988

View differences:

trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/symbols/PictureMarkerSymbol.java
43 43
 *
44 44
 * $Id$
45 45
 * $Log$
46
 * Revision 1.12  2007-08-08 12:05:17  jvidal
46
 * Revision 1.13  2007-08-09 06:42:24  jvidal
47 47
 * javadoc
48 48
 *
49
 * Revision 1.12  2007/08/08 12:05:17  jvidal
50
 * javadoc
51
 *
49 52
 * Revision 1.11  2007/07/18 06:54:35  jaume
50 53
 * continuing with cartographic support
51 54
 *
......
113 116
import com.iver.utiles.XMLEntity;
114 117

  
115 118
/**
116
 * PictureMarkerSymbol allows to use an image file to be painted instead of a symbol
119
 * PictureMarkerSymbol allows to use an image file as a definition to be painted
120
 * instead of a marker symbol.
117 121
 *
118 122
 * @author   jaume dominguez faus - jaume.dominguez@iver.es
119 123
 */
......
163 167
			setSelImage(selImageFile);
164 168
	}
165 169
	/**
166
	 * Sets the file for the image to be used as a symbol
170
	 * Sets the file for the image to be used as a marker symbol
167 171
	 * @param imageFile, File
168 172
	 * @throws IOException
169 173
	 */
......
174 178
	}
175 179

  
176 180
	/**
177
	 * Returns the image that will substitute the symbol
181
	 * Returns the image that will substitute the marker symbol
178 182
	 * @return img, BufferedImage
179 183
	 * @throws IOException
180 184
	 */
......
186 190
		return img;
187 191
	}
188 192
	/**
189
	 * Sets the file for the image to be used as a symbol (when it is selected in the map)
193
	 * Sets the file for the image to be used as a  marker symbol (when it is selected in the map)
190 194
	 * @param imageFile, File
191 195
	 * @throws IOException
192 196
	 */
......
203 207
	}
204 208

  
205 209
	/**
206
	 * Returns the image that will substitute the symbol when it is selected in the map
210
	 * Returns the image that will substitute the marker symbol when it is selected in the map
207 211
	 * @return selImg, BufferedImage
208 212
	 * @throws IOException
209 213
	 */
......
317 321

  
318 322
	}
319 323
	/**
320
	 * Return the path of the image that is used as a symbol
324
	 * Return the path of the image that is used as a marker symbol
321 325
	 * @return imagePath,String
322 326
	 */
323 327
	public String getImagePath() {
324 328
		return imagePath;
325 329
	}
326 330
	/**
327
	 * Return the path of the image that is used as a symbol (when it is selected in the map)
331
	 * Return the path of the image that is used as a marker symbol (when it is selected in the map)
328 332
	 * @return selimagePath,String
329 333
	 */
330 334
	public String getSelImagePath() {
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/symbols/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