svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / symbols / SimpleFillSymbol.java @ 28367
History | View | Annotate | Download (7.52 KB)
1 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib��ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
|
42 |
/* CVS MESSAGES:
|
43 |
*
|
44 |
* $Id: SimpleFillSymbol.java 28367 2009-05-04 15:30:10Z vcaballero $
|
45 |
* $Log$
|
46 |
* Revision 1.14 2007-09-21 12:25:32 jaume
|
47 |
* cancellation support extended down to the IGeometry and ISymbol level
|
48 |
*
|
49 |
* Revision 1.13 2007/09/19 16:22:04 jaume
|
50 |
* removed unnecessary imports
|
51 |
*
|
52 |
* Revision 1.12 2007/09/18 14:50:31 caballero
|
53 |
* Leyendas sobre el Layout
|
54 |
*
|
55 |
* Revision 1.11 2007/07/23 06:52:25 jaume
|
56 |
* default selection color refactored, moved to MapContext
|
57 |
*
|
58 |
* Revision 1.10 2007/03/26 15:02:49 jaume
|
59 |
* Refactored IPrintable
|
60 |
*
|
61 |
* Revision 1.9 2007/03/21 11:37:00 jaume
|
62 |
* *** empty log message ***
|
63 |
*
|
64 |
* Revision 1.8 2007/03/21 11:02:17 jaume
|
65 |
* *** empty log message ***
|
66 |
*
|
67 |
* Revision 1.7 2007/03/20 17:00:50 jaume
|
68 |
* *** empty log message ***
|
69 |
*
|
70 |
* Revision 1.6 2007/03/20 16:02:09 jaume
|
71 |
* *** empty log message ***
|
72 |
*
|
73 |
* Revision 1.5 2007/03/09 11:20:57 jaume
|
74 |
* Advanced symbology (start committing)
|
75 |
*
|
76 |
* Revision 1.3.2.5 2007/02/21 07:34:09 jaume
|
77 |
* labeling starts working
|
78 |
*
|
79 |
* Revision 1.3.2.4 2007/02/16 10:54:12 jaume
|
80 |
* multilayer splitted to multilayerline, multilayermarker,and multilayerfill
|
81 |
*
|
82 |
* Revision 1.3.2.3 2007/02/15 16:23:44 jaume
|
83 |
* *** empty log message ***
|
84 |
*
|
85 |
* Revision 1.3.2.2 2007/02/12 15:15:20 jaume
|
86 |
* refactored interval legend and added graduated symbol legend
|
87 |
*
|
88 |
* Revision 1.3.2.1 2007/02/09 07:47:05 jaume
|
89 |
* Isymbol moved
|
90 |
*
|
91 |
* Revision 1.3 2007/01/24 17:58:22 jaume
|
92 |
* new features and architecture error fixes
|
93 |
*
|
94 |
* Revision 1.2 2007/01/10 16:39:41 jaume
|
95 |
* ISymbol now belongs to com.iver.cit.gvsig.fmap.core.symbols package
|
96 |
*
|
97 |
* Revision 1.1 2007/01/10 16:31:36 jaume
|
98 |
* *** empty log message ***
|
99 |
*
|
100 |
* Revision 1.7 2006/11/14 11:10:27 jaume
|
101 |
* *** empty log message ***
|
102 |
*
|
103 |
* Revision 1.6 2006/11/09 18:39:05 jaume
|
104 |
* *** empty log message ***
|
105 |
*
|
106 |
* Revision 1.5 2006/11/09 10:22:50 jaume
|
107 |
* *** empty log message ***
|
108 |
*
|
109 |
* Revision 1.4 2006/11/08 13:05:51 jaume
|
110 |
* *** empty log message ***
|
111 |
*
|
112 |
* Revision 1.3 2006/11/08 10:56:47 jaume
|
113 |
* *** empty log message ***
|
114 |
*
|
115 |
* Revision 1.2 2006/11/06 16:06:52 jaume
|
116 |
* *** empty log message ***
|
117 |
*
|
118 |
* Revision 1.1 2006/10/30 19:30:35 jaume
|
119 |
* *** empty log message ***
|
120 |
*
|
121 |
*
|
122 |
*/
|
123 |
package com.iver.cit.gvsig.fmap.core.symbols; |
124 |
|
125 |
import java.awt.Color; |
126 |
import java.awt.Graphics2D; |
127 |
import java.awt.Rectangle; |
128 |
import java.awt.geom.AffineTransform; |
129 |
|
130 |
import javax.print.attribute.PrintRequestAttributeSet; |
131 |
|
132 |
import com.iver.cit.gvsig.fmap.MapContext; |
133 |
import com.iver.cit.gvsig.fmap.core.FPolygon2D; |
134 |
import com.iver.cit.gvsig.fmap.core.FShape; |
135 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
136 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
137 |
import com.iver.utiles.StringUtilities; |
138 |
import com.iver.utiles.XMLEntity; |
139 |
import com.iver.utiles.swing.threads.Cancellable; |
140 |
|
141 |
/**
|
142 |
* Basic fill symbol. It will allow to paint a shape with its filling color (and transparency) and the outline.
|
143 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
144 |
*/
|
145 |
public class SimpleFillSymbol extends AbstractFillSymbol { |
146 |
private SimpleFillSymbol symbolForSelection;
|
147 |
|
148 |
|
149 |
public ISymbol getSymbolForSelection() {
|
150 |
if (symbolForSelection == null) { |
151 |
XMLEntity xml = getXMLEntity(); |
152 |
xml.putProperty("hasFill", true); |
153 |
xml.putProperty("color", StringUtilities.color2String(MapContext.getSelectionColor()));
|
154 |
symbolForSelection = (SimpleFillSymbol) SymbologyFactory. |
155 |
createSymbolFromXML(xml, getDescription()+" version for selection");
|
156 |
} |
157 |
return symbolForSelection;
|
158 |
} |
159 |
|
160 |
public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp, Cancellable cancel) { |
161 |
Color c = getFillColor();
|
162 |
if (c!=null && hasFill()) { |
163 |
g.setColor(c); |
164 |
g.fill(shp); |
165 |
} |
166 |
if (getOutline() != null && hasOutline()) |
167 |
getOutline().draw(g, affineTransform, shp, cancel); |
168 |
} |
169 |
|
170 |
public XMLEntity getXMLEntity() {
|
171 |
XMLEntity xml = new XMLEntity();
|
172 |
|
173 |
// the class name
|
174 |
xml.putProperty("className", getClassName());
|
175 |
|
176 |
// color
|
177 |
Color c = getFillColor();
|
178 |
if (c!=null) |
179 |
xml.putProperty("color", StringUtilities.color2String(getFillColor()));
|
180 |
|
181 |
//has Fill
|
182 |
xml.putProperty("hasFill", hasFill());
|
183 |
|
184 |
// description
|
185 |
xml.putProperty("desc", getDescription());
|
186 |
|
187 |
// is shape visible
|
188 |
xml.putProperty("isShapeVisible", isShapeVisible());
|
189 |
|
190 |
xml.putProperty("referenceSystem", getReferenceSystem());
|
191 |
xml.putProperty("unit", getUnit());
|
192 |
|
193 |
// outline
|
194 |
if (getOutline() != null) |
195 |
xml.addChild(getOutline().getXMLEntity()); |
196 |
|
197 |
//has Outline
|
198 |
xml.putProperty("hasOutline", hasOutline());
|
199 |
|
200 |
return xml;
|
201 |
} |
202 |
|
203 |
public int getSymbolType() { |
204 |
return FShape.POLYGON;
|
205 |
} |
206 |
|
207 |
public void drawInsideRectangle(Graphics2D g, |
208 |
AffineTransform scaleInstance, Rectangle r, PrintRequestAttributeSet properties) throws SymbolDrawingException { |
209 |
Rectangle rect = new Rectangle(r.x, r.y, r.width, r.height); |
210 |
rect.setFrame(((int) rect.getMinX())+1, ((int) rect.getMinY())+1, ((int) rect.getWidth())-2, ((int) rect.getHeight())-2); |
211 |
FShape shp = new FPolygon2D(new GeneralPathX(rect)); |
212 |
|
213 |
Color c = getFillColor();
|
214 |
if (c != null && hasFill()) { |
215 |
g.setColor(c); |
216 |
g.fillRect(rect.x, rect.y, rect.width, rect.height); |
217 |
} |
218 |
|
219 |
if (getOutline() != null && hasOutline()) |
220 |
if (properties==null) |
221 |
getOutline().draw(g, scaleInstance, shp, null);
|
222 |
else
|
223 |
print(g, new AffineTransform(), shp, properties); |
224 |
} |
225 |
|
226 |
public String getClassName() { |
227 |
return getClass().getName();
|
228 |
} |
229 |
|
230 |
public void setXMLEntity(XMLEntity xml) { |
231 |
// color
|
232 |
if (xml.contains("color")) |
233 |
setFillColor(StringUtilities.string2Color(xml.getStringProperty("color")));
|
234 |
|
235 |
//has Fill
|
236 |
if(xml.contains("hasFill")) |
237 |
setHasFill(xml.getBooleanProperty("hasFill"));
|
238 |
|
239 |
// description
|
240 |
setDescription(xml.getStringProperty("desc"));
|
241 |
|
242 |
// is shape visible
|
243 |
setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
|
244 |
|
245 |
|
246 |
// outline
|
247 |
if (xml.getChildrenCount() > 0) |
248 |
setOutline((ILineSymbol) SymbologyFactory.createSymbolFromXML(xml.getChild(0), null)); |
249 |
|
250 |
if (xml.contains("unit")) { // remove this line when done |
251 |
// measure unit (for outline)
|
252 |
setUnit(xml.getIntProperty("unit"));
|
253 |
|
254 |
// reference system (for outline)
|
255 |
setReferenceSystem(xml.getIntProperty("referenceSystem"));
|
256 |
} |
257 |
|
258 |
//has Outline
|
259 |
if(xml.contains("hasOutline")) |
260 |
setHasOutline(xml.getBooleanProperty("hasOutline"));
|
261 |
} |
262 |
|
263 |
public void print(Graphics2D g, AffineTransform at, FShape shape, PrintRequestAttributeSet properties) { |
264 |
Color c = getFillColor();
|
265 |
if (c!=null && hasFill()) { |
266 |
g.setColor(c); |
267 |
g.fill(shape); |
268 |
} |
269 |
if (getOutline() != null && hasOutline()) |
270 |
getOutline().print(g, at, shape, properties); |
271 |
|
272 |
} |
273 |
} |