root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / symbols / CharacterMarkerSymbol.java @ 11271
History | View | Annotate | Download (10.1 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: CharacterMarkerSymbol.java 11271 2007-04-19 14:22:29Z jaume $
|
45 |
* $Log$
|
46 |
* Revision 1.11 2007-04-19 14:21:30 jaume
|
47 |
* *** empty log message ***
|
48 |
*
|
49 |
* Revision 1.10 2007/03/26 14:24:13 jaume
|
50 |
* implemented Print
|
51 |
*
|
52 |
* Revision 1.9 2007/03/21 11:37:00 jaume
|
53 |
* *** empty log message ***
|
54 |
*
|
55 |
* Revision 1.8 2007/03/21 11:02:17 jaume
|
56 |
* *** empty log message ***
|
57 |
*
|
58 |
* Revision 1.7 2007/03/09 11:20:56 jaume
|
59 |
* Advanced symbology (start committing)
|
60 |
*
|
61 |
* Revision 1.5.2.8 2007/02/21 07:34:09 jaume
|
62 |
* labeling starts working
|
63 |
*
|
64 |
* Revision 1.5.2.7 2007/02/16 10:54:12 jaume
|
65 |
* multilayer splitted to multilayerline, multilayermarker,and multilayerfill
|
66 |
*
|
67 |
* Revision 1.5.2.6 2007/02/15 16:23:44 jaume
|
68 |
* *** empty log message ***
|
69 |
*
|
70 |
* Revision 1.5.2.5 2007/02/14 09:58:37 jaume
|
71 |
* *** empty log message ***
|
72 |
*
|
73 |
* Revision 1.5.2.4 2007/02/12 15:15:20 jaume
|
74 |
* refactored interval legend and added graduated symbol legend
|
75 |
*
|
76 |
* Revision 1.5.2.3 2007/02/09 07:47:04 jaume
|
77 |
* Isymbol moved
|
78 |
*
|
79 |
* Revision 1.5.2.2 2007/02/05 14:59:04 jaume
|
80 |
* *** empty log message ***
|
81 |
*
|
82 |
* Revision 1.5.2.1 2007/01/30 18:10:45 jaume
|
83 |
* start commiting labeling stuff
|
84 |
*
|
85 |
* Revision 1.5 2007/01/25 16:25:23 jaume
|
86 |
* *** empty log message ***
|
87 |
*
|
88 |
* Revision 1.4 2007/01/24 17:58:22 jaume
|
89 |
* new features and architecture error fixes
|
90 |
*
|
91 |
* Revision 1.3 2007/01/16 11:50:44 jaume
|
92 |
* *** empty log message ***
|
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.6 2006/12/04 17:13:39 fjp
|
101 |
* *** empty log message ***
|
102 |
*
|
103 |
* Revision 1.5 2006/11/14 11:10:27 jaume
|
104 |
* *** empty log message ***
|
105 |
*
|
106 |
* Revision 1.4 2006/11/09 18:39:05 jaume
|
107 |
* *** empty log message ***
|
108 |
*
|
109 |
* Revision 1.3 2006/11/08 10:56:47 jaume
|
110 |
* *** empty log message ***
|
111 |
*
|
112 |
* Revision 1.2 2006/11/06 17:08:45 jaume
|
113 |
* *** empty log message ***
|
114 |
*
|
115 |
* Revision 1.1 2006/10/31 16:16:34 jaume
|
116 |
* *** empty log message ***
|
117 |
*
|
118 |
* Revision 1.4 2006/10/30 19:30:35 jaume
|
119 |
* *** empty log message ***
|
120 |
*
|
121 |
* Revision 1.3 2006/10/29 23:53:49 jaume
|
122 |
* *** empty log message ***
|
123 |
*
|
124 |
* Revision 1.2 2006/10/26 16:27:33 jaume
|
125 |
* support for composite marker symbols (not tested)
|
126 |
*
|
127 |
* Revision 1.1 2006/10/25 10:50:41 jaume
|
128 |
* movement of classes and gui stuff
|
129 |
*
|
130 |
* Revision 1.3 2006/10/24 19:54:16 jaume
|
131 |
* added IPersistence
|
132 |
*
|
133 |
* Revision 1.2 2006/10/24 08:02:51 jaume
|
134 |
* *** empty log message ***
|
135 |
*
|
136 |
* Revision 1.1 2006/10/18 07:54:06 jaume
|
137 |
* *** empty log message ***
|
138 |
*
|
139 |
*
|
140 |
*/
|
141 |
package com.iver.cit.gvsig.fmap.core.symbols; |
142 |
|
143 |
import java.awt.Color; |
144 |
import java.awt.Font; |
145 |
import java.awt.Graphics2D; |
146 |
import java.awt.Point; |
147 |
import java.awt.Rectangle; |
148 |
import java.awt.RenderingHints; |
149 |
import java.awt.Shape; |
150 |
import java.awt.geom.AffineTransform; |
151 |
import java.awt.geom.Point2D; |
152 |
|
153 |
import javax.print.attribute.PrintRequestAttributeSet; |
154 |
|
155 |
import org.apache.batik.ext.awt.geom.PathLength; |
156 |
|
157 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
158 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
159 |
import com.iver.cit.gvsig.fmap.core.FShape; |
160 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
161 |
import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
162 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
163 |
import com.iver.utiles.StringUtilities; |
164 |
import com.iver.utiles.XMLEntity; |
165 |
import com.vividsolutions.jts.geom.Geometry; |
166 |
|
167 |
|
168 |
/**
|
169 |
* Symbol that manages symbols from a TrueType font source
|
170 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
171 |
*/
|
172 |
public class CharacterMarkerSymbol extends CartographicMarkerSymbol { |
173 |
private Font font = new Font("Arial", Font.PLAIN, 20); |
174 |
private int unicode; |
175 |
private ISymbol selectionSymbol;
|
176 |
|
177 |
/**
|
178 |
* Creates a new instance of CharacterMarker with default values
|
179 |
*
|
180 |
*/
|
181 |
public CharacterMarkerSymbol() {
|
182 |
super();
|
183 |
} |
184 |
|
185 |
/**
|
186 |
* Creates a new instance of CharacterMarker specifying the marker source
|
187 |
* font, the character code corresponding to the symbol, and the color that
|
188 |
* will be used in rendering time.
|
189 |
*
|
190 |
* @param font -
|
191 |
* src Font
|
192 |
* @param charCode -
|
193 |
* character code of the symbol for this font
|
194 |
* @param color -
|
195 |
* color to be used in when rendering.
|
196 |
*/
|
197 |
public CharacterMarkerSymbol(Font font, int charCode, Color color) { |
198 |
super();
|
199 |
this.font = font;
|
200 |
unicode = charCode; |
201 |
setColor(color); |
202 |
} |
203 |
|
204 |
/**
|
205 |
* @return
|
206 |
* @uml.property name="font"
|
207 |
*/
|
208 |
public Font getFont() { |
209 |
return font;
|
210 |
} |
211 |
|
212 |
/**
|
213 |
* @param font
|
214 |
* @uml.property name="font"
|
215 |
*/
|
216 |
public void setFont(Font font) { |
217 |
this.font = font;
|
218 |
} |
219 |
|
220 |
public ISymbol getSymbolForSelection() {
|
221 |
if (selectionSymbol == null) { |
222 |
XMLEntity xml = getXMLEntity(); |
223 |
xml.putProperty("color", FSymbol.getSelectionColor());
|
224 |
selectionSymbol = SymbologyFactory.createSymbolFromXML(xml, getDescription() + " version for selection.");
|
225 |
} |
226 |
return selectionSymbol;
|
227 |
} |
228 |
|
229 |
public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) { |
230 |
g.setFont(getFont()); |
231 |
g.setColor(getColor()); |
232 |
double theta = getRotation();
|
233 |
int xOffset = (int) getOffset().getX(); // * multiplicador d'unitats; |
234 |
int yOffset = (int) getOffset().getY(); // * multiplicador d'unitats |
235 |
Point2D p = new Point2D.Double(((FPoint2D) shp).getX(), ((FPoint2D) shp) |
236 |
.getY()); |
237 |
|
238 |
/*
|
239 |
|
240 |
Point2D p = null;
|
241 |
switch (shp.getShapeType()) {
|
242 |
case FShape.POINT:
|
243 |
p = new Point2D.Double(((FPoint2D) shp).getX(), ((FPoint2D) shp)
|
244 |
.getY());
|
245 |
break;
|
246 |
case FShape.LINE:
|
247 |
final PathLength pathLen = new PathLength(shp);
|
248 |
final float midDistance = pathLen.lengthOfPath() / 2;
|
249 |
p = pathLen.pointAtLength(midDistance);
|
250 |
break;
|
251 |
case FShape.POLYGON:
|
252 |
Geometry geom = FConverter.java2d_to_jts(shp);
|
253 |
com.vividsolutions.jts.geom.Point centroid = geom.getCentroid();
|
254 |
p = new Point2D.Double(centroid.getX(), centroid.getY());
|
255 |
}
|
256 |
*/
|
257 |
g.translate((int) (p.getX() + xOffset), (int) (p.getY() + yOffset)); |
258 |
if (theta != 0) g.rotate(theta); |
259 |
|
260 |
char[] text = new char[] { (char) unicode }; |
261 |
g.drawChars(text, 0, text.length, 0, 0); |
262 |
|
263 |
if (theta!=0) g.rotate(-theta); |
264 |
g.translate(-(int) (p.getX() + xOffset), - (int) (p.getY() + yOffset)); |
265 |
|
266 |
} |
267 |
|
268 |
public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform, |
269 |
Shape shp) {
|
270 |
return 0; |
271 |
} |
272 |
|
273 |
public XMLEntity getXMLEntity() {
|
274 |
XMLEntity xml = new XMLEntity();
|
275 |
|
276 |
// the class name
|
277 |
xml.putProperty("className", getClassName());
|
278 |
|
279 |
// color
|
280 |
xml.putProperty("color", StringUtilities.color2String(getColor()));
|
281 |
|
282 |
// font
|
283 |
xml.putProperty("font", font.getFontName());
|
284 |
|
285 |
// font style
|
286 |
xml.putProperty("fontStyle", font.getStyle());
|
287 |
|
288 |
// marker size
|
289 |
xml.putProperty("size", font.getSize());
|
290 |
|
291 |
// symbol code
|
292 |
xml.putProperty("symbolCode", unicode);
|
293 |
|
294 |
// description
|
295 |
xml.putProperty("desc", getDescription());
|
296 |
|
297 |
// is shape visible
|
298 |
xml.putProperty("isShapeVisible", isShapeVisible());
|
299 |
|
300 |
// x offset
|
301 |
xml.putProperty("xOffset", getOffset().getX());
|
302 |
|
303 |
// y offset
|
304 |
xml.putProperty("yOffset", getOffset().getY());
|
305 |
|
306 |
// rotation
|
307 |
xml.putProperty("rotation", getRotation());
|
308 |
return xml;
|
309 |
} |
310 |
|
311 |
public int getSymbolType() { |
312 |
return FShape.POINT;
|
313 |
} |
314 |
|
315 |
public void drawInsideRectangle(Graphics2D g, AffineTransform scaleInstance, Rectangle r) { |
316 |
g.rotate(getRotation()); |
317 |
// Sirve de algo el scaleInstance???
|
318 |
RenderingHints old = g.getRenderingHints();
|
319 |
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); |
320 |
double h = r.getHeight();
|
321 |
g.setFont(font); |
322 |
g.setColor(getColor()); |
323 |
r.y = (int) h;
|
324 |
|
325 |
int x = r.x;
|
326 |
int y = r.y;
|
327 |
int width = (int) r.getHeight(); |
328 |
int height = (int) r.getWidth(); |
329 |
int diff = (width-height);
|
330 |
if (diff<0) { |
331 |
x -= diff /2;
|
332 |
} else {
|
333 |
y += diff /2;
|
334 |
} |
335 |
|
336 |
// and apply the offset
|
337 |
x = x + (int) getOffset().getX(); // TODO scale offset |
338 |
y = y + (int) getOffset().getY(); // TODO scale offset |
339 |
char[] text = new char[] { (char) unicode }; |
340 |
g.drawChars(text, 0, text.length, x, y);
|
341 |
g.setRenderingHints(old); |
342 |
} |
343 |
|
344 |
public void setUnicode(int symbol) { |
345 |
this.unicode = symbol;
|
346 |
} |
347 |
|
348 |
public int getUnicode() { |
349 |
return unicode;
|
350 |
} |
351 |
|
352 |
public String getClassName() { |
353 |
return this.getClass().getName(); |
354 |
} |
355 |
|
356 |
public void setXMLEntity(XMLEntity xml) { |
357 |
setColor(StringUtilities.string2Color(xml.getStringProperty("color")));
|
358 |
Point p = new Point(); |
359 |
p.setLocation(xml.getDoubleProperty("xOffset"), xml.getDoubleProperty("yOffset")); |
360 |
|
361 |
setDescription(xml.getStringProperty("desc"));
|
362 |
font = new Font(xml.getStringProperty("font"), |
363 |
xml.getIntProperty("fontStyle"),
|
364 |
(int) xml.getFloatProperty("size")); |
365 |
setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
|
366 |
unicode = xml.getIntProperty("symbolCode");
|
367 |
setOffset(p); |
368 |
setRotation(xml.getDoubleProperty("rotation"));
|
369 |
|
370 |
} |
371 |
|
372 |
public void print(Graphics2D g, AffineTransform at, FShape shape) throws ReadDriverException { |
373 |
// TODO Implement it
|
374 |
throw new Error("Not yet implemented!"); |
375 |
|
376 |
} |
377 |
|
378 |
public double getSize() { |
379 |
return font.getSize();
|
380 |
} |
381 |
|
382 |
public void setSize(double size) { |
383 |
font = new Font(font.getName(), font.getStyle(), (int) size); |
384 |
} |
385 |
|
386 |
} |