Revision 19091 trunk/extensions/extSymbology/src/org/gvsig/symbology/fmap/symbols/PictureFillSymbol.java
PictureFillSymbol.java | ||
---|---|---|
86 | 86 |
|
87 | 87 |
private IMarkerFillPropertiesStyle markerFillProperties = new SimpleMarkerFillPropertiesStyle(); |
88 | 88 |
private String imagePath; |
89 |
// private BufferedImage img; |
|
90 | 89 |
private BackgroundFileStyle bgImage; |
91 | 90 |
|
92 | 91 |
|
93 |
|
|
94 | 92 |
public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp, Cancellable cancel) { |
95 | 93 |
Color fillColor = getFillColor(); |
96 | 94 |
if (fillColor != null) { |
... | ... | |
99 | 97 |
} |
100 | 98 |
|
101 | 99 |
g.setClip(shp); |
102 |
// try{ |
|
103 |
if (xScale<=0 && yScale<=0) |
|
104 |
return; |
|
105 | 100 |
|
106 |
// BufferedImage img = getImg();
|
|
107 |
BackgroundFileStyle bg = bgImage ;
|
|
101 |
if (xScale<=0 && yScale<=0)
|
|
102 |
return;
|
|
108 | 103 |
|
109 |
final double imageWidth = bg.getBounds().getWidth() * xScale; |
|
110 |
final double imageHeight = bg.getBounds().getWidth() * yScale; |
|
104 |
BackgroundFileStyle bg = bgImage ; |
|
111 | 105 |
|
112 |
if (imageWidth==0 || imageHeight==0) return; |
|
106 |
final double imageWidth = bg.getBounds().getWidth() * xScale; |
|
107 |
final double imageHeight = bg.getBounds().getWidth() * yScale; |
|
113 | 108 |
|
114 |
Rectangle rProv = new Rectangle(); |
|
115 |
rProv.setFrame(0, 0, imageWidth, imageHeight); |
|
116 |
Paint resulPatternFill = null; |
|
109 |
if (imageWidth==0 || imageHeight==0) return; |
|
117 | 110 |
|
118 |
Graphics2D gAux;// = img.createGraphics(); |
|
111 |
Rectangle rProv = new Rectangle(); |
|
112 |
rProv.setFrame(0, 0, imageWidth, imageHeight); |
|
113 |
Paint resulPatternFill = null; |
|
119 | 114 |
|
120 |
double xSeparation = markerFillProperties.getXSeparation(); |
|
121 |
double ySeparation = markerFillProperties.getYSeparation(); |
|
122 |
double xOffset = markerFillProperties.getXOffset(); |
|
123 |
double yOffset = markerFillProperties.getYOffset(); |
|
115 |
Graphics2D gAux;// = img.createGraphics(); |
|
124 | 116 |
|
125 |
rProv.setRect(0, 0, |
|
126 |
rProv.getWidth() + xSeparation, |
|
127 |
rProv.getHeight() + ySeparation); |
|
117 |
double xSeparation = markerFillProperties.getXSeparation(); |
|
118 |
double ySeparation = markerFillProperties.getYSeparation(); |
|
119 |
double xOffset = markerFillProperties.getXOffset(); |
|
120 |
double yOffset = markerFillProperties.getYOffset(); |
|
128 | 121 |
|
129 |
BufferedImage bi = new BufferedImage(rProv.width, rProv.height, BufferedImage.TYPE_INT_ARGB); |
|
130 |
gAux = bi.createGraphics(); |
|
131 |
AffineTransform tx = AffineTransform.getScaleInstance(xScale, yScale); |
|
132 |
tx.translate(xSeparation*0.5, ySeparation*0.5); |
|
133 |
tx.rotate(angle, rProv.getWidth(), rProv.getHeight()); |
|
134 |
gAux.setTransform(tx); |
|
135 |
bg.drawInsideRectangle(gAux, rProv); |
|
136 |
// gAux.drawImage(img, tx, null); |
|
122 |
rProv.setRect(0, 0, |
|
123 |
rProv.getWidth() + xSeparation, |
|
124 |
rProv.getHeight() + ySeparation); |
|
137 | 125 |
|
138 |
resulPatternFill = new TexturePaint(bi,rProv); |
|
139 |
g.translate(xOffset, yOffset); |
|
140 |
g.setPaint(resulPatternFill); |
|
141 |
g.fill(shp); |
|
142 |
g.translate(-xOffset, -yOffset); |
|
126 |
BufferedImage bi = new BufferedImage(rProv.width, rProv.height, BufferedImage.TYPE_INT_ARGB); |
|
127 |
gAux = bi.createGraphics(); |
|
128 |
AffineTransform tx = AffineTransform.getScaleInstance(xScale, yScale); |
|
129 |
tx.translate(xSeparation*0.5, ySeparation*0.5); |
|
130 |
tx.rotate(angle, rProv.getWidth(), rProv.getHeight()); |
|
131 |
gAux.setTransform(tx); |
|
132 |
bg.drawInsideRectangle(gAux, rProv); |
|
143 | 133 |
|
144 |
// } catch (IOException e) { |
|
145 |
// Logger.getLogger(this.getClass()).error(Messages.getString("failed_to_read_image_file"), e); |
|
146 |
// } |
|
134 |
resulPatternFill = new TexturePaint(bi,rProv); |
|
135 |
g.translate(xOffset, yOffset); |
|
136 |
g.setPaint(resulPatternFill); |
|
137 |
g.fill(shp); |
|
138 |
g.translate(-xOffset, -yOffset); |
|
147 | 139 |
|
140 |
|
|
148 | 141 |
g.setClip(null); |
149 | 142 |
if (getOutline()!=null) { |
150 | 143 |
getOutline().draw(g, affineTransform, shp, cancel); |
151 | 144 |
} |
152 | 145 |
} |
146 |
|
|
153 | 147 |
/** |
154 |
* Gets the path of the picture that is used to fill the polygon |
|
155 |
* @return img,BufferedImage |
|
156 |
* @throws IOException |
|
157 |
*/ |
|
158 |
// private BufferedImage getImg() throws IOException { |
|
159 |
// |
|
160 |
// if (img == null) { |
|
161 |
// if (imagePath == null) |
|
162 |
// throw new IOException("No filename"); |
|
163 |
// |
|
164 |
// img = ImageIO.read(new File(imagePath)); |
|
165 |
// } |
|
166 |
// return img; |
|
167 |
// } |
|
168 |
/** |
|
169 | 148 |
* Defines the file from where the picture to fill the polygon is taken. |
170 | 149 |
* @param imageFile |
171 | 150 |
* @throws IOException |
Also available in: Unified diff