Statistics
| Revision:

svn-gvsig-desktop / branches / simbologia / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / fframes / FFrameLegend.java @ 10437

History | View | Annotate | Download (31.6 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.project.documents.layout.fframes;
42

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

    
53
import com.iver.andami.PluginServices;
54
import com.iver.cit.gvsig.fmap.DriverException;
55
import com.iver.cit.gvsig.fmap.core.FShape;
56
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
57
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
58
import com.iver.cit.gvsig.fmap.layers.FLayer;
59
import com.iver.cit.gvsig.fmap.layers.FLayers;
60
import com.iver.cit.gvsig.fmap.layers.FLyrAnnotation;
61
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
62
import com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable;
63
import com.iver.cit.gvsig.fmap.layers.layerOperations.IHasImageLegend;
64
import com.iver.cit.gvsig.fmap.rendering.ClassifiedLegendInfo;
65
import com.iver.cit.gvsig.project.documents.exceptions.SaveException;
66
import com.iver.cit.gvsig.project.documents.layout.FLayoutUtilities;
67
import com.iver.cit.gvsig.project.documents.layout.LayoutContext;
68
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.FFrameLegendDialog;
69
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.IFFrameDialog;
70
import com.iver.cit.gvsig.project.documents.layout.gui.Layout;
71
import com.iver.utiles.XMLEntity;
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
        public FFrameLegend() {
94

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

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

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

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

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

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

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

    
169
        if ((fframeview != null) && (fframeview.getMapContext() != null)) {
170
            layers = fframeview.getMapContext().getLayers();
171
        }
172

    
173
        m_max = 0;
174
        m_numLayers = 0;
175

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

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

    
191
        g.rotate(Math.toRadians(-getRotation()), re.x + (re.width / 2),
192
            re.y + (re.height / 2));
193
    }
194

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

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

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

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

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

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

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

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

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

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

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

    
301
                        if (layout!=null) {
302
                                toFFrameSymbol(layout,re,xl,yl,fs2d,sizefont, h);
303
                        }else {
304
                                drawSymbolLegend(g, re, xl, yl, fs2d, sizefont,
305
                                                h);
306
                        }
307
                        n[0]++;
308
                    }
309
                }else if (layer instanceof IHasImageLegend){
310
                        Image image=((IHasImageLegend)layer).getImageLegend();
311
                        String path=((IHasImageLegend)layer).getPathImage();
312
                        if (image!=null) {
313
                        FFramePicture picture =(FFramePicture)FrameFactory.createFrameFromName(FFramePictureFactory.registerName);
314

    
315
                        picture.setLayout(getLayout());
316
                        BufferedImage bi = new BufferedImage(image.getWidth(null),
317
                            image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
318
                    Graphics2D biContext = bi.createGraphics();
319
                    biContext.drawImage(image, 0, 0, null);
320
                    picture.setImage(bi);
321
                    double dY = n[0] * h;
322
                    Rectangle2D rectImage=new Rectangle2D.Double(re.getX(),re.getY()+dY,re.getWidth(),h);
323
                   if (layout!=null) {
324
                            picture.setBoundBox(FLayoutUtilities.toSheetRect(rectImage, layout.getAT()));
325
                            picture.setPath(path);
326
                            layout.addFFrame(picture, false, true);
327
                    }else {
328
                            picture.setBoundBox(FLayoutUtilities.toSheetRect(rectImage,new AffineTransform()));
329
                        picture.draw(g,new AffineTransform(),re,bi);
330
                    }
331
                        }
332
                    n[0]++;
333
                }else {
334
                        double dX = 0;
335
                    double dY = n[0] * h;
336

    
337
                    double xl = (re.getX() + dX);
338
                    double yl = (re.getY() + dY);
339
                    if (layout!=null) {
340
                            toFFrameText(layout,layer.getName(),re,sizefont,xl,yl,h);
341
                    }else {
342
                            drawNameLegend(g, layer.getName(), re, sizefont, xl,
343
                                            yl, h);
344
                    }
345
                    n[0]++;
346
                }
347
            }
348
        }
349
    }
