svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / project / documents / view / toc / TocItemBranch.java @ 42811
History | View | Annotate | Download (6.74 KB)
1 | 40558 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | *
|
||
4 | * Copyright (C) 2007-2013 gvSIG Association.
|
||
5 | *
|
||
6 | * This program is free software; you can redistribute it and/or
|
||
7 | * modify it under the terms of the GNU General Public License
|
||
8 | * as published by the Free Software Foundation; either version 3
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | *
|
||
11 | * This program is distributed in the hope that it will be useful,
|
||
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
14 | * GNU General Public License for more details.
|
||
15 | *
|
||
16 | * You should have received a copy of the GNU General Public License
|
||
17 | * along with this program; if not, write to the Free Software
|
||
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
||
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | * For any additional information, do not hesitate to contact us
|
||
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | */
|
||
24 | 40596 | jjdelcerro | |
25 | 40435 | jjdelcerro | package org.gvsig.app.project.documents.view.toc; |
26 | |||
27 | import java.awt.Dimension; |
||
28 | import java.awt.Graphics2D; |
||
29 | import java.awt.Image; |
||
30 | import java.awt.datatransfer.DataFlavor; |
||
31 | import java.awt.datatransfer.UnsupportedFlavorException; |
||
32 | import java.awt.image.BufferedImage; |
||
33 | import java.io.File; |
||
34 | import java.io.IOException; |
||
35 | import java.net.URL; |
||
36 | |||
37 | import javax.swing.Icon; |
||
38 | import javax.swing.ImageIcon; |
||
39 | |||
40 | import org.gvsig.andami.IconThemeHelper; |
||
41 | import org.gvsig.andami.PluginServices; |
||
42 | import org.gvsig.app.project.documents.view.IContextMenuAction; |
||
43 | import org.gvsig.app.project.documents.view.toc.actions.FLyrVectEditPropertiesTocMenuEntry; |
||
44 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
45 | import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
||
46 | |||
47 | |||
48 | /**
|
||
49 | * @author FJP
|
||
50 | *
|
||
51 | * TODO To change the template for this generated type comment go to
|
||
52 | * Window - Preferences - Java - Code Generation - Code and Comments
|
||
53 | */
|
||
54 | public class TocItemBranch implements ITocItem { |
||
55 | |||
56 | private ImageIcon icolayer = null; |
||
57 | |||
58 | private ImageIcon finalIcon = null; |
||
59 | |||
60 | private BufferedImage unavailableImg = null; |
||
61 | 41853 | jjdelcerro | |
62 | private BufferedImage temporaryLayerImg = null; |
||
63 | |||
64 | 40435 | jjdelcerro | private final String defaultIcon = "images/icolayer.PNG"; |
65 | |||
66 | private FLayer lyr;
|
||
67 | |||
68 | private Dimension sz; |
||
69 | |||
70 | final public static DataFlavor INFO_FLAVOR = |
||
71 | new DataFlavor(TocItemBranch.class, "ItemBranch"); |
||
72 | static DataFlavor flavors[] = {INFO_FLAVOR }; |
||
73 | |||
74 | public TocItemBranch(FLayer lyr)
|
||
75 | { |
||
76 | this.lyr = lyr;
|
||
77 | } |
||
78 | /* (non-Javadoc)
|
||
79 | * @see com.iver.cit.gvsig.gui.toc.ITocItem#getLabel()
|
||
80 | */
|
||
81 | public String getLabel() { |
||
82 | /*if (lyr instanceof FLyrVect && ((FLyrVect)lyr).isBroken())
|
||
83 | {
|
||
84 | return lyr.getName() + "(broken)";
|
||
85 | }
|
||
86 | else*/
|
||
87 | return lyr.getName();
|
||
88 | } |
||
89 | |||
90 | /* (non-Javadoc)
|
||
91 | * @see com.iver.cit.gvsig.gui.toc.ITocItem#getIcon()
|
||
92 | */
|
||
93 | public Icon getIcon() { |
||
94 | // TODO Pedirle el icono a la capa. Por defecto habr? un icono
|
||
95 | // para vectoriales y otro para raster, pero se podr?n cambiar.
|
||
96 | |||
97 | if (finalIcon == null) { |
||
98 | ImageIcon icon = (ImageIcon) PluginServices.getIconTheme().get(lyr.getTocImageIcon()); |
||
99 | this.setIcon(icon);
|
||
100 | } |
||
101 | updateStateIcon(); |
||
102 | |||
103 | return finalIcon;
|
||
104 | } |
||
105 | |||
106 | private void setIcon(String path) { |
||
107 | File f = new File(path); |
||
108 | if (f.exists()) {
|
||
109 | icolayer = new ImageIcon(f.getAbsolutePath()); |
||
110 | } else {
|
||
111 | URL url =PluginServices.getPluginServices("org.gvsig.app").getClassLoader().getResource(path); |
||
112 | if (url!=null) { |
||
113 | icolayer = new ImageIcon(url); |
||
114 | return;
|
||
115 | } |
||
116 | } |
||
117 | updateStateIcon(); |
||
118 | |||
119 | } |
||
120 | private void updateStateIcon() { |
||
121 | 41853 | jjdelcerro | if (icolayer == null) { |
122 | return;
|
||
123 | } |
||
124 | BufferedImage newImage = new BufferedImage(icolayer.getIconWidth(),icolayer.getIconHeight(),BufferedImage.TYPE_INT_ARGB); |
||
125 | Graphics2D grp = newImage.createGraphics();
|
||
126 | grp.drawImage(icolayer.getImage(),0,0,null); |
||
127 | if (lyr.getTocStatusImage() != null) { |
||
128 | 40435 | jjdelcerro | Image img = lyr.getTocStatusImage();
|
129 | 41853 | jjdelcerro | grp.drawImage(img,0,icolayer.getIconHeight()-img.getHeight(null),null); |
130 | 40435 | jjdelcerro | } |
131 | 41853 | jjdelcerro | |
132 | 42811 | jjdelcerro | if (!this.lyr.isAvailable()) { |
133 | BufferedImage img = this.getUnavailableImage(); |
||
134 | grp.drawImage(img,0,icolayer.getIconHeight()-img.getHeight(),null); |
||
135 | } |
||
136 | 41853 | jjdelcerro | |
137 | if( this.lyr.isTemporary() ) { |
||
138 | BufferedImage img = this.getTemporaryLayerImage(); |
||
139 | grp.drawImage(img,icolayer.getIconWidth()-img.getWidth(),icolayer.getIconHeight()-img.getHeight(),null);
|
||
140 | } |
||
141 | |||
142 | this.finalIcon = new ImageIcon(newImage); |
||
143 | } |
||
144 | 40435 | jjdelcerro | |
145 | private void setIcon(ImageIcon icon) { |
||
146 | if (icon!=null) { |
||
147 | icolayer = icon; |
||
148 | } else {
|
||
149 | this.setIcon(defaultIcon);
|
||
150 | |||
151 | } |
||
152 | updateStateIcon(); |
||
153 | |||
154 | } |
||
155 | |||
156 | public FLayer getLayer() {
|
||
157 | return lyr;
|
||
158 | } |
||
159 | |||
160 | /* (non-Javadoc)
|
||
161 | * @see java.awt.datatransfer.Transferable#getTransferDataFlavors()
|
||
162 | */
|
||
163 | public DataFlavor[] getTransferDataFlavors() { |
||
164 | return flavors;
|
||
165 | } |
||
166 | |||
167 | /* (non-Javadoc)
|
||
168 | * @see java.awt.datatransfer.Transferable#isDataFlavorSupported(java.awt.datatransfer.DataFlavor)
|
||
169 | */
|
||
170 | public boolean isDataFlavorSupported(DataFlavor dF) { |
||
171 | return dF.equals(INFO_FLAVOR);
|
||
172 | } |
||
173 | |||
174 | /* (non-Javadoc)
|
||
175 | * @see java.awt.datatransfer.Transferable#getTransferData(java.awt.datatransfer.DataFlavor)
|
||
176 | */
|
||
177 | public Object getTransferData(DataFlavor dF) throws UnsupportedFlavorException, IOException { |
||
178 | if (dF.equals(INFO_FLAVOR)) {
|
||
179 | return this; |
||
180 | } |
||
181 | else throw new UnsupportedFlavorException(dF); |
||
182 | } |
||
183 | /* (non-Javadoc)
|
||
184 | * @see com.iver.cit.gvsig.gui.toc.ITocItem#getSize()
|
||
185 | */
|
||
186 | public Dimension getSize() { |
||
187 | return sz;
|
||
188 | } |
||
189 | /* (non-Javadoc)
|
||
190 | * @see com.iver.cit.gvsig.gui.toc.ITocItem#setSize(java.awt.Dimension)
|
||
191 | */
|
||
192 | public void setSize(Dimension sz) { |
||
193 | this.sz = sz;
|
||
194 | } |
||
195 | |||
196 | private BufferedImage getUnavailableImage() { |
||
197 | if (this.unavailableImg == null) { |
||
198 | 41853 | jjdelcerro | ImageIcon uIcon = IconThemeHelper.getImageIcon("layer-chk-unavailable"); |
199 | 40435 | jjdelcerro | if (uIcon != null) { |
200 | this.unavailableImg = new BufferedImage(uIcon.getIconWidth(), uIcon.getIconHeight(), BufferedImage.TYPE_INT_RGB); |
||
201 | this.unavailableImg.getGraphics().drawImage(uIcon.getImage(), 0, 0, null); |
||
202 | } |
||
203 | } |
||
204 | return this.unavailableImg; |
||
205 | } |
||
206 | 41853 | jjdelcerro | |
207 | private BufferedImage getTemporaryLayerImage() { |
||
208 | if (this.temporaryLayerImg == null) { |
||
209 | ImageIcon uIcon = IconThemeHelper.getImageIcon("layer-chk-temporary"); |
||
210 | if (uIcon != null) { |
||
211 | this.temporaryLayerImg = new BufferedImage(uIcon.getIconWidth(), uIcon.getIconHeight(), BufferedImage.TYPE_INT_RGB); |
||
212 | this.temporaryLayerImg.getGraphics().drawImage(uIcon.getImage(), 0, 0, null); |
||
213 | } |
||
214 | } |
||
215 | return this.temporaryLayerImg; |
||
216 | } |
||
217 | 40435 | jjdelcerro | |
218 | public IContextMenuAction getDoubleClickAction() {
|
||
219 | // TODO
|
||
220 | // THIS IS A PATCH; IT WILL BE REMOVED WHEN ALL THE PROPERTIES
|
||
221 | // FOR ALL LAYERS WILL BE MERGED IN THE SAME DIALOG
|
||
222 | if (!(getLayer() instanceof FLyrVect)) { |
||
223 | return null; |
||
224 | } |
||
225 | return new FLyrVectEditPropertiesTocMenuEntry(); |
||
226 | } |
||
227 | } |