Statistics
| Revision:

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

History | View | Annotate | Download (28.7 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
import java.util.ArrayList;
68
import java.util.HashMap;
69
import java.util.Set;
70

    
71
import org.apache.batik.dom.util.HashTable;
72

    
73

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

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

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

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

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

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

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

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

    
166
        if ((fframeview != null) && (fframeview.getFMap() != null)) {
167
            layers = fframeview.getFMap().getLayers();
168
        }
169

    
170
        m_max = 0;
171
        m_numLayers = 0;
172

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

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

    
188
        g.rotate(Math.toRadians(-getRotation()), re.x + (re.width / 2),
189
            re.y + (re.height / 2));
190
    }
191

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

    
208
        if ((re.getHeight() / m_numLayers) < (re.getWidth() / (m_max * 0.7))) {
209
            sizefont = (float) (re.getHeight() / m_numLayers);
210
        } else {
211
            sizefont = (float) (re.getWidth() / (m_max * 0.7));
212
        }
213

    
214
        int l=0;
215
        //////Se recorren los layers dibujando el s?mbolo y su nombre sobre el graphics
216
        for (int i = layers.getLayersCount() - 1; i >= 0; i--) {
217
            FLayer layer = (FLayer) layers.getLayer(i);
218
            boolean b=false;
219

    
220
            if (nameLayers.size()>l && nameLayers.get(l).equals(layer.getName())) {
221
                    b=((Boolean)areVisible.get(l)).booleanValue();
222
            }else {
223
                    b=layer.isVisible();
224
            }
225
            l++;
226
            if (b) {
227
                if (layer instanceof FLayers) {
228
                    n[0]++;
229

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

    
246
                    if (((Classifiable) cO).getLegend() instanceof ClassifiedLegendInfo && !(cO instanceof FLyrAnnotation)) {
247
                        ClassifiedLegendInfo cli = (ClassifiedLegendInfo) ((Classifiable) cO).getLegend();
248
                        double dX = 0;
249
                        double dY = n[0] * h;
250

    
251
                        double xl = (re.getX() + dX);
252
                        double yl = (re.getY() + dY);
253
                        if (layout!=null) {
254
                                toFFrameText(layout,layer.getName(),re,sizefont,(xl - (re.getWidth() / 5)),yl,h, typeFont);
255
                        }else {
256
                                drawNameLegend(g, layer.getName(), re, sizefont,
257
                                                (xl - (re.getWidth() / 5)), yl, h, typeFont);
258
                        }
259
                        n[0]++;
260

    
261
                        for (int j = 0; j < cli.getValues().length; j++) {
262
                            dY = n[0] * h;
263

    
264
                            xl = (re.getX() + dX);
265
                            yl = (re.getY() + dY);
266

    
267
                            String s = cli.getDescriptions()[j];
268
                            if (layout!=null) {
269
                                    toFFrameText(layout,s,re,sizefont,xl,yl,h, typeFont);
270
                            }else {
271
                                    drawNameLegend(g, s, re, sizefont, xl, yl, h,
272
                                                    typeFont);
273
                            }
274
                            FSymbol fs2d = cli.getSymbols()[j];
275
                            if (layout!=null) {
276
                                    toFFrameSymbol(layout,re,xl,yl,fs2d,sizefont, ((Classifiable) cO).getShapeType(),h);
277
                            }else {
278
                                    drawSymbolLegend(g, re, xl, yl, fs2d, sizefont,
279
                                                    ((Classifiable) cO).getShapeType(), h);
280
                            }
281
                            n[0]++;
282
                        }
283
                    } else {
284
                        double dX = 0;
285
                        double dY = n[0] * h;
286

    
287
                        double xl = (re.getX() + dX);
288
                        double yl = (re.getY() + dY);
289
                        if (layout!=null) {
290
                                toFFrameText(layout,layer.getName(),re,sizefont,xl,yl,h, typeFont);
291
                        }else {
292
                                drawNameLegend(g, layer.getName(), re, sizefont, xl,
293
                                                yl, h, typeFont);
294
                        }
295
                        FSymbol fs2d = ((Classifiable) cO).getLegend()
296
                                        .getDefaultSymbol();
297

    
298
                        if (layout!=null) {
299
                                toFFrameSymbol(layout,re,xl,yl,fs2d,sizefont, ((Classifiable) cO).getShapeType(),h);
300
                        }else {
301
                                drawSymbolLegend(g, re, xl, yl, fs2d, sizefont,
302
                                                ((Classifiable) cO).getShapeType(), h);
303
                        }
304
                        n[0]++;
305
                    }
306
                }
307
            }
308
        }