350

    
351
    /**
352
     * Dibuja sobre el graphics el nombre de la capa que se pasa como
353
     * par?metro.
354
     *
355
     * @param g Graphics2D sobre el que dibujar.
356
     * @param name Nombre de la capa.
357
     * @param re Rect?ngulo a ocupar por el nombre.
358
     * @param sizefont tama?o de la fuente.
359
     * @param x Posici?n X.
360
     * @param y Posici?n Y.
361
     * @param h Altura.
362
     */
363
    private void drawNameLegend(Graphics2D g, String name, Rectangle2D re,
364
        float sizefont, double x, double y, double h) {
365
        Font f = getFont(sizefont);
366
        g.setFont(f);
367
        g.setColor(Color.black);
368
        g.drawString(name, (float) (x + (re.getWidth() / 4)),
369
            (float) (y + (h / 2)));
370
    }
371

    
372
    private Font getFont(float sizefont) {
373
                Font f=getFont();
374
                return new Font(f.getName(),f.getStyle(),(int)sizefont);
375
  }
376

    
377
        /**
378
     * A?ade al Layout un nuevo FFrameText a partir de los par?metros de
379
     * entrada.
380
     *
381
     * @param layout Layout sobre el que se crea el nuevo FFrame.
382
         * @param name Texto.
383
         * @param sizefont tama?o de la fuente.
384
         * @param x Posici?n X.
385
         * @param y Posici?n Y.
386
         * @param h Altura.
387
         * @param wT Rect?ngulo del FFrame.
388
         * @param hT DOCUMENT ME!
389
     */
390
  /*  private void toFFrameText(Layout layout, String name, double wT, double hT,
391
        float sizefont, double x, double y, double h) {
392
        double wl = (wT / 1.5);
393
        double haux = hT / (m_numLayers * 1.3); //(sizefont * 0.7);
394

395
        if (haux > (wl / 3)) {
396
            haux = wl / 3;
397
        }
398

399
        Rectangle2D rAux = new Rectangle2D.Double(x, ((y + (h / 2)) - haux),
400
                wl, haux);
401
        FFrameText text = new FFrameText();
402
        text.setFixedFontSize(true);
403
        text.setFontSize((int) sizefont);
404
        text.setBoundBox(FLayoutUtilities.toSheetRect(rAux, layout.getAT()));
405
        text.addText(name);
406
        layout.addFFrame(text, false, true);
407
    }*/
408
    private void toFFrameText(LayoutContext layout, String name, Rectangle2D re,
409
            float sizefont, double x, double y, double h) {
410
            //Font f = getFont(sizefont);
411
            Rectangle2D rAux = new Rectangle2D.Double(x+re.getWidth()/4, ((y + (h / 2)) - h),
412
                    re.getWidth()-re.getWidth()/4, h);
413
            FFrameText text =(FFrameText)FrameFactory.createFrameFromName(FFrameTextFactory.registerName);
414

    
415
            text.setLayout(getLayout());
416
            text.setFixedFontSize(true);
417
            //text.setFontSize((int) (sizefont*1.4));
418
            double myScale = layout.getAT().getScaleX() * 0.0234;
419
            text.setFontSize((int)(sizefont/myScale));
420
            text.setBoundBox(FLayoutUtilities.toSheetRect(rAux, layout.getAT()));
421
            text.addText(name);
422
            layout.addFFrame(text, false, true);
423
        }
424

    
425
    /**
426
     * Dibuja sobre el Graphics2D el s?mbolo.
427
     *
428
     * @param g Graphics2D.
429
     * @param re Rect?ngulo a cubrir por el s?mbolo.
430
     * @param x Posici?n X.
431
     * @param y Posici?n Y.
432
     * @param fs2d S?mbolo a dibujar.
433
     * @param sizefont Tama?o de la fuente.
434
     * @param h Altura.
435
     */
436
    private void drawSymbolLegend(Graphics2D g, Rectangle2D re, double x,
437
        double y, ISymbol fs2d, float sizefont, double h) {
438
        double pW = 5;
439
        double wl = (re.getWidth() / pW);
440
        double haux = (sizefont * 0.7);
441
        Font font=null;
442
        if (fs2d instanceof FSymbol && (font=((FSymbol)fs2d).getFont()) != null) {
443
            ((FSymbol)fs2d).setFont(new Font(font.getFontName(), font.getStyle(),
444
                    (int) (wl / 6)));
445
        }
446
        fs2d.drawInsideRectangle(g, new AffineTransform(),
447
            new Rectangle((int) x, (int) ((y + (h / 2)) - haux), (int) wl,
448
                (int) haux));
449
    }
