Revision 47476 trunk/org.gvsig.desktop/org.gvsig.desktop.library/org.gvsig.symbology/org.gvsig.symbology.lib/org.gvsig.symbology.lib.impl/src/main/java/org/gvsig/symbology/fmap/mapcontext/rendering/symbol/fill/impl/MarkerFillSymbol.java

View differences:

MarkerFillSymbol.java
24 24

  
25 25
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl;
26 26

  
27
import java.awt.Color;
27
import java.awt.Dimension;
28 28
import java.awt.Graphics2D;
29 29
import java.awt.Paint;
30 30
import java.awt.Rectangle;
......
34 34
import java.awt.geom.AffineTransform;
35 35
import java.awt.image.BufferedImage;
36 36
import java.util.Random;
37

  
38
import org.gvsig.compat.print.PrintAttributes;
39 37
import org.gvsig.fmap.dal.feature.Feature;
40 38
import org.gvsig.fmap.geom.Geometry;
41 39
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
42
import org.gvsig.fmap.geom.Geometry.TYPES;
43 40
import org.gvsig.fmap.geom.GeometryLocator;
44 41
import org.gvsig.fmap.geom.GeometryManager;
45 42
import org.gvsig.fmap.geom.exception.CreateGeometryException;
46
import org.gvsig.fmap.geom.operation.GeometryOperationException;
47
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException;
43
import org.gvsig.fmap.geom.primitive.Envelope;
48 44
import org.gvsig.fmap.geom.primitive.Point;
49 45
import org.gvsig.fmap.mapcontext.MapContext;
50 46
import org.gvsig.fmap.mapcontext.MapContextLocator;
51
import org.gvsig.fmap.mapcontext.ViewPort;
47
import org.gvsig.fmap.mapcontext.rendering.symbols.CartographicSupport;
52 48
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
49
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol_v2;
53 50
import org.gvsig.fmap.mapcontext.rendering.symbols.IWarningSymbol;
54 51
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException;
55 52
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager;
56 53
import org.gvsig.i18n.Messages;
57 54
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol;
58 55
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IMarkerFillSymbol;
59
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl.CartographicSupportToolkit;
60 56
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol;
61
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.PictureMarkerSymbol;
57
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol_v2;
62 58
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.IMarkerFillPropertiesStyle;
63 59
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.SimpleMarkerFillPropertiesStyle;
64 60
import org.gvsig.tools.ToolsLocator;
......
66 62
import org.gvsig.tools.persistence.PersistenceManager;
67 63
import org.gvsig.tools.persistence.PersistentState;
68 64
import org.gvsig.tools.persistence.exception.PersistenceException;
65
import org.gvsig.tools.swing.api.ToolsSwingLocator;
69 66
import org.gvsig.tools.task.Cancellable;
70 67
import org.gvsig.tools.util.Callable;
71 68
import org.slf4j.Logger;
......
75 72
 * Allows to define a marker symbol of any type as a path image to be used for a filled of a
76 73
 * polygon's padding
77 74
 *
78
 * @author   jaume dominguez faus - jaume.dominguez@iver.es
75
 * @author   gvSIG Team
79 76
 */
