root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / FFrameLegend.java @ 7304
History | View | Annotate | Download (29.2 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.gui.layout.fframes; |
42 |
|
43 |
import java.awt.Color; |
44 |
import java.awt.Font; |
45 |
import java.awt.Graphics2D; |
46 |
import java.awt.Rectangle; |
47 |
import java.awt.geom.AffineTransform; |
48 |
import java.awt.geom.Rectangle2D; |
49 |
import java.awt.image.BufferedImage; |
50 |
import java.util.ArrayList; |
51 |
|
52 |
import com.iver.andami.PluginServices; |
53 |
import com.iver.cit.gvsig.fmap.DriverException; |
54 |
import com.iver.cit.gvsig.fmap.core.v02.FGraphicUtilities; |
55 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
56 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
57 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
58 |
import com.iver.cit.gvsig.fmap.layers.FLyrAnnotation; |
59 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
60 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable; |
61 |
import com.iver.cit.gvsig.fmap.rendering.ClassifiedLegendInfo; |
62 |
import com.iver.cit.gvsig.gui.layout.Layout; |
63 |
import com.iver.cit.gvsig.project.documents.exceptions.SaveException; |
64 |
import com.iver.cit.gvsig.project.documents.layout.FLayoutUtilities; |
65 |
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame; |
66 |
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameViewDependence; |
67 |
import com.iver.utiles.XMLEntity; |
68 |
|
69 |
|
70 |
/**
|
71 |
* FFrame para introducir una leyenda en el Layout.
|
72 |
*
|
73 |
* @author Vicente Caballero Navarro
|
74 |
*/
|
75 |
public class FFrameLegend extends FFrame implements IFFrameViewDependence { |
76 |
private static final int PRESENTACION = 0; |
77 |
private static final int BORRADOR = 1; |
78 |
private int m_quality = 0; |
79 |
private int m_viewing = 0; |
80 |
private Font m_f = new Font("SansSerif", Font.PLAIN, 9); |
81 |
private FFrameView fframeview = null; |
82 |
private int m_max; |
83 |
private int m_numLayers; |
84 |
private FLayers layers = null; |
85 |
private int dependenceIndex = -1; |
86 |
private ArrayList nameLayers=new ArrayList(); |
87 |
private ArrayList areVisible=new ArrayList(); |
88 |
|
89 |
/**
|
90 |
* Rellena la calidad que se quiere aplicar.
|
91 |
*
|
92 |
* @param q entero que representa la calidad a aplicar.
|
93 |
*/
|
94 |
public void setQuality(int q) { |
95 |
m_quality = q; |
96 |
} |
97 |
|
98 |
/**
|
99 |
* Devuelve un entero que representa la calidad que est? seleccionada.
|
100 |
*
|
101 |
* @return tipo de calidad selccionada.
|
102 |
*/
|
103 |
public int getQuality() { |
104 |
return m_quality;
|
105 |
} |
106 |
|
107 |
/**
|
108 |
* Devuelve un entero que representa la forma en que se actualiza la vista.
|
109 |
*
|
110 |
* @return forma que se actualiza la vista.
|
111 |
*/
|
112 |
public int getViewing() { |
113 |
return m_viewing;
|
114 |
} |
115 |
|
116 |
/**
|
117 |
* Inserta una FFrameView de donde se obtiene la informaci?n de las capas
|
118 |
* para generar la leyenda.
|
119 |
*
|
120 |
* @param f FFrameView para obtener los nombres de las capas.
|
121 |
*/
|
122 |
public void setFFrameDependence(IFFrame f) { |
123 |
fframeview = (FFrameView) f; |
124 |
} |
125 |
|
126 |
/**
|
127 |
* Devuelve el FFrameView utilizado para obtener la leyenda.
|
128 |
*
|
129 |
* @return FFrameView utilizado.
|
130 |
*/
|
131 |
public IFFrame getFFrameDependence() {
|
132 |
return fframeview;
|
133 |
} |
134 |
|
135 |
/**
|
136 |
* Rellena la forma de actualizar la vista.
|
137 |
*
|
138 |
* @param v entero que representa la forma de actualizar la vista.
|
139 |
*/
|
140 |
public void setViewing(int v) { |
141 |
m_viewing = v; |
142 |
} |
143 |
|
144 |
/**
|
145 |
* M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
|
146 |
* la transformada afin que se debe de aplicar y el rect?ngulo que se debe
|
147 |
* de dibujar.
|
148 |
*
|
149 |
* @param g Graphics
|
150 |
* @param at Transformada afin.
|
151 |
* @param rv rect?ngulo sobre el que hacer un clip.
|
152 |
* @param imgBase Imagen para acelerar el dibujado.
|
153 |
*
|
154 |
* @throws DriverException
|
155 |
*/
|
156 |
public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv, |
157 |
BufferedImage imgBase) throws DriverException { |
158 |
Rectangle2D.Double re = getBoundingBox(at);
|
159 |
g.rotate(Math.toRadians(getRotation()), re.x + (re.width / 2), |
160 |
re.y + (re.height / 2));
|
161 |
|
162 |
if ((fframeview != null) && (fframeview.getMapContext() != null)) { |
163 |
layers = fframeview.getMapContext().getLayers(); |
164 |
} |
165 |
|
166 |
m_max = 0;
|
167 |
m_numLayers = 0;
|
168 |
|
169 |
if (intersects(rv, re)) {
|
170 |
if (layers == null) { //Si no se ha seleccionado ninguna vista para crear la leyenda. |
171 |
drawEmpty(g); |
172 |
} else if ((rv == null) || (getQuality() == PRESENTACION)) { |
173 |
m_numLayers = getSizeNum(layers); |
174 |
|
175 |
double h = re.getHeight() / m_numLayers;
|
176 |
int[] n = new int[1]; |
177 |
n[0] = 0; |
178 |
drawLegendOrToFFrame(g, re, h, layers, n, null);
|
179 |
} else if (getQuality() == BORRADOR) { //Si se selecciona la calidad BORRADOR. |
180 |
drawDraft(g); |
181 |
} |
182 |
} |
183 |
|
184 |
g.rotate(Math.toRadians(-getRotation()), re.x + (re.width / 2), |
185 |
re.y + (re.height / 2));
|
186 |
} |
187 |
|
188 |
/**
|
189 |
* Dibuja el nombre u s?mbolo de la capa que se pasa como par?metro.
|
190 |
*
|
191 |
* @param g Graphics2D sobre el que se dibuja.
|
192 |
* @param re Rectangle a rellenar.
|
193 |
* @param h Altura en pixels.
|
194 |
* @param layers Capa a representar.
|
195 |
* @param n ?ndice de la capa a dibujar.
|
196 |
* @throws DriverException
|
197 |
*/
|
198 |
private void drawLegendOrToFFrame(Graphics2D g, Rectangle2D re, double h, |
199 |
FLayers layers, int[] n, Layout layout) throws DriverException { |
200 |
float sizefont = 0; |
201 |
|
202 |
if ((re.getHeight() / m_numLayers) < (re.getWidth() / (m_max * 0.7))) { |
203 |
sizefont = (float) (re.getHeight() / m_numLayers);
|
204 |
} else {
|
205 |
sizefont = (float) (re.getWidth() / (m_max * 0.7)); |
206 |
} |
207 |
|
208 |
int l=0; |
209 |
//////Se recorren los layers dibujando el s?mbolo y su nombre sobre el graphics
|
210 |
for (int i = layers.getLayersCount() - 1; i >= 0; i--) { |
211 |
FLayer layer = layers.getLayer(i); |
212 |
boolean b=false; |
213 |
|
214 |
if (nameLayers.size()>l && nameLayers.get(l).equals(layer.getName())) {
|
215 |
b=((Boolean)areVisible.get(l)).booleanValue();
|
216 |
}else {
|
217 |
b=layer.isVisible(); |
218 |
} |
219 |
l++; |
220 |
if (b) {
|
221 |
if (layer instanceof FLayers) { |
222 |
n[0]++;
|
223 |
|
224 |
double dX = 0; |
225 |
double dY = n[0] * h; |
226 |
double xl = (re.getX() + dX);
|
227 |
double yl = (re.getY() + dY);
|
228 |
if (layout!=null) { |
229 |
toFFrameText(layout,layer.getName(),re,sizefont,(xl - (re.getWidth() / 5)),yl,h);
|
230 |
}else {
|
231 |
drawNameLegend(g, layer.getName(), re, sizefont, |
232 |
(xl - (re.getWidth() / 5)), yl, h);
|
233 |
} |
234 |
n[0]++;
|
235 |
drawLegendOrToFFrame(g, re, h, (FLayers) layer, n, layout); |
236 |
n[0]++;
|
237 |
} else if (layer instanceof AlphanumericData) { |
238 |
AlphanumericData cO = (AlphanumericData) layer; |
239 |
|
240 |
if (((Classifiable) cO).getLegend() instanceof ClassifiedLegendInfo && !(cO instanceof FLyrAnnotation)) { |
241 |
ClassifiedLegendInfo cli = (ClassifiedLegendInfo) ((Classifiable) cO).getLegend(); |
242 |
double dX = 0; |
243 |
double dY = n[0] * h; |
244 |
|
245 |
double xl = (re.getX() + dX);
|
246 |
double yl = (re.getY() + dY);
|
247 |
if (layout!=null) { |
248 |
toFFrameText(layout,layer.getName(),re,sizefont,(xl - (re.getWidth() / 5)),yl,h);
|
249 |
}else {
|
250 |
drawNameLegend(g, layer.getName(), re, sizefont, |
251 |
(xl - (re.getWidth() / 5)), yl, h);
|
252 |
} |
253 |
n[0]++;
|
254 |
|
255 |
for (int j = 0; j < cli.getValues().length; j++) { |
256 |
dY = n[0] * h;
|
257 |
|
258 |
xl = (re.getX() + dX); |
259 |
yl = (re.getY() + dY); |
260 |
|
261 |
String s = cli.getDescriptions()[j];
|
262 |
if (layout!=null) { |
263 |
toFFrameText(layout,s,re,sizefont,xl,yl,h); |
264 |
}else {
|
265 |
drawNameLegend(g, s, re, sizefont, xl, yl, h); |
266 |
} |
267 |
FSymbol fs2d = cli.getSymbols()[j]; |
268 |
if (layout!=null) { |
269 |
toFFrameSymbol(layout,re,xl,yl,fs2d,sizefont, h); |
270 |
}else {
|
271 |
drawSymbolLegend(g, re, xl, yl, fs2d, sizefont, |
272 |
h); |
273 |
} |
274 |
n[0]++;
|
275 |
} |
276 |
} else {
|
277 |
double dX = 0; |
278 |
double dY = n[0] * h; |
279 |
|
280 |
double xl = (re.getX() + dX);
|
281 |
double yl = (re.getY() + dY);
|
282 |
if (layout!=null) { |
283 |
toFFrameText(layout,layer.getName(),re,sizefont,xl,yl,h); |
284 |
}else {
|
285 |
drawNameLegend(g, layer.getName(), re, sizefont, xl, |
286 |
yl, h); |
287 |
} |
288 |
FSymbol fs2d = ((Classifiable) cO).getLegend() |
289 |
.getDefaultSymbol(); |
290 |
|
291 |
if (layout!=null) { |
292 |
toFFrameSymbol(layout,re,xl,yl,fs2d,sizefont, h); |
293 |
}else {
|
294 |
drawSymbolLegend(g, re, xl, yl, fs2d, sizefont, |
295 |
h); |
296 |
} |
297 |
n[0]++;
|
298 |
} |
299 |
}else{
|
300 |
double dX = 0; |
301 |
double dY = n[0] * h; |
302 |
|
303 |
double xl = (re.getX() + dX);
|
304 |
double yl = (re.getY() + dY);
|
305 |
if (layout!=null) { |
306 |
toFFrameText(layout,layer.getName(),re,sizefont,xl,yl,h); |
307 |
}else {
|
308 |
drawNameLegend(g, layer.getName(), re, sizefont, xl, |
309 |
yl, h); |
310 |
} |
311 |
n[0]++;
|
312 |
} |
313 |
} |
314 |
} |
315 |
} |
316 |
|
317 |
/**
|
318 |
* Dibuja sobre el graphics el nombre de la capa que se pasa como
|
319 |
* par?metro.
|
320 |
*
|
321 |
* @param g Graphics2D sobre el que dibujar.
|
322 |
* @param name Nombre de la capa.
|
323 |
* @param re Rect?ngulo a ocupar por el nombre.
|
324 |
* @param sizefont tama?o de la fuente.
|
325 |
* @param x Posici?n X.
|
326 |
* @param y Posici?n Y.
|
327 |
* @param h Altura.
|
328 |
*/
|
329 |
private void drawNameLegend(Graphics2D g, String name, Rectangle2D re, |
330 |
float sizefont, double x, double y, double h) { |
331 |
Font f = getFont(sizefont);
|
332 |
g.setFont(f); |
333 |
g.setColor(Color.black);
|
334 |
g.drawString(name, (float) (x + (re.getWidth() / 4)), |
335 |
(float) (y + (h / 2))); |
336 |
} |
337 |
|
338 |
private Font getFont(float sizefont) { |
339 |
Font f=getFont();
|
340 |
return new Font(f.getName(),f.getStyle(),(int)sizefont); |
341 |
} |
342 |
|
343 |
/**
|
344 |
* A?ade al Layout un nuevo FFrameText a partir de los par?metros de
|
345 |
* entrada.
|
346 |
*
|
347 |
* @param layout Layout sobre el que se crea el nuevo FFrame.
|
348 |
* @param name Texto.
|
349 |
* @param sizefont tama?o de la fuente.
|
350 |
* @param x Posici?n X.
|
351 |
* @param y Posici?n Y.
|
352 |
* @param h Altura.
|
353 |
* @param wT Rect?ngulo del FFrame.
|
354 |
* @param hT DOCUMENT ME!
|
355 |
*/
|
356 |
/* private void toFFrameText(Layout layout, String name, double wT, double hT,
|
357 |
float sizefont, double x, double y, double h) {
|
358 |
double wl = (wT / 1.5);
|
359 |
double haux = hT / (m_numLayers * 1.3); //(sizefont * 0.7);
|
360 |
|
361 |
if (haux > (wl / 3)) {
|
362 |
haux = wl / 3;
|
363 |
}
|
364 |
|
365 |
Rectangle2D rAux = new Rectangle2D.Double(x, ((y + (h / 2)) - haux),
|
366 |
wl, haux);
|
367 |
FFrameText text = new FFrameText();
|
368 |
text.setFixedFontSize(true);
|
369 |
text.setFontSize((int) sizefont);
|
370 |
text.setBoundBox(FLayoutUtilities.toSheetRect(rAux, layout.getAT()));
|
371 |
text.addText(name);
|
372 |
layout.addFFrame(text, false, true);
|
373 |
}*/
|
374 |
private void toFFrameText(Layout layout, String name, Rectangle2D re, |
375 |
float sizefont, double x, double y, double h) { |
376 |
//Font f = getFont(sizefont);
|
377 |
Rectangle2D rAux = new Rectangle2D.Double(x+re.getWidth()/4, ((y + (h / 2)) - h), |
378 |
re.getWidth()-re.getWidth()/4, h);
|
379 |
FFrameText text = new FFrameText();
|
380 |
text.setFixedFontSize(true);
|
381 |
//text.setFontSize((int) (sizefont*1.4));
|
382 |
double myScale = layout.getAT().getScaleX() * 0.0234; |
383 |
text.setFontSize((int)(sizefont/myScale));
|
384 |
text.setBoundBox(FLayoutUtilities.toSheetRect(rAux, layout.getAT())); |
385 |
text.addText(name); |
386 |
layout.addFFrame(text, false, true); |
387 |
} |
388 |
|
389 |
/**
|
390 |
* Dibuja sobre el Graphics2D el s?mbolo.
|
391 |
*
|
392 |
* @param g Graphics2D.
|
393 |
* @param re Rect?ngulo a cubrir por el s?mbolo.
|
394 |
* @param x Posici?n X.
|
395 |
* @param y Posici?n Y.
|
396 |
* @param fs2d S?mbolo a dibujar.
|
397 |
* @param sizefont Tama?o de la fuente.
|
398 |
* @param h Altura.
|
399 |
*/
|
400 |
private void drawSymbolLegend(Graphics2D g, Rectangle2D re, double x, |
401 |
double y, FSymbol fs2d, float sizefont, double h) { |
402 |
double pW = 5; |
403 |
double wl = (re.getWidth() / pW);
|
404 |
double haux = (sizefont * 0.7); |
405 |
Font font = fs2d.getFont();
|
406 |
|
407 |
if (font != null) { |
408 |
fs2d.setFont(new Font(font.getFontName(), font.getStyle(), |
409 |
(int) (wl / 6))); |
410 |
} |
411 |
|
412 |
FGraphicUtilities.DrawSymbol(g, new AffineTransform(), |
413 |
new Rectangle((int) x, (int) ((y + (h / 2)) - haux), (int) wl, |
414 |
(int) haux), fs2d);
|
415 |
} |
416 |
|
417 |
/**
|
418 |
* A?ade al Layout un nuevo FFrameSymbol.
|
419 |
*
|
420 |
* @param layout Layout sobe el que se a?ade el FFrame.
|
421 |
* @param x Posici?n X.
|
422 |
* @param y Posici?n Y.
|
423 |
* @param fs2d S?mbolo a a?adir.
|
424 |
* @param h Altura.
|
425 |
* @param wT Rect?ngulo del FFrame.
|
426 |
* @param hT tama?o de la fuente.
|
427 |
*/
|
428 |
/* private void toFFrameSymbol(Layout layout, double wT, double hT, double x,
|
429 |
double y, FSymbol fs2d, int type, double h) {
|
430 |
double pW = 5;
|
431 |
double wl = (wT / pW);
|
432 |
double haux = hT / (m_numLayers * 1.3); //(sizefont * 0.7);
|
433 |
|
434 |
if (haux > (wT / 4.5)) {
|
435 |
haux = wT / 4.5;
|
436 |
}
|
437 |
|
438 |
Rectangle2D rAux3 = new Rectangle2D.Double(x, ((y + (h / 2)) - haux),
|
439 |
wl, haux);
|
440 |
FFrameSymbol symbol = new FFrameSymbol();
|
441 |
symbol.setBoundBox(FLayoutUtilities.toSheetRect(rAux3, layout.getAT()));
|
442 |
symbol.setSymbol(fs2d, type);
|
443 |
layout.addFFrame(symbol, false, true);
|
444 |
}*/
|
445 |
private void toFFrameSymbol(Layout layout, Rectangle2D re, double x, |
446 |
double y, FSymbol fs2d, float sizefont, double h) { |
447 |
double pW = 5; |
448 |
double wl = (re.getWidth() / pW);
|
449 |
double haux = (sizefont * 0.7); |
450 |
Font font = fs2d.getFont();
|
451 |
|
452 |
if (font != null) { |
453 |
fs2d.setFont(new Font(font.getFontName(), font.getStyle(), |
454 |
(int) (wl / 6))); |
455 |
} |
456 |
|
457 |
Rectangle2D rAux3 = new Rectangle2D.Double(x, ((y + (h / 2)) - haux), |
458 |
wl, haux); |
459 |
FFrameSymbol symbol = new FFrameSymbol();
|
460 |
symbol.setBoundBox(FLayoutUtilities.toSheetRect(rAux3, layout.getAT())); |
461 |
symbol.setFSymbol(fs2d); |
462 |
layout.addFFrame(symbol, false, true); |
463 |
} |
464 |
|
465 |
/**
|
466 |
* Devuelve el n?mero total de capas incluyendo las subcapas.
|
467 |
*
|
468 |
* @param layers Capa a contar.
|
469 |
*
|
470 |
* @return N?mero de capas y subcapas.
|
471 |
*/
|
472 |
private int getSizeNum(FLayers layers) { |
473 |
int n = 0; |
474 |
|
475 |
/////Aqu? hay que calcular cuantos layers y sublayers hay, para saber que distancias dejar entre uno y otro.
|
476 |
///y adem?s el tama?o de cada uno de ellos para saber que anchura dejar.
|
477 |
int l=0; |
478 |
for (int i = layers.getLayersCount()-1; i>=0; i--) { |
479 |
FLayer layer = layers.getLayer(i); |
480 |
boolean b=false; |
481 |
if (nameLayers.size()>l && nameLayers.get(l).equals(layer.getName())) {
|
482 |
b=((Boolean)areVisible.get(l)).booleanValue();
|
483 |
}else {
|
484 |
b=layer.isVisible(); |
485 |
} |
486 |
l++; |
487 |
if (b) {
|
488 |
//if (layer.isVisible()) {
|
489 |
if (layer.getName().length() > m_max) {
|
490 |
m_max = layer.getName().length(); |
491 |
} |
492 |
|
493 |
if (layer instanceof FLayers) { |
494 |
//n++;
|
495 |
n = n + 3;
|
496 |
n += getSizeNum((FLayers) layer); //m_numLayers += getNumInLyrGroup((FLayers) layer);
|
497 |
} else {
|
498 |
if (layer instanceof AlphanumericData) { |
499 |
AlphanumericData cO = (AlphanumericData) layer; |
500 |
n++; |
501 |
|
502 |
if (((Classifiable) cO).getLegend() instanceof ClassifiedLegendInfo && !(cO instanceof FLyrAnnotation)) { |
503 |
ClassifiedLegendInfo cli = (ClassifiedLegendInfo) ((Classifiable) cO).getLegend(); |
504 |
|
505 |
for (int j = 0; j < cli.getValues().length; j++) { |
506 |
String s = cli.getDescriptions()[j];
|
507 |
|
508 |
if (s.length() > m_max) {
|
509 |
m_max = s.length(); |
510 |
} |
511 |
|
512 |
n++; |
513 |
} |
514 |
} |
515 |
}else{
|
516 |
String s = layer.getName();
|
517 |
|
518 |
if (s.length() > m_max) {
|
519 |
m_max = s.length(); |
520 |
} |
521 |
|
522 |
n++; |
523 |
} |
524 |
|
525 |
} |
526 |
} |
527 |
} |
528 |
|
529 |
return n;
|
530 |
} |
531 |
|
532 |
/**
|
533 |
* Transforma el FFrameLegend en diferentes FFrameSymbol y FFrameText.
|
534 |
*
|
535 |
* @param layout Layout sobre el que a?adir los FFrame nuevos y sobre el
|
536 |
* que elimnar el FFrameLegend anterior.
|
537 |
*/
|
538 |
public void toFFrames(Layout layout) { |
539 |
Rectangle2D rectangle = getBoundingBox(null); |
540 |
//Rectangle2D r = getBoundBox();
|
541 |
double h = rectangle.getHeight() / m_numLayers;
|
542 |
FLayers lays = layers; |
543 |
|
544 |
//layout.getEFS().startComplexCommand();
|
545 |
//toFFrames(layout, lays, rectangle, r.getWidth(), r.getHeight(), h, 0);
|
546 |
int[] n = new int[1]; |
547 |
n[0] = 0; |
548 |
try {
|
549 |
drawLegendOrToFFrame(null,rectangle,h,lays,n,layout);
|
550 |
} catch (DriverException e) {
|
551 |
e.printStackTrace(); |
552 |
} |
553 |
layout.delFFrame(this);
|
554 |
|
555 |
///layout.getFFrames().remove(this);
|
556 |
//layout.getEFS().endComplexCommand();
|
557 |
} |
558 |
|
559 |
/**
|
560 |
* Transforma el FFrameLegend en diferentes FFrameSymbol y FFrameText.
|
561 |
*
|
562 |
* @param layout Referencia al Layout.
|
563 |
* @param lays Layers a a?adir
|
564 |
* @param rectangle Rect?ngulo del FFrameLegend.
|
565 |
* @param wT DOCUMENT ME!
|
566 |
* @param hT DOCUMENT ME!
|
567 |
* @param h Altura
|
568 |
* @param n n?mero de Capa a?adida.
|
569 |
*
|
570 |
* @return n?mero de Capa a a?adir.
|
571 |
*/
|
572 |
/* public int toFFrames(Layout layout, FLayers lays, Rectangle2D rectangle,
|
573 |
double wT, double hT, double h, int n) {
|
574 |
int N = 39;
|
575 |
float sizefont = 0;
|
576 |
|
577 |
if ((rectangle.getHeight() / m_numLayers) < ((wT * N) / (m_max * 0.7))) {
|
578 |
sizefont = (float) ((hT * N) / m_numLayers);
|
579 |
} else {
|
580 |
sizefont = (float) ((wT * N) / (m_max * 0.7));
|
581 |
}
|
582 |
|
583 |
////// Se recorren los layers dibujando el s?mbolo y su nombre sobre el graphics
|
584 |
for (int i = 0; i < lays.getLayersCount(); i++) {
|
585 |
FLayer layer = (FLayer) lays.getLayer(i);
|
586 |
|
587 |
if (layer.isVisible()) {
|
588 |
if (layer instanceof FLayers) {
|
589 |
rectangle.setRect(rectangle.getX(),
|
590 |
rectangle.getY() + (h * n), wT, rectangle.getHeight());
|
591 |
n += toFFrames(layout, lays, rectangle, wT, hT, h, n); //drawTheme(g, re, h, layers, n);
|
592 |
} else if (layer instanceof AlphanumericData) {
|
593 |
AlphanumericData cO = (AlphanumericData) layer;
|
594 |
|
595 |
if (((Classifiable) cO).getLegend() instanceof ClassifiedLegendInfo) {
|
596 |
ClassifiedLegendInfo cli = (ClassifiedLegendInfo) ((Classifiable) cO).getLegend();
|
597 |
double dX = rectangle.getWidth() / 4;
|
598 |
double dY = n * h;
|
599 |
|
600 |
double xl = (rectangle.getX() + dX);
|
601 |
double yl = (rectangle.getY() + dY);
|
602 |
toFFrameText(layout, layer.getName(),
|
603 |
rectangle.getWidth(), rectangle.getHeight(),
|
604 |
sizefont, xl, yl, h);
|
605 |
n++;
|
606 |
|
607 |
for (int j = 0; j < cli.getValues().length; j++) {
|
608 |
dY = n * h;
|
609 |
|
610 |
xl = (rectangle.getX() + dX);
|
611 |
yl = (rectangle.getY() + dY);
|
612 |
|
613 |
String s = cli.getDescriptions()[j];
|
614 |
toFFrameText(layout, s, rectangle.getWidth(),
|
615 |
rectangle.getHeight(), sizefont, xl, yl, h);
|
616 |
|
617 |
FSymbol fs2d = cli.getSymbols()[j];
|
618 |
|
619 |
try {
|
620 |
// toFFrameSymbol(layout, rectangle.getWidth(),
|
621 |
// rectangle.getHeight(), rectangle.getX(),
|
622 |
// yl, fs2d,
|
623 |
// ((Classifiable) cO).getShapeType(), h);
|
624 |
toFFrameSymbol(layout, rectangle,
|
625 |
rectangle.getHeight(), rectangle.getX(),
|
626 |
yl, fs2d,
|
627 |
((Classifiable) cO).getShapeType(), h);
|
628 |
} catch (DriverException e) {
|
629 |
e.printStackTrace();
|
630 |
}
|
631 |
|
632 |
n++;
|
633 |
}
|
634 |
} else {
|
635 |
double dX = rectangle.getWidth() / 4;
|
636 |
double dY = n * h;
|
637 |
|
638 |
double xl = (rectangle.getX() + dX);
|
639 |
double yl = (rectangle.getY() + dY);
|
640 |
|
641 |
toFFrameText(layout, layer.getName(),
|
642 |
rectangle.getWidth(), rectangle.getHeight(),
|
643 |
sizefont, xl, yl, h);
|
644 |
|
645 |
FSymbol fs2d = ((Classifiable) cO).getLegend()
|
646 |
.getDefaultSymbol();
|
647 |
|
648 |
try {
|
649 |
toFFrameSymbol(layout, rectangle.getWidth(),
|
650 |
rectangle.getHeight(), rectangle.getX(), yl,
|
651 |
fs2d, ((Classifiable) cO).getShapeType(), h);
|
652 |
} catch (DriverException e) {
|
653 |
e.printStackTrace();
|
654 |
}
|
655 |
|
656 |
n++;
|
657 |
}
|
658 |
}
|
659 |
}
|
660 |
}
|
661 |
|
662 |
return n;
|
663 |
}
|
664 |
*/
|
665 |
/**
|
666 |
* Rellena la fuente a utilizar al dibujar los String sobre el graphics.
|
667 |
*
|
668 |
* @param f Font.
|
669 |
*/
|
670 |
public void setFont(Font f) { |
671 |
m_f = f; |
672 |
} |
673 |
|
674 |
/**
|
675 |
* Devuelve la fuente que esta utilizando.
|
676 |
*
|
677 |
* @return Font.
|
678 |
*/
|
679 |
public Font getFont() { |
680 |
if (m_f != null) { |
681 |
return new Font(m_f.getName(),m_f.getStyle(),9); |
682 |
// return new Font(m_f.getFontName(), m_f.getStyle(), 9);
|
683 |
} |
684 |
return new Font("SansSerif",Font.PLAIN,9); |
685 |
} |
686 |
|
687 |
/**
|
688 |
* @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#getXMLEntity()
|
689 |
*/
|
690 |
public XMLEntity getXMLEntity() throws SaveException { |
691 |
XMLEntity xml = super.getXMLEntity();
|
692 |
|
693 |
try {
|
694 |
xml.putProperty("type", Layout.RECTANGLELEGEND);
|
695 |
xml.putProperty("m_numLayers", m_numLayers);
|
696 |
xml.putProperty("m_max", m_max);
|
697 |
xml.putProperty("m_quality", m_quality);
|
698 |
xml.putProperty("m_viewing", m_viewing);
|
699 |
xml.putProperty("fontName", m_f.getFontName());
|
700 |
xml.putProperty("fontStyle", m_f.getStyle());
|
701 |
|
702 |
if (fframeview != null) { |
703 |
Layout layout = fframeview.getLayout(); |
704 |
IFFrame[] fframes = layout.getAllFFrames();
|
705 |
|
706 |
for (int i = 0; i < fframes.length; i++) { |
707 |
if (fframeview.equals(fframes[i])) {
|
708 |
xml.putProperty("index", i);
|
709 |
break;
|
710 |
} |
711 |
} |
712 |
} |
713 |
|
714 |
String[] s=new String[nameLayers.size()]; |
715 |
boolean[] b=new boolean[nameLayers.size()]; |
716 |
for (int i=0;i<nameLayers.size();i++) { |
717 |
String k=(String)nameLayers.get(i); |
718 |
s[i]=k; |
719 |
b[i]=((Boolean)areVisible.get(i)).booleanValue();
|
720 |
} |
721 |
xml.putProperty("nameLayers",s);
|
722 |
xml.putProperty("areVisible",b);
|
723 |
} catch (Exception e) { |
724 |
throw new SaveException(e, this.getClass().getName()); |
725 |
} |
726 |
|
727 |
return xml;
|
728 |
} |
729 |
|
730 |
/**
|
731 |
* @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
|
732 |
* com.iver.cit.gvsig.project.Project)
|
733 |
*/
|
734 |
public void setXMLEntity03(XMLEntity xml, Layout l) { |
735 |
if (xml.getIntProperty("m_Selected") != 0) { |
736 |
this.setSelected(true); |
737 |
} else {
|
738 |
this.setSelected(false); |
739 |
} |
740 |
|
741 |
this.m_numLayers = xml.getIntProperty("m_numLayers"); |
742 |
this.m_max = xml.getIntProperty("m_max"); |
743 |
this.m_quality = xml.getIntProperty("m_quality"); |
744 |
this.m_viewing = xml.getIntProperty("m_viewing"); |
745 |
this.m_f = new Font(xml.getStringProperty("fontName"), |
746 |
xml.getIntProperty("fontStyle"), 9); |
747 |
|
748 |
if (xml.contains("index")) { |
749 |
fframeview = (FFrameView) l.getFFrame(xml.getIntProperty("index"));
|
750 |
} |
751 |
} |
752 |
|
753 |
/**
|
754 |
* @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
|
755 |
* com.iver.cit.gvsig.project.Project)
|
756 |
*/
|
757 |
public void setXMLEntity(XMLEntity xml) { |
758 |
if (xml.getIntProperty("m_Selected") != 0) { |
759 |
this.setSelected(true); |
760 |
} else {
|
761 |
this.setSelected(false); |
762 |
} |
763 |
|
764 |
this.m_numLayers = xml.getIntProperty("m_numLayers"); |
765 |
this.m_max = xml.getIntProperty("m_max"); |
766 |
this.m_quality = xml.getIntProperty("m_quality"); |
767 |
this.m_viewing = xml.getIntProperty("m_viewing"); |
768 |
this.m_f = new Font(xml.getStringProperty("fontName"), |
769 |
xml.getIntProperty("fontStyle"), 9); |
770 |
setRotation(xml.getDoubleProperty("m_rotation"));
|
771 |
|
772 |
if (xml.contains("index")) { |
773 |
dependenceIndex = xml.getIntProperty("index");
|
774 |
} |
775 |
if (xml.contains("nameLayers")) { |
776 |
String[] s=xml.getStringArrayProperty("nameLayers"); |
777 |
boolean[] b=xml.getBooleanArrayProperty("areVisible"); |
778 |
for (int i=0;i<s.length;i++) { |
779 |
nameLayers.add(s[i]); |
780 |
areVisible.add(new Boolean(b[i])); |
781 |
} |
782 |
} |
783 |
} |
784 |
|
785 |
/**
|
786 |
* @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#getNameFFrame()
|
787 |
*/
|
788 |
public String getNameFFrame() { |
789 |
return PluginServices.getText(this, "leyenda")+ num; |
790 |
} |
791 |
|
792 |
/**
|
793 |
* @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#print(java.awt.Graphics2D,
|
794 |
* java.awt.geom.AffineTransform)
|
795 |
*/
|
796 |
public void print(Graphics2D g, AffineTransform at) |
797 |
throws DriverException {
|
798 |
draw(g, at, null, null); |
799 |
} |
800 |
|
801 |
/**
|
802 |
* Actualiza las dependencias que tenga este FFrame con el resto.
|
803 |
*
|
804 |
* @param fframes Resto de FFrames.
|
805 |
*/
|
806 |
public void initDependence(IFFrame[] fframes) { |
807 |
if ((dependenceIndex != -1) && |
808 |
fframes[dependenceIndex] instanceof FFrameView) {
|
809 |
fframeview = (FFrameView) fframes[dependenceIndex]; |
810 |
} |
811 |
} |
812 |
|
813 |
public void initialize() { |
814 |
// TODO Auto-generated method stub
|
815 |
|
816 |
} |
817 |
|
818 |
public void setNameLayers(ArrayList nameLayers) { |
819 |
this.nameLayers=nameLayers;
|
820 |
} |
821 |
|
822 |
public void setAreVisible(ArrayList areVisible) { |
823 |
this.areVisible=areVisible;
|
824 |
} |
825 |
|
826 |
public ArrayList getNameLayers() { |
827 |
return nameLayers;
|
828 |
} |
829 |
|
830 |
public ArrayList getAreVisible() { |
831 |
return areVisible;
|
832 |
} |
833 |
} |