Statistics
| Revision:

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

History | View | Annotate | Download (26.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 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
                                    toFFrameSymbol(layout,re,xl,yl,fs2d,sizefont, h);
286
                            }else {
287
                                    drawSymbolLegend(g, re, xl, yl, fs2d, sizefont,
288
                                                    h);
289
                            }
290
                            n[0]++;
291
                        }
292
                    } else {
293
                        double dX = 0;
294
                        double dY = n[0] * h;
295

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

    
309
                                                        if (layout != null) {
310
                                                                toFFrameSymbol(layout, re, xl, yl, fs2d,
311
                                                                                sizefont, h);
312
                                                        } else {
313
                                                                drawSymbolLegend(g, re, xl, yl, fs2d, sizefont,
314
                                                                                h);
315
                                                        }
316
                                                }
317
                        n[0]++;
318
                    }
319
                }else if (layer instanceof IHasImageLegend){
320
                        Image image=((IHasImageLegend)layer).getImageLegend();
321
                        String path=((IHasImageLegend)layer).getPathImage();
322
                        if (image!=null) {
323
                        FFramePicture picture =(FFramePicture)FrameFactory.createFrameFromName(FFramePictureFactory.registerName);
324

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

    
347
                    double xl = (re.getX() + dX);
348
                    double yl = (re.getY() + dY);
349
                    if (layout!=null) {
350
                            toFFrameText(layout,layer.getName(),re,sizefont,xl,yl,h);
351
                    }else {
352
                            drawNameLegend(g, layer.getName(), re, sizefont, xl,
353
                                            yl, h);
354
                    }
355
                    n[0]++;
356
                }
357
            }
358
        }
359
    }
360

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

    
382
    private Font getFont(float sizefont) {
383
                Font f=getFont();
384
                return new Font(f.getName(),f.getStyle(),(int)sizefont);
385
  }
386

    
387
        /**
388
     * A?ade al Layout un nuevo FFrameText a partir de los par?metros de
389
     * entrada.
390
     *
391
     * @param layout Layout sobre el que se crea el nuevo FFrame.
392
         * @param name Texto.
393
         * @param sizefont tama?o de la fuente.
394
         * @param x Posici?n X.
395
         * @param y Posici?n Y.
396
         * @param h Altura.
397
         * @param wT Rect?ngulo del FFrame.
398
         * @param hT DOCUMENT ME!
399
     */
400
    private void toFFrameText(LayoutContext layout, String name, Rectangle2D re,
401
            float sizefont, double x, double y, double h) {
402
            //Font f = getFont(sizefont);
403
            Rectangle2D rAux = new Rectangle2D.Double(x+re.getWidth()/4, ((y + (h / 2)) - h),
404
                    re.getWidth()-re.getWidth()/4, h);
405
            FFrameText text =(FFrameText)FrameFactory.createFrameFromName(FFrameTextFactory.registerName);
406

    
407
            text.setLayout(getLayout());
408
            text.setFixedFontSize(true);
409
            //text.setFontSize((int) (sizefont*1.4));
410
            double myScale = layout.getAT().getScaleX() * 0.0234;
411
            text.setFontSize((int)(sizefont/myScale));
412
            text.setBoundBox(FLayoutUtilities.toSheetRect(rAux, layout.getAT()));
413
            text.addText(name);
414
            layout.addFFrame(text, false, true);
415
        }
416

    
417
    /**
418
     * Dibuja sobre el Graphics2D el s?mbolo.
419
     *
420
     * @param g Graphics2D.
421
     * @param re Rect?ngulo a cubrir por el s?mbolo.
422
     * @param x Posici?n X.
423
     * @param y Posici?n Y.
424
     * @param symbol2d S?mbolo a dibujar.
425
     * @param sizefont Tama?o de la fuente.
426
     * @param h Altura.
427
     */
428
    private void drawSymbolLegend(Graphics2D g, Rectangle2D re, double x,
429
            double y, ISymbol symbol2d, float sizefont, double h) {
430
            double pW = 5;
431
            double wl = (re.getWidth() / pW);
432
            double haux = (sizefont * 0.7);
433
            Font font=null;
434

    
435
            if (symbol2d instanceof ITextSymbol && (font=((ITextSymbol)symbol2d).getFont()) != null) {
436
                    ((ITextSymbol)symbol2d).setFont(new Font(font.getFontName(), font.getStyle(),
437
                                    (int) (wl / 6)));
438
            }
439

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

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

    
484
            Rectangle2D rAux3 = new Rectangle2D.Double(x, ((y + (h / 2)) - haux),
485
                    wl, haux);
486
            FFrameSymbol symbol =(FFrameSymbol)FrameFactory.createFrameFromName(FFrameSymbolFactory.registerName);
487

    
488
            symbol.setLayout(getLayout());
489
            symbol.setBoundBox(FLayoutUtilities.toSheetRect(rAux3, layout.getAT()));
490
            symbol.setFSymbol(fs2d);
491
            layout.addFFrame(symbol, false, true);
492
        }
