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