309
    }
310

    
311
    /**
312
     * Dibuja sobre el graphics el nombre de la capa que se pasa como
313
     * par?metro.
314
     *
315
     * @param g Graphics2D sobre el que dibujar.
316
     * @param name Nombre de la capa.
317
     * @param re Rect?ngulo a ocupar por el nombre.
318
     * @param sizefont tama?o de la fuente.
319
     * @param x Posici?n X.
320
     * @param y Posici?n Y.
321
     * @param h Altura.
322
     * @param typeFont DOCUMENT ME!
323
     */
324
    private void drawNameLegend(Graphics2D g, String name, Rectangle2D re,
325
        float sizefont, double x, double y, double h, int typeFont) {
326
        Font f = getFont(sizefont);
327
        g.setFont(f);
328
        g.setColor(Color.black);
329
        g.drawString(name, (float) (x + (re.getWidth() / 4)),
330
            (float) (y + (h / 2)));
331
    }
332

    
333
    private Font getFont(float sizefont) {
334
                Font f=getFont();
335
                return new Font(f.getName(),f.getStyle(),(int)sizefont);
336
  }
337

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

356
        if (haux > (wl / 3)) {
357
            haux = wl / 3;
358
        }
359

360
        Rectangle2D rAux = new Rectangle2D.Double(x, ((y + (h / 2)) - haux),
361
                wl, haux);
362
        FFrameText text = new FFrameText();
363
        text.setFixedFontSize(true);
364
        text.setFontSize((int) sizefont);
365
        text.setBoundBox(FLayoutUtilities.toSheetRect(rAux, layout.getAT()));
366
        text.addText(name);
367
        layout.addFFrame(text, false, true);
368
    }*/
369
    private void toFFrameText(Layout layout, String name, Rectangle2D re,
370
            float sizefont, double x, double y, double h, int typeFont) {
371
            //Font f = getFont(sizefont);
372
            Rectangle2D rAux = new Rectangle2D.Double(x+re.getWidth()/4, ((y + (h / 2)) - h),
373
                    re.getWidth()-re.getWidth()/4, h);
374
            FFrameText text = new FFrameText();
375
            text.setFixedFontSize(true);
376
            text.setFontSize((int) (sizefont*1.4));
377
            text.setBoundBox(FLayoutUtilities.toSheetRect(rAux, layout.getAT()));
378
            text.addText(name);
379
            layout.addFFrame(text, false, true);
380
        }
381

    
382
    /**
383
     * Dibuja sobre el Graphics2D el s?mbolo.
384
     *
385
     * @param g Graphics2D.
386
     * @param re Rect?ngulo a cubrir por el s?mbolo.
387
     * @param x Posici?n X.
388
     * @param y Posici?n Y.
389
     * @param fs2d S?mbolo a dibujar.
390
     * @param sizefont Tama?o de la fuente.
391
     * @param type Tipo de s?mbolo.
392
     * @param h Altura.
393
     */
394
    private void drawSymbolLegend(Graphics2D g, Rectangle2D re, double x,
395
        double y, FSymbol fs2d, float sizefont, int type, double h) {
396
        double pW = 5;
397
        double wl = (re.getWidth() / pW);
398
        double haux = (sizefont * 0.7);
399
        Font font = fs2d.getFont();
400

    
401
        if (font != null) {
402
            fs2d.setFont(new Font(font.getFontName(), font.getStyle(),
403
                    (int) (wl / 6)));
404
        }
405

    
406
        FGraphicUtilities.DrawSymbol(g, new AffineTransform(),
407
            new Rectangle((int) x, (int) ((y + (h / 2)) - haux), (int) wl,
408
                (int) haux), fs2d);
409
    }
410

    
411
    /**
412
     * A?ade al Layout un nuevo FFrameSymbol.
413
     *
414
     * @param layout Layout sobe el que se a?ade el FFrame.
415
     * @param wT Rect?ngulo del FFrame.
416
     * @param hT tama?o de la fuente.
417
     * @param x Posici?n X.
418
     * @param y Posici?n Y.
419
     * @param fs2d S?mbolo a a?adir.
420
     * @param type Tipo de s?mbolo.
421
     * @param h Altura.
422
     */
