Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / symbols / MultiShapeSymbol.java @ 11741

History | View | Annotate | Download (7.29 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

    
10
import javax.print.attribute.PrintRequestAttributeSet;
11

    
12
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
13
import com.iver.cit.gvsig.fmap.core.FShape;
14
import com.iver.cit.gvsig.fmap.core.IGeometry;
15
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
16
import com.iver.cit.gvsig.fmap.core.styles.ILineStyle;
17
import com.iver.cit.gvsig.fmap.core.styles.IMask;
18
import com.iver.utiles.XMLEntity;
19

    
20
public class MultiShapeSymbol implements ILineSymbol, IMarkerSymbol, IFillSymbol {
21
        private IMarkerSymbol marker = SymbologyFactory.createDefaultMarkerSymbol();
22
        private ILineSymbol line = SymbologyFactory.createDefaultLineSymbol();
23
        private IFillSymbol fill = SymbologyFactory.createDefaultFillSymbol();
24
        private IMask mask;
25
        private String desc;
26
        private int referenceSystem;
27

    
28
        public Color getLineColor() {
29
                return line.getColor();
30
        }
31

    
32
        public void setLineColor(Color color) {
33
                line.setLineColor(color);
34
        }
35

    
36
        public ILineStyle getLineStyle() {
37
                return line.getLineStyle();
38
        }
39

    
40
        public void setLineStyle(ILineStyle lineStyle) {
41
                line.setLineStyle(lineStyle);
42
        }
43

    
44
        public void setLineWidth(double width) {
45
                line.setLineWidth(width);
46
        }
47

    
48
        public double getLineWidth() {
49
                return line.getLineWidth();
50
        }
51

    
52
        public int getAlpha() {
53
                return line.getAlpha();
54
        }
55

    
56
        public void setAlpha(int outlineAlpha) {
57
                line.setAlpha(outlineAlpha);
58
        }
59

    
60
        public ISymbol getSymbolForSelection() {
61
                // TODO Implement it
62
                throw new Error("Not yet implemented!");
63

    
64
        }
65

    
66
        public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) {
67
                switch (shp.getShapeType()) {
68
                case FShape.POINT: //Tipo punto
69
        case FShape.POINT + FShape.Z:
70
                        marker.draw(g, affineTransform, shp);
71
                        break;
72
                case FShape.LINE:
73
        case FShape.LINE + FShape.Z:
74
                case FShape.ARC:
75
                case FShape.ARC + FShape.Z:
76
                        line.draw(g, affineTransform, shp);
77
                        break;
78

    
79
                case FShape.POLYGON:
80
        case FShape.POLYGON + FShape.Z:
81
                case FShape.ELLIPSE:
82
                case FShape.ELLIPSE + FShape.Z:
83
        case FShape.CIRCLE:
84
                case FShape.CIRCLE + FShape.Z:
85
                        fill.draw(g, affineTransform, shp);
86
                        break;
87
                }
88

    
89

    
90
        }
91

    
92
        public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform,
93
                        Shape shp) {
94
                // TODO Implement it
95
                throw new Error("Not yet implemented!");
96

    
97
        }
98

    
99
        public int getOnePointRgb() {
100
                // will return a mixture of all symbol's getOnePointRgb() value
101
                int rMarker = marker.getColor().getRed();
102
                int rLine = line.getColor().getRed();
103
                int rFill = fill.getOutline().getColor().getRed();
104
                int red = (rMarker + rLine + rFill) / 3;
105

    
106
                int gMarker = marker.getColor().getGreen();
107
                int gLine = line.getColor().getGreen();
108
                int gFill = fill.getOutline().getColor().getGreen();
109
                int green = (gMarker + gLine + gFill) / 3;
110

    
111
                int bMarker = marker.getColor().getBlue();
112
                int bLine = line.getColor().getBlue();
113
                int bFill = fill.getOutline().getColor().getBlue();
114
                int blue = (bMarker + bLine + bFill) / 3;
115

    
116
                int aMarker = marker.getColor().getAlpha();
117
                int aLine = line.getColor().getAlpha();
118
                int aFill = fill.getOutline().getColor().getAlpha();
119
                int alpha = (aMarker + aLine + aFill) / 3;
120

    
121
                return (alpha) << 24 + (red << 16) + (green << 8) + blue;
122
        }
123

    
124
        public XMLEntity getXMLEntity() {
125
                XMLEntity xml = new XMLEntity();
126
                xml.putProperty("className", getClassName());
127
                xml.putProperty("desc", getDescription());
128
                xml.putProperty("unit", getUnit());
129
                xml.addChild(marker.getXMLEntity());
130
                xml.addChild(line.getXMLEntity());
131
                xml.addChild(fill.getXMLEntity());
132
                return xml;
133
        }
134

    
135
        public void setXMLEntity(XMLEntity xml) {
136
                setDescription(xml.getStringProperty("desc"));
137
                setUnit(xml.getIntProperty("unit"));
138
                marker = (IMarkerSymbol) SymbologyFactory.createSymbolFromXML(xml.getChild(0), null);
139
                line = (ILineSymbol) SymbologyFactory.createSymbolFromXML(xml.getChild(0), null);
140
                fill = (IFillSymbol) SymbologyFactory.createSymbolFromXML(xml.getChild(0), null);
141
        }
