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 / gui / preferencespage / SnapConfigPage.java @ 43288
History | View | Annotate | Download (9.02 KB)
1 | 42037 | fdiaz | /**
|
---|---|---|---|
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.gui.preferencespage; |
||
25 | |||
26 | import java.awt.BorderLayout; |
||
27 | import java.awt.event.KeyEvent; |
||
28 | import java.awt.event.KeyListener; |
||
29 | import java.awt.event.MouseEvent; |
||
30 | import java.awt.event.MouseListener; |
||
31 | 43288 | fdiaz | import java.util.prefs.Preferences; |
32 | 42037 | fdiaz | |
33 | import javax.swing.ImageIcon; |
||
34 | import javax.swing.JPanel; |
||
35 | |||
36 | import org.slf4j.Logger; |
||
37 | import org.slf4j.LoggerFactory; |
||
38 | |||
39 | import org.gvsig.andami.IconThemeHelper; |
||
40 | import org.gvsig.andami.PluginServices; |
||
41 | import org.gvsig.andami.PluginsLocator; |
||
42 | import org.gvsig.andami.PluginsManager; |
||
43 | import org.gvsig.andami.preferences.AbstractPreferencePage; |
||
44 | import org.gvsig.andami.preferences.StoreException; |
||
45 | import org.gvsig.app.project.documents.view.toolListeners.snapping.gui.SnapConfig; |
||
46 | import org.gvsig.fmap.mapcontrol.MapControlLocator; |
||
47 | import org.gvsig.fmap.mapcontrol.MapControlManager; |
||
48 | import org.gvsig.fmap.mapcontrol.tools.snapping.snappers.ISnapper; |
||
49 | import org.gvsig.tools.ToolsLocator; |
||
50 | import org.gvsig.tools.dynobject.DynObject; |
||
51 | import org.gvsig.tools.dynobject.exception.DynFieldNotFoundException; |
||
52 | import org.gvsig.tools.i18n.I18nManager; |
||
53 | |||
54 | |||
55 | |||
56 | |||
57 | /**
|
||
58 | * Preferencias de snapping.
|
||
59 | *
|
||
60 | * @author Vicente Caballero Navarro
|
||
61 | */
|
||
62 | public class SnapConfigPage extends AbstractPreferencePage { |
||
63 | /**
|
||
64 | *
|
||
65 | */
|
||
66 | private static final long serialVersionUID = -3288863201776046550L; |
||
67 | |||
68 | private static final Logger logger = LoggerFactory.getLogger(SnapConfigPage.class); |
||
69 | |||
70 | public static final String ID = SnapConfigPage.class.getName(); |
||
71 | |||
72 | |||
73 | private SnapConfig snapConfig;
|
||
74 | private static boolean applySnappers=true; |
||
75 | private static MapControlManager mapControlManager = MapControlLocator.getMapControlManager(); |
||
76 | |||
77 | private DynObject pluginProperties;
|
||
78 | private PluginServices plugin;
|
||
79 | |||
80 | public SnapConfigPage() {
|
||
81 | // super();
|
||
82 | PluginsManager pluginManager = PluginsLocator.getManager(); |
||
83 | this.plugin = pluginManager.getPlugin(this); |
||
84 | this.pluginProperties = this.plugin.getPluginProperties(); |
||
85 | |||
86 | this.snapConfig = new SnapConfig(new MouseListener() { |
||
87 | public void mouseReleased(MouseEvent e) { |
||
88 | } |
||
89 | public void mousePressed(MouseEvent e) { |
||
90 | setChanged(true);
|
||
91 | } |
||
92 | public void mouseExited(MouseEvent e) { |
||
93 | } |
||
94 | public void mouseEntered(MouseEvent e) { |
||
95 | } |
||
96 | public void mouseClicked(MouseEvent e) { |
||
97 | } |
||
98 | }, new KeyListener() { |
||
99 | public void keyTyped(KeyEvent e) { |
||
100 | setChanged(true);
|
||
101 | } |
||
102 | public void keyReleased(KeyEvent e) { |
||
103 | setChanged(true);
|
||
104 | } |
||
105 | public void keyPressed(KeyEvent e) { |
||
106 | setChanged(true);
|
||
107 | } |
||
108 | }); |
||
109 | |||
110 | this.setLayout(new BorderLayout()); |
||
111 | this.add(this.snapConfig, BorderLayout.NORTH); |
||
112 | this.snapConfig.setSnappers();
|
||
113 | initializeValues(); |
||
114 | } |
||
115 | |||
116 | |||
117 | |||
118 | /**
|
||
119 | * DOCUMENT ME!
|
||
120 | *
|
||
121 | * @throws StoreException DOCUMENT ME!
|
||
122 | */
|
||
123 | public void storeValues() throws StoreException { |
||
124 | for (int n = 0; n < mapControlManager.getSnapperCount(); n++) { |
||
125 | Boolean b = (Boolean) snapConfig.getTableModel().getValueAt(n, 0); |
||
126 | ISnapper snp = (ISnapper) mapControlManager.getSnapperAt(n); |
||
127 | String nameClass=snp.getClass().getName();
|
||
128 | nameClass=nameClass.substring(nameClass.lastIndexOf('.')+1); |
||
129 | this.pluginProperties.setDynValue("snapperActivated" + nameClass, b.booleanValue()); |
||
130 | |||
131 | if (b.booleanValue()){
|
||
132 | snp.setEnabled(b); |
||
133 | } |
||
134 | this.pluginProperties.setDynValue("snapperPriority" + nameClass, snp.getPriority()); |
||
135 | } |
||
136 | Boolean b = (Boolean)snapConfig.applySnappers(); |
||
137 | this.pluginProperties.setDynValue("applySnappers", b.booleanValue()); |
||
138 | applySnappers=b; |
||
139 | |||
140 | 43288 | fdiaz | Preferences prefs = Preferences.userRoot().node("snappers"); |
141 | prefs.putBoolean("apply-snappers", applySnappers);
|
||
142 | |||
143 | 42037 | fdiaz | Integer snapTolerance = snapConfig.getSnapTolerance();
|
144 | this.pluginProperties.setDynValue("snapTolerance", snapTolerance.intValue()); |
||
145 | mapControlManager.setTolerance(snapTolerance); |
||
146 | |||
147 | this.plugin.savePluginProperties();
|
||
148 | } |
||
149 | |||
150 | /**
|
||
151 | * DOCUMENT ME!
|
||
152 | */
|
||
153 | public void setChangesApplied() { |
||
154 | setChanged(false);
|
||
155 | } |
||
156 | |||
157 | /**
|
||
158 | * DOCUMENT ME!
|
||
159 | *
|
||
160 | * @return DOCUMENT ME!
|
||
161 | */
|
||
162 | public String getID() { |
||
163 | return ID;
|
||
164 | } |
||
165 | |||
166 | /**
|
||
167 | * DOCUMENT ME!
|
||
168 | *
|
||
169 | * @return DOCUMENT ME!
|
||
170 | */
|
||
171 | public String getTitle() { |
||
172 | I18nManager i18nManager = ToolsLocator.getI18nManager(); |
||
173 | return i18nManager.getTranslation("Snapping"); |
||
174 | } |
||
175 | |||
176 | /**
|
||
177 | * DOCUMENT ME!
|
||
178 | *
|
||
179 | * @return DOCUMENT ME!
|
||
180 | */
|
||
181 | public JPanel getPanel() { |
||
182 | return this; |
||
183 | } |
||
184 | |||
185 | /**
|
||
186 | * DOCUMENT ME!
|
||
187 | */
|
||
188 | public void initializeValues() { |
||
189 | try {
|
||
190 | 43288 | fdiaz | applySnappers = (Boolean) pluginProperties.getDynValue("applySnappers"); |
191 | 42037 | fdiaz | } catch (DynFieldNotFoundException e){
|
192 | initializeDefaults(); |
||
193 | } |
||
194 | |||
195 | snapConfig.setApplySnappers(applySnappers); |
||
196 | |||
197 | for (int n = 0; n < mapControlManager.getSnapperCount(); n++) { |
||
198 | // Boolean b = (Boolean) snapConfig.getTableModel().getValueAt(n, 0);
|
||
199 | ISnapper snp = (ISnapper) mapControlManager.getSnapperAt(n); |
||
200 | String nameClass = snp.getClass().getName();
|
||
201 | nameClass = nameClass.substring(nameClass.lastIndexOf('.')+1); |
||
202 | Boolean active = (Boolean) pluginProperties.getDynValue("snapperActivated"+nameClass); |
||
203 | snapConfig.getTableModel().setValueAt(active.booleanValue(),n,0);
|
||
204 | Integer prior = (Integer) pluginProperties.getDynValue("snapperPriority"+nameClass); |
||
205 | snapConfig.getTableModel().setValueAt(prior, n, 3);
|
||
206 | } |
||
207 | Integer snapTolerance = (Integer) pluginProperties.getDynValue("snapTolerance"); |
||
208 | snapConfig.setSnapTolerance(snapTolerance); |
||
209 | |||
210 | } |
||
211 | |||
212 | /**
|
||
213 | * DOCUMENT ME!
|
||
214 | */
|
||
215 | public void initializeDefaults() { |
||
216 | for (int n = 0; n < mapControlManager.getSnapperCount(); n++) { |
||
217 | ISnapper snp = mapControlManager.getSnapperAt(n); |
||
218 | String nameClass=snp.getClass().getName();
|
||
219 | nameClass=nameClass.substring(nameClass.lastIndexOf('.')+1); |
||
220 | if (nameClass.equals(".FinalPointSnapper")){ |
||
221 | int priority = 1; |
||
222 | //FIXME: ?Por qu? hay que a?adir esta l?nea?
|
||
223 | // this.pluginProperties.setDynValue("snapperPriority" + nameClass, priority);
|
||
224 | snp.setEnabled(true);
|
||
225 | snp.setPriority(priority); |
||
226 | }else if (nameClass.equals(".NearestPointSnapper")){ |
||
227 | int priority = 2; |
||
228 | //FIXME: ?Por qu? hay que a?adir esta l?nea?
|
||
229 | // this.pluginProperties.setDynValue("snapperPriority" + nameClass, priority);
|
||
230 | snp.setEnabled(true);
|
||
231 | snp.setPriority(priority); |
||
232 | }else{
|
||
233 | int priority = 3; |
||
234 | //FIXME: ?Por qu? hay que a?adir esta l?nea?
|
||
235 | // this.pluginProperties.setDynValue("snapperPriority" + nameClass, priority);
|
||
236 | snp.setEnabled(false);
|
||
237 | snp.setPriority(priority); |
||
238 | } |
||
239 | } |
||
240 | applySnappers = true;
|
||
241 | snapConfig.setApplySnappers(applySnappers); |
||
242 | snapConfig.selectSnappers(); |
||
243 | |||
244 | this.pluginProperties.setDynValue("snapTolerance", 4); |
||
245 | snapConfig.setSnapTolerance(4);
|
||
246 | } |
||
247 | |||
248 | /**
|
||
249 | * DOCUMENT ME!
|
||
250 | *
|
||
251 | * @return DOCUMENT ME!
|
||
252 | */
|
||
253 | public ImageIcon getIcon() { |
||
254 | return IconThemeHelper.getImageIcon("preferences-snapper"); |
||
255 | } |
||
256 | |||
257 | /**
|
||
258 | * DOCUMENT ME!
|
||
259 | *
|
||
260 | * @return DOCUMENT ME!
|
||
261 | */
|
||
262 | public boolean isValueChanged() { |
||
263 | return super.hasChanged(); |
||
264 | } |
||
265 | |||
266 | /*
|
||
267 | * (non-Javadoc)
|
||
268 | * @see org.gvsig.andami.preferences.AbstractPreferencePage#isResizeable()
|
||
269 | */
|
||
270 | public boolean isResizeable() { |
||
271 | return true; |
||
272 | } |
||
273 | |||
274 | |||
275 | |||
276 | } |