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