Statistics
| Revision:

root / branches / v2_0_0_prep / extensions / org.gvsig.app.document.layout.app / org.gvsig.app.document.layout.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / fframes / FFrameLegend.java @ 37196

History | View | Annotate | Download (28.7 KB)

1 36648 cordinyana
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.app.project.documents.layout.fframes;
23
24
import java.awt.Color;
25
import java.awt.Font;
26
import java.awt.Graphics2D;
27
import java.awt.Image;
28
import java.awt.Rectangle;
29
import java.awt.geom.AffineTransform;
30
import java.awt.geom.Rectangle2D;
31
import java.awt.image.BufferedImage;
32
import java.util.ArrayList;
33
import java.util.List;
34
35
import org.gvsig.andami.PluginServices;
36
import org.gvsig.app.project.documents.layout.FLayoutUtilities;
37
import org.gvsig.app.project.documents.layout.LayoutContext;
38
import org.gvsig.compat.print.PrintAttributes;
39
import org.gvsig.fmap.dal.exception.ReadException;
40
import org.gvsig.fmap.geom.Geometry;
41
import org.gvsig.fmap.mapcontext.MapContextLocator;
42
import org.gvsig.fmap.mapcontext.MapContextManager;
43
import org.gvsig.fmap.mapcontext.layers.FLayer;
44
import org.gvsig.fmap.mapcontext.layers.FLayers;
45
import org.gvsig.fmap.mapcontext.layers.operations.Classifiable;
46
import org.gvsig.fmap.mapcontext.layers.operations.IHasImageLegend;
47
import org.gvsig.fmap.mapcontext.rendering.legend.IClassifiedLegend;
48
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol;
49
import org.gvsig.fmap.mapcontext.rendering.symbols.ITextSymbol;
50
import org.gvsig.fmap.mapcontext.rendering.symbols.SymbolDrawingException;
51
import org.gvsig.tools.ToolsLocator;
52
import org.gvsig.tools.dynobject.DynStruct;
53
import org.gvsig.tools.persistence.PersistenceManager;
54
import org.gvsig.tools.persistence.PersistentState;
55
import org.gvsig.tools.persistence.exception.PersistenceException;
56
57
/**
58
 * FFrame para introducir una leyenda en el Layout.
59
 *
60
 * @author Vicente Caballero Navarro
61
 */
62
public class FFrameLegend extends AbstractFFrameViewDependence implements
63
    IFFrameViewDependence {
64
65
    public static final String PERSISTENCE_DEFINITION_NAME = "FFrameLegend";
66
67
    private static final String NUMLAYERS_FIELD = "numLayers";
68
    private static final String MAX_FIELD = "max";
69
    private static final String QUALITY_FIELD = "quality";
70
    private static final String VIEWING_FIELD = "viewing";
71
    private static final String FONT_FIELD = "font";
72
    private static final String NAMELAYERS_FIELD = "nameLayers";
73
    private static final String AREVISIBLE_FIELD = "areVisible";
74
75
    private static final int PRESENTACION = 0;
76
    private static final int BORRADOR = 1;
77
    private int m_quality = 0;
78
    private int m_viewing = 0;
79
    private Font m_font = new Font("SansSerif", Font.PLAIN, 9);
80
    private int m_max;
81
    private int m_numLayers;
82
    private FLayers layers = null;
83
    private List<String> nameLayers = new ArrayList<String>();
84
    private List<Boolean> areVisible = new ArrayList<Boolean>();
85
    private PrintAttributes properties;
86
87
    private MapContextManager mapContextManager = MapContextLocator
88
        .getMapContextManager();
89
90
    public FFrameLegend() {
91
92
    }
93
94
    /**
95
     * Rellena la calidad que se quiere aplicar.
96
     *
97
     * @param q
98
     *            entero que representa la calidad a aplicar.
99
     */
100
    public void setQuality(int q) {
101
        m_quality = q;
102
    }
103
104
    /**
105
     * Devuelve un entero que representa la calidad que est? seleccionada.
106
     *
107
     * @return tipo de calidad selccionada.
108
     */
109
    public int getQuality() {
110
        return m_quality;
111
    }
112
113
    /**
114
     * Devuelve un entero que representa la forma en que se actualiza la vista.
115
     *
116
     * @return forma que se actualiza la vista.
117
     */
118
    public int getViewing() {
119
        return m_viewing;
120
    }
121
122
    /**
123
     * Rellena la forma de actualizar la vista.
124
     *
125
     * @param v
126
     *            entero que representa la forma de actualizar la vista.
127
     */
128
    public void setViewing(int v) {
129
        m_viewing = v;
130
    }
131
132
    /**
133
     * M?todo que dibuja sobre el graphics que se le pasa como par?metro, seg?n
134
     * la transformada afin que se debe de aplicar y el rect?ngulo que se debe
135
     * de dibujar.
136
     *
137
     * @param g
138
     *            Graphics
139
     * @param at
140
     *            Transformada afin.
141
     * @param rv
142
     *            rect?ngulo sobre el que hacer un clip.
143
     * @param imgBase
144
     *            Imagen para acelerar el dibujado.
145
     */
146
    public void draw(Graphics2D g, AffineTransform at, Rectangle2D rv,
147
        BufferedImage imgBase) {
148
        Rectangle2D.Double re = getBoundingBox(at);
149
        g.rotate(Math.toRadians(getRotation()), re.x + (re.width / 2), re.y
150
            + (re.height / 2));
151
152
        if ((fframeViewDependence != null)
153
            && (fframeViewDependence.getMapContext() != null)) {
154
            layers = fframeViewDependence.getMapContext().getLayers();
155
        }
156
157
        m_max = 0;
158
        m_numLayers = 0;
159
160
        if (intersects(rv, re)) {
161
            if (layers == null) { // Si no se ha seleccionado ninguna vista para
162
                                  // crear la leyenda.
163
                drawEmpty(g);
164
            } else
165
                if ((rv == null) || (getQuality() == PRESENTACION)) {
166
                    m_numLayers = getSizeNum(layers);
167
168
                    double h = re.getHeight() / m_numLayers;
169
                    int[] n = new int[1];
170
                    n[0] = 0;
171
                    drawLegendOrToFFrame(g, re, h, layers, n, null);
172
                } else
173
                    if (getQuality() == BORRADOR) { // Si se selecciona la
174
                                                    // calidad BORRADOR.
175
                        drawDraft(g);
176
                    }
177
        }
178
179
        g.rotate(Math.toRadians(-getRotation()), re.x + (re.width / 2), re.y
180
            + (re.height / 2));
181
    }
182
183
    /**
184
     * Dibuja el nombre u s?mbolo de la capa que se pasa como par?metro.
185
     *
186
     * @param g
187
     *            Graphics2D sobre el que se dibuja.
188
     * @param re
189
     *            Rectangle a rellenar.
190
     * @param h
191
     *            Altura en pixels.
192
     * @param layers
193
     *            Capa a representar.
194
     * @param n
195
     *            ?ndice de la capa a dibujar.
196
     * @throws ReadDriverException
197
     *             TODO
198
     */
199
    private void drawLegendOrToFFrame(Graphics2D g, Rectangle2D re, double h,
200
        FLayers layers, int[] n, LayoutContext layout) {
201
        float sizefont = 0;
202
203
        if ((re.getHeight() / m_numLayers) < (re.getWidth() / (m_max * 0.7))) {
204
            sizefont = (float) (re.getHeight() / m_numLayers);
205
        } else {
206
            sizefont = (float) (re.getWidth() / (m_max * 0.7));
207
        }
208
209
        int l = 0;
210
        // ////Se recorren los layers dibujando el s?mbolo y su nombre sobre el
211
        // graphics
212
        for (int i = layers.getLayersCount() - 1; i >= 0; i--) {
213
            FLayer layer = layers.getLayer(i);
214
            boolean b = false;
215
216
            if (nameLayers.size() > l
217
                && nameLayers.get(l).equals(layer.getName())) {
218
                b = ((Boolean) areVisible.get(l)).booleanValue();
219
            } else {
220
                b = layer.isVisible();
221
            }
222
            l++;
223
            if (b) {
224
                if (layer instanceof FLayers) {
225
                    n[0]++;
226
227
                    double dX = 0;
228
                    double dY = n[0] * h;
229
                    double xl = (re.getX() + dX);
230
                    double yl = (re.getY() + dY);
231
                    if (layout != null) {
232
                        toFFrameText(layout, layer.getName(), re, sizefont,
233
                            (xl - (re.getWidth() / 5)), yl, h);
234
                    } else {
235
                        drawNameLegend(g, layer.getName(), re, sizefont,
236
                            (xl - (re.getWidth() / 5)), yl, h);
237
                    }
238
                    n[0]++;
239
                    drawLegendOrToFFrame(g, re, h, (FLayers) layer, n, layout);
240
                    n[0]++;
241
                } else
242
                    if (layer instanceof Classifiable
243
                        && !(layer instanceof IHasImageLegend)) {
244
                        Classifiable cO = (Classifiable) layer;
245
246
                        if (cO.getLegend() instanceof IClassifiedLegend) {// &&
247
                                                                          // !(cO
248
                                                                          // instanceof
249
                                                                          // FLyrAnnotation))
250
                                                                          // {
251
                            IClassifiedLegend cli =
252
                                (IClassifiedLegend) cO.getLegend();
253
                            double dX = 0;
254
                            double dY = n[0] * h;
255
256
                            double xl = (re.getX() + dX);
257
                            double yl = (re.getY() + dY);
258
                            if (layout != null) {
259
                                toFFrameText(layout, layer.getName(), re,
260
                                    sizefont, (xl - (re.getWidth() / 5)), yl, h);
261
                            } else {
262
                                drawNameLegend(g, layer.getName(), re,
263
                                    sizefont, (xl - (re.getWidth() / 5)), yl, h);
264
                            }
265
                            n[0]++;
266
                            String[] descriptions = cli.getDescriptions();
267
                            ISymbol[] symbols = cli.getSymbols();
268
                            for (int j = 0; j < descriptions.length; j++) {
269
                                dY = n[0] * h;
270
271
                                xl = (re.getX() + dX);
272
                                yl = (re.getY() + dY);
273
274
                                String s = descriptions[j];
275
                                if (layout != null) {
276
                                    toFFrameText(layout, s, re, sizefont, xl,
277
                                        yl, h);
278
                                } else {
279
                                    drawNameLegend(g, s, re, sizefont, xl, yl,
280
                                        h);
281
                                }
282
                                ISymbol fs2d = symbols[j];
283
                                if (layout != null) {
284
                                    try {
285
                                        toFFrameSymbol(layout, re, xl, yl,
286
                                            fs2d, sizefont, h,
287
                                            cO.getShapeType());
288
                                    } catch (ReadException e) {
289
                                        e.printStackTrace();
290
                                    }
291
                                } else {
292
                                    drawSymbolLegend(g, re, xl, yl, fs2d,
293
                                        sizefont, h);
294
                                }
295
                                n[0]++;
296
                            }
297
                        } else {
298
                            double dX = 0;
299
                            double dY = n[0] * h;
300
301
                            double xl = (re.getX() + dX);
302
                            double yl = (re.getY() + dY);
303
                            if (layout != null) {
304
                                toFFrameText(layout, layer.getName(), re,
305
                                    sizefont, xl, yl, h);
306
                            } else {
307
                                drawNameLegend(g, layer.getName(), re,
308
                                    sizefont, xl, yl, h);
309
                            }
310
                            // TO DO: CAMBIAR TO_DO ESTO PARA QUE ACEPTE ISYMBOL
311
                            // TODO: comprovar que no es trenca res
312
                            if (cO.getLegend() != null) {
313
                                ISymbol fs2d =
314
                                    cO.getLegend().getDefaultSymbol();
315
316
                                if (layout != null) {
317
                                    try {
318
                                        toFFrameSymbol(layout, re, xl, yl,
319
                                            fs2d, sizefont, h,
320
                                            cO.getShapeType());
321
                                    } catch (ReadException e) {
322
                                        e.printStackTrace();
323
                                    }
324
                                } else {
325
                                    drawSymbolLegend(g, re, xl, yl, fs2d,
326
                                        sizefont, h);
327
                                }
328
                            }
329
                            n[0]++;
330
                        }
331
                    } else
332
                        if (layer instanceof IHasImageLegend) {
333
                            Image image =
334
                                ((IHasImageLegend) layer).getImageLegend();
335
                            String path =
336
                                ((IHasImageLegend) layer).getPathImage();
337
                            if (image != null) {
338
                                FFramePicture picture =
339
                                    (FFramePicture) layoutManager
340
                                        .createFrame(FFramePicture.PERSISTENCE_DEFINITION_NAME);
341
342
                                BufferedImage bi =
343
                                    new BufferedImage(image.getWidth(null),
344
                                        image.getHeight(null),
345
                                        BufferedImage.TYPE_INT_ARGB);
346
                                Graphics2D biContext = bi.createGraphics();
347
                                biContext.drawImage(image, 0, 0, null);
348
                                picture.setImage(bi);
349
                                double dY = n[0] * h;
350
                                Rectangle2D rectImage =
351
                                    new Rectangle2D.Double(re.getX(), re.getY()
352
                                        + dY, re.getWidth(), h);
353
                                if (layout != null) {
354
                                    picture
355
                                        .setBoundBox(FLayoutUtilities
356
                                            .toSheetRect(rectImage,
357
                                                layout.getAT()));
358
                                    picture.setPath(path);
359
                                    layout.addFFrame(picture, false, true);
360
                                } else {
361
                                    picture.setBoundBox(FLayoutUtilities
362
                                        .toSheetRect(rectImage,
363
                                            new AffineTransform()));
364
                                    picture.draw(g, new AffineTransform(), re,
365
                                        bi);
366
                                }
367
                            }
368
                            n[0]++;
369
                        } else {
370
                            double dX = 0;
371
                            double dY = n[0] * h;
372
373
                            double xl = (re.getX() + dX);
374
                            double yl = (re.getY() + dY);
375
                            if (layout != null) {
376
                                toFFrameText(layout, layer.getName(), re,
377
                                    sizefont, xl, yl, h);
378
                            } else {
379
                                drawNameLegend(g, layer.getName(), re,
380
                                    sizefont, xl, yl, h);
381
                            }
382
                            n[0]++;
383
                        }
384
            }
385
        }
386
    }
387
388
    /**
389
     * Dibuja sobre el graphics el nombre de la capa que se pasa como
390
     * par?metro.
391
     *
392
     * @param g
393
     *            Graphics2D sobre el que dibujar.
394
     * @param name
395
     *            Nombre de la capa.
396
     * @param re
397
     *            Rect?ngulo a ocupar por el nombre.
398
     * @param sizefont
399
     *            tama?o de la fuente.
400
     * @param x
401
     *            Posici?n X.
402
     * @param y
403
     *            Posici?n Y.
404
     * @param h
405
     *            Altura.
406
     */
407
    private void drawNameLegend(Graphics2D g, String name, Rectangle2D re,
408
        float sizefont, double x, double y, double h) {
409
        Font f = getFont(sizefont);
410
        g.setFont(f);
411
        g.setColor(Color.black);
412
        if (name != null)
413
            g.drawString(name, (float) (x + (re.getWidth() / 4)),
414
                (float) (y + (h / 2)));
415
    }
416
417
    private Font getFont(float sizefont) {
418
        Font f = getFont();
419
        return new Font(f.getName(), f.getStyle(), (int) sizefont);
420
    }
421
422
    /**
423
     * A?ade al Layout un nuevo FFrameText a partir de los par?metros de
424
     * entrada.
425
     *
426
     * @param layout
427
     *            Layout sobre el que se crea el nuevo FFrame.
428
     * @param name
429
     *            Texto.
430
     * @param sizefont
431
     *            tama?o de la fuente.
432
     * @param x
433
     *            Posici?n X.
434
     * @param y
435
     *            Posici?n Y.
436
     * @param h
437
     *            Altura.
438
     * @param wT
439
     *            Rect?ngulo del FFrame.
440
     * @param hT
441
     *            DOCUMENT ME!
442
     */
443
    private void toFFrameText(LayoutContext layout, String name,
444
        Rectangle2D re, float sizefont, double x, double y, double h) {
445
        // Font f = getFont(sizefont);
446
        Rectangle2D rAux =
447
            new Rectangle2D.Double(x + re.getWidth() / 4, ((y + (h / 2)) - h),
448
                re.getWidth() - re.getWidth() / 4, h);
449
        FFrameText text =
450
            (FFrameText) layoutManager
451
                .createFrame(FFrameText.PERSISTENCE_DEFINITION_NAME);
452
453
        text.setFixedFontSize(true);
454
        double myScale = layout.getAT().getScaleX() * 0.0234;
455
        text.setFontSize((int) (sizefont / myScale));
456
        text.setBoundBox(FLayoutUtilities.toSheetRect(rAux, layout.getAT()));
457
        text.addText(name);
458
        layout.addFFrame(text, false, true);
459
    }
460
461
    /**
462
     * Dibuja sobre el Graphics2D el s?mbolo.
463
     *
464
     * @param g
465
     *            Graphics2D.
466
     * @param re
467
     *            Rect?ngulo a cubrir por el s?mbolo.
468
     * @param x
469
     *            Posici?n X.
470
     * @param y
471
     *            Posici?n Y.
472
     * @param symbol2d
473
     *            S?mbolo a dibujar.
474
     * @param sizefont
475
     *            Tama?o de la fuente.
476
     * @param h
477
     *            Altura.
478
     */
479
    private void drawSymbolLegend(Graphics2D g, Rectangle2D re, double x,
480
        double y, ISymbol symbol2d, float sizefont, double h) {
481
        double pW = 5;
482
        double wl = (re.getWidth() / pW);
483
        double haux = (sizefont * 0.7);
484
        Font font = null;
485
486
        if (symbol2d instanceof ITextSymbol
487
            && (font = ((ITextSymbol) symbol2d).getFont()) != null) {
488
            ((ITextSymbol) symbol2d).setFont(new Font(font.getFontName(), font
489
                .getStyle(), (int) (wl / 6)));
490
        }
491
492
        Rectangle rectangle =
493
            new Rectangle((int) x, (int) ((y + (h / 2)) - haux), (int) wl,
494
                (int) haux);
495
        try {
496
            symbol2d.drawInsideRectangle(g, new AffineTransform(), rectangle,
497
                properties);
498
        } catch (SymbolDrawingException e) {
499
            if (e.getType() == SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS) {
500
                try {
501
                    mapContextManager
502
                        .getSymbolManager()
503
                        .getWarningSymbol(
504
                            SymbolDrawingException.STR_UNSUPPORTED_SET_OF_SETTINGS,
505
                            symbol2d.getDescription(),
506
                            SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS)
507
                        .drawInsideRectangle(g, null, rectangle, null);
508
                } catch (SymbolDrawingException e1) {
509
                    // IMPOSSIBLE TO REACH THIS
510
                }
511
            } else {
512
                // should be unreachable code
513
                throw new Error(PluginServices.getText(this,
514
                    "symbol_shapetype_mismatch"));
515
            }
516
        }
517
    }
518
519
    /**
520
     * A?ade al Layout un nuevo FFrameSymbol.
521
     *
522
     * @param layout
523
     *            Layout sobe el que se a?ade el FFrame.
524
     * @param x
525
     *            Posici?n X.
526
     * @param y
527
     *            Posici?n Y.
528
     * @param fs2d
529
     *            S?mbolo a a?adir.
530
     * @param h
531
     *            Altura.
532
     * @param shapeType
533
     * @param wT
534
     *            Rect?ngulo del FFrame.
535
     * @param hT
536
     *            tama?o de la fuente.
537
     */
538
    private void toFFrameSymbol(LayoutContext layout, Rectangle2D re, double x,
539
        double y, ISymbol fs2d, float sizefont, double h, int shapeType) {
540
        double pW = 5;
541
        double wl = (re.getWidth() / pW);
542
        double haux = (sizefont * 0.7);
543
        Font font = null;
544
        if (fs2d instanceof ITextSymbol
545
            && (font = ((ITextSymbol) fs2d).getFont()) != null) {
546
            ((ITextSymbol) fs2d).setFont(new Font(font.getFontName(), font
547
                .getStyle(), (int) (wl / 6)));
548
        }
549
550
        Rectangle2D rAux3 =
551
            new Rectangle2D.Double(x, ((y + (h / 2)) - haux), wl, haux);
552
        FFrameSymbol symbol =
553
            (FFrameSymbol) layoutManager
554
                .createFrame(FFrameSymbol.PERSISTENCE_DEFINITION_NAME);
555
556
        // symbol.setLayout(getLayout());
557
        symbol.setBoundBox(FLayoutUtilities.toSheetRect(rAux3, layout.getAT()));
558
        symbol.setSymbol(fs2d);
559
        symbol.setShapeType(shapeType);
560
        layout.addFFrame(symbol, false, true);
561
    }
562
563
    /**
564
     * Devuelve el n?mero total de capas incluyendo las subcapas.
565
     *
566
     * @param layers
567
     *            Capa a contar.
568
     *
569
     * @return N?mero de capas y subcapas.
570
     */
571
    private int getSizeNum(FLayers layers) {
572
        int n = 0;
573
574
        // ///Aqu? hay que calcular cuantos layers y sublayers hay, para saber
575
        // que distancias dejar entre uno y otro.
576
        // /y adem?s el tama?o de cada uno de ellos para saber que anchura
577
        // dejar.
578
        int l = 0;
579
        for (int i = layers.getLayersCount() - 1; i >= 0; i--) {
580
            FLayer layer = layers.getLayer(i);
581
            boolean b = false;
582
            if (nameLayers.size() > l
583
                && nameLayers.get(l).equals(layer.getName())) {
584
                b = ((Boolean) areVisible.get(l)).booleanValue();
585
            } else {
586
                b = layer.isVisible();
587
            }
588
            l++;
589
            if (b) {
590
                // if (layer.isVisible()) {
591
                if (layer.getName().length() > m_max) {
592
                    m_max = layer.getName().length();
593
                }
594
595
                if (layer instanceof FLayers) {
596
                    // n++;
597
                    n = n + 3;
598
                    n += getSizeNum((FLayers) layer); // m_numLayers +=
599
                                                      // getNumInLyrGroup((FLayers)
600
                                                      // layer);
601
                } else {
602
                    if (layer instanceof Classifiable) {
603
                        Classifiable cO = (Classifiable) layer;
604
                        n++;
605
606
                        if (cO.getLegend() instanceof IClassifiedLegend) {// &&
607
                                                                          // !(cO
608
                                                                          // instanceof
609
                                                                          // FLyrAnnotation))
610
                                                                          // {
611
                            IClassifiedLegend cli =
612
                                (IClassifiedLegend) cO.getLegend();
613
614
                            for (int j = 0; j < cli.getValues().length; j++) {
615
                                String s = cli.getDescriptions()[j];
616
617
                                if (s != null && s.length() > m_max) {
618
                                    m_max = s.length();
619
                                }
620
621
                                n++;
622
                            }
623
                        }
624
                    } else {
625
                        String s = layer.getName();
626
627
                        if (s != null && s.length() > m_max) {
628
                            m_max = s.length();
629
                        }
630
631
                        n++;
632
                    }
633
634
                }
635
            }
636
        }
637
638
        return n;
639
    }
640
641
    /**
642
     * Transforma el FFrameLegend en diferentes FFrameSymbol y FFrameText.
643
     *
644
     * @param layout
645
     *            Layout sobre el que a?adir los FFrame nuevos y sobre el
646
     *            que elimnar el FFrameLegend anterior.
647
     */
648
    public void toFFrames(LayoutContext layout) {
649
        Rectangle2D rectangle = getBoundingBox(null);
650
        double h = rectangle.getHeight() / m_numLayers;
651
        FLayers lays = layers;
652
653
        // layout.getEFS().startComplexCommand();
654
        // toFFrames(layout, lays, rectangle, r.getWidth(), r.getHeight(), h,
655
        // 0);
656
        int[] n = new int[1];
657
        n[0] = 0;
658
        drawLegendOrToFFrame(null, rectangle, h, lays, n, layout);
659
        layout.delFFrame(this);
660
661
        // /layout.getFFrames().remove(this);
662
        // layout.getEFS().endComplexCommand();
663
    }
664
665
    /**
666
     * Rellena la fuente a utilizar al dibujar los String sobre el graphics.
667
     *
668
     * @param f
669
     *            Font.
670
     */
671
    public void setFont(Font f) {
672
        m_font = f;
673
    }
674
675
    /**
676
     * Devuelve la fuente que esta utilizando.
677
     *
678
     * @return Font.
679
     */
680
    public Font getFont() {
681
        if (m_font != null) {
682
            return new Font(m_font.getName(), m_font.getStyle(), 9);
683
        }
684
        return new Font("SansSerif", Font.PLAIN, 9);
685
    }
686
687
    public String getNameFFrame() {
688
        return PluginServices.getText(this, "leyenda") + num;
689
    }
690
691
    public String getName() {
692
        return PERSISTENCE_DEFINITION_NAME;
693
    }
694
695
    public void print(Graphics2D g, AffineTransform at, Geometry geom,
696
        PrintAttributes properties) {
697
        this.properties = properties;
698
        draw(g, at, null, null);
699
        this.properties = null;
700
    }
701
702
    public void initialize() {
703
704
    }
705
706
    public void setNameLayers(List nameLayers) {
707
        this.nameLayers = nameLayers;
708
    }
709
710
    public void setAreVisible(List areVisible) {
711
        this.areVisible = areVisible;
712
    }
713
714
    public List getNameLayers() {
715
        return nameLayers;
716
    }
717
718
    public List getAreVisible() {
719
        return areVisible;
720
    }
721
722
    public static void registerPersistent() {
723
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
724
        if (manager.getDefinition(PERSISTENCE_DEFINITION_NAME) == null) {
725
            DynStruct definition =
726
                manager.addDefinition(FFrameLegend.class,
727
                    PERSISTENCE_DEFINITION_NAME,
728
                    "FFrameLegend persistence definition", null, null);
729
730
            definition
731
                .extend(manager
732
                    .getDefinition(AbstractFFrameViewDependence.PERSISTENCE_DEFINITION_NAME));
733
734
            definition.addDynFieldInt(NUMLAYERS_FIELD).setMandatory(true);
735
            definition.addDynFieldInt(MAX_FIELD).setMandatory(true);
736
            definition.addDynFieldInt(QUALITY_FIELD).setMandatory(true);
737
            definition.addDynFieldInt(VIEWING_FIELD).setMandatory(true);
738
            definition.addDynFieldObject(FONT_FIELD)
739
                .setClassOfValue(Font.class).setMandatory(true);
740
            definition.addDynFieldList(NAMELAYERS_FIELD)
741
                .setClassOfItems(String.class).setMandatory(true);
742
            definition.addDynFieldList(AREVISIBLE_FIELD)
743
                .setClassOfItems(Boolean.class).setMandatory(true);
744
        }
745
    }
746
747
    @Override
748
    public void loadFromState(PersistentState state)
749
        throws PersistenceException {
750
        super.loadFromState(state);
751
        m_numLayers = state.getInt(NUMLAYERS_FIELD);
752
        m_max = state.getInt(MAX_FIELD);
753
        m_quality = state.getInt(QUALITY_FIELD);
754
        m_viewing = state.getInt(VIEWING_FIELD);
755
        m_font = (Font) state.get(FONT_FIELD);
756
        nameLayers = (List<String>) state.getList(NAMELAYERS_FIELD);
757
        areVisible = (List<Boolean>) state.getList(AREVISIBLE_FIELD);
758
    }
759
760
    @Override
761
    public void saveToState(PersistentState state) throws PersistenceException {
762
        super.saveToState(state);
763
        state.set(NUMLAYERS_FIELD, m_numLayers);
764
        state.set(MAX_FIELD, m_max);
765
        state.set(QUALITY_FIELD, m_quality);
766
        state.set(VIEWING_FIELD, m_viewing);
767
        state.set(FONT_FIELD, m_font);
768
        state.set(NAMELAYERS_FIELD, nameLayers);
769
        state.set(AREVISIBLE_FIELD, areVisible);
770
    }
771
}