Statistics
| Revision:

svn-gvsig-desktop / branches / simbologia / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / symbols / DotDensityFillSymbol.java @ 10450

History | View | Annotate | Download (6.97 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 10450 2007-02-21 16:09:35Z jaume $
45
* $Log$
46
* Revision 1.3.2.4  2007-02-21 16:09:02  jaume
47
* *** empty log message ***
48
*
49
* Revision 1.3.2.3  2007/02/16 10:54:12  jaume
50
* multilayer splitted to multilayerline, multilayermarker,and  multilayerfill
51
*
52
* Revision 1.3.2.2  2007/02/15 16:23:44  jaume
53
* *** empty log message ***
54
*
55
* Revision 1.3.2.1  2007/02/09 07:47:04  jaume
56
* Isymbol moved
57
*
58
* Revision 1.3  2007/01/12 10:08:26  jaume
59
* *** empty log message ***
60
*
61
* Revision 1.2  2007/01/10 16:39:41  jaume
62
* ISymbol now belongs to com.iver.cit.gvsig.fmap.core.symbols package
63
*
64
* Revision 1.1  2007/01/10 16:31:36  jaume
65
* *** empty log message ***
66
*
67
* Revision 1.4  2006/11/14 11:10:27  jaume
68
* *** empty log message ***
69
*
70
* Revision 1.3  2006/11/13 09:15:23  jaume
71
* javadoc and some clean-up
72
*
73
* Revision 1.2  2006/11/09 18:39:05  jaume
74
* *** empty log message ***
75
*
76
* Revision 1.1  2006/11/09 10:22:50  jaume
77
* *** empty log message ***
78
*
79
*
80
*/
81
package com.iver.cit.gvsig.fmap.core.symbols;
82

    
83
import java.awt.Color;
84
import java.awt.Graphics2D;
85
import java.awt.Point;
86
import java.awt.Rectangle;
87
import java.awt.Shape;
88
import java.awt.geom.AffineTransform;
89
import java.util.Random;
90

    
91
import com.iver.cit.gvsig.fmap.DriverException;
92
import com.iver.cit.gvsig.fmap.core.FShape;
93
import com.iver.utiles.StringUtilities;
94
import com.iver.utiles.XMLEntity;
95

    
96
/**
97
 * <p> Symbol that draws a set of points within a polygon. The amount of points is defined by the field dotCount.<br> </p> <p> This symbol only draws the points. The outline and the fill of the polygon is handled by a SimpleFillSymboll where a DotDensityFillSymbol should be embedded.<br> </p>
98
 * @author  jaume dominguez faus - jaume.dominguez@iver.es
99
 */
100
public class DotDensityFillSymbol extends AbstractFillSymbol {
101
        /**
102
         * @uml.property  name="dotCount"
103
         */
104
        private int  dotCount;
105
        /**
106
         * @uml.property  name="dotSize"
107
         */
108
        private double dotSize;
109
        /**
110
         * @uml.property  name="dotSpacing"
111
         */
112
        private double dotSpacing;
113
        private Color dotColor;
114
        private boolean fixedPlacement;
115

    
116
        public DotDensityFillSymbol() {
117
                super();
118
        }
119

    
120
        public ISymbol getSymbolForSelection() {
121
                return this; // the selection color is applied in the SimpleFillSymbol
122
        }
123

    
124
        public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) {
125
                int width = shp.getBounds().width;
126
                int height = shp.getBounds().height;
127
                int minx = shp.getBounds().x;
128
                int miny = shp.getBounds().y;
129
                Random random = new Random();
130
                g.setClip(shp);
131
                g.setColor(getDotColor());
132
                g.setBackground(null);
133
                int size = (int) dotSize;
134
                for (int i = 0; i < dotCount; i++) {
135
                        int x = (int) Math.abs(random.nextDouble() * width);
136
                        int y = (int) Math.abs(random.nextDouble() * height);
137
                        x = x + minx;
138
                        y = y + miny;
139
                        g.fillRect(x, y, size, size);
140
                }
141
                g.setClip(null);
142
        }
143

    
144
        public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform,
145
                        Shape shp) {
146
                // TODO Auto-generated method stub
147
                throw new Error("Not yet implemented!");
148
        }