423
   /* private void toFFrameSymbol(Layout layout, double wT, double hT, double x,
424
        double y, FSymbol fs2d, int type, double h) {
425
        double pW = 5;
426
        double wl = (wT / pW);
427
        double haux = hT / (m_numLayers * 1.3); //(sizefont * 0.7);
428

429
        if (haux > (wT / 4.5)) {
430
            haux = wT / 4.5;
431
        }
432

433
        Rectangle2D rAux3 = new Rectangle2D.Double(x, ((y + (h / 2)) - haux),
434
                wl, haux);
435
        FFrameSymbol symbol = new FFrameSymbol();
436
        symbol.setBoundBox(FLayoutUtilities.toSheetRect(rAux3, layout.getAT()));
437
        symbol.setSymbol(fs2d, type);
438
        layout.addFFrame(symbol, false, true);
439
    }*/
440
    private void toFFrameSymbol(Layout layout, Rectangle2D re, double x,
441
            double y, FSymbol fs2d, float sizefont, int type, double h) {
442
            double pW = 5;
443
            double wl = (re.getWidth() / pW);
444
            double haux = (sizefont * 0.7);
445
            Font font = fs2d.getFont();
446

    
447
            if (font != null) {
448
                fs2d.setFont(new Font(font.getFontName(), font.getStyle(),
449
                        (int) (wl / 6)));
450
            }
451

    
452
            Rectangle2D rAux3 = new Rectangle2D.Double(x, ((y + (h / 2)) - haux),
453
                    wl, haux);
454
            FFrameSymbol symbol = new FFrameSymbol();
455
            symbol.setBoundBox(FLayoutUtilities.toSheetRect(rAux3, layout.getAT()));
456
            symbol.setFSymbol(fs2d);
457
            layout.addFFrame(symbol, false, true);
458
        }
459

    
460
    /**
461
     * Devuelve el n?mero total de capas incluyendo las subcapas.
462
     *
463
     * @param layers Capa a contar.
464
     *
465
     * @return N?mero de capas y subcapas.
466
     */
467
    private int getSizeNum(FLayers layers) {
468
        int n = 0;
469

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

    
488
                if (layer instanceof FLayers) {
489
                    n = n + 3;
490
                    n += getSizeNum((FLayers) layer); //m_numLayers += getNumInLyrGroup((FLayers) layer);
491
                } else if (layer instanceof AlphanumericData) {
492
                    AlphanumericData cO = (AlphanumericData) layer;
493
                    n++;
494

    
495
                    if (((Classifiable) cO).getLegend() instanceof ClassifiedLegendInfo && !(cO instanceof FLyrAnnotation)) {
496
                        ClassifiedLegendInfo cli = (ClassifiedLegendInfo) ((Classifiable) cO).getLegend();
497

    
498
                        for (int j = 0; j < cli.getValues().length; j++) {
499
                            String s = cli.getDescriptions()[j];
500

    
501
                            if (s.length() > m_max) {
502
                                m_max = s.length();
503
                            }
504

    
505
                            n++;
506
                        }
507
                    }
508
                }
509
            }
510
        }
511

    
512
        return n;
513
    }
514

    
515
    /**
516
     * Transforma el FFrameLegend en diferentes FFrameSymbol y FFrameText.
517
     *
518
     * @param layout Layout sobre el que a?adir los FFrame nuevos y sobre el
519
     *        que elimnar el FFrameLegend anterior.
520
     */
521
    public void toFFrames(Layout layout) {
522
        Rectangle2D rectangle = getBoundingBox(null);
523
        //Rectangle2D r = getBoundBox();
524
        double h = rectangle.getHeight() / m_numLayers;
525
        FLayers lays = layers;
526

    
527
        //layout.getEFS().startComplexCommand();
528
        //toFFrames(layout, lays, rectangle, r.getWidth(), r.getHeight(), h, 0);
529
        int[] n = new int[1];
530
        n[0] = 0;
531
        try {
532
                        drawLegendOrToFFrame(null,rectangle,h,lays,n,Font.PLAIN,layout);
533
                } catch (DriverException e) {
534
                        e.printStackTrace();
535
                }
536
        layout.delFFrame(this);
537

    
538
        ///layout.getFFrames().remove(this);
539
        //layout.getEFS().endComplexCommand();
540
    }
541

    
542
    /**
543
     * Transforma el FFrameLegend en diferentes FFrameSymbol y FFrameText.
544
     *
545
     * @param layout Referencia al Layout.
546
     * @param lays Layers a a?adir
547
     * @param rectangle Rect?ngulo del FFrameLegend.
548
     * @param wT DOCUMENT ME!
549
     * @param hT DOCUMENT ME!
550
     * @param h Altura
551
     * @param n n?mero de Capa a?adida.
552
     *
553
     * @return n?mero de Capa a a?adir.
554
     */
