Statistics
| Revision:

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

History | View | Annotate | Download (11 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: SimpleMarkerSymbol.java 13881 2007-09-19 16:22:04Z jaume $
45
* $Log$
46
* Revision 1.18  2007-09-19 16:22:04  jaume
47
* removed unnecessary imports
48
*
49
* Revision 1.17  2007/08/09 07:32:20  jvidal
50
* javadoc
51
*
52
* Revision 1.16  2007/07/23 06:52:25  jaume
53
* default selection color refactored, moved to MapContext
54
*
55
* Revision 1.15  2007/07/18 06:54:35  jaume
56
* continuing with cartographic support
57
*
58
* Revision 1.14  2007/07/03 10:58:29  jaume
59
* first refactor on CartographicSupport
60
*
61
* Revision 1.13  2007/06/27 06:31:17  jaume
62
* *** empty log message ***
63
*
64
* Revision 1.12  2007/06/07 06:50:40  jaume
65
* *** empty log message ***
66
*
67
* Revision 1.11  2007/05/29 15:46:37  jaume
68
* *** empty log message ***
69
*
70
* Revision 1.10  2007/05/28 15:36:42  jaume
71
* *** empty log message ***
72
*
73
* Revision 1.9  2007/05/09 16:07:26  jaume
74
* *** empty log message ***
75
*
76
* Revision 1.8  2007/05/08 08:47:40  jaume
77
* *** empty log message ***
78
*
79
* Revision 1.7  2007/03/27 07:11:32  jaume
80
* *** empty log message ***
81
*
82
* Revision 1.6  2007/03/13 16:58:36  jaume
83
* Added QuantityByCategory (Multivariable legend) and some bugfixes in symbols
84
*
85
* Revision 1.5  2007/03/09 11:20:56  jaume
86
* Advanced symbology (start committing)
87
*
88
* Revision 1.3.2.7  2007/02/21 07:34:09  jaume
89
* labeling starts working
90
*
91
* Revision 1.3.2.6  2007/02/16 10:54:12  jaume
92
* multilayer splitted to multilayerline, multilayermarker,and  multilayerfill
93
*
94
* Revision 1.3.2.5  2007/02/15 16:23:44  jaume
95
* *** empty log message ***
96
*
97
* Revision 1.3.2.4  2007/02/13 16:19:19  jaume
98
* graduated symbol legends (start commiting)
99
*
100
* Revision 1.3.2.3  2007/02/12 15:15:20  jaume
101
* refactored interval legend and added graduated symbol legend
102
*
103
* Revision 1.3.2.2  2007/02/09 07:47:05  jaume
104
* Isymbol moved
105
*
106
* Revision 1.3.2.1  2007/02/05 14:59:03  jaume
107
* *** empty log message ***
108
*
109
* Revision 1.3  2007/01/25 16:25:23  jaume
110
* *** empty log message ***
111
*
112
* Revision 1.2  2007/01/10 16:39:41  jaume
113
* ISymbol now belongs to com.iver.cit.gvsig.fmap.core.symbols package
114
*
115
* Revision 1.1  2007/01/10 16:31:36  jaume
116
* *** empty log message ***
117
*
118
* Revision 1.1  2006/11/14 11:10:27  jaume
119
* *** empty log message ***
120
*
121
*
122
*/
123
package com.iver.cit.gvsig.fmap.core.symbols;
124

    
125
import java.awt.Color;
126
import java.awt.Graphics2D;
127
import java.awt.Point;
128
import java.awt.RenderingHints;
129
import java.awt.Shape;
130
import java.awt.geom.AffineTransform;
131

    
132
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
133
import com.iver.cit.gvsig.fmap.MapContext;
134
import com.iver.cit.gvsig.fmap.core.FPoint2D;
135
import com.iver.cit.gvsig.fmap.core.FShape;
136
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
137
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
138
import com.iver.cit.gvsig.fmap.core.styles.IMask;
139
import com.iver.utiles.StringUtilities;
140
import com.iver.utiles.XMLEntity;
141

    
142
/**
143
 * SimpleMarkerSymbol is the most basic symbol for the representation of point objects
144
 * which can define its size and color apart from the rotation and the offset from a point
145
 * in the map.
146
 * @author   jaume dominguez faus - jaume.dominguez@iver.es
147
 */
148
public class SimpleMarkerSymbol extends AbstractMarkerSymbol {
149

    
150
        public static final int CIRCLE_STYLE = 0;
151
        public static final int SQUARE_STYLE = 1;
152
        public static final int CROSS_STYLE = 2;
153
        public static final int DIAMOND_STYLE = 3;
154
        public static final int X_STYLE = 4;
155
        public static final int TRIANGLE_STYLE = 5;
156
        private boolean outlined;
157
        private Color outlineColor;
158
        private double outlineSize;
159
        private ISymbol selectionSymbol;
160
        private int markerStyle;
161

    
162
        public ISymbol getSymbolForSelection() {
163
                if (selectionSymbol == null) {
164
                        XMLEntity xml = getXMLEntity();
165
                        xml.putProperty("color", StringUtilities.color2String(MapContext.getSelectionColor()));
166
                        selectionSymbol = (SimpleMarkerSymbol) SymbologyFactory.
167
                                        createSymbolFromXML(xml, getDescription()+" version for selection");
168
                }
169
                return selectionSymbol;
170
        }
171

    
172
        public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) {
173
                int x, y;
174
//                Point2D p = new Point2D.Double(((FPoint2D) shp).getX(), ((FPoint2D) shp)
175
//                                .getY());
176
                FPoint2D p = (FPoint2D) shp;
177
                RenderingHints old = g.getRenderingHints();
178
                g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
179

    
180
                int size = (int) getSize();
181

    
182
                int halfSize = size/2;
183
                x = ((int) (p.getX() + getOffset().getX()) - halfSize);
184
                y = ((int) (p.getY() + getOffset().getY()) - halfSize);
185

    
186
                IMask mask = getMask();
187
                if (mask != null) {
188
                        IFillSymbol maskShape = mask.getFillSymbol();
189
//                        maskShape.draw(g, null, mask.getHaloShape(shp));
190
                }
191

    
192
                g.setColor(getColor());
193
                GeneralPathX genPath = null;
194

    
195
                switch (markerStyle) {
196
                case CIRCLE_STYLE:
197
                        g.fillOval(x, y, size, size);
198
                        break;
199
                case SQUARE_STYLE:
200
                        g.fillRect(x, y, size, size);
201
                        break;
202
                case CROSS_STYLE:
203
                        x = x + halfSize;
204
                        y = y + halfSize;
205
                        genPath = new GeneralPathX();
206
                        genPath.moveTo(x, y - halfSize);
207
                        genPath.lineTo(x, y + halfSize);
208
                        genPath.moveTo(x - halfSize, y);
209
                        genPath.lineTo(x + halfSize, y);
210
                        g.draw(genPath);
211
                        break;
212
                case DIAMOND_STYLE:
213
                        x = x + halfSize;
214
                        y = y + halfSize;
215
                        genPath = new GeneralPathX();
216
                        genPath.moveTo(x-halfSize, y);
217
                        genPath.lineTo(x, y+halfSize);
218
                        genPath.lineTo(x+halfSize, y);
219
                        genPath.lineTo(x, y-halfSize);
220
                        genPath.lineTo(x-halfSize, y);
221
                        genPath.closePath();
222
                        g.fill(genPath);
223
                        break;
224
                case X_STYLE:
225
                        x = x + halfSize;
226
                        y = y + halfSize;
227
                        genPath = new GeneralPathX();
228
                        genPath.moveTo(x-halfSize, y - halfSize);
229
                        genPath.lineTo(x+halfSize, y + halfSize);
230
                        genPath.moveTo(x - halfSize, y + halfSize);
231
                        genPath.lineTo(x + halfSize, y - halfSize);
232
                        g.draw(genPath);
233
                        break;
234
                case TRIANGLE_STYLE:
235
                        x = x + halfSize;
236
                        y = y + halfSize;
237
                        int otherSize = (int) (size * 0.55);
238
                        genPath = new GeneralPathX();
239
                        genPath.moveTo(x - halfSize,
240
                                y + halfSize);
241
                        genPath.lineTo(x + halfSize,
242
                                y + halfSize);
243
                        genPath.lineTo(x, y - otherSize);
244
                        genPath.closePath();
245

    
246
                        g.fill(genPath);
247
                        break;
248
                }
249

    
250
                if (outlined) {
251
                        g.setColor(outlineColor);
252

    
253
                        switch (markerStyle) {
254
                        case CIRCLE_STYLE:
255
                                g.drawOval(x, y, size, size);
256
                                break;
257
                        case SQUARE_STYLE:
258
                                g.drawRect(x, y, size, size);
259
                                break;
260
                        case CROSS_STYLE:
261
                        case DIAMOND_STYLE:
262
                        case X_STYLE:
263
                        case TRIANGLE_STYLE:
264
                                g.draw(genPath);
265
                                break;
266
                        }
267
                }
268
                g.setRenderingHints(old);
269
        }
270

    
271
        public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform, Shape shp) {
272
                return 0;
273
        }