142

    
143
        public String getDescription() {
144
                return desc;
145
        }
146

    
147
        public boolean isShapeVisible() {
148
                return marker.isShapeVisible() || line.isShapeVisible() || fill.isShapeVisible();
149
        }
150

    
151
        public void setDescription(String desc) {
152
                this.desc = desc ;
153
        }
154

    
155
        public int getSymbolType() {
156
                return FShape.MULTI;
157
        }
158

    
159
        public boolean isSuitableFor(IGeometry geom) {
160
                // suitable for everything (why else does it exist?)
161
                return true;
162
        }
163

    
164
        public void drawInsideRectangle(Graphics2D g,
165
                        AffineTransform scaleInstance, Rectangle r) {
166

    
167
                Rectangle rect = new Rectangle(r.x, r.y+1, r.width, r.height-2);
168
                double myWidth =  (rect.getWidth()/3);
169

    
170
                rect.setBounds(0, rect.y, (int) myWidth, rect.height);
171
//                g.setColor(Color.RED);
172
//                g.drawRect(rect.x, rect.y, rect.width, rect.height);
173
                marker.drawInsideRectangle(g, scaleInstance, rect);
174

    
175
                rect.setBounds((int) (myWidth), rect.y, (int) myWidth, rect.height  );
176
//                g.setColor(Color.GREEN);
177
//                g.drawRect(rect.x, rect.y, rect.width, rect.height);
178
                line.drawInsideRectangle(g, scaleInstance, rect);
179

    
180
                rect.setBounds((int) (myWidth + myWidth)-1,  rect.y, (int) myWidth, rect.height  );
181
//                g.setColor(Color.BLUE);
182
//                g.drawRect(rect.x, rect.y, rect.width, rect.height);
183
                fill.drawInsideRectangle(g, scaleInstance, rect);
184

    
185
        }
186

    
187
        public String getClassName() {
188
                return getClass().getName();
189
        }
190

    
191
        public void print(Graphics2D g, AffineTransform at, FShape shape, PrintRequestAttributeSet properties)
192
                        throws ReadDriverException {
193
                switch (shape.getShapeType()) {
194
                case FShape.POINT: //Tipo punto
195
        case FShape.POINT + FShape.Z:
196
                        marker.print(g, at, shape, properties);
197
                        break;
198
                case FShape.LINE:
199
        case FShape.LINE + FShape.Z:
200
                case FShape.ARC:
201
                case FShape.ARC + FShape.Z:
202
                        line.print(g, at, shape, properties);
203
                        break;
204

    
205
                case FShape.POLYGON:
206
        case FShape.POLYGON + FShape.Z:
207
                case FShape.ELLIPSE:
208
                case FShape.ELLIPSE + FShape.Z:
209
        case FShape.CIRCLE:
210
                case FShape.CIRCLE + FShape.Z:
211
                        fill.print(g, at, shape, properties);
212
                        break;
213
                }
214
        }
215

    
216
        public double getRotation() {
217
                return marker.getRotation();
218
        }
219

    
220
        public void setRotation(double rotation) {
221
                marker.setRotation(rotation);
222
        }
223

    
224
        public Point2D getOffset() {
225
                return marker.getOffset();
226
        }
227

    
228
        public void setOffset(Point2D offset) {
229
                marker.setOffset(offset);
230
        }
231

    
232
        public double getSize() {
233
                return marker.getSize();
234
        }
235

    
236
        public void setSize(double size) {
237
                marker.setSize(size);
238
        }
239

    
240
        public Color getColor() {
241
                return marker.getColor();
242
        }
243

    
244
        public void setColor(Color color) {
245
                marker.setColor(color);
246
        }
247

    
248
        public void setFillColor(Color color) {
249
                fill.setFillColor(color);
250
        }
251

    
252
        public void setOutline(ILineSymbol outline) {
253
                fill.setOutline(outline);
254
        }
255

    
256
        public Color getFillColor() {
257
                return fill.getFillColor();
258
        }
259

    
260
        public ILineSymbol getOutline() {
261
                return fill.getOutline();
262
        }
263

    
264
        public int getFillAlpha() {
265
                return fill.getFillAlpha();
266
        }
267

    
268
        public IMask getMask() {
269
                return mask;
270
        }
271

    
272
        public void setUnit(int unitIndex) {
273
                marker.setUnit(unitIndex);
274
                line.setUnit(unitIndex);
275
        }
276

    
277
        public int getUnit() {
278
                return marker.getUnit();
279
        }
280

    
281
        public void setMask(IMask mask) {
282
                // TODO Implement it
283
                throw new Error("Not yet implemented!");
284

    
285
        }
286

    
287

    
288
        public int getReferenceSystem() {
289
                return this.referenceSystem;
290
        }
291

    
292
        public void setReferenceSystem(int system) {
293
                this.referenceSystem = system;
294

    
295
        }
296

    
297
}