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 / ViewSelectionControls.java @ 41066
History | View | Annotate | Download (5.47 KB)
1 | 40558 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | 40435 | jjdelcerro | *
|
4 | 40558 | jjdelcerro | * Copyright (C) 2007-2013 gvSIG Association.
|
5 | 40435 | jjdelcerro | *
|
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 | 40558 | jjdelcerro | * as published by the Free Software Foundation; either version 3
|
9 | 40435 | jjdelcerro | * 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 | 40558 | jjdelcerro | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | * MA 02110-1301, USA.
|
||
20 | 40435 | jjdelcerro | *
|
21 | 40558 | jjdelcerro | * For any additional information, do not hesitate to contact us
|
22 | * at info AT gvsig.com, or visit our website www.gvsig.com.
|
||
23 | 40435 | jjdelcerro | */
|
24 | /* CVS MESSAGES:
|
||
25 | *
|
||
26 | * $Id: ViewSelectionControls.java 38702 2012-08-09 18:40:20Z jjdelcerro $
|
||
27 | * $Log$
|
||
28 | * Revision 1.16 2007-03-06 16:34:02 caballero
|
||
29 | * Exceptions
|
||
30 | *
|
||
31 | * Revision 1.15 2007/01/04 07:24:32 caballero
|
||
32 | * isModified
|
||
33 | *
|
||
34 | * Revision 1.14 2006/12/27 11:08:56 fdiaz
|
||
35 | * Arreglado el metodo hasVectorLayers para que no se pare en los grupos de capas cuando estos no tienen capas vectoriales.
|
||
36 | *
|
||
37 | * Revision 1.13 2006/09/25 16:54:12 caballero
|
||
38 | * invert selection
|
||
39 | *
|
||
40 | * Revision 1.12 2006/09/20 13:17:40 jaume
|
||
41 | * *** empty log message ***
|
||
42 | *
|
||
43 | * Revision 1.11 2006/09/20 10:56:56 sbayarri
|
||
44 | * Refactorizaci�n clases View y ProjectView
|
||
45 | *
|
||
46 | * Revision 1.10 2006/09/15 10:40:03 caballero
|
||
47 | * extensibilidad de documentos
|
||
48 | *
|
||
49 | * Revision 1.9 2006/09/11 16:14:15 fjp
|
||
50 | * Invertir seleccion. Falta subirlo al branch de la 1.0
|
||
51 | *
|
||
52 | * Revision 1.8 2006/09/11 06:53:13 fjp
|
||
53 | * Antes del parto
|
||
54 | *
|
||
55 | * Revision 1.7 2006/09/04 16:26:54 fjp
|
||
56 | * Seleccionar por pol�gono
|
||
57 | *
|
||
58 | * Revision 1.6 2006/08/29 07:56:27 cesar
|
||
59 | * Rename the *View* family of classes to *Window* (ie: SingletonView to SingletonWindow, ViewInfo to WindowInfo, etc)
|
||
60 | *
|
||
61 | * Revision 1.5 2006/08/29 07:21:08 cesar
|
||
62 | * Rename com.iver.cit.gvsig.fmap.Fmap class to com.iver.cit.gvsig.fmap.MapContext
|
||
63 | *
|
||
64 | * Revision 1.4 2006/08/29 07:13:53 cesar
|
||
65 | * Rename class com.iver.andami.ui.mdiManager.View to com.iver.andami.ui.mdiManager.IWindow
|
||
66 | *
|
||
67 | * Revision 1.3 2006/08/18 08:40:04 jmvivo
|
||
68 | * Actualizado para que el isEnabled tenga en cuenta que las capas esten 'avialable'
|
||
69 | *
|
||
70 | * Revision 1.2 2006/07/27 06:20:28 jaume
|
||
71 | * *** empty log message ***
|
||
72 | *
|
||
73 | * Revision 1.1 2006/07/26 09:53:05 jaume
|
||
74 | * separadas las herramientas de selecci�n del viewControls al ViewSelectionControls
|
||
75 | *
|
||
76 | *
|
||
77 | */
|
||
78 | package org.gvsig.app.extension; |
||
79 | |||
80 | import org.gvsig.andami.IconThemeHelper; |
||
81 | import org.gvsig.andami.PluginServices; |
||
82 | import org.gvsig.andami.plugins.Extension; |
||
83 | import org.gvsig.andami.ui.mdiManager.IWindow; |
||
84 | import org.gvsig.app.project.documents.AbstractDocument; |
||
85 | import org.gvsig.app.project.documents.view.ViewDocument; |
||
86 | import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
||
87 | import org.gvsig.fmap.mapcontext.MapContext; |
||
88 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
89 | import org.gvsig.fmap.mapcontext.layers.FLayers; |
||
90 | import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
||
91 | import org.gvsig.fmap.mapcontrol.MapControl; |
||
92 | import org.slf4j.Logger; |
||
93 | import org.slf4j.LoggerFactory; |
||
94 | |||
95 | |||
96 | /**
|
||
97 | * Extension that handles the selection tools, selection tools have sense on
|
||
98 | * vectorial layers only.
|
||
99 | *
|
||
100 | */
|
||
101 | public class ViewSelectionControls extends Extension { |
||
102 | private static final Logger logger = LoggerFactory |
||
103 | .getLogger(ViewSelectionControls.class); |
||
104 | private DefaultViewPanel vista;
|
||
105 | public void initialize() { |
||
106 | // TODO Auto-generated method stub
|
||
107 | registerIcons(); |
||
108 | } |
||
109 | |||
110 | private void registerIcons(){ |
||
111 | IconThemeHelper.registerIcon("action", "selection-select-by-rectangle", this); |
||
112 | IconThemeHelper.registerIcon("action", "selection-select-by-polygon", this); |
||
113 | IconThemeHelper.registerIcon("action", "selection-clear", this); |
||
114 | } |
||
115 | |||
116 | public void execute(String actionCommand) { |
||
117 | MapControl mapCtrl = vista.getMapControl(); |
||
118 | logger.debug("Comand : " + actionCommand);
|
||
119 | if (actionCommand.equalsIgnoreCase("selection-select-by-rectangle-view")) { |
||
120 | mapCtrl.setTool("rectSelection");
|
||
121 | ((AbstractDocument)vista.getModel()).setModified(true); |
||
122 | |||
123 | } else if (actionCommand.equalsIgnoreCase("selection-select-by-polygon")) { |
||
124 | mapCtrl.setTool("polSelection");
|
||
125 | ((AbstractDocument)vista.getModel()).setModified(true); |
||
126 | |||
127 | } |
||
128 | } |
||
129 | |||
130 | public boolean isEnabled() { |
||
131 | ViewDocument model = vista.getModel(); |
||
132 | MapContext mapa = model.getMapContext(); |
||
133 | |||
134 | for (int i = 0; i < mapa.getLayers().getActives().length; i++) { |
||
135 | FLayer lyr = mapa.getLayers().getActives()[i]; |
||
136 | if (lyr.isAvailable() && lyr instanceof FLyrVect) { // && !lyr.isEditing()) { |
||
137 | return true; |
||
138 | } |
||
139 | } |
||
140 | return false; |
||
141 | } |
||
142 | |||
143 | public boolean isVisible() { |
||
144 | IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
||
145 | |||
146 | if (f != null && f instanceof DefaultViewPanel) { |
||
147 | vista = (DefaultViewPanel) f; |
||
148 | ViewDocument model = vista.getModel(); |
||
149 | MapContext mapa = model.getMapContext(); |
||
150 | |||
151 | return hasVectorLayers(mapa.getLayers());
|
||
152 | |||
153 | } |
||
154 | return false; |
||
155 | } |
||
156 | |||
157 | private boolean hasVectorLayers(FLayers layers) { |
||
158 | for (int i = 0; i < layers.getLayersCount(); i++) { |
||
159 | FLayer lyr =layers.getLayer(i); |
||
160 | if (lyr instanceof FLayers){ |
||
161 | if (hasVectorLayers((FLayers) lyr)){
|
||
162 | return true; |
||
163 | } |
||
164 | } else if (lyr instanceof FLyrVect) { |
||
165 | return true; |
||
166 | } |
||
167 | } |
||
168 | return false; |
||
169 | } |
||
170 | } |