555
 /*   public int toFFrames(Layout layout, FLayers lays, Rectangle2D rectangle,
556
        double wT, double hT, double h, int n) {
557
        int N = 39;
558
        float sizefont = 0;
559

560
        if ((rectangle.getHeight() / m_numLayers) < ((wT * N) / (m_max * 0.7))) {
561
            sizefont = (float) ((hT * N) / m_numLayers);
562
        } else {
563
            sizefont = (float) ((wT * N) / (m_max * 0.7));
564
        }
565

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

570
            if (layer.isVisible()) {
571
                if (layer instanceof FLayers) {
572
                    rectangle.setRect(rectangle.getX(),
573
                        rectangle.getY() + (h * n), wT, rectangle.getHeight());
574
                    n += toFFrames(layout, lays, rectangle, wT, hT, h, n); //drawTheme(g, re, h, layers, n);
575
                } else if (layer instanceof AlphanumericData) {
576
                    AlphanumericData cO = (AlphanumericData) layer;
577

578
                    if (((Classifiable) cO).getLegend() instanceof ClassifiedLegendInfo) {
579
                        ClassifiedLegendInfo cli = (ClassifiedLegendInfo) ((Classifiable) cO).getLegend();
580
                        double dX = rectangle.getWidth() / 4;
581
                        double dY = n * h;
582

583
                        double xl = (rectangle.getX() + dX);
584
                        double yl = (rectangle.getY() + dY);
585
                        toFFrameText(layout, layer.getName(),
586
                            rectangle.getWidth(), rectangle.getHeight(),
587
                            sizefont, xl, yl, h);
588
                        n++;
589

590
                        for (int j = 0; j < cli.getValues().length; j++) {
591
                            dY = n * h;
592

593
                            xl = (rectangle.getX() + dX);
594
                            yl = (rectangle.getY() + dY);
595

596
                            String s = cli.getDescriptions()[j];
597
                            toFFrameText(layout, s, rectangle.getWidth(),
598
                                rectangle.getHeight(), sizefont, xl, yl, h);
599

600
                            FSymbol fs2d = cli.getSymbols()[j];
601

602
                            try {
603
//                                toFFrameSymbol(layout, rectangle.getWidth(),
604
//                                    rectangle.getHeight(), rectangle.getX(),
605
//                                    yl, fs2d,
606
//                                    ((Classifiable) cO).getShapeType(), h);
607
                                    toFFrameSymbol(layout, rectangle,
608
                                        rectangle.getHeight(), rectangle.getX(),
609
                                        yl, fs2d,
610
                                        ((Classifiable) cO).getShapeType(), h);
611
                            } catch (DriverException e) {
612
                                e.printStackTrace();
613
                            }
614

615
                            n++;
616
                        }
617
                    } else {
618
                        double dX = rectangle.getWidth() / 4;
619
                        double dY = n * h;
620

621
                        double xl = (rectangle.getX() + dX);
622
                        double yl = (rectangle.getY() + dY);
623

624
                        toFFrameText(layout, layer.getName(),
625
                            rectangle.getWidth(), rectangle.getHeight(),
626
                            sizefont, xl, yl, h);
627

628
                        FSymbol fs2d = ((Classifiable) cO).getLegend()
629
                                        .getDefaultSymbol();
630

631
                        try {
632
                            toFFrameSymbol(layout, rectangle.getWidth(),
633
                                rectangle.getHeight(), rectangle.getX(), yl,
634
                                fs2d, ((Classifiable) cO).getShapeType(), h);
635
                        } catch (DriverException e) {
636
                            e.printStackTrace();
637
                        }
638

639
                        n++;
640
                    }
641
                }
642
            }
643
        }
644

645
        return n;
646
    }
647
*/
648
    /**
649
     * Rellena la fuente a utilizar al dibujar los String sobre el graphics.
650
     *
651
     * @param f Font.
652
     */
653
    public void setFont(Font f) {
654
        m_f = f;
655
    }
656

    
657
    /**
658
     * Devuelve la fuente que esta utilizando.
659
     *
660
     * @return Font.
661
     */
662
    public Font getFont() {
663
        if (m_f != null) {
664
                return new Font(m_f.getName(),m_f.getStyle(),9);
665
        //    return new Font(m_f.getFontName(), m_f.getStyle(), 9);
666
        }
667
        return new Font("SansSerif",Font.PLAIN,9);
668
    }
669

    
670
    /**
671
     * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
672
     */