450

    
451
    /**
452
     * A?ade al Layout un nuevo FFrameSymbol.
453
     *
454
     * @param layout Layout sobe el que se a?ade el FFrame.
455
     * @param x Posici?n X.
456
     * @param y Posici?n Y.
457
     * @param fs2d S?mbolo a a?adir.
458
     * @param h Altura.
459
     * @param wT Rect?ngulo del FFrame.
460
     * @param hT tama?o de la fuente.
461
     */
462
   /* private void toFFrameSymbol(Layout layout, double wT, double hT, double x,
463
        double y, FSymbol fs2d, int type, double h) {
464
        double pW = 5;
465
        double wl = (wT / pW);
466
        double haux = hT / (m_numLayers * 1.3); //(sizefont * 0.7);
467

468
        if (haux > (wT / 4.5)) {
469
            haux = wT / 4.5;
470
        }
471

472
        Rectangle2D rAux3 = new Rectangle2D.Double(x, ((y + (h / 2)) - haux),
473
                wl, haux);
474
        FFrameSymbol symbol = new FFrameSymbol();
475
        symbol.setBoundBox(FLayoutUtilities.toSheetRect(rAux3, layout.getAT()));
476
        symbol.setSymbol(fs2d, type);
477
        layout.addFFrame(symbol, false, true);
478
    }*/
479
    private void toFFrameSymbol(LayoutContext layout, Rectangle2D re, double x,
480
            double y, ISymbol fs2d, float sizefont, double h) {
481
            double pW = 5;
482
            double wl = (re.getWidth() / pW);
483
            double haux = (sizefont * 0.7);
484
            Font font=null;
485
            if (fs2d instanceof FSymbol && (font=((FSymbol)fs2d).getFont()) != null) {
486
                ((FSymbol)fs2d).setFont(new Font(font.getFontName(), font.getStyle(),
487
                        (int) (wl / 6)));
488
            }
489

    
490
            Rectangle2D rAux3 = new Rectangle2D.Double(x, ((y + (h / 2)) - haux),
491
                    wl, haux);
492
            FFrameSymbol symbol =(FFrameSymbol)FrameFactory.createFrameFromName(FFrameSymbolFactory.registerName);
493

    
494
            symbol.setLayout(getLayout());
495
            symbol.setBoundBox(FLayoutUtilities.toSheetRect(rAux3, layout.getAT()));
496
            symbol.setFSymbol(fs2d);
497
            layout.addFFrame(symbol, false, true);
498
        }
499

    
500
    /**
501
     * Devuelve el n?mero total de capas incluyendo las subcapas.
502
     *
503
     * @param layers Capa a contar.
504
     *
505
     * @return N?mero de capas y subcapas.
506
     */
507
    private int getSizeNum(FLayers layers) {
508
        int n = 0;
509

    
510
        /////Aqu? hay que calcular cuantos layers y sublayers hay, para saber que distancias dejar entre uno y otro.
511
        ///y adem?s el tama?o de cada uno de ellos para saber que anchura dejar.
512
        int l=0;
513
        for (int i = layers.getLayersCount()-1; i>=0; i--) {
514
            FLayer layer = layers.getLayer(i);
515
            boolean b=false;
516
            if (nameLayers.size()>l && nameLayers.get(l).equals(layer.getName())) {
517
                    b=((Boolean)areVisible.get(l)).booleanValue();
518
            }else {
519
                    b=layer.isVisible();
520
            }
521
            l++;
522
            if (b) {
523
            //if (layer.isVisible()) {
524
                if (layer.getName().length() > m_max) {
525
                    m_max = layer.getName().length();
526
                }
527

    
528
                if (layer instanceof FLayers) {
529
                    //n++;
530
                        n = n + 3;
531
                    n += getSizeNum((FLayers) layer); //m_numLayers += getNumInLyrGroup((FLayers) layer);
532
                } else {
533
                        if (layer instanceof AlphanumericData) {
534
                    AlphanumericData cO = (AlphanumericData) layer;
535
                    n++;
536

    
537
                    if (((Classifiable) cO).getLegend() instanceof ClassifiedLegendInfo && !(cO instanceof FLyrAnnotation)) {
538
                        ClassifiedLegendInfo cli = (ClassifiedLegendInfo) ((Classifiable) cO).getLegend();
539

    
540
                        for (int j = 0; j < cli.getValues().length; j++) {
541
                            String s = cli.getDescriptions()[j];
542

    
543
                            if (s.length() > m_max) {
544
                                m_max = s.length();
545
                            }
546

    
547
                            n++;
548
                        }
549
                    }
550
                        }else{
551
                                  String s = layer.getName();
552

    
553
                          if (s.length() > m_max) {
554
                              m_max = s.length();
555
                          }
556

    
557
                          n++;
558
                        }
559

    
560
                }
561
            }
562
        }
563

    
564
        return n;
565
    }
