Statistics
| Revision:

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

History | View | Annotate | Download (7.27 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 9641 2007-01-10 16:42:08Z jaume $
45
* $Log$
46
* Revision 1.2  2007-01-10 16:39:41  jaume
47
* ISymbol now belongs to com.iver.cit.gvsig.fmap.core.symbols package
48
*
49
* Revision 1.1  2007/01/10 16:31:36  jaume
50
* *** empty log message ***
51
*
52
* Revision 1.10  2006/11/09 18:39:05  jaume
53
* *** empty log message ***
54
*
55
* Revision 1.9  2006/11/09 10:22:50  jaume
56
* *** empty log message ***
57
*
58
* Revision 1.8  2006/11/08 13:05:51  jaume
59
* *** empty log message ***
60
*
61
* Revision 1.7  2006/11/08 10:56:47  jaume
62
* *** empty log message ***
63
*
64
* Revision 1.6  2006/11/07 08:52:30  jaume
65
* *** empty log message ***
66
*
67
* Revision 1.5  2006/11/06 17:08:45  jaume
68
* *** empty log message ***
69
*
70
* Revision 1.4  2006/11/06 16:06:52  jaume
71
* *** empty log message ***
72
*
73
* Revision 1.3  2006/11/06 07:33:54  jaume
74
* javadoc, source style
75
*
76
* Revision 1.2  2006/10/31 16:16:34  jaume
77
* *** empty log message ***
78
*
79
* Revision 1.1  2006/10/30 19:30:35  jaume
80
* *** empty log message ***
81
*
82
*
83
*/
84
package com.iver.cit.gvsig.fmap.core.symbols;
85

    
86
import java.awt.BasicStroke;
87
import java.awt.Color;
88
import java.awt.Dimension;
89
import java.awt.Graphics2D;
90
import java.awt.Paint;
91
import java.awt.Rectangle;
92
import java.awt.RenderingHints;
93
import java.awt.Shape;
94
import java.awt.TexturePaint;
95
import java.awt.geom.AffineTransform;
96
import java.awt.geom.Point2D;
97
import java.awt.image.BufferedImage;
98
import java.util.ArrayList;
99

    
100
import com.iver.cit.gvsig.fmap.DriverException;
101
import com.iver.cit.gvsig.fmap.core.FShape;
102
import com.iver.cit.gvsig.fmap.core.SymbolFactory;
103
import com.iver.utiles.StringUtilities;
104
import com.iver.utiles.XMLEntity;
105

    
106
public class MarkerFillSymbol extends AbstractFillSymbol {
107
        private double rotation;
108
        private AbstractMarkerSymbol markerSymbol = new CharacterMarkerSymbol();
109
        private boolean grid = true;
110
        private double xOffset = 0;
111
        private double yOffset = 0;
112
        private double xSeparation = 20;
113
        private double ySeparation = 20;
114

    
115
        public boolean isGrid() {
116
                return grid;
117
        }
118

    
119
        public void setGrid(boolean grid) {
120
                this.grid = grid;
121
        }
122

    
123
        public AbstractMarkerSymbol getMarkerSymbol() {
124
                return markerSymbol;
125
        }
126

    
127
        public void setMarkerSymbol(AbstractMarkerSymbol markerSymbol) {
128
                this.markerSymbol = markerSymbol;
129
        }
130

    
131
        public double getRotation() {
132
                return rotation;
133
        }
134

    
135
        public void setRotation(double rotation) {
136
                this.rotation = rotation;
137
        }
138

    
139
        public double getXOffset() {
140
                return xOffset;
141
        }
142

    
143
        public void setXOffset(double offset) {
144
                xOffset = offset;
145
        }
146

    
147
        public double getXSeparation() {
148
                return xSeparation;
149
        }
150

    
151
        public void setXSeparation(double separation) {
152
                xSeparation = separation;
153
        }
154

    
155
        public double getYOffset() {
156
                return yOffset;
157
        }
158

    
159
        public void setYOffset(double offset) {
160
                yOffset = offset;
161
        }
162

    
163
        public double getYSeparation() {
164
                return ySeparation;
165
        }
166

    
167
        public void setYSeparation(double separation) {
168
                ySeparation = separation;
169
        }
170

    
171
        public ISymbol getSymbolForSelection() {
172
                // TODO Auto-generated method stub
173
                throw new Error("Not yet implemented!");
174
        }
175

    
176
        public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) {
177
                g.setColor(null);
178
                g.setStroke(new BasicStroke(0));
179
                int w=7;
180
                int h=7;
181

    
182
                BufferedImage bi = null;
183

    
184

    
185
                Rectangle rProv = new Rectangle();
186
                rProv.setFrame(0, 0,w,h);
187

    
188
                Paint resulPatternFill = null;
189
                bi= new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
190
                Graphics2D gAux = bi.createGraphics();
191
                markerSymbol.drawInsideRectangle(gAux, new AffineTransform(), rProv);
192
                resulPatternFill = new TexturePaint(bi,rProv);
193
                g.setColor(null);
194
                g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
195
                                RenderingHints.VALUE_ANTIALIAS_ON);
196

    
197
                g.setPaint(resulPatternFill);
198
                g.fill(shp);
199

    
200
        }