80 77
public class MarkerFillSymbol extends AbstractFillSymbol implements IMarkerFillSymbol {
81 78
	private static final Logger logger = LoggerFactory.getLogger(MarkerFillSymbol.class);
......
94 91
	private MarkerFillSymbol selectionSymbol;
95 92
	private IMarkerFillPropertiesStyle markerFillProperties = new SimpleMarkerFillPropertiesStyle();
96 93
	private IMarkerSymbol markerSymbol = (IMarkerSymbol) MapContextLocator.getSymbolManager().createSymbol(IMarkerSymbol.SYMBOL_NAME);
97
	private double previousMarkerSize = markerSymbol.getSize();
98
	private PrintAttributes properties;
99
	private GeometryManager geometryManager = GeometryLocator.getGeometryManager();
100 94

  
101
	public ISymbol getSymbolForSelection() {
102
		if (selectionSymbol == null) {
103
			selectionSymbol = (MarkerFillSymbol) cloneForSelection();
104
			selectionSymbol.setFillColor(MapContext.getSelectionColor());
105
		}else {
95
    @Override
96
    public ISymbol getSymbolForSelection() {
97
        if (selectionSymbol == null) {
98
            selectionSymbol = (MarkerFillSymbol) cloneForSelection();
99
            selectionSymbol.setMarker((IMarkerSymbol) selectionSymbol.getMarker().getSymbolForSelection());
100
            selectionSymbol.setFillColor(MapContext.getSelectionColor());
101
        } else {
106 102
            selectionSymbol.setColor(MapContext.getSelectionColor());
107 103
        }
104
        if (selectionSymbol instanceof CartographicSupport) {
105
            ((CartographicSupport) selectionSymbol).setUnit(this.getUnit());
106
        }
107
        if (selectionSymbol.getMarker() instanceof CartographicSupport) {
108
            ((CartographicSupport) selectionSymbol.getMarker()).setUnit(this.getUnit());
109
        }
108 110

  
109
		return selectionSymbol;
110
	}
111
        return selectionSymbol;
112
    }
111 113

  
112
	public void draw(Graphics2D g, AffineTransform affineTransform, Geometry geom, Feature feat, Cancellable cancel) {
113
		Point centroid = null;
114
		Point p = null;
115
			switch (markerFillProperties.getFillStyle()) {
116
			case SINGLE_CENTERED_SYMBOL:
117
				// case a single marker is used into a polygon shapetype
118
				//			Geometry geom = FConverter.java2d_to_jts(geom);
119
				//			com.vividsolutions.jts.geom.Point centroid = geom.getCentroid();
120
				try {
121
					centroid = geom.centroid();
122
				} catch (GeometryOperationNotSupportedException e2) {
123
					logger.warn("Can't get centroid", e2);
124
				} catch (GeometryOperationException e2) {
125
					logger.warn("Can't get centroid", e2);
126
				}
114
    @Override
115
    public void draw(Graphics2D g, AffineTransform affineTransform, Geometry geom, Feature f, Cancellable cancel, Rectangle rect) {
116
        GeometryManager geometryManager = GeometryLocator.getGeometryManager();
117
        Point centroid = null;
118
        Point p;
127 119

  
128
				/*
129
				 * Hay ocasiones en que jts no puede calcular un centroide y devuelve NaN
130
				 * (por ejemplo con geometr?as poligonales cuyos puntos tienen todos la misma
131
				 * abscisa y distinta ordenada con tan solo una diferencia de 1 ? 2 unidades)
132
				 * entonces, en lugar de utilizar este centroide tomamos el centro del
133
				 * bounds del shp (la geometr?a es tan peque?a que consideramos que deben coincidir).
134
				 */
135
				p = null;
136
				if(centroid!=null && !(Double.isNaN(centroid.getX()) || Double.isNaN(centroid.getY()))){
137
					double pX = centroid.getX()+markerFillProperties.getXOffset();
138
					double pY = centroid.getY()+markerFillProperties.getYOffset();
139
					try {
140
						p = geometryManager.createPoint(pX, pY, SUBTYPES.GEOM2D);
141
					} catch (CreateGeometryException e) {
142
						logger.error("Can't create the point ("+pX+","+pY+")", e);
143
					}
144
					if (p != null) {
145
						markerSymbol.draw(g, affineTransform, p, feat, null);
146
					}
147
				} else {
148
					double pX = geom.getShape().getBounds().getCenterX();
149
					double pY = geom.getShape().getBounds().getCenterY();
150
					try {
151
					p = geometryManager.createPoint(pX, pY, SUBTYPES.GEOM2D);
152
					} catch (CreateGeometryException e) {
153
						logger.error("Can't create the point ("+pX+","+pY+")", e);
154
					}
155
					if (p != null) {
156
						markerSymbol.draw(g, affineTransform, p, feat, null);
157
					}
158
				}
159
				break;
160
			case GRID_FILL:
161
				// case a grid fill is used
162
			{
163
				Rectangle rClip = null;
164
				if (g.getClipBounds()!=null){
165
					rClip=(Rectangle)g.getClipBounds().clone();
166
					g.setClip(rClip.x, rClip.y, rClip.width, rClip.height);
167
				}
168
				g.clip(geom.getShape(affineTransform));
120
        if (this.markerSymbol instanceof CartographicSupport) {
121
            this.markerSymbol.setCartographicContext(this.getCartographicContext());
122
        }
169 123

  
170
				int size = (int) markerSymbol.getSize();
171
				Rectangle rProv = new Rectangle();
172
				rProv.setFrame(0, 0, size, size);
173
				Paint resulPatternFill = null;
124
        if (rect != null) {
125
            geom = getSampleGeometry(rect);
126
        }
127
        switch (markerFillProperties.getFillStyle()) {
128
            case SINGLE_CENTERED_SYMBOL:
129
                // case a single marker is used into a polygon shapetype
130
                //			Geometry geom = FConverter.java2d_to_jts(geom);
131
                //			com.vividsolutions.jts.geom.Point centroid = geom.getCentroid();
132
                try {
133
                    centroid = geom.centroid();
134
                } catch (Exception e2) {
135
                    logger.warn("Can't get centroid", e2);
136
                }
174 137

  
175
				double xSeparation = markerFillProperties.getXSeparation(); // TODO apply CartographicSupport
176
				double ySeparation = markerFillProperties.getYSeparation(); // TODO apply CartographicSupport
177
				double xOffset = markerFillProperties.getXOffset();
178
				double yOffset = markerFillProperties.getYOffset();
138
                /*
139
                                             * Hay ocasiones en que jts no puede calcular un centroide y devuelve NaN
140
                                             * (por ejemplo con geometr?as poligonales cuyos puntos tienen todos la misma
141
                                             * abscisa y distinta ordenada con tan solo una diferencia de 1 ? 2 unidades)
142
                                             * entonces, en lugar de utilizar este centroide tomamos el centro del
143
                                             * bounds del shp (la geometr?a es tan peque?a que consideramos que deben coincidir).
144
                 */
145
                p = null;
146
                if (centroid != null && !(Double.isNaN(centroid.getX()) || Double.isNaN(centroid.getY()))) {
147
                    double pX = centroid.getX() + markerFillProperties.getXOffset();
148
                    double pY = centroid.getY() + markerFillProperties.getYOffset();
149
                    try {
150
                        p = geometryManager.createPoint(pX, pY, SUBTYPES.GEOM2D);
151
                    } catch (CreateGeometryException e) {
152
                        logger.error("Can't create the point (" + pX + "," + pY + ")", e);
153
                    }
154
                    if (p != null) {
155
                        if (markerSymbol instanceof IMarkerSymbol_v2) {
156
                            ((IMarkerSymbol_v2) markerSymbol).draw(g, affineTransform, p, f, null, null);
157
                        } else {
158
                            markerSymbol.draw(g, affineTransform, p, f, null);
159
                        }
160
                    }
161
                } else {
162
                    //                Rectangle bounds = geom.getShape().getBounds();
163
                    //                double pX = bounds.getCenterX();
164
                    //                double pY = bounds.getCenterY();
165
                    Envelope env = geom.getEnvelope();
166
                    double pX = env.getCenter(Geometry.DIMENSIONS.X);
167
                    double pY = env.getCenter(Geometry.DIMENSIONS.Y);
168
                    try {
169
                        p = geometryManager.createPoint(pX, pY, SUBTYPES.GEOM2D);
170
                    } catch (CreateGeometryException e) {
171
                        logger.error("Can't create the point (" + pX + "," + pY + ")", e);
172
                    }
173
                    if (p != null) {
174
                        if (markerSymbol instanceof IMarkerSymbol_v2) {
175
                            ((IMarkerSymbol_v2) markerSymbol).draw(g, affineTransform, p, f, null, null);
176
                        } else {
177
                            markerSymbol.draw(g, affineTransform, p, f, null);
178
                        }
179
                    }
180
                }
181
                break;
182
            case GRID_FILL: { // case a grid fill is used
183
                Rectangle rClip = null;
184
                if (g.getClipBounds() != null) {
185
                    rClip = (Rectangle) g.getClipBounds().clone();
186
                    g.setClip(rClip.x, rClip.y, rClip.width, rClip.height);
187
                }
188
                g.clip(geom.getShape(affineTransform));
179 189

  
180
				BufferedImage sample = null;
181
				sample = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
182
				Graphics2D gAux = sample.createGraphics();
190
                int size = (int) this.toCartographicUnits(markerSymbol.getSize());
191
                Dimension maxSize = ToolsSwingLocator.getToolsSwingManager().getMaxPhysicalSizeOfBufferedImage();
192
                if (size > 0 && size <= maxSize.width && size <= maxSize.height) {
193
                    Rectangle rProv = new Rectangle();
194
                    rProv.setFrame(0, 0, size, size);
195
                    Paint resulPatternFill = null;
183 196

  
184
				try {
185
					markerSymbol.drawInsideRectangle(gAux, gAux.getTransform(), rProv, null);
186
				} catch (SymbolDrawingException e) {
187
					if (e.getType() == SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS) {
188
						try {
189
							IWarningSymbol warning =
190
								(IWarningSymbol) MapContextLocator.getSymbolManager()
191
								.getWarningSymbol(
192
										SymbolDrawingException.STR_UNSUPPORTED_SET_OF_SETTINGS,
193
										"",
194
										SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS);
195
							warning.drawInsideRectangle(gAux, gAux.getTransform(), rProv, null);
196
						} catch (SymbolDrawingException e1) {
197
							// IMPOSSIBLE TO REACH THIS
198
						}
199
					} else {
200
						// should be unreachable code
201
						throw new Error(Messages.getText("symbol_shapetype_mismatch"));
202
					}
203
				}
204
				rProv.setRect(0, 0,
205
						rProv.getWidth() + xSeparation,
206
						rProv.getHeight() + ySeparation);
197
                    double xSeparation = this.toCartographicUnits(markerFillProperties.getXSeparation()); // TODO apply CartographicSupport
198
                    double ySeparation = this.toCartographicUnits(markerFillProperties.getYSeparation()); // TODO apply CartographicSupport
199
                    double xOffset = this.toCartographicUnits(markerFillProperties.getXOffset());
200
                    double yOffset = this.toCartographicUnits(markerFillProperties.getYOffset());
207 201

  
208
				BufferedImage bi = new BufferedImage(rProv.width, rProv.height, BufferedImage.TYPE_INT_ARGB);
209
				gAux = bi.createGraphics();
210
				gAux.drawImage(sample, null, (int) (xSeparation*0.5), (int) (ySeparation*0.5));
202
                    BufferedImage sample = null;
203
                    //                                    sample = ToolsSwingLocator.getToolsSwingManager().createBufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
204
                    Graphics2D gAux = null;
205
                    if (size > 0) {
206
                        sample = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
207
                        gAux = sample.createGraphics();
211 208

  
212
				resulPatternFill = new TexturePaint(bi,rProv);
213
				sample = null;
214
				gAux.dispose();
209
                        try {
210
                            markerSymbol.drawInsideRectangle(gAux, gAux.getTransform(), rProv);
211
                        } catch (SymbolDrawingException e) {
212
                            if (e.getType() == SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS) {
213
                                try {
214
                                    IWarningSymbol warning
215
                                            = (IWarningSymbol) MapContextLocator.getSymbolManager()
216
                                                    .getWarningSymbol(
217
                                                            SymbolDrawingException.STR_UNSUPPORTED_SET_OF_SETTINGS,
218
                                                            "",
219
                                                            SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS);
220
                                    warning.drawInsideRectangle(gAux, gAux.getTransform(), rProv);
221
                                } catch (SymbolDrawingException e1) {
222
                                    // IMPOSSIBLE TO REACH THIS
223
                                }
224
                            } else {
225
                                // should be unreachable code
226
                                throw new Error(Messages.getText("symbol_shapetype_mismatch"));
227
                            }
228
                        }
229
                        rProv.setRect(xOffset, yOffset,
230
                                rProv.getWidth() + xSeparation,
231
                                rProv.getHeight() + ySeparation);
215 232

  
216
				g.setColor(null);
217
				g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
218
						RenderingHints.VALUE_ANTIALIAS_ON);
233
                        BufferedImage bi = new BufferedImage(rProv.width, rProv.height, BufferedImage.TYPE_INT_ARGB);
234
                        gAux = bi.createGraphics();
235
                        gAux.drawImage(sample, null, 0 , 0 ); //(int) (xSeparation * 0.5), (int) (ySeparation * 0.5));
219 236

  
220
				g.translate(xOffset, -yOffset);
221
				g.setPaint(resulPatternFill);
222
				g.fill(geom.getShape(affineTransform));
223
				g.translate(-xOffset, +yOffset);
224
				g.setClip(rClip);
225
				bi = null;
226
			}
227
			break;
228
			case RANDOM_FILL:
229
			{
237
                        resulPatternFill = new TexturePaint(bi, rProv);
238
                        sample = null;
239
                        if (gAux != null) {
240
                            gAux.dispose();
241
                        }
230 242

  
231
				double s = markerSymbol.getSize();
232
				Geometry auxgeo = geom.cloneGeometry();
233
				auxgeo.transform(affineTransform);
234
				Shape shp = auxgeo.getShape();
235
				Rectangle r = shp.getBounds();
236
				int drawCount = (int) (Math.min(r.getWidth(), r.getHeight())/s);
237
				Random random = new Random();
243
                        g.setColor(null);
244
                        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
245
                                RenderingHints.VALUE_ANTIALIAS_ON);
238 246

  
239
				int minx = r.x;
240
				int miny = r.y;
241
				int width = r.width;
242
				int height = r.height;
247
                        g.setPaint(resulPatternFill);
248
                        g.fill(geom.getShape(affineTransform));
249
                        g.setClip(rClip);
250
                        bi = null;
251
                    }
252
                    break;
253
                }
254
            }
255
            case RANDOM_FILL: {
243 256

  
244
				r = new Rectangle();
245
				g.setClip(shp);
257
                double s = markerSymbol.getSize();
258
                Shape shp = geom.getShape(affineTransform);
259
                Rectangle r = shp.getBounds();
260
                int drawCount = (int) (Math.min(r.getWidth(), r.getHeight()) / s);
261
                Random random = new Random();
246 262

  
247
				for (int i = 0; (cancel==null || !cancel.isCanceled()) && i < drawCount; i++) {
248
					int x = (int) Math.abs(random.nextDouble() * width);
249
					int y = (int) Math.abs(random.nextDouble() * height);
250
					x = x + minx;
251
					y = y + miny;
252
					//				markerSymbol.draw(g, new AffineTransform(), new FPoint2D(x, y), cancel);
253
					p = null;
254
					try {
255
						p = geometryManager.createPoint(x, y, SUBTYPES.GEOM2D);
256
					} catch (CreateGeometryException e) {
257
						logger.error("Can't create the point ("+x+","+y+")", e);
258
					}
259
					if (p!=null){
260
						markerSymbol.draw(g, new AffineTransform(), p, feat, cancel);
261
					}
262
				}
263
				g.setClip(null);
264
			}
265
			break;
266
			}
267
			if(getOutline()!= null){
268
				getOutline().draw(g, affineTransform, geom, feat, cancel);
269
			}
270
	}
263
                int minx = r.x;
264
                int miny = r.y;
265
                int width = r.width;
266
                int height = r.height;
271 267

  
268
                r = new Rectangle();
269
                g.setClip(shp);
270

  
271
                for (int i = 0; (cancel == null || !cancel.isCanceled()) && i < drawCount; i++) {
272
                    int x = (int) Math.abs(random.nextDouble() * width);
273
                    int y = (int) Math.abs(random.nextDouble() * height);
274
                    x = x + minx;
275
                    y = y + miny;
276
                    //				markerSymbol.draw(g, new AffineTransform(), new FPoint2D(x, y), cancel);
277
                    p = null;
278
                    try {
279
                        p = geometryManager.createPoint(x, y, SUBTYPES.GEOM2D);
280
                    } catch (CreateGeometryException e) {
281
                        logger.error("Can't create the point (" + x + "," + y + ")", e);
282
                    }
283
                    if (p != null) {
284
                        if (markerSymbol instanceof IMarkerSymbol_v2) {
285
                            ((IMarkerSymbol_v2) markerSymbol).draw(g, new AffineTransform(), p, f, cancel, null);
286
                        } else {
287
                            markerSymbol.draw(g, new AffineTransform(), p, f, cancel);
288
                        }
289
                    }
290
                }
291
                g.setClip(null);
292
                break;
293
            }
294
        }
295
        if (getOutline() != null) {
296
            getOutline().setCartographicContext(this.getCartographicContext());
297
            if (getOutline() instanceof ISymbol_v2) {
298
                ((ISymbol_v2) getOutline()).draw(g, affineTransform, geom, f, cancel, null);
299
            } else {
300
                getOutline().draw(g, affineTransform, geom, f, cancel);
301
            }
302
        }
303
    }
