Revision 41066
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/extension/ViewSimpleSelectionControl.java | ||
---|---|---|
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 |
/* 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.app.project.documents.view.gui.IView; |
|
88 |
import org.gvsig.fmap.mapcontext.MapContext; |
|
89 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
90 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
|
91 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
92 |
import org.gvsig.fmap.mapcontrol.MapControl; |
|
93 |
import org.slf4j.Logger; |
|
94 |
import org.slf4j.LoggerFactory; |
|
95 |
|
|
96 |
|
|
97 |
/** |
|
98 |
* Extension that handles the simple selection tool |
|
99 |
* |
|
100 |
*/ |
|
101 |
public class ViewSimpleSelectionControl extends Extension { |
|
102 |
|
|
103 |
private static final Logger logger = LoggerFactory |
|
104 |
.getLogger(ViewSimpleSelectionControl.class); |
|
105 |
|
|
106 |
public void initialize() { |
|
107 |
registerIcons(); |
|
108 |
} |
|
109 |
|
|
110 |
private void registerIcons(){ |
|
111 |
IconThemeHelper.registerIcon("action", "selection-simple-select", this); |
|
112 |
} |
|
113 |
|
|
114 |
public void execute(String actionCommand) { |
|
115 |
|
|
116 |
IView view = this.getView(); |
|
117 |
if (view == null) { |
|
118 |
logger.info("Didn't find the view.", new Exception("Didn't find the view")); |
|
119 |
return; |
|
120 |
} |
|
121 |
|
|
122 |
MapControl mapCtrl = view.getMapControl(); |
|
123 |
logger.debug("Comand : " + actionCommand); |
|
124 |
if (actionCommand.equalsIgnoreCase("selection-simple-select-view")) { |
|
125 |
mapCtrl.setTool("pointSelection"); |
|
126 |
view.getViewDocument().setModified(true); |
|
127 |
} |
|
128 |
} |
|
129 |
|
|
130 |
public boolean isEnabled() { |
|
131 |
return isVisible(); |
|
132 |
} |
|
133 |
|
|
134 |
public boolean isVisible() { |
|
135 |
|
|
136 |
IView view = getView(); |
|
137 |
if (view != null) { |
|
138 |
MapContext mapa = view.getMapControl().getMapContext(); |
|
139 |
if (hasVectorLayers(mapa.getLayers())) { |
|
140 |
if (singleActiveInEditing(mapa)) { |
|
141 |
return false; |
|
142 |
} else { |
|
143 |
return true; |
|
144 |
} |
|
145 |
} else { |
|
146 |
return false; |
|
147 |
} |
|
148 |
} else { |
|
149 |
return false; |
|
150 |
} |
|
151 |
} |
|
152 |
|
|
153 |
private boolean singleActiveInEditing(MapContext mapa) { |
|
154 |
|
|
155 |
FLayer[] lyrs = mapa.getLayers().getActives(); |
|
156 |
if (lyrs != null && lyrs.length == 1) { |
|
157 |
return lyrs[0].isEditing(); |
|
158 |
} else { |
|
159 |
return false; |
|
160 |
} |
|
161 |
} |
|
162 |
|
|
163 |
private boolean hasVectorLayers(FLayers layers) { |
|
164 |
for (int i = 0; i < layers.getLayersCount(); i++) { |
|
165 |
FLayer lyr =layers.getLayer(i); |
|
166 |
if (lyr instanceof FLayers){ |
|
167 |
if (hasVectorLayers((FLayers) lyr)){ |
|
168 |
return true; |
|
169 |
} |
|
170 |
} else if (lyr instanceof FLyrVect) { |
|
171 |
return true; |
|
172 |
} |
|
173 |
} |
|
174 |
return false; |
|
175 |
} |
|
176 |
|
|
177 |
private IView getView() { |
|
178 |
|
|
179 |
IView resp = null; |
|
180 |
IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
|
181 |
|
|
182 |
if (f != null && f instanceof IView) { |
|
183 |
resp = (IView) f; |
|
184 |
} |
|
185 |
return resp; |
|
186 |
} |
|
187 |
|
|
188 |
} |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/java/org/gvsig/app/extension/ViewSelectionControls.java | ||
---|---|---|
108 | 108 |
} |
109 | 109 |
|
110 | 110 |
private void registerIcons(){ |
111 |
IconThemeHelper.registerIcon("action", "selection-simple-select", this); |
|
112 | 111 |
IconThemeHelper.registerIcon("action", "selection-select-by-rectangle", this); |
113 | 112 |
IconThemeHelper.registerIcon("action", "selection-select-by-polygon", this); |
114 | 113 |
IconThemeHelper.registerIcon("action", "selection-clear", this); |
... | ... | |
121 | 120 |
mapCtrl.setTool("rectSelection"); |
122 | 121 |
((AbstractDocument)vista.getModel()).setModified(true); |
123 | 122 |
|
124 |
} else if (actionCommand.equalsIgnoreCase("selection-simple-select-view")) { |
|
125 |
mapCtrl.setTool("pointSelection"); |
|
126 |
((AbstractDocument)vista.getModel()).setModified(true); |
|
127 |
|
|
128 | 123 |
} else if (actionCommand.equalsIgnoreCase("selection-select-by-polygon")) { |
129 | 124 |
mapCtrl.setTool("polSelection"); |
130 | 125 |
((AbstractDocument)vista.getModel()).setModified(true); |
trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.app/org.gvsig.app.mainplugin/src/main/resources-plugin/config.xml | ||
---|---|---|
529 | 529 |
description="Extensi?n encargada de gestionar la vista." |
530 | 530 |
active="true" |
531 | 531 |
priority="30"> |
532 |
|
|
532 | 533 |
<action |
533 |
name="selection-simple-select-view" |
|
534 |
label="_Simple_select" |
|
535 |
position="300700000" |
|
536 |
action-command="selection-simple-select-view" |
|
537 |
icon="selection-simple-select" |
|
538 |
tooltip="_Simple_select" |
|
539 |
accelerator="" |
|
540 |
/> |
|
541 |
<action |
|
542 | 534 |
name="selection-select-by-rectangle-view" |
543 | 535 |
label="Select_by_rectangle" |
544 | 536 |
position="301200000" |
... | ... | |
557 | 549 |
accelerator="" |
558 | 550 |
/> |
559 | 551 |
|
560 |
|
|
561 | 552 |
<menu |
562 |
name="selection-simple-select-view" |
|
563 |
text="Selection/Simple" |
|
564 |
/> |
|
565 |
<menu |
|
566 | 553 |
name="selection-select-by-rectangle-view" |
567 | 554 |
text="Selection/Select_by_rectangle" |
568 | 555 |
/> |
... | ... | |
572 | 559 |
/> |
573 | 560 |
|
574 | 561 |
<tool-bar name="view_selection" position="6"> |
575 |
<selectable-tool name="selection-simple-select-view" /> |
|
576 | 562 |
<selectable-tool name="selection-select-by-rectangle-view" /> |
577 | 563 |
<selectable-tool name="selection-select-by-polygon" /> |
578 | 564 |
</tool-bar> |
579 | 565 |
|
580 | 566 |
</extension> |
581 | 567 |
|
568 |
|
|
569 |
|
|
570 |
<extension class-name="org.gvsig.app.extension.ViewSimpleSelectionControl" |
|
571 |
description="Extensi?n encargada de gestionar la herramienta de selecci?n simple." |
|
572 |
active="true" |
|
573 |
priority="30"> |
|
574 |
<action |
|
575 |
name="selection-simple-select-view" |
|
576 |
label="_Simple_select" |
|
577 |
position="300700000" |
|
578 |
action-command="selection-simple-select-view" |
|
579 |
icon="selection-simple-select" |
|
580 |
tooltip="_Simple_select" |
|
581 |
accelerator="" |
|
582 |
/> |
|
583 |
|
|
584 |
<menu |
|
585 |
name="selection-simple-select-view" |
|
586 |
text="Selection/Simple" |
|
587 |
/> |
|
588 |
|
|
589 |
<tool-bar name="view_selection" position="6"> |
|
590 |
<selectable-tool name="selection-simple-select-view" /> |
|
591 |
</tool-bar> |
|
592 |
|
|
593 |
</extension> |
|
594 |
|
|
595 |
|
|
582 | 596 |
<extension class-name="org.gvsig.app.extension.ViewSelectionByTheme" |
583 | 597 |
description="Extensi?n encargada de la selecci?n por tema." |
584 | 598 |
active="true" |
Also available in: Unified diff