Statistics
| Revision:

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

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

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

    
135
import javax.print.attribute.PrintRequestAttributeSet;
136
import javax.print.attribute.standard.PrintQuality;
137

    
138
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
139
import com.iver.cit.gvsig.fmap.ViewPort;
140
import com.iver.cit.gvsig.fmap.core.CartographicSupportToolkit;
141
import com.iver.cit.gvsig.fmap.core.FPoint2D;
142
import com.iver.cit.gvsig.fmap.core.FShape;
143
import com.iver.cit.gvsig.fmap.core.IGeometry;
144
import com.iver.cit.gvsig.fmap.core.styles.IMask;
145

    
146

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

    
158
        public double getRotation() {
159
                return rotation;
160
        }
161

    
162
        public void setRotation(double r) {
163
                this.rotation = r;
164
        }
165

    
166
        public Point2D getOffset() {
167
                if (offset == null) {
168
                        offset = new Point();
169
                }
170
                return offset;
171
        }
172

    
173
        public void setOffset(Point2D offset) {
174
                this.offset = offset;
175
        }
176

    
177
        public boolean isSuitableFor(IGeometry geom) {
178
                return geom.getGeometryType() == FShape.POINT;
179
        }
180

    
181
        public int getOnePointRgb() {
182
                return color.getRGB();
183
        }
184

    
185
        public double getSize() {
186
                return size;
187
        }
188

    
189
        public void setSize(double size) {
190
                this.size = size;
191
        }
192

    
193
        public Color getColor() {
194
                return color;
195
        }
196

    
197
        public void setColor(Color color) {
198
                this.color = color;
199
        }
200

    
201
        public void print(Graphics2D g, AffineTransform at, FShape shape, PrintRequestAttributeSet properties) throws ReadDriverException {
202
                double originalSize = getSize();
203
                // scale it to size
204
                PrintQuality pq = (PrintQuality) properties.get(PrintQuality.class);
205
                if (pq.equals(PrintQuality.NORMAL)){
206
                        originalSize *= (double) 300/72;
207
                }else if (pq.equals(PrintQuality.HIGH)){
208
                        originalSize *= (double) 600/72;
209
                }else if (pq.equals(PrintQuality.DRAFT)){
210
                        //        unitFactor *= 72; (which is the same than doing nothing)
211
                }
212
                setSize(originalSize);
213
        }
214

    
215
        public final IMask getMask() {
216
                return mask;
217
        }
218

    
219
        public void drawInsideRectangle(Graphics2D g, AffineTransform scaleInstance, Rectangle r) {
220
                draw(g, scaleInstance, new FPoint2D(r.getCenterX(), r.getCenterY()));
221
        }
222

    
223
        public final void setMask(IMask mask) {
224
                this.mask = mask;
225
        }
226

    
227

    
228

    
229
        public void setCartographicSize(double cartographicSize, FShape shp) {
230
                setSize(cartographicSize);
231
        }
232

    
233
        public double toCartographicSize(ViewPort viewPort, double dpi, FShape shp) {
234
                double oldSize = getSize();
235
                setCartographicSize(getCartographicSize(
236
                                                                viewPort,
237
                                                                dpi,
238
                                                                shp),
239
                                                        shp);
240
                return oldSize;
241
        }
242

    
243
        public double getCartographicSize(ViewPort viewPort, double dpi, FShape shp) {
244
                return CartographicSupportToolkit.
245
                                        getCartographicLength(this,
246
                                                                                  getSize(),
247
                                                                                  viewPort,
248
                                                                                  dpi);
249
        }
250

    
251
        private int unit;
252
        private int referenceSystem;
253

    
254
        public void setUnit(int unitIndex) {
255
                this.unit = unitIndex;
256
        }
257

    
258
        public int getUnit() {
259
                return this.unit;
260
        }
261

    
262
        public int getReferenceSystem() {
263
                return this.referenceSystem;
264
        }
265

    
266
        public void setReferenceSystem(int system) {
267
                this.referenceSystem = system;
268

    
269
        }
270
}