149

    
150
        public XMLEntity getXMLEntity() {
151
                XMLEntity xml = new XMLEntity();
152
                xml.putProperty("className", getClassName());
153

    
154
                // color
155
                xml.putProperty("color", StringUtilities.color2String(getDotColor()));
156

    
157
                // description
158
                xml.putProperty("desc", getDescription());
159

    
160
                // is shape visible
161
                xml.putProperty("isShapeVisible", isShapeVisible());
162

    
163
                // dot count
164
                xml.putProperty("dotCount", dotCount);
165

    
166
                // dot size
167
                xml.putProperty("dotSize", dotSize);
168

    
169
                // dot spacing
170
                xml.putProperty("dotSpacing", dotSpacing);
171

    
172
                return xml;
173
        }
174

    
175
        public int getSymbolType() {
176
                return FShape.POLYGON;
177
        }
178

    
179
        public void drawInsideRectangle(Graphics2D g,
180
                        AffineTransform scaleInstance, Rectangle r) {
181
                int x = r.x;
182
                int y = r.y;
183
                int width = r.width;
184
                int height= r.height;
185
                int size = height / 5;
186
                g.setColor(getDotColor());
187
                g.setBackground(null);
188
                g.fillRect((int) (x+height*0.2), (int) (y+width*0.2), size, size);
189
                g.fillRect((int) (x+height*0.25), (int) (y+width*0.7), size, size);
190
                g.fillRect((int) (x+height*0.65), (int) (y+width*0.5), size, size);
191
                g.fillRect((int) (x+height*0.8), (int) (y+width*0.1), size, size);
192
                g.fillRect((int) (x+height*0.8), (int) (y+width*0.8), size, size);
193
                g.fillRect((int) (x+height*0.9), (int) (y+width*0.3), size, size);
194
                g.fillRect((int) (x+height*1.1), (int) (y+width*0.8), size, size);
195
        }
196

    
197
        public String getClassName() {
198
                return getClass().getName();
199
        }
200

    
201
        public void setXMLEntity(XMLEntity xml) {
202
                // color
203
                setDotColor(StringUtilities.string2Color(xml.getStringProperty("color")));
204

    
205
                // description
206
                setDescription(xml.getStringProperty("desc"));
207

    
208
                // is shape visible
209
                setIsShapeVisible(xml.getBooleanProperty("isShapeVisible"));
210

    
211
                // dot count
212
                dotCount = xml.getIntProperty("dotCount");
213

    
214
                // dot size
215
                dotSize = xml.getDoubleProperty("dotSize");
216

    
217
                // dot spacing
218
                dotSpacing = xml.getDoubleProperty("dotSpacing");
219
        }
220

    
221
        /**
222
         * @return
223
         * @uml.property  name="dotCount"
224
         */
225
        public int getDotCount() {
226
                return dotCount;
227
        }
228

    
229
        /**
230
         * @param dotCount
231
         * @uml.property  name="dotCount"
232
         */
233
        public void setDotCount(int dotCount) {
234
                this.dotCount = dotCount;
235
        }
236

    
237
        /**
238
         * @return
239
         * @uml.property  name="dotSize"
240
         */
241
        public double getDotSize() {
242
                return dotSize;
243
        }
244

    
245
        /**
246
         * @param dotSize
247
         * @uml.property  name="dotSize"
248
         */
249
        public void setDotSize(double dotSize) {
250
                this.dotSize = dotSize;
251
        }
252

    
253
        /**
254
         * @return
255
         * @uml.property  name="dotSpacing"
256
         */
257
        public double getDotSpacing() {
258
                return dotSpacing;
259
        }
260

    
261
        /**
262
         * @param dotSpacing
263
         * @uml.property  name="dotSpacing"
264
         */
265
        public void setDotSpacing(double dotSpacing) {
266
                this.dotSpacing = dotSpacing;
267
        }
268

    
269
        public Color getDotColor() {
270
                return dotColor;
271
        }
272

    
273
        public void setDotColor(Color dotColor) {
274
                this.dotColor = dotColor;
275
        }
276

    
277
        public void print(Graphics2D g, AffineTransform at, FShape shape) throws DriverException {
278
                // TODO Implement it
279
                throw new Error("Not yet implemented!");
280

    
281
        }
282

    
283
        
284
}