Statistics
| Revision:

root / trunk / extensions / extGraph_predes / src / com / iver / cit / gvsig / fmap / core / symbols / MarkerFillSymbol.java @ 8516

History | View | Annotate | Download (5.88 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: MarkerFillSymbol.java 8516 2006-11-06 07:34:21Z jaume $
45
* $Log$
46
* Revision 1.3  2006-11-06 07:33:54  jaume
47
* javadoc, source style
48
*
49
* Revision 1.2  2006/10/31 16:16:34  jaume
50
* *** empty log message ***
51
*
52
* Revision 1.1  2006/10/30 19:30:35  jaume
53
* *** empty log message ***
54
*
55
*
56
*/
57
package com.iver.cit.gvsig.fmap.core.symbols;
58

    
59
import java.awt.Dimension;
60
import java.awt.Graphics2D;
61
import java.awt.Rectangle;
62
import java.awt.Shape;
63
import java.awt.TexturePaint;
64
import java.awt.geom.AffineTransform;
65
import java.awt.geom.Point2D;
66
import java.util.ArrayList;
67

    
68
import com.iver.cit.gvsig.fmap.core.FShape;
69
import com.iver.cit.gvsig.fmap.core.ISymbol;
70
import com.iver.utiles.XMLEntity;
71

    
72
public class MarkerFillSymbol extends AbstractFillSymbol {
73
        private double rotation;
74
        private AbstractMarkerSymbol markerSymbol;
75
        private boolean grid;
76
        private double xOffset = 0;
77
        private double yOffset = 0;
78
        private double xSeparation = 20;
79
        private double ySeparation = 20;
80
        private Dimension markerSize = new Dimension(7,7);
81
        private TexturePaint texture;
82

    
83
        public boolean isGrid() {
84
                return grid;
85
        }
86

    
87
        public void setGrid(boolean grid) {
88
                this.grid = grid;
89
        }
90

    
91
        public Dimension getMarkerSize() {
92
                return markerSize;
93
        }
94

    
95
        public void setMarkerSize(Dimension markerSize) {
96
                this.markerSize = markerSize;
97
        }
98

    
99
        public AbstractMarkerSymbol getMarkerSymbol() {
100
                return markerSymbol;
101
        }
102

    
103
        public void setMarkerSymbol(AbstractMarkerSymbol markerSymbol) {
104
                this.markerSymbol = markerSymbol;
105
        }
106

    
107
        public double getRotation() {
108
                return rotation;
109
        }
110

    
111
        public void setRotation(double rotation) {
112
                this.rotation = rotation;
113
        }
114
        
115
        public double getXOffset() {
116
                return xOffset;
117
        }
118

    
119
        public void setXOffset(double offset) {
120
                xOffset = offset;
121
        }
122

    
123
        public double getXSeparation() {
124
                return xSeparation;
125
        }
126

    
127
        public void setXSeparation(double separation) {
128
                xSeparation = separation;
129
        }
130

    
131
        public double getYOffset() {
132
                return yOffset;
133
        }
134

    
135
        public void setYOffset(double offset) {
136
                yOffset = offset;
137
        }
138

    
139
        public double getYSeparation() {
140
                return ySeparation;
141
        }
142

    
143
        public void setYSeparation(double separation) {
144
                ySeparation = separation;
145
        }
146

    
147
        public ISymbol getSymbolForSelection() {
148
                // TODO Auto-generated method stub
149
                throw new Error("Not yet implemented!");
150
        }
151

    
152
        public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) {
153
                throw new Error("Not yet implemented!");
154
        }
155

    
156
        public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform, Shape shp) {
157
                // TODO Auto-generated method stub
158
                throw new Error("Not yet implemented!");
159
        }
160

    
161
        public int getOnePointRgb() {
162
                // TODO Auto-generated method stub
163
                throw new Error("Not yet implemented!");
164
        }
165

    
166
        public XMLEntity getXMLEntity() {
167
                XMLEntity xml = new XMLEntity();
168
                xml.putProperty("className", getClassName());
169
                xml.putProperty("rotation", rotation);
170
                xml.putProperty("grid", grid);
171
                xml.putProperty("xOffset", xOffset);
172
                xml.putProperty("yOffset", yOffset);
173
                xml.putProperty("xSeparation", xSeparation);
174
                xml.putProperty("ySeparation", ySeparation);
175

    
176
                xml.addChild(markerSymbol.getXMLEntity());
177
                return xml;
178
        }
179

    
180
        public int getSymbolType() {
181
                // TODO Auto-generated method stub
182
                throw new Error("Not yet implemented!");
183
        }
184

    
185
        public void drawInsideRectangle(Graphics2D g, AffineTransform scaleInstance, Rectangle r) {
186
                Point2D[] points = calculatePoints(r);
187
                for (int i = 0; i < points.length; i++) {
188
                        Rectangle myRect = new Rectangle((int) points[i].getX(),
189
                                                                                          (int) points[i].getY(),
190
                                                                                          (int) markerSize.getHeight(),
191
                                                                                          (int) markerSize.getWidth());
192
                        markerSymbol.drawInsideRectangle(g, scaleInstance, myRect);
193
                }
194
        }
195

    
196
        private Point2D[] calculatePoints(Rectangle r) {
197
                ArrayList points = new ArrayList();
198
                if (grid) {
199
                        int rowCount = (int) ((r.getHeight()-yOffset)/ySeparation);
200
                        int colCount = (int) ((r.getWidth()-xOffset)/xSeparation);
201

    
202
                        double x = xOffset;
203
                        double y = r.getHeight()-yOffset;
204
                        for (int i = 0; i < rowCount; i++) {
205
                                for (int j = 0; j < colCount; j++) {
206
                                        points.add(new Point2D.Double(x, y));
207
                                        x += xSeparation;
208
                                }
209
                                x = xOffset;
210
                                y -= ySeparation;
211
                        }
212
                } else {
213
                        throw new Error("Not yet implemented!");
214
                }
215
                return (Point2D[]) points.toArray(new Point2D[0]);
216
        }
217

    
218
        public String getClassName() {
219
                return getClass().getName();
220
        }
221

    
222
        public void setXMLEntity(XMLEntity xml) {
223
                rotation = xml.getDoubleProperty("rotation");
224
                grid = xml.getBooleanProperty("grid");
225
                xOffset = xml.getDoubleProperty("xOffset");
226
                yOffset = xml.getDoubleProperty("yOffset");
227
                xSeparation = xml.getDoubleProperty("xSeparation");
228
                ySeparation = xml.getDoubleProperty("ySeparation");
229
                markerSymbol = (AbstractMarkerSymbol) SymbolFactory.
230
                                                        createFromXML(xml.getChild(0));
231
        }
232

    
233
        public void setMarker(AbstractMarkerSymbol marker) {
234
                this.markerSymbol = marker;
235
        }
236

    
237
}