304

  
305
        @Override
272 306
	public int getSymbolType() {
273 307
		return Geometry.TYPES.SURFACE;
274 308
	}
275 309

  
276
	public void drawInsideRectangle(Graphics2D g, AffineTransform scaleInstance, Rectangle r, PrintAttributes properties) throws SymbolDrawingException {
277
		markerFillProperties.setSampleSymbol(markerSymbol);
278
		Point p;
279
		try {
280
			switch (markerFillProperties.getFillStyle()) {
281
			case SINGLE_CENTERED_SYMBOL:
282
				p = geometryManager.createPoint(r.getCenterX(), r.getCenterY(), SUBTYPES.GEOM2D);
283
				markerSymbol.draw(g, null, p, null, null);
284
				break;
285
			case GRID_FILL:
286
			{
287
				g.setClip(r);
288
				int size = (int) markerSymbol.getSize();
289
				if (size <= 0 ) size = 1;
290
				Rectangle rProv = new Rectangle();
291
				rProv.setFrame(0, 0, size, size);
292
				Paint resulPatternFill = null;
293

  
294
				BufferedImage sample = null;
295
				sample = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB);
296
				Graphics2D gAux = sample.createGraphics();
297

  
298
				double xSeparation = markerFillProperties.getXSeparation(); // TODO apply CartographicSupport
299
				double ySeparation = markerFillProperties.getYSeparation(); // TODO apply CartographicSupport
300
				double xOffset = markerFillProperties.getXOffset();
301
				double yOffset = markerFillProperties.getYOffset();
302

  
303
				markerSymbol.drawInsideRectangle(gAux, new AffineTransform(), rProv, properties);
304

  
305
				rProv.setRect(0, 0,
306
						rProv.getWidth() + xSeparation,
307
						rProv.getHeight() + ySeparation);
308

  
309
				BufferedImage bi = new BufferedImage(rProv.width, rProv.height, BufferedImage.TYPE_INT_ARGB);
310
				gAux = bi.createGraphics();
311
				gAux.drawImage(sample, null, (int) (xSeparation*0.5), (int) (ySeparation*0.5));
312

  
313

  
314
				resulPatternFill = new TexturePaint(bi,rProv);
315
				g.setColor(null);
316
				g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
317
						RenderingHints.VALUE_ANTIALIAS_ON);
318

  
319
				g.translate(xOffset, -yOffset);
320
				g.setPaint(resulPatternFill);
321
				g.fill(r);
322
				g.translate(-xOffset, yOffset);
323
				g.setClip(null);
324
			}
325
			break;
326
			case RANDOM_FILL:
327
				g.setClip(r);
328
				int x = r.x;
329
				int y = r.y;
330
				int width = r.width;
331
				int height= r.height;
332
				g.setBackground(null);
333

  
334
				markerSymbol.draw(g, null, geometryManager.createPoint((x+width*0.2), (y+height*0.8), SUBTYPES.GEOM2D), null, null);
335
				markerSymbol.draw(g, null, geometryManager.createPoint((x+width*0.634), (y+height*0.3), SUBTYPES.GEOM2D), null, null);
336
				markerSymbol.draw(g, null, geometryManager.createPoint((x+width*0.26), (y+height*0.35), SUBTYPES.GEOM2D), null, null);
337
				markerSymbol.draw(g, null, geometryManager.createPoint((x+width*0.45), (y+height*0.98), SUBTYPES.GEOM2D), null, null);
338
				markerSymbol.draw(g, null, geometryManager.createPoint((x+width*0.9), (y+height*0.54), SUBTYPES.GEOM2D), null, null);
339
				markerSymbol.draw(g, null, geometryManager.createPoint((x+width*1.1), (y+height*0.7), SUBTYPES.GEOM2D), null, null);
340
				g.setClip(null);
341
				break;
342
			}
