Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / layout / fframes / FFrameLegend.java @ 6117

History | View | Annotate | Download (26.9 KB)

1 1103 fjp
/* 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 312 fernando
package com.iver.cit.gvsig.gui.layout.fframes;
42
43 3610 caballero
import com.iver.andami.PluginServices;
44 3552 caballero
45 654 fernando
import com.iver.cit.gvsig.fmap.DriverException;
46 458 fjp
import com.iver.cit.gvsig.fmap.core.v02.FGraphicUtilities;
47
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
48 384 vcaballero
import com.iver.cit.gvsig.fmap.layers.FLayer;
49
import com.iver.cit.gvsig.fmap.layers.FLayers;
50 5483 caballero
import com.iver.cit.gvsig.fmap.layers.FLyrAnnotation;
51 638 vcaballero
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
52
import com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable;
53 384 vcaballero
import com.iver.cit.gvsig.fmap.rendering.ClassifiedLegendInfo;
54 1273 vcaballero
import com.iver.cit.gvsig.gui.layout.FLayoutUtilities;
55 312 fernando
import com.iver.cit.gvsig.gui.layout.Layout;
56 3183 caballero
import com.iver.cit.gvsig.gui.project.SaveException;
57 3610 caballero
58 312 fernando
import com.iver.utiles.XMLEntity;
59
60 3610 caballero
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 384 vcaballero
68 3610 caballero
69 312 fernando
/**
70 1073 vcaballero
 * FFrame para introducir una leyenda en el Layout.
71 312 fernando
 *
72
 * @author Vicente Caballero Navarro
73
 */
