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