Statistics
| Revision:

root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / symbols / MultiShapeSymbol.java @ 13606

History | View | Annotate | Download (9.92 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.CartographicSupportToolkit;
18
import com.iver.cit.gvsig.fmap.core.FShape;
19
import com.iver.cit.gvsig.fmap.core.IGeometry;
20
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
21
import com.iver.cit.gvsig.fmap.core.styles.ILineStyle;
22
import com.iver.cit.gvsig.fmap.core.styles.IMask;
23
import com.iver.utiles.XMLEntity;
24

    
25
/**
26
 * MultiShapeSymbol class allows to create a composition of several symbols with
27
 * different shapes and be treated as a single symbol.These shapes can be marker,line
28
 * or fill.
29
 *
30
 * @author   jaume dominguez faus - jaume.dominguez@iver.es
31
 */
32

    
33
public class MultiShapeSymbol implements ILineSymbol, IMarkerSymbol, IFillSymbol {
34
        private IMarkerSymbol marker = SymbologyFactory.createDefaultMarkerSymbol();
35
        private ILineSymbol line = SymbologyFactory.createDefaultLineSymbol();
36
        private IFillSymbol fill = SymbologyFactory.createDefaultFillSymbol();
37
        private IMask mask;
38
        private String desc;
39
        private int referenceSystem;
40

    
41
        public Color getLineColor() {
42
                return line.getColor();
43
        }
44

    
45
        public void setLineColor(Color color) {
46
                line.setLineColor(color);
47
        }
48

    
49
        public ILineStyle getLineStyle() {
50
                return line.getLineStyle();
51
        }
52

    
53
        public void setLineStyle(ILineStyle lineStyle) {
54
                line.setLineStyle(lineStyle);
55
        }
56

    
57
        public void setLineWidth(double width) {
58
                line.setLineWidth(width);
59
        }
60

    
61
        public double getLineWidth() {
62
                return line.getLineWidth();
63
        }
64

    
65
        public int getAlpha() {
66
                return line.getAlpha();
67
        }
68

    
69
        public void setAlpha(int outlineAlpha) {
70
                line.setAlpha(outlineAlpha);
71
        }
72

    
73
        public ISymbol getSymbolForSelection() {
74
                // TODO Implement it
75
                throw new Error("Not yet implemented!");
76

    
77
        }
78

    
79
        public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) {
80
                switch (shp.getShapeType()) {
81
                case FShape.POINT: //Tipo punto
82
        case FShape.POINT + FShape.Z:
83
                        marker.draw(g, affineTransform, shp);
84
                        break;
85
                case FShape.LINE:
86
        case FShape.LINE + FShape.Z:
87
                case FShape.ARC:
88
                case FShape.ARC + FShape.Z:
89
                        line.draw(g, affineTransform, shp);
90
                        break;
91

    
92
                case FShape.POLYGON:
93
        case FShape.POLYGON + FShape.Z:
94
                case FShape.ELLIPSE:
95
                case FShape.ELLIPSE + FShape.Z:
96
        case FShape.CIRCLE:
97
                case FShape.CIRCLE + FShape.Z:
98
                        fill.draw(g, affineTransform, shp);
99
                        break;
100
                }
101

    
102

    
103
        }
104

    
105
        public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform,
106
                        Shape shp) {
107
                // TODO Implement it
108
                throw new Error("Not yet implemented!");
109

    
110
        }
111

    
112
        public int getOnePointRgb() {
113
                // will return a mixture of all symbol's getOnePointRgb() value
114
                int rMarker = marker.getColor().getRed();
115
                int rLine = line.getColor().getRed();
116
                int rFill = fill.getOutline().getColor().getRed();
117
                int red = (rMarker + rLine + rFill) / 3;
118

    
119
                int gMarker = marker.getColor().getGreen();
120
                int gLine = line.getColor().getGreen();
121
                int gFill = fill.getOutline().getColor().getGreen();
122
                int green = (gMarker + gLine + gFill) / 3;
123

    
124
                int bMarker = marker.getColor().getBlue();
125
                int bLine = line.getColor().getBlue();
126
                int bFill = fill.getOutline().getColor().getBlue();
127
                int blue = (bMarker + bLine + bFill) / 3;
128

    
129
                int aMarker = marker.getColor().getAlpha();
130
                int aLine = line.getColor().getAlpha();
131
                int aFill = fill.getOutline().getColor().getAlpha();
132
                int alpha = (aMarker + aLine + aFill) / 3;
133

    
134
                return (alpha) << 24 + (red << 16) + (green << 8) + blue;
135
        }