343
			if(getOutline()!= null && hasOutline()){
344
				if (properties==null) {
345
					//				getOutline().draw(g, scaleInstance, new FPolyline2D(new GeneralPathX(r)), null);
346
					getOutline().draw(g, scaleInstance, geometryManager.createPoint(r.getCenterX(), r.getCenterY(), SUBTYPES.GEOM2D), null,  null);
347
				} else {
348
					//				getOutline().print(g, scaleInstance, new FPolyline2D(new GeneralPathX(r)), properties);
349
					getOutline().print(g, scaleInstance, geometryManager.createPoint(r.getCenterX(), r.getCenterY(), SUBTYPES.GEOM2D), properties);
350
				}
351
			}
352
		} catch (CreateGeometryException e) {
353
			throw new SymbolDrawingException(TYPES.POINT);
354
		}
355
	}
356

  
357

  
358 310
	public String getClassName() {
359 311
		return getClass().getName();
360 312
	}
361 313

  
314
        @Override
362 315
	public void setMarker(IMarkerSymbol marker) {
363 316
		this.markerSymbol = marker;
364 317
	}
365 318

  
319
        @Override
366 320
	public IMarkerSymbol getMarker() {
367 321
		return markerSymbol;
368 322
	}
369 323

  
370
	public Color getFillColor(){
371
		return markerSymbol.getColor();
372
	}
