root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / toc / TocItemLeaf.java @ 7738
History | View | Annotate | Download (6.12 KB)
1 |
/*
|
---|---|
2 |
* Created on 03-dic-2004
|
3 |
*
|
4 |
* TODO To change the template for this generated file go to
|
5 |
* Window - Preferences - Java - Code Generation - Code and Comments
|
6 |
*/
|
7 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
8 |
*
|
9 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
10 |
*
|
11 |
* This program is free software; you can redistribute it and/or
|
12 |
* modify it under the terms of the GNU General Public License
|
13 |
* as published by the Free Software Foundation; either version 2
|
14 |
* of the License, or (at your option) any later version.
|
15 |
*
|
16 |
* This program is distributed in the hope that it will be useful,
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19 |
* GNU General Public License for more details.
|
20 |
*
|
21 |
* You should have received a copy of the GNU General Public License
|
22 |
* along with this program; if not, write to the Free Software
|
23 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
24 |
*
|
25 |
* For more information, contact:
|
26 |
*
|
27 |
* Generalitat Valenciana
|
28 |
* Conselleria d'Infraestructures i Transport
|
29 |
* Av. Blasco Ib??ez, 50
|
30 |
* 46010 VALENCIA
|
31 |
* SPAIN
|
32 |
*
|
33 |
* +34 963862235
|
34 |
* gvsig@gva.es
|
35 |
* www.gvsig.gva.es
|
36 |
*
|
37 |
* or
|
38 |
*
|
39 |
* IVER T.I. S.A
|
40 |
* Salamanca 50
|
41 |
* 46005 Valencia
|
42 |
* Spain
|
43 |
*
|
44 |
* +34 963163400
|
45 |
* dac@iver.es
|
46 |
*/
|
47 |
package com.iver.cit.gvsig.project.documents.view.toc; |
48 |
|
49 |
import java.awt.Dimension; |
50 |
import java.awt.Graphics2D; |
51 |
import java.awt.Image; |
52 |
import java.awt.Rectangle; |
53 |
import java.awt.datatransfer.DataFlavor; |
54 |
import java.awt.datatransfer.UnsupportedFlavorException; |
55 |
import java.awt.geom.AffineTransform; |
56 |
import java.awt.image.BufferedImage; |
57 |
import java.io.IOException; |
58 |
|
59 |
import javax.swing.Icon; |
60 |
import javax.swing.ImageIcon; |
61 |
|
62 |
import com.iver.cit.gvsig.fmap.core.FShape; |
63 |
import com.iver.cit.gvsig.fmap.core.ISymbol; |
64 |
|
65 |
/**
|
66 |
* @author FJP
|
67 |
*
|
68 |
* TODO To change the template for this generated type comment go to
|
69 |
* Window - Preferences - Java - Code Generation - Code and Comments
|
70 |
*/
|
71 |
public class TocItemLeaf implements ITocItem { |
72 |
|
73 |
private ISymbol symbol;
|
74 |
private String description; |
75 |
private int layerType; |
76 |
private static int w_1symbol = 20; |
77 |
private static int h_1symbol = 15; |
78 |
|
79 |
private Dimension sz; |
80 |
BufferedImage imgLegend = null; |
81 |
|
82 |
final public static DataFlavor INFO_FLAVOR = |
83 |
new DataFlavor(TocItemLeaf.class, "ItemLeaf"); |
84 |
|
85 |
static DataFlavor flavors[] = {INFO_FLAVOR }; |
86 |
|
87 |
|
88 |
public TocItemLeaf(ISymbol symbol, String description, int layerType) |
89 |
{ |
90 |
this.symbol = symbol;
|
91 |
this.description = description;
|
92 |
this.layerType = layerType;
|
93 |
} |
94 |
public TocItemLeaf()
|
95 |
{ |
96 |
|
97 |
} |
98 |
public void setImageLegend(Image imageLegend, String descrip, Dimension size) |
99 |
{ |
100 |
this.description = descrip;
|
101 |
this.sz = size;
|
102 |
imgLegend = new BufferedImage(sz.width, sz.height, BufferedImage.TYPE_INT_ARGB); |
103 |
Graphics2D g2 = imgLegend.createGraphics();
|
104 |
// Rectangle r = new Rectangle(sz.width, sz.height);
|
105 |
// TODO: Calcular ratio
|
106 |
|
107 |
double ratioImage = (double) imageLegend.getWidth(null) / (double) imageLegend.getHeight(null); |
108 |
double ratioToc = (double) sz.width / (double) sz.height; |
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 |
} |
117 |
|
118 |
|
119 |
|
120 |
} |
121 |
/* (non-Javadoc)
|
122 |
* @see com.iver.cit.gvsig.gui.toc.ITocItem#getLabel()
|
123 |
*/
|
124 |
public String getLabel() { |
125 |
return description;
|
126 |
} |
127 |
|
128 |
/* (non-Javadoc)
|
129 |
* @see com.iver.cit.gvsig.gui.toc.ITocItem#getIcon()
|
130 |
*/
|
131 |
public Icon getIcon() { |
132 |
// System.out.println("Dentro de getIcon: layerType=" + layerType);
|
133 |
if (imgLegend != null) |
134 |
{ |
135 |
Graphics2D g2 = imgLegend.createGraphics();
|
136 |
g2.drawString("Prueba", 10, 20); |
137 |
return new ImageIcon(imgLegend); |
138 |
} |
139 |
|
140 |
BufferedImage img = null; |
141 |
|
142 |
switch (layerType)
|
143 |
{ |
144 |
case FShape.POINT:
|
145 |
case FShape.LINE:
|
146 |
case FShape.POLYGON:
|
147 |
case FShape.MULTIPOINT:
|
148 |
img = new BufferedImage(w_1symbol, h_1symbol, BufferedImage.TYPE_INT_ARGB); |
149 |
Graphics2D g2 = img.createGraphics();
|
150 |
Rectangle r = new Rectangle(w_1symbol, h_1symbol); |
151 |
symbol.drawInsideRectangle(g2, AffineTransform.getScaleInstance(0.8,0.8), r); |
152 |
// // TODO: CAMBIAR PARA QUE NO DEPENDA DE FSYMBOL
|
153 |
// if (symbol instanceof FSymbol)
|
154 |
// FGraphicUtilities.DrawSymbol(g2, AffineTransform.getScaleInstance(0.8,0.8), r, (FSymbol) symbol);
|
155 |
// // Por ahora, los que no sean FSymbol no se renderizan en el TOC.
|
156 |
break;
|
157 |
case FShape.MULTI:
|
158 |
img = new BufferedImage(3*w_1symbol, h_1symbol, BufferedImage.TYPE_INT_ARGB); |
159 |
g2 = img.createGraphics(); |
160 |
r = new Rectangle(3*w_1symbol, h_1symbol); |
161 |
symbol.drawInsideRectangle(g2, AffineTransform.getScaleInstance(0.8,0.8), r); |
162 |
// if (symbol instanceof FSymbol)
|
163 |
// FGraphicUtilities.DrawSymbol(g2, AffineTransform.getScaleInstance(0.8,0.8), r, (FSymbol) symbol);
|
164 |
break;
|
165 |
|
166 |
} |
167 |
if (img==null)return null;//TODO tipo de shape no soportado. |
168 |
return new ImageIcon(img); |
169 |
} |
170 |
|
171 |
/* (non-Javadoc)
|
172 |
* @see java.awt.datatransfer.Transferable#getTransferDataFlavors()
|
173 |
*/
|
174 |
public DataFlavor[] getTransferDataFlavors() { |
175 |
return flavors;
|
176 |
} |
177 |
|
178 |
/* (non-Javadoc)
|
179 |
* @see java.awt.datatransfer.Transferable#isDataFlavorSupported(java.awt.datatransfer.DataFlavor)
|
180 |
*/
|
181 |
public boolean isDataFlavorSupported(DataFlavor dF) { |
182 |
return dF.equals(INFO_FLAVOR);
|
183 |
} |
184 |
|
185 |
/* (non-Javadoc)
|
186 |
* @see java.awt.datatransfer.Transferable#getTransferData(java.awt.datatransfer.DataFlavor)
|
187 |
*/
|
188 |
public Object getTransferData(DataFlavor dF) throws UnsupportedFlavorException, IOException { |
189 |
if (dF.equals(INFO_FLAVOR)) {
|
190 |
return this; |
191 |
} |
192 |
else throw new UnsupportedFlavorException(dF); |
193 |
} |
194 |
/* (non-Javadoc)
|
195 |
* @see com.iver.cit.gvsig.gui.toc.ITocItem#getSize()
|
196 |
*/
|
197 |
public Dimension getSize() { |
198 |
return sz;
|
199 |
} |
200 |
/* (non-Javadoc)
|
201 |
* @see com.iver.cit.gvsig.gui.toc.ITocItem#setSize(java.awt.Dimension)
|
202 |
*/
|
203 |
public void setSize(Dimension sz) { |
204 |
this.sz = sz;
|
205 |
|
206 |
} |
207 |
|
208 |
|
209 |
/**
|
210 |
* @return Returns the symbol.
|
211 |
*/
|
212 |
public ISymbol getSymbol() {
|
213 |
return symbol;
|
214 |
} |
215 |
} |