Statistics
| Revision:

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

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

    
119
import java.awt.Color;
120
import java.awt.Graphics2D;
121
import java.awt.Point;
122
import java.awt.Rectangle;
123
import java.awt.geom.AffineTransform;
124
import java.awt.geom.Point2D;
125

    
126
import javax.print.attribute.PrintRequestAttributeSet;
127
import javax.print.attribute.standard.PrintQuality;
128

    
129
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
130
import com.iver.cit.gvsig.fmap.MapContext;
131
import com.iver.cit.gvsig.fmap.ViewPort;
132
import com.iver.cit.gvsig.fmap.core.FPoint2D;
133
import com.iver.cit.gvsig.fmap.core.FShape;
134
import com.iver.cit.gvsig.fmap.core.IGeometry;
135
import com.iver.cit.gvsig.fmap.core.styles.IMask;
136

    
137

    
138
/**
139
 * Abstract class that any MARKER SYMBOL should extend.
140
 * @author  jaume dominguez faus - jaume.dominguez@iver.es
141
 */
142
public abstract class AbstractMarkerSymbol extends AbstractSymbol implements IMarkerSymbol {
143
        private Color color = Color.BLACK;
144
        private double rotation;
145
        private Point2D offset = new Point2D.Double();
146
        private double size;
147
        private IMask mask;
148
        transient private double cartographicScaleY = 1;
149
        transient private double cartographicScaleX = 1;
150

    
151
        public double getRotation() {
152
                return rotation;
153
        }
154

    
155
        public void setRotation(double r) {
156
                this.rotation = r;
157
        }
158

    
159
        public Point2D getOffset() {
160
                if (offset == null) {
161
                        offset = new Point();
162
                }
163
                return offset;
164
        }
165

    
166
        public void setOffset(Point2D offset) {
167
                this.offset = offset;
168
        }
169

    
170
        public boolean isSuitableFor(IGeometry geom) {
171
                return geom.getGeometryType() == FShape.POINT;
172
        }
173

    
174
        public int getOnePointRgb() {
175
                return color.getRGB();
176
        }
177

    
178
        public double getSize() {
179
                return size;
180
        }
181

    
182
        public void setSize(double size) {
183
                this.size = size;
184
        }
185

    
186
        public Color getColor() {
187
                return color;
188
        }
189

    
190
        public void setColor(Color color) {
191
                this.color = color;
192
        }
193

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

    
208
        public final IMask getMask() {
209
                return mask;
210
        }
211

    
212
        public void drawInsideRectangle(Graphics2D g, AffineTransform scaleInstance, Rectangle r) {
213
                draw(g, scaleInstance, new FPoint2D(r.getCenterX(), r.getCenterY()));
214
        }
215

    
216
        public final void setMask(IMask mask) {
217
                this.mask = mask;
218
        }
219

    
220
        public int getCartographicSize(ViewPort viewPort, double dpi, FShape shp) {
221
                return CartographicSupportToolkit.getCartographicLength(this, getSize(), viewPort, dpi);
222
//                double dpiScale = dpi/MapContext.getScreenDPI();
223
//                int unit = getUnit();
224
//                double sizeInPixel;
225
//                if (unit==-1) {
226
//                        sizeInPixel = getSize();
227
//                } else {
228
//                        double dist1Pixel = viewPort.getDist1pixel()*MapContext.CHANGEM[viewPort.getMapUnits()];
229
//                        double lineWidth = getSize()*MapContext.CHANGEM[unit];
230
//                        sizeInPixel = lineWidth/dist1Pixel;
231
//                }
232
//                return (int) (sizeInPixel*dpiScale);
233
        }
234
}