74 3146 caballero
public class FFrameLegend extends FFrame implements IFFrameViewDependence {
75 2755 caballero
    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 5777 caballero
    private Font m_f = new Font("SansSerif", Font.PLAIN, 9);
80 2755 caballero
    private FFrameView fframeview = null;
81
    private int m_max;
82
    private int m_numLayers;
83
    private FLayers layers = null;
84 3610 caballero
    private int dependenceIndex = -1;
85 312 fernando
86 2755 caballero
    /**
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 312 fernando
95 2755 caballero
    /**
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 312 fernando
104 2755 caballero
    /**
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 312 fernando
113 2755 caballero
    /**
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 3114 caballero
    public void setFFrameDependence(IFFrame f) {
120 3135 caballero
        fframeview = (FFrameView) f;
121 2755 caballero
    }
122 384 vcaballero
123 2755 caballero
    /**
124
     * Devuelve el FFrameView utilizado para obtener la leyenda.
125
     *
126
     * @return FFrameView utilizado.
127
     */
128 3114 caballero
    public IFFrame getFFrameDependence() {
129 2755 caballero
        return fframeview;
130
    }
131 384 vcaballero
132 2755 caballero
    /**
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 312 fernando
141 2755 caballero
    /**
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 312 fernando
159 2755 caballero
        if ((fframeview != null) && (fframeview.getFMap() != null)) {
160
            layers = fframeview.getFMap().getLayers();
161
        }
162 312 fernando
163 2755 caballero
        m_max = 0;
164
        m_numLayers = 0;
165 312 fernando
166 2755 caballero
        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 312 fernando
172 2755 caballero
                double h = re.getHeight() / m_numLayers;
173
                int[] n = new int[1];
174
                n[0] = 0;
175 5927 caballero
                drawLegendOrToFFrame(g, re, h, layers, n, Font.PLAIN,null);
176 2755 caballero
            } else if (getQuality() == BORRADOR) { //Si se selecciona la calidad BORRADOR.
177
                drawDraft(g);
178
            }
179
        }
180 312 fernando
181 2755 caballero
        g.rotate(Math.toRadians(-getRotation()), re.x + (re.width / 2),
182
            re.y + (re.height / 2));
183
    }
184 1073 vcaballero
185 2755 caballero
    /**
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 5927 caballero
    private void drawLegendOrToFFrame(Graphics2D g, Rectangle2D re, double h,
198
        FLayers layers, int[] n, int typeFont,Layout layout) throws DriverException {
199 3552 caballero
        float sizefont = 0;
200 3610 caballero
201
        if ((re.getHeight() / m_numLayers) < (re.getWidth() / (m_max * 0.7))) {
202 3270 caballero
            sizefont = (float) (re.getHeight() / m_numLayers);
203
        } else {
204
            sizefont = (float) (re.getWidth() / (m_max * 0.7));
205
        }
206 3610 caballero
207 4203 caballero
        //////Se recorren los layers dibujando el s?mbolo y su nombre sobre el graphics
208 3610 caballero
        for (int i = layers.getLayersCount() - 1; i >= 0; i--) {
209 2755 caballero
            FLayer layer = (FLayer) layers.getLayer(i);
210 312 fernando
211 2755 caballero
            if (layer.isVisible()) {
212
                if (layer instanceof FLayers) {
213
                    n[0]++;
214 312 fernando
215 2755 caballero
                    double dX = 0;
216
                    double dY = n[0] * h;
217
                    double xl = (re.getX() + dX);
218
                    double yl = (re.getY() + dY);
219 5927 caballero
                    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 2755 caballero
                    n[0]++;
228
                } else if (layer instanceof AlphanumericData) {
229
                    AlphanumericData cO = (AlphanumericData) layer;
230 483 vcaballero
231 5483 caballero
                    if (((Classifiable) cO).getLegend() instanceof ClassifiedLegendInfo && !(cO instanceof FLyrAnnotation)) {
232 2755 caballero
                        ClassifiedLegendInfo cli = (ClassifiedLegendInfo) ((Classifiable) cO).getLegend();
233
                        double dX = 0;
234
                        double dY = n[0] * h;
235 1073 vcaballero
236 2755 caballero
                        double xl = (re.getX() + dX);
237
                        double yl = (re.getY() + dY);
238 5927 caballero
                        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 2755 caballero
                        n[0]++;
245 483 vcaballero
246 2755 caballero
                        for (int j = 0; j < cli.getValues().length; j++) {
247
                            dY = n[0] * h;
248 483 vcaballero
249 2755 caballero
                            xl = (re.getX() + dX);
250
                            yl = (re.getY() + dY);
251 312 fernando
252 2755 caballero
                            String s = cli.getDescriptions()[j];
253 5927 caballero
                            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 2755 caballero
                            FSymbol fs2d = cli.getSymbols()[j];
260 5927 caballero
                            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 2755 caballero
                            n[0]++;
267
                        }
268
                    } else {
269
                        double dX = 0;
270
                        double dY = n[0] * h;
271 312 fernando
272 2755 caballero
                        double xl = (re.getX() + dX);
273
                        double yl = (re.getY() + dY);
274 5927 caballero
                        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 2755 caballero
                        FSymbol fs2d = ((Classifiable) cO).getLegend()
281
                                        .getDefaultSymbol();
282 1273 vcaballero
283 5927 caballero
                        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 2755 caballero
                        n[0]++;
290
                    }
291
                }
292
            }
293
        }
294
    }
295 483 vcaballero
296 2755 caballero
    /**
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 5777 caballero
        Font f = getFont(sizefont);
312 2755 caballero
        g.setFont(f);
313
        g.setColor(Color.black);
314
        g.drawString(name, (float) (x + (re.getWidth() / 4)),
315
            (float) (y + (h / 2)));
316
    }
317 483 vcaballero
318 5777 caballero
    private Font getFont(float sizefont) {
319
                Font f=getFont();
320
                return new Font(f.getName(),f.getStyle(),(int)sizefont);
321
  }
322
323
        /**
324 2755 caballero
     * 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 3610 caballero
     * @param wT Rect?ngulo del FFrame.
330
     * @param hT DOCUMENT ME!
331 2755 caballero
     * @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 5927 caballero
  /*  private void toFFrameText(Layout layout, String name, double wT, double hT,
337 2755 caballero
        float sizefont, double x, double y, double h) {
338 3610 caballero
        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 3243 caballero
        }
344 3610 caballero

345
        Rectangle2D rAux = new Rectangle2D.Double(x, ((y + (h / 2)) - haux),
346
                wl, haux);
347 2755 caballero
        FFrameText text = new FFrameText();
348 2933 caballero
        text.setFixedFontSize(true);
349 3103 caballero
        text.setFontSize((int) sizefont);
350 2755 caballero
        text.setBoundBox(FLayoutUtilities.toSheetRect(rAux, layout.getAT()));
351
        text.addText(name);
352 3103 caballero
        layout.addFFrame(text, false, true);
353 5927 caballero
    }*/
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 1273 vcaballero
367 2755 caballero
    /**
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 312 fernando
386 2755 caballero
        if (font != null) {
387
            fs2d.setFont(new Font(font.getFontName(), font.getStyle(),
388
                    (int) (wl / 6)));
389
        }
390 312 fernando
391 2755 caballero
        FGraphicUtilities.DrawSymbol(g, new AffineTransform(),
392
            new Rectangle((int) x, (int) ((y + (h / 2)) - haux), (int) wl,
393
                (int) haux), fs2d);
394
    }
395 312 fernando
396 2755 caballero
    /**
397
     * A?ade al Layout un nuevo FFrameSymbol.
398
     *
399
     * @param layout Layout sobe el que se a?ade el FFrame.
400 3610 caballero
     * @param wT Rect?ngulo del FFrame.
401
     * @param hT tama?o de la fuente.
402 2755 caballero
     * @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 5927 caballero
   /* private void toFFrameSymbol(Layout layout, double wT, double hT, double x,
409 3243 caballero
        double y, FSymbol fs2d, int type, double h) {
410 2755 caballero
        double pW = 5;
411 3243 caballero
        double wl = (wT / pW);
412 3610 caballero
        double haux = hT / (m_numLayers * 1.3); //(sizefont * 0.7);
413

414
        if (haux > (wT / 4.5)) {
415
            haux = wT / 4.5;
416 3243 caballero
        }
417 3610 caballero

418 2755 caballero
        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 3103 caballero
        layout.addFFrame(symbol, false, true);
424 5927 caballero
    }*/
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 1073 vcaballero
432 5927 caballero
            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 6031 caballero
            symbol.setFSymbol(fs2d);
442 5927 caballero
            layout.addFFrame(symbol, false, true);
443
        }