566

    
567
    /**
568
     * Transforma el FFrameLegend en diferentes FFrameSymbol y FFrameText.
569
     *
570
     * @param layout Layout sobre el que a?adir los FFrame nuevos y sobre el
571
     *        que elimnar el FFrameLegend anterior.
572
     */
573
    public void toFFrames(LayoutContext layout) {
574
        Rectangle2D rectangle = getBoundingBox(null);
575
        //Rectangle2D r = getBoundBox();
576
        double h = rectangle.getHeight() / m_numLayers;
577
        FLayers lays = layers;
578

    
579
        //layout.getEFS().startComplexCommand();
580
        //toFFrames(layout, lays, rectangle, r.getWidth(), r.getHeight(), h, 0);
581
        int[] n = new int[1];
582
        n[0] = 0;
583
        try {
584
                        drawLegendOrToFFrame(null,rectangle,h,lays,n,layout);
585
                } catch (DriverException e) {
586
                        e.printStackTrace();
587
                }
588
        layout.delFFrame(this);
589

    
590
        ///layout.getFFrames().remove(this);
591
        //layout.getEFS().endComplexCommand();
592
    }
593

    
594
    /**
595
     * Transforma el FFrameLegend en diferentes FFrameSymbol y FFrameText.
596
     *
597
     * @param layout Referencia al Layout.
598
     * @param lays Layers a a?adir
599
     * @param rectangle Rect?ngulo del FFrameLegend.
600
     * @param wT DOCUMENT ME!
601
     * @param hT DOCUMENT ME!
602
     * @param h Altura
603
     * @param n n?mero de Capa a?adida.
604
     *
605
     * @return n?mero de Capa a a?adir.
606
     */
