svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.selectiontools.app / org.gvsig.selectiontools.app.mainplugin / src / main / java / org / gvsig / selectiontools / app / extension / SelectByCircleExtension.java @ 43938
History | View | Annotate | Download (3.99 KB)
1 | 40556 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | *
|
||
4 | * Copyright (C) 2007-2013 gvSIG Association.
|
||
5 | *
|
||
6 | 41264 | 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 | 40556 | jjdelcerro | *
|
11 | 41264 | 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 | 40556 | jjdelcerro | *
|
16 | 41264 | 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 | 40556 | jjdelcerro | *
|
20 | 41264 | 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 | 40556 | jjdelcerro | */
|
23 | 40435 | jjdelcerro | package org.gvsig.selectiontools.app.extension; |
24 | |||
25 | import org.gvsig.andami.IconThemeHelper; |
||
26 | import org.gvsig.andami.plugins.Extension; |
||
27 | 41264 | jjdelcerro | import org.gvsig.app.ApplicationLocator; |
28 | import org.gvsig.app.ApplicationManager; |
||
29 | 40435 | jjdelcerro | import org.gvsig.app.project.documents.view.ViewDocument; |
30 | import org.gvsig.app.project.documents.view.gui.IView; |
||
31 | import org.gvsig.app.project.documents.view.toolListeners.StatusBarListener; |
||
32 | import org.gvsig.fmap.mapcontext.MapContext; |
||
33 | import org.gvsig.fmap.mapcontrol.MapControl; |
||
34 | import org.gvsig.fmap.mapcontrol.tools.Behavior.Behavior; |
||
35 | import org.gvsig.fmap.mapcontrol.tools.Behavior.MouseMovementBehavior; |
||
36 | import org.gvsig.selectiontools.app.extension.tools.CircleSelectListener; |
||
37 | import org.gvsig.selectiontools.app.extension.tools.behavior.CircleSelectionBehavior; |
||
38 | |||
39 | /**
|
||
40 | * Extension to add support for selecting the geometries of the active vector
|
||
41 | * layers that intersect with a circle defined by the user.
|
||
42 | */
|
||
43 | public class SelectByCircleExtension extends Extension { |
||
44 | |||
45 | public static final String CIRCLE_SELECTION_TOOL_NAME = "circleSelection"; |
||
46 | |||
47 | public void initialize() { |
||
48 | 41264 | jjdelcerro | IconThemeHelper.registerIcon("action", "selection-select-by-circle", this); |
49 | IconThemeHelper.registerIcon("cursor", "cursor-select-by-circle", this); |
||
50 | 40435 | jjdelcerro | } |
51 | |||
52 | public void execute(String actionCommand) { |
||
53 | 41264 | jjdelcerro | ApplicationManager application = ApplicationLocator.getManager(); |
54 | 40435 | jjdelcerro | |
55 | 41264 | jjdelcerro | IView view = (IView) application.getActiveComponent(ViewDocument.class); |
56 | if (view == null) { |
||
57 | return;
|
||
58 | } |
||
59 | if (actionCommand.equals("SELCIRCLE")) { |
||
60 | MapControl mc = view.getMapControl(); |
||
61 | /*
|
||
62 | If current's view MapControl doesn't have the
|
||
63 | "CircleSelection" tool, adds it
|
||
64 | */
|
||
65 | if (!mc.getNamesMapTools().containsKey(CIRCLE_SELECTION_TOOL_NAME)) {
|
||
66 | CircleSelectListener circleSelListener = new CircleSelectListener(mc);
|
||
67 | mc.addBehavior( |
||
68 | CIRCLE_SELECTION_TOOL_NAME, |
||
69 | new Behavior[]{ |
||
70 | new CircleSelectionBehavior(circleSelListener),
|
||
71 | new MouseMovementBehavior(new StatusBarListener(mc)) |
||
72 | }); |
||
73 | 40435 | jjdelcerro | } |
74 | 41264 | jjdelcerro | mc.setTool(CIRCLE_SELECTION_TOOL_NAME); |
75 | 40435 | jjdelcerro | } |
76 | } |
||
77 | |||
78 | public boolean isVisible() { |
||
79 | 41264 | jjdelcerro | ApplicationManager application = ApplicationLocator.getManager(); |
80 | 40435 | jjdelcerro | |
81 | 41264 | jjdelcerro | IView view = (IView) application.getActiveComponent(ViewDocument.class); |
82 | if (view == null) { |
||
83 | 40435 | jjdelcerro | return false; |
84 | } |
||
85 | 41264 | jjdelcerro | ViewDocument document = view.getViewDocument(); |
86 | MapContext mapa = document.getMapContext(); |
||
87 | return mapa.getLayers().getLayersCount() > 0; |
||
88 | 40435 | jjdelcerro | } |
89 | |||
90 | public boolean isEnabled() { |
||
91 | 41264 | jjdelcerro | ApplicationManager application = ApplicationLocator.getManager(); |
92 | 40435 | jjdelcerro | |
93 | 41264 | jjdelcerro | IView view = (IView) application.getActiveComponent(ViewDocument.class); |
94 | if (view == null) { |
||
95 | 40435 | jjdelcerro | return false; |
96 | } |
||
97 | 41264 | jjdelcerro | ViewDocument document = view.getViewDocument(); |
98 | return document.getMapContext().hasActiveVectorLayers();
|
||
99 | 40435 | jjdelcerro | } |
100 | } |