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 @ 41853
History | View | Annotate | Download (6.83 KB)
1 |
/**
|
---|---|
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 |
|
25 |
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 |
|
62 |
private BufferedImage temporaryLayerImg = null; |
63 |
|
64 |
private final String defaultIcon = "images/icolayer.PNG"; |
65 |
|
66 |
private boolean isAvailable = true; |
67 |
|
68 |
private FLayer lyr;
|
69 |
|
70 |
private Dimension sz; |
71 |
|
72 |
final public static DataFlavor INFO_FLAVOR = |
73 |
new DataFlavor(TocItemBranch.class, "ItemBranch"); |
74 |
static DataFlavor flavors[] = {INFO_FLAVOR }; |
75 |
|
76 |
public TocItemBranch(FLayer lyr)
|
77 |
{ |
78 |
this.lyr = lyr;
|
79 |
} |
80 |
/* (non-Javadoc)
|
81 |
* @see com.iver.cit.gvsig.gui.toc.ITocItem#getLabel()
|
82 |
*/
|
83 |
public String getLabel() { |
84 |
/*if (lyr instanceof FLyrVect && ((FLyrVect)lyr).isBroken())
|
85 |
{
|
86 |
return lyr.getName() + "(broken)";
|
87 |
}
|
88 |
else*/
|
89 |
return lyr.getName();
|
90 |
} |
91 |
|
92 |
/* (non-Javadoc)
|
93 |
* @see com.iver.cit.gvsig.gui.toc.ITocItem#getIcon()
|
94 |
*/
|
95 |
public Icon getIcon() { |
96 |
// TODO Pedirle el icono a la capa. Por defecto habr? un icono
|
97 |
// para vectoriales y otro para raster, pero se podr?n cambiar.
|
98 |
|
99 |
if (finalIcon == null) { |
100 |
ImageIcon icon = (ImageIcon) PluginServices.getIconTheme().get(lyr.getTocImageIcon()); |
101 |
this.setIcon(icon);
|
102 |
} |
103 |
updateStateIcon(); |
104 |
|
105 |
return finalIcon;
|
106 |
} |
107 |
|
108 |
private void setIcon(String path) { |
109 |
File f = new File(path); |
110 |
if (f.exists()) {
|
111 |
icolayer = new ImageIcon(f.getAbsolutePath()); |
112 |
} else {
|
113 |
URL url =PluginServices.getPluginServices("org.gvsig.app").getClassLoader().getResource(path); |
114 |
if (url!=null) { |
115 |
icolayer = new ImageIcon(url); |
116 |
return;
|
117 |
} |
118 |
} |
119 |
updateStateIcon(); |
120 |
|
121 |
} |
122 |
private void updateStateIcon() { |
123 |
if (icolayer == null) { |
124 |
return;
|
125 |
} |
126 |
BufferedImage newImage = new BufferedImage(icolayer.getIconWidth(),icolayer.getIconHeight(),BufferedImage.TYPE_INT_ARGB); |
127 |
Graphics2D grp = newImage.createGraphics();
|
128 |
grp.drawImage(icolayer.getImage(),0,0,null); |
129 |
if (lyr.getTocStatusImage() != null) { |
130 |
Image img = lyr.getTocStatusImage();
|
131 |
grp.drawImage(img,0,icolayer.getIconHeight()-img.getHeight(null),null); |
132 |
} |
133 |
|
134 |
if (this.lyr.isAvailable() != this.isAvailable ) { |
135 |
if (!this.lyr.isAvailable()) { |
136 |
BufferedImage img = this.getUnavailableImage(); |
137 |
grp.drawImage(img,0,icolayer.getIconHeight()-img.getHeight(),null); |
138 |
} |
139 |
this.isAvailable =(this.lyr.isAvailable()); |
140 |
} |
141 |
|
142 |
if( this.lyr.isTemporary() ) { |
143 |
BufferedImage img = this.getTemporaryLayerImage(); |
144 |
grp.drawImage(img,icolayer.getIconWidth()-img.getWidth(),icolayer.getIconHeight()-img.getHeight(),null);
|
145 |
} |
146 |
|
147 |
this.finalIcon = new ImageIcon(newImage); |
148 |
} |
149 |
|
150 |
private void setIcon(ImageIcon icon) { |
151 |
if (icon!=null) { |
152 |
icolayer = icon; |
153 |
} else {
|
154 |
this.setIcon(defaultIcon);
|
155 |
|
156 |
} |
157 |
updateStateIcon(); |
158 |
|
159 |
} |
160 |
|
161 |
public FLayer getLayer() {
|
162 |
return lyr;
|
163 |
} |
164 |
|
165 |
/* (non-Javadoc)
|
166 |
* @see java.awt.datatransfer.Transferable#getTransferDataFlavors()
|
167 |
*/
|
168 |
public DataFlavor[] getTransferDataFlavors() { |
169 |
return flavors;
|
170 |
} |
171 |
|
172 |
/* (non-Javadoc)
|
173 |
* @see java.awt.datatransfer.Transferable#isDataFlavorSupported(java.awt.datatransfer.DataFlavor)
|
174 |
*/
|
175 |
public boolean isDataFlavorSupported(DataFlavor dF) { |
176 |
return dF.equals(INFO_FLAVOR);
|
177 |
} |
178 |
|
179 |
/* (non-Javadoc)
|
180 |
* @see java.awt.datatransfer.Transferable#getTransferData(java.awt.datatransfer.DataFlavor)
|
181 |
*/
|
182 |
public Object getTransferData(DataFlavor dF) throws UnsupportedFlavorException, IOException { |
183 |
if (dF.equals(INFO_FLAVOR)) {
|
184 |
return this; |
185 |
} |
186 |
else throw new UnsupportedFlavorException(dF); |
187 |
} |
188 |
/* (non-Javadoc)
|
189 |
* @see com.iver.cit.gvsig.gui.toc.ITocItem#getSize()
|
190 |
*/
|
191 |
public Dimension getSize() { |
192 |
return sz;
|
193 |
} |
194 |
/* (non-Javadoc)
|
195 |
* @see com.iver.cit.gvsig.gui.toc.ITocItem#setSize(java.awt.Dimension)
|
196 |
*/
|
197 |
public void setSize(Dimension sz) { |
198 |
this.sz = sz;
|
199 |
} |
200 |
|
201 |
private BufferedImage getUnavailableImage() { |
202 |
if (this.unavailableImg == null) { |
203 |
ImageIcon uIcon = IconThemeHelper.getImageIcon("layer-chk-unavailable"); |
204 |
if (uIcon != null) { |
205 |
this.unavailableImg = new BufferedImage(uIcon.getIconWidth(), uIcon.getIconHeight(), BufferedImage.TYPE_INT_RGB); |
206 |
this.unavailableImg.getGraphics().drawImage(uIcon.getImage(), 0, 0, null); |
207 |
} |
208 |
} |
209 |
return this.unavailableImg; |
210 |
} |
211 |
|
212 |
private BufferedImage getTemporaryLayerImage() { |
213 |
if (this.temporaryLayerImg == null) { |
214 |
ImageIcon uIcon = IconThemeHelper.getImageIcon("layer-chk-temporary"); |
215 |
if (uIcon != null) { |
216 |
this.temporaryLayerImg = new BufferedImage(uIcon.getIconWidth(), uIcon.getIconHeight(), BufferedImage.TYPE_INT_RGB); |
217 |
this.temporaryLayerImg.getGraphics().drawImage(uIcon.getImage(), 0, 0, null); |
218 |
} |
219 |
} |
220 |
return this.temporaryLayerImg; |
221 |
} |
222 |
|
223 |
public IContextMenuAction getDoubleClickAction() {
|
224 |
// TODO
|
225 |
// THIS IS A PATCH; IT WILL BE REMOVED WHEN ALL THE PROPERTIES
|
226 |
// FOR ALL LAYERS WILL BE MERGED IN THE SAME DIALOG
|
227 |
if (!(getLayer() instanceof FLyrVect)) { |
228 |
return null; |
229 |
} |
230 |
return new FLyrVectEditPropertiesTocMenuEntry(); |
231 |
} |
232 |
} |