svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.app.document.table.app / org.gvsig.app.document.table.app.mainplugin / src / main / java / org / gvsig / app / extension / ZoomToSelectExtension.java @ 36443
History | View | Annotate | Download (4.93 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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 2
|
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 |
*/
|
22 |
package org.gvsig.app.extension; |
23 |
|
24 |
import org.gvsig.andami.PluginServices; |
25 |
import org.gvsig.andami.messages.NotificationManager; |
26 |
import org.gvsig.andami.plugins.Extension; |
27 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
28 |
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel; |
29 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
30 |
import org.gvsig.fmap.dal.exception.DataException; |
31 |
import org.gvsig.fmap.geom.primitive.Envelope; |
32 |
import org.gvsig.fmap.mapcontext.MapContext; |
33 |
import org.gvsig.tools.exception.BaseException; |
34 |
|
35 |
/**
|
36 |
* Extensi?n de zoom a lo seleccionado teniendo como ventana activa una tabla.
|
37 |
*
|
38 |
* @author Vicente Caballero Navarro
|
39 |
*/
|
40 |
public class ZoomToSelectExtension extends Extension { |
41 |
|
42 |
public void execute(String s) { |
43 |
org.gvsig.andami.ui.mdiManager.IWindow f = |
44 |
PluginServices.getMDIManager().getActiveWindow(); |
45 |
MapContext mapa = null;
|
46 |
Envelope selectedExtent = null;
|
47 |
if (f instanceof FeatureTableDocumentPanel) { |
48 |
FeatureTableDocumentPanel table = (FeatureTableDocumentPanel) f; |
49 |
mapa = (table.getModel().getAssociatedLayer()).getMapContext(); |
50 |
} |
51 |
|
52 |
try {
|
53 |
selectedExtent = mapa.getSelectionBounds(); |
54 |
mapa.getViewPort().setEnvelope(selectedExtent); |
55 |
} catch (BaseException e) {
|
56 |
NotificationManager.addError(e); |
57 |
} |
58 |
|
59 |
} |
60 |
|
61 |
public boolean isVisible() { |
62 |
org.gvsig.andami.ui.mdiManager.IWindow window = |
63 |
PluginServices.getMDIManager().getActiveWindow(); |
64 |
if (window instanceof FeatureTableDocumentPanel) { |
65 |
FeatureTableDocumentPanel featureTableDocumentPanel = |
66 |
(FeatureTableDocumentPanel) window; |
67 |
IWindow[] windows = PluginServices.getMDIManager().getAllWindows();
|
68 |
for (int i = 0; i < windows.length; i++) { |
69 |
if (windows[i] instanceof DefaultViewPanel) { |
70 |
if (featureTableDocumentPanel.getModel()
|
71 |
.getAssociatedLayer() != null) {
|
72 |
if (((DefaultViewPanel) windows[i])
|
73 |
.getMapControl() |
74 |
.getMapContext() |
75 |
.equals( |
76 |
(featureTableDocumentPanel.getModel() |
77 |
.getAssociatedLayer()).getMapContext())) { |
78 |
return true; |
79 |
} |
80 |
} |
81 |
} |
82 |
} |
83 |
} |
84 |
return false; |
85 |
} |
86 |
|
87 |
public boolean isEnabled() { |
88 |
org.gvsig.andami.ui.mdiManager.IWindow f = |
89 |
PluginServices.getMDIManager().getActiveWindow(); |
90 |
if (f == null) { |
91 |
return false; |
92 |
} |
93 |
if (f instanceof FeatureTableDocumentPanel) { |
94 |
FeatureTableDocumentPanel t = (FeatureTableDocumentPanel) f; |
95 |
IWindow[] windows = PluginServices.getMDIManager().getAllWindows();
|
96 |
for (int i = 0; i < windows.length; i++) { |
97 |
if (windows[i] instanceof DefaultViewPanel) { |
98 |
if (((DefaultViewPanel) windows[i])
|
99 |
.getMapControl() |
100 |
.getMapContext() |
101 |
.equals( |
102 |
(t.getModel().getAssociatedLayer()).getMapContext())) { |
103 |
try {
|
104 |
if (!t.getModel().getStore().getFeatureSelection()
|
105 |
.isEmpty()) { |
106 |
return true; |
107 |
} |
108 |
} catch (DataException e) {
|
109 |
NotificationManager.addError(e); |
110 |
return false; |
111 |
} |
112 |
} |
113 |
} |
114 |
} |
115 |
|
116 |
} |
117 |
return false; |
118 |
} |
119 |
|
120 |
public void initialize() { |
121 |
registerIcons(); |
122 |
} |
123 |
|
124 |
private void registerIcons() { |
125 |
PluginServices.getIconTheme().registerDefault( |
126 |
"table-zoom-to-seleccion",
|
127 |
this.getClass().getClassLoader()
|
128 |
.getResource("images/ZoomSeleccion.png"));
|
129 |
} |
130 |
} |