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 @ 44259
History | View | Annotate | Download (3.4 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 | 41248 | jjdelcerro | * 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 | 40435 | jjdelcerro | *
|
11 | 41248 | jjdelcerro | * 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 | 40435 | jjdelcerro | *
|
16 | 41248 | jjdelcerro | * 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 | 40435 | jjdelcerro | *
|
20 | 41248 | jjdelcerro | * For any additional information, do not hesitate to contact us at info AT
|
21 | * gvsig.com, or visit our website www.gvsig.com.
|
||
22 | 40435 | jjdelcerro | */
|
23 | package org.gvsig.app.extension; |
||
24 | |||
25 | import org.gvsig.andami.IconThemeHelper; |
||
26 | import org.gvsig.andami.plugins.Extension; |
||
27 | 41248 | jjdelcerro | import org.gvsig.app.ApplicationLocator; |
28 | import org.gvsig.app.ApplicationManager; |
||
29 | 40435 | jjdelcerro | import org.gvsig.app.project.documents.view.ViewDocument; |
30 | 41248 | jjdelcerro | import org.gvsig.app.project.documents.view.gui.IView; |
31 | 40435 | jjdelcerro | import org.gvsig.fmap.mapcontrol.MapControl; |
32 | import org.slf4j.Logger; |
||
33 | import org.slf4j.LoggerFactory; |
||
34 | |||
35 | /**
|
||
36 | * Extension that handles the selection tools, selection tools have sense on
|
||
37 | * vectorial layers only.
|
||
38 | *
|
||
39 | */
|
||
40 | public class ViewSelectionControls extends Extension { |
||
41 | 41248 | jjdelcerro | |
42 | 40435 | jjdelcerro | private static final Logger logger = LoggerFactory |
43 | .getLogger(ViewSelectionControls.class); |
||
44 | |||
45 | 41248 | jjdelcerro | public void initialize() { |
46 | registerIcons(); |
||
47 | } |
||
48 | 40435 | jjdelcerro | |
49 | 41248 | jjdelcerro | private void registerIcons() { |
50 | IconThemeHelper.registerIcon("action", "selection-select-by-rectangle", this); |
||
51 | IconThemeHelper.registerIcon("action", "selection-select-by-polygon", this); |
||
52 | IconThemeHelper.registerIcon("action", "selection-clear", this); |
||
53 | } |
||
54 | 40435 | jjdelcerro | |
55 | 41248 | jjdelcerro | public void execute(String actionCommand) { |
56 | ApplicationManager application = ApplicationLocator.getManager(); |
||
57 | 40435 | jjdelcerro | |
58 | 41264 | jjdelcerro | IView view = (IView) application.getActiveComponent(ViewDocument.class); |
59 | if (view == null) { |
||
60 | 41248 | jjdelcerro | return;
|
61 | } |
||
62 | 41264 | jjdelcerro | ViewDocument document = view.getViewDocument(); |
63 | MapControl mapCtrl = view.getMapControl(); |
||
64 | 40435 | jjdelcerro | |
65 | 41248 | jjdelcerro | if (actionCommand.equalsIgnoreCase("selection-select-by-rectangle-view")) { |
66 | mapCtrl.setTool("rectSelection");
|
||
67 | document.setModified(true);
|
||
68 | 40435 | jjdelcerro | |
69 | 41248 | jjdelcerro | } else if (actionCommand.equalsIgnoreCase("selection-select-by-polygon")) { |
70 | mapCtrl.setTool("polSelection");
|
||
71 | document.setModified(true);
|
||
72 | 40435 | jjdelcerro | |
73 | 41248 | jjdelcerro | } |
74 | } |
||
75 | |||
76 | public boolean isEnabled() { |
||
77 | ApplicationManager application = ApplicationLocator.getManager(); |
||
78 | |||
79 | 41264 | jjdelcerro | IView view = (IView) application.getActiveComponent(ViewDocument.class); |
80 | if (view == null) { |
||
81 | 41248 | jjdelcerro | return false; |
82 | } |
||
83 | 41264 | jjdelcerro | ViewDocument document = view.getViewDocument(); |
84 | 41248 | jjdelcerro | return document.getMapContext().hasActiveVectorLayers();
|
85 | } |
||
86 | |||
87 | public boolean isVisible() { |
||
88 | ApplicationManager application = ApplicationLocator.getManager(); |
||
89 | |||
90 | 41264 | jjdelcerro | IView view = (IView) application.getActiveComponent(ViewDocument.class); |
91 | if (view == null) { |
||
92 | 41248 | jjdelcerro | return false; |
93 | } |
||
94 | 41264 | jjdelcerro | ViewDocument document = view.getViewDocument(); |
95 | 41248 | jjdelcerro | return document.getMapContext().hasVectorLayers();
|
96 | } |
||
97 | |||
98 | 40435 | jjdelcerro | } |