svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / symbols / SimpleMarkerSymbol.java @ 9919
History | View | Annotate | Download (5.96 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: SimpleMarkerSymbol.java 9919 2007-01-25 16:25:23Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.3 2007-01-25 16:25:23 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.2 2007/01/10 16:39:41 jaume
|
50 |
* ISymbol now belongs to com.iver.cit.gvsig.fmap.core.symbols package
|
51 |
*
|
52 |
* Revision 1.1 2007/01/10 16:31:36 jaume
|
53 |
* *** empty log message ***
|
54 |
*
|
55 |
* Revision 1.1 2006/11/14 11:10:27 jaume
|
56 |
* *** empty log message ***
|
57 |
*
|
58 |
*
|
59 |
*/
|
60 |
package com.iver.cit.gvsig.fmap.core.symbols; |
61 |
|
62 |
import java.awt.Color; |
63 |
import java.awt.Graphics2D; |
64 |
import java.awt.Point; |
65 |
import java.awt.Rectangle; |
66 |
import java.awt.Shape; |
67 |
import java.awt.geom.AffineTransform; |
68 |
|
69 |
import com.iver.cit.gvsig.fmap.DriverException; |
70 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
71 |
import com.iver.cit.gvsig.fmap.core.FShape; |
72 |
import com.iver.cit.gvsig.fmap.core.SymbolFactory; |
73 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
74 |
import com.iver.utiles.StringUtilities; |
75 |
import com.iver.utiles.XMLEntity; |
76 |
|
77 |
public class SimpleMarkerSymbol extends AbstractMarkerSymbol { |
78 |
private boolean outline; |
79 |
private Color outlineColor; |
80 |
private double outlineSize; |
81 |
|
82 |
|
83 |
private ISymbol selectionSymbol;
|
84 |
|
85 |
public ISymbol getSymbolForSelection() {
|
86 |
if (selectionSymbol == null) { |
87 |
XMLEntity xml = getXMLEntity(); |
88 |
xml.putProperty("color", FSymbol.getSelectionColor());
|
89 |
selectionSymbol = SymbolFactory.createFromXML(xml, getDescription() + " version for selection.");
|
90 |
} |
91 |
return selectionSymbol;
|
92 |
} |
93 |
|
94 |
public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) { |
95 |
int minx, miny;
|
96 |
FPoint2D p = (FPoint2D) shp; |
97 |
int halfSize = (int) size/2; |
98 |
minx = ((int) (p.getX() - offset.getX()) - halfSize);
|
99 |
miny = ((int) (p.getY() - offset.getY()) - halfSize);
|
100 |
g.setColor(getColor()); |
101 |
g.drawOval(minx, miny, (int) size, (int) size); |
102 |
} |
103 |
|
104 |
public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform, Shape shp) { |
105 |
return 0; |
106 |
} |
107 |
|
108 |
public XMLEntity getXMLEntity() {
|
109 |
XMLEntity xml = new XMLEntity();
|
110 |
xml.putProperty("className", getClassName());
|
111 |
xml.putProperty("desc", getDescription());
|
112 |
xml.putProperty("isShapeVisible", isShapeVisible());
|
113 |
xml.putProperty("color", StringUtilities.color2String(color));
|
114 |
xml.putProperty("rotation", getRotation());
|
115 |
xml.putProperty("offsetX", offset.getX());
|
116 |
xml.putProperty("offsetY", offset.getY());
|
117 |
xml.putProperty("size", size);
|
118 |
xml.putProperty("outline", outline);
|
119 |
if (outline) {
|
120 |
xml.putProperty("outlineColor", StringUtilities.color2String(outlineColor));
|
121 |
xml.putProperty("outlineSize", outlineSize);
|
122 |
} |
123 |
return xml;
|
124 |
} |
125 |
|
126 |
public int getSymbolType() { |
127 |
return FShape.POINT;
|
128 |
} |
129 |
|
130 |
public void drawInsideRectangle(Graphics2D g, AffineTransform scaleInstance, Rectangle r) { |
131 |
int minx, miny;
|
132 |
int rectSize = (int) ((size < r.width && size < r.height) |
133 |
? size |
134 |
: (int) (Math.min(r.width, r.height) * 0.8)); // does not fit, scale it |
135 |
|
136 |
minx = (int) ((r.getWidth() - rectSize) / 2); |
137 |
miny = (int) ((r.getHeight()- rectSize) / 2); |
138 |
g.setColor(getColor()); |
139 |
g.drawOval(minx, miny, rectSize, rectSize); |
140 |
} |
141 |
|
142 |
public String getClassName() { |
143 |
return getClass().getName();
|
144 |
} |
145 |
|
146 |
public void setXMLEntity(XMLEntity xml) { |
147 |
setDescription(xml.getStringProperty("desc"));
|
148 |
setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
|
149 |
setColor(StringUtilities.string2Color(xml.getStringProperty("color")));
|
150 |
setRotation(xml.getDoubleProperty("rotation"));
|
151 |
setOffset(new Point.Double(xml.getDoubleProperty("offsetX"), |
152 |
xml.getDoubleProperty("offsetY")));
|
153 |
setSize(xml.getDoubleProperty("size"));
|
154 |
setOutline(xml.getBooleanProperty("outline"));
|
155 |
if (hasOutline()) {
|
156 |
setOutlineColor(StringUtilities.string2Color(xml.getStringProperty("outlineColor")));
|
157 |
setOutlineSize(xml.getDoubleProperty("outlineSize"));
|
158 |
} |
159 |
|
160 |
} |
161 |
|
162 |
public void print(Graphics2D g, AffineTransform at, FShape shape) throws DriverException { |
163 |
// TODO Implement it
|
164 |
throw new Error("Not yet implemented!"); |
165 |
|
166 |
} |
167 |
|
168 |
/**
|
169 |
* @return Returns the outline.
|
170 |
*/
|
171 |
public boolean hasOutline() { |
172 |
return outline;
|
173 |
} |
174 |
|
175 |
/**
|
176 |
* @param outline The outline to set.
|
177 |
*/
|
178 |
public void setOutline(boolean outline) { |
179 |
this.outline = outline;
|
180 |
} |
181 |
|
182 |
/**
|
183 |
* @return Returns the outlineColor.
|
184 |
*/
|
185 |
public Color getOutlineColor() { |
186 |
return outlineColor;
|
187 |
} |
188 |
|
189 |
/**
|
190 |
* @param outlineColor The outlineColor to set.
|
191 |
*/
|
192 |
public void setOutlineColor(Color outlineColor) { |
193 |
this.outlineColor = outlineColor;
|
194 |
} |
195 |
|
196 |
/**
|
197 |
* @return Returns the outlineSize.
|
198 |
*/
|
199 |
public double getOutlineSize() { |
200 |
return outlineSize;
|
201 |
} |
202 |
|
203 |
/**
|
204 |
* @param outlineSize The outlineSize to set.
|
205 |
*/
|
206 |
public void setOutlineSize(double outlineSize) { |
207 |
this.outlineSize = outlineSize;
|
208 |
} |
209 |
|
210 |
/**
|
211 |
* @return Returns the selectionSymbol.
|
212 |
*/
|
213 |
public ISymbol getSelectionSymbol() {
|
214 |
return selectionSymbol;
|
215 |
} |
216 |
|
217 |
/**
|
218 |
* @param selectionSymbol The selectionSymbol to set.
|
219 |
*/
|
220 |
public void setSelectionSymbol(ISymbol selectionSymbol) { |
221 |
this.selectionSymbol = selectionSymbol;
|
222 |
} |
223 |
|
224 |
} |