root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / symbols / AbstractMarkerSymbol.java @ 29132
History | View | Annotate | Download (7.66 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: AbstractMarkerSymbol.java 29132 2009-06-02 09:57:46Z 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:20:45 jaume
|
50 |
* removed unnecessary imports
|
51 |
*
|
52 |
* Revision 1.12 2007/09/17 09:33:47 jaume
|
53 |
* some multishapedsymbol bugs fixed
|
54 |
*
|
55 |
* Revision 1.11 2007/07/18 06:54:35 jaume
|
56 |
* continuing with cartographic support
|
57 |
*
|
58 |
* Revision 1.10 2007/07/03 10:58:29 jaume
|
59 |
* first refactor on CartographicSupport
|
60 |
*
|
61 |
* Revision 1.9 2007/05/22 10:05:31 jaume
|
62 |
* *** empty log message ***
|
63 |
*
|
64 |
* Revision 1.8 2007/05/09 16:07:26 jaume
|
65 |
* *** empty log message ***
|
66 |
*
|
67 |
* Revision 1.7 2007/05/08 08:47:40 jaume
|
68 |
* *** empty log message ***
|
69 |
*
|
70 |
* Revision 1.6 2007/03/26 14:24:13 jaume
|
71 |
* implemented Print
|
72 |
*
|
73 |
* Revision 1.5 2007/03/21 11:02:17 jaume
|
74 |
* *** empty log message ***
|
75 |
*
|
76 |
* Revision 1.4 2007/03/09 11:20:56 jaume
|
77 |
* Advanced symbology (start committing)
|
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/09 07:47:05 jaume
|
86 |
* Isymbol moved
|
87 |
*
|
88 |
* Revision 1.3.2.1 2007/02/02 16:21:24 jaume
|
89 |
* start commiting labeling stuff
|
90 |
*
|
91 |
* Revision 1.3 2007/01/25 16:25:23 jaume
|
92 |
* *** empty log message ***
|
93 |
*
|
94 |
* Revision 1.2 2007/01/16 11:50:44 jaume
|
95 |
* *** empty log message ***
|
96 |
*
|
97 |
* Revision 1.1 2007/01/10 16:31:36 jaume
|
98 |
* *** empty log message ***
|
99 |
*
|
100 |
* Revision 1.4 2006/12/04 17:13:39 fjp
|
101 |
* *** empty log message ***
|
102 |
*
|
103 |
* Revision 1.3 2006/11/14 11:10:27 jaume
|
104 |
* *** empty log message ***
|
105 |
*
|
106 |
* Revision 1.2 2006/11/09 18:39:05 jaume
|
107 |
* *** empty log message ***
|
108 |
*
|
109 |
* Revision 1.1 2006/10/31 16:16:34 jaume
|
110 |
* *** empty log message ***
|
111 |
*
|
112 |
* Revision 1.4 2006/10/30 19:30:35 jaume
|
113 |
* *** empty log message ***
|
114 |
*
|
115 |
* Revision 1.3 2006/10/26 16:27:33 jaume
|
116 |
* support for composite marker symbols (not tested)
|
117 |
*
|
118 |
* Revision 1.2 2006/10/26 07:46:58 jaume
|
119 |
* *** empty log message ***
|
120 |
*
|
121 |
* Revision 1.1 2006/10/25 10:50:41 jaume
|
122 |
* movement of classes and gui stuff
|
123 |
*
|
124 |
* Revision 1.1 2006/10/18 07:54:06 jaume
|
125 |
* *** empty log message ***
|
126 |
*
|
127 |
*
|
128 |
*/
|
129 |
package com.iver.cit.gvsig.fmap.core.symbols; |
130 |
|
131 |
import java.awt.Color; |
132 |
import java.awt.Graphics2D; |
133 |
import java.awt.Point; |
134 |
import java.awt.Rectangle; |
135 |
import java.awt.geom.AffineTransform; |
136 |
import java.awt.geom.Point2D; |
137 |
|
138 |
import javax.print.attribute.PrintRequestAttributeSet; |
139 |
import javax.print.attribute.standard.PrintQuality; |
140 |
|
141 |
import com.iver.cit.gvsig.fmap.ViewPort; |
142 |
import com.iver.cit.gvsig.fmap.core.CartographicSupportToolkit; |
143 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
144 |
import com.iver.cit.gvsig.fmap.core.FPolygon2D; |
145 |
import com.iver.cit.gvsig.fmap.core.FShape; |
146 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
147 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
148 |
import com.iver.cit.gvsig.fmap.core.styles.IMask; |
149 |
|
150 |
|
151 |
/**
|
152 |
* Abstract class that any MARKER SYMBOL should extend.
|
153 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
154 |
*/
|
155 |
public abstract class AbstractMarkerSymbol extends AbstractSymbol implements IMarkerSymbol { |
156 |
private Color color = SymbologyFactory.DefaultSymbolColor; |
157 |
private double rotation; |
158 |
private Point2D offset = new Point2D.Double(); |
159 |
private double size; |
160 |
private IMask mask;
|
161 |
|
162 |
public final int getSymbolType() { |
163 |
return FShape.POINT;
|
164 |
} |
165 |
|
166 |
public double getRotation() { |
167 |
return rotation;
|
168 |
} |
169 |
|
170 |
public void setRotation(double r) { |
171 |
this.rotation = r;
|
172 |
} |
173 |
|
174 |
public Point2D getOffset() { |
175 |
if (offset == null) { |
176 |
offset = new Point(); |
177 |
} |
178 |
return offset;
|
179 |
} |
180 |
|
181 |
public void setOffset(Point2D offset) { |
182 |
this.offset = offset;
|
183 |
} |
184 |
|
185 |
public boolean isSuitableFor(IGeometry geom) { |
186 |
return (geom.getGeometryType()%FShape.Z) == FShape.POINT;
|
187 |
} |
188 |
|
189 |
public int getOnePointRgb() { |
190 |
return color.getRGB();
|
191 |
} |
192 |
|
193 |
public double getSize() { |
194 |
return size;
|
195 |
} |
196 |
|
197 |
public void setSize(double size) { |
198 |
this.size = size;
|
199 |
} |
200 |
|
201 |
public Color getColor() { |
202 |
return color;
|
203 |
} |
204 |
|
205 |
public void setColor(Color color) { |
206 |
this.color = color;
|
207 |
} |
208 |
|
209 |
public void getPixExtentPlus(FShape shp, float[] distances, ViewPort viewPort, int dpi) { |
210 |
float cs = (float) getCartographicSize(viewPort, dpi, shp); |
211 |
distances[0] = cs;
|
212 |
distances[1] = cs;
|
213 |
} |
214 |
|
215 |
|
216 |
public void print(Graphics2D g, AffineTransform at, FShape shape, PrintRequestAttributeSet properties) { |
217 |
double originalSize = getSize();
|
218 |
double size=originalSize;
|
219 |
// scale it to size
|
220 |
PrintQuality pq = (PrintQuality) properties.get(PrintQuality.class); |
221 |
if (pq.equals(PrintQuality.NORMAL)){ |
222 |
size *= (double) 300/72; |
223 |
}else if (pq.equals(PrintQuality.HIGH)){ |
224 |
size *= (double) 600/72; |
225 |
}else if (pq.equals(PrintQuality.DRAFT)){ |
226 |
// unitFactor *= 72; (which is the same than doing nothing)
|
227 |
} |
228 |
// setSize(size);
|
229 |
draw(g,at,shape,null);
|
230 |
// setSize(originalSize);
|
231 |
} |
232 |
|
233 |
public final IMask getMask() { |
234 |
return mask;
|
235 |
} |
236 |
|
237 |
public void drawInsideRectangle(Graphics2D g, AffineTransform scaleInstance, Rectangle r, PrintRequestAttributeSet properties) throws SymbolDrawingException { |
238 |
if (properties==null) |
239 |
draw(g, scaleInstance, new FPoint2D(r.getCenterX(), r.getCenterY()), null); |
240 |
else{
|
241 |
double originalSize = getSize();
|
242 |
double size=originalSize;
|
243 |
PrintQuality pq = (PrintQuality) properties.get(PrintQuality.class); |
244 |
if (pq.equals(PrintQuality.NORMAL)){ |
245 |
size *= (double) 300/72; |
246 |
}else if (pq.equals(PrintQuality.HIGH)){ |
247 |
size *= (double) 600/72; |
248 |
}else if (pq.equals(PrintQuality.DRAFT)){ |
249 |
// unitFactor *= 72; (which is the same than doing nothing)
|
250 |
} |
251 |
setSize(size); |
252 |
print(g, scaleInstance, new FPoint2D(r.getCenterX(), r.getCenterY()), properties);
|
253 |
setSize(originalSize); |
254 |
} |
255 |
} |
256 |
|
257 |
public final void setMask(IMask mask) { |
258 |
this.mask = mask;
|
259 |
} |
260 |
|
261 |
|
262 |
|
263 |
public void setCartographicSize(double cartographicSize, FShape shp) { |
264 |
setSize(cartographicSize); |
265 |
} |
266 |
|
267 |
public double toCartographicSize(ViewPort viewPort, double dpi, FShape shp) { |
268 |
double oldSize = getSize();
|
269 |
setCartographicSize(getCartographicSize( |
270 |
viewPort, |
271 |
dpi, |
272 |
shp), |
273 |
shp); |
274 |
return oldSize;
|
275 |
} |
276 |
|
277 |
public double getCartographicSize(ViewPort viewPort, double dpi, FShape shp) { |
278 |
return CartographicSupportToolkit.
|
279 |
getCartographicLength(this,
|
280 |
getSize(), |
281 |
viewPort, |
282 |
dpi); |
283 |
} |
284 |
|
285 |
private int unit; |
286 |
private int referenceSystem; |
287 |
|
288 |
public void setUnit(int unitIndex) { |
289 |
this.unit = unitIndex;
|
290 |
} |
291 |
|
292 |
public int getUnit() { |
293 |
return this.unit; |
294 |
} |
295 |
|
296 |
public int getReferenceSystem() { |
297 |
return this.referenceSystem; |
298 |
} |
299 |
|
300 |
public void setReferenceSystem(int system) { |
301 |
this.referenceSystem = system;
|
302 |
|
303 |
} |
304 |
} |