444
445 2755 caballero
    /**
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 1073 vcaballero
455 2755 caballero
        /////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 312 fernando
460 2755 caballero
            if (layer.isVisible()) {
461
                if (layer.getName().length() > m_max) {
462
                    m_max = layer.getName().length();
463
                }
464 312 fernando
465 2755 caballero
                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 312 fernando
472 5483 caballero
                    if (((Classifiable) cO).getLegend() instanceof ClassifiedLegendInfo && !(cO instanceof FLyrAnnotation)) {
473 2755 caballero
                        ClassifiedLegendInfo cli = (ClassifiedLegendInfo) ((Classifiable) cO).getLegend();
474 483 vcaballero
475 2755 caballero
                        for (int j = 0; j < cli.getValues().length; j++) {
476
                            String s = cli.getDescriptions()[j];
477 1273 vcaballero
478 2755 caballero
                            if (s.length() > m_max) {
479
                                m_max = s.length();
480
                            }
481 1273 vcaballero
482 2755 caballero
                            n++;
483
                        }
484
                    }
485
                }
486
            }
487
        }
488 1273 vcaballero
489 2755 caballero
        return n;
490
    }
491 1273 vcaballero
492 2755 caballero
    /**
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 5927 caballero
        //Rectangle2D r = getBoundBox();
501 2755 caballero
        double h = rectangle.getHeight() / m_numLayers;
502
        FLayers lays = layers;
503 3610 caballero
504 3552 caballero
        //layout.getEFS().startComplexCommand();
505 5927 caballero
        //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 3552 caballero
        layout.delFFrame(this);
514 3610 caballero
515 3552 caballero
        ///layout.getFFrames().remove(this);
516
        //layout.getEFS().endComplexCommand();
517 2755 caballero
    }
518 1273 vcaballero
519 2755 caballero
    /**
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 3610 caballero
     * @param wT DOCUMENT ME!
526
     * @param hT DOCUMENT ME!
527 2755 caballero
     * @param h Altura
528
     * @param n n?mero de Capa a?adida.
529
     *
530
     * @return n?mero de Capa a a?adir.
531
     */
