svn-gvsig-desktop / 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 @ 43491
History | View | Annotate | Download (19.4 KB)
1 | 40560 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40560 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | 40560 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * of the License, or (at your option) any later version.
|
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | 40560 | jjdelcerro | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | * MA 02110-1301, USA.
|
||
20 | 40435 | jjdelcerro | *
|
21 | 40560 | jjdelcerro | * For any additional information, do not hesitate to contact us
|
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40435 | jjdelcerro | */
|
24 | 43491 | jjdelcerro | |
25 | 40435 | jjdelcerro | package org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.impl; |
26 | |||
27 | import java.awt.Color; |
||
28 | import java.awt.Graphics2D; |
||
29 | import java.awt.Paint; |
||
30 | import java.awt.Rectangle; |
||
31 | import java.awt.RenderingHints; |
||
32 | 40985 | jldominguez | import java.awt.Shape; |
33 | 40435 | jjdelcerro | import java.awt.TexturePaint; |
34 | import java.awt.geom.AffineTransform; |
||
35 | import java.awt.image.BufferedImage; |
||
36 | import java.util.Random; |
||
37 | |||
38 | import org.gvsig.compat.print.PrintAttributes; |
||
39 | import org.gvsig.fmap.dal.feature.Feature; |
||
40 | import org.gvsig.fmap.geom.Geometry; |
||
41 | import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
||
42 | import org.gvsig.fmap.geom.Geometry.TYPES; |
||
43 | import org.gvsig.fmap.geom.GeometryLocator; |
||
44 | import org.gvsig.fmap.geom.GeometryManager; |
||
45 | import org.gvsig.fmap.geom.exception.CreateGeometryException; |
||
46 | import org.gvsig.fmap.geom.operation.GeometryOperationException; |
||
47 | import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
||
48 | import org.gvsig.fmap.geom.primitive.Point; |
||
49 | import org.gvsig.fmap.mapcontext.MapContext; |
||
50 | import org.gvsig.fmap.mapcontext.MapContextLocator; |
||
51 | import org.gvsig.fmap.mapcontext.ViewPort; |
||
52 | import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
||
53 | import org.gvsig.fmap.mapcontext.rendering.symbols.IWarningSymbol; |
||
54 | import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException; |
||
55 | import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolManager; |
||
56 | import org.gvsig.i18n.Messages; |
||
57 | import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol; |
||
58 | import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IMarkerFillSymbol; |
||
59 | import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.impl.CartographicSupportToolkit; |
||
60 | import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.IMarkerSymbol; |
||
61 | import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.marker.impl.PictureMarkerSymbol; |
||
62 | import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.IMarkerFillPropertiesStyle; |
||
63 | import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style.SimpleMarkerFillPropertiesStyle; |
||
64 | import org.gvsig.tools.ToolsLocator; |
||
65 | import org.gvsig.tools.dynobject.DynStruct; |
||
66 | import org.gvsig.tools.persistence.PersistenceManager; |
||
67 | import org.gvsig.tools.persistence.PersistentState; |
||
68 | import org.gvsig.tools.persistence.exception.PersistenceException; |
||
69 | import org.gvsig.tools.task.Cancellable; |
||
70 | import org.gvsig.tools.util.Callable; |
||
71 | import org.slf4j.Logger; |
||
72 | import org.slf4j.LoggerFactory; |
||
73 | |||
74 | /**
|
||
75 | * Allows to define a marker symbol of any type as a path image to be used for a filled of a
|
||
76 | * polygon's padding
|
||
77 | *
|
||
78 | * @author jaume dominguez faus - jaume.dominguez@iver.es
|
||
79 | */
|
||
80 | public class MarkerFillSymbol extends AbstractFillSymbol implements IMarkerFillSymbol { |
||
81 | private static final Logger logger = LoggerFactory.getLogger(MarkerFillSymbol.class); |
||
82 | 42439 | dmartinezizquierdo | |
83 | 40435 | jjdelcerro | public static final String MARK_FILL_SYMBOL_PERSISTENCE_DEFINITION_NAME = |
84 | "MarkerFillSymbol";
|
||
85 | private static final String MARKER_SYMBOL = "markerSymbol"; |
||
86 | private static final String SELECTION_SYMBOL = "selectionSymbol"; |
||
87 | private static final String MARKER_FILL_PROPERTIES = "markerFillProperties"; |
||
88 | private static final String PREVIOUS_MARKERSIZE = "previousMarkerSize"; |
||
89 | |||
90 | public static final int RANDOM_FILL = 3; |
||
91 | public static final int GRID_FILL = 1; |
||
92 | public static final int SINGLE_CENTERED_SYMBOL = 2; |
||
93 | public static int DefaultFillStyle = GRID_FILL; |
||
94 | private MarkerFillSymbol selectionSymbol;
|
||
95 | private IMarkerFillPropertiesStyle markerFillProperties = new SimpleMarkerFillPropertiesStyle(); |
||
96 | 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 | |||
101 | public ISymbol getSymbolForSelection() {
|
||
102 | if (selectionSymbol == null) { |
||
103 | selectionSymbol = (MarkerFillSymbol) cloneForSelection(); |
||
104 | selectionSymbol.setFillColor(MapContext.getSelectionColor()); |
||
105 | 42439 | dmartinezizquierdo | }else {
|
106 | selectionSymbol.setColor(MapContext.getSelectionColor()); |
||
107 | } |
||
108 | 40435 | jjdelcerro | |
109 | return selectionSymbol;
|
||
110 | } |
||
111 | |||
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 | } |
||
127 | |||
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 | 40985 | jldominguez | g.clip(geom.getShape(affineTransform)); |
169 | 40435 | jjdelcerro | |
170 | int size = (int) markerSymbol.getSize(); |
||
171 | Rectangle rProv = new Rectangle(); |
||
172 | rProv.setFrame(0, 0, size, size); |
||
173 | Paint resulPatternFill = null; |
||
174 | |||
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();
|
||
179 | |||
180 | BufferedImage sample = null; |
||
181 | sample = new BufferedImage(size, size, BufferedImage.TYPE_INT_ARGB); |
||
182 | Graphics2D gAux = sample.createGraphics();
|
||
183 | |||
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); |
||
207 | |||
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)); |
||
211 | |||
212 | resulPatternFill = new TexturePaint(bi,rProv); |
||
213 | sample = null;
|
||
214 | gAux.dispose(); |
||
215 | |||
216 | g.setColor(null);
|
||
217 | g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||
218 | RenderingHints.VALUE_ANTIALIAS_ON);
|
||
219 | |||
220 | g.translate(xOffset, -yOffset); |
||
221 | g.setPaint(resulPatternFill); |
||
222 | 40985 | jldominguez | g.fill(geom.getShape(affineTransform)); |
223 | 40435 | jjdelcerro | g.translate(-xOffset, +yOffset); |
224 | g.setClip(rClip); |
||
225 | bi = null;
|
||
226 | } |
||
227 | break;
|
||
228 | case RANDOM_FILL:
|
||
229 | { |
||
230 | |||
231 | double s = markerSymbol.getSize();
|
||
232 | 40985 | jldominguez | Geometry auxgeo = geom.cloneGeometry(); |
233 | auxgeo.transform(affineTransform); |
||
234 | Shape shp = auxgeo.getShape();
|
||
235 | Rectangle r = shp.getBounds();
|
||
236 | 40435 | jjdelcerro | int drawCount = (int) (Math.min(r.getWidth(), r.getHeight())/s); |
237 | Random random = new Random(); |
||
238 | |||
239 | int minx = r.x;
|
||
240 | int miny = r.y;
|
||
241 | int width = r.width;
|
||
242 | int height = r.height;
|
||
243 | |||
244 | r = new Rectangle(); |
||
245 | 40985 | jldominguez | g.setClip(shp); |
246 | 40435 | jjdelcerro | |
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 | } |
||
271 | |||
272 | public int getSymbolType() { |
||
273 | return Geometry.TYPES.SURFACE;
|
||
274 | } |
||
275 | |||
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 | public String getClassName() { |
||
359 | return getClass().getName();
|
||
360 | } |
||
361 | |||
362 | public void setMarker(IMarkerSymbol marker) { |
||
363 | this.markerSymbol = marker;
|
||
364 | } |
||
365 | |||
366 | public IMarkerSymbol getMarker() {
|
||
367 | return markerSymbol;
|
||
368 | } |
||
369 | |||
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 | /**
|
||
385 | * Sets the markerfillproperties to be used by the class
|
||
386 | *
|
||
387 | * @param markerFillStyle,IMarkerFillPropertiesStyle
|
||
388 | */
|
||
389 | public void setMarkerFillProperties(IMarkerFillPropertiesStyle markerFillStyle) { |
||
390 | this.markerFillProperties = markerFillStyle;
|
||
391 | } |
||
392 | |||
393 | /**
|
||
394 | * Returns the markerfillproperties that are used by the class
|
||
395 | *
|
||
396 | * @return markerFillProperties,IMarkerFillPropertiesStyle
|
||
397 | */
|
||
398 | public IMarkerFillPropertiesStyle getMarkerFillProperties() {
|
||
399 | return markerFillProperties;
|
||
400 | } |
||
401 | |||
402 | @Override
|
||
403 | public void setUnit(int unitIndex) { |
||
404 | super.setUnit(unitIndex);
|
||
405 | if (getMarker()!=null) { |
||
406 | getMarker().setUnit(unitIndex); |
||
407 | } |
||
408 | } |
||
409 | |||
410 | @Override
|
||
411 | public void setReferenceSystem(int system) { |
||
412 | super.setReferenceSystem(system);
|
||
413 | if (getMarker()!=null) { |
||
414 | getMarker().setReferenceSystem(system); |
||
415 | } |
||
416 | } |
||
417 | |||
418 | public void setCartographicSize(double cartographicSize, Geometry geom) { |
||
419 | 42439 | dmartinezizquierdo | |
420 | 40435 | jjdelcerro | super.setCartographicSize(cartographicSize, geom);
|
421 | IMarkerSymbol marker = getMarker(); |
||
422 | if (marker!=null) { |
||
423 | marker.setCartographicSize(previousMarkerSize, geom); |
||
424 | } |
||
425 | 42439 | dmartinezizquierdo | |
426 | 40435 | jjdelcerro | 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 | 42439 | dmartinezizquierdo | |
440 | 40435 | jjdelcerro | } |
441 | 42439 | dmartinezizquierdo | |
442 | |||
443 | 40435 | jjdelcerro | public Object clone() throws CloneNotSupportedException { |
444 | MarkerFillSymbol copy = (MarkerFillSymbol) super.clone();
|
||
445 | |||
446 | // clone marker
|
||
447 | if (markerSymbol != null) { |
||
448 | copy.markerSymbol = (IMarkerSymbol) markerSymbol.clone(); |
||
449 | } |
||
450 | |||
451 | // clone selection
|
||
452 | if (selectionSymbol != null) { |
||
453 | copy.selectionSymbol = (MarkerFillSymbol) selectionSymbol.clone(); |
||
454 | } |
||
455 | |||
456 | // clone markerFillProperties
|
||
457 | if (markerFillProperties != null) { |
||
458 | copy.markerFillProperties = (IMarkerFillPropertiesStyle) markerFillProperties.clone(); |
||
459 | } |
||
460 | |||
461 | // FIXME: clone properties
|
||
462 | 42439 | dmartinezizquierdo | |
463 | 40435 | jjdelcerro | return copy;
|
464 | } |
||
465 | |||
466 | public void loadFromState(PersistentState state) throws PersistenceException { |
||
467 | // Set parent style properties
|
||
468 | super.loadFromState(state);
|
||
469 | |||
470 | this.markerSymbol = (IMarkerSymbol) state.get(MARKER_SYMBOL);
|
||
471 | this.selectionSymbol = (MarkerFillSymbol) state.get(SELECTION_SYMBOL);
|
||
472 | this.markerFillProperties = (IMarkerFillPropertiesStyle) state.get(MARKER_FILL_PROPERTIES);
|
||
473 | this.previousMarkerSize = (Double) state.get(PREVIOUS_MARKERSIZE); |
||
474 | } |
||
475 | |||
476 | public void saveToState(PersistentState state) throws PersistenceException { |
||
477 | // Save parent fill symbol properties
|
||
478 | super.saveToState(state);
|
||
479 | |||
480 | // Save own properties
|
||
481 | state.set(MARKER_SYMBOL, this.markerSymbol);
|
||
482 | state.set(SELECTION_SYMBOL, this.selectionSymbol);
|
||
483 | state.set(MARKER_FILL_PROPERTIES, this.markerFillProperties);
|
||
484 | state.set(PREVIOUS_MARKERSIZE, this.previousMarkerSize);
|
||
485 | } |
||
486 | |||
487 | public static class RegisterPersistence implements Callable { |
||
488 | |||
489 | public Object call() throws Exception { |
||
490 | PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
||
491 | if (manager.getDefinition(MARK_FILL_SYMBOL_PERSISTENCE_DEFINITION_NAME) == null) { |
||
492 | DynStruct definition = |
||
493 | manager.addDefinition(MarkerFillSymbol.class, |
||
494 | MARK_FILL_SYMBOL_PERSISTENCE_DEFINITION_NAME, |
||
495 | MARK_FILL_SYMBOL_PERSISTENCE_DEFINITION_NAME |
||
496 | + " Persistence definition",
|
||
497 | null,
|
||
498 | null);
|
||
499 | |||
500 | // Extend the Style base definition
|
||
501 | definition.extend(manager.getDefinition(FILL_SYMBOL_PERSISTENCE_DEFINITION_NAME)); |
||
502 | |||
503 | definition.addDynFieldObject(MARKER_SYMBOL) |
||
504 | .setClassOfValue(IMarkerSymbol.class).setMandatory(true);
|
||
505 | definition.addDynFieldObject(SELECTION_SYMBOL) |
||
506 | .setClassOfValue(IMarkerFillSymbol.class).setMandatory(false);
|
||
507 | definition.addDynFieldObject(MARKER_FILL_PROPERTIES) |
||
508 | .setClassOfValue(IMarkerFillPropertiesStyle.class).setMandatory(true);
|
||
509 | definition.addDynFieldDouble(PREVIOUS_MARKERSIZE); |
||
510 | } |
||
511 | return Boolean.TRUE; |
||
512 | } |
||
513 | } |
||
514 | |||
515 | public static class RegisterSymbol implements Callable { |
||
516 | |||
517 | public Object call() throws Exception { |
||
518 | int[] shapeTypes; |
||
519 | SymbolManager manager = MapContextLocator.getSymbolManager(); |
||
520 | 42439 | dmartinezizquierdo | |
521 | 40435 | jjdelcerro | shapeTypes = |
522 | new int[] { Geometry.TYPES.SURFACE, Geometry.TYPES.CIRCLE, |
||
523 | Geometry.TYPES.ELLIPSE, Geometry.TYPES.MULTISURFACE }; |
||
524 | manager.registerMultiLayerSymbol(IFillSymbol.SYMBOL_NAME, |
||
525 | shapeTypes, |
||
526 | MarkerFillSymbol.class); |
||
527 | 42439 | dmartinezizquierdo | |
528 | 40435 | jjdelcerro | return Boolean.TRUE; |
529 | } |
||
530 | 42439 | dmartinezizquierdo | |
531 | 40435 | jjdelcerro | } |
532 | |||
533 | |||
534 | } |