Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / fframes / FFrameLegend.java @ 30131

History | View | Annotate | Download (27 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 javax.print.attribute.PrintRequestAttributeSet;
54

    
55
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
56
import com.iver.andami.PluginServices;
57
import com.iver.cit.gvsig.fmap.core.FShape;
58
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
59
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
60
import com.iver.cit.gvsig.fmap.core.symbols.ITextSymbol;
61
import com.iver.cit.gvsig.fmap.core.symbols.SymbolDrawingException;
62
import com.iver.cit.gvsig.fmap.layers.FLayer;
63
import com.iver.cit.gvsig.fmap.layers.FLayers;
64
import com.iver.cit.gvsig.fmap.layers.FLyrAnnotation;
65
import com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable;
66
import com.iver.cit.gvsig.fmap.layers.layerOperations.IHasImageLegend;
67
import com.iver.cit.gvsig.fmap.rendering.IClassifiedLegend;
68
import com.iver.cit.gvsig.project.documents.exceptions.SaveException;
69
import com.iver.cit.gvsig.project.documents.layout.FLayoutUtilities;
70
import com.iver.cit.gvsig.project.documents.layout.LayoutContext;
71
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.FFrameLegendDialog;
72
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.IFFrameDialog;
73
import com.iver.cit.gvsig.project.documents.layout.gui.Layout;
74
import com.iver.utiles.XMLEntity;
75

    
76

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

    
97
        public FFrameLegend() {
98

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

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

    
118
    /**
119
     * Devuelve un entero que representa la forma en que se actualiza la vista.
120
     *
121
     * @return forma que se actualiza la vista.
122
     */
123
    public int getViewing() {
124
        return m_viewing;
125
    }
126

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

    
137
    public void refreshDependence(IFFrame fant, IFFrame fnew) {
138
            if ((fframeview != null) &&
139
                fframeview.equals(fant)) {
140
            fframeview=(FFrameView)fnew;
141
            }
142
    }
143
    /**
144
     * Devuelve el FFrameView utilizado para obtener la leyenda.
145
     *
146
     * @return FFrameView utilizado.
147
     */
148
    public IFFrame[] getFFrameDependence() {
149
        return new IFFrame[]{fframeview};
150
    }
151

    
152
    /**
153
     * Rellena la forma de actualizar la vista.
154
     *
155
     * @param v entero que representa la forma de actualizar la vista.
156
     */
157
    public void setViewing(int v) {
158
        m_viewing = v;
159
    }
160

    
161
    /**
162
     * M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
163
     * la transformada afin que se debe de aplicar y el rect?ngulo que se debe
164
     * de dibujar.
165
     *
166
     * @param g Graphics
167
     * @param at Transformada afin.
168
     * @param rv rect?ngulo sobre el que hacer un clip.
169
     * @param imgBase Imagen para acelerar el dibujado.
170
     */
171
    public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv,
172
        BufferedImage imgBase) {
173
        Rectangle2D.Double re = getBoundingBox(at);
174
        g.rotate(Math.toRadians(getRotation()), re.x + (re.width / 2),
175
            re.y + (re.height / 2));
176

    
177
        if ((fframeview != null) && (fframeview.getMapContext() != null)) {
178
            layers = fframeview.getMapContext().getLayers();
179
        }
180

    
181
        m_max = 0;
182
        m_numLayers = 0;
183

    
184
        if (intersects(rv, re)) {
185
            if (layers == null) { //Si no se ha seleccionado ninguna vista para crear la leyenda.
186
                drawEmpty(g);
187
            } else if ((rv == null) || (getQuality() == PRESENTACION)) {
188
                m_numLayers = getSizeNum(layers);
189

    
190
                double h = re.getHeight() / m_numLayers;
191
                int[] n = new int[1];
192
                n[0] = 0;
193
                drawLegendOrToFFrame(g, re, h, layers, n, null);
194
            } else if (getQuality() == BORRADOR) { //Si se selecciona la calidad BORRADOR.
195
                drawDraft(g);
196
            }
197
        }
198

    
199
        g.rotate(Math.toRadians(-getRotation()), re.x + (re.width / 2),
200
            re.y + (re.height / 2));
201
    }
202

    
203
    /**
204
     * Dibuja el nombre u s?mbolo de la capa que se pasa como par?metro.
205
     *
206
     * @param g Graphics2D sobre el que se dibuja.
207
     * @param re Rectangle a rellenar.
208
     * @param h Altura en pixels.
209
     * @param layers Capa a representar.
210
     * @param n ?ndice de la capa a dibujar.
211
     * @throws ReadDriverException TODO
212
     */
213
    private void drawLegendOrToFFrame(Graphics2D g, Rectangle2D re, double h,
214
        FLayers layers, int[] n, LayoutContext layout)  {
215
        float sizefont = 0;
216

    
217
        if ((re.getHeight() / m_numLayers) < (re.getWidth() / (m_max * 0.7))) {
218
            sizefont = (float) (re.getHeight() / m_numLayers);
219
        } else {
220
            sizefont = (float) (re.getWidth() / (m_max * 0.7));
221
        }
222

    
223
        int l=0;
224
        //////Se recorren los layers dibujando el s?mbolo y su nombre sobre el graphics
225
        for (int i = layers.getLayersCount() - 1; i >= 0; i--) {
226
            FLayer layer = layers.getLayer(i);
227
            boolean b=false;
228

    
229
            if (nameLayers.size()>l && nameLayers.get(l).equals(layer.getName())) {
230
                    b=((Boolean)areVisible.get(l)).booleanValue();
231
            }else {
232
                    b=layer.isVisible();
233
            }
234
            l++;
235
            if (b) {
236
                if (layer instanceof FLayers) {
237
                    n[0]++;
238

    
239
                    double dX = 0;
240
                    double dY = n[0] * h;
241
                    double xl = (re.getX() + dX);
242
                    double yl = (re.getY() + dY);
243
                    if (layout!=null) {
244
                            toFFrameText(layout,layer.getName(),re,sizefont,(xl - (re.getWidth() / 5)),yl,h);
245
                    }else {
246
                            drawNameLegend(g, layer.getName(), re, sizefont,
247
                                            (xl - (re.getWidth() / 5)), yl, h);
248
                    }
249
                            n[0]++;
250
                    drawLegendOrToFFrame(g, re, h, (FLayers) layer, n, layout);
251
                    n[0]++;
252
                } else if (layer instanceof Classifiable && !(layer instanceof IHasImageLegend) ) {
253
                    Classifiable cO = (Classifiable) layer;
254

    
255
                    if (cO.getLegend() instanceof IClassifiedLegend && !(cO instanceof FLyrAnnotation)) {
256
                        IClassifiedLegend cli = (IClassifiedLegend) cO.getLegend();
257
                        double dX = 0;
258
                        double dY = n[0] * h;
259

    
260
                        double xl = (re.getX() + dX);
261
                        double yl = (re.getY() + dY);
262
                        if (layout!=null) {
263
                                toFFrameText(layout,layer.getName(),re,sizefont,(xl - (re.getWidth() / 5)),yl,h);
264
                        }else {
265
                                drawNameLegend(g, layer.getName(), re, sizefont,
266
                                                (xl - (re.getWidth() / 5)), yl, h);
267
                        }
268
                        n[0]++;
269
                        String[] descriptions=cli.getDescriptions();
270
                        ISymbol[] symbols=cli.getSymbols();
271
                        for (int j = 0; j < descriptions.length; j++) {
272
                            dY = n[0] * h;
273

    
274
                            xl = (re.getX() + dX);
275
                            yl = (re.getY() + dY);
276

    
277
                            String s = descriptions[j];
278
                            if (layout!=null) {
279
                                    toFFrameText(layout,s,re,sizefont,xl,yl,h);
280
                            }else {
281
                                    drawNameLegend(g, s, re, sizefont, xl, yl, h);
282
                            }
283
                            ISymbol fs2d = symbols[j];
284
                            if (layout!=null) {
285
                                    try {
286
                                                                        toFFrameSymbol(layout,re,xl,yl,fs2d,sizefont, h, cO.getShapeType());
287
                                                                } catch (ReadDriverException e) {
288
                                                                        e.printStackTrace();
289
                                                                }
290
                            }else {
291
                                    drawSymbolLegend(g, re, xl, yl, fs2d, sizefont,
292
                                                    h);
293
                            }
294
                            n[0]++;
295
                        }
296
                    } else {
297
                        double dX = 0;
298
                        double dY = n[0] * h;
299

    
300
                        double xl = (re.getX() + dX);
301
                        double yl = (re.getY() + dY);
302
                        if (layout!=null) {
303
                                toFFrameText(layout,layer.getName(),re,sizefont,xl,yl,h);
304
                        }else {
305
                                drawNameLegend(g, layer.getName(), re, sizefont, xl,
306
                                                yl, h);
307
                        }
308
                        // TO DO: CAMBIAR TO_DO ESTO PARA QUE ACEPTE ISYMBOL
309
                        // TODO: comprovar que no es trenca res
310
                        if (cO.getLegend() != null) {
311
                                                        ISymbol fs2d = cO.getLegend().getDefaultSymbol();
312

    
313
                                                        if (layout != null) {
314
                                                                try {
315
                                                                        toFFrameSymbol(layout, re, xl, yl, fs2d,
316
                                                                                        sizefont, h, cO.getShapeType());
317
                                                                } catch (ReadDriverException e) {
318
                                                                        e.printStackTrace();
319
                                                                }
320
                                                        } else {
321
                                                                drawSymbolLegend(g, re, xl, yl, fs2d, sizefont,
322
                                                                                h);
323
                                                        }
324
                                                }
325
                        n[0]++;
326
                    }
327
                }else if (layer instanceof IHasImageLegend){
328
                        Image image=((IHasImageLegend)layer).getImageLegend();
329
                        String path=((IHasImageLegend)layer).getPathImage();
330
                        if (image!=null) {
331
                        FFramePicture picture =(FFramePicture)FrameFactory.createFrameFromName(FFramePictureFactory.registerName);
332

    
333
                        picture.setLayout(getLayout());
334
                        BufferedImage bi = new BufferedImage(image.getWidth(null),
335
                            image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
336
                    Graphics2D biContext = bi.createGraphics();
337
                    biContext.drawImage(image, 0, 0, null);
338
                    picture.setImage(bi);
339
                    double dY = n[0] * h;
340
                    Rectangle2D rectImage=new Rectangle2D.Double(re.getX(),re.getY()+dY,re.getWidth(),h);
341
                   if (layout!=null) {
342
                            picture.setBoundBox(FLayoutUtilities.toSheetRect(rectImage, layout.getAT()));
343
                            picture.setPath(path);
344
                            layout.addFFrame(picture, false, true);
345
                    }else {
346
                            picture.setBoundBox(FLayoutUtilities.toSheetRect(rectImage,new AffineTransform()));
347
                        picture.draw(g,new AffineTransform(),re,bi);
348
                    }
349
                        }
350
                    n[0]++;
351
                }else {
352
                        double dX = 0;
353
                    double dY = n[0] * h;
354

    
355
                    double xl = (re.getX() + dX);
356
                    double yl = (re.getY() + dY);
357
                    if (layout!=null) {
358
                            toFFrameText(layout,layer.getName(),re,sizefont,xl,yl,h);
359
                    }else {
360
                            drawNameLegend(g, layer.getName(), re, sizefont, xl,
361
                                            yl, h);
362
                    }
363
                    n[0]++;
364
                }
365
            }
366
        }
367
    }
368

    
369
    /**
370
     * Dibuja sobre el graphics el nombre de la capa que se pasa como
371
     * par?metro.
372
     *
373
     * @param g Graphics2D sobre el que dibujar.
374
     * @param name Nombre de la capa.
375
     * @param re Rect?ngulo a ocupar por el nombre.
376
     * @param sizefont tama?o de la fuente.
377
     * @param x Posici?n X.
378
     * @param y Posici?n Y.
379
     * @param h Altura.
380
     */
381
    private void drawNameLegend(Graphics2D g, String name, Rectangle2D re,
382
        float sizefont, double x, double y, double h) {
383
        Font f = getFont(sizefont);
384
        g.setFont(f);
385
        g.setColor(Color.black);
386
        g.drawString(name, (float) (x + (re.getWidth() / 4)),
387
            (float) (y + (h / 2)));
388
    }
389

    
390
    private Font getFont(float sizefont) {
391
                Font f=getFont();
392
                return new Font(f.getName(),f.getStyle(),(int)sizefont);
393
  }
394

    
395
        /**
396
     * A?ade al Layout un nuevo FFrameText a partir de los par?metros de
397
     * entrada.
398
     *
399
     * @param layout Layout sobre el que se crea el nuevo FFrame.
400
         * @param name Texto.
401
         * @param sizefont tama?o de la fuente.
402
         * @param x Posici?n X.
403
         * @param y Posici?n Y.
404
         * @param h Altura.
405
         * @param wT Rect?ngulo del FFrame.
406
         * @param hT DOCUMENT ME!
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 symbol2d 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 symbol2d, 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

    
443
            if (symbol2d instanceof ITextSymbol && (font=((ITextSymbol)symbol2d).getFont()) != null) {
444
                    ((ITextSymbol)symbol2d).setFont(new Font(font.getFontName(), font.getStyle(),
445
                                    (int) (wl / 6)));
446
            }
447

    
448
                Rectangle rectangle = new Rectangle((int) x, (int) ((y + (h / 2)) - haux), (int) wl,
449
                                (int) haux);
450
                try {
451
                        symbol2d.drawInsideRectangle(g, new AffineTransform(),
452
                                        rectangle, properties);
453
                } catch (SymbolDrawingException e) {
454
                        if (e.getType() == SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS) {
455
                                try {
456
                                        SymbologyFactory.getWarningSymbol(
457
                                                        SymbolDrawingException.STR_UNSUPPORTED_SET_OF_SETTINGS,
458
                                                        symbol2d.getDescription(),
459
                                                        SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS).drawInsideRectangle(g, null, rectangle, null);
460
                                } catch (SymbolDrawingException e1) {
461
                                        // IMPOSSIBLE TO REACH THIS
462
                                }
463
                        } else {
464
                                // should be unreachable code
465
                                throw new Error(PluginServices.getText(this, "symbol_shapetype_mismatch"));
466
                        }
467
                }
468
    }
469

    
470
    /**
471
     * A?ade al Layout un nuevo FFrameSymbol.
472
     *
473
     * @param layout Layout sobe el que se a?ade el FFrame.
474
     * @param x Posici?n X.
475
     * @param y Posici?n Y.
476
     * @param fs2d S?mbolo a a?adir.
477
     * @param h Altura.
478
     * @param wT Rect?ngulo del FFrame.
479
     * @param hT tama?o de la fuente.
480
     */
481
    private void toFFrameSymbol(LayoutContext layout, Rectangle2D re, double x,
482
            double y, ISymbol fs2d, float sizefont, double h, int shapeType) {
483
            double pW = 5;
484
            double wl = (re.getWidth() / pW);
485
            double haux = (sizefont * 0.7);
486
            Font font=null;
487
            if (fs2d instanceof ITextSymbol && (font=((ITextSymbol)fs2d).getFont()) != null) {
488
              ((ITextSymbol)fs2d).setFont(new Font(font.getFontName(), font.getStyle(),
489
                      (int) (wl / 6)));
490
            }
491

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

    
496
            symbol.setLayout(getLayout());
497
            symbol.setBoundBox(FLayoutUtilities.toSheetRect(rAux3, layout.getAT()));
498
            symbol.setFSymbol(fs2d);
499
            symbol.setShapeType(shapeType);
500
            layout.addFFrame(symbol, false, true);
501
        }
502

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

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

    
531
                if (layer instanceof FLayers) {
532
                    //n++;
533
                        n = n + 3;
534
                    n += getSizeNum((FLayers) layer); //m_numLayers += getNumInLyrGroup((FLayers) layer);
535
                } else {
536
                        if (layer instanceof Classifiable) {
537
                    Classifiable cO = (Classifiable) layer;
538
                    n++;
539

    
540
                    if (cO.getLegend() instanceof IClassifiedLegend && !(cO instanceof FLyrAnnotation)) {
541
                        IClassifiedLegend cli = (IClassifiedLegend) cO.getLegend();
542

    
543
                        for (int j = 0; j < cli.getValues().length; j++) {
544
                            String s = cli.getDescriptions()[j];
545

    
546
                            if (s != null && s.length() > m_max) {
547
                                m_max = s.length();
548
                            }
549

    
550
                            n++;
551
                        }
552
                    }
553
                        }else{
554
                                  String s = layer.getName();
555

    
556
                          if (s != null && s.length() > m_max) {
557
                              m_max = s.length();
558
                          }
559

    
560
                          n++;
561
                        }
562

    
563
                }
564
            }
565
        }
