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 @ 44437
History | View | Annotate | Download (4.4 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 modify it under
|
7 |
* the terms of the GNU General Public License as published by the Free Software
|
8 |
* Foundation; either version 3 of the License, or (at your option) any later
|
9 |
* version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful, but WITHOUT
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
13 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
14 |
* details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License along with
|
17 |
* this program; if not, write to the Free Software Foundation, Inc., 51
|
18 |
* Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
21 |
* gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.app.extension; |
24 |
|
25 |
import javax.swing.JOptionPane; |
26 |
import org.gvsig.andami.IconThemeHelper; |
27 |
import org.gvsig.andami.plugins.Extension; |
28 |
import org.gvsig.app.ApplicationLocator; |
29 |
import org.gvsig.app.ApplicationManager; |
30 |
import org.gvsig.app.project.documents.view.ViewDocument; |
31 |
import org.gvsig.app.project.documents.view.gui.IView; |
32 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
33 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
34 |
import org.gvsig.fmap.dal.feature.FeatureType; |
35 |
import org.gvsig.fmap.geom.primitive.Envelope; |
36 |
import org.gvsig.fmap.mapcontext.MapContext; |
37 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
38 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
39 |
import org.gvsig.tools.exception.BaseException; |
40 |
import org.slf4j.Logger; |
41 |
import org.slf4j.LoggerFactory; |
42 |
|
43 |
/**
|
44 |
* Extensi?n de zoom a lo seleccionado teniendo como ventana activa una vista.
|
45 |
*
|
46 |
*/
|
47 |
public class ZoomToSelectExtension extends Extension { |
48 |
|
49 |
private static final Logger logger = LoggerFactory |
50 |
.getLogger(ZoomToSelectExtension.class); |
51 |
|
52 |
public void initialize() { |
53 |
IconThemeHelper.registerIcon("action", "view-navigation-zoom-to-selection", this); |
54 |
} |
55 |
|
56 |
public void execute(String s) { |
57 |
ApplicationManager application = ApplicationLocator.getManager(); |
58 |
|
59 |
IView view = (IView) application.getActiveComponent(ViewDocument.class); |
60 |
if (view == null) { |
61 |
return;
|
62 |
} |
63 |
ViewDocument document = view.getViewDocument(); |
64 |
MapContext mapa = document.getMapContext(); |
65 |
Envelope selectedExtent = null;
|
66 |
try {
|
67 |
selectedExtent = mapa.getSelectionBounds(); |
68 |
mapa.getViewPort().setEnvelope(selectedExtent); |
69 |
} catch (BaseException e) {
|
70 |
String msg = "Can't zoom to the seleccion."; |
71 |
logger.warn(msg, e); |
72 |
application.message(msg, JOptionPane.WARNING_MESSAGE);
|
73 |
} |
74 |
} |
75 |
|
76 |
public boolean isVisible() { |
77 |
ApplicationManager application = ApplicationLocator.getManager(); |
78 |
|
79 |
IView view = (IView) application.getActiveComponent(ViewDocument.class); |
80 |
if (view == null) { |
81 |
return false; |
82 |
} |
83 |
ViewDocument document = view.getViewDocument(); |
84 |
return document.getMapContext().getLayers().getLayersCount() > 0; |
85 |
} |
86 |
|
87 |
@Override
|
88 |
public boolean isEnabled() { |
89 |
ApplicationManager application = ApplicationLocator.getManager(); |
90 |
|
91 |
IView view = (IView) application.getActiveComponent(ViewDocument.class); |
92 |
if (view == null) { |
93 |
return false; |
94 |
} |
95 |
ViewDocument document = view.getViewDocument(); |
96 |
if( document == null ) { |
97 |
return false; |
98 |
} |
99 |
boolean hasActiveVectorLayers = false; |
100 |
boolean hasSelection = false; |
101 |
for (FLayer layer : document.getMapContext().getLayers()) {
|
102 |
if( layer.isActive() && layer.isAvailable() && layer instanceof FLyrVect ) { |
103 |
try {
|
104 |
hasActiveVectorLayers = true;
|
105 |
FeatureStore store = ((FLyrVect)layer).getFeatureStore(); |
106 |
FeatureSelection selection = store.getFeatureSelection(); |
107 |
if( !selection.isAvailable() ) {
|
108 |
return false; |
109 |
} |
110 |
if( !selection.isEmpty() ) {
|
111 |
hasSelection = true;
|
112 |
} |
113 |
} catch (Exception ex) { |
114 |
} |
115 |
} |
116 |
} |
117 |
return hasActiveVectorLayers && hasSelection;
|
118 |
} |
119 |
|
120 |
} |