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 @ 43288
History | View | Annotate | Download (5.83 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 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 |
*
|
11 |
* 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 |
*
|
16 |
* 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 |
*
|
20 |
* For any additional information, do not hesitate to contact us at info AT
|
21 |
* gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.app.extension; |
24 |
|
25 |
import java.util.prefs.Preferences; |
26 |
|
27 |
import org.gvsig.andami.IconThemeHelper; |
28 |
import org.gvsig.andami.PluginServices; |
29 |
import org.gvsig.andami.plugins.Extension; |
30 |
import org.gvsig.andami.preferences.IPreference; |
31 |
import org.gvsig.andami.preferences.IPreferenceExtension; |
32 |
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 |
|
48 |
|
49 |
/**
|
50 |
* Extension for config the snapping
|
51 |
*
|
52 |
* @author fdiaz
|
53 |
*
|
54 |
*/
|
55 |
public class SnappingExtension extends Extension implements IPreferenceExtension { |
56 |
|
57 |
private IPreference[] preferencePages = null; |
58 |
|
59 |
public void initialize() { |
60 |
Snapping.register(); |
61 |
|
62 |
registerIcons(); |
63 |
|
64 |
MapControlManager mapControlManager = MapControlLocator.getMapControlManager(); |
65 |
for (int n = 0; n < mapControlManager.getSnapperCount(); n++) { |
66 |
ISnapper snp = (ISnapper) mapControlManager.getSnapperAt(n); |
67 |
String nameClass = snp.getClass().getName();
|
68 |
nameClass = nameClass.substring(nameClass.lastIndexOf('.') + 1); |
69 |
snp.setEnabled((Boolean) getPlugin().getPluginProperties().getDynValue("snapperActivated" + nameClass)); |
70 |
snp.setPriority((Integer) getPlugin().getPluginProperties().getDynValue("snapperPriority" + nameClass)); |
71 |
} |
72 |
|
73 |
Integer snapTolerance
|
74 |
= (Integer) getPlugin().getPluginProperties().getDynValue("snapTolerance"); |
75 |
mapControlManager.setTolerance(snapTolerance.intValue()); |
76 |
|
77 |
Boolean applySnappers
|
78 |
= (Boolean) getPlugin().getPluginProperties().getDynValue("applySnappers"); |
79 |
|
80 |
Preferences prefs = Preferences.userRoot().node("snappers"); |
81 |
prefs.putBoolean("apply-snappers", applySnappers);
|
82 |
|
83 |
//TODO: si se a?ade al MapControlManager para habilitar/deshabilitar de manera global los snappers activos, invocarlo aqu?
|
84 |
// mapControlManager.applySnappers(applySnappers);
|
85 |
|
86 |
PropertiesPageManager manager = MapControlLocator.getPropertiesPageManager(); |
87 |
manager.registerFactory(new ViewSnappingPropertiesPageFactory());
|
88 |
|
89 |
} |
90 |
|
91 |
@Override
|
92 |
public void postInitialize() { |
93 |
|
94 |
} |
95 |
|
96 |
private void registerIcons() { |
97 |
IconThemeHelper.registerIcon("preferences", "preferences-snapper", this); |
98 |
IconThemeHelper.registerIcon("preferences", "grid-preferences", this); |
99 |
IconThemeHelper.registerIcon("actions", "enable-snapping", this); |
100 |
IconThemeHelper.registerIcon("actions", "disable-snapping", this); |
101 |
} |
102 |
|
103 |
public void execute(String actionCommand) { |
104 |
} |
105 |
|
106 |
public boolean isEnabled() { |
107 |
return true; |
108 |
} |
109 |
|
110 |
public boolean isVisible() { |
111 |
|
112 |
org.gvsig.andami.ui.mdiManager.IWindow f |
113 |
= PluginServices.getMDIManager().getActiveWindow(); |
114 |
|
115 |
if (f != null && f instanceof DefaultViewPanel) { |
116 |
DefaultViewPanel vista = (DefaultViewPanel) f; |
117 |
ViewDocument model = vista.getViewDocument(); |
118 |
MapContext mapa = model.getMapContext(); |
119 |
|
120 |
FLayers capas = mapa.getLayers(); |
121 |
|
122 |
int numActiveVectorial = 0; |
123 |
int numActiveVectorialEditable = 0; |
124 |
|
125 |
LayersIterator iter = new LayersIterator(capas);
|
126 |
|
127 |
FLayer capa; |
128 |
while (iter.hasNext()) {
|
129 |
capa = iter.nextLayer(); |
130 |
if (capa instanceof FLyrVect && capa.isActive() |
131 |
&& capa.isAvailable()) { |
132 |
numActiveVectorial++; |
133 |
if (capa.isEditing()) {
|
134 |
numActiveVectorialEditable++; |
135 |
} |
136 |
} |
137 |
|
138 |
} |
139 |
|
140 |
if (numActiveVectorialEditable == 1 && numActiveVectorial == 1) { |
141 |
return true; |
142 |
} |
143 |
} |
144 |
return false; |
145 |
} |
146 |
|
147 |
@Override
|
148 |
public IPreference[] getPreferencesPages() { |
149 |
if( this.preferencePages == null ) { |
150 |
this.preferencePages = new IPreference[] { |
151 |
new SnapConfigPage(),
|
152 |
new GridPage()
|
153 |
}; |
154 |
} |
155 |
return this.preferencePages; |
156 |
} |
157 |
} |