svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / extension / ZoomToSelectExtension.java @ 40596
History | View | Annotate | Download (3.85 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.extension; |
26 |
|
27 |
import org.gvsig.andami.IconThemeHelper; |
28 |
import org.gvsig.andami.PluginServices; |
29 |
import org.gvsig.andami.messages.NotificationManager; |
30 |
import org.gvsig.andami.plugins.Extension; |
31 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
32 |
import org.gvsig.fmap.dal.exception.DataException; |
33 |
import org.gvsig.fmap.geom.primitive.Envelope; |
34 |
import org.gvsig.fmap.mapcontext.MapContext; |
35 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
36 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
37 |
import org.gvsig.tools.exception.BaseException; |
38 |
|
39 |
|
40 |
|
41 |
/**
|
42 |
* Extensi?n de zoom a lo seleccionado teniendo como ventana activa una vista.
|
43 |
*
|
44 |
* @author Vicente Caballero Navarro
|
45 |
*/
|
46 |
public class ZoomToSelectExtension extends Extension { |
47 |
/**
|
48 |
* @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
|
49 |
*/
|
50 |
public void execute(String s) { |
51 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
52 |
.getActiveWindow(); |
53 |
MapContext mapa = null;
|
54 |
Envelope selectedExtent = null;
|
55 |
if (f instanceof DefaultViewPanel) { |
56 |
DefaultViewPanel vista = (DefaultViewPanel)f; |
57 |
mapa = vista.getModel().getMapContext(); |
58 |
} |
59 |
try {
|
60 |
selectedExtent = mapa.getSelectionBounds(); |
61 |
mapa.getViewPort().setEnvelope(selectedExtent); |
62 |
} catch (BaseException e) {
|
63 |
NotificationManager.addError(e); |
64 |
} |
65 |
|
66 |
//if (selectedExtent != null) {
|
67 |
//Envelope env=new DefaultEnvelope(2,new double[]{selectedExtent.getX(),selectedExtent.getY()},new double[]{selectedExtent.getMaxX(),selectedExtent.getMaxY()});
|
68 |
//((ProjectDocument) vista.getModel()).setModified(true);
|
69 |
|
70 |
//}
|
71 |
|
72 |
} |
73 |
|
74 |
/**
|
75 |
* @see com.iver.mdiApp.plugins.IExtension#isVisible()
|
76 |
*/
|
77 |
public boolean isVisible() { |
78 |
org.gvsig.andami.ui.mdiManager.IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
79 |
if (window != null && window instanceof DefaultViewPanel) { |
80 |
MapContext mapa = ((DefaultViewPanel) window).getModel().getMapContext(); |
81 |
return mapa.getLayers().getLayersCount() > 0; |
82 |
} |
83 |
return false; |
84 |
} |
85 |
|
86 |
/**
|
87 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled()
|
88 |
*/
|
89 |
public boolean isEnabled() { |
90 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
91 |
.getActiveWindow(); |
92 |
if (f == null) { |
93 |
return false; |
94 |
} |
95 |
if (f instanceof DefaultViewPanel) { |
96 |
DefaultViewPanel view = (DefaultViewPanel) f; |
97 |
FLayer[] selected = view.getModel().getMapContext().getLayers().getActives();
|
98 |
if (selected.length == 1 && selected[0] instanceof FLyrVect && selected[0].isAvailable()){ |
99 |
try {
|
100 |
if (!((FLyrVect) selected[0]).getFeatureStore() |
101 |
.getFeatureSelection().isEmpty()) { |
102 |
return true; |
103 |
} |
104 |
} catch (DataException e) {
|
105 |
NotificationManager.addError(e); |
106 |
return false; |
107 |
} |
108 |
} |
109 |
} |
110 |
|
111 |
|
112 |
return false; |
113 |
} |
114 |
|
115 |
/**
|
116 |
* @see org.gvsig.andami.plugins.IExtension#initialize()
|
117 |
*/
|
118 |
public void initialize() { |
119 |
IconThemeHelper.registerIcon("action", "view-navigation-zoom-to-selection", this); |
120 |
} |
121 |
} |