Statistics
| Revision:

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

History | View | Annotate | Download (29.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.gui.layout.fframes;
42

    
43
import java.awt.Color;
44
import java.awt.Font;
45
import java.awt.Graphics2D;
46
import java.awt.Rectangle;
47
import java.awt.geom.AffineTransform;
48
import java.awt.geom.Rectangle2D;
49
import java.awt.image.BufferedImage;
50
import java.util.ArrayList;
51

    
52
import com.iver.andami.PluginServices;
53
import com.iver.cit.gvsig.fmap.DriverException;
54
import com.iver.cit.gvsig.fmap.core.ISymbol;
55
import com.iver.cit.gvsig.fmap.core.v02.FGraphicUtilities;
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.rendering.ClassifiedLegendInfo;
63
import com.iver.cit.gvsig.gui.layout.Layout;
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.IFFrame;
67
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrameViewDependence;
68
import com.iver.utiles.XMLEntity;
69

    
70

    
71
/**
72
 * FFrame para introducir una leyenda en el Layout.
73
 *
74
 * @author Vicente Caballero Navarro
75
 */
76
public class FFrameLegend extends FFrame implements IFFrameViewDependence {
77
    private static final int PRESENTACION = 0;
78
    private static final int BORRADOR = 1;
79
    private int m_quality = 0;
80
    private int m_viewing = 0;
81
    private Font m_f = new Font("SansSerif", Font.PLAIN, 9);
82
    private FFrameView fframeview = null;
83
    private int m_max;
84
    private int m_numLayers;
85
    private FLayers layers = null;
86
    private int dependenceIndex = -1;
87
        private ArrayList nameLayers=new ArrayList();
88
        private ArrayList areVisible=new ArrayList();
89

    
90
    /**
91
     * Rellena la calidad que se quiere aplicar.
92
     *
93
     * @param q entero que representa la calidad a aplicar.
94
     */
95
    public void setQuality(int q) {
96
        m_quality = q;
97
    }
98

    
99
    /**
100
     * Devuelve un entero que representa la calidad que est? seleccionada.
101
     *
102
     * @return tipo de calidad selccionada.
103
     */
104
    public int getQuality() {
105
        return m_quality;
106
    }
107

    
108
    /**
109
     * Devuelve un entero que representa la forma en que se actualiza la vista.
110
     *
111
     * @return forma que se actualiza la vista.
112
     */
113
    public int getViewing() {
114
        return m_viewing;
115
    }
116

    
117
    /**
118
     * Inserta una FFrameView de donde se obtiene la informaci?n de las capas
119
     * para generar la leyenda.
120
     *
121
     * @param f FFrameView para obtener los nombres de las capas.
122
     */
123
    public void setFFrameDependence(IFFrame f) {
124
        fframeview = (FFrameView) f;
125
    }
126

    
127
    /**
128
     * Devuelve el FFrameView utilizado para obtener la leyenda.
129
     *
130
     * @return FFrameView utilizado.
131
     */
132
    public IFFrame getFFrameDependence() {
133
        return fframeview;
134
    }
135

    
136
    /**
137
     * Rellena la forma de actualizar la vista.
138
     *
139
     * @param v entero que representa la forma de actualizar la vista.
140
     */
141
    public void setViewing(int v) {
142
        m_viewing = v;
143
    }
144

    
145
    /**
146
     * M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
147
     * la transformada afin que se debe de aplicar y el rect?ngulo que se debe
148
     * de dibujar.
149
     *
150
     * @param g Graphics
151
     * @param at Transformada afin.
152
     * @param rv rect?ngulo sobre el que hacer un clip.
153
     * @param imgBase Imagen para acelerar el dibujado.
154
     *
155
     * @throws DriverException
156
     */
157
    public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv,
158
        BufferedImage imgBase) throws DriverException {
159
        Rectangle2D.Double re = getBoundingBox(at);
160
        g.rotate(Math.toRadians(getRotation()), re.x + (re.width / 2),
161
            re.y + (re.height / 2));
162

    
163
        if ((fframeview != null) && (fframeview.getMapContext() != null)) {
164
            layers = fframeview.getMapContext().getLayers();
165
        }
166

    
167
        m_max = 0;
168
        m_numLayers = 0;
169

    
170
        if (intersects(rv, re)) {
171
            if (layers == null) { //Si no se ha seleccionado ninguna vista para crear la leyenda.
172
                drawEmpty(g);
173
            } else if ((rv == null) || (getQuality() == PRESENTACION)) {
174
                m_numLayers = getSizeNum(layers);
175

    
176
                double h = re.getHeight() / m_numLayers;
177
                int[] n = new int[1];
178
                n[0] = 0;
179
                drawLegendOrToFFrame(g, re, h, layers, n, null);
180
            } else if (getQuality() == BORRADOR) { //Si se selecciona la calidad BORRADOR.
181
                drawDraft(g);
182
            }
183
        }
184

    
185
        g.rotate(Math.toRadians(-getRotation()), re.x + (re.width / 2),
186
            re.y + (re.height / 2));
187
    }
188

    
189
    /**
190
     * Dibuja el nombre u s?mbolo de la capa que se pasa como par?metro.
191
     *
192
     * @param g Graphics2D sobre el que se dibuja.
193
     * @param re Rectangle a rellenar.
194
     * @param h Altura en pixels.
195
     * @param layers Capa a representar.
196
     * @param n ?ndice de la capa a dibujar.
197
     * @throws DriverException
198
     */
199
    private void drawLegendOrToFFrame(Graphics2D g, Rectangle2D re, double h,
200
        FLayers layers, int[] n, Layout layout) throws DriverException {
201
        float sizefont = 0;
202

    
203
        if ((re.getHeight() / m_numLayers) < (re.getWidth() / (m_max * 0.7))) {
204
            sizefont = (float) (re.getHeight() / m_numLayers);
205
        } else {
206
            sizefont = (float) (re.getWidth() / (m_max * 0.7));
207
        }
208

    
209
        int l=0;
210
        //////Se recorren los layers dibujando el s?mbolo y su nombre sobre el graphics
211
        for (int i = layers.getLayersCount() - 1; i >= 0; i--) {
212
            FLayer layer = layers.getLayer(i);
213
            boolean b=false;
214

    
215
            if (nameLayers.size()>l && nameLayers.get(l).equals(layer.getName())) {
216
                    b=((Boolean)areVisible.get(l)).booleanValue();
217
            }else {
218
                    b=layer.isVisible();
219
            }
220
            l++;
221
            if (b) {
222
                if (layer instanceof FLayers) {
223
                    n[0]++;
224

    
225
                    double dX = 0;
226
                    double dY = n[0] * h;
227
                    double xl = (re.getX() + dX);
228
                    double yl = (re.getY() + dY);
229
                    if (layout!=null) {
230
                            toFFrameText(layout,layer.getName(),re,sizefont,(xl - (re.getWidth() / 5)),yl,h);
231
                    }else {
232
                            drawNameLegend(g, layer.getName(), re, sizefont,
233
                                            (xl - (re.getWidth() / 5)), yl, h);
234
                    }
235
                            n[0]++;
236
                    drawLegendOrToFFrame(g, re, h, (FLayers) layer, n, layout);
237
                    n[0]++;
238
                } else if (layer instanceof AlphanumericData) {
239
                    AlphanumericData cO = (AlphanumericData) layer;
240

    
241
                    if (((Classifiable) cO).getLegend() instanceof ClassifiedLegendInfo && !(cO instanceof FLyrAnnotation)) {
242
                        ClassifiedLegendInfo cli = (ClassifiedLegendInfo) ((Classifiable) cO).getLegend();
243
                        double dX = 0;
244
                        double dY = n[0] * h;
245

    
246
                        double xl = (re.getX() + dX);
247
                        double yl = (re.getY() + dY);
248
                        if (layout!=null) {
249
                                toFFrameText(layout,layer.getName(),re,sizefont,(xl - (re.getWidth() / 5)),yl,h);
250
                        }else {
251
                                drawNameLegend(g, layer.getName(), re, sizefont,
252
                                                (xl - (re.getWidth() / 5)), yl, h);
253
                        }
254
                        n[0]++;
255

    
256
                        for (int j = 0; j < cli.getValues().length; j++) {
257
                            dY = n[0] * h;
258

    
259
                            xl = (re.getX() + dX);
260
                            yl = (re.getY() + dY);
261

    
262
                            String s = cli.getDescriptions()[j];
263
                            if (layout!=null) {
264
                                    toFFrameText(layout,s,re,sizefont,xl,yl,h);
265
                            }else {
266
                                    drawNameLegend(g, s, re, sizefont, xl, yl, h);
267
                            }
268
                            // TODO: HACER ESTO BIEN PARA QUE FUNCIONE
269
                            // CON ISymbol
270
                            FSymbol fs2d = (FSymbol) cli.getSymbols()[j];
271
                            if (layout!=null) {
272
                                    toFFrameSymbol(layout,re,xl,yl,fs2d,sizefont, h);
273
                            }else {
274
                                    drawSymbolLegend(g, re, xl, yl, fs2d, sizefont,
275
                                                    h);
276
                            }
277
                            n[0]++;
278
                        }
279
                    } else {
280
                        double dX = 0;
281
                        double dY = n[0] * h;
282

    
283
                        double xl = (re.getX() + dX);
284
                        double yl = (re.getY() + dY);
285
                        if (layout!=null) {
286
                                toFFrameText(layout,layer.getName(),re,sizefont,xl,yl,h);
287
                        }else {
288
                                drawNameLegend(g, layer.getName(), re, sizefont, xl,
289
                                                yl, h);
290
                        }
291
                        // TODO: CAMBIAR TODO ESTO PARA QUE ACEPTE ISYMBOL
292
                        FSymbol fs2d = (FSymbol) ((Classifiable) cO).getLegend()
293
                                        .getDefaultSymbol();
294

    
295
                        if (layout!=null) {
296
                                toFFrameSymbol(layout,re,xl,yl,fs2d,sizefont, h);
297
                        }else {
298
                                drawSymbolLegend(g, re, xl, yl, fs2d, sizefont,
299
                                                h);
300
                        }
301
                        n[0]++;
302
                    }
303
                }else{
304
                        double dX = 0;
305
                    double dY = n[0] * h;
306

    
307
                    double xl = (re.getX() + dX);
308
                    double yl = (re.getY() + dY);
309
                    if (layout!=null) {
310
                            toFFrameText(layout,layer.getName(),re,sizefont,xl,yl,h);
311
                    }else {
312
                            drawNameLegend(g, layer.getName(), re, sizefont, xl,
313
                                            yl, h);
314
                    }
315
                    n[0]++;
316
                }
317
            }
318
        }
319
    }
320

    
321
    /**
322
     * Dibuja sobre el graphics el nombre de la capa que se pasa como
323
     * par?metro.
324
     *
325
     * @param g Graphics2D sobre el que dibujar.
326
     * @param name Nombre de la capa.
327
     * @param re Rect?ngulo a ocupar por el nombre.
328
     * @param sizefont tama?o de la fuente.
329
     * @param x Posici?n X.
330
     * @param y Posici?n Y.
331
     * @param h Altura.
332
     */
333
    private void drawNameLegend(Graphics2D g, String name, Rectangle2D re,
334
        float sizefont, double x, double y, double h) {
335
        Font f = getFont(sizefont);
336
        g.setFont(f);
337
        g.setColor(Color.black);
338
        g.drawString(name, (float) (x + (re.getWidth() / 4)),
339
            (float) (y + (h / 2)));
340
    }
341

    
342
    private Font getFont(float sizefont) {
343
                Font f=getFont();
344
                return new Font(f.getName(),f.getStyle(),(int)sizefont);
345
  }
346

    
347
        /**
348
     * A?ade al Layout un nuevo FFrameText a partir de los par?metros de
349
     * entrada.
350
     *
351
     * @param layout Layout sobre el que se crea el nuevo FFrame.
352
         * @param name Texto.
353
         * @param sizefont tama?o de la fuente.
354
         * @param x Posici?n X.
355
         * @param y Posici?n Y.
356
         * @param h Altura.
357
         * @param wT Rect?ngulo del FFrame.
358
         * @param hT DOCUMENT ME!
359
     */
360
  /*  private void toFFrameText(Layout layout, String name, double wT, double hT,
361
        float sizefont, double x, double y, double h) {
362
        double wl = (wT / 1.5);
363
        double haux = hT / (m_numLayers * 1.3); //(sizefont * 0.7);
364

365
        if (haux > (wl / 3)) {
366
            haux = wl / 3;
367
        }
368

369
        Rectangle2D rAux = new Rectangle2D.Double(x, ((y + (h / 2)) - haux),
370
                wl, haux);
371
        FFrameText text = new FFrameText();
372
        text.setFixedFontSize(true);
373
        text.setFontSize((int) sizefont);
374
        text.setBoundBox(FLayoutUtilities.toSheetRect(rAux, layout.getAT()));
375
        text.addText(name);
376
        layout.addFFrame(text, false, true);
377
    }*/
378
    private void toFFrameText(Layout layout, String name, Rectangle2D re,
379
            float sizefont, double x, double y, double h) {
380
            //Font f = getFont(sizefont);
381
            Rectangle2D rAux = new Rectangle2D.Double(x+re.getWidth()/4, ((y + (h / 2)) - h),
382
                    re.getWidth()-re.getWidth()/4, h);
383
            FFrameText text = new FFrameText();
384
            text.setFixedFontSize(true);
385
            //text.setFontSize((int) (sizefont*1.4));
386
            double myScale = layout.getAT().getScaleX() * 0.0234;
387
            text.setFontSize((int)(sizefont/myScale));
388
            text.setBoundBox(FLayoutUtilities.toSheetRect(rAux, layout.getAT()));
389
            text.addText(name);
390
            layout.addFFrame(text, false, true);
391
        }
392

    
393
    /**
394
     * Dibuja sobre el Graphics2D el s?mbolo.
395
     *
396
     * @param g Graphics2D.
397
     * @param re Rect?ngulo a cubrir por el s?mbolo.
398
     * @param x Posici?n X.
399
     * @param y Posici?n Y.
400
     * @param fs2d S?mbolo a dibujar.
401
     * @param sizefont Tama?o de la fuente.
402
     * @param h Altura.
403
     */
404
    private void drawSymbolLegend(Graphics2D g, Rectangle2D re, double x,
405
        double y, FSymbol fs2d, float sizefont, double h) {
406
        double pW = 5;
407
        double wl = (re.getWidth() / pW);
408
        double haux = (sizefont * 0.7);
409
        Font font = fs2d.getFont();
410

    
411
        if (font != null) {
412
            fs2d.setFont(new Font(font.getFontName(), font.getStyle(),
413
                    (int) (wl / 6)));
414
        }
415

    
416
        FGraphicUtilities.DrawSymbol(g, new AffineTransform(),
417
            new Rectangle((int) x, (int) ((y + (h / 2)) - haux), (int) wl,
418
                (int) haux), fs2d);
419
    }
420

    
421
    /**
422
     * A?ade al Layout un nuevo FFrameSymbol.
423
     *
424
     * @param layout Layout sobe el que se a?ade el FFrame.
425
     * @param x Posici?n X.
426
     * @param y Posici?n Y.
427
     * @param fs2d S?mbolo a a?adir.
428
     * @param h Altura.
429
     * @param wT Rect?ngulo del FFrame.
430
     * @param hT tama?o de la fuente.
431
     */
432
   /* private void toFFrameSymbol(Layout layout, double wT, double hT, double x,
433
        double y, FSymbol fs2d, int type, double h) {
434
        double pW = 5;
435
        double wl = (wT / pW);
436
        double haux = hT / (m_numLayers * 1.3); //(sizefont * 0.7);
437

438
        if (haux > (wT / 4.5)) {
439
            haux = wT / 4.5;
440
        }
441

442
        Rectangle2D rAux3 = new Rectangle2D.Double(x, ((y + (h / 2)) - haux),
443
                wl, haux);
444
        FFrameSymbol symbol = new FFrameSymbol();
445
        symbol.setBoundBox(FLayoutUtilities.toSheetRect(rAux3, layout.getAT()));
446
        symbol.setSymbol(fs2d, type);
447
        layout.addFFrame(symbol, false, true);
448
    }*/
449
    private void toFFrameSymbol(Layout layout, Rectangle2D re, double x,
450
            double y, FSymbol fs2d, float sizefont, double h) {
451
            double pW = 5;
452
            double wl = (re.getWidth() / pW);
453
            double haux = (sizefont * 0.7);
454
            Font font = fs2d.getFont();
455

    
456
            if (font != null) {
457
                fs2d.setFont(new Font(font.getFontName(), font.getStyle(),
458
                        (int) (wl / 6)));
459
            }
460

    
461
            Rectangle2D rAux3 = new Rectangle2D.Double(x, ((y + (h / 2)) - haux),
462
                    wl, haux);
463
            FFrameSymbol symbol = new FFrameSymbol();
464
            symbol.setBoundBox(FLayoutUtilities.toSheetRect(rAux3, layout.getAT()));
465
            symbol.setFSymbol(fs2d);
466
            layout.addFFrame(symbol, false, true);
467
        }
468

    
469
    /**
470
     * Devuelve el n?mero total de capas incluyendo las subcapas.
471
     *
472
     * @param layers Capa a contar.
473
     *
474
     * @return N?mero de capas y subcapas.
475
     */
476
    private int getSizeNum(FLayers layers) {
477
        int n = 0;
478

    
479
        /////Aqu? hay que calcular cuantos layers y sublayers hay, para saber que distancias dejar entre uno y otro.
480
        ///y adem?s el tama?o de cada uno de ellos para saber que anchura dejar.
481
        int l=0;
482
        for (int i = layers.getLayersCount()-1; i>=0; i--) {
483
            FLayer layer = layers.getLayer(i);
484
            boolean b=false;
485
            if (nameLayers.size()>l && nameLayers.get(l).equals(layer.getName())) {
486
                    b=((Boolean)areVisible.get(l)).booleanValue();
487
            }else {
488
                    b=layer.isVisible();
489
            }
490
            l++;
491
            if (b) {
492
            //if (layer.isVisible()) {
493
                if (layer.getName().length() > m_max) {
494
                    m_max = layer.getName().length();
495
                }
496

    
497
                if (layer instanceof FLayers) {
498
                    //n++;
499
                        n = n + 3;
500
                    n += getSizeNum((FLayers) layer); //m_numLayers += getNumInLyrGroup((FLayers) layer);
501
                } else {
502
                        if (layer instanceof AlphanumericData) {
503
                    AlphanumericData cO = (AlphanumericData) layer;
504
                    n++;
505

    
506
                    if (((Classifiable) cO).getLegend() instanceof ClassifiedLegendInfo && !(cO instanceof FLyrAnnotation)) {
507
                        ClassifiedLegendInfo cli = (ClassifiedLegendInfo) ((Classifiable) cO).getLegend();
508

    
509
                        for (int j = 0; j < cli.getValues().length; j++) {
510
                            String s = cli.getDescriptions()[j];
511

    
512
                            if (s.length() > m_max) {
513
                                m_max = s.length();
514
                            }
515

    
516
                            n++;
517
                        }
518
                    }
519
                        }else{
520
                                  String s = layer.getName();
521

    
522
                          if (s.length() > m_max) {
523
                              m_max = s.length();
524
                          }
525

    
526
                          n++;
527
                        }
528

    
529
                }
530
            }
531
        }
532

    
533
        return n;
534
    }
535

    
536
    /**
537
     * Transforma el FFrameLegend en diferentes FFrameSymbol y FFrameText.
538
     *
539
     * @param layout Layout sobre el que a?adir los FFrame nuevos y sobre el
540
     *        que elimnar el FFrameLegend anterior.
541
     */
542
    public void toFFrames(Layout layout) {
543
        Rectangle2D rectangle = getBoundingBox(null);
544
        //Rectangle2D r = getBoundBox();
545
        double h = rectangle.getHeight() / m_numLayers;
546
        FLayers lays = layers;
547

    
548
        //layout.getEFS().startComplexCommand();
549
        //toFFrames(layout, lays, rectangle, r.getWidth(), r.getHeight(), h, 0);
550
        int[] n = new int[1];
551
        n[0] = 0;
552
        try {
553
                        drawLegendOrToFFrame(null,rectangle,h,lays,n,layout);
554
                } catch (DriverException e) {
555
                        e.printStackTrace();
556
                }
557
        layout.delFFrame(this);
558

    
559
        ///layout.getFFrames().remove(this);
560
        //layout.getEFS().endComplexCommand();
561
    }
562

    
563
    /**
564
     * Transforma el FFrameLegend en diferentes FFrameSymbol y FFrameText.
565
     *
566
     * @param layout Referencia al Layout.
567
     * @param lays Layers a a?adir
568
     * @param rectangle Rect?ngulo del FFrameLegend.
569
     * @param wT DOCUMENT ME!
570
     * @param hT DOCUMENT ME!
571
     * @param h Altura
572
     * @param n n?mero de Capa a?adida.
573
     *
574
     * @return n?mero de Capa a a?adir.
575
     */
576
 /*   public int toFFrames(Layout layout, FLayers lays, Rectangle2D rectangle,
577
        double wT, double hT, double h, int n) {
578
        int N = 39;
579
        float sizefont = 0;
580

581
        if ((rectangle.getHeight() / m_numLayers) < ((wT * N) / (m_max * 0.7))) {
582
            sizefont = (float) ((hT * N) / m_numLayers);
583
        } else {
584
            sizefont = (float) ((wT * N) / (m_max * 0.7));
585
        }
586

587
        //////        Se recorren los layers dibujando el s?mbolo y su nombre sobre el graphics
588
        for (int i = 0; i < lays.getLayersCount(); i++) {
589
            FLayer layer = (FLayer) lays.getLayer(i);
590

591
            if (layer.isVisible()) {
592
                if (layer instanceof FLayers) {
593
                    rectangle.setRect(rectangle.getX(),
594
                        rectangle.getY() + (h * n), wT, rectangle.getHeight());
595
                    n += toFFrames(layout, lays, rectangle, wT, hT, h, n); //drawTheme(g, re, h, layers, n);
596
                } else if (layer instanceof AlphanumericData) {
597
                    AlphanumericData cO = (AlphanumericData) layer;
598

599
                    if (((Classifiable) cO).getLegend() instanceof ClassifiedLegendInfo) {
600
                        ClassifiedLegendInfo cli = (ClassifiedLegendInfo) ((Classifiable) cO).getLegend();
601
                        double dX = rectangle.getWidth() / 4;
602
                        double dY = n * h;
603

604
                        double xl = (rectangle.getX() + dX);
605
                        double yl = (rectangle.getY() + dY);
606
                        toFFrameText(layout, layer.getName(),
607
                            rectangle.getWidth(), rectangle.getHeight(),
608
                            sizefont, xl, yl, h);
609
                        n++;
610

611
                        for (int j = 0; j < cli.getValues().length; j++) {
612
                            dY = n * h;
613

614
                            xl = (rectangle.getX() + dX);
615
                            yl = (rectangle.getY() + dY);
616

617
                            String s = cli.getDescriptions()[j];
618
                            toFFrameText(layout, s, rectangle.getWidth(),
619
                                rectangle.getHeight(), sizefont, xl, yl, h);
620

621
                            FSymbol fs2d = cli.getSymbols()[j];
622

623
                            try {
624
//                                toFFrameSymbol(layout, rectangle.getWidth(),
625
//                                    rectangle.getHeight(), rectangle.getX(),
626
//                                    yl, fs2d,
627
//                                    ((Classifiable) cO).getShapeType(), h);
628
                                    toFFrameSymbol(layout, rectangle,
629
                                        rectangle.getHeight(), rectangle.getX(),
630
                                        yl, fs2d,
631
                                        ((Classifiable) cO).getShapeType(), h);
632
                            } catch (DriverException e) {
633
                                e.printStackTrace();
634
                            }
635

636
                            n++;
637
                        }
638
                    } else {
639
                        double dX = rectangle.getWidth() / 4;
640
                        double dY = n * h;
641

642
                        double xl = (rectangle.getX() + dX);
643
                        double yl = (rectangle.getY() + dY);
644

645
                        toFFrameText(layout, layer.getName(),
646
                            rectangle.getWidth(), rectangle.getHeight(),
647
                            sizefont, xl, yl, h);
648

649
                        FSymbol fs2d = ((Classifiable) cO).getLegend()
650
                                        .getDefaultSymbol();
651

652
                        try {
653
                            toFFrameSymbol(layout, rectangle.getWidth(),
654
                                rectangle.getHeight(), rectangle.getX(), yl,
655
                                fs2d, ((Classifiable) cO).getShapeType(), h);
656
                        } catch (DriverException e) {
657
                            e.printStackTrace();
658
                        }
659

660
                        n++;
661
                    }
662
                }
663
            }
664
        }
665

666
        return n;
667
    }
668
*/
669
    /**
670
     * Rellena la fuente a utilizar al dibujar los String sobre el graphics.
671
     *
672
     * @param f Font.
673
     */
674
    public void setFont(Font f) {
675
        m_f = f;
676
    }
677

    
678
    /**
679
     * Devuelve la fuente que esta utilizando.
680
     *
681
     * @return Font.
682
     */
683
    public Font getFont() {
684
        if (m_f != null) {
685
                return new Font(m_f.getName(),m_f.getStyle(),9);
686
        //    return new Font(m_f.getFontName(), m_f.getStyle(), 9);
687
        }
688
        return new Font("SansSerif",Font.PLAIN,9);
689
    }
690

    
691
    /**
692
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#getXMLEntity()
693
     */
694
    public XMLEntity getXMLEntity() throws SaveException {
695
        XMLEntity xml = super.getXMLEntity();
696

    
697
        try {
698
            xml.putProperty("type", Layout.RECTANGLELEGEND);
699
            xml.putProperty("m_numLayers", m_numLayers);
700
            xml.putProperty("m_max", m_max);
701
            xml.putProperty("m_quality", m_quality);
702
            xml.putProperty("m_viewing", m_viewing);
703
            xml.putProperty("fontName", m_f.getFontName());
704
            xml.putProperty("fontStyle", m_f.getStyle());
705

    
706
            if (fframeview != null) {
707
                Layout layout = fframeview.getLayout();
708
                IFFrame[] fframes = layout.getAllFFrames();
709

    
710
                for (int i = 0; i < fframes.length; i++) {
711
                    if (fframeview.equals(fframes[i])) {
712
                        xml.putProperty("index", i);
713
                        break;
714
                    }
715
                }
716
            }
717

    
718
            String[] s=new String[nameLayers.size()];
719
            boolean[] b=new boolean[nameLayers.size()];
720
            for (int i=0;i<nameLayers.size();i++) {
721
                    String k=(String)nameLayers.get(i);
722
                    s[i]=k;
723
                    b[i]=((Boolean)areVisible.get(i)).booleanValue();
724
            }
725
            xml.putProperty("nameLayers",s);
726
            xml.putProperty("areVisible",b);
727
        } catch (Exception e) {
728
            throw new SaveException(e, this.getClass().getName());
729
        }
730

    
731
        return xml;
732
    }
733

    
734
    /**
735
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
736
     *      com.iver.cit.gvsig.project.Project)
737
     */
738
    public void setXMLEntity03(XMLEntity xml, Layout l) {
739
        if (xml.getIntProperty("m_Selected") != 0) {
740
            this.setSelected(true);
741
        } else {
742
            this.setSelected(false);
743
        }
744

    
745
        this.m_numLayers = xml.getIntProperty("m_numLayers");
746
        this.m_max = xml.getIntProperty("m_max");
747
        this.m_quality = xml.getIntProperty("m_quality");
748
        this.m_viewing = xml.getIntProperty("m_viewing");
749
        this.m_f = new Font(xml.getStringProperty("fontName"),
750
                xml.getIntProperty("fontStyle"), 9);
751

    
752
        if (xml.contains("index")) {
753
            fframeview = (FFrameView) l.getFFrame(xml.getIntProperty("index"));
754
        }
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 setXMLEntity(XMLEntity xml) {
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
        setRotation(xml.getDoubleProperty("m_rotation"));
775

    
776
        if (xml.contains("index")) {
777
            dependenceIndex = xml.getIntProperty("index");
778
        }
779
        if (xml.contains("nameLayers")) {
780
                String[] s=xml.getStringArrayProperty("nameLayers");
781
                boolean[] b=xml.getBooleanArrayProperty("areVisible");
782
                for (int i=0;i<s.length;i++) {
783
                        nameLayers.add(s[i]);
784
                        areVisible.add(new Boolean(b[i]));
785
                }
786
        }
787
    }
788

    
789
    /**
790
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#getNameFFrame()
791
     */
792
    public String getNameFFrame() {
793
        return PluginServices.getText(this, "leyenda")+ num;
794
    }
795

    
796
    /**
797
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#print(java.awt.Graphics2D,
798
     *      java.awt.geom.AffineTransform)
799
     */
800
    public void print(Graphics2D g, AffineTransform at)
801
        throws DriverException {
802
        draw(g, at, null, null);
803
    }
804

    
805
    /**
806
     * Actualiza las dependencias que tenga este FFrame con el resto.
807
     *
808
     * @param fframes Resto de FFrames.
809
     */
810
    public void initDependence(IFFrame[] fframes) {
811
        if ((dependenceIndex != -1) &&
812
                fframes[dependenceIndex] instanceof FFrameView) {
813
            fframeview = (FFrameView) fframes[dependenceIndex];
814
        }
815
    }
816

    
817
        public void initialize() {
818
                // TODO Auto-generated method stub
819

    
820
        }
821

    
822
        public void setNameLayers(ArrayList nameLayers) {
823
                this.nameLayers=nameLayers;
824
        }
825

    
826
        public void setAreVisible(ArrayList areVisible) {
827
                this.areVisible=areVisible;
828
        }
829

    
830
        public ArrayList getNameLayers() {
831
                return nameLayers;
832
        }
833

    
834
        public ArrayList getAreVisible() {
835
                return areVisible;
836
        }
837
}