Revision 12997 trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/core/symbols/PictureFillSymbol.java

View differences:

PictureFillSymbol.java
68 68
import com.iver.utiles.XMLEntity;
69 69

  
70 70
/**
71
 * PictureFillSymbol allows to use an image file suported by gvSIG as a padding
72
 * for the polygons.This image can be modified using methods to scale or rotate it.
71 73
 * @author jaume dominguez faus - jaume.dominguez@iver.es
72 74
 */
73 75
public class PictureFillSymbol extends AbstractFillSymbol {
74 76
	private double angle = 0;
75 77
	private double xScale = 1;
76 78
	private double yScale = 1;
77
	
79

  
78 80
	private IMarkerFillPropertiesStyle markerFillProperties = new SimpleMarkerFillPropertiesStyle();
79 81
	private String imagePath;
80 82
	private BufferedImage img;
......
89 91
		try{
90 92
			if (xScale<=0 &&  yScale<=0)
91 93
				return;
92
			
94

  
93 95
			BufferedImage img = getImg();
94
			
96

  
95 97
			final double imageWidth  = img.getWidth()  * xScale;
96 98
			final double imageHeight = img.getHeight() * yScale;
97
			
99

  
98 100
			if (imageWidth==0 || imageHeight==0) return;
99
			
101

  
100 102
			Rectangle rProv = new Rectangle();
101 103
			rProv.setFrame(0, 0, imageWidth, imageHeight);
102 104
			Paint resulPatternFill = null;
103
			
105

  
104 106
			Graphics2D gAux = img.createGraphics();
105 107

  
106 108
			double xSeparation = markerFillProperties.getXSeparation(); // TODO apply CartographicSupport
107 109
			double ySeparation = markerFillProperties.getYSeparation(); // TODO apply CartographicSupport
108 110
			double xOffset = markerFillProperties.getXOffset();// TODO apply CartographicSupport
109 111
			double yOffset = markerFillProperties.getYOffset();// TODO apply CartographicSupport
110
			
112

  
111 113
			rProv.setRect(0, 0,
112 114
					rProv.getWidth() + xSeparation,
113 115
					rProv.getHeight() + ySeparation);
......
124 126
			g.setPaint(resulPatternFill);
125 127
			g.fill(shp);
126 128
			g.translate(-xOffset, -yOffset);
127
			
129

  
128 130
		} catch (IOException e) {
129 131
			Logger.getLogger(this.getClass()).error(Messages.getString("failed_to_read_image_file"), e);
130 132
		}
131
		
133

  
132 134
		g.setClip(null);
133 135
		if (getOutline()!=null) {
134 136
			getOutline().draw(g, affineTransform, shp);
135 137
		}
136 138
	}
137

  
139
	/**
140
	 * Gets the path of the picture that is used to fill the polygon
141
	 * @return img,BufferedImage
142
	 * @throws IOException
143
	 */
138 144
	private BufferedImage getImg() throws IOException {
139 145
		if (img == null) {
140 146
			img = ImageIO.read(new File(imagePath));
141 147
		}
142 148
		return img;
143 149
	}
144
	
150
	/**
151
	 * Defines the file from where the picture to fill the polygon is taken.
152
	 * @param imageFile
153
	 * @throws IOException
154
	 */
145 155
	public void setImage(File imageFile) throws IOException{
146 156
		img = ImageIO.read(imageFile);
147 157
		imagePath = imageFile.getAbsolutePath();
148 158
	}
149
	
159

  
150 160
	public void drawInsideRectangle(Graphics2D g,
151 161
			AffineTransform scaleInstance, Rectangle r) {
152 162
		draw(g, null, new FPolygon2D(new GeneralPathX(r)));
......
172 182
		xml.putProperty("desc", getDescription());
173 183
		xml.putProperty("className", getClassName());
174 184
		xml.putProperty("isShapeVisible", isShapeVisible());
175
		
185

  
176 186
		xml.putProperty("angle", angle);
177 187
		xml.putProperty("scaleX", xScale);
178 188
		xml.putProperty("scaleY", yScale);
......
222 232
		// TODO Auto-generated method stub
223 233
		throw new Error("Not yet implemented!");
224 234
	}
225

  
235
	/**
236
	 * Returns the IMarkerFillProperties that allows this class to treat the picture as
237
	 * a marker in order to scale it, rotate it and so on.
238
	 * @return markerFillProperties,IMarkerFillPropertiesStyle
239
	 */
226 240
	public IMarkerFillPropertiesStyle getMarkerFillProperties() {
227 241
		return markerFillProperties;
228 242
	}
229
	
243

  
244
	/**
245
	 * Sets the MarkerFillProperties in order to allow the user to modify the picture as
246
	 * a marker (it is possible to scale it, rotate it and so on)
247
	 * @param prop
248
	 */
230 249
	public void setMarkerFillProperties(IMarkerFillPropertiesStyle prop) {
231 250
		this.markerFillProperties = prop;
232 251
	}
233

  
252
	/**
253
	 * Defines the angle for the rotation of the image when it is added to create the
254
	 * padding
255
	 *
256
	 * @return angle
257
	 */
234 258
	public double getAngle() {
235 259
		return angle;
236 260
	}
237

  
261
	/**
262
	 * Sets the angle for the rotation of the image when it is added to create the padding
263
	 * @param angle
264
	 */
238 265
	public void setAngle(double angle) {
239 266
		this.angle = angle;
240 267
	}
241 268

  
269
	/**
270
	 * Defines the scale for the x axis of the image when it is added to create the
271
	 * padding
272
	 * @return xScale
273
	 */
242 274
	public double getXScale() {
243 275
		return xScale;
244 276
	}
245

  
277
	/**
278
	 * Returns the scale for the x axis of the image when it is added to create the
279
	 * padding
280
	 * @param xScale
281
	 */
246 282
	public void setXScale(double xScale) {
247 283
		this.xScale = xScale;
248 284
	}
249

  
285
	/**
286
	 * Defines the scale for the y axis of the image when it is added to create the
287
	 * padding
288
	 * @return yScale
289
	 */
250 290
	public double getYScale() {
251 291
		return yScale;
252 292
	}
253

  
293
	/**
294
	 * Returns the scale for the y axis of the image when it is added to create the
295
	 * padding
296
	 * @param yScale
297
	 */
254 298
	public void setYScale(double yScale) {
255 299
		this.yScale = yScale;
256 300
	}
257
	
301
	/**
302
	 * Returns the path of the image that is used to create the padding to fill the
303
	 * polygon
304
	 * @return imagePath
305
	 */
258 306
	public String getImagePath() {
259 307
		return imagePath;
260 308
	}

Also available in: Unified diff