493

    
494
    /**
495
     * Devuelve el n?mero total de capas incluyendo las subcapas.
496
     *
497
     * @param layers Capa a contar.
498
     *
499
     * @return N?mero de capas y subcapas.
500
     */
501
    private int getSizeNum(FLayers layers) {
502
        int n = 0;
503

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

    
522
                if (layer instanceof FLayers) {
523
                    //n++;
524
                        n = n + 3;
525
                    n += getSizeNum((FLayers) layer); //m_numLayers += getNumInLyrGroup((FLayers) layer);
526
                } else {
527
                        if (layer instanceof Classifiable) {
528
                    Classifiable cO = (Classifiable) layer;
529
                    n++;
530

    
531
                    if (cO.getLegend() instanceof IClassifiedLegend && !(cO instanceof FLyrAnnotation)) {
532
                        IClassifiedLegend cli = (IClassifiedLegend) cO.getLegend();
533

    
534
                        for (int j = 0; j < cli.getValues().length; j++) {
535
                            String s = cli.getDescriptions()[j];
536

    
537
                            if (s.length() > m_max) {
538
                                m_max = s.length();
539
                            }
540

    
541
                            n++;
542
                        }
543
                    }
544
                        }else{
545
                                  String s = layer.getName();
546

    
547
                          if (s.length() > m_max) {
548
                              m_max = s.length();
549
                          }
550

    
551
                          n++;
552
                        }
553

    
554
                }
555
            }
556
        }
557

    
558
        return n;
559
    }
560

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

    
573
        //layout.getEFS().startComplexCommand();
574
        //toFFrames(layout, lays, rectangle, r.getWidth(), r.getHeight(), h, 0);
575
        int[] n = new int[1];
576
        n[0] = 0;
577
              drawLegendOrToFFrame(null,rectangle,h,lays,n,layout);
578
                layout.delFFrame(this);
579

    
580
        ///layout.getFFrames().remove(this);
581
        //layout.getEFS().endComplexCommand();
582
    }
583

    
584
    /**
585
     * Rellena la fuente a utilizar al dibujar los String sobre el graphics.
586
     *
587
     * @param f Font.
588
     */
589
    public void setFont(Font f) {
590
        m_f = f;
591
    }
592

    
593
    /**
594
     * Devuelve la fuente que esta utilizando.
595
     *
596
     * @return Font.
597
     */
598
    public Font getFont() {
599
        if (m_f != null) {
600
                return new Font(m_f.getName(),m_f.getStyle(),9);
601
        //    return new Font(m_f.getFontName(), m_f.getStyle(), 9);
602
        }
603
        return new Font("SansSerif",Font.PLAIN,9);
604
    }
605

    
606
    /**
607
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#getXMLEntity()
608
     */
609
    public XMLEntity getXMLEntity() throws SaveException {
610
        XMLEntity xml = super.getXMLEntity();
611

    
612
        try {
613
//            xml.putProperty("type", Layout.RECTANGLELEGEND);
614
            xml.putProperty("m_numLayers", m_numLayers);
615
            xml.putProperty("m_max", m_max);
616
            xml.putProperty("m_quality", m_quality);
617
            xml.putProperty("m_viewing", m_viewing);
618
            xml.putProperty("fontName", m_f.getFontName());
619
            xml.putProperty("fontStyle", m_f.getStyle());
620

    
621
            if (fframeview != null) {
622
                Layout layout = fframeview.getLayout();
623
                IFFrame[] fframes = layout.getLayoutContext().getAllFFrames();
624

    
625
                for (int i = 0; i < fframes.length; i++) {
626
                    if (fframeview.equals(fframes[i])) {
627
                        xml.putProperty("index", i);
628
                        break;
629
                    }
630
                }
631
            }
632

    
633
            String[] s=new String[nameLayers.size()];
634
            boolean[] b=new boolean[nameLayers.size()];
635
            for (int i=0;i<nameLayers.size();i++) {
636
                    String k=(String)nameLayers.get(i);
637
                    s[i]=k;
638
                    b[i]=((Boolean)areVisible.get(i)).booleanValue();
639
            }
640
            xml.putProperty("nameLayers",s);
641
            xml.putProperty("areVisible",b);
642
        } catch (Exception e) {
643
            throw new SaveException(e, this.getClass().getName());
644
        }
645

    
646
        return xml;
647
    }
648

    
649
    /**
650
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
651
     *      com.iver.cit.gvsig.project.Project)
652
     */
653
    public void setXMLEntity03(XMLEntity xml, Layout l) {
654
        if (xml.getIntProperty("m_Selected") != 0) {
655
            this.setSelected(true);
656
        } else {
657
            this.setSelected(false);
658
        }
659

    
660
        this.m_numLayers = xml.getIntProperty("m_numLayers");
661
        this.m_max = xml.getIntProperty("m_max");
662
        this.m_quality = xml.getIntProperty("m_quality");
663
        this.m_viewing = xml.getIntProperty("m_viewing");
664
        this.m_f = new Font(xml.getStringProperty("fontName"),
665
                xml.getIntProperty("fontStyle"), 9);
666

    
667
        if (xml.contains("index")) {
668
            fframeview = (FFrameView) l.getLayoutContext().getFFrame(xml.getIntProperty("index"));
669
        }
670
    }
671

    
672
    /**
673
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#setXMLEntity(com.iver.utiles.XMLEntity,
674
     *      com.iver.cit.gvsig.project.Project)
675
     */
676
    public void setXMLEntity(XMLEntity xml) {
677
        if (xml.getIntProperty("m_Selected") != 0) {
678
            this.setSelected(true);
679
        } else {
680
            this.setSelected(false);
681
        }
682

    
683
        this.m_numLayers = xml.getIntProperty("m_numLayers");
684
        this.m_max = xml.getIntProperty("m_max");
685
        this.m_quality = xml.getIntProperty("m_quality");
686
        this.m_viewing = xml.getIntProperty("m_viewing");
687
        this.m_f = new Font(xml.getStringProperty("fontName"),
688
                xml.getIntProperty("fontStyle"), 9);
689
        setRotation(xml.getDoubleProperty("m_rotation"));
690

    
691
        if (xml.contains("index")) {
692
            dependenceIndex = xml.getIntProperty("index");
693
        }
694
        if (xml.contains("nameLayers")) {
695
                String[] s=xml.getStringArrayProperty("nameLayers");
696
                boolean[] b=xml.getBooleanArrayProperty("areVisible");
697
                for (int i=0;i<s.length;i++) {
698
                        nameLayers.add(s[i]);
699
                        areVisible.add(new Boolean(b[i]));
700
                }
701
        }
702
    }
703

    
704
    /*
705
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#getNameFFrame()
706
     */
707
    public String getNameFFrame() {
708
        return PluginServices.getText(this, "leyenda")+ num;
709
    }
710

    
711
    /*
712
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#print(java.awt.Graphics2D,
713
     *      java.awt.geom.AffineTransform)
714
     */
715
    public void print(Graphics2D g, AffineTransform at,FShape shape, PrintRequestAttributeSet properties) {
716
            this.properties=properties;
717
        draw(g, at, s, null);
718
        this.properties=null;
719
    }
720

    
721
    /**
722
     * Actualiza las dependencias que tenga este FFrame con el resto.
723
     *
724
     * @param fframes Resto de FFrames.
725
     */
726
    public void initDependence(IFFrame[] fframes) {
727
        if ((dependenceIndex != -1) &&
728
                fframes[dependenceIndex] instanceof FFrameView) {
729
            fframeview = (FFrameView) fframes[dependenceIndex];
730
        }
731
    }
732

    
733
        public void initialize() {
734
                // TODO Auto-generated method stub
735

    
736
        }
737

    
738
        public void setNameLayers(ArrayList nameLayers) {
739
                this.nameLayers=nameLayers;
740
        }
741

    
742
        public void setAreVisible(ArrayList areVisible) {
743
                this.areVisible=areVisible;
744
        }
745

    
746
        public ArrayList getNameLayers() {
747
                return nameLayers;
748
        }
749

    
750
        public ArrayList getAreVisible() {
751
                return areVisible;
752
        }
753

    
754
        public void cloneActions(IFFrame frame) {
755
                // TODO Auto-generated method stub
756

    
757
        }
758

    
759
        public IFFrameDialog getPropertyDialog() {
760
                return new FFrameLegendDialog(getLayout(),this);
761
        }
762
}