Statistics
| Revision:

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

History | View | Annotate | Download (6.16 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: DotDensityFillSymbol.java 10627 2007-03-06 17:10:21Z caballero $
45
* $Log$
46
* Revision 1.4  2007-03-06 17:08:54  caballero
47
* Exceptions
48
*
49
* Revision 1.3  2007/01/12 10:08:26  jaume
50
* *** empty log message ***
51
*
52
* Revision 1.2  2007/01/10 16:39:41  jaume
53
* ISymbol now belongs to com.iver.cit.gvsig.fmap.core.symbols package
54
*
55
* Revision 1.1  2007/01/10 16:31:36  jaume
56
* *** empty log message ***
57
*
58
* Revision 1.4  2006/11/14 11:10:27  jaume
59
* *** empty log message ***
60
*
61
* Revision 1.3  2006/11/13 09:15:23  jaume
62
* javadoc and some clean-up
63
*
64
* Revision 1.2  2006/11/09 18:39:05  jaume
65
* *** empty log message ***
66
*
67
* Revision 1.1  2006/11/09 10:22:50  jaume
68
* *** empty log message ***
69
*
70
*
71
*/
72
package com.iver.cit.gvsig.fmap.core.symbols;
73

    
74
import java.awt.Color;
75
import java.awt.Graphics2D;
76
import java.awt.Rectangle;
77
import java.awt.Shape;
78
import java.awt.geom.AffineTransform;
79
import java.util.Random;
80

    
81
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
82
import com.iver.cit.gvsig.fmap.core.FShape;
83
import com.iver.utiles.StringUtilities;
84
import com.iver.utiles.XMLEntity;
85

    
86
/**
87
 * <p>
88
 * Symbol that draws a set of points within a polygon. The amount of points is
89
 * defined by the field dotCount.<br>
90
 * </p>
91
 * <p>
92
 * This symbol only draws the points. The outline and the fill of the polygon is
93
 * handled by a SimpleFillSymboll where a DotDensityFillSymbol should be
94
 * embedded.<br>
95
 * </p>
96
 * @author jaume dominguez faus - jaume.dominguez@iver.es
97
 *
98
 */
99
public class DotDensityFillSymbol extends AbstractFillSymbol {
100
        private int  dotCount;
101
        private double dotSize;
102
        private double dotSpacing;
103
        private boolean fixedPlacement;
104

    
105
        public DotDensityFillSymbol() {
106
                super();
107
        }
108

    
109
        public ISymbol getSymbolForSelection() {
110
                return this; // the selection color is applied in the SimpleFillSymbol
111
        }
112

    
113
        public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) {
114
                int width = shp.getBounds().width;
115
                int height = shp.getBounds().height;
116
                int minx = shp.getBounds().x;
117
                int miny = shp.getBounds().y;
118
                Random random = new Random();
119
                g.setClip(shp);
120
                g.setColor(color);
121
                g.setBackground(null);
122
                int size = (int) dotSize;
123
                for (int i = 0; i < dotCount; i++) {
124
                        int x = (int) Math.abs(random.nextDouble() * width);
125
                        int y = (int) Math.abs(random.nextDouble() * height);
126
                        x = x + minx;
127
                        y = y + miny;
128
                        g.fillRect(x, y, size, size);
129
                }
130
                g.setClip(null);
131
        }
132

    
133
        public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform,
134
                        Shape shp) {
135
                // TODO Auto-generated method stub
136
                throw new Error("Not yet implemented!");
137
        }
138

    
139
        public XMLEntity getXMLEntity() {
140
                XMLEntity xml = new XMLEntity();
141
                xml.putProperty("className", getClassName());
142

    
143
                // color
144
                xml.putProperty("color", StringUtilities.color2String(color));
145

    
146
                // description
147
                xml.putProperty("desc", getDescription());
148

    
149
                // is shape visible
150
                xml.putProperty("isShapeVisible", isShapeVisible());
151

    
152
                // dot count
153
                xml.putProperty("dotCount", dotCount);
154

    
155
                // dot size
156
                xml.putProperty("dotSize", dotSize);
157

    
158
                // dot spacing
159
                xml.putProperty("dotSpacing", dotSpacing);
160

    
161
                return xml;
162
        }
163

    
164
        public int getSymbolType() {
165
                return FShape.POLYGON;
166
        }
167

    
168
        public void drawInsideRectangle(Graphics2D g,
169
                        AffineTransform scaleInstance, Rectangle r) {
170
                int x = r.x;
171
                int y = r.y;
172
                int width = r.width;
173
                int height= r.height;
174
                int size = height / 5;
175
                g.setColor(color);
176
                g.setBackground(null);
177
                g.fillRect((int) (x+height*0.2), (int) (y+width*0.2), size, size);
178
                g.fillRect((int) (x+height*0.25), (int) (y+width*0.7), size, size);
179
                g.fillRect((int) (x+height*0.65), (int) (y+width*0.5), size, size);
180
                g.fillRect((int) (x+height*0.8), (int) (y+width*0.1), size, size);
181
                g.fillRect((int) (x+height*0.8), (int) (y+width*0.8), size, size);
182
                g.fillRect((int) (x+height*0.9), (int) (y+width*0.3), size, size);
183
                g.fillRect((int) (x+height*1.1), (int) (y+width*0.8), size, size);
184
        }
185

    
186
        public String getClassName() {
187
                return getClass().getName();
188
        }
189

    
190
        public void setXMLEntity(XMLEntity xml) {
191
                // color
192
                color = StringUtilities.string2Color(xml.getStringProperty("color"));
193

    
194
                // description
195
                setDescription(xml.getStringProperty("desc"));
196

    
197
                // is shape visible
198
                setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
199

    
200
                // dot count
201
                dotCount = xml.getIntProperty("dotCount");
202

    
203
                // dot size
204
                dotSize = xml.getDoubleProperty("dotSize");
205

    
206
                // dot spacing
207
                dotSpacing = xml.getDoubleProperty("dotSpacing");
208
        }
209

    
210
        public int getDotCount() {
211
                return dotCount;
212
        }
213

    
214
        public void setDotCount(int dotCount) {
215
                this.dotCount = dotCount;
216
        }
217

    
218
        public double getDotSize() {
219
                return dotSize;
220
        }
221

    
222
        public void setDotSize(double dotSize) {
223
                this.dotSize = dotSize;
224
        }
225

    
226
        public double getDotSpacing() {
227
                return dotSpacing;
228
        }
229

    
230
        public void setDotSpacing(double dotSpacing) {
231
                this.dotSpacing = dotSpacing;
232
        }
233

    
234
        public Color getDotColor() {
235
                return color;
236
        }
237

    
238
        public void setDotColor(Color dotColor) {
239
                this.color = dotColor;
240
        }
241

    
242
        public void print(Graphics2D g, AffineTransform at, FShape shape) throws ReadDriverException {
243
                // TODO Implement it
244
                throw new Error("Not yet implemented!");
245

    
246
        }
247

    
248
}