607
 /*   public int toFFrames(Layout layout, FLayers lays, Rectangle2D rectangle,
608
        double wT, double hT, double h, int n) {
609
        int N = 39;
610
        float sizefont = 0;
611

612
        if ((rectangle.getHeight() / m_numLayers) < ((wT * N) / (m_max * 0.7))) {
613
            sizefont = (float) ((hT * N) / m_numLayers);
614
        } else {
615
            sizefont = (float) ((wT * N) / (m_max * 0.7));
616
        }
617

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

622
            if (layer.isVisible()) {
623
                if (layer instanceof FLayers) {
624
                    rectangle.setRect(rectangle.getX(),
625
                        rectangle.getY() + (h * n), wT, rectangle.getHeight());
626
                    n += toFFrames(layout, lays, rectangle, wT, hT, h, n); //drawTheme(g, re, h, layers, n);
627
                } else if (layer instanceof AlphanumericData) {
628
                    AlphanumericData cO = (AlphanumericData) layer;
629

630
                    if (((Classifiable) cO).getLegend() instanceof ClassifiedLegendInfo) {
631
                        ClassifiedLegendInfo cli = (ClassifiedLegendInfo) ((Classifiable) cO).getLegend();
632
                        double dX = rectangle.getWidth() / 4;
633
                        double dY = n * h;
634

635
                        double xl = (rectangle.getX() + dX);
636
                        double yl = (rectangle.getY() + dY);
637
                        toFFrameText(layout, layer.getName(),
638
                            rectangle.getWidth(), rectangle.getHeight(),
639
                            sizefont, xl, yl, h);
640
                        n++;
641

642
                        for (int j = 0; j < cli.getValues().length; j++) {
643
                            dY = n * h;
644

645
                            xl = (rectangle.getX() + dX);
646
                            yl = (rectangle.getY() + dY);
647

648
                            String s = cli.getDescriptions()[j];
649
                            toFFrameText(layout, s, rectangle.getWidth(),
650
                                rectangle.getHeight(), sizefont, xl, yl, h);
651

652
                            FSymbol fs2d = cli.getSymbols()[j];
653

654
                            try {
655
//                                toFFrameSymbol(layout, rectangle.getWidth(),
656
//                                    rectangle.getHeight(), rectangle.getX(),
657
//                                    yl, fs2d,
658
//                                    ((Classifiable) cO).getShapeType(), h);
659
                                    toFFrameSymbol(layout, rectangle,
660
                                        rectangle.getHeight(), rectangle.getX(),
661
                                        yl, fs2d,
662
                                        ((Classifiable) cO).getShapeType(), h);
663
                            } catch (DriverException e) {
664
                                e.printStackTrace();
665
                            }
666

667
                            n++;
668
                        }
669
                    } else {
670
                        double dX = rectangle.getWidth() / 4;
671
                        double dY = n * h;
672

673
                        double xl = (rectangle.getX() + dX);
674
                        double yl = (rectangle.getY() + dY);
675

676
                        toFFrameText(layout, layer.getName(),
677
                            rectangle.getWidth(), rectangle.getHeight(),
678
                            sizefont, xl, yl, h);
679

680
                        FSymbol fs2d = ((Classifiable) cO).getLegend()
681
                                        .getDefaultSymbol();
682

683
                        try {
684
                            toFFrameSymbol(layout, rectangle.getWidth(),
685
                                rectangle.getHeight(), rectangle.getX(), yl,
686
                                fs2d, ((Classifiable) cO).getShapeType(), h);
687
                        } catch (DriverException e) {
688
                            e.printStackTrace();
689
                        }
690

691
                        n++;
692
                    }
693
                }
694
            }
695
        }
696

697
        return n;
698
    }
699
*/
700
    /**
701
     * Rellena la fuente a utilizar al dibujar los String sobre el graphics.
702
     *
703
     * @param f Font.
704
     */
705
    public void setFont(Font f) {
706
        m_f = f;
707
    }
708

    
709
    /**
710
     * Devuelve la fuente que esta utilizando.
711
     *
712
     * @return Font.
713
     */
714
    public Font getFont() {
715
        if (m_f != null) {
716
                return new Font(m_f.getName(),m_f.getStyle(),9);
717
        //    return new Font(m_f.getFontName(), m_f.getStyle(), 9);
718
        }
719
        return new Font("SansSerif",Font.PLAIN,9);
720
    }
721

    
722
    /**
723
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#getXMLEntity()
724
     */
725
    public XMLEntity getXMLEntity() throws SaveException {
726
        XMLEntity xml = super.getXMLEntity();
727

    
728
        try {
729
//            xml.putProperty("type", Layout.RECTANGLELEGEND);
730
            xml.putProperty("m_numLayers", m_numLayers);
731
            xml.putProperty("m_max", m_max);
732
            xml.putProperty("m_quality", m_quality);
733
            xml.putProperty("m_viewing", m_viewing);
734
            xml.putProperty("fontName", m_f.getFontName());
735
            xml.putProperty("fontStyle", m_f.getStyle());
736

    
737
            if (fframeview != null) {
738
                Layout layout = fframeview.getLayout();
739
                IFFrame[] fframes = layout.getLayoutContext().getAllFFrames();
740

    
741
                for (int i = 0; i < fframes.length; i++) {
742
                    if (fframeview.equals(fframes[i])) {
743
                        xml.putProperty("index", i);
744
                        break;
745
                    }
746
                }
747
            }
748

    
749
            String[] s=new String[nameLayers.size()];
750
            boolean[] b=new boolean[nameLayers.size()];
751
            for (int i=0;i<nameLayers.size();i++) {
752
                    String k=(String)nameLayers.get(i);
753
                    s[i]=k;
754
                    b[i]=((Boolean)areVisible.get(i)).booleanValue();
755
            }
756
            xml.putProperty("nameLayers",s);
757
            xml.putProperty("areVisible",b);
758
        } catch (Exception e) {
759
            throw new SaveException(e, this.getClass().getName());
760
        }
761

    
762
        return xml;
763
    }
