Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / fframes / FFrameLegend.java @ 24759

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 org.gvsig.fmap.dal.exception.ReadException;
56
import org.gvsig.fmap.geom.Geometry;
57
import org.gvsig.fmap.mapcontext.layers.FLayer;
58
import org.gvsig.fmap.mapcontext.layers.FLayers;
59
import org.gvsig.fmap.mapcontext.layers.operations.Classifiable;
60
import org.gvsig.fmap.mapcontext.layers.operations.IHasImageLegend;
61
import org.gvsig.fmap.mapcontext.rendering.legend.IClassifiedLegend;
62
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
63
import org.gvsig.fmap.mapcontext.rendering.symbols.ITextSymbol;
64
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException;
65
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbologyFactory;
66

    
67
import com.iver.andami.PluginServices;
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

    
96
        public FFrameLegend() {
97

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

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

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

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

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

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

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

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

    
180
        m_max = 0;
181
        m_numLayers = 0;
182

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    
550
                          n++;
551
                        }
552

    
553
                }
554
            }
555
        }
556

    
557
        return n;
558
    }
559

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

    
572
        //layout.getEFS().startComplexCommand();
573
        //toFFrames(layout, lays, rectangle, r.getWidth(), r.getHeight(), h, 0);
574
        int[] n = new int[1];
575
        n[0] = 0;
576
        try {
577
                        drawLegendOrToFFrame(null,rectangle,h,lays,n,layout);
578
                } catch (ReadException e) {
579
                        e.printStackTrace();
580
                }
581
        layout.delFFrame(this);
582

    
583
        ///layout.getFFrames().remove(this);
584
        //layout.getEFS().endComplexCommand();
585
    }
586

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

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

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

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

    
624
            if (fframeview != null) {
625
                Layout layout = fframeview.getLayout();
626
                IFFrame[] fframes = layout.getLayoutContext().getAllFFrames();
627

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

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

    
649
        return xml;
650
    }
651

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

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

    
670
        if (xml.contains("index")) {
671
            fframeview = (FFrameView) l.getLayoutContext().getFFrame(xml.getIntProperty("index"));
672
        }
673
    }
674

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

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

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

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

    
714
    /*
715
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#print(java.awt.Graphics2D,
716
     *      java.awt.geom.AffineTransform)
717
     */
718
    public void print(Graphics2D g, AffineTransform at,Geometry geom, PrintRequestAttributeSet properties)
719
        throws ReadException {
720
        draw(g, at, null, null);
721
    }
722

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

    
735
        public void initialize() {
736
                // TODO Auto-generated method stub
737

    
738
        }
739

    
740
        public void setNameLayers(ArrayList nameLayers) {
741
                this.nameLayers=nameLayers;
742
        }
743

    
744
        public void setAreVisible(ArrayList areVisible) {
745
                this.areVisible=areVisible;
746
        }
747

    
748
        public ArrayList getNameLayers() {
749
                return nameLayers;
750
        }
751

    
752
        public ArrayList getAreVisible() {
753
                return areVisible;
754
        }
755

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

    
759
        }
760

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