Statistics
| Revision:

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

History | View | Annotate | Download (5.3 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 8687 2006-11-13 09:15:23Z jaume $
45
* $Log$
46
* Revision 1.3  2006-11-13 09:15:23  jaume
47
* javadoc and some clean-up
48
*
49
* Revision 1.2  2006/11/09 18:39:05  jaume
50
* *** empty log message ***
51
*
52
* Revision 1.1  2006/11/09 10:22:50  jaume
53
* *** empty log message ***
54
*
55
*
56
*/
57
package com.iver.cit.gvsig.fmap.core.symbols;
58

    
59
import java.awt.Color;
60
import java.awt.Graphics2D;
61
import java.awt.Point;
62
import java.awt.Rectangle;
63
import java.awt.Shape;
64
import java.awt.geom.AffineTransform;
65
import java.util.Random;
66

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

    
72
public class DotDensityFillSymbol extends AbstractFillSymbol {
73
        private int  dotCount;
74
        private double dotSize;
75
        private double dotSpacing;
76
        private boolean fixedPlacement;
77

    
78
        public DotDensityFillSymbol() {
79
                super();
80
                isShapeVisible = true;
81
        }
82

    
83
        public ISymbol getSymbolForSelection() {
84
                // TODO Auto-generated method stub
85
                throw new Error("Not yet implemented!");
86
        }
87

    
88
        public void draw(Graphics2D g, AffineTransform affineTransform, FShape shp) {
89
                int width = shp.getBounds().width;
90
                int height = shp.getBounds().height;
91
                int minx = shp.getBounds().x;
92
                int miny = shp.getBounds().y;
93
                Random random = new Random();
94
                g.setClip(shp);
95
                g.setColor(color);
96
                int size = (int) dotSize;
97
                for (int i = 0; i < dotCount; i++) {
98
                        int x = (int) Math.abs(random.nextDouble() * width);
99
                        int y = (int) Math.abs(random.nextDouble() * height);
100
                        x = x + minx;
101
                        y = y + miny;
102
                        g.fillRect(x, y, size, size);
103
                }
104
        }
105

    
106
        public int getPixExtentPlus(Graphics2D g, AffineTransform affineTransform,
107
                        Shape shp) {
108
                // TODO Auto-generated method stub
109
                throw new Error("Not yet implemented!");
110
        }
111

    
112
        public XMLEntity getXMLEntity() {
113
                XMLEntity xml = new XMLEntity();
114
                xml.putProperty("className", getClassName());
115

    
116
                // color
117
                xml.putProperty("color", StringUtilities.color2String(color));
118

    
119
                // description
120
                xml.putProperty("desc", desc);
121

    
122
                // is shape visible
123
                xml.putProperty("isShapeVisible", isShapeVisible);
124

    
125
                // dot count
126
                xml.putProperty("dotCount", dotCount);
127

    
128
                // dot size
129
                xml.putProperty("dotSize", dotSize);
130

    
131
                // dot spacing
132
                xml.putProperty("dotSpacing", dotSpacing);
133

    
134

    
135
                // layers
136
                if (layers!=null)
137
                        for (int i = 0; i < layers.length; i++) {
138
                                xml.addChild(layers[i].getXMLEntity());
139
                        }
140

    
141
                return xml;
142
        }
143

    
144
        public int getSymbolType() {
145
                return FShape.POLYGON;
146
        }
147

    
148
        public void drawInsideRectangle(Graphics2D g,
149
                        AffineTransform scaleInstance, Rectangle r) {
150
                int x = r.x;
151
                int y = r.y;
152
                int width = r.width;
153
                int height= r.height;
154
                int size = height / 15;
155
                g.setColor(color);
156
                g.fillRect((int) (x+height*0.2), (int) (y+width*0.2), size, size);
157
                g.fillRect((int) (x+height*0.25), (int) (y+width*0.7), size, size);
158
                g.fillRect((int) (x+height*0.65), (int) (y+width*0.5), size, size);
159
                g.fillRect((int) (x+height*0.8), (int) (y+width*0.1), size, size);
160
                g.fillRect((int) (x+height*0.8), (int) (y+width*0.8), size, size);
161
                g.fillRect((int) (x+height*0.9), (int) (y+width*0.3), size, size);
162
                g.fillRect((int) (x+height*1.1), (int) (y+width*0.8), size, size);
163
        }
164

    
165
        public String getClassName() {
166
                return getClass().getName();
167
        }
168

    
169
        public void setXMLEntity(XMLEntity xml) {
170
                // color
171
                color = StringUtilities.string2Color(xml.getStringProperty("color"));
172

    
173
                // description
174
                desc = xml.getStringProperty("desc");
175

    
176
                // is shape visible
177
                isShapeVisible = xml.getBooleanProperty("isShapeVisible");
178

    
179
                // dot count
180
                dotCount = xml.getIntProperty("dotCount");
181

    
182
                // dot size
183
                dotSize = xml.getDoubleProperty("dotSize");
184

    
185
                // dot spacing
186
                dotSpacing = xml.getDoubleProperty("dotSpacing");
187

    
188
        }
189

    
190
        public int getDotCount() {
191
                return dotCount;
192
        }
193

    
194
        public void setDotCount(int dotCount) {
195
                this.dotCount = dotCount;
196
        }
197

    
198
        public double getDotSize() {
199
                return dotSize;
200
        }
201

    
202
        public void setDotSize(double dotSize) {
203
                this.dotSize = dotSize;
204
        }
205

    
206
        public double getDotSpacing() {
207
                return dotSpacing;
208
        }
209

    
210
        public void setDotSpacing(double dotSpacing) {
211
                this.dotSpacing = dotSpacing;
212
        }
213

    
214
        public Color getDotColor() {
215
                return color;
216
        }
217

    
218
        public void setDotColor(Color dotColor) {
219
                this.color = dotColor;
220
        }
221

    
222
}