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