Revision 42164 trunk/org.gvsig.desktop/org.gvsig.desktop.plugin/org.gvsig.snapping.app/org.gvsig.snapping.app.mainplugin/src/main/java/org/gvsig/app/extension/EnableSnappingExtension.java
EnableSnappingExtension.java | ||
---|---|---|
23 | 23 |
*/ |
24 | 24 |
package org.gvsig.app.extension; |
25 | 25 |
|
26 |
import java.util.prefs.Preferences; |
|
27 |
|
|
28 | 26 |
import org.gvsig.andami.PluginServices; |
29 | 27 |
import org.gvsig.andami.PluginsLocator; |
30 | 28 |
import org.gvsig.andami.PluginsManager; |
31 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
|
32 |
import org.gvsig.app.gui.preferencespage.GridPage; |
|
33 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
|
29 |
import org.gvsig.andami.plugins.Extension; |
|
30 |
import org.gvsig.app.ApplicationLocator; |
|
31 |
import org.gvsig.app.ApplicationManager; |
|
32 |
import org.gvsig.app.project.documents.view.ViewDocument; |
|
33 |
import org.gvsig.app.project.documents.view.gui.IView; |
|
34 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
|
35 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
|
34 | 36 |
import org.gvsig.fmap.mapcontrol.MapControl; |
35 | 37 |
import org.gvsig.tools.dynobject.DynObject; |
36 | 38 |
|
... | ... | |
39 | 41 |
* @author jldominguez |
40 | 42 |
* |
41 | 43 |
*/ |
42 |
public class EnableSnappingExtension extends AbstractTogglePropertyExtension {
|
|
44 |
public class EnableSnappingExtension extends Extension { |
|
43 | 45 |
|
46 |
public void initialize() { |
|
47 |
// TODO Auto-generated method stub |
|
44 | 48 |
|
45 |
protected void doToggleValue(MapControl mc) { |
|
46 |
PluginsManager pluginManager = PluginsLocator.getManager(); |
|
47 |
PluginServices plugin = pluginManager.getPlugin(this); |
|
48 |
DynObject pluginProperties = plugin.getPluginProperties(); |
|
49 |
} |
|
49 | 50 |
|
51 |
public void execute(String actionCommand) { |
|
52 |
if (actionCommand.equals("edit-enable-snapping")) { |
|
50 | 53 |
|
51 |
boolean curr = mc.isRefentEnabled(); |
|
52 |
mc.setRefentEnabled(!curr); |
|
53 |
// Not clear if this can be saved in prefs: |
|
54 |
// Preferences prefs = SnapConfigPage... |
|
55 |
// prefs.putBoolean("???", mc.isRefentEnabled()); |
|
56 |
pluginProperties.setDynValue("applySnappers", mc.getGrid().isShowGrid()); |
|
57 |
plugin.savePluginProperties(); |
|
54 |
PluginsManager pluginManager = PluginsLocator.getManager(); |
|
55 |
PluginServices plugin = pluginManager.getPlugin(this); |
|
56 |
DynObject pluginProperties = plugin.getPluginProperties(); |
|
58 | 57 |
|
58 |
IView view = getActiveView(); |
|
59 |
MapControl mc = view.getMapControl(); |
|
60 |
mc.setRefentEnabled(true); |
|
61 |
pluginProperties.setDynValue("applySnappers", mc.isRefentEnabled()); |
|
62 |
plugin.savePluginProperties(); |
|
63 |
ApplicationLocator.getManager().refreshMenusAndToolBars(); |
|
64 |
} |
|
65 |
|
|
59 | 66 |
} |
60 | 67 |
|
61 |
protected String getActionCommand() { |
|
62 |
return "edit-toggle-snapping"; |
|
68 |
public boolean isEnabled() { |
|
69 |
IView view = getActiveView(); |
|
70 |
if (view != null) { |
|
71 |
MapControl mc = view.getMapControl(); |
|
72 |
if (mc != null) { |
|
73 |
FLyrVect layer = getActiveLayer(view); |
|
74 |
return (!mc.isRefentEnabled() && layer != null && layer.isEditing()); |
|
75 |
} |
|
76 |
} |
|
77 |
return false; |
|
63 | 78 |
} |
64 | 79 |
|
80 |
public boolean isVisible() { |
|
81 |
return isEnabled(); |
|
82 |
} |
|
65 | 83 |
|
84 |
private IView getActiveView() { |
|
85 |
ApplicationManager application = ApplicationLocator.getManager(); |
|
86 |
IView view = (IView) application.getActiveComponent(ViewDocument.class); |
|
87 |
return view; |
|
88 |
} |
|
66 | 89 |
|
90 |
private FLyrVect getActiveLayer(IView vista) { |
|
91 |
if (vista != null) { |
|
92 |
ViewDocument viewDocument = vista.getViewDocument(); |
|
93 |
FLayer[] actives = |
|
94 |
viewDocument.getMapContext().getLayers().getActives(); |
|
67 | 95 |
|
96 |
if ((actives.length == 1) && (actives[0] instanceof FLyrVect)) { |
|
97 |
return (FLyrVect) actives[0]; |
|
98 |
} |
|
99 |
} |
|
100 |
return null; |
|
101 |
} |
|
102 |
|
|
68 | 103 |
} |
Also available in: Unified diff