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 / SnappingExtension.java @ 47426
History | View | Annotate | Download (6.22 KB)
1 | 42037 | fdiaz | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | *
|
||
4 | * Copyright (C) 2007-2013 gvSIG Association.
|
||
5 | *
|
||
6 | 42501 | 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 | 42037 | fdiaz | *
|
11 | 42501 | 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 | 42037 | fdiaz | *
|
16 | 42501 | 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 | 42037 | fdiaz | *
|
20 | 42501 | 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 | 42037 | fdiaz | */
|
23 | package org.gvsig.app.extension; |
||
24 | |||
25 | 43288 | fdiaz | import java.util.prefs.Preferences; |
26 | |||
27 | 42037 | fdiaz | import org.gvsig.andami.IconThemeHelper; |
28 | import org.gvsig.andami.PluginServices; |
||
29 | import org.gvsig.andami.plugins.Extension; |
||
30 | 42508 | jjdelcerro | import org.gvsig.andami.preferences.IPreference; |
31 | import org.gvsig.andami.preferences.IPreferenceExtension; |
||
32 | 42037 | fdiaz | import org.gvsig.app.gui.preferencespage.GridPage; |
33 | import org.gvsig.app.gui.preferencespage.SnapConfigPage; |
||
34 | import org.gvsig.app.project.documents.view.ViewDocument; |
||
35 | import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
||
36 | import org.gvsig.app.project.documents.view.gui.ViewSnappingPropertiesPageFactory; |
||
37 | import org.gvsig.app.project.documents.view.toolListeners.snapping.Snapping; |
||
38 | import org.gvsig.fmap.mapcontext.MapContext; |
||
39 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
40 | import org.gvsig.fmap.mapcontext.layers.FLayers; |
||
41 | import org.gvsig.fmap.mapcontext.layers.LayersIterator; |
||
42 | import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
||
43 | import org.gvsig.fmap.mapcontrol.MapControlLocator; |
||
44 | import org.gvsig.fmap.mapcontrol.MapControlManager; |
||
45 | import org.gvsig.fmap.mapcontrol.tools.snapping.snappers.ISnapper; |
||
46 | import org.gvsig.propertypage.PropertiesPageManager; |
||
47 | 47426 | jjdelcerro | import org.gvsig.tools.swing.api.ToolsSwingUtils; |
48 | 42037 | fdiaz | |
49 | 43288 | fdiaz | |
50 | 42037 | fdiaz | /**
|
51 | * Extension for config the snapping
|
||
52 | 42501 | jjdelcerro | *
|
53 | 42037 | fdiaz | * @author fdiaz
|
54 | *
|
||
55 | */
|
||
56 | 42508 | jjdelcerro | public class SnappingExtension extends Extension implements IPreferenceExtension { |
57 | 42037 | fdiaz | |
58 | 42508 | jjdelcerro | private IPreference[] preferencePages = null; |
59 | 43288 | fdiaz | |
60 | 42037 | fdiaz | public void initialize() { |
61 | Snapping.register(); |
||
62 | |||
63 | registerIcons(); |
||
64 | |||
65 | 42508 | jjdelcerro | MapControlManager mapControlManager = MapControlLocator.getMapControlManager(); |
66 | 42037 | fdiaz | for (int n = 0; n < mapControlManager.getSnapperCount(); n++) { |
67 | ISnapper snp = (ISnapper) mapControlManager.getSnapperAt(n); |
||
68 | 42501 | jjdelcerro | String nameClass = snp.getClass().getName();
|
69 | nameClass = nameClass.substring(nameClass.lastIndexOf('.') + 1); |
||
70 | snp.setEnabled((Boolean) getPlugin().getPluginProperties().getDynValue("snapperActivated" + nameClass)); |
||
71 | snp.setPriority((Integer) getPlugin().getPluginProperties().getDynValue("snapperPriority" + nameClass)); |
||
72 | 42037 | fdiaz | } |
73 | |||
74 | 42501 | jjdelcerro | Integer snapTolerance
|
75 | = (Integer) getPlugin().getPluginProperties().getDynValue("snapTolerance"); |
||
76 | 42037 | fdiaz | mapControlManager.setTolerance(snapTolerance.intValue()); |
77 | |||
78 | 42501 | jjdelcerro | Boolean applySnappers
|
79 | = (Boolean) getPlugin().getPluginProperties().getDynValue("applySnappers"); |
||
80 | 43288 | fdiaz | |
81 | Preferences prefs = Preferences.userRoot().node("snappers"); |
||
82 | prefs.putBoolean("apply-snappers", applySnappers);
|
||
83 | |||
84 | 42037 | fdiaz | //TODO: si se a?ade al MapControlManager para habilitar/deshabilitar de manera global los snappers activos, invocarlo aqu?
|
85 | // mapControlManager.applySnappers(applySnappers);
|
||
86 | |||
87 | PropertiesPageManager manager = MapControlLocator.getPropertiesPageManager(); |
||
88 | manager.registerFactory(new ViewSnappingPropertiesPageFactory());
|
||
89 | |||
90 | } |
||
91 | |||
92 | 42501 | jjdelcerro | @Override
|
93 | public void postInitialize() { |
||
94 | 42508 | jjdelcerro | |
95 | 42037 | fdiaz | } |
96 | |||
97 | 42501 | jjdelcerro | private void registerIcons() { |
98 | 47426 | jjdelcerro | ToolsSwingUtils.registerIcons( |
99 | this.getClass(),
|
||
100 | "/images/action",
|
||
101 | this.getPlugin().getPluginName(),
|
||
102 | new String[] { "action", "enable-snapping","snapping" }, |
||
103 | new String[] { "action", "disable-snapping","snapping" } |
||
104 | ); |
||
105 | ToolsSwingUtils.registerIcons( |
||
106 | this.getClass(),
|
||
107 | "/images/preferences",
|
||
108 | this.getPlugin().getPluginName(),
|
||
109 | new String[] { "preferences", "preferences-snapper","snapping" }, |
||
110 | new String[] { "preferences", "grid-preferences","snapping" } |
||
111 | ); |
||
112 | |||
113 | 42501 | jjdelcerro | } |
114 | 42037 | fdiaz | |
115 | 42501 | jjdelcerro | public void execute(String actionCommand) { |
116 | } |
||
117 | 42037 | fdiaz | |
118 | 42501 | jjdelcerro | public boolean isEnabled() { |
119 | return true; |
||
120 | } |
||
121 | 42037 | fdiaz | |
122 | public boolean isVisible() { |
||
123 | |||
124 | 42501 | jjdelcerro | org.gvsig.andami.ui.mdiManager.IWindow f |
125 | = PluginServices.getMDIManager().getActiveWindow(); |
||
126 | 42037 | fdiaz | |
127 | if (f != null && f instanceof DefaultViewPanel) { |
||
128 | DefaultViewPanel vista = (DefaultViewPanel) f; |
||
129 | ViewDocument model = vista.getViewDocument(); |
||
130 | MapContext mapa = model.getMapContext(); |
||
131 | |||
132 | FLayers capas = mapa.getLayers(); |
||
133 | |||
134 | int numActiveVectorial = 0; |
||
135 | int numActiveVectorialEditable = 0; |
||
136 | |||
137 | LayersIterator iter = new LayersIterator(capas);
|
||
138 | |||
139 | FLayer capa; |
||
140 | while (iter.hasNext()) {
|
||
141 | capa = iter.nextLayer(); |
||
142 | if (capa instanceof FLyrVect && capa.isActive() |
||
143 | 42501 | jjdelcerro | && capa.isAvailable()) { |
144 | 42037 | fdiaz | numActiveVectorial++; |
145 | 42501 | jjdelcerro | if (capa.isEditing()) {
|
146 | 42037 | fdiaz | numActiveVectorialEditable++; |
147 | 42501 | jjdelcerro | } |
148 | 42037 | fdiaz | } |
149 | |||
150 | } |
||
151 | |||
152 | if (numActiveVectorialEditable == 1 && numActiveVectorial == 1) { |
||
153 | return true; |
||
154 | } |
||
155 | } |
||
156 | return false; |
||
157 | } |
||
158 | |||
159 | 42508 | jjdelcerro | @Override
|
160 | public IPreference[] getPreferencesPages() { |
||
161 | if( this.preferencePages == null ) { |
||
162 | this.preferencePages = new IPreference[] { |
||
163 | new SnapConfigPage(),
|
||
164 | new GridPage()
|
||
165 | }; |
||
166 | } |
||
167 | return this.preferencePages; |
||
168 | } |
||
169 | 42501 | jjdelcerro | } |