Revision 3610 trunk/applications/appgvSIG/src/com/iver/cit/gvsig/gui/layout/fframes/FFrameLegend.java

View differences:

FFrameLegend.java
40 40
 */
41 41
package com.iver.cit.gvsig.gui.layout.fframes;
42 42

  
43
import java.awt.Color;
44
import java.awt.Font;
45
import java.awt.Graphics2D;
46
import java.awt.Rectangle;
47
import java.awt.geom.AffineTransform;
48
import java.awt.geom.Rectangle2D;
49
import java.awt.image.BufferedImage;
43
import com.iver.andami.PluginServices;
50 44

  
51
import com.iver.andami.PluginServices;
52 45
import com.iver.cit.gvsig.fmap.DriverException;
53 46
import com.iver.cit.gvsig.fmap.core.v02.FGraphicUtilities;
54 47
import com.iver.cit.gvsig.fmap.core.v02.FSymbol;
......
60 53
import com.iver.cit.gvsig.gui.layout.FLayoutUtilities;
61 54
import com.iver.cit.gvsig.gui.layout.Layout;
62 55
import com.iver.cit.gvsig.gui.project.SaveException;
56

  
63 57
import com.iver.utiles.XMLEntity;
64 58

  
59
import java.awt.Color;
60
import java.awt.Font;
61
import java.awt.Graphics2D;
62
import java.awt.Rectangle;
63
import java.awt.geom.AffineTransform;
64
import java.awt.geom.Rectangle2D;
65
import java.awt.image.BufferedImage;
65 66

  
67

  
66 68
/**
67 69
 * FFrame para introducir una leyenda en el Layout.
68 70
 *
......
79 81
    private int m_max;
80 82
    private int m_numLayers;
81 83
    private FLayers layers = null;
82
    private int dependenceIndex=-1;
84
    private int dependenceIndex = -1;
83 85

  
84 86
    /**
85 87
     * Rellena la calidad que se quiere aplicar.
......
195 197
    private void drawTheme(Graphics2D g, Rectangle2D re, double h,
196 198
        FLayers layers, int[] n, int typeFont) throws DriverException {
197 199
        float sizefont = 0;
198
        
199
        if ((re.getHeight() / m_numLayers) < (re.getWidth() /(m_max * 0.7))) {
200

  
201
        if ((re.getHeight() / m_numLayers) < (re.getWidth() / (m_max * 0.7))) {
200 202
            sizefont = (float) (re.getHeight() / m_numLayers);
201 203
        } else {
202 204
            sizefont = (float) (re.getWidth() / (m_max * 0.7));
203 205
        }
206

  
204 207
        //////Se recorren los layers dibujando el s?mbolo y su nombre sobre el graphics	
205
        for (int i =layers.getLayersCount()-1; i >=0; i--) {
208
        for (int i = layers.getLayersCount() - 1; i >= 0; i--) {
206 209
            FLayer layer = (FLayer) layers.getLayer(i);
207 210

  
208 211
            if (layer.isVisible()) {
......
298 301
     *
299 302
     * @param layout Layout sobre el que se crea el nuevo FFrame.
300 303
     * @param name Texto.
301
     * @param re Rect?ngulo del FFrame.
304
     * @param wT Rect?ngulo del FFrame.
305
     * @param hT DOCUMENT ME!
302 306
     * @param sizefont tama?o de la fuente.
303 307
     * @param x Posici?n X.
304 308
     * @param y Posici?n Y.
305 309
     * @param h Altura.
306 310
     */
307
    private void toFFrameText(Layout layout, String name, double wT,double hT,
311
    private void toFFrameText(Layout layout, String name, double wT, double hT,
308 312
        float sizefont, double x, double y, double h) {
309
    	double wl = (wT / 1.5);
310
        double haux = hT/(m_numLayers*1.3);//(sizefont * 0.7);
311
        if (haux>(wl/3)){
312
        	haux=wl/3;
313
        double wl = (wT / 1.5);
314
        double haux = hT / (m_numLayers * 1.3); //(sizefont * 0.7);
315

  
316
        if (haux > (wl / 3)) {
317
            haux = wl / 3;
313 318
        }
314
        Rectangle2D rAux = new Rectangle2D.Double(x, ((y + (h / 2)) - haux), wl, haux);
319

  
320
        Rectangle2D rAux = new Rectangle2D.Double(x, ((y + (h / 2)) - haux),
321
                wl, haux);
315 322
        FFrameText text = new FFrameText();
316 323
        text.setFixedFontSize(true);
317 324
        text.setFontSize((int) sizefont);
......
353 360
     * A?ade al Layout un nuevo FFrameSymbol.
354 361
     *
355 362
     * @param layout Layout sobe el que se a?ade el FFrame.
356
     * @param re Rect?ngulo del FFrame.
363
     * @param wT Rect?ngulo del FFrame.
364
     * @param hT tama?o de la fuente.
357 365
     * @param x Posici?n X.
358 366
     * @param y Posici?n Y.
359 367
     * @param fs2d S?mbolo a a?adir.
360
     * @param sizefont tama?o de la fuente.
361 368
     * @param type Tipo de s?mbolo.
362 369
     * @param h Altura.
363 370
     */
364
    private void toFFrameSymbol(Layout layout, double wT, double hT,double x,
371
    private void toFFrameSymbol(Layout layout, double wT, double hT, double x,
365 372
        double y, FSymbol fs2d, int type, double h) {
366 373
        double pW = 5;
367 374
        double wl = (wT / pW);
368
        double haux = hT/(m_numLayers*1.3);//(sizefont * 0.7);
369
        if (haux>(wT/4.5)){
370
        	haux=wT/4.5;
375
        double haux = hT / (m_numLayers * 1.3); //(sizefont * 0.7);
376

  
377
        if (haux > (wT / 4.5)) {
378
            haux = wT / 4.5;
371 379
        }
380

  
372 381
        Rectangle2D rAux3 = new Rectangle2D.Double(x, ((y + (h / 2)) - haux),
373 382
                wl, haux);
374 383
        FFrameSymbol symbol = new FFrameSymbol();
......
432 441
     */
433 442
    public void toFFrames(Layout layout) {
434 443
        Rectangle2D rectangle = getBoundingBox(null);
435
        Rectangle2D r=getBoundBox();
444
        Rectangle2D r = getBoundBox();
436 445
        double h = rectangle.getHeight() / m_numLayers;
437 446
        FLayers lays = layers;
447

  
438 448
        //layout.getEFS().startComplexCommand();
439
        toFFrames(layout, lays, rectangle,r.getWidth(),r.getHeight(), h, 0);
449
        toFFrames(layout, lays, rectangle, r.getWidth(), r.getHeight(), h, 0);
440 450
        layout.delFFrame(this);
451

  
441 452
        ///layout.getFFrames().remove(this);
442 453
        //layout.getEFS().endComplexCommand();
443 454
    }
......
448 459
     * @param layout Referencia al Layout.
449 460
     * @param lays Layers a a?adir
450 461
     * @param rectangle Rect?ngulo del FFrameLegend.
462
     * @param wT DOCUMENT ME!
463
     * @param hT DOCUMENT ME!
451 464
     * @param h Altura
452 465
     * @param n n?mero de Capa a?adida.
453 466
     *
454 467
     * @return n?mero de Capa a a?adir.
455 468
     */
456
    public int toFFrames(Layout layout, FLayers lays, Rectangle2D rectangle,double wT,double hT,
457
        double h, int n) {
458
        int N=39;
469
    public int toFFrames(Layout layout, FLayers lays, Rectangle2D rectangle,
470
        double wT, double hT, double h, int n) {
471
        int N = 39;
459 472
        float sizefont = 0;
460 473

  
461
        if ((rectangle.getHeight() / m_numLayers) < (wT*N / (m_max * 0.7))) {
462
            sizefont = (float) (hT*N / m_numLayers);
474
        if ((rectangle.getHeight() / m_numLayers) < ((wT * N) / (m_max * 0.7))) {
475
            sizefont = (float) ((hT * N) / m_numLayers);
463 476
        } else {
464
            sizefont = (float) (wT*N /(m_max * 0.7));
477
            sizefont = (float) ((wT * N) / (m_max * 0.7));
465 478
        }
466
        
467
    	//////	Se recorren los layers dibujando el s?mbolo y su nombre sobre el graphics	
479

  
480
        //////	Se recorren los layers dibujando el s?mbolo y su nombre sobre el graphics	
468 481
        for (int i = 0; i < lays.getLayersCount(); i++) {
469 482
            FLayer layer = (FLayer) lays.getLayer(i);
470 483

  
471 484
            if (layer.isVisible()) {
472 485
                if (layer instanceof FLayers) {
473 486
                    rectangle.setRect(rectangle.getX(),
474
                        rectangle.getY() + (h * n), wT,
475
                        rectangle.getHeight());
476
                    n += toFFrames(layout, lays,rectangle, wT,hT, h, n); //drawTheme(g, re, h, layers, n);
487
                        rectangle.getY() + (h * n), wT, rectangle.getHeight());
488
                    n += toFFrames(layout, lays, rectangle, wT, hT, h, n); //drawTheme(g, re, h, layers, n);
477 489
                } else if (layer instanceof AlphanumericData) {
478 490
                    AlphanumericData cO = (AlphanumericData) layer;
479 491

  
......
484 496

  
485 497
                        double xl = (rectangle.getX() + dX);
486 498
                        double yl = (rectangle.getY() + dY);
487
                        toFFrameText(layout, layer.getName(), rectangle.getWidth(),rectangle.getHeight(),
499
                        toFFrameText(layout, layer.getName(),
500
                            rectangle.getWidth(), rectangle.getHeight(),
488 501
                            sizefont, xl, yl, h);
489 502
                        n++;
490 503

  
......
495 508
                            yl = (rectangle.getY() + dY);
496 509

  
497 510
                            String s = cli.getDescriptions()[j];
498
                              toFFrameText(layout, s,  rectangle.getWidth(),rectangle.getHeight(),sizefont, xl,
499
                                yl, h);
511
                            toFFrameText(layout, s, rectangle.getWidth(),
512
                                rectangle.getHeight(), sizefont, xl, yl, h);
500 513

  
501 514
                            FSymbol fs2d = cli.getSymbols()[j];
502 515

  
503 516
                            try {
504
                                toFFrameSymbol(layout, rectangle.getWidth(),rectangle.getHeight(),
505
                                    rectangle.getX(), yl, fs2d,
517
                                toFFrameSymbol(layout, rectangle.getWidth(),
518
                                    rectangle.getHeight(), rectangle.getX(),
519
                                    yl, fs2d,
506 520
                                    ((Classifiable) cO).getShapeType(), h);
507 521
                            } catch (DriverException e) {
508 522
                                e.printStackTrace();
......
516 530

  
517 531
                        double xl = (rectangle.getX() + dX);
518 532
                        double yl = (rectangle.getY() + dY);
519
                       
520
                        toFFrameText(layout, layer.getName(),  rectangle.getWidth(),rectangle.getHeight(),
521
                            sizefont, xl, yl , h);
522 533

  
534
                        toFFrameText(layout, layer.getName(),
535
                            rectangle.getWidth(), rectangle.getHeight(),
536
                            sizefont, xl, yl, h);
537

  
523 538
                        FSymbol fs2d = ((Classifiable) cO).getLegend()
524 539
                                        .getDefaultSymbol();
525 540

  
526 541
                        try {
527
                            toFFrameSymbol(layout, rectangle.getWidth(),rectangle.getHeight(), rectangle.getX(),
528
                                yl, fs2d,
529
                                ((Classifiable) cO).getShapeType(), h);
542
                            toFFrameSymbol(layout, rectangle.getWidth(),
543
                                rectangle.getHeight(), rectangle.getX(), yl,
544
                                fs2d, ((Classifiable) cO).getShapeType(), h);
530 545
                        } catch (DriverException e) {
531 546
                            e.printStackTrace();
532 547
                        }
......
536 551
                }
537 552
            }
538 553
        }
539
       
554

  
540 555
        return n;
541 556
    }
542 557

  
......
565 580
    /**
566 581
     * @see com.iver.cit.gvsig.gui.layout.fframes.IFFrame#getXMLEntity()
567 582
     */
568
    public XMLEntity getXMLEntity() throws SaveException{
569
        XMLEntity xml = new XMLEntity();
570
        try{
571
        xml.putProperty("className", this.getClass().getName());
572
        xml.putProperty("m_name", m_name);
573
        xml.putProperty("x", getBoundBox().x);
574
        xml.putProperty("y", getBoundBox().y);
575
        xml.putProperty("w", getBoundBox().width);
576
        xml.putProperty("h", getBoundBox().height);
577
        xml.putProperty("m_Selected", m_Selected);
578
        xml.putProperty("type", Layout.RECTANGLELEGEND);
579
        xml.putProperty("m_numLayers", m_numLayers);
580
        xml.putProperty("m_max", m_max);
581
        xml.putProperty("m_quality", m_quality);
582
        xml.putProperty("m_viewing", m_viewing);
583
        xml.putProperty("fontName", m_f.getFontName());
584
        xml.putProperty("fontStyle", m_f.getStyle());
585
        xml.putProperty("tag", getTag());
586
        xml.putProperty("m_rotation", getRotation());
587
        if (fframeview!=null){
588
        Layout layout = fframeview.getLayout();
589
        IFFrame[] fframes = layout.getAllFFrames();
583
    public XMLEntity getXMLEntity() throws SaveException {
584
        XMLEntity xml = super.getXMLEntity();
590 585

  
591
        for (int i = 0; i < fframes.length; i++) {
592
            if (fframeview.equals(fframes[i])) {
593
                xml.putProperty("index", i);
586
        try {
587
            xml.putProperty("type", Layout.RECTANGLELEGEND);
588
            xml.putProperty("m_numLayers", m_numLayers);
589
            xml.putProperty("m_max", m_max);
590
            xml.putProperty("m_quality", m_quality);
591
            xml.putProperty("m_viewing", m_viewing);
592
            xml.putProperty("fontName", m_f.getFontName());
593
            xml.putProperty("fontStyle", m_f.getStyle());
594

  
595
            if (fframeview != null) {
596
                Layout layout = fframeview.getLayout();
597
                IFFrame[] fframes = layout.getAllFFrames();
598

  
599
                for (int i = 0; i < fframes.length; i++) {
600
                    if (fframeview.equals(fframes[i])) {
601
                        xml.putProperty("index", i);
602
                    }
603
                }
594 604
            }
605
        } catch (Exception e) {
606
            throw new SaveException(e, this.getClass().getName());
595 607
        }
596
        }
597
        }catch (Exception e) {
598
			throw new SaveException(e,this.getClass().getName());
599
		}
608

  
600 609
        return xml;
601 610
    }
602 611

  
......
617 626
        this.m_viewing = xml.getIntProperty("m_viewing");
618 627
        this.m_f = new Font(xml.getStringProperty("fontName"),
619 628
                xml.getIntProperty("fontStyle"), 9);
620
        if(xml.contains("index"))
621
        fframeview = (FFrameView)l.getFFrame(xml.getIntProperty("index"));
622
        
629

  
630
        if (xml.contains("index")) {
631
            fframeview = (FFrameView) l.getFFrame(xml.getIntProperty("index"));
632
        }
623 633
    }
624 634

  
625 635
    /**
......
668 678
     * @param fframes Resto de FFrames.
669 679
     */
670 680
    public void initDependence(IFFrame[] fframes) {
671
    	if (dependenceIndex!=-1 && fframes[dependenceIndex] instanceof FFrameView)
672
        fframeview = (FFrameView) fframes[dependenceIndex];
681
        if ((dependenceIndex != -1) &&
682
                fframes[dependenceIndex] instanceof FFrameView) {
683
            fframeview = (FFrameView) fframes[dependenceIndex];
684
        }
673 685
    }
674
	
675 686
}

Also available in: Unified diff