373

  
374
	public void setFillColor (Color color) {
375
		markerSymbol.setColor(color);
376
	}
377

  
378
	public void print(Graphics2D g, AffineTransform at, Geometry geom, PrintAttributes properties) {
379
		this.properties=properties;
380
        draw(g, at, geom, null, null);
381
        this.properties=null;
382

  
383
	}
384 324
	/**
385 325
	 * Sets the markerfillproperties to be used by the class
386 326
	 *
387 327
	 * @param markerFillStyle,IMarkerFillPropertiesStyle
388 328
	 */
329
        @Override
389 330
	public void setMarkerFillProperties(IMarkerFillPropertiesStyle markerFillStyle) {
390 331
		this.markerFillProperties = markerFillStyle;
391 332
	}
......
395 336
	 *
396 337
	 * @return markerFillProperties,IMarkerFillPropertiesStyle
397 338
	 */
339
        @Override
398 340
	public IMarkerFillPropertiesStyle getMarkerFillProperties() {
399 341
		return markerFillProperties;
400 342
	}
......
415 357
		}
416 358
	}
417 359

  
418
	public void setCartographicSize(double cartographicSize, Geometry geom) {
360
    @Override
361
    public void setCartographicContext(CartographicContext ctx) {
362
        super.setCartographicContext(ctx);
363
        IMarkerSymbol marker = getMarker();
364
        if (marker != null) {
365
            marker.setCartographicContext(ctx);
366
        }
367
        
368
    }
419 369

  
420
		super.setCartographicSize(cartographicSize, geom);
421
		IMarkerSymbol marker = getMarker();
422
		if (marker!=null) {
423
				marker.setCartographicSize(previousMarkerSize, geom);
424
			}
425

  
426
		super.setCartographicSize(cartographicSize, geom);
427

  
428
	}