136

    
137
        public XMLEntity getXMLEntity() {
138
                XMLEntity xml = new XMLEntity();
139
                xml.putProperty("className", getClassName());
140
                xml.putProperty("desc", getDescription());
141
                xml.putProperty("unit", getUnit());
142
                xml.addChild(marker.getXMLEntity());
143
                xml.addChild(line.getXMLEntity());
144
                xml.addChild(fill.getXMLEntity());
145
                return xml;
146
        }
147

    
148
        public void setXMLEntity(XMLEntity xml) {
149
                setDescription(xml.getStringProperty("desc"));
150
                setUnit(xml.getIntProperty("unit"));
151
                marker = (IMarkerSymbol) SymbologyFactory.createSymbolFromXML(xml.getChild(0), null);
152
                line = (ILineSymbol) SymbologyFactory.createSymbolFromXML(xml.getChild(1), null);
153
                fill = (IFillSymbol) SymbologyFactory.createSymbolFromXML(xml.getChild(2), null);
154
        }
155

    
156
        public String getDescription() {
157
                return desc;
158
        }
159

    
160
        public boolean isShapeVisible() {
161
                return marker.isShapeVisible() || line.isShapeVisible() || fill.isShapeVisible();
162
        }
163

    
164
        public void setDescription(String desc) {
165
                this.desc = desc ;
166
        }
167

    
168
        public int getSymbolType() {
169
                return FShape.MULTI;
170
        }
171

    
172
        public boolean isSuitableFor(IGeometry geom) {
173
                // suitable for everything (why else does it exist?)
174
                return true;
175
        }
176

    
177
        public void drawInsideRectangle(Graphics2D g,
178
                        AffineTransform scaleInstance, Rectangle r) {
179

    
180
                Rectangle rect = new Rectangle(r.x, r.y+1, r.width, r.height-2);
181
                double myWidth =  (rect.getWidth()/3);
182

    
183
                rect.setBounds(0, rect.y, (int) myWidth, rect.height);
184
//                g.setColor(Color.RED);
185
//                g.drawRect(rect.x, rect.y, rect.width, rect.height);
186
                marker.drawInsideRectangle(g, scaleInstance, rect);
187

    
188
                rect.setBounds((int) (myWidth), rect.y, (int) myWidth, rect.height  );
189
//                g.setColor(Color.GREEN);
190
//                g.drawRect(rect.x, rect.y, rect.width, rect.height);
191
                line.drawInsideRectangle(g, scaleInstance, rect);
192

    
193
                rect.setBounds((int) (myWidth + myWidth)-1,  rect.y, (int) myWidth, rect.height  );
194
//                g.setColor(Color.BLUE);
195
//                g.drawRect(rect.x, rect.y, rect.width, rect.height);
196
                fill.drawInsideRectangle(g, scaleInstance, rect);
197

    
198
        }
199

    
200
        public String getClassName() {
201
                return getClass().getName();
202
        }
203

    
204
        public void print(Graphics2D g, AffineTransform at, FShape shape, PrintRequestAttributeSet properties)
205
                        throws ReadDriverException {
206
                switch (shape.getShapeType()) {
207
                case FShape.POINT: //Tipo punto
208
        case FShape.POINT + FShape.Z:
209
                        marker.print(g, at, shape, properties);
210
                        break;
211
                case FShape.LINE:
212
        case FShape.LINE + FShape.Z:
213
                case FShape.ARC:
214
                case FShape.ARC + FShape.Z:
215
                        line.print(g, at, shape, properties);
216
                        break;
217

    
218
                case FShape.POLYGON:
219
        case FShape.POLYGON + FShape.Z:
220
                case FShape.ELLIPSE:
221
                case FShape.ELLIPSE + FShape.Z:
222
        case FShape.CIRCLE:
223
                case FShape.CIRCLE + FShape.Z:
224
                        fill.print(g, at, shape, properties);
225
                        break;
226
                }
227
        }
228

    
229
        public double getRotation() {
230
                return marker.getRotation();
231
        }
232

    
233
        public void setRotation(double rotation) {
234
                marker.setRotation(rotation);
235
        }
236

    
237
        public Point2D getOffset() {
238
                return marker.getOffset();
239
        }
240

    
241
        public void setOffset(Point2D offset) {
242
                marker.setOffset(offset);
243
        }
244

    
245
        public double getSize() {
246
                return marker.getSize();
247
        }
248

    
249
        public void setSize(double size) {
250
                marker.setSize(size);
251
        }
252

    
253
        public Color getColor() {
254
                return marker.getColor();
255
        }