274

    
275
        public XMLEntity getXMLEntity() {
276
                XMLEntity xml = new XMLEntity();
277
                xml.putProperty("className", getClassName());
278
                xml.putProperty("desc", getDescription());
279
                xml.putProperty("isShapeVisible", isShapeVisible());
280
                xml.putProperty("color", StringUtilities.color2String(getColor()));
281
                xml.putProperty("rotation", getRotation());
282
                xml.putProperty("offsetX", getOffset().getX());
283
                xml.putProperty("offsetY", getOffset().getY());
284
                xml.putProperty("size", getSize());
285
                xml.putProperty("outline", outlined);
286
                xml.putProperty("unit", getUnit());
287
                xml.putProperty("referenceSystem", getReferenceSystem());
288
                xml.putProperty("markerStyle", getStyle());
289

    
290
                if (outlined) {
291
                        xml.putProperty("outlineColor", StringUtilities.color2String(outlineColor));
292
                        xml.putProperty("outlineSize", outlineSize);
293
                }
294
                return xml;
295
        }
296

    
297
        public int getSymbolType() {
298
                return FShape.POINT;
299
        }
300

    
301
        public String getClassName() {
302
                return getClass().getName();
303
        }
304

    
305
        public void setXMLEntity(XMLEntity xml) {
306
                setDescription(xml.getStringProperty("desc"));
307
                setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
308
                setColor(StringUtilities.string2Color(xml.getStringProperty("color")));
309
                setRotation(xml.getDoubleProperty("rotation"));
310
                setOffset(new Point.Double(xml.getDoubleProperty("offsetX"),
311
                                                xml.getDoubleProperty("offsetY")));
312
                setSize(xml.getDoubleProperty("size"));
313
                setOutlined(xml.getBooleanProperty("outline"));
314
                setUnit(xml.getIntProperty("unit"));
315
                setReferenceSystem(xml.getIntProperty("referenceSystem"));
316
                setStyle(xml.getIntProperty("markerStyle"));
317
                if (hasOutline()) {
318
                        setOutlineColor(StringUtilities.string2Color(xml.getStringProperty("outlineColor")));
319
                        setOutlineSize(xml.getDoubleProperty("outlineSize"));
320
                }
321

    
322
        }
323

    
324
        public void print(Graphics2D g, AffineTransform at, FShape shape) throws ReadDriverException {
325
                // TODO Implement it
326
                throw new Error("Not yet implemented!");
327

    
328
        }
329

    
330
        /**
331
         * Returns true or false depending if the simple marker symbol has an outline or not.
332
         * @return Returns the outline.
333
         */
334
        public boolean hasOutline() {
335
                return outlined;
336
        }
337

    
338
        /**
339
         * Establishes the outline for the simple marker symbol.
340
         * @param outline  The outline to set.
341
         */
342
        public void setOutlined(boolean outlined) {
343
                this.outlined = outlined;
344
        }
345

    
346
        /**
347
         * Returns the outline color for the symple marker symbol
348
         *
349
         * @return Color,outlineColor.
350
         */
351
        public Color getOutlineColor() {
352
                return outlineColor;
353
        }
354

    
355
        /**
356
         * Sets the outline color for the simple marker symbol
357
         * @param outlineColor, Color
358
         */
359
        public void setOutlineColor(Color outlineColor) {
360
                this.outlineColor = outlineColor;
361
        }
362

    
363
        /**
364
         * Gets the size of the outline for the simple marker symbol
365
         * @return  Returns the outlineSize.
366
         */
367
        public double getOutlineSize() {
368
                return outlineSize;
369
        }
370

    
371
        /**
372
         * Establishes the size for the outline of the simple marker symbol
373
         * @param outlineSize  The outlineSize to set.
374
         */
375
        public void setOutlineSize(double outlineSize) {
376
                this.outlineSize = outlineSize;
377
        }
378

    
379
        /**
380
         * @return  Returns the selectionSymbol.
381
         */
382
        public ISymbol getSelectionSymbol() {
383
                return selectionSymbol;
384
        }
385

    
386
        /**
387
         * @param selectionSymbol  The selectionSymbol to set.
388
         */
389
        public void setSelectionSymbol(ISymbol selectionSymbol) {
390
                this.selectionSymbol = selectionSymbol;
391
        }
392
        /**
393
         * Sets the style for the simple marker symbol
394
         * @param style
395
         */
396
        public void setStyle(int style) {
397
                this.markerStyle = style;
398
        }
399

    
400
        /**
401
         * Obtains the style for the simple marker symbol
402
         * @return markerStyle,int
403
         */
404
        public int getStyle() {
405
                return markerStyle;
406
        }
407

    
408
}