429

  
430
	public double toCartographicSize(ViewPort viewPort, double dpi, Geometry geom) {
431
		IMarkerSymbol marker = getMarker();
432
		if (marker!=null) {
433
			previousMarkerSize = marker.getSize();
434
			double size = CartographicSupportToolkit.getCartographicLength(this, previousMarkerSize, viewPort, dpi);
435
			marker.setSize(size);
436
		}
437
		double s = super.toCartographicSize(viewPort, dpi, geom);
438
		return s;
439

  
440
	}
441

  
442

  
370
    @Override
443 371
    public Object clone() throws CloneNotSupportedException {
444 372
    	MarkerFillSymbol copy = (MarkerFillSymbol) super.clone();
445 373

  
......
463 391
        return copy;
464 392
    }
465 393

  
394
    @Override
466 395
    public void loadFromState(PersistentState state) throws PersistenceException {
467 396
        // Set parent style properties
468 397
        super.loadFromState(state);
......
470 399
        this.markerSymbol =  (IMarkerSymbol) state.get(MARKER_SYMBOL);
471 400
        this.selectionSymbol = (MarkerFillSymbol) state.get(SELECTION_SYMBOL);
472 401
        this.markerFillProperties = (IMarkerFillPropertiesStyle) state.get(MARKER_FILL_PROPERTIES);
473
        this.previousMarkerSize = (Double) state.get(PREVIOUS_MARKERSIZE);
474 402
    }
