Revision 7836

View differences:

trunk/extensions/extWMS/src/com/iver/cit/gvsig/fmap/drivers/wms/FMapWMSDriver.java
110 110
            throw new WMSException("WMS Unexpected server error."+e.getMessage());
111 111
        }
112 112
    }
113
    
114
    /**
115
     * Gets the legend graphic of one layer
116
     */
117
    public File getLegendGraphic(String layerName, ICancellable cancel) throws WMSException {
118
        try {
119
			return client.getLegendGraphic(layerName, cancel);
120
        } catch (org.gvsig.remoteClient.exceptions.WMSException e) {
121
            throw new WMSException(e.getMessage());
122
        } catch (ServerErrorException e) {
123
            throw new WMSException("WMS Unexpected server error."+e.getMessage());
124
        }   	
125
    }
113 126

  
114 127
	/**
115 128
	 * Devuelve WMSClient a partir de su URL.
trunk/extensions/extWMS/src/com/iver/cit/gvsig/fmap/layers/FLyrWMS.java
43 43
import java.awt.Component;
44 44
import java.awt.Dimension;
45 45
import java.awt.Graphics2D;
46
import java.awt.Image;
46 47
import java.awt.Point;
47 48
import java.awt.Rectangle;
48 49
import java.awt.geom.AffineTransform;
......
64 65
import java.util.Map;
65 66
import java.util.Vector;
66 67

  
68
import javax.imageio.ImageIO;
67 69
import javax.swing.ImageIcon;
68 70
import javax.swing.JOptionPane;
69 71

  
......
93 95
import com.iver.cit.gvsig.fmap.drivers.wms.FMapWMSDriverFactory;
94 96
import com.iver.cit.gvsig.fmap.drivers.wms.WMSException;
95 97
import com.iver.cit.gvsig.fmap.layers.WMSLayerNode.FMapWMSStyle;
98
import com.iver.cit.gvsig.fmap.layers.layerOperations.IHasImageLegend;
96 99
import com.iver.cit.gvsig.fmap.layers.layerOperations.InfoByPoint;
97 100
import com.iver.cit.gvsig.fmap.layers.layerOperations.StringXMLItem;
98 101
import com.iver.cit.gvsig.fmap.layers.layerOperations.XMLItem;
......
111 114
* 		  Nacho Brodin
112 115
*
113 116
*/
114
public class FLyrWMS extends FLyrDefault implements InfoByPoint, RasterOperations {
117
public class FLyrWMS extends FLyrDefault implements InfoByPoint, RasterOperations, IHasImageLegend {
115 118
	private boolean 					isPrinting = false;
116 119
	private boolean 					mustTileDraw = true;
117 120
	private boolean 					mustTilePrint = true;
......
1717 1720
		return mustTileDraw;
1718 1721
	}
1719 1722

  
1723
	public Image getImageLegend() {
1724
		try {
1725
			File legend = getDriver().getLegendGraphic(layerQuery, null);
1726
			Image img = null;
1727
			img = ImageIO.read(legend);
1728
			return img;
1729
		}catch(Exception e){
1730
			e.printStackTrace();
1731
			return null;
1732
		}
1733
	}
1720 1734

  
1735

  
1721 1736
}
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/toc/gui/TOC.java
48 48

  
49 49
import java.awt.BorderLayout;
50 50
import java.awt.Dimension;
51
import java.awt.Image;
51 52
import java.awt.Point;
52 53
import java.awt.Rectangle;
53 54
import java.awt.event.ActionEvent;
......
356 357
                {
357 358
                    TocItemLeaf itemLeaf;
358 359
                    IHasImageLegend aux = (IHasImageLegend) lyr;
359
                    if (aux.getImageLegend() != null)
360
                    Image image = aux.getImageLegend();
361
                    
362
                    if (image != null)
360 363
                    {
361
                    	itemLeaf = new TocItemLeaf();
362
                    	// TODO: Por defecto, este es el tama?o que 
363
                    	// usaremos en el toc.
364
                       	itemLeaf.setImageLegend(aux.getImageLegend(), "Hola", new Dimension(140, 200));
364
                    	itemLeaf = new TocItemLeaf();                    	
365
                       	itemLeaf.setImageLegend(image, "", 
366
                       							new Dimension(image.getWidth( null ),
367
                       							image.getHeight( null )));//new Dimension(150,200));
365 368

  
366 369
                        DefaultMutableTreeNode nodeValue = new DefaultMutableTreeNode(itemLeaf);
367 370
                        m_TreeModel.insertNodeInto(nodeValue, nodeLayer,
368
                            nodeLayer.getChildCount());
369
                    	
371
                            nodeLayer.getChildCount());                    	
370 372
                    }                	
371 373
                }
372 374
            } // if instanceof layers
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/toc/gui/TOCRenderer.java
49 49
import java.awt.Color;
50 50
import java.awt.Component;
51 51
import java.awt.Dimension;
52
import java.awt.FlowLayout;
52 53
import java.awt.Font;
53 54
import java.awt.GridBagConstraints;
54 55
import java.awt.GridBagLayout;
......
100 101
    public TOCRenderer() {
101 102
        this.setBackground(Color.lightGray);
102 103
        // this.setLayout(new BorderLayout());
103
        
104
        this.setLayout(new FlowLayout(FlowLayout.LEADING, 0,0));
104 105
		check = new JCheckBox();
105 106
		label = new JLabel();
106 107
		
trunk/applications/appgvSIG/src/com/iver/cit/gvsig/project/documents/view/toc/TocItemLeaf.java
107 107
		double ratioImage =  (double) imageLegend.getWidth(null) / (double) imageLegend.getHeight(null);
108 108
	    double ratioToc  = (double) sz.width / (double) sz.height;
109 109

  
110
		if (ratioImage > ratioToc) {
111
			int newHeight = (int) (sz.width / ratioImage);
112
			boolean resul = g2.drawImage(imageLegend, 0, 0, sz.width, newHeight, null);
113
		} else {
114
			int newWidth = (int) (sz.height * ratioImage);
115
			boolean resul = g2.drawImage(imageLegend, 0, 0, newWidth, sz.height, null);
116
		}
110
	    boolean resul = g2.drawImage(imageLegend, 0, 0, sz.width, sz.height, null);
111
//		if (ratioImage > ratioToc) {
112
//			int newHeight = (int) (sz.width / ratioImage);
113
//			boolean resul = g2.drawImage(imageLegend, 0, 0, sz.width, newHeight, null);
114
//		} else {
115
//			int newWidth = (int) (sz.height * ratioImage);
116
//			boolean resul = g2.drawImage(imageLegend, 0, 0, newWidth, sz.height, null);
117
//		}
117 118
		
118
		
119
		
120 119
	}
121 120
	/* (non-Javadoc)
122 121
	 * @see com.iver.cit.gvsig.gui.toc.ITocItem#getLabel()
......
132 131
		// System.out.println("Dentro de getIcon: layerType=" + layerType);
133 132
		if (imgLegend != null)
134 133
		{
135
			Graphics2D g2 = imgLegend.createGraphics();
136
			g2.drawString("Prueba", 10, 20);
134
//			Graphics2D g2 = imgLegend.createGraphics();
135
//			g2.drawString("Prueba", 10, 20);
137 136
			return new ImageIcon(imgLegend);
138 137
		}
139 138
		

Also available in: Unified diff