201

    
202
        public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform, Shape shp) {
203
                // TODO Auto-generated method stub
204
                throw new Error("Not yet implemented!");
205
        }
206

    
207
        public XMLEntity getXMLEntity() {
208
                XMLEntity xml = new XMLEntity();
209
                xml.putProperty("className", getClassName());
210
                // color
211
                xml.putProperty("color", StringUtilities.color2String(color));
212

    
213
                xml.putProperty("rotation", rotation);
214
                xml.putProperty("grid", grid);
215
                xml.putProperty("xOffset", xOffset);
216
                xml.putProperty("yOffset", yOffset);
217
                xml.putProperty("xSeparation", xSeparation);
218
                xml.putProperty("ySeparation", ySeparation);
219

    
220
                xml.addChild(markerSymbol.getXMLEntity());
221
                return xml;
222
        }
223

    
224
        public int getSymbolType() {
225
                // TODO Auto-generated method stub
226
                throw new Error("Not yet implemented!");
227
        }
228

    
229
        public void drawInsideRectangle(Graphics2D g, AffineTransform scaleInstance, Rectangle r) {
230
                if (isGrid()) {
231
                        // Use a TexturePaint
232
                        int w=7;
233
                        int h=7;
234

    
235
                        BufferedImage bi = null;
236

    
237
                        Rectangle rProv = new Rectangle();
238
                        rProv.setFrame(0, 0,w,h);
239

    
240
                        Paint resulPatternFill = null;
241
                        bi= new BufferedImage(w, h, BufferedImage.TYPE_INT_ARGB);
242
                        Graphics2D gAux = bi.createGraphics();
243
                        markerSymbol.drawInsideRectangle(gAux, new AffineTransform(), rProv);
244
                        resulPatternFill = new TexturePaint(bi,rProv);
245
                        g.setColor(null);
246
                        g.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
247
                                        RenderingHints.VALUE_ANTIALIAS_ON);
248

    
249
                        g.setPaint(resulPatternFill);
250
                        g.fill(r);
251
                        g.drawRect(0, 0, r.width, r.height);
252
                } else {
253
                        Point2D[] points = ramdonizePoints(r);
254
                        for (int i = 0; i < points.length; i++) {
255

    
256
                        }
257
                }
258
        }
259

    
260
        private Point2D[] ramdonizePoints(Rectangle r) {
261
                ArrayList points = new ArrayList();
262
                        throw new Error("Not yet implemented!");
263
//                return (Point2D[]) points.toArray(new Point2D[0]);
264
        }
265

    
266
        public String getClassName() {
267
                return getClass().getName();
268
        }
269

    
270
        public void setXMLEntity(XMLEntity xml) {
271
                rotation = xml.getDoubleProperty("rotation");
272
                grid = xml.getBooleanProperty("grid");
273
                xOffset = xml.getDoubleProperty("xOffset");
274
                yOffset = xml.getDoubleProperty("yOffset");
275
                xSeparation = xml.getDoubleProperty("xSeparation");
276
                ySeparation = xml.getDoubleProperty("ySeparation");
277
                markerSymbol = (AbstractMarkerSymbol) SymbolFactory.
278
                                                        createFromXML(xml.getChild(0), null);
279
        }
280

    
281
        public void setMarker(AbstractMarkerSymbol marker) {
282
                this.markerSymbol = marker;
283
        }
284

    
285
        public void print(Graphics2D g, AffineTransform at, FShape shape) throws DriverException {
286
                // TODO Implement it
287
                throw new Error("Not yet implemented!");
288

    
289
        }
290

    
291
}