svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.editing.app / org.gvsig.editing.app.mainplugin / src / main / java / org / gvsig / editing / gui / preferences / EditionPreferencePage.java @ 40557
History | View | Annotate | Download (14.4 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.editing.gui.preferences; |
25 |
|
26 |
import java.awt.BorderLayout; |
27 |
import java.awt.Color; |
28 |
import java.awt.event.KeyEvent; |
29 |
import java.awt.event.KeyListener; |
30 |
import java.util.ArrayList; |
31 |
|
32 |
import javax.swing.ImageIcon; |
33 |
import javax.swing.JLabel; |
34 |
import javax.swing.JPanel; |
35 |
import javax.swing.JScrollPane; |
36 |
import javax.swing.JSeparator; |
37 |
import javax.swing.JTable; |
38 |
import javax.swing.JTextField; |
39 |
import javax.swing.border.EmptyBorder; |
40 |
import javax.swing.border.LineBorder; |
41 |
import javax.swing.table.AbstractTableModel; |
42 |
import javax.swing.table.TableModel; |
43 |
|
44 |
import org.gvsig.andami.PluginServices; |
45 |
import org.gvsig.andami.preferences.AbstractPreferencePage; |
46 |
import org.gvsig.andami.preferences.StoreException; |
47 |
import org.gvsig.editing.CADExtension; |
48 |
import org.gvsig.editing.EditionLocator; |
49 |
import org.gvsig.editing.IEditionManager; |
50 |
import org.gvsig.editing.layers.VectorialLayerEdited; |
51 |
import org.gvsig.fmap.mapcontext.MapContext; |
52 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
53 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
54 |
import org.gvsig.fmap.mapcontext.layers.SingleLayerIterator; |
55 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
56 |
import org.gvsig.fmap.mapcontrol.MapControlLocator; |
57 |
import org.gvsig.fmap.mapcontrol.MapControlManager; |
58 |
|
59 |
public class EditionPreferencePage extends AbstractPreferencePage { |
60 |
private JLabel jLabel = null; |
61 |
|
62 |
private JTextField jTxtTolerance = null; |
63 |
|
64 |
private JLabel jLabel1 = null; |
65 |
|
66 |
private JSeparator jSeparator = null; |
67 |
|
68 |
private JScrollPane jScrollPane = null; |
69 |
|
70 |
private JTable jTableSnapping = null; |
71 |
|
72 |
private JLabel jLabelCache = null; |
73 |
|
74 |
private JPanel jPanelNord = null; |
75 |
|
76 |
private JPanel jPanelCache = null; |
77 |
private boolean changed = false; |
78 |
|
79 |
private FLayers layers;
|
80 |
|
81 |
private MapContext mapContext;
|
82 |
|
83 |
private static MapControlManager mapControlManager = MapControlLocator.getMapControlManager(); |
84 |
|
85 |
private class MyRecord { |
86 |
public Boolean bSelec = new Boolean(false); |
87 |
|
88 |
public String layerName; |
89 |
|
90 |
public Integer maxFeat = new Integer(1000); |
91 |
} |
92 |
|
93 |
private class MyTableModel extends AbstractTableModel { |
94 |
private ArrayList records = new ArrayList(); |
95 |
|
96 |
public MyTableModel(FLayers layers) {
|
97 |
addLayer(layers); |
98 |
} |
99 |
|
100 |
private void addLayer(FLayer lyr) { |
101 |
if (lyr instanceof FLayers) { |
102 |
FLayers lyrGroup = (FLayers) lyr; |
103 |
for (int i = 0; i < lyrGroup.getLayersCount(); i++) { |
104 |
FLayer lyr2 = lyrGroup.getLayer(i); |
105 |
addLayer(lyr2); |
106 |
} |
107 |
} else {
|
108 |
if (lyr instanceof FLyrVect) { |
109 |
FLyrVect aux = (FLyrVect) lyr; |
110 |
MyRecord rec = new MyRecord();
|
111 |
rec.layerName = lyr.getName(); |
112 |
rec.bSelec = new Boolean(aux.isSpatialCacheEnabled()); |
113 |
rec.maxFeat = new Integer(aux.getSpatialCache() |
114 |
.getMaxFeatures()); |
115 |
records.add(rec); |
116 |
} |
117 |
} |
118 |
} |
119 |
|
120 |
public int getColumnCount() { |
121 |
return 3; |
122 |
} |
123 |
|
124 |
public int getRowCount() { |
125 |
return records.size();
|
126 |
} |
127 |
|
128 |
public Object getValueAt(int rowIndex, int columnIndex) { |
129 |
MyRecord rec = (MyRecord) records.get(rowIndex); |
130 |
if (columnIndex == 0) |
131 |
return rec.bSelec;
|
132 |
if (columnIndex == 1) |
133 |
return rec.layerName;
|
134 |
if (columnIndex == 2) |
135 |
return rec.maxFeat;
|
136 |
return null; |
137 |
|
138 |
} |
139 |
|
140 |
public Class getColumnClass(int c) { |
141 |
if (c == 0) |
142 |
return Boolean.class; |
143 |
if (c == 2) |
144 |
return Integer.class; |
145 |
return String.class; |
146 |
} |
147 |
|
148 |
public void setValueAt(Object aValue, int rowIndex, int columnIndex) { |
149 |
MyRecord rec = (MyRecord) records.get(rowIndex); |
150 |
if (columnIndex == 0) |
151 |
rec.bSelec = (Boolean) aValue;
|
152 |
if (columnIndex == 2) { |
153 |
if (aValue != null) |
154 |
rec.maxFeat = (Integer) aValue;
|
155 |
else
|
156 |
rec.maxFeat = new Integer(0); |
157 |
} |
158 |
changed =true;
|
159 |
super.setValueAt(aValue, rowIndex, columnIndex);
|
160 |
} |
161 |
|
162 |
public boolean isCellEditable(int rowIndex, int columnIndex) { |
163 |
if (columnIndex == 0) |
164 |
return true; |
165 |
if (columnIndex == 2) |
166 |
return true; |
167 |
|
168 |
return false; |
169 |
} |
170 |
|
171 |
public String getColumnName(int column) { |
172 |
if (column == 0) |
173 |
return PluginServices.getText(this, "Selected"); |
174 |
if (column == 1) |
175 |
return PluginServices.getText(this, "LayerName"); |
176 |
if (column == 2) |
177 |
return PluginServices.getText(this, "MaxFeaturesEditionCache"); |
178 |
return "You shouldn't reach this point"; |
179 |
|
180 |
} |
181 |
|
182 |
} |
183 |
|
184 |
/**
|
185 |
* This method initializes
|
186 |
*
|
187 |
*/
|
188 |
public EditionPreferencePage() {
|
189 |
super();
|
190 |
initialize(); |
191 |
} |
192 |
|
193 |
/*
|
194 |
* private void addLayer(FLayer lyr) { if (lyr instanceof FLayers) { FLayers
|
195 |
* lyrGroup = (FLayers) lyr; for (int i=0; i < lyrGroup.getLayersCount();
|
196 |
* i++) { FLayer lyr2 = lyrGroup.getLayer(i); addLayer(lyr2); } } else { if
|
197 |
* (lyr instanceof FLyrVect) { layers.add(lyr); } } }
|
198 |
*/
|
199 |
|
200 |
/**
|
201 |
* This method initializes this
|
202 |
*
|
203 |
*/
|
204 |
private void initialize() { |
205 |
BorderLayout layout = new BorderLayout(); |
206 |
layout.setHgap(20);
|
207 |
|
208 |
this.setLayout(layout);
|
209 |
|
210 |
jLabelCache = new JLabel(); |
211 |
jLabelCache |
212 |
.setText(PluginServices.getText(this, "capas_edition_cache")); |
213 |
jLabelCache.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT); |
214 |
jLabelCache.setPreferredSize(new java.awt.Dimension(500,20)); |
215 |
jLabelCache.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); |
216 |
jLabel1 = new JLabel(); |
217 |
jLabel1.setText("pixels");
|
218 |
jLabel1.setBounds(new java.awt.Rectangle(195, 8, 207, 15)); |
219 |
jLabel1.setPreferredSize(new java.awt.Dimension(28, 20)); |
220 |
jLabel1.setName("jLabel1");
|
221 |
jLabel = new JLabel(); |
222 |
jLabel.setText("Snap Tolerance:");
|
223 |
jLabel.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); |
224 |
jLabel.setName("jLabel");
|
225 |
jLabel.setBounds(new java.awt.Rectangle(15, 8, 122, 15)); |
226 |
jLabel.setPreferredSize(new java.awt.Dimension(28, 20)); |
227 |
jLabel.setHorizontalTextPosition(javax.swing.SwingConstants.LEFT); |
228 |
|
229 |
this.setSize(new java.awt.Dimension(502,288)); |
230 |
this.setPreferredSize(this.getSize()); |
231 |
this.add(getJPanelNord(), BorderLayout.NORTH); |
232 |
|
233 |
this.add(getJPanelCache(), BorderLayout.CENTER); |
234 |
|
235 |
} |
236 |
|
237 |
public String getID() { |
238 |
return this.getClass().getName(); |
239 |
} |
240 |
|
241 |
public String getTitle() { |
242 |
return PluginServices.getText(this, "Edition"); |
243 |
} |
244 |
|
245 |
public JPanel getPanel() { |
246 |
return this; |
247 |
} |
248 |
|
249 |
/*
|
250 |
* (non-Javadoc)
|
251 |
*
|
252 |
* @see com.iver.cit.gvsig.gui.preferences.IPreference#initializeValues()
|
253 |
*/
|
254 |
public void initializeValues() { |
255 |
TableModel tm = getJTableSnapping().getModel();
|
256 |
IEditionManager edManager = EditionLocator.getEditionManager(); |
257 |
FLayer layerActive=layers.getActives()[0];
|
258 |
VectorialLayerEdited lyrEd = (VectorialLayerEdited) edManager |
259 |
.getLayerEdited(layerActive); |
260 |
ArrayList layersToSnap = layerActive.getMapContext().getLayersToSnap();
|
261 |
ArrayList layersVect=new ArrayList(); |
262 |
for (int i = 0; i < layers.getLayersCount(); i++) { |
263 |
FLayer layer=layers.getLayer(i); |
264 |
if (layer instanceof FLyrVect) { |
265 |
layersVect.add(layer); |
266 |
} |
267 |
} |
268 |
for (int i = 0; i < layersVect.size(); i++) { |
269 |
FLyrVect lv=(FLyrVect)layersVect.get(i); |
270 |
tm.setValueAt(lv.getName(), i, 1);
|
271 |
tm.setValueAt(layersToSnap.contains(lv), i, 0);
|
272 |
tm.setValueAt(lv.getSpatialCache().getMaxFeatures(), i, 2);
|
273 |
} |
274 |
} |
275 |
|
276 |
public void storeValues() throws StoreException { |
277 |
TableModel tm = getJTableSnapping().getModel();
|
278 |
ArrayList layersToSnap = new ArrayList(); |
279 |
for (int i = 0; i < tm.getRowCount(); i++) { |
280 |
String layerName = (String) tm.getValueAt(i, 1); |
281 |
FLyrVect lyr = (FLyrVect) layers.getLayer(layerName); |
282 |
Boolean bUseCache = (Boolean) tm.getValueAt(i, 0); |
283 |
Integer maxFeat = (Integer) tm.getValueAt(i, 2); |
284 |
|
285 |
// Decidimos si vamos a habilitar el spatialCache DESPUES, justo
|
286 |
// antes de renderizar.
|
287 |
// Necesitamos un m?todo que explore las capas en edici?n y mire las
|
288 |
// capas sobre las
|
289 |
// que se necestia el cache. Aqu? lo que hacemos es a?adir las
|
290 |
// seleccionadas a la
|
291 |
// lista de capas asociadas al snapping de los temas activos en
|
292 |
// edici?n.
|
293 |
// Lo del m?ximo de features en cach?, tiene que ser para cada capa
|
294 |
// distinto. Pero no
|
295 |
// puedes "chafar" el que ya hay, porque puedes fastidiar a otra
|
296 |
// capa en edici?n.
|
297 |
// Como m?ximo, lo que podemos hacer es que si es mayor al que hay,
|
298 |
// lo subimos. Si
|
299 |
// se solicita uno menor, lo dejamos como est?.
|
300 |
// Otra opci?n ser?a no hacer caso de esto para cada capa, y ponerlo
|
301 |
// de forma global.
|
302 |
// lyr.setSpatialCacheEnabled(bUseCache.booleanValue());
|
303 |
lyr.setMaxFeaturesInEditionCache(maxFeat.intValue()); |
304 |
if (bUseCache.booleanValue())
|
305 |
layersToSnap.add(lyr); |
306 |
} |
307 |
SingleLayerIterator it = new SingleLayerIterator(layers);
|
308 |
|
309 |
while (it.hasNext()) {
|
310 |
FLayer aux = it.next(); |
311 |
if (aux instanceof FLyrVect) |
312 |
{ |
313 |
FLyrVect lyrVect = (FLyrVect) aux; |
314 |
// Inicializamos todas
|
315 |
lyrVect.setSpatialCacheEnabled(false);
|
316 |
if (aux.isActive())
|
317 |
if (aux.isEditing()) {
|
318 |
// Sobre la capa en edici?n siempre se puede hacer snapping
|
319 |
lyrVect.setSpatialCacheEnabled(true);
|
320 |
lyrVect.getMapContext().setLayersToSnap(layersToSnap); |
321 |
// VectorialLayerEdited lyrEd = (VectorialLayerEdited) edManager
|
322 |
// .getLayerEdited(aux);
|
323 |
// lyrEd.setLayersToSnap(layersToSnap);
|
324 |
|
325 |
} |
326 |
} |
327 |
} // while
|
328 |
it.rewind(); |
329 |
/*
|
330 |
* Iteramos por las capas en edici?n y marcamos aquellas capas que
|
331 |
* necesitan trabajar con el cache habilitado
|
332 |
*/
|
333 |
while (it.hasNext()) {
|
334 |
FLayer aux = it.next(); |
335 |
if (aux.isEditing())
|
336 |
if (aux instanceof FLyrVect) { |
337 |
MapContext mx=aux.getMapContext(); |
338 |
// VectorialLayerEdited lyrEd = (VectorialLayerEdited) edManager
|
339 |
// .getLayerEdited(aux);
|
340 |
for (int i=0; i<mx.getLayersToSnap().size(); i++) |
341 |
{ |
342 |
FLyrVect lyrVect = (FLyrVect) mx.getLayersToSnap().get(i); |
343 |
lyrVect.setSpatialCacheEnabled(true);
|
344 |
} |
345 |
|
346 |
} |
347 |
|
348 |
} // while
|
349 |
mapContext.invalidate(); |
350 |
try{
|
351 |
mapControlManager.setTolerance(Integer.parseInt(getJTxtTolerance().getText()));
|
352 |
|
353 |
}catch (Exception e) { |
354 |
throw new StoreException(PluginServices.getText(this, "tolerancia_incorrecta"),e); |
355 |
} |
356 |
} |
357 |
|
358 |
public void initializeDefaults() { |
359 |
getJTxtTolerance().setText("4");
|
360 |
TableModel tm = getJTableSnapping().getModel();
|
361 |
for (int i = 0; i < tm.getRowCount(); i++) { |
362 |
String layerName = (String) tm.getValueAt(i, 1); |
363 |
FLyrVect lyr = (FLyrVect) layers.getLayer(layerName); |
364 |
Boolean bUseCache = (Boolean) tm.getValueAt(i, 0); |
365 |
Integer maxFeat = (Integer) tm.getValueAt(i, 2); |
366 |
lyr.setSpatialCacheEnabled(bUseCache.booleanValue()); |
367 |
lyr.setMaxFeaturesInEditionCache(maxFeat.intValue()); |
368 |
} |
369 |
|
370 |
} |
371 |
|
372 |
public ImageIcon getIcon() { |
373 |
return null; |
374 |
} |
375 |
|
376 |
public void setMapContext(MapContext mc) { |
377 |
// addLayer(layers);
|
378 |
this.mapContext = mc;
|
379 |
this.layers = mc.getLayers();
|
380 |
MyTableModel tm = new MyTableModel(layers);
|
381 |
getJTableSnapping().setModel(tm); |
382 |
getJTxtTolerance().setText(String.valueOf(mapControlManager.getTolerance()));
|
383 |
} |
384 |
|
385 |
/**
|
386 |
* This method initializes jTxtTolerance
|
387 |
*
|
388 |
* @return javax.swing.JTextField
|
389 |
*/
|
390 |
private JTextField getJTxtTolerance() { |
391 |
if (jTxtTolerance == null) { |
392 |
jTxtTolerance = new JTextField(); |
393 |
jTxtTolerance.setPreferredSize(new java.awt.Dimension(28, 20)); |
394 |
jTxtTolerance.setName("jTxtTolerance");
|
395 |
jTxtTolerance.setHorizontalAlignment(javax.swing.JTextField.RIGHT); |
396 |
jTxtTolerance.setText("4");
|
397 |
jTxtTolerance.setBounds(new java.awt.Rectangle(142, 8, 39, 15)); |
398 |
jTxtTolerance.addKeyListener(new KeyListener() { |
399 |
public void keyPressed(KeyEvent e) { changed = true; } |
400 |
public void keyReleased(KeyEvent e) { changed = true; } |
401 |
public void keyTyped(KeyEvent e){ changed = true; } |
402 |
}); |
403 |
} |
404 |
return jTxtTolerance;
|
405 |
} |
406 |
|
407 |
/**
|
408 |
* This method initializes jSeparator
|
409 |
*
|
410 |
* @return javax.swing.JSeparator
|
411 |
*/
|
412 |
private JSeparator getJSeparator() { |
413 |
if (jSeparator == null) { |
414 |
jSeparator = new JSeparator(); |
415 |
jSeparator.setPreferredSize(new java.awt.Dimension(200,2)); |
416 |
} |
417 |
return jSeparator;
|
418 |
} |
419 |
|
420 |
/**
|
421 |
* This method initializes jScrollPane
|
422 |
*
|
423 |
* @return javax.swing.JScrollPane
|
424 |
*/
|
425 |
private JScrollPane getJScrollPane() { |
426 |
if (jScrollPane == null) { |
427 |
jScrollPane = new JScrollPane(); |
428 |
jScrollPane.setBorder(new LineBorder(Color.GRAY)); |
429 |
jScrollPane.setPreferredSize(new java.awt.Dimension(500,419)); |
430 |
jScrollPane.setViewportView(getJTableSnapping()); |
431 |
} |
432 |
return jScrollPane;
|
433 |
} |
434 |
|
435 |
/**
|
436 |
* This method initializes jTableSnapping
|
437 |
*
|
438 |
* @return javax.swing.JTable
|
439 |
*/
|
440 |
private JTable getJTableSnapping() { |
441 |
if (jTableSnapping == null) { |
442 |
jTableSnapping = new JTable(); |
443 |
jTableSnapping.addKeyListener(new KeyListener() { |
444 |
public void keyPressed(KeyEvent e) { changed = true; } |
445 |
public void keyReleased(KeyEvent e) { changed = true; } |
446 |
public void keyTyped(KeyEvent e){ changed = true; } |
447 |
}); |
448 |
} |
449 |
return jTableSnapping;
|
450 |
} |
451 |
|
452 |
/**
|
453 |
* This method initializes jPanelNord
|
454 |
*
|
455 |
* @return javax.swing.JPanel
|
456 |
*/
|
457 |
private JPanel getJPanelNord() { |
458 |
if (jPanelNord == null) { |
459 |
jPanelNord = new JPanel(); |
460 |
jPanelNord.setLayout(null);
|
461 |
jPanelNord |
462 |
.setComponentOrientation(java.awt.ComponentOrientation.UNKNOWN); |
463 |
jPanelNord.setPreferredSize(new java.awt.Dimension(30, 30)); |
464 |
jPanelNord.add(jLabel, null);
|
465 |
jPanelNord.add(getJTxtTolerance(), null);
|
466 |
jPanelNord.add(jLabel1, null);
|
467 |
|
468 |
} |
469 |
return jPanelNord;
|
470 |
} |
471 |
|
472 |
/**
|
473 |
* This method initializes jPanelCache
|
474 |
*
|
475 |
* @return javax.swing.JPanel
|
476 |
*/
|
477 |
private JPanel getJPanelCache() { |
478 |
if (jPanelCache == null) { |
479 |
jPanelCache = new JPanel(); |
480 |
jPanelCache.setLayout(new BorderLayout()); |
481 |
jPanelCache.setBorder(new EmptyBorder(10, 10, 10, 10)); |
482 |
jPanelCache.add(jLabelCache, java.awt.BorderLayout.NORTH); |
483 |
jPanelCache.add(getJScrollPane(), java.awt.BorderLayout.CENTER); |
484 |
} |
485 |
return jPanelCache;
|
486 |
} |
487 |
|
488 |
public boolean isValueChanged() { |
489 |
return changed;
|
490 |
} |
491 |
|
492 |
public void setChangesApplied() { |
493 |
changed = false;
|
494 |
} |
495 |
|
496 |
/*
|
497 |
* non-Javadoc)
|
498 |
* @see org.gvsig.andami.preferences.AbstractPreferencePage#isResizeable()
|
499 |
*/
|
500 |
public boolean isResizeable() { |
501 |
return true; |
502 |
} |
503 |
} // @jve:decl-index=0:visual-constraint="14,10"
|
504 |
|