532 5927 caballero
 /*   public int toFFrames(Layout layout, FLayers lays, Rectangle2D rectangle,
533 3610 caballero
        double wT, double hT, double h, int n) {
534
        int N = 39;
535 3270 caballero
        float sizefont = 0;
536

537 3610 caballero
        if ((rectangle.getHeight() / m_numLayers) < ((wT * N) / (m_max * 0.7))) {
538
            sizefont = (float) ((hT * N) / m_numLayers);
539 3270 caballero
        } else {
540 3610 caballero
            sizefont = (float) ((wT * N) / (m_max * 0.7));
541 3270 caballero
        }
542 3610 caballero

543 4203 caballero
        //////        Se recorren los layers dibujando el s?mbolo y su nombre sobre el graphics
544 2755 caballero
        for (int i = 0; i < lays.getLayersCount(); i++) {
545
            FLayer layer = (FLayer) lays.getLayer(i);
546 1273 vcaballero

547 2755 caballero
            if (layer.isVisible()) {
548
                if (layer instanceof FLayers) {
549
                    rectangle.setRect(rectangle.getX(),
550 3610 caballero
                        rectangle.getY() + (h * n), wT, rectangle.getHeight());
551
                    n += toFFrames(layout, lays, rectangle, wT, hT, h, n); //drawTheme(g, re, h, layers, n);
552 2755 caballero
                } else if (layer instanceof AlphanumericData) {
553
                    AlphanumericData cO = (AlphanumericData) layer;
554 1273 vcaballero

555 2755 caballero
                    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 1273 vcaballero

560 2755 caballero
                        double xl = (rectangle.getX() + dX);
561
                        double yl = (rectangle.getY() + dY);
562 3610 caballero
                        toFFrameText(layout, layer.getName(),
563
                            rectangle.getWidth(), rectangle.getHeight(),
564 3243 caballero
                            sizefont, xl, yl, h);
565 2755 caballero
                        n++;
566 1273 vcaballero

567 2755 caballero
                        for (int j = 0; j < cli.getValues().length; j++) {
568
                            dY = n * h;
569 1273 vcaballero

570 2755 caballero
                            xl = (rectangle.getX() + dX);
571
                            yl = (rectangle.getY() + dY);
572 1273 vcaballero

573 2755 caballero
                            String s = cli.getDescriptions()[j];
574 3610 caballero
                            toFFrameText(layout, s, rectangle.getWidth(),
575
                                rectangle.getHeight(), sizefont, xl, yl, h);
576 1273 vcaballero

577 2755 caballero
                            FSymbol fs2d = cli.getSymbols()[j];
578 312 fernando

579 2755 caballero
                            try {
580 5927 caballero
//                                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 2755 caballero
                            } catch (DriverException e) {
589
                                e.printStackTrace();
590
                            }
591 483 vcaballero

592 2755 caballero
                            n++;
593
                        }
594
                    } else {
595
                        double dX = rectangle.getWidth() / 4;
596
                        double dY = n * h;
597 483 vcaballero

598 2755 caballero
                        double xl = (rectangle.getX() + dX);
599
                        double yl = (rectangle.getY() + dY);
600 686 vcaballero

601 3610 caballero
                        toFFrameText(layout, layer.getName(),
602
                            rectangle.getWidth(), rectangle.getHeight(),
603
                            sizefont, xl, yl, h);
604

605 2755 caballero
                        FSymbol fs2d = ((Classifiable) cO).getLegend()
606
                                        .getDefaultSymbol();
607 686 vcaballero

608 2755 caballero
                        try {
609 3610 caballero
                            toFFrameSymbol(layout, rectangle.getWidth(),
610
                                rectangle.getHeight(), rectangle.getX(), yl,
611
                                fs2d, ((Classifiable) cO).getShapeType(), h);
612 2755 caballero
                        } catch (DriverException e) {
613
                            e.printStackTrace();
614
                        }
615 483 vcaballero

616 2755 caballero
                        n++;
617
                    }
618
                }
619
            }
620
        }
621 3610 caballero

622 2755 caballero
        return n;
623
    }
624 5927 caballero
*/
625 2755 caballero
    /**
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 1073 vcaballero
634 2755 caballero
    /**
635
     * Devuelve la fuente que esta utilizando.
636
     *
637
     * @return Font.
638
     */
639
    public Font getFont() {
640
        if (m_f != null) {
641 5777 caballero
                return new Font(m_f.getName(),m_f.getStyle(),9);
642
        //    return new Font(m_f.getFontName(), m_f.getStyle(), 9);
643 2755 caballero
        }
644 5777 caballero
        return new Font("SansSerif",Font.PLAIN,9);
645 2755 caballero
    }
646 1073 vcaballero
647 2755 caballero
    /**
648
     * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
649
     */
650 3610 caballero
    public XMLEntity getXMLEntity() throws SaveException {
651
        XMLEntity xml = super.getXMLEntity();
652 3135 caballero
653 3610 caballero
        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 2755 caballero
            }
672 3610 caballero
        } catch (Exception e) {
673
            throw new SaveException(e, this.getClass().getName());
674 2755 caballero
        }
675 3610 caballero
676 2755 caballero
        return xml;
677
    }
678 2183 fernando
679 2755 caballero
    /**
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 2183 fernando
690 2755 caballero
        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 3610 caballero
697
        if (xml.contains("index")) {
698
            fframeview = (FFrameView) l.getFFrame(xml.getIntProperty("index"));
699
        }
700 2755 caballero
    }
701 398 vcaballero
702 2755 caballero
    /**
703
     * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
704
     *      com.iver.cit.gvsig.project.Project)
705
     */
706 3135 caballero
    public void setXMLEntity(XMLEntity xml) {
707 2755 caballero
        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 3135 caballero
            dependenceIndex = xml.getIntProperty("index");
723 2755 caballero
        }
724
    }
725
726
    /**
727
     * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getNameFFrame()
728
     */
729
    public String getNameFFrame() {
730 5476 caballero
        return PluginServices.getText(this, "leyenda")+ num;
731 2755 caballero
    }
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 3114 caballero
742 3135 caballero
    /**
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 3610 caballero
        if ((dependenceIndex != -1) &&
749
                fframes[dependenceIndex] instanceof FFrameView) {
750
            fframeview = (FFrameView) fframes[dependenceIndex];
751
        }
752 3135 caballero
    }
753 4203 caballero
754
        public void initialize() {
755
                // TODO Auto-generated method stub
756
757
        }
758 312 fernando
}