svn-gvsig-desktop / branches / Fmap_GisPlanet / libraries / libFMap / src / com / iver / cit / gvsig / fmap / rendering / styling / SymbolPreviewDrawer.java @ 1841
History | View | Annotate | Download (8.5 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 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 |
package com.iver.cit.gvsig.fmap.rendering.styling; |
42 |
|
43 |
import com.iver.cit.gvsig.fmap.ViewPort; |
44 |
import com.iver.cit.gvsig.fmap.core.FPoint2D; |
45 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
46 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
47 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
48 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
49 |
import com.iver.cit.gvsig.fmap.rendering.Legend; |
50 |
|
51 |
import org.geotools.renderer.style.Style2D; |
52 |
|
53 |
import java.awt.Dimension; |
54 |
import java.awt.Graphics2D; |
55 |
import java.awt.Label; |
56 |
import java.awt.Rectangle; |
57 |
import java.awt.geom.Point2D; |
58 |
|
59 |
import javax.swing.JFrame; |
60 |
import javax.swing.JPanel; |
61 |
|
62 |
|
63 |
/**
|
64 |
* DOCUMENT ME!
|
65 |
*
|
66 |
* @author Vicente Caballero Navarro
|
67 |
*/
|
68 |
public class SymbolPreviewDrawer { |
69 |
private static IGeometry gPoint; |
70 |
private static IGeometry gLine; |
71 |
private static IGeometry gPolygon; |
72 |
private static IGeometry gText; |
73 |
FStyle2D fs2d; |
74 |
|
75 |
/**
|
76 |
* Crea un nuevo SymbolPreviewDrawer.
|
77 |
*/
|
78 |
public SymbolPreviewDrawer() {
|
79 |
} |
80 |
|
81 |
/**
|
82 |
* Crea un nuevo PreviousSymbolDrawer.
|
83 |
*
|
84 |
* @param f DOCUMENT ME!
|
85 |
*/
|
86 |
public SymbolPreviewDrawer(FStyle2D f) {
|
87 |
fs2d = f; |
88 |
} |
89 |
|
90 |
/**
|
91 |
* DOCUMENT ME!
|
92 |
*
|
93 |
* @param g DOCUMENT ME!
|
94 |
* @param rec DOCUMENT ME!
|
95 |
* @param type DOCUMENT ME!
|
96 |
*/
|
97 |
public void draw(Graphics2D g, Rectangle rec, int type) { |
98 |
boolean point = false; |
99 |
boolean line = false; |
100 |
boolean polygon = false; |
101 |
boolean text = false; |
102 |
int all = 0; |
103 |
|
104 |
System.out.println("type = " + type); |
105 |
|
106 |
if ((type % 2) > 0) { //POINT |
107 |
point = true;
|
108 |
all++; |
109 |
} |
110 |
|
111 |
type = type / 2;
|
112 |
|
113 |
if ((type % 2) > 0) { //LINE |
114 |
line = true;
|
115 |
all++; |
116 |
} |
117 |
|
118 |
type = type / 2;
|
119 |
|
120 |
if ((type % 2) > 0) { //POLYGON |
121 |
polygon = true;
|
122 |
all++; |
123 |
} |
124 |
|
125 |
type = type / 2;
|
126 |
|
127 |
if ((type % 2) > 0) { //TEXT |
128 |
text = true;
|
129 |
all++; |
130 |
} |
131 |
|
132 |
double x = rec.getX();
|
133 |
double y = rec.getY();
|
134 |
double w = rec.getWidth();
|
135 |
double h = rec.getHeight();
|
136 |
x = x + (w / 1.3);
|
137 |
y = y + (h / 4);
|
138 |
w = w / 5;
|
139 |
h = h / 2;
|
140 |
|
141 |
double part = w / all;
|
142 |
|
143 |
Rectangle[] symbolRect = new Rectangle[all]; |
144 |
|
145 |
for (int i = 0; i < all; i++) { |
146 |
symbolRect[i] = new Rectangle((int) (x + (part * i)), (int) y, |
147 |
(int) (part), (int) h); |
148 |
} |
149 |
|
150 |
int num = 0; |
151 |
|
152 |
if (point) {
|
153 |
drawPoint(g, symbolRect[num++]); |
154 |
} |
155 |
|
156 |
if (line) {
|
157 |
drawLine(g, symbolRect[num++]); |
158 |
} |
159 |
|
160 |
if (polygon) {
|
161 |
drawPolygon(g, symbolRect[num++]); |
162 |
} |
163 |
|
164 |
if (text) {
|
165 |
drawText(g, symbolRect[num++]); |
166 |
} |
167 |
} |
168 |
|
169 |
/**
|
170 |
* DOCUMENT ME!
|
171 |
*
|
172 |
* @param rec DOCUMENT ME!
|
173 |
*/
|
174 |
private void initPoint(Rectangle rec) { |
175 |
gPoint = ShapeFactory.createPoint2D(rec.getCenterX(), rec.getCenterY()); |
176 |
} |
177 |
|
178 |
/**
|
179 |
* DOCUMENT ME!
|
180 |
*
|
181 |
* @param rec DOCUMENT ME!
|
182 |
*/
|
183 |
private void initLine(Rectangle rec) { |
184 |
Point2D[] points = new Point2D.Double[4]; |
185 |
int x = (int) rec.getX(); |
186 |
int y = (int) rec.getY(); |
187 |
int height = (int) rec.getHeight(); |
188 |
int width = (int) rec.getWidth(); |
189 |
points[0] = new Point2D.Double(x, y + (height / 2)); |
190 |
points[1] = new Point2D.Double(x + (width / 3), y + height); |
191 |
points[2] = new Point2D.Double(x + ((2 * width) / 3), y); |
192 |
points[3] = new Point2D.Double(x + width, y + (height / 2)); |
193 |
|
194 |
int[] parts = new int[1]; |
195 |
parts[0] = 0; |
196 |
|
197 |
GeneralPathX gPX = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
|
198 |
points.length); |
199 |
initGeneralPathX(gPX, points, parts); |
200 |
gLine = ShapeFactory.createPolyline2D(gPX); |
201 |
} |
202 |
|
203 |
/**
|
204 |
* DOCUMENT ME!
|
205 |
*
|
206 |
* @param rec DOCUMENT ME!
|
207 |
*/
|
208 |
private void initPolygon(Rectangle rec) { |
209 |
Point2D[] points = new Point2D.Double[5]; |
210 |
int x = (int) rec.getX(); |
211 |
int y = (int) rec.getY(); |
212 |
int height = (int) rec.getHeight(); |
213 |
int width = (int) rec.getWidth(); |
214 |
|
215 |
points[0] = new Point2D.Double(x, y); |
216 |
points[1] = new Point2D.Double(rec.getMaxX(), y); |
217 |
points[2] = new Point2D.Double(rec.getMaxX(), rec.getMaxY()); |
218 |
points[3] = new Point2D.Double(x, rec.getMaxY()); |
219 |
points[4] = new Point2D.Double(x, y); |
220 |
|
221 |
int[] parts = new int[1]; |
222 |
parts[0] = 0; |
223 |
|
224 |
GeneralPathX gPX = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD,
|
225 |
points.length); |
226 |
initGeneralPathX(gPX, points, parts); |
227 |
gPolygon = ShapeFactory.createPolygon2D(gPX); |
228 |
} |
229 |
|
230 |
/**
|
231 |
* DOCUMENT ME!
|
232 |
*
|
233 |
* @param rec DOCUMENT ME!
|
234 |
*/
|
235 |
private void initText(Rectangle rec) { |
236 |
// TODO:
|
237 |
|
238 |
} |
239 |
|
240 |
/**
|
241 |
* DOCUMENT ME!
|
242 |
*
|
243 |
* @param gPX DOCUMENT ME!
|
244 |
* @param po DOCUMENT ME!
|
245 |
* @param pa DOCUMENT ME!
|
246 |
*/
|
247 |
private void initGeneralPathX(GeneralPathX gPX, Point2D[] po, int[] pa) { |
248 |
int j = 0; |
249 |
|
250 |
for (int i = 0; i < po.length; i++) { |
251 |
if (i == pa[j]) {
|
252 |
gPX.moveTo(po[i].getX(), po[i].getY()); |
253 |
|
254 |
if (j < (pa.length - 1)) { |
255 |
j++; |
256 |
} |
257 |
} else {
|
258 |
gPX.lineTo(po[i].getX(), po[i].getY()); |
259 |
} |
260 |
} |
261 |
} |
262 |
|
263 |
/**
|
264 |
* DOCUMENT ME!
|
265 |
*
|
266 |
* @param g DOCUMENT ME!
|
267 |
* @param rect DOCUMENT ME!
|
268 |
*/
|
269 |
public void drawPoint(Graphics2D g, Rectangle rect) { |
270 |
initPoint(rect); |
271 |
|
272 |
ViewPort vp = new ViewPort(null); |
273 |
vp.setOffset(new Point2D.Double(rect.getX(), rect.getY())); |
274 |
vp.setImageSize(new Dimension((int) rect.getWidth(), |
275 |
(int) rect.getHeight()));
|
276 |
vp.setExtent(rect); |
277 |
gPoint.draw(g, vp, fs2d); |
278 |
} |
279 |
|
280 |
/**
|
281 |
* DOCUMENT ME!
|
282 |
*
|
283 |
* @param g DOCUMENT ME!
|
284 |
* @param rect DOCUMENT ME!
|
285 |
*/
|
286 |
public void drawLine(Graphics2D g, Rectangle rect) { |
287 |
initLine(rect); |
288 |
|
289 |
ViewPort vp = new ViewPort(null); |
290 |
vp.setOffset(new Point2D.Double(rect.getX(), rect.getY())); |
291 |
vp.setImageSize(new Dimension((int) rect.getWidth(), |
292 |
(int) rect.getHeight()));
|
293 |
vp.setExtent(rect); |
294 |
gLine.draw(g, vp, fs2d); |
295 |
} |
296 |
|
297 |
/**
|
298 |
* DOCUMENT ME!
|
299 |
*
|
300 |
* @param g DOCUMENT ME!
|
301 |
* @param rect DOCUMENT ME!
|
302 |
*/
|
303 |
public void drawPolygon(Graphics2D g, Rectangle rect) { |
304 |
initPolygon(rect); |
305 |
|
306 |
ViewPort vp = new ViewPort(null); |
307 |
vp.setOffset(new Point2D.Double(rect.getX(), rect.getY())); |
308 |
vp.setImageSize(new Dimension((int) rect.getWidth(), |
309 |
(int) rect.getHeight()));
|
310 |
vp.setExtent(rect); |
311 |
gPolygon.draw(g, vp, fs2d); |
312 |
} |
313 |
|
314 |
/**
|
315 |
* DOCUMENT ME!
|
316 |
*
|
317 |
* @param g DOCUMENT ME!
|
318 |
* @param rect DOCUMENT ME!
|
319 |
*/
|
320 |
public void drawText(Graphics2D g, Rectangle rect) { |
321 |
initText(rect); |
322 |
|
323 |
ViewPort vp = new ViewPort(null); |
324 |
vp.setOffset(new Point2D.Double(rect.getX(), rect.getY())); |
325 |
vp.setImageSize(new Dimension((int) rect.getWidth(), |
326 |
(int) rect.getHeight()));
|
327 |
vp.setExtent(rect); |
328 |
gText.draw(g, vp, fs2d); |
329 |
} |
330 |
|
331 |
/**
|
332 |
* DOCUMENT ME!
|
333 |
*
|
334 |
* @param fs2d DOCUMENT ME!
|
335 |
*/
|
336 |
public void setSymbol(FStyle2D fs2d) { |
337 |
this.fs2d = fs2d;
|
338 |
} |
339 |
} |