Statistics
| Revision:

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

History | View | Annotate | Download (6.99 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 18621 2008-02-08 07:59:54Z jdominguez $
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 com.iver.cit.gvsig.fmap.core.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 com.hardcode.gdbms.driver.exceptions.ReadDriverException;
142
import com.iver.cit.gvsig.fmap.ViewPort;
143
import com.iver.cit.gvsig.fmap.core.CartographicSupportToolkit;
144
import com.iver.cit.gvsig.fmap.core.FPoint2D;
145
import com.iver.cit.gvsig.fmap.core.FShape;
146
import com.iver.cit.gvsig.fmap.core.IGeometry;
147
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
148
import com.iver.cit.gvsig.fmap.core.styles.IMask;
149

    
150

    
151
/**
152
 * Abstract class that any MARKER SYMBOL should extend.
153
 * @author  jaume dominguez faus - jaume.dominguez@iver.es
154
 */
155
public abstract class AbstractMarkerSymbol extends AbstractSymbol implements IMarkerSymbol {
156
        private Color color = SymbologyFactory.DefaultSymbolColor;
157
        private double rotation;
158
        private Point2D offset = new Point2D.Double();
159
        private double size;
160
        private IMask mask;
161

    
162
        public double getRotation() {
163
                return rotation;
164
        }
165

    
166
        public void setRotation(double r) {
167
                this.rotation = r;
168
        }
169

    
170
        public Point2D getOffset() {
171
                if (offset == null) {
172
                        offset = new Point();
173
                }
174
                return offset;
175
        }
176

    
177
        public void setOffset(Point2D offset) {
178
                this.offset = offset;
179
        }
180

    
181
        public boolean isSuitableFor(IGeometry geom) {
182
                return geom.getGeometryType() == FShape.POINT;
183
        }
184

    
185
        public int getOnePointRgb() {
186
                return color.getRGB();
187
        }
188

    
189
        public double getSize() {
190
                return size;
191
        }
192

    
193
        public void setSize(double size) {
194
                this.size = size;
195
        }
196

    
197
        public Color getColor() {
198
                return color;
199
        }
200

    
201
        public void setColor(Color color) {
202
                this.color = color;
203
        }
204
        
205
        public void getPixExtentPlus(FShape shp, float[] distances, ViewPort viewPort, int dpi) {
206
                float cs = (float) getCartographicSize(viewPort, dpi, shp);
207
                distances[0] = cs;
208
                distances[1] = cs;
209
        }
210

    
211

    
212
        public void print(Graphics2D g, AffineTransform at, FShape shape, PrintRequestAttributeSet properties) throws ReadDriverException {
213
                double originalSize = getSize();
214
                // scale it to size
215
                PrintQuality pq = (PrintQuality) properties.get(PrintQuality.class);
216
                if (pq.equals(PrintQuality.NORMAL)){
217
                        originalSize *= (double) 300/72;
218
                }else if (pq.equals(PrintQuality.HIGH)){
219
                        originalSize *= (double) 600/72;
220
                }else if (pq.equals(PrintQuality.DRAFT)){
221
                        //        unitFactor *= 72; (which is the same than doing nothing)
222
                }
223
                setSize(originalSize);
224
        }
225

    
226
        public final IMask getMask() {
227
                return mask;
228
        }
229

    
230
        public void drawInsideRectangle(Graphics2D g, AffineTransform scaleInstance, Rectangle r) throws SymbolDrawingException {
231
                draw(g, scaleInstance, new FPoint2D(r.getCenterX(), r.getCenterY()), null);
232
        }
233

    
234
        public final void setMask(IMask mask) {
235
                this.mask = mask;
236
        }
237

    
238

    
239

    
240
        public void setCartographicSize(double cartographicSize, FShape shp) {
241
                setSize(cartographicSize);
242
        }
243

    
244
        public double toCartographicSize(ViewPort viewPort, double dpi, FShape shp) {
245
                double oldSize = getSize();
246
                setCartographicSize(getCartographicSize(
247
                                                                viewPort,
248
                                                                dpi,
249
                                                                shp),
250
                                                        shp);
251
                return oldSize;
252
        }
253

    
254
        public double getCartographicSize(ViewPort viewPort, double dpi, FShape shp) {
255
                return CartographicSupportToolkit.
256
                                        getCartographicLength(this,
257
                                                                                  getSize(),
258
                                                                                  viewPort,
259
                                                                                  dpi);
260
        }
261

    
262
        private int unit;
263
        private int referenceSystem;
264

    
265
        public void setUnit(int unitIndex) {
266
                this.unit = unitIndex;
267
        }
268

    
269
        public int getUnit() {
270
                return this.unit;
271
        }
272

    
273
        public int getReferenceSystem() {
274
                return this.referenceSystem;
275
        }
276

    
277
        public void setReferenceSystem(int system) {
278
                this.referenceSystem = system;
279

    
280
        }
281
}