673
    public XMLEntity getXMLEntity() throws SaveException {
674
        XMLEntity xml = super.getXMLEntity();
675

    
676
        try {
677
            xml.putProperty("type", Layout.RECTANGLELEGEND);
678
            xml.putProperty("m_numLayers", m_numLayers);
679
            xml.putProperty("m_max", m_max);
680
            xml.putProperty("m_quality", m_quality);
681
            xml.putProperty("m_viewing", m_viewing);
682
            xml.putProperty("fontName", m_f.getFontName());
683
            xml.putProperty("fontStyle", m_f.getStyle());
684

    
685
            if (fframeview != null) {
686
                Layout layout = fframeview.getLayout();
687
                IFFrame[] fframes = layout.getAllFFrames();
688

    
689
                for (int i = 0; i < fframes.length; i++) {
690
                    if (fframeview.equals(fframes[i])) {
691
                        xml.putProperty("index", i);
692
                        break;
693
                    }
694
                }
695
            }
696

    
697
            String[] s=new String[nameLayers.size()];
698
            boolean[] b=new boolean[nameLayers.size()];
699
            for (int i=0;i<nameLayers.size();i++) {
700
                    String k=(String)nameLayers.get(i);
701
                    s[i]=k;
702
                    b[i]=((Boolean)areVisible.get(i)).booleanValue();
703
            }
704
            xml.putProperty("nameLayers",s);
705
            xml.putProperty("areVisible",b);
706
        } catch (Exception e) {
707
            throw new SaveException(e, this.getClass().getName());
708
        }
709

    
710
        return xml;
711
    }
712

    
713
    /**
714
     * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
715
     *      com.iver.cit.gvsig.project.Project)
716
     */
717
    public void setXMLEntity03(XMLEntity xml, Layout l) {
718
        if (xml.getIntProperty("m_Selected") != 0) {
719
            this.setSelected(true);
720
        } else {
721
            this.setSelected(false);
722
        }
723

    
724
        this.m_numLayers = xml.getIntProperty("m_numLayers");
725
        this.m_max = xml.getIntProperty("m_max");
726
        this.m_quality = xml.getIntProperty("m_quality");
727
        this.m_viewing = xml.getIntProperty("m_viewing");
728
        this.m_f = new Font(xml.getStringProperty("fontName"),
729
                xml.getIntProperty("fontStyle"), 9);
730

    
731
        if (xml.contains("index")) {
732
            fframeview = (FFrameView) l.getFFrame(xml.getIntProperty("index"));
733
        }
734
    }
735

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

    
747
        this.m_numLayers = xml.getIntProperty("m_numLayers");
748
        this.m_max = xml.getIntProperty("m_max");
749
        this.m_quality = xml.getIntProperty("m_quality");
750
        this.m_viewing = xml.getIntProperty("m_viewing");
751
        this.m_f = new Font(xml.getStringProperty("fontName"),
752
                xml.getIntProperty("fontStyle"), 9);
753
        setRotation(xml.getDoubleProperty("m_rotation"));
754

    
755
        if (xml.contains("index")) {
756
            dependenceIndex = xml.getIntProperty("index");
757
        }
758
        if (xml.contains("nameLayers")) {
759
                String[] s=xml.getStringArrayProperty("nameLayers");
760
                boolean[] b=xml.getBooleanArrayProperty("areVisible");
761
                for (int i=0;i<s.length;i++) {
762
                        nameLayers.add(s[i]);
763
                        areVisible.add(new Boolean(b[i]));
764
                }
765
        }
766
    }
767

    
768
    /**
769
     * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getNameFFrame()
770
     */
771
    public String getNameFFrame() {
772
        return PluginServices.getText(this, "leyenda")+ num;
773
    }
774

    
775
    /**
776
     * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#print(java.awt.Graphics2D,
777
     *      java.awt.geom.AffineTransform)
778
     */
779
    public void print(Graphics2D g, AffineTransform at)
780
        throws DriverException {
781
        draw(g, at, null, null);
782
    }
783

    
784
    /**
785
     * Actualiza las dependencias que tenga este FFrame con el resto.
786
     *
787
     * @param fframes Resto de FFrames.
788
     */
789
    public void initDependence(IFFrame[] fframes) {
790
        if ((dependenceIndex != -1) &&
791
                fframes[dependenceIndex] instanceof FFrameView) {
792
            fframeview = (FFrameView) fframes[dependenceIndex];
793
        }
794
    }
795

    
796
        public void initialize() {
797
                // TODO Auto-generated method stub
798

    
799
        }
800

    
801
        public void setNameLayers(ArrayList nameLayers) {
802
                this.nameLayers=nameLayers;
803
        }
804

    
805
        public void setAreVisible(ArrayList areVisible) {
806
                this.areVisible=areVisible;
807
        }
808

    
809
        public ArrayList getNameLayers() {
810
                return nameLayers;
811
        }
812

    
813
        public ArrayList getAreVisible() {
814
                return areVisible;
815
        }
816
}