764

    
765
    /**
766
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
767
     *      com.iver.cit.gvsig.project.Project)
768
     */
769
    public void setXMLEntity03(XMLEntity xml, Layout l) {
770
        if (xml.getIntProperty("m_Selected") != 0) {
771
            this.setSelected(true);
772
        } else {
773
            this.setSelected(false);
774
        }
775

    
776
        this.m_numLayers = xml.getIntProperty("m_numLayers");
777
        this.m_max = xml.getIntProperty("m_max");
778
        this.m_quality = xml.getIntProperty("m_quality");
779
        this.m_viewing = xml.getIntProperty("m_viewing");
780
        this.m_f = new Font(xml.getStringProperty("fontName"),
781
                xml.getIntProperty("fontStyle"), 9);
782

    
783
        if (xml.contains("index")) {
784
            fframeview = (FFrameView) l.getLayoutContext().getFFrame(xml.getIntProperty("index"));
785
        }
786
    }
787

    
788
    /**
789
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
790
     *      com.iver.cit.gvsig.project.Project)
791
     */
792
    public void setXMLEntity(XMLEntity xml) {
793
        if (xml.getIntProperty("m_Selected") != 0) {
794
            this.setSelected(true);
795
        } else {
796
            this.setSelected(false);
797
        }
798

    
799
        this.m_numLayers = xml.getIntProperty("m_numLayers");
800
        this.m_max = xml.getIntProperty("m_max");
801
        this.m_quality = xml.getIntProperty("m_quality");
802
        this.m_viewing = xml.getIntProperty("m_viewing");
803
        this.m_f = new Font(xml.getStringProperty("fontName"),
804
                xml.getIntProperty("fontStyle"), 9);
805
        setRotation(xml.getDoubleProperty("m_rotation"));
806

    
807
        if (xml.contains("index")) {
808
            dependenceIndex = xml.getIntProperty("index");
809
        }
810
        if (xml.contains("nameLayers")) {
811
                String[] s=xml.getStringArrayProperty("nameLayers");
812
                boolean[] b=xml.getBooleanArrayProperty("areVisible");
813
                for (int i=0;i<s.length;i++) {
814
                        nameLayers.add(s[i]);
815
                        areVisible.add(new Boolean(b[i]));
816
                }
817
        }
818
    }
819

    
820
    /**
821
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#getNameFFrame()
822
     */
823
    public String getNameFFrame() {
824
        return PluginServices.getText(this, "leyenda")+ num;
825
    }
826

    
827
    /**
828
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#print(java.awt.Graphics2D,
829
     *      java.awt.geom.AffineTransform)
830
     */
831
    public void print(Graphics2D g, AffineTransform at,FShape shape)
832
        throws DriverException {
833
        draw(g, at, null, null);
834
    }
835

    
836
    /**
837
     * Actualiza las dependencias que tenga este FFrame con el resto.
838
     *
839
     * @param fframes Resto de FFrames.
840
     */
841
    public void initDependence(IFFrame[] fframes) {
842
        if ((dependenceIndex != -1) &&
843
                fframes[dependenceIndex] instanceof FFrameView) {
844
            fframeview = (FFrameView) fframes[dependenceIndex];
845
        }
846
    }
847

    
848
        public void initialize() {
849
                // TODO Auto-generated method stub
850

    
851
        }
852

    
853
        public void setNameLayers(ArrayList nameLayers) {
854
                this.nameLayers=nameLayers;
855
        }
856

    
857
        public void setAreVisible(ArrayList areVisible) {
858
                this.areVisible=areVisible;
859
        }
860

    
861
        public ArrayList getNameLayers() {
862
                return nameLayers;
863
        }
864

    
865
        public ArrayList getAreVisible() {
866
                return areVisible;
867
        }
868

    
869
        public void cloneActions(IFFrame frame) {
870
                // TODO Auto-generated method stub
871

    
872
        }
873

    
874
        public IFFrameDialog getPropertyDialog() {
875
                return new FFrameLegendDialog(getLayout(),this);
876
        }
877
}