Revision 17187

View differences:

trunk/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/layout/fframes/FFrameLegend.java
55 55
import com.hardcode.gdbms.driver.exceptions.ReadDriverException;
56 56
import com.iver.andami.PluginServices;
57 57
import com.iver.cit.gvsig.fmap.core.FShape;
58
import com.iver.cit.gvsig.fmap.core.SymbologyFactory;
58 59
import com.iver.cit.gvsig.fmap.core.symbols.ISymbol;
59 60
import com.iver.cit.gvsig.fmap.core.symbols.ITextSymbol;
61
import com.iver.cit.gvsig.fmap.core.symbols.SymbolDrawingException;
60 62
import com.iver.cit.gvsig.fmap.layers.FLayer;
61 63
import com.iver.cit.gvsig.fmap.layers.FLayers;
62 64
import com.iver.cit.gvsig.fmap.layers.FLyrAnnotation;
......
379 381
    private Font getFont(float sizefont) {
380 382
		Font f=getFont();
381 383
		return new Font(f.getName(),f.getStyle(),(int)sizefont);
382
  }
384
    }
383 385

  
384 386
	/**
385 387
     * A?ade al Layout un nuevo FFrameText a partir de los par?metros de
......
394 396
	 * @param wT Rect?ngulo del FFrame.
395 397
	 * @param hT DOCUMENT ME!
396 398
     */
397
  /*  private void toFFrameText(Layout layout, String name, double wT, double hT,
398
        float sizefont, double x, double y, double h) {
399
        double wl = (wT / 1.5);
400
        double haux = hT / (m_numLayers * 1.3); //(sizefont * 0.7);
401

  
402
        if (haux > (wl / 3)) {
403
            haux = wl / 3;
404
        }
405

  
406
        Rectangle2D rAux = new Rectangle2D.Double(x, ((y + (h / 2)) - haux),
407
                wl, haux);
408
        FFrameText text = new FFrameText();
409
        text.setFixedFontSize(true);
410
        text.setFontSize((int) sizefont);
411
        text.setBoundBox(FLayoutUtilities.toSheetRect(rAux, layout.getAT()));
412
        text.addText(name);
413
        layout.addFFrame(text, false, true);
414
    }*/
415 399
    private void toFFrameText(LayoutContext layout, String name, Rectangle2D re,
416 400
            float sizefont, double x, double y, double h) {
417 401
            //Font f = getFont(sizefont);
......
436 420
     * @param re Rect?ngulo a cubrir por el s?mbolo.
437 421
     * @param x Posici?n X.
438 422
     * @param y Posici?n Y.
439
     * @param fs2d S?mbolo a dibujar.
423
     * @param symbol2d S?mbolo a dibujar.
440 424
     * @param sizefont Tama?o de la fuente.
441 425
     * @param h Altura.
442 426
     */
443 427
    private void drawSymbolLegend(Graphics2D g, Rectangle2D re, double x,
444
        double y, ISymbol fs2d, float sizefont, double h) {
445
        double pW = 5;
446
        double wl = (re.getWidth() / pW);
447
        double haux = (sizefont * 0.7);
448
        Font font=null;
449
        // jaume
450
//      if (fs2d instanceof FSymbol && (font=((FSymbol)fs2d).getFont()) != null) {
451
//          ((FSymbol)fs2d).setFont(new Font(font.getFontName(), font.getStyle(),
452
//                  (int) (wl / 6)));
453
//      }
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;
454 433

  
455
      if (fs2d instanceof ITextSymbol && (font=((ITextSymbol)fs2d).getFont()) != null) {
456
        ((ITextSymbol)fs2d).setFont(new Font(font.getFontName(), font.getStyle(),
457
                (int) (wl / 6)));
458
      }
459
        fs2d.drawInsideRectangle(g, new AffineTransform(),
460
            new Rectangle((int) x, (int) ((y + (h / 2)) - haux), (int) wl,
461
                (int) haux));
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
		}
462 459
    }
463 460

  
464 461
    /**
......
472 469
     * @param wT Rect?ngulo del FFrame.
473 470
     * @param hT tama?o de la fuente.
474 471
     */
475
   /* private void toFFrameSymbol(Layout layout, double wT, double hT, double x,
476
        double y, FSymbol fs2d, int type, double h) {
477
        double pW = 5;
478
        double wl = (wT / pW);
479
        double haux = hT / (m_numLayers * 1.3); //(sizefont * 0.7);
480

  
481
        if (haux > (wT / 4.5)) {
482
            haux = wT / 4.5;
483
        }
484

  
485
        Rectangle2D rAux3 = new Rectangle2D.Double(x, ((y + (h / 2)) - haux),
486
                wl, haux);
487
        FFrameSymbol symbol = new FFrameSymbol();
488
        symbol.setBoundBox(FLayoutUtilities.toSheetRect(rAux3, layout.getAT()));
489
        symbol.setSymbol(fs2d, type);
490
        layout.addFFrame(symbol, false, true);
491
    }*/
