svn-gvsig-desktop / tags / v10_RC2c / applications / appgvSIG / src / com / iver / cit / gvsig / gui / toc / TocItemLeaf.java @ 8745
History | View | Annotate | Download (4.94 KB)
1 | 418 | fjp | /*
|
---|---|---|---|
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 | 1103 | fjp | /* 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 | 418 | fjp | package com.iver.cit.gvsig.gui.toc; |
48 | |||
49 | 423 | fjp | import java.awt.Dimension; |
50 | 418 | fjp | import java.awt.Graphics2D; |
51 | import java.awt.Rectangle; |
||
52 | import java.awt.datatransfer.DataFlavor; |
||
53 | import java.awt.datatransfer.UnsupportedFlavorException; |
||
54 | 458 | fjp | import java.awt.geom.AffineTransform; |
55 | 418 | fjp | import java.awt.image.BufferedImage; |
56 | import java.io.IOException; |
||
57 | |||
58 | import javax.swing.Icon; |
||
59 | import javax.swing.ImageIcon; |
||
60 | |||
61 | import com.iver.cit.gvsig.fmap.core.FShape; |
||
62 | 458 | fjp | import com.iver.cit.gvsig.fmap.core.v02.FGraphicUtilities; |
63 | import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
||
64 | 418 | fjp | import com.iver.cit.gvsig.fmap.rendering.styling.FStyle2D; |
65 | import com.iver.cit.gvsig.fmap.rendering.styling.SymbolPreviewDrawer; |
||
66 | |||
67 | /**
|
||
68 | * @author FJP
|
||
69 | *
|
||
70 | * TODO To change the template for this generated type comment go to
|
||
71 | * Window - Preferences - Java - Code Generation - Code and Comments
|
||
72 | */
|
||
73 | public class TocItemLeaf implements ITocItem { |
||
74 | |||
75 | 458 | fjp | private FSymbol symbol;
|
76 | 418 | fjp | private String description; |
77 | private int layerType; |
||
78 | private static int w_1symbol = 20; |
||
79 | private static int h_1symbol = 15; |
||
80 | 423 | fjp | |
81 | private Dimension sz; |
||
82 | |||
83 | 418 | fjp | private static SymbolPreviewDrawer pSD = new SymbolPreviewDrawer(); |
84 | |||
85 | final public static DataFlavor INFO_FLAVOR = |
||
86 | new DataFlavor(TocItemLeaf.class, "ItemLeaf"); |
||
87 | |||
88 | static DataFlavor flavors[] = {INFO_FLAVOR }; |
||
89 | |||
90 | |||
91 | 458 | fjp | public TocItemLeaf(FSymbol symbol, String description, int layerType) |
92 | 418 | fjp | { |
93 | this.symbol = symbol;
|
||
94 | this.description = description;
|
||
95 | this.layerType = layerType;
|
||
96 | } |
||
97 | /* (non-Javadoc)
|
||
98 | * @see com.iver.cit.gvsig.gui.toc.ITocItem#getLabel()
|
||
99 | */
|
||
100 | public String getLabel() { |
||
101 | return description;
|
||
102 | } |
||
103 | |||
104 | /* (non-Javadoc)
|
||
105 | * @see com.iver.cit.gvsig.gui.toc.ITocItem#getIcon()
|
||
106 | */
|
||
107 | public Icon getIcon() { |
||
108 | 423 | fjp | // System.out.println("Dentro de getIcon: layerType=" + layerType);
|
109 | 810 | fjp | BufferedImage img = null; |
110 | 861 | fjp | |
111 | 418 | fjp | switch (layerType)
|
112 | { |
||
113 | case FShape.POINT:
|
||
114 | case FShape.LINE:
|
||
115 | case FShape.POLYGON:
|
||
116 | 2208 | vcaballero | case FShape.MULTIPOINT:
|
117 | 810 | fjp | img = new BufferedImage(w_1symbol, h_1symbol, BufferedImage.TYPE_INT_ARGB); |
118 | Graphics2D g2 = img.createGraphics();
|
||
119 | Rectangle r = new Rectangle(w_1symbol, h_1symbol); |
||
120 | FGraphicUtilities.DrawSymbol(g2, AffineTransform.getScaleInstance(0.8,0.8), r, symbol); |
||
121 | break;
|
||
122 | case FShape.MULTI:
|
||
123 | 843 | fjp | img = new BufferedImage(3*w_1symbol, h_1symbol, BufferedImage.TYPE_INT_ARGB); |
124 | 810 | fjp | g2 = img.createGraphics(); |
125 | 843 | fjp | r = new Rectangle(3*w_1symbol, h_1symbol); |
126 | 810 | fjp | |
127 | FGraphicUtilities.DrawSymbol(g2, AffineTransform.getScaleInstance(0.8,0.8), r, symbol); |
||
128 | break;
|
||
129 | |||
130 | 418 | fjp | } |
131 | 2208 | vcaballero | if (img==null)return null;//TODO tipo de shape no soportado. |
132 | 418 | fjp | return new ImageIcon(img); |
133 | } |
||
134 | |||
135 | /* (non-Javadoc)
|
||
136 | * @see java.awt.datatransfer.Transferable#getTransferDataFlavors()
|
||
137 | */
|
||
138 | public DataFlavor[] getTransferDataFlavors() { |
||
139 | return flavors;
|
||
140 | } |
||
141 | |||
142 | /* (non-Javadoc)
|
||
143 | * @see java.awt.datatransfer.Transferable#isDataFlavorSupported(java.awt.datatransfer.DataFlavor)
|
||
144 | */
|
||
145 | public boolean isDataFlavorSupported(DataFlavor dF) { |
||
146 | return dF.equals(INFO_FLAVOR);
|
||
147 | } |
||
148 | |||
149 | /* (non-Javadoc)
|
||
150 | * @see java.awt.datatransfer.Transferable#getTransferData(java.awt.datatransfer.DataFlavor)
|
||
151 | */
|
||
152 | public Object getTransferData(DataFlavor dF) throws UnsupportedFlavorException, IOException { |
||
153 | if (dF.equals(INFO_FLAVOR)) {
|
||
154 | return this; |
||
155 | } |
||
156 | else throw new UnsupportedFlavorException(dF); |
||
157 | } |
||
158 | 423 | fjp | /* (non-Javadoc)
|
159 | * @see com.iver.cit.gvsig.gui.toc.ITocItem#getSize()
|
||
160 | */
|
||
161 | public Dimension getSize() { |
||
162 | return sz;
|
||
163 | } |
||
164 | /* (non-Javadoc)
|
||
165 | * @see com.iver.cit.gvsig.gui.toc.ITocItem#setSize(java.awt.Dimension)
|
||
166 | */
|
||
167 | public void setSize(Dimension sz) { |
||
168 | this.sz = sz;
|
||
169 | |||
170 | } |
||
171 | 418 | fjp | |
172 | |||
173 | 1090 | fjp | /**
|
174 | * @return Returns the symbol.
|
||
175 | */
|
||
176 | public FSymbol getSymbol() {
|
||
177 | return symbol;
|
||
178 | } |
||
179 | 418 | fjp | } |