svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.snapping.app / org.gvsig.snapping.app.mainplugin / src / main / java / org / gvsig / app / extension / DisableSnappingExtension.java @ 43288
History | View | Annotate | Download (3.68 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
|
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 |
package org.gvsig.app.extension; |
25 |
|
26 |
import java.util.prefs.Preferences; |
27 |
|
28 |
import org.gvsig.andami.PluginServices; |
29 |
import org.gvsig.andami.PluginsLocator; |
30 |
import org.gvsig.andami.PluginsManager; |
31 |
import org.gvsig.andami.plugins.Extension; |
32 |
import org.gvsig.app.ApplicationLocator; |
33 |
import org.gvsig.app.ApplicationManager; |
34 |
import org.gvsig.app.project.documents.view.ViewDocument; |
35 |
import org.gvsig.app.project.documents.view.gui.IView; |
36 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
37 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
38 |
import org.gvsig.fmap.mapcontrol.MapControl; |
39 |
import org.gvsig.tools.dynobject.DynObject; |
40 |
|
41 |
|
42 |
/**
|
43 |
* @author jldominguez
|
44 |
*
|
45 |
*/
|
46 |
public class DisableSnappingExtension extends Extension { |
47 |
|
48 |
public void initialize() { |
49 |
// TODO Auto-generated method stub
|
50 |
|
51 |
} |
52 |
|
53 |
public void execute(String actionCommand) { |
54 |
if (actionCommand.equals("edit-disable-snapping")) { |
55 |
|
56 |
PluginsManager pluginManager = PluginsLocator.getManager(); |
57 |
PluginServices plugin = pluginManager.getPlugin(this);
|
58 |
DynObject pluginProperties = plugin.getPluginProperties(); |
59 |
|
60 |
IView view = getActiveView(); |
61 |
MapControl mc = view.getMapControl(); |
62 |
mc.setRefentEnabled(false);
|
63 |
pluginProperties.setDynValue("applySnappers", mc.isRefentEnabled());
|
64 |
plugin.savePluginProperties(); |
65 |
|
66 |
Preferences prefs = Preferences.userRoot().node("snappers"); |
67 |
prefs.putBoolean("apply-snappers", mc.isRefentEnabled());
|
68 |
|
69 |
ApplicationLocator.getManager().refreshMenusAndToolBars(); |
70 |
} |
71 |
|
72 |
} |
73 |
|
74 |
public boolean isEnabled() { |
75 |
IView view = getActiveView(); |
76 |
if (view != null) { |
77 |
MapControl mc = view.getMapControl(); |
78 |
if (mc != null) { |
79 |
FLyrVect layer = getActiveLayer(view); |
80 |
return (mc.isRefentEnabled() && layer != null && layer.isEditing()); |
81 |
} |
82 |
} |
83 |
return false; |
84 |
} |
85 |
|
86 |
public boolean isVisible() { |
87 |
return isEnabled();
|
88 |
} |
89 |
|
90 |
private IView getActiveView() {
|
91 |
ApplicationManager application = ApplicationLocator.getManager(); |
92 |
IView view = (IView) application.getActiveComponent(ViewDocument.class); |
93 |
return view;
|
94 |
} |
95 |
|
96 |
private FLyrVect getActiveLayer(IView vista) {
|
97 |
if (vista != null) { |
98 |
ViewDocument viewDocument = vista.getViewDocument(); |
99 |
FLayer[] actives =
|
100 |
viewDocument.getMapContext().getLayers().getActives(); |
101 |
|
102 |
if ((actives.length == 1) && (actives[0] instanceof FLyrVect)) { |
103 |
return (FLyrVect) actives[0]; |
104 |
} |
105 |
} |
106 |
return null; |
107 |
} |
108 |
|
109 |
} |