475 403

  
404
        @Override
476 405
    public void saveToState(PersistentState state) throws PersistenceException {
477 406
        // Save parent fill symbol properties
478 407
        super.saveToState(state);
......
481 410
        state.set(MARKER_SYMBOL, this.markerSymbol);
482 411
        state.set(SELECTION_SYMBOL, this.selectionSymbol);
483 412
        state.set(MARKER_FILL_PROPERTIES, this.markerFillProperties);
484
        state.set(PREVIOUS_MARKERSIZE, this.previousMarkerSize);
485 413
    }
486 414

  
487 415
    public static class RegisterPersistence implements Callable {
488 416

  
417
        @Override
489 418
        public Object call() throws Exception {
490 419
            PersistenceManager manager = ToolsLocator.getPersistenceManager();
491 420
            if (manager.getDefinition(MARK_FILL_SYMBOL_PERSISTENCE_DEFINITION_NAME) == null) {
......
514 443

  
515 444
	public static class RegisterSymbol implements Callable {
516 445

  
446
                @Override
517 447
		public Object call() throws Exception {
518 448
	        int[] shapeTypes;
519 449
	        SymbolManager manager = MapContextLocator.getSymbolManager();
......
530 460

  
531 461
	}
532 462

  
533

  
534 463
}

Also available in: Unified diff