root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / symbols / MultiShapeSymbol.java @ 12467
History | View | Annotate | Download (8.08 KB)
1 |
package com.iver.cit.gvsig.fmap.core.symbols; |
---|---|
2 |
|
3 |
import java.awt.Color; |
4 |
import java.awt.Graphics2D; |
5 |
import java.awt.Rectangle; |
6 |
import java.awt.Shape; |
7 |
import java.awt.geom.AffineTransform; |
8 |
import java.awt.geom.Point2D; |
9 |
import java.util.logging.Logger; |
10 |
|
11 |
import javax.print.attribute.PrintRequestAttributeSet; |
12 |
|
13 |
import sun.rmi.runtime.Log; |
14 |
|
15 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
16 |
import com.iver.cit.gvsig.fmap.ViewPort; |
17 |
import com.iver.cit.gvsig.fmap.core.FShape; |
18 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
19 |
import com.iver.cit.gvsig.fmap.core.SymbologyFactory; |
20 |
import com.iver.cit.gvsig.fmap.core.styles.ILineStyle; |
21 |
import com.iver.cit.gvsig.fmap.core.styles.IMask; |
22 |
import com.iver.utiles.XMLEntity; |
23 |
|
24 |
public class MultiShapeSymbol implements ILineSymbol, IMarkerSymbol, IFillSymbol { |
25 |
private IMarkerSymbol marker = SymbologyFactory.createDefaultMarkerSymbol();
|
26 |
private ILineSymbol line = SymbologyFactory.createDefaultLineSymbol();
|
27 |
private IFillSymbol fill = SymbologyFactory.createDefaultFillSymbol();
|
28 |
private IMask mask;
|
29 |
private String desc; |
30 |
private int referenceSystem; |
31 |
|
32 |
public Color getLineColor() { |
33 |
return line.getColor();
|
34 |
} |
35 |
|
36 |
public void setLineColor(Color color) { |
37 |
line.setLineColor(color); |
38 |
} |
39 |
|
40 |
public ILineStyle getLineStyle() {
|
41 |
return line.getLineStyle();
|
42 |
} |
43 |
|
44 |
public void setLineStyle(ILineStyle lineStyle) { |
45 |
line.setLineStyle(lineStyle); |
46 |
} |
47 |
|
48 |
public void setLineWidth(double width) { |
49 |
line.setLineWidth(width); |
50 |
} |
51 |
|
52 |
public double getLineWidth() { |
53 |
return line.getLineWidth();
|
54 |
} |
55 |
|
56 |
public int getAlpha() { |
57 |
return line.getAlpha();
|
58 |
} |
59 |
|
60 |
public void setAlpha(int outlineAlpha) { |
61 |
line.setAlpha(outlineAlpha); |
62 |
} |
63 |
|
64 |
public ISymbol getSymbolForSelection() {
|
65 |
// TODO Implement it
|
66 |
throw new Error("Not yet implemented!"); |
67 |
|
68 |
} |
69 |
|
70 |
public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) { |
71 |
switch (shp.getShapeType()) {
|
72 |
case FShape.POINT: //Tipo punto |
73 |
case FShape.POINT + FShape.Z:
|
74 |
marker.draw(g, affineTransform, shp); |
75 |
break;
|
76 |
case FShape.LINE:
|
77 |
case FShape.LINE + FShape.Z:
|
78 |
case FShape.ARC:
|
79 |
case FShape.ARC + FShape.Z:
|
80 |
line.draw(g, affineTransform, shp); |
81 |
break;
|
82 |
|
83 |
case FShape.POLYGON:
|
84 |
case FShape.POLYGON + FShape.Z:
|
85 |
case FShape.ELLIPSE:
|
86 |
case FShape.ELLIPSE + FShape.Z:
|
87 |
case FShape.CIRCLE:
|
88 |
case FShape.CIRCLE + FShape.Z:
|
89 |
fill.draw(g, affineTransform, shp); |
90 |
break;
|
91 |
} |
92 |
|
93 |
|
94 |
} |
95 |
|
96 |
public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform, |
97 |
Shape shp) {
|
98 |
// TODO Implement it
|
99 |
throw new Error("Not yet implemented!"); |
100 |
|
101 |
} |
102 |
|
103 |
public int getOnePointRgb() { |
104 |
// will return a mixture of all symbol's getOnePointRgb() value
|
105 |
int rMarker = marker.getColor().getRed();
|
106 |
int rLine = line.getColor().getRed();
|
107 |
int rFill = fill.getOutline().getColor().getRed();
|
108 |
int red = (rMarker + rLine + rFill) / 3; |
109 |
|
110 |
int gMarker = marker.getColor().getGreen();
|
111 |
int gLine = line.getColor().getGreen();
|
112 |
int gFill = fill.getOutline().getColor().getGreen();
|
113 |
int green = (gMarker + gLine + gFill) / 3; |
114 |
|
115 |
int bMarker = marker.getColor().getBlue();
|
116 |
int bLine = line.getColor().getBlue();
|
117 |
int bFill = fill.getOutline().getColor().getBlue();
|
118 |
int blue = (bMarker + bLine + bFill) / 3; |
119 |
|
120 |
int aMarker = marker.getColor().getAlpha();
|
121 |
int aLine = line.getColor().getAlpha();
|
122 |
int aFill = fill.getOutline().getColor().getAlpha();
|
123 |
int alpha = (aMarker + aLine + aFill) / 3; |
124 |
|
125 |
return (alpha) << 24 + (red << 16) + (green << 8) + blue; |
126 |
} |
127 |
|
128 |
public XMLEntity getXMLEntity() {
|
129 |
XMLEntity xml = new XMLEntity();
|
130 |
xml.putProperty("className", getClassName());
|
131 |
xml.putProperty("desc", getDescription());
|
132 |
xml.putProperty("unit", getUnit());
|
133 |
xml.addChild(marker.getXMLEntity()); |
134 |
xml.addChild(line.getXMLEntity()); |
135 |
xml.addChild(fill.getXMLEntity()); |
136 |
return xml;
|
137 |
} |
138 |
|
139 |
public void setXMLEntity(XMLEntity xml) { |
140 |
setDescription(xml.getStringProperty("desc"));
|
141 |
setUnit(xml.getIntProperty("unit"));
|
142 |
marker = (IMarkerSymbol) SymbologyFactory.createSymbolFromXML(xml.getChild(0), null); |
143 |
line = (ILineSymbol) SymbologyFactory.createSymbolFromXML(xml.getChild(0), null); |
144 |
fill = (IFillSymbol) SymbologyFactory.createSymbolFromXML(xml.getChild(0), null); |
145 |
} |
146 |
|
147 |
public String getDescription() { |
148 |
return desc;
|
149 |
} |
150 |
|
151 |
public boolean isShapeVisible() { |
152 |
return marker.isShapeVisible() || line.isShapeVisible() || fill.isShapeVisible();
|
153 |
} |
154 |
|
155 |
public void setDescription(String desc) { |
156 |
this.desc = desc ;
|
157 |
} |
158 |
|
159 |
public int getSymbolType() { |
160 |
return FShape.MULTI;
|
161 |
} |
162 |
|
163 |
public boolean isSuitableFor(IGeometry geom) { |
164 |
// suitable for everything (why else does it exist?)
|
165 |
return true; |
166 |
} |
167 |
|
168 |
public void drawInsideRectangle(Graphics2D g, |
169 |
AffineTransform scaleInstance, Rectangle r) { |
170 |
|
171 |
Rectangle rect = new Rectangle(r.x, r.y+1, r.width, r.height-2); |
172 |
double myWidth = (rect.getWidth()/3); |
173 |
|
174 |
rect.setBounds(0, rect.y, (int) myWidth, rect.height); |
175 |
// g.setColor(Color.RED);
|
176 |
// g.drawRect(rect.x, rect.y, rect.width, rect.height);
|
177 |
marker.drawInsideRectangle(g, scaleInstance, rect); |
178 |
|
179 |
rect.setBounds((int) (myWidth), rect.y, (int) myWidth, rect.height ); |
180 |
// g.setColor(Color.GREEN);
|
181 |
// g.drawRect(rect.x, rect.y, rect.width, rect.height);
|
182 |
line.drawInsideRectangle(g, scaleInstance, rect); |
183 |
|
184 |
rect.setBounds((int) (myWidth + myWidth)-1, rect.y, (int) myWidth, rect.height ); |
185 |
// g.setColor(Color.BLUE);
|
186 |
// g.drawRect(rect.x, rect.y, rect.width, rect.height);
|
187 |
fill.drawInsideRectangle(g, scaleInstance, rect); |
188 |
|
189 |
} |
190 |
|
191 |
public String getClassName() { |
192 |
return getClass().getName();
|
193 |
} |
194 |
|
195 |
public void print(Graphics2D g, AffineTransform at, FShape shape, PrintRequestAttributeSet properties) |
196 |
throws ReadDriverException {
|
197 |
switch (shape.getShapeType()) {
|
198 |
case FShape.POINT: //Tipo punto |
199 |
case FShape.POINT + FShape.Z:
|
200 |
marker.print(g, at, shape, properties); |
201 |
break;
|
202 |
case FShape.LINE:
|
203 |
case FShape.LINE + FShape.Z:
|
204 |
case FShape.ARC:
|
205 |
case FShape.ARC + FShape.Z:
|
206 |
line.print(g, at, shape, properties); |
207 |
break;
|
208 |
|
209 |
case FShape.POLYGON:
|
210 |
case FShape.POLYGON + FShape.Z:
|
211 |
case FShape.ELLIPSE:
|
212 |
case FShape.ELLIPSE + FShape.Z:
|
213 |
case FShape.CIRCLE:
|
214 |
case FShape.CIRCLE + FShape.Z:
|
215 |
fill.print(g, at, shape, properties); |
216 |
break;
|
217 |
} |
218 |
} |
219 |
|
220 |
public double getRotation() { |
221 |
return marker.getRotation();
|
222 |
} |
223 |
|
224 |
public void setRotation(double rotation) { |
225 |
marker.setRotation(rotation); |
226 |
} |
227 |
|
228 |
public Point2D getOffset() { |
229 |
return marker.getOffset();
|
230 |
} |
231 |
|
232 |
public void setOffset(Point2D offset) { |
233 |
marker.setOffset(offset); |
234 |
} |
235 |
|
236 |
public double getSize() { |
237 |
return marker.getSize();
|
238 |
} |
239 |
|
240 |
public void setSize(double size) { |
241 |
marker.setSize(size); |
242 |
} |
243 |
|
244 |
public Color getColor() { |
245 |
return marker.getColor();
|
246 |
} |
247 |
|
248 |
public void setColor(Color color) { |
249 |
marker.setColor(color); |
250 |
} |
251 |
|
252 |
public void setFillColor(Color color) { |
253 |
fill.setFillColor(color); |
254 |
} |
255 |
|
256 |
public void setOutline(ILineSymbol outline) { |
257 |
fill.setOutline(outline); |
258 |
} |
259 |
|
260 |
public Color getFillColor() { |
261 |
return fill.getFillColor();
|
262 |
} |
263 |
|
264 |
public ILineSymbol getOutline() {
|
265 |
return fill.getOutline();
|
266 |
} |
267 |
|
268 |
public int getFillAlpha() { |
269 |
return fill.getFillAlpha();
|
270 |
} |
271 |
|
272 |
public IMask getMask() {
|
273 |
return mask;
|
274 |
} |
275 |
|
276 |
public void setUnit(int unitIndex) { |
277 |
marker.setUnit(unitIndex); |
278 |
line.setUnit(unitIndex); |
279 |
} |
280 |
|
281 |
public int getUnit() { |
282 |
return marker.getUnit();
|
283 |
} |
284 |
|
285 |
public void setMask(IMask mask) { |
286 |
// TODO Implement it
|
287 |
throw new Error("Not yet implemented!"); |
288 |
|
289 |
} |
290 |
|
291 |
|
292 |
public int getReferenceSystem() { |
293 |
return this.referenceSystem; |
294 |
} |
295 |
|
296 |
public void setReferenceSystem(int system) { |
297 |
this.referenceSystem = system;
|
298 |
|
299 |
} |
300 |
|
301 |
public int getCartographicSize(ViewPort viewPort, double dpi, FShape shp) { |
302 |
switch (shp.getShapeType()) {
|
303 |
case FShape.POINT: //Tipo punto |
304 |
case FShape.POINT + FShape.Z:
|
305 |
return marker.getCartographicSize(viewPort, dpi, shp);
|
306 |
case FShape.LINE:
|
307 |
case FShape.LINE + FShape.Z:
|
308 |
case FShape.ARC:
|
309 |
case FShape.ARC + FShape.Z:
|
310 |
return line.getCartographicSize(viewPort, dpi, shp);
|
311 |
case FShape.POLYGON:
|
312 |
case FShape.POLYGON + FShape.Z:
|
313 |
case FShape.ELLIPSE:
|
314 |
case FShape.ELLIPSE + FShape.Z:
|
315 |
case FShape.CIRCLE:
|
316 |
case FShape.CIRCLE + FShape.Z:
|
317 |
Logger.getAnonymousLogger().warning("Cartographic size does not have any sense for fill symbols"); |
318 |
|
319 |
} |
320 |
return -1; |
321 |
} |
322 |
|
323 |
|
324 |
} |