Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / libraries / libFMap_mapcontext / src / org / gvsig / fmap / mapcontext / rendering / symbols / AbstractMarkerSymbol.java @ 28879

History | View | Annotate | Download (8.49 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: AbstractMarkerSymbol.java 21071 2008-06-02 10:55:35Z vcaballero $
45
* $Log$
46
* Revision 1.14  2007-09-21 12:25:32  jaume
47
* cancellation support extended down to the IGeometry and ISymbol level
48
*
49
* Revision 1.13  2007/09/19 16:20:45  jaume
50
* removed unnecessary imports
51
*
52
* Revision 1.12  2007/09/17 09:33:47  jaume
53
* some multishapedsymbol bugs fixed
54
*
55
* Revision 1.11  2007/07/18 06:54:35  jaume
56
* continuing with cartographic support
57
*
58
* Revision 1.10  2007/07/03 10:58:29  jaume
59
* first refactor on CartographicSupport
60
*
61
* Revision 1.9  2007/05/22 10:05:31  jaume
62
* *** empty log message ***
63
*
64
* Revision 1.8  2007/05/09 16:07:26  jaume
65
* *** empty log message ***
66
*
67
* Revision 1.7  2007/05/08 08:47:40  jaume
68
* *** empty log message ***
69
*
70
* Revision 1.6  2007/03/26 14:24:13  jaume
71
* implemented Print
72
*
73
* Revision 1.5  2007/03/21 11:02:17  jaume
74
* *** empty log message ***
75
*
76
* Revision 1.4  2007/03/09 11:20:56  jaume
77
* Advanced symbology (start committing)
78
*
79
* Revision 1.3.2.4  2007/02/16 10:54:12  jaume
80
* multilayer splitted to multilayerline, multilayermarker,and  multilayerfill
81
*
82
* Revision 1.3.2.3  2007/02/15 16:23:44  jaume
83
* *** empty log message ***
84
*
85
* Revision 1.3.2.2  2007/02/09 07:47:05  jaume
86
* Isymbol moved
87
*
88
* Revision 1.3.2.1  2007/02/02 16:21:24  jaume
89
* start commiting labeling stuff
90
*
91
* Revision 1.3  2007/01/25 16:25:23  jaume
92
* *** empty log message ***
93
*
94
* Revision 1.2  2007/01/16 11:50:44  jaume
95
* *** empty log message ***
96
*
97
* Revision 1.1  2007/01/10 16:31:36  jaume
98
* *** empty log message ***
99
*
100
* Revision 1.4  2006/12/04 17:13:39  fjp
101
* *** empty log message ***
102
*
103
* Revision 1.3  2006/11/14 11:10:27  jaume
104
* *** empty log message ***
105
*
106
* Revision 1.2  2006/11/09 18:39:05  jaume
107
* *** empty log message ***
108
*
109
* Revision 1.1  2006/10/31 16:16:34  jaume
110
* *** empty log message ***
111
*
112
* Revision 1.4  2006/10/30 19:30:35  jaume
113
* *** empty log message ***
114
*
115
* Revision 1.3  2006/10/26 16:27:33  jaume
116
* support for composite marker symbols (not tested)
117
*
118
* Revision 1.2  2006/10/26 07:46:58  jaume
119
* *** empty log message ***
120
*
121
* Revision 1.1  2006/10/25 10:50:41  jaume
122
* movement of classes and gui stuff
123
*
124
* Revision 1.1  2006/10/18 07:54:06  jaume
125
* *** empty log message ***
126
*
127
*
128
*/
129
package org.gvsig.fmap.mapcontext.rendering.symbols;
130

    
131
import java.awt.Color;
132
import java.awt.Graphics2D;
133
import java.awt.Point;
134
import java.awt.Rectangle;
135
import java.awt.geom.AffineTransform;
136
import java.awt.geom.Point2D;
137

    
138
import javax.print.attribute.PrintRequestAttributeSet;
139
import javax.print.attribute.standard.PrintQuality;
140

    
141
import org.gvsig.fmap.geom.Geometry;
142
import org.gvsig.fmap.geom.GeometryLocator;
143
import org.gvsig.fmap.geom.GeometryManager;
144
import org.gvsig.fmap.geom.Geometry.SUBTYPES;
145
import org.gvsig.fmap.geom.Geometry.TYPES;
146
import org.gvsig.fmap.geom.exception.CreateGeometryException;
147
import org.gvsig.fmap.geom.util.UtilFunctions;
148
import org.gvsig.fmap.mapcontext.ViewPort;
149
import org.gvsig.fmap.mapcontext.rendering.symbols.styles.IMask;
150
import org.slf4j.Logger;
151
import org.slf4j.LoggerFactory;
152

    
153

    
154
/**
155
 * Abstract class that any MARKER SYMBOL should extend.
156
 * @author  jaume dominguez faus - jaume.dominguez@iver.es
157
 */
158
public abstract class AbstractMarkerSymbol extends AbstractSymbol implements IMarkerSymbol {
159
        private static final GeometryManager geomManager = GeometryLocator.getGeometryManager();
160
        private static final Logger logger = LoggerFactory.getLogger(AbstractMarkerSymbol.class);
161
        private Color color = SymbologyFactory.DefaultSymbolColor;
162
        private double rotation;
163
        private Point2D offset = new Point2D.Double();
164
        private double size;
165
        private IMask mask;
166

    
167
        public final int getSymbolType() {
168
                return Geometry.TYPES.POINT;
169
        }
170

    
171
        public double getRotation() {
172
                return rotation;
173
        }
174

    
175
        public void setRotation(double r) {
176
                this.rotation = r;
177
        }
178

    
179
        public Point2D getOffset() {
180
                if (offset == null) {
181
                        offset = new Point();
182
                }
183
                return offset;
184
        }
185

    
186
        public void setOffset(Point2D offset) {
187
                this.offset = offset;
188
        }
189

    
190
        public boolean isSuitableFor(Geometry geom) {
191
                return geom.getType() == Geometry.TYPES.POINT;
192
        }
193

    
194
        public int getOnePointRgb() {
195
                return color.getRGB();
196
        }
197

    
198
        public double getSize() {
199
                return size;
200
        }
201

    
202
        public void setSize(double size) {
203
                this.size = size;
204
        }
205

    
206
        public Color getColor() {
207
                return color;
208
        }
209

    
210
        public void setColor(Color color) {
211
                this.color = color;
212
        }
213

    
214
        public void getPixExtentPlus(Geometry geom, float[] distances, ViewPort viewPort, int dpi) {
215
                float cs = (float) getCartographicSize(viewPort, dpi, geom);
216
                distances[0] = cs;
217
                distances[1] = cs;
218
        }
219

    
220

    
221
        public void print(Graphics2D g, AffineTransform at, Geometry geom, PrintRequestAttributeSet properties) {
222
                double originalSize = getSize();
223
                double size=originalSize;
224
                // scale it to size
225
                PrintQuality pq = (PrintQuality) properties.get(PrintQuality.class);
226
                if (pq.equals(PrintQuality.NORMAL)){
227
                        size *= (double) 300/72;
228
                }else if (pq.equals(PrintQuality.HIGH)){
229
                        size *= (double) 600/72;
230
                }else if (pq.equals(PrintQuality.DRAFT)){
231
                        //        unitFactor *= 72; (which is the same than doing nothing)
232
                }
233
//                setSize(size);
234
                draw(g,at,geom,null);
235
//                setSize(originalSize);
236
        }
237

    
238
        public final IMask getMask() {
239
                return mask;
240
        }
241

    
242
        public void drawInsideRectangle(Graphics2D g, AffineTransform scaleInstance, Rectangle r, PrintRequestAttributeSet properties) throws SymbolDrawingException {
243
                try {
244
                        if (properties==null)
245
                                draw(g, scaleInstance, geomManager.createPoint(r.getCenterX(), r.getCenterY(), SUBTYPES.GEOM2D), null);
246
                        else{
247
                                double originalSize = getSize();
248
                                double size=originalSize;
249
                                PrintQuality pq = (PrintQuality) properties.get(PrintQuality.class);
250
                                if (pq.equals(PrintQuality.NORMAL)){
251
                                        size *= (double) 300/72;
252
                                }else if (pq.equals(PrintQuality.HIGH)){
253
                                        size *= (double) 600/72;
254
                                }else if (pq.equals(PrintQuality.DRAFT)){
255
                                        //        unitFactor *= 72; (which is the same than doing nothing)
256
                                }
257
                                setSize(size);
258
                                print(g, scaleInstance, geomManager.createPoint(r.getCenterX(), r.getCenterY(), SUBTYPES.GEOM2D), properties);
259
                                setSize(originalSize);
260
                        }
261

    
262

    
263

    
264
                } catch (CreateGeometryException e) {
265
                        throw new SymbolDrawingException(TYPES.POINT);
266
                }
267
        }
268

    
269
        public final void setMask(IMask mask) {
270
                this.mask = mask;
271
        }
272

    
273

    
274

    
275
        public void setCartographicSize(double cartographicSize, Geometry geom) {
276
                setSize(cartographicSize);
277
        }
278

    
279
        public double toCartographicSize(ViewPort viewPort, double dpi, Geometry geom) {
280
                double oldSize = getSize();
281
                setCartographicSize(getCartographicSize(
282
                                                                viewPort,
283
                                                                dpi,
284
                                                                geom),
285
                                                        geom);
286
                return oldSize;
287
        }
288

    
289
        public double getCartographicSize(ViewPort viewPort, double dpi, Geometry geom) {
290
                return CartographicSupportToolkit.
291
                                        getCartographicLength(this,
292
                                                                                  getSize(),
293
                                                                                  viewPort,
294
                                                                                  dpi);
295
        }
296

    
297
        private int unit;
298
        private int referenceSystem;
299

    
300
        public void setUnit(int unitIndex) {
301
                this.unit = unitIndex;
302
        }
303

    
304
        public int getUnit() {
305
                return this.unit;
306
        }
307

    
308
        public int getReferenceSystem() {
309
                return this.referenceSystem;
310
        }
311

    
312
        public void setReferenceSystem(int system) {
313
                this.referenceSystem = system;
314

    
315
        }
316
}