256

    
257
        public void setColor(Color color) {
258
                marker.setColor(color);
259
        }
260

    
261
        public void setFillColor(Color color) {
262
                fill.setFillColor(color);
263
        }
264

    
265
        public void setOutline(ILineSymbol outline) {
266
                fill.setOutline(outline);
267
        }
268

    
269
        public Color getFillColor() {
270
                return fill.getFillColor();
271
        }
272

    
273
        public ILineSymbol getOutline() {
274
                return fill.getOutline();
275
        }
276

    
277
        public int getFillAlpha() {
278
                return fill.getFillAlpha();
279
        }
280

    
281
        public IMask getMask() {
282
                return mask;
283
        }
284

    
285
        public void setUnit(int unitIndex) {
286
                marker.setUnit(unitIndex);
287
                line.setUnit(unitIndex);
288
        }
289

    
290
        public int getUnit() {
291
                return marker.getUnit();
292
        }
293

    
294
        public void setMask(IMask mask) {
295
                // TODO Implement it
296
                throw new Error("Not yet implemented!");
297

    
298
        }
299

    
300
        public int getReferenceSystem() {
301
                return this.referenceSystem;
302
        }
303

    
304
        public void setReferenceSystem(int system) {
305
                this.referenceSystem = system;
306

    
307
        }
308

    
309
        public double toCartographicSize(ViewPort viewPort, double dpi, FShape shp) {
310
                switch (shp.getShapeType()) {
311
                case FShape.POINT: //Tipo punto
312
        case FShape.POINT + FShape.Z:
313
                        return marker.toCartographicSize(viewPort, dpi, shp);
314
                case FShape.LINE:
315
        case FShape.LINE + FShape.Z:
316
                case FShape.ARC:
317
                case FShape.ARC + FShape.Z:
318
                        return line.toCartographicSize(viewPort, dpi, shp);
319
                case FShape.POLYGON:
320
        case FShape.POLYGON + FShape.Z:
321
                case FShape.ELLIPSE:
322
                case FShape.ELLIPSE + FShape.Z:
323
        case FShape.CIRCLE:
324
                case FShape.CIRCLE + FShape.Z:
325
                        Logger.getAnonymousLogger().warning("Cartographic size does not have any sense for fill symbols");
326

    
327
                }
328
                return -1;
329
        }
330

    
331
        public void setCartographicSize(double cartographicSize, FShape shp) {
332
                switch (shp.getShapeType()) {
333
                case FShape.POINT: //Tipo punto
334
        case FShape.POINT + FShape.Z:
335
                marker.setCartographicSize(cartographicSize, null);
336
                break;
337
                case FShape.LINE:
338
        case FShape.LINE + FShape.Z:
339
                case FShape.ARC:
340
                case FShape.ARC + FShape.Z:
341
                        line.setCartographicSize(cartographicSize, null);
342
                break;
343
                case FShape.POLYGON:
344
        case FShape.POLYGON + FShape.Z:
345
                case FShape.ELLIPSE:
346
                case FShape.ELLIPSE + FShape.Z:
347
        case FShape.CIRCLE:
348
                case FShape.CIRCLE + FShape.Z:
349
                        Logger.getAnonymousLogger().warning("Cartographic size does not have any sense for fill symbols");
350
                }
351
        }
352

    
353

    
354
        public double getCartographicSize(ViewPort viewPort, double dpi, FShape shp) {
355

    
356
                switch (shp.getShapeType()) {
357
                case FShape.POINT: //Tipo punto
358
        case FShape.POINT + FShape.Z:
359
                return CartographicSupportToolkit.
360
                        getCartographicLength(marker,
361
                                                                  getSize(),
362
                                                                  viewPort,
363
                                                                  dpi);
364
                case FShape.LINE:
365
        case FShape.LINE + FShape.Z:
366
                case FShape.ARC:
367
                case FShape.ARC + FShape.Z:
368
                        return CartographicSupportToolkit.
369
                        getCartographicLength(line,
370
                                                                  getSize(),
371
                                                                  viewPort,
372
                                                                  dpi);
373
                case FShape.POLYGON:
374
        case FShape.POLYGON + FShape.Z:
375
                case FShape.ELLIPSE:
376
                case FShape.ELLIPSE + FShape.Z:
377
        case FShape.CIRCLE:
378
                case FShape.CIRCLE + FShape.Z:
379
                        Logger.getAnonymousLogger().warning("Cartographic size does not have any sense for fill symbols");
380
                }
381
                return -1;
382
        }
383

    
384

    
385
}