Revision 34228 branches/v2_0_0_prep/applications/appgvSIG/src/org/gvsig/app/project/documents/layout/fframes/FFrameLegend.java

View differences:

FFrameLegend.java
81 81
 * @author Vicente Caballero Navarro
82 82
 */
83 83
public class FFrameLegend extends AbstractFFrameViewDependence implements IFFrameViewDependence {
84
	public static final String PERSISTENCE_DEFINITION_NAME = "FFrameLegend";
85
	
86
	private static final String NUMLAYERS_FIELD = "numLayers";
87
	private static final String MAX_FIELD = "max";  
88
	private static final String QUALITY_FIELD = "quality"; 
89
	private static final String VIEWING_FIELD = "viewing"; 
90
	private static final String FONT_FIELD = "font";	
91
	private static final String INDEX_FIELD = "index";
92
	private static final String NAMELAYERS_FIELD = "nameLayers";
93
	private static final String AREVISIBLE_FIELD = "areVisible";  
94
	
95
	private static final int PRESENTACION = 0;
84
    public static final String PERSISTENCE_DEFINITION_NAME = "FFrameLegend";
85

  
86
    private static final String NUMLAYERS_FIELD = "numLayers";
87
    private static final String MAX_FIELD = "max";  
88
    private static final String QUALITY_FIELD = "quality"; 
89
    private static final String VIEWING_FIELD = "viewing"; 
90
    private static final String FONT_FIELD = "font";	
91
    private static final String NAMELAYERS_FIELD = "nameLayers";
92
    private static final String AREVISIBLE_FIELD = "areVisible";  
93

  
94
    private static final int PRESENTACION = 0;
96 95
    private static final int BORRADOR = 1;
97 96
    private int m_quality = 0;
98 97
    private int m_viewing = 0;
99 98
    private Font m_font = new Font("SansSerif", Font.PLAIN, 9);
100
    private FFrameView fframeview = null;
101 99
    private int m_max;
102 100
    private int m_numLayers;
103 101
    private FLayers layers = null;
104
    private int dependenceIndex = -1;
105
	private List<String> nameLayers = new ArrayList<String>();
106
	private List<Boolean> areVisible = new ArrayList<Boolean>();
107
	private PrintAttributes properties;
102
    private List<String> nameLayers = new ArrayList<String>();
103
    private List<Boolean> areVisible = new ArrayList<Boolean>();
104
    private PrintAttributes properties;
108 105

  
109 106
    private MapContextManager mapContextManager = MapContextLocator
110
			.getMapContextManager();
107
    .getMapContextManager();
111 108

  
112
	public FFrameLegend() {
109
    public FFrameLegend() {
113 110

  
114
	}
111
    }
115 112
    /**
116 113
     * Rellena la calidad que se quiere aplicar.
117 114
     *
......
140 137
    }
141 138

  
142 139
    /**
143
     * Inserta una FFrameView de donde se obtiene la informaci?n de las capas
144
     * para generar la leyenda.
145
     *
146
     * @param f FFrameView para obtener los nombres de las capas.
147
     */
148
    public void setFFrameDependence(IFFrame f) {
149
        fframeview = (FFrameView) f;
150
    }
151

  
152
    public void refreshDependence(IFFrame fant, IFFrame fnew) {
153
    	if ((fframeview != null) &&
154
                fframeview.equals(fant)) {
155
            fframeview=(FFrameView)fnew;
156
    	}
157
    }
158
    /**
159
     * Devuelve el FFrameView utilizado para obtener la leyenda.
160
     *
161
     * @return FFrameView utilizado.
162
     */
163
    public IFFrame[] getFFrameDependence() {
164
        return new IFFrame[]{fframeview};
165
    }
166

  
167
    /**
168 140
     * Rellena la forma de actualizar la vista.
169 141
     *
170 142
     * @param v entero que representa la forma de actualizar la vista.
......
189 161
        g.rotate(Math.toRadians(getRotation()), re.x + (re.width / 2),
190 162
            re.y + (re.height / 2));
191 163

  
192
        if ((fframeview != null) && (fframeview.getMapContext() != null)) {
193
            layers = fframeview.getMapContext().getLayers();
164
        if ((fframeViewDependence != null) && (fframeViewDependence.getMapContext() != null)) {
165
            layers = fframeViewDependence.getMapContext().getLayers();
194 166
        }
195 167

  
196 168
        m_max = 0;
......
242 214
            boolean b=false;
243 215

  
244 216
            if (nameLayers.size()>l && nameLayers.get(l).equals(layer.getName())) {
245
            	b=((Boolean)areVisible.get(l)).booleanValue();
217
                b=((Boolean)areVisible.get(l)).booleanValue();
246 218
            }else {
247
            	b=layer.isVisible();
219
                b=layer.isVisible();
248 220
            }
249 221
            l++;
250 222
            if (b) {
......
256 228
                    double xl = (re.getX() + dX);
257 229
                    double yl = (re.getY() + dY);
258 230
                    if (layout!=null) {
259
                    	toFFrameText(layout,layer.getName(),re,sizefont,(xl - (re.getWidth() / 5)),yl,h);
231
                        toFFrameText(layout,layer.getName(),re,sizefont,(xl - (re.getWidth() / 5)),yl,h);
260 232
                    }else {
261
                    	drawNameLegend(g, layer.getName(), re, sizefont,
262
                    			(xl - (re.getWidth() / 5)), yl, h);
233
                        drawNameLegend(g, layer.getName(), re, sizefont,
234
                            (xl - (re.getWidth() / 5)), yl, h);
263 235
                    }
264
                    	n[0]++;
236
                    n[0]++;
265 237
                    drawLegendOrToFFrame(g, re, h, (FLayers) layer, n, layout);
266 238
                    n[0]++;
267 239
                } else if (layer instanceof Classifiable && !(layer instanceof IHasImageLegend) ) {
......
275 247
                        double xl = (re.getX() + dX);
276 248
                        double yl = (re.getY() + dY);
277 249
                        if (layout!=null) {
278
                        	toFFrameText(layout,layer.getName(),re,sizefont,(xl - (re.getWidth() / 5)),yl,h);
250
                            toFFrameText(layout,layer.getName(),re,sizefont,(xl - (re.getWidth() / 5)),yl,h);
279 251
                        }else {
280
                        	drawNameLegend(g, layer.getName(), re, sizefont,
281
                        			(xl - (re.getWidth() / 5)), yl, h);
252
                            drawNameLegend(g, layer.getName(), re, sizefont,
253
                                (xl - (re.getWidth() / 5)), yl, h);
282 254
                        }
283 255
                        n[0]++;
284 256
                        String[] descriptions=cli.getDescriptions();
......
291 263

  
292 264
                            String s = descriptions[j];
293 265
                            if (layout!=null) {
294
                            	toFFrameText(layout,s,re,sizefont,xl,yl,h);
266
                                toFFrameText(layout,s,re,sizefont,xl,yl,h);
295 267
                            }else {
296
                            	drawNameLegend(g, s, re, sizefont, xl, yl, h);
268
                                drawNameLegend(g, s, re, sizefont, xl, yl, h);
297 269
                            }
298 270
                            ISymbol fs2d = symbols[j];
299 271
                            if (layout!=null) {
300
                            	try {
301
									toFFrameSymbol(layout, re, xl, yl, fs2d,
302
											sizefont, h, cO.getShapeType());
303
								} catch (ReadException e) {
304
									e.printStackTrace();
305
								}
272
                                try {
273
                                    toFFrameSymbol(layout, re, xl, yl, fs2d,
274
                                        sizefont, h, cO.getShapeType());
275
                                } catch (ReadException e) {
276
                                    e.printStackTrace();
277
                                }
306 278
                            }else {
307
                            	drawSymbolLegend(g, re, xl, yl, fs2d, sizefont,
308
                            			h);
279
                                drawSymbolLegend(g, re, xl, yl, fs2d, sizefont,
280
                                    h);
309 281
                            }
310 282
                            n[0]++;
311 283
                        }
......
316 288
                        double xl = (re.getX() + dX);
317 289
                        double yl = (re.getY() + dY);
318 290
                        if (layout!=null) {
319
                        	toFFrameText(layout,layer.getName(),re,sizefont,xl,yl,h);
291
                            toFFrameText(layout,layer.getName(),re,sizefont,xl,yl,h);
320 292
                        }else {
321
                        	drawNameLegend(g, layer.getName(), re, sizefont, xl,
322
                        			yl, h);
293
                            drawNameLegend(g, layer.getName(), re, sizefont, xl,
294
                                yl, h);
323 295
                        }
324 296
                        // TO DO: CAMBIAR TO_DO ESTO PARA QUE ACEPTE ISYMBOL
325 297
                        // TODO: comprovar que no es trenca res
326 298
                        if (cO.getLegend() != null) {
327
							ISymbol fs2d = cO.getLegend().getDefaultSymbol();
299
                            ISymbol fs2d = cO.getLegend().getDefaultSymbol();
328 300

  
329
							if (layout != null) {
330
								try {
331
									toFFrameSymbol(layout, re, xl, yl, fs2d,
332
											sizefont, h, cO.getShapeType());
333
								} catch (ReadException e) {
334
									e.printStackTrace();
335
								}
336
							} else {
337
								drawSymbolLegend(g, re, xl, yl, fs2d, sizefont,
338
										h);
339
							}
340
						}
301
                            if (layout != null) {
302
                                try {
303
                                    toFFrameSymbol(layout, re, xl, yl, fs2d,
304
                                        sizefont, h, cO.getShapeType());
305
                                } catch (ReadException e) {
306
                                    e.printStackTrace();
307
                                }
308
                            } else {
309
                                drawSymbolLegend(g, re, xl, yl, fs2d, sizefont,
310
                                    h);
311
                            }
312
                        }
341 313
                        n[0]++;
342 314
                    }
343 315
                }else if (layer instanceof IHasImageLegend){
344
                	Image image=((IHasImageLegend)layer).getImageLegend();
345
                	String path=((IHasImageLegend)layer).getPathImage();
346
                	if (image!=null) {
347
                	FFramePicture picture =(FFramePicture)layoutManager.createFrame(FFramePicture.PERSISTENCE_DEFINITION_NAME);
316
                    Image image=((IHasImageLegend)layer).getImageLegend();
317
                    String path=((IHasImageLegend)layer).getPathImage();
318
                    if (image!=null) {
319
                        FFramePicture picture =(FFramePicture)layoutManager.createFrame(FFramePicture.PERSISTENCE_DEFINITION_NAME);
348 320

  
349
//                	picture.setLayout(getLayout());
350
                	BufferedImage bi = new BufferedImage(image.getWidth(null),
321
                        //                	picture.setLayout(getLayout());
322
                        BufferedImage bi = new BufferedImage(image.getWidth(null),
351 323
                            image.getHeight(null), BufferedImage.TYPE_INT_ARGB);
352
                    Graphics2D biContext = bi.createGraphics();
353
                    biContext.drawImage(image, 0, 0, null);
354
                    picture.setImage(bi);
355
                    double dY = n[0] * h;
356
                    Rectangle2D rectImage=new Rectangle2D.Double(re.getX(),re.getY()+dY,re.getWidth(),h);
357
                   if (layout!=null) {
358
                    	picture.setBoundBox(FLayoutUtilities.toSheetRect(rectImage, layout.getAT()));
359
                    	picture.setPath(path);
360
                    	layout.addFFrame(picture, false, true);
361
                    }else {
362
                    	picture.setBoundBox(FLayoutUtilities.toSheetRect(rectImage,new AffineTransform()));
363
                        picture.draw(g,new AffineTransform(),re,bi);
324
                        Graphics2D biContext = bi.createGraphics();
325
                        biContext.drawImage(image, 0, 0, null);
326
                        picture.setImage(bi);
327
                        double dY = n[0] * h;
328
                        Rectangle2D rectImage=new Rectangle2D.Double(re.getX(),re.getY()+dY,re.getWidth(),h);
329
                        if (layout!=null) {
330
                            picture.setBoundBox(FLayoutUtilities.toSheetRect(rectImage, layout.getAT()));
331
                            picture.setPath(path);
332
                            layout.addFFrame(picture, false, true);
333
                        }else {
334
                            picture.setBoundBox(FLayoutUtilities.toSheetRect(rectImage,new AffineTransform()));
335
                            picture.draw(g,new AffineTransform(),re,bi);
336
                        }
364 337
                    }
365
                	}
366 338
                    n[0]++;
367 339
                }else {
368
                	double dX = 0;
340
                    double dX = 0;
369 341
                    double dY = n[0] * h;
370 342

  
371 343
                    double xl = (re.getX() + dX);
372 344
                    double yl = (re.getY() + dY);
373 345
                    if (layout!=null) {
374
                    	toFFrameText(layout,layer.getName(),re,sizefont,xl,yl,h);
346
                        toFFrameText(layout,layer.getName(),re,sizefont,xl,yl,h);
375 347
                    }else {
376
                    	drawNameLegend(g, layer.getName(), re, sizefont, xl,
377
                    			yl, h);
348
                        drawNameLegend(g, layer.getName(), re, sizefont, xl,
349
                            yl, h);
378 350
                    }
379 351
                    n[0]++;
380 352
                }
......
400 372
        g.setFont(f);
401 373
        g.setColor(Color.black);
402 374
        if (name!=null)
403
        	g.drawString(name, (float) (x + (re.getWidth() / 4)),
404
        			(float) (y + (h / 2)));
375
            g.drawString(name, (float) (x + (re.getWidth() / 4)),
376
                (float) (y + (h / 2)));
405 377
    }
406 378

  
407 379
    private Font getFont(float sizefont) {
408
		Font f=getFont();
409
		return new Font(f.getName(),f.getStyle(),(int)sizefont);
410
  }
380
        Font f=getFont();
381
        return new Font(f.getName(),f.getStyle(),(int)sizefont);
382
    }
411 383

  
412
	/**
384
    /**
413 385
     * A?ade al Layout un nuevo FFrameText a partir de los par?metros de
414 386
     * entrada.
415 387
     *
416 388
     * @param layout Layout sobre el que se crea el nuevo FFrame.
417
	 * @param name Texto.
418
	 * @param sizefont tama?o de la fuente.
419
	 * @param x Posici?n X.
420
	 * @param y Posici?n Y.
421
	 * @param h Altura.
422
	 * @param wT Rect?ngulo del FFrame.
423
	 * @param hT DOCUMENT ME!
389
     * @param name Texto.
390
     * @param sizefont tama?o de la fuente.
391
     * @param x Posici?n X.
392
     * @param y Posici?n Y.
393
     * @param h Altura.
394
     * @param wT Rect?ngulo del FFrame.
395
     * @param hT DOCUMENT ME!
424 396
     */
425 397
    private void toFFrameText(LayoutContext layout, String name, Rectangle2D re,
426
            float sizefont, double x, double y, double h) {
427
            //Font f = getFont(sizefont);
428
            Rectangle2D rAux = new Rectangle2D.Double(x+re.getWidth()/4, ((y + (h / 2)) - h),
429
                    re.getWidth()-re.getWidth()/4, h);
430
            FFrameText text =(FFrameText)layoutManager.createFrame(FFrameText.PERSISTENCE_DEFINITION_NAME);
398
        float sizefont, double x, double y, double h) {
399
        //Font f = getFont(sizefont);
400
        Rectangle2D rAux = new Rectangle2D.Double(x+re.getWidth()/4, ((y + (h / 2)) - h),
401
            re.getWidth()-re.getWidth()/4, h);
402
        FFrameText text =(FFrameText)layoutManager.createFrame(FFrameText.PERSISTENCE_DEFINITION_NAME);
431 403

  
432
//            text.setLayout(getLayout());
433
            text.setFixedFontSize(true);
434
            //text.setFontSize((int) (sizefont*1.4));
435
            double myScale = layout.getAT().getScaleX() * 0.0234;
436
            text.setFontSize((int)(sizefont/myScale));
437
            text.setBoundBox(FLayoutUtilities.toSheetRect(rAux, layout.getAT()));
438
            text.addText(name);
439
            layout.addFFrame(text, false, true);
440
        }
404
        //            text.setLayout(getLayout());
405
        text.setFixedFontSize(true);
406
        //text.setFontSize((int) (sizefont*1.4));
407
        double myScale = layout.getAT().getScaleX() * 0.0234;
408
        text.setFontSize((int)(sizefont/myScale));
409
        text.setBoundBox(FLayoutUtilities.toSheetRect(rAux, layout.getAT()));
410
        text.addText(name);
411
        layout.addFFrame(text, false, true);
412
    }
441 413

  
442 414
    /**
443 415
     * Dibuja sobre el Graphics2D el s?mbolo.
......
451 423
     * @param h Altura.
452 424
     */
453 425
    private void drawSymbolLegend(Graphics2D g, Rectangle2D re, double x,
454
    	double y, ISymbol symbol2d, float sizefont, double h) {
455
    	double pW = 5;
456
    	double wl = (re.getWidth() / pW);
457
    	double haux = (sizefont * 0.7);
458
    	Font font=null;
426
        double y, ISymbol symbol2d, float sizefont, double h) {
427
        double pW = 5;
428
        double wl = (re.getWidth() / pW);
429
        double haux = (sizefont * 0.7);
430
        Font font=null;
459 431

  
460
    	if (symbol2d instanceof ITextSymbol && (font=((ITextSymbol)symbol2d).getFont()) != null) {
461
    		((ITextSymbol)symbol2d).setFont(new Font(font.getFontName(), font.getStyle(),
462
    				(int) (wl / 6)));
463
    	}
432
        if (symbol2d instanceof ITextSymbol && (font=((ITextSymbol)symbol2d).getFont()) != null) {
433
            ((ITextSymbol)symbol2d).setFont(new Font(font.getFontName(), font.getStyle(),
434
                (int) (wl / 6)));
435
        }
464 436

  
465
		Rectangle rectangle = new Rectangle((int) x, (int) ((y + (h / 2)) - haux), (int) wl,
466
				(int) haux);
467
		try {
468
			symbol2d.drawInsideRectangle(g, new AffineTransform(),
469
					rectangle, properties);
470
		} catch (SymbolDrawingException e) {
471
			if (e.getType() == SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS) {
472
				try {
473
					mapContextManager.getSymbolManager()
474
							.getWarningSymbol(
475
									SymbolDrawingException.STR_UNSUPPORTED_SET_OF_SETTINGS,
476
									symbol2d.getDescription(),
477
									SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS)
478
							.drawInsideRectangle(g, null, rectangle, null);
479
				} catch (SymbolDrawingException e1) {
480
					// IMPOSSIBLE TO REACH THIS
481
				}
482
			} else {
483
				// should be unreachable code
484
				throw new Error(PluginServices.getText(this, "symbol_shapetype_mismatch"));
485
			}
486
		}
437
        Rectangle rectangle = new Rectangle((int) x, (int) ((y + (h / 2)) - haux), (int) wl,
438
            (int) haux);
439
        try {
440
            symbol2d.drawInsideRectangle(g, new AffineTransform(),
441
                rectangle, properties);
442
        } catch (SymbolDrawingException e) {
443
            if (e.getType() == SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS) {
444
                try {
445
                    mapContextManager.getSymbolManager()
446
                    .getWarningSymbol(
447
                        SymbolDrawingException.STR_UNSUPPORTED_SET_OF_SETTINGS,
448
                        symbol2d.getDescription(),
449
                        SymbolDrawingException.UNSUPPORTED_SET_OF_SETTINGS)
450
                        .drawInsideRectangle(g, null, rectangle, null);
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
        }
487 459
    }
488 460

  
489 461
    /**
......
499 471
     * @param hT tama?o de la fuente.
500 472
     */
501 473
    private void toFFrameSymbol(LayoutContext layout, Rectangle2D re, double x,
502
            double y, ISymbol fs2d, float sizefont, double h, int shapeType) {
503
            double pW = 5;
504
            double wl = (re.getWidth() / pW);
505
            double haux = (sizefont * 0.7);
506
            Font font=null;
507
            if (fs2d instanceof ITextSymbol && (font=((ITextSymbol)fs2d).getFont()) != null) {
508
              ((ITextSymbol)fs2d).setFont(new Font(font.getFontName(), font.getStyle(),
509
                      (int) (wl / 6)));
510
            }
474
        double y, ISymbol fs2d, float sizefont, double h, int shapeType) {
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
        }
511 483

  
512
            Rectangle2D rAux3 = new Rectangle2D.Double(x, ((y + (h / 2)) - haux),
513
                    wl, haux);
514
            FFrameSymbol symbol =(FFrameSymbol)layoutManager.createFrame(FFrameSymbol.PERSISTENCE_DEFINITION_NAME);
484
        Rectangle2D rAux3 = new Rectangle2D.Double(x, ((y + (h / 2)) - haux),
485
            wl, haux);
486
        FFrameSymbol symbol =(FFrameSymbol)layoutManager.createFrame(FFrameSymbol.PERSISTENCE_DEFINITION_NAME);
515 487

  
516
//            symbol.setLayout(getLayout());
517
            symbol.setBoundBox(FLayoutUtilities.toSheetRect(rAux3, layout.getAT()));
518
            symbol.setSymbol(fs2d);
519
            symbol.setShapeType(shapeType);
520
            layout.addFFrame(symbol, false, true);
521
        }
488
        //            symbol.setLayout(getLayout());
489
        symbol.setBoundBox(FLayoutUtilities.toSheetRect(rAux3, layout.getAT()));
490
        symbol.setSymbol(fs2d);
491
        symbol.setShapeType(shapeType);
492
        layout.addFFrame(symbol, false, true);
493
    }
522 494

  
523 495
    /**
524 496
     * Devuelve el n?mero total de capas incluyendo las subcapas.
......
537 509
            FLayer layer = layers.getLayer(i);
538 510
            boolean b=false;
539 511
            if (nameLayers.size()>l && nameLayers.get(l).equals(layer.getName())) {
540
            	b=((Boolean)areVisible.get(l)).booleanValue();
512
                b=((Boolean)areVisible.get(l)).booleanValue();
541 513
            }else {
542
            	b=layer.isVisible();
514
                b=layer.isVisible();
543 515
            }
544 516
            l++;
545 517
            if (b) {
546
            //if (layer.isVisible()) {
518
                //if (layer.isVisible()) {
547 519
                if (layer.getName().length() > m_max) {
548 520
                    m_max = layer.getName().length();
549 521
                }
550 522

  
551 523
                if (layer instanceof FLayers) {
552 524
                    //n++;
553
                	n = n + 3;
525
                    n = n + 3;
554 526
                    n += getSizeNum((FLayers) layer); //m_numLayers += getNumInLyrGroup((FLayers) layer);
555 527
                } else {
556
                	if (layer instanceof Classifiable) {
557
                    Classifiable cO = (Classifiable) layer;
558
                    n++;
528
                    if (layer instanceof Classifiable) {
529
                        Classifiable cO = (Classifiable) layer;
530
                        n++;
559 531

  
560
                    if (cO.getLegend() instanceof IClassifiedLegend){// && !(cO instanceof FLyrAnnotation)) {
561
                        IClassifiedLegend cli = (IClassifiedLegend) cO.getLegend();
532
                        if (cO.getLegend() instanceof IClassifiedLegend){// && !(cO instanceof FLyrAnnotation)) {
533
                            IClassifiedLegend cli = (IClassifiedLegend) cO.getLegend();
562 534

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

  
566
                            if (s != null && s.length() > m_max) {
567
                                m_max = s.length();
538
                                if (s != null && s.length() > m_max) {
539
                                    m_max = s.length();
540
                                }
541

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

  
570
                            n++;
548
                        if (s != null && s.length() > m_max) {
549
                            m_max = s.length();
571 550
                        }
551

  
552
                        n++;
572 553
                    }
573
                	}else{
574
                		  String s = layer.getName();
575 554

  
576
                          if (s != null && s.length() > m_max) {
577
                              m_max = s.length();
578
                          }
579

  
580
                          n++;
581
                	}
582

  
583 555
                }
584 556
            }
585 557
        }
......
604 576
        int[] n = new int[1];
605 577
        n[0] = 0;
606 578
        drawLegendOrToFFrame(null,rectangle,h,lays,n,layout);
607
		layout.delFFrame(this);
579
        layout.delFFrame(this);
608 580

  
609 581
        ///layout.getFFrames().remove(this);
610 582
        //layout.getEFS().endComplexCommand();
......
626 598
     */
627 599
    public Font getFont() {
628 600
        if (m_font != null) {
629
        	return new Font(m_font.getName(),m_font.getStyle(),9);
630
        //    return new Font(m_f.getFontName(), m_f.getStyle(), 9);
601
            return new Font(m_font.getName(),m_font.getStyle(),9);
602
            //    return new Font(m_f.getFontName(), m_f.getStyle(), 9);
631 603
        }
632 604
        return new Font("SansSerif",Font.PLAIN,9);
633 605
    }
634
   
606

  
635 607
    /*
636 608
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#getNameFFrame()
637 609
     */
638 610
    public String getNameFFrame() {
639 611
        return PluginServices.getText(this, "leyenda")+ num;
640 612
    }
641
    
613

  
642 614
    public String getName() {
643 615
        return PERSISTENCE_DEFINITION_NAME;
644 616
    }
......
648 620
     *      java.awt.geom.AffineTransform)
649 621
     */
650 622
    public void print(Graphics2D g, AffineTransform at, Geometry geom,
651
			PrintAttributes properties) {
652
    	this.properties=properties;
623
        PrintAttributes properties) {
624
        this.properties=properties;
653 625
        draw(g, at, null, null);
654 626
        this.properties=null;
655 627
    }
628
   
629
    public void initialize() {
630
        // TODO Auto-generated method stub
656 631

  
657
    /**
658
     * Actualiza las dependencias que tenga este FFrame con el resto.
659
     *
660
     * @param fframes Resto de FFrames.
661
     */
662
    public void initDependence(IFFrame[] fframes) {
663
        if ((dependenceIndex != -1) &&
664
                fframes[dependenceIndex] instanceof FFrameView) {
665
            fframeview = (FFrameView) fframes[dependenceIndex];
666
        }
667 632
    }
668 633

  
669
	public void initialize() {
670
		// TODO Auto-generated method stub
634
    public void setNameLayers(List nameLayers) {
635
        this.nameLayers = nameLayers;
636
    }
671 637

  
672
	}
638
    public void setAreVisible(List areVisible) {
639
        this.areVisible = areVisible;
640
    }
673 641

  
674
	public void setNameLayers(List nameLayers) {
675
		this.nameLayers = nameLayers;
676
	}
642
    public List getNameLayers() {
643
        return nameLayers;
644
    }
677 645

  
678
	public void setAreVisible(List areVisible) {
679
		this.areVisible = areVisible;
680
	}
646
    public List getAreVisible() {
647
        return areVisible;
648
    }
681 649

  
682
	public List getNameLayers() {
683
		return nameLayers;
684
	}
650
    public static void registerPersistent() {
651
        PersistenceManager manager = ToolsLocator.getPersistenceManager();
652
        if( manager.getDefinition(PERSISTENCE_DEFINITION_NAME)==null ) {
653
            DynStruct definition = manager.addDefinition(
654
                FFrameLegend.class,
655
                PERSISTENCE_DEFINITION_NAME,
656
                "FFrameLegend persistence definition",
657
                null, 
658
                null
659
            ); 
685 660

  
686
	public List getAreVisible() {
687
		return areVisible;
688
	}
661
            definition.extend(manager.getDefinition(AbstractFFrameViewDependence.PERSISTENCE_DEFINITION_NAME));	
689 662

  
690
	public static void registerPersistent() {
691
		PersistenceManager manager = ToolsLocator.getPersistenceManager();
692
		if( manager.getDefinition(PERSISTENCE_DEFINITION_NAME)==null ) {
693
			DynStruct definition = manager.addDefinition(
694
					FFrameLegend.class,
695
					PERSISTENCE_DEFINITION_NAME,
696
					"FFrameLegend persistence definition",
697
					null, 
698
					null
699
			); 
663
            definition.addDynFieldInt(NUMLAYERS_FIELD).setMandatory(true);	
664
            definition.addDynFieldInt(MAX_FIELD).setMandatory(true);	
665
            definition.addDynFieldInt(QUALITY_FIELD).setMandatory(true);	
666
            definition.addDynFieldInt(VIEWING_FIELD).setMandatory(true);	
667
            definition.addDynFieldObject(FONT_FIELD).setClassOfValue(Font.class).setMandatory(true);				
668
            definition.addDynFieldList(NAMELAYERS_FIELD).setClassOfItems(String.class).setMandatory(true);
669
            definition.addDynFieldList(AREVISIBLE_FIELD).setClassOfItems(Boolean.class).setMandatory(true);
670
        }
671
    }
700 672

  
701
			definition.extend(manager.getDefinition(FFrame.PERSISTENCE_DEFINITION_NAME));	
702

  
703
			definition.addDynFieldInt(NUMLAYERS_FIELD).setMandatory(true);	
704
			definition.addDynFieldInt(MAX_FIELD).setMandatory(true);	
705
			definition.addDynFieldInt(QUALITY_FIELD).setMandatory(true);	
706
			definition.addDynFieldInt(VIEWING_FIELD).setMandatory(true);	
707
			definition.addDynFieldObject(FONT_FIELD).setClassOfValue(Font.class).setMandatory(true);	
708
			definition.addDynFieldInt(INDEX_FIELD);
709
			definition.addDynFieldList(NAMELAYERS_FIELD).setClassOfItems(String.class).setMandatory(true);
710
			definition.addDynFieldList(AREVISIBLE_FIELD).setClassOfItems(Boolean.class).setMandatory(true);
711
		}
712
	}
713

  
714
	@Override
715
	public void loadFromState(PersistentState state)
716
	throws PersistenceException {
717
		super.loadFromState(state);
718
		m_numLayers = state.getInt(NUMLAYERS_FIELD);
719
		m_max = state.getInt(MAX_FIELD); 	
720
		m_quality = state.getInt(QUALITY_FIELD);
721
		m_viewing = state.getInt(VIEWING_FIELD); 	
722
		m_font = (Font)state.get(FONT_FIELD); 		
723
		dependenceIndex = state.getInt(INDEX_FIELD);
673
    @Override
674
    public void loadFromState(PersistentState state)
675
    throws PersistenceException {
676
        super.loadFromState(state);
677
        m_numLayers = state.getInt(NUMLAYERS_FIELD);
678
        m_max = state.getInt(MAX_FIELD); 	
679
        m_quality = state.getInt(QUALITY_FIELD);
680
        m_viewing = state.getInt(VIEWING_FIELD); 	
681
        m_font = (Font)state.get(FONT_FIELD); 				
724 682
        nameLayers = (List<String>)state.getList(NAMELAYERS_FIELD);
725 683
        areVisible = (List<Boolean>)state.getList(AREVISIBLE_FIELD);
726
	}
684
    }
727 685

  
728
	@Override
729
	public void saveToState(PersistentState state) throws PersistenceException {
730
		super.saveToState(state);
731
		state.set(NUMLAYERS_FIELD, m_numLayers);
732
		state.set(MAX_FIELD, m_max);  
733
		state.set(QUALITY_FIELD, m_quality); 
734
		state.set(VIEWING_FIELD, m_viewing); 
735
		state.set(FONT_FIELD, m_font); 		
736
		
737
       if (fframeview != null) {           
738
           IFFrame[] fframes = getLayoutContext().getAllFFrames();
739

  
740
           for (int i = 0; i < fframes.length; i++) {
741
               if (fframeview.equals(fframes[i])) {
742
                   state.set(INDEX_FIELD, i);
743
                   break;
744
               }
745
           }
746
       }
747

  
748
       state.set(NAMELAYERS_FIELD, nameLayers);
749
       state.set(AREVISIBLE_FIELD, areVisible);  
750
	}
686
    @Override
687
    public void saveToState(PersistentState state) throws PersistenceException {
688
        super.saveToState(state);
689
        state.set(NUMLAYERS_FIELD, m_numLayers);
690
        state.set(MAX_FIELD, m_max);  
691
        state.set(QUALITY_FIELD, m_quality); 
692
        state.set(VIEWING_FIELD, m_viewing); 
693
        state.set(FONT_FIELD, m_font); 	
694
        state.set(NAMELAYERS_FIELD, nameLayers);
695
        state.set(AREVISIBLE_FIELD, areVisible);  
696
    }
751 697
}

Also available in: Unified diff