566

    
567
        return n;
568
    }
569

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

    
582
        //layout.getEFS().startComplexCommand();
583
        //toFFrames(layout, lays, rectangle, r.getWidth(), r.getHeight(), h, 0);
584
        int[] n = new int[1];
585
        n[0] = 0;
586
              drawLegendOrToFFrame(null,rectangle,h,lays,n,layout);
587
                layout.delFFrame(this);
588

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

    
593
    /**
594
     * Rellena la fuente a utilizar al dibujar los String sobre el graphics.
595
     *
596
     * @param f Font.
597
     */
598
    public void setFont(Font f) {
599
        m_f = f;
600
    }
601

    
602
    /**
603
     * Devuelve la fuente que esta utilizando.
604
     *
605
     * @return Font.
606
     */
607
    public Font getFont() {
608
        if (m_f != null) {
609
                return new Font(m_f.getName(),m_f.getStyle(),9);
610
        //    return new Font(m_f.getFontName(), m_f.getStyle(), 9);
611
        }
612
        return new Font("SansSerif",Font.PLAIN,9);
613
    }
614

    
615
    /**
616
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#getXMLEntity()
617
     */
618
    public XMLEntity getXMLEntity() throws SaveException {
619
        XMLEntity xml = super.getXMLEntity();
620

    
621
        try {
622
//            xml.putProperty("type", Layout.RECTANGLELEGEND);
623
            xml.putProperty("m_numLayers", m_numLayers);
624
            xml.putProperty("m_max", m_max);
625
            xml.putProperty("m_quality", m_quality);
626
            xml.putProperty("m_viewing", m_viewing);
627
            xml.putProperty("fontName", m_f.getFontName());
628
            xml.putProperty("fontStyle", m_f.getStyle());
629

    
630
            if (fframeview != null) {
631
                Layout layout = fframeview.getLayout();
632
                IFFrame[] fframes = layout.getLayoutContext().getAllFFrames();
633

    
634
                for (int i = 0; i < fframes.length; i++) {
635
                    if (fframeview.equals(fframes[i])) {
636
                        xml.putProperty("index", i);
637
                        break;
638
                    }
639
                }
640
            }
641

    
642
            String[] s=new String[nameLayers.size()];
643
            boolean[] b=new boolean[nameLayers.size()];
644
            for (int i=0;i<nameLayers.size();i++) {
645
                    String k=(String)nameLayers.get(i);
646
                    s[i]=k;
647
                    b[i]=((Boolean)areVisible.get(i)).booleanValue();
648
            }
649
            xml.putProperty("nameLayers",s);
650
            xml.putProperty("areVisible",b);
651
        } catch (Exception e) {
652
            throw new SaveException(e, this.getClass().getName());
653
        }
654

    
655
        return xml;
656
    }
657

    
658
    /**
659
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
660
     *      com.iver.cit.gvsig.project.Project)
661
     */
662
    public void setXMLEntity03(XMLEntity xml, Layout l) {
663
        if (xml.getIntProperty("m_Selected") != 0) {
664
            this.setSelected(true);
665
        } else {
666
            this.setSelected(false);
667
        }
668

    
669
        this.m_numLayers = xml.getIntProperty("m_numLayers");
670
        this.m_max = xml.getIntProperty("m_max");
671
        this.m_quality = xml.getIntProperty("m_quality");
672
        this.m_viewing = xml.getIntProperty("m_viewing");
673
        this.m_f = new Font(xml.getStringProperty("fontName"),
674
                xml.getIntProperty("fontStyle"), 9);
675

    
676
        if (xml.contains("index")) {
677
            fframeview = (FFrameView) l.getLayoutContext().getFFrame(xml.getIntProperty("index"));
678
        }
679
    }
680

    
681
    /**
682
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
683
     *      com.iver.cit.gvsig.project.Project)
684
     */
685
    public void setXMLEntity(XMLEntity xml) {
686
        if (xml.getIntProperty("m_Selected") != 0) {
687
            this.setSelected(true);
688
        } else {
689
            this.setSelected(false);
690
        }
691

    
692
        this.m_numLayers = xml.getIntProperty("m_numLayers");
693
        this.m_max = xml.getIntProperty("m_max");
694
        this.m_quality = xml.getIntProperty("m_quality");
695
        this.m_viewing = xml.getIntProperty("m_viewing");
696
        this.m_f = new Font(xml.getStringProperty("fontName"),
697
                xml.getIntProperty("fontStyle"), 9);
698
        setRotation(xml.getDoubleProperty("m_rotation"));
699

    
700
        if (xml.contains("index")) {
701
            dependenceIndex = xml.getIntProperty("index");
702
        }
703
        if (xml.contains("nameLayers")) {
704
                String[] s=xml.getStringArrayProperty("nameLayers");
705
                boolean[] b=xml.getBooleanArrayProperty("areVisible");
706
                for (int i=0;i<s.length;i++) {
707
                        nameLayers.add(s[i]);
708
                        areVisible.add(new Boolean(b[i]));
709
                }
710
        }
711
    }
712

    
713
    /*
714
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#getNameFFrame()
715
     */
716
    public String getNameFFrame() {
717
        return PluginServices.getText(this, "leyenda")+ num;
718
    }
719

    
720
    /*
721
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#print(java.awt.Graphics2D,
722
     *      java.awt.geom.AffineTransform)
723
     */
724
    public void print(Graphics2D g, AffineTransform at,FShape shape, PrintRequestAttributeSet properties) {
725
            this.properties=properties;
726
        draw(g, at, null, null);
727
        this.properties=null;
728
    }
729

    
730
    /**
731
     * Actualiza las dependencias que tenga este FFrame con el resto.
732
     *
733
     * @param fframes Resto de FFrames.
734
     */
735
    public void initDependence(IFFrame[] fframes) {
736
        if ((dependenceIndex != -1) &&
737
                fframes[dependenceIndex] instanceof FFrameView) {
738
            fframeview = (FFrameView) fframes[dependenceIndex];
739
        }
740
    }
741

    
742
        public void initialize() {
743
                // TODO Auto-generated method stub
744

    
745
        }
746

    
747
        public void setNameLayers(ArrayList nameLayers) {
748
                this.nameLayers=nameLayers;
749
        }
750

    
751
        public void setAreVisible(ArrayList areVisible) {
752
                this.areVisible=areVisible;
753
        }
754

    
755
        public ArrayList getNameLayers() {
756
                return nameLayers;
757
        }
758

    
759
        public ArrayList getAreVisible() {
760
                return areVisible;
761
        }
762

    
763
        public void cloneActions(IFFrame frame) {
764
                // TODO Auto-generated method stub
765

    
766
        }
767

    
768
        public IFFrameDialog getPropertyDialog() {
769
                return new FFrameLegendDialog(getLayout(),this);
770
        }
771
}