svn-gvsig-desktop / trunk / extensions / extQuickInfo / src / org / gvsig / quickInfo / QuickInfoToolExtension.java @ 28223
History | View | Annotate | Download (4.52 KB)
1 |
package org.gvsig.quickInfo; |
---|---|
2 |
|
3 |
/* gvSIG. Geographic Information System of the Valencian Government
|
4 |
*
|
5 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
6 |
* of the Valencian Government (CIT)
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
21 |
* MA 02110-1301, USA.
|
22 |
*
|
23 |
*/
|
24 |
|
25 |
import org.gvsig.quickInfo.gui.QuickInfoDataSelectionPanel; |
26 |
|
27 |
import com.iver.andami.PluginServices; |
28 |
import com.iver.andami.plugins.Extension; |
29 |
import com.iver.cit.gvsig.fmap.MapContext; |
30 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
31 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
32 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
33 |
import com.iver.cit.gvsig.project.documents.view.IProjectView; |
34 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
35 |
|
36 |
/**
|
37 |
* <p><a href="http://www.gvsig.com/">gvSIG</a> extension.</p>
|
38 |
* <p>Tool that displays the selected information that the cursor points on the active view.</p>
|
39 |
*
|
40 |
* @author Pablo Piqueras Bartolom? (pablo.piqueras@iver.es)
|
41 |
*/
|
42 |
public class QuickInfoToolExtension extends Extension { |
43 |
/*
|
44 |
* (non-Javadoc)
|
45 |
* @see com.iver.andami.plugins.IExtension#execute(java.lang.String)
|
46 |
*/
|
47 |
public void execute(String actionCommand) { |
48 |
if (actionCommand.equals("QINFO")) { |
49 |
View view = (View)PluginServices.getMDIManager().getActiveWindow(); |
50 |
new QuickInfoDataSelectionPanel(view.getMapControl());
|
51 |
// PluginServices.getMDIManager().addWindow(dataSelectionPanel);
|
52 |
} |
53 |
} |
54 |
|
55 |
/*
|
56 |
* (non-Javadoc)
|
57 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
58 |
*/
|
59 |
public void initialize() { |
60 |
registerIcons(); |
61 |
} |
62 |
|
63 |
protected void registerIcons() { |
64 |
PluginServices.getIconTheme().registerDefault( |
65 |
"right-arrow-icon",
|
66 |
this.getClass().getClassLoader().getResource("images/arrow_right.png") |
67 |
); |
68 |
|
69 |
PluginServices.getIconTheme().registerDefault( |
70 |
"layerGroup",
|
71 |
this.getClass().getClassLoader().getResource("images/layerGroup.png") |
72 |
); |
73 |
|
74 |
PluginServices.getIconTheme().registerDefault( |
75 |
"field-leaf-icon",
|
76 |
this.getClass().getClassLoader().getResource("images/field-leaf-icon.png") |
77 |
); |
78 |
|
79 |
PluginServices.getIconTheme().registerDefault( |
80 |
"field-complex-icon",
|
81 |
this.getClass().getClassLoader().getResource("images/field-complex-icon.png") |
82 |
); |
83 |
|
84 |
PluginServices.getIconTheme().registerDefault( |
85 |
"field-child-icon",
|
86 |
this.getClass().getClassLoader().getResource("images/field-child-icon.png") |
87 |
); |
88 |
} |
89 |
|
90 |
/*
|
91 |
* (non-Javadoc)
|
92 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
93 |
*/
|
94 |
public boolean isEnabled() { |
95 |
com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
96 |
|
97 |
if (f == null) { |
98 |
return false; |
99 |
} |
100 |
|
101 |
if (f instanceof View) { |
102 |
View view = (View) f; |
103 |
|
104 |
IProjectView model = view.getModel(); |
105 |
MapContext map = model.getMapContext(); |
106 |
|
107 |
return hasVectorVisibleLayers(map.getLayers());
|
108 |
} |
109 |
|
110 |
return false; |
111 |
} |
112 |
|
113 |
/*
|
114 |
* (non-Javadoc)
|
115 |
* @see com.iver.andami.plugins.IExtension#isVisible()
|
116 |
*/
|
117 |
public boolean isVisible() { |
118 |
com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
119 |
|
120 |
if (f == null) { |
121 |
return false; |
122 |
} |
123 |
|
124 |
if (f instanceof View) { |
125 |
View view = (View) f; |
126 |
|
127 |
IProjectView model = view.getModel(); |
128 |
MapContext map = model.getMapContext(); |
129 |
|
130 |
return map.getLayers().getLayersCount() > 0; |
131 |
} else {
|
132 |
return false; |
133 |
} |
134 |
} |
135 |
|
136 |
/**
|
137 |
* <p>Finds recursively if there is any visible vector layer.</p>
|
138 |
*
|
139 |
* @param root the root node
|
140 |
* @return <code>true</code> if the layer is found and is visible in the tree; otherwise <code>false</code>
|
141 |
*/
|
142 |
private boolean hasVectorVisibleLayers(FLayers root) { |
143 |
if (root != null) { |
144 |
FLayer node; |
145 |
|
146 |
for (int i = 0; i < root.getLayersCount(); i++) { |
147 |
node = root.getLayer(i); |
148 |
|
149 |
if (node instanceof FLyrVect) { |
150 |
if (node.isVisible())
|
151 |
return true; |
152 |
} |
153 |
else {
|
154 |
if (node instanceof FLayers) { |
155 |
if (hasVectorVisibleLayers((FLayers) node))
|
156 |
return true; |
157 |
} |
158 |
} |
159 |
} |
160 |
} |
161 |
|
162 |
return false; |
163 |
} |
164 |
} |