Statistics
| Revision:

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

History | View | Annotate | Download (6.81 KB)

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