root / branches / v2_0_0_prep / extensions / org.gvsig.symbology / src / main / java / org / gvsig / symbology / fmap / mapcontext / rendering / symbol / style / DefaultMask.java @ 32880
History | View | Annotate | Download (4.84 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
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 |
* as published by the Free Software Foundation; either version 2
|
9 |
* 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 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.symbology.fmap.mapcontext.rendering.symbol.style; |
23 |
|
24 |
import java.awt.BasicStroke; |
25 |
import java.awt.Graphics2D; |
26 |
import java.awt.Rectangle; |
27 |
import java.awt.Shape; |
28 |
|
29 |
import org.gvsig.fmap.geom.Geometry; |
30 |
import org.gvsig.fmap.geom.GeometryLocator; |
31 |
import org.gvsig.fmap.geom.GeometryManager; |
32 |
import org.gvsig.fmap.geom.Geometry.SUBTYPES; |
33 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
34 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
35 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
36 |
import org.gvsig.symbology.fmap.mapcontext.rendering.symbol.fill.IFillSymbol; |
37 |
import org.gvsig.tools.ToolsLocator; |
38 |
import org.gvsig.tools.dynobject.DynStruct; |
39 |
import org.gvsig.tools.persistence.PersistenceManager; |
40 |
import org.gvsig.tools.persistence.PersistentState; |
41 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
42 |
import org.slf4j.Logger; |
43 |
import org.slf4j.LoggerFactory; |
44 |
|
45 |
/**
|
46 |
* @author 2005-2008 jaume dominguez faus - jaume.dominguez@iver.es
|
47 |
* @author 2009- <a href="cordinyana@gvsig.org">C?sar Ordi?ana</a> - gvSIG team
|
48 |
*/
|
49 |
public class DefaultMask extends AbstractStyle implements IMask { |
50 |
|
51 |
public static final String DEFAULT_MASK_DYNCLASS_NAME = "DefaultMask"; |
52 |
|
53 |
private static final String FIELD_SIZE = "size"; |
54 |
private static final String FIELD_FILL_SYMBOL = "fillSymbol"; |
55 |
|
56 |
private static final GeometryManager geomManager = GeometryLocator |
57 |
.getGeometryManager(); |
58 |
private static final Logger logger = LoggerFactory |
59 |
.getLogger(DefaultMask.class); |
60 |
private double size; |
61 |
private IFillSymbol fill;
|
62 |
|
63 |
public double getSize() { |
64 |
return size;
|
65 |
} |
66 |
|
67 |
public void setSize(double size) { |
68 |
this.size = size;
|
69 |
} |
70 |
|
71 |
public IFillSymbol getFillSymbol() {
|
72 |
return fill;
|
73 |
|
74 |
} |
75 |
|
76 |
public void setFillSymbol(IFillSymbol fill) { |
77 |
this.fill = fill;
|
78 |
} |
79 |
|
80 |
public void drawInsideRectangle(Graphics2D g, Rectangle r) { |
81 |
// TODO Implement it
|
82 |
throw new Error("Not yet implemented!"); |
83 |
|
84 |
} |
85 |
|
86 |
public Geometry getHaloShape(Shape shp) { |
87 |
BasicStroke stroke = new BasicStroke( |
88 |
(int) /* falta CartographicSupport */getSize()); |
89 |
Shape myShp = stroke.createStrokedShape(shp);
|
90 |
Geometry haloShape = null;
|
91 |
; |
92 |
try {
|
93 |
haloShape = geomManager.createSurface(new GeneralPathX(myShp
|
94 |
.getBounds2D().getPathIterator(null)), SUBTYPES.GEOM2D);
|
95 |
} catch (CreateGeometryException e) {
|
96 |
logger.error("Error creating a surface", e);
|
97 |
} |
98 |
|
99 |
return haloShape;
|
100 |
} |
101 |
|
102 |
public boolean isSuitableFor(ISymbol symbol) { |
103 |
// TODO Implement it
|
104 |
throw new Error("Not yet implemented!"); |
105 |
|
106 |
} |
107 |
|
108 |
public void drawOutline(Graphics2D g, Rectangle r) { |
109 |
// TODO Implement it
|
110 |
throw new Error("Not yet implemented!"); |
111 |
|
112 |
} |
113 |
|
114 |
public String getClassName() { |
115 |
return this.getClass().getName(); |
116 |
} |
117 |
|
118 |
public Object clone() throws CloneNotSupportedException { |
119 |
DefaultMask copy = (DefaultMask) super.clone();
|
120 |
if (fill != null) { |
121 |
copy.fill = (IFillSymbol) fill.clone(); |
122 |
} |
123 |
return copy;
|
124 |
} |
125 |
|
126 |
public void loadFromState(PersistentState state) |
127 |
throws PersistenceException {
|
128 |
// Set parent style properties
|
129 |
super.loadFromState(state);
|
130 |
|
131 |
// Set own properties
|
132 |
setFillSymbol((IFillSymbol) state.get(FIELD_FILL_SYMBOL)); |
133 |
setSize(state.getDouble(FIELD_SIZE)); |
134 |
} |
135 |
|
136 |
public void saveToState(PersistentState state) throws PersistenceException { |
137 |
// Save parent fill symbol properties
|
138 |
super.saveToState(state);
|
139 |
|
140 |
// Save own properties
|
141 |
if (getFillSymbol() != null) { |
142 |
state.set(FIELD_FILL_SYMBOL, getFillSymbol()); |
143 |
} |
144 |
state.set(FIELD_SIZE, getSize()); |
145 |
} |
146 |
|
147 |
public static void registerPersistence() { |
148 |
// Add the DynClass definition.
|
149 |
PersistenceManager manager = ToolsLocator.getPersistenceManager(); |
150 |
DynStruct definition = manager.addDefinition( |
151 |
DefaultMask.class, |
152 |
DEFAULT_MASK_DYNCLASS_NAME, |
153 |
DEFAULT_MASK_DYNCLASS_NAME+" Persistence definition",
|
154 |
null,
|
155 |
null
|
156 |
); |
157 |
|
158 |
// Extend the Style base definition
|
159 |
definition.extend(STYLE_DYNCLASS_NAME); |
160 |
|
161 |
// Fill symbol
|
162 |
definition.addDynFieldObject(FIELD_FILL_SYMBOL); |
163 |
// size
|
164 |
definition.addDynFieldDouble(FIELD_SIZE).setMandatory(true);
|
165 |
} |
166 |
} |