Statistics
| Revision:

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

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

    
128
import java.awt.BasicStroke;
129
import java.awt.Color;
130
import java.awt.Graphics2D;
131
import java.awt.Point;
132
import java.awt.geom.AffineTransform;
133

    
134
import com.iver.cit.gvsig.fmap.MapContext;
135
import com.iver.cit.gvsig.fmap.core.FPoint2D;
136
import com.iver.cit.gvsig.fmap.core.FShape;
137
import com.iver.cit.gvsig.fmap.core.GeneralPathX;
138
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
139
import com.iver.cit.gvsig.fmap.core.styles.IMask;
140
import com.iver.utiles.StringUtilities;
141
import com.iver.utiles.XMLEntity;
142
import com.iver.utiles.swing.threads.Cancellable;
143

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

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

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

    
175
        public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp, Cancellable cancel) {
176
                int x, y;
177
//                Point2D p = new Point2D.Double(((FPoint2D) shp).getX(), ((FPoint2D) shp)
178
//                                .getY());
179
                FPoint2D p = (FPoint2D) shp;
180

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

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

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

    
193
                g.setColor(getColor());
194
                GeneralPathX genPath = null;
195
                g.setStroke(new BasicStroke(1));
196

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

    
248
                        g.fill(genPath);
249
                        break;
250
                case STAR_STYLE:
251
                        x = x + halfSize;
252
                        y = y + halfSize;
253
                        genPath = new GeneralPathX();
254
                        genPath.moveTo(x-halfSize, y);
255

    
256
                        genPath.lineTo(x-2*(halfSize/3), y+(halfSize/3));
257
                        genPath.lineTo(x-2*(halfSize/3), y+2*(halfSize/3));
258
                        genPath.lineTo(x-(halfSize/3), y+2*(halfSize/3));
259

    
260
                        genPath.lineTo(x, y+halfSize);
261

    
262
                        genPath.lineTo(x+(halfSize/3), y+2*(halfSize/3));
263
                        genPath.lineTo(x+2*(halfSize/3), y+2*(halfSize/3));
264
                        genPath.lineTo(x+2*(halfSize/3), y+(halfSize/3));
265

    
266
                        genPath.lineTo(x+(halfSize), y);
267

    
268
                        genPath.lineTo(x+2*(halfSize/3), y-(halfSize/3));
269
                        genPath.lineTo(x+2*(halfSize/3), y-2*(halfSize/3));
270
                        genPath.lineTo(x+(halfSize/3), y-2*(halfSize/3));
271

    
272
                        genPath.lineTo(x, y-halfSize);
273

    
274
                        genPath.lineTo(x-(halfSize/3), y-2*(halfSize/3));
275
                        genPath.lineTo(x-2*(halfSize/3), y-2*(halfSize/3));
276
                        genPath.lineTo(x-2*(halfSize/3), y-(halfSize/3));
277

    
278
                        genPath.lineTo(x-halfSize, y);
279

    
280
                        genPath.closePath();
281

    
282

    
283
                        g.fill(genPath);
284

    
285
                        break;
286
                }
287

    
288

    
289
                if (outlined) {
290
                        g.setColor(outlineColor);
291
                        switch (markerStyle) {
292
                        case CIRCLE_STYLE:
293
                                g.drawOval(x, y, size, size);
294
                                break;
295
                        case SQUARE_STYLE:
296
                                g.drawRect(x, y, size, size);
297
                                break;
298
                        case CROSS_STYLE:
299
                        case DIAMOND_STYLE:
300
                        case STAR_STYLE:
301
                        case X_STYLE:
302
                        case TRIANGLE_STYLE:
303
                                g.draw(genPath);
304
                                break;
305
                        }
306
                }
307
        }
308

    
309
        public XMLEntity getXMLEntity() {
310
                XMLEntity xml = new XMLEntity();
311
                xml.putProperty("className", getClassName());
312
                xml.putProperty("desc", getDescription());
313
                xml.putProperty("isShapeVisible", isShapeVisible());
314
                xml.putProperty("color", StringUtilities.color2String(getColor()));
315
                xml.putProperty("rotation", getRotation());
316
                xml.putProperty("offsetX", getOffset().getX());
317
                xml.putProperty("offsetY", getOffset().getY());
318
                xml.putProperty("size", getSize());
319
                xml.putProperty("outline", outlined);
320
                xml.putProperty("unit", getUnit());
321
                xml.putProperty("referenceSystem", getReferenceSystem());
322
                xml.putProperty("markerStyle", getStyle());
323

    
324
                if (outlined) {
325
                        xml.putProperty("outlineColor", StringUtilities.color2String(outlineColor));
326
                        xml.putProperty("outlineSize", outlineSize);
327
                }
328
                return xml;
329
        }
330

    
331

    
332
        public String getClassName() {
333
                return getClass().getName();
334
        }
335

    
336
        public void setXMLEntity(XMLEntity xml) {
337
                setDescription(xml.getStringProperty("desc"));
338
                setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
339
                setColor(StringUtilities.string2Color(xml.getStringProperty("color")));
340
                setRotation(xml.getDoubleProperty("rotation"));
341
                setOffset(new Point.Double(xml.getDoubleProperty("offsetX"),
342
                                                xml.getDoubleProperty("offsetY")));
343
                setSize(xml.getDoubleProperty("size"));
344
                setOutlined(xml.getBooleanProperty("outline"));
345
                setUnit(xml.getIntProperty("unit"));
346
                setReferenceSystem(xml.getIntProperty("referenceSystem"));
347
                setStyle(xml.getIntProperty("markerStyle"));
348
                if (hasOutline()) {
349
                        setOutlineColor(StringUtilities.string2Color(xml.getStringProperty("outlineColor")));
350
                        setOutlineSize(xml.getDoubleProperty("outlineSize"));
351
                }
352
        }
353

    
354
        /**
355
         * Returns true or false depending if the simple marker symbol has an outline or not.
356
         * @return Returns the outline.
357
         */
358
        public boolean hasOutline() {
359
                return outlined;
360
        }
361

    
362
        /**
363
         * Establishes the outline for the simple marker symbol.
364
         * @param outline  The outline to set.
365
         */
366
        public void setOutlined(boolean outlined) {
367
                this.outlined = outlined;
368
        }
369

    
370
        /**
371
         * Returns the outline color for the symple marker symbol
372
         *
373
         * @return Color,outlineColor.
374
         */
375
        public Color getOutlineColor() {
376
                return outlineColor;
377
        }
378

    
379
        /**
380
         * Sets the outline color for the simple marker symbol
381
         * @param outlineColor, Color
382
         */
383
        public void setOutlineColor(Color outlineColor) {
384
                this.outlineColor = outlineColor;
385
        }
386

    
387
        /**
388
         * Gets the size of the outline for the simple marker symbol
389
         * @return  Returns the outlineSize.
390
         */
391
        public double getOutlineSize() {
392
                return outlineSize;
393
        }
394

    
395
        /**
396
         * Establishes the size for the outline of the simple marker symbol
397
         * @param outlineSize  The outlineSize to set.
398
         */
399
        public void setOutlineSize(double outlineSize) {
400
                this.outlineSize = outlineSize;
401
        }
402

    
403
        /**
404
         * @return  Returns the selectionSymbol.
405
         */
406
        public ISymbol getSelectionSymbol() {
407
                return selectionSymbol;
408
        }
409

    
410
        /**
411
         * @param selectionSymbol  The selectionSymbol to set.
412
         */
413
        public void setSelectionSymbol(ISymbol selectionSymbol) {
414
                this.selectionSymbol = selectionSymbol;
415
        }
416
        /**
417
         * Sets the style for the simple marker symbol
418
         * @param style
419
         */
420
        public void setStyle(int style) {
421
                this.markerStyle = style;
422
        }
423

    
424
        /**
425
         * Obtains the style for the simple marker symbol
426
         * @return markerStyle,int
427
         */
428
        public int getStyle() {
429
                return markerStyle;
430
        }
431

    
432
}