492 472
    private void toFFrameSymbol(LayoutContext layout, Rectangle2D re, double x,
493 473
            double y, ISymbol fs2d, float sizefont, double h) {
494 474
            double pW = 5;
495 475
            double wl = (re.getWidth() / pW);
496 476
            double haux = (sizefont * 0.7);
497 477
            Font font=null;
498
            // jaume
499
//            if (fs2d instanceof FSymbol && (font=((FSymbol)fs2d).getFont()) != null) {
500
//                ((FSymbol)fs2d).setFont(new Font(font.getFontName(), font.getStyle(),
501
//                        (int) (wl / 6)));
502
//            }
503

  
504 478
            if (fs2d instanceof ITextSymbol && (font=((ITextSymbol)fs2d).getFont()) != null) {
505 479
              ((ITextSymbol)fs2d).setFont(new Font(font.getFontName(), font.getStyle(),
506 480
                      (int) (wl / 6)));
......
610 584
        //layout.getEFS().endComplexCommand();
611 585
    }
612 586

  
587
 
613 588
    /**
614
     * Transforma el FFrameLegend en diferentes FFrameSymbol y FFrameText.
615
     *
616
     * @param layout Referencia al Layout.
617
     * @param lays Layers a a?adir
618
     * @param rectangle Rect?ngulo del FFrameLegend.
619
     * @param wT DOCUMENT ME!
620
     * @param hT DOCUMENT ME!
621
     * @param h Altura
622
     * @param n n?mero de Capa a?adida.
623
     *
624
     * @return n?mero de Capa a a?adir.
625
     */
626
 /*   public int toFFrames(Layout layout, FLayers lays, Rectangle2D rectangle,
627
        double wT, double hT, double h, int n) {
628
        int N = 39;
629
        float sizefont = 0;
630

  
631
        if ((rectangle.getHeight() / m_numLayers) < ((wT * N) / (m_max * 0.7))) {
632
            sizefont = (float) ((hT * N) / m_numLayers);
633
        } else {
634
            sizefont = (float) ((wT * N) / (m_max * 0.7));
635
        }
636

  
637
        //////	Se recorren los layers dibujando el s?mbolo y su nombre sobre el graphics
638
        for (int i = 0; i < lays.getLayersCount(); i++) {
639
            FLayer layer = (FLayer) lays.getLayer(i);
640

  
641
            if (layer.isVisible()) {
642
                if (layer instanceof FLayers) {
643
                    rectangle.setRect(rectangle.getX(),
644
                        rectangle.getY() + (h * n), wT, rectangle.getHeight());
645
                    n += toFFrames(layout, lays, rectangle, wT, hT, h, n); //drawTheme(g, re, h, layers, n);
646
                } else if (layer instanceof AlphanumericData) {
647
                    AlphanumericData cO = (AlphanumericData) layer;
648

  
649
                    if (((Classifiable) cO).getLegend() instanceof ClassifiedLegendInfo) {
650
                        ClassifiedLegendInfo cli = (ClassifiedLegendInfo) ((Classifiable) cO).getLegend();
651
                        double dX = rectangle.getWidth() / 4;
652
                        double dY = n * h;
653

  
654
                        double xl = (rectangle.getX() + dX);
655
                        double yl = (rectangle.getY() + dY);
656
                        toFFrameText(layout, layer.getName(),
657
                            rectangle.getWidth(), rectangle.getHeight(),
658
                            sizefont, xl, yl, h);
659
                        n++;
660

  
661
                        for (int j = 0; j < cli.getValues().length; j++) {
662
                            dY = n * h;
663

  
664
                            xl = (rectangle.getX() + dX);
665
                            yl = (rectangle.getY() + dY);
666

  
667
                            String s = cli.getDescriptions()[j];
668
                            toFFrameText(layout, s, rectangle.getWidth(),
669
                                rectangle.getHeight(), sizefont, xl, yl, h);
670

  
671
                            FSymbol fs2d = cli.getSymbols()[j];
672

  
673
                            try {
674
//                                toFFrameSymbol(layout, rectangle.getWidth(),
675
//                                    rectangle.getHeight(), rectangle.getX(),
676
//                                    yl, fs2d,
677
//                                    ((Classifiable) cO).getShapeType(), h);
678
                            	toFFrameSymbol(layout, rectangle,
679
                                        rectangle.getHeight(), rectangle.getX(),
680
                                        yl, fs2d,
681
                                        ((Classifiable) cO).getShapeType(), h);
682
                            } catch (DriverException e) {
683
                                e.printStackTrace();
684
                            }
685

  
686
                            n++;
687
                        }
688
                    } else {
689
                        double dX = rectangle.getWidth() / 4;
690
                        double dY = n * h;
691

  
692
                        double xl = (rectangle.getX() + dX);
693
                        double yl = (rectangle.getY() + dY);
694

  
695
                        toFFrameText(layout, layer.getName(),
696
                            rectangle.getWidth(), rectangle.getHeight(),
697
                            sizefont, xl, yl, h);
698

  
699
                        FSymbol fs2d = ((Classifiable) cO).getLegend()
700
                                        .getDefaultSymbol();
701

  
702
                        try {
703
                            toFFrameSymbol(layout, rectangle.getWidth(),
704
                                rectangle.getHeight(), rectangle.getX(), yl,
705
                                fs2d, ((Classifiable) cO).getShapeType(), h);
706
                        } catch (DriverException e) {
707
                            e.printStackTrace();
708
                        }
709

  
710
                        n++;
711
                    }
712
                }
713
            }
714
        }
715

  
716
        return n;
717
    }
718
*/
719
    /**
720 589
     * Rellena la fuente a utilizar al dibujar los String sobre el graphics.
721 590
     *
722 591
     * @param f Font.
......
836 705
        }
837 706
    }
838 707

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

  
846
    /**
715
    /*
847 716
     * @see com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame#print(java.awt.Graphics2D,
848 717
     *      java.awt.geom.AffineTransform)
849 718
     */

Also available in: Unified diff