svn-gvsig-desktop / trunk / extensions / extCAD / src / com / iver / cit / gvsig / gui / preferences / EditionPreferencePage.java @ 10254
History | View | Annotate | Download (15 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.gui.preferences; |
42 |
|
43 |
import java.awt.BorderLayout; |
44 |
import java.awt.event.KeyEvent; |
45 |
import java.awt.event.KeyListener; |
46 |
import java.util.ArrayList; |
47 |
|
48 |
import javax.swing.ImageIcon; |
49 |
import javax.swing.JLabel; |
50 |
import javax.swing.JPanel; |
51 |
import javax.swing.JScrollPane; |
52 |
import javax.swing.JSeparator; |
53 |
import javax.swing.JTable; |
54 |
import javax.swing.JTextField; |
55 |
import javax.swing.table.AbstractTableModel; |
56 |
import javax.swing.table.TableModel; |
57 |
|
58 |
import com.iver.andami.PluginServices; |
59 |
import com.iver.andami.preferences.AbstractPreferencePage; |
60 |
import com.iver.andami.preferences.StoreException; |
61 |
import com.iver.cit.gvsig.CADExtension; |
62 |
import com.iver.cit.gvsig.EditionManager; |
63 |
import com.iver.cit.gvsig.fmap.MapContext; |
64 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
65 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
66 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
67 |
import com.iver.cit.gvsig.fmap.layers.SingleLayerIterator; |
68 |
import com.iver.cit.gvsig.gui.cad.tools.SelectionCADTool; |
69 |
import com.iver.cit.gvsig.layers.VectorialLayerEdited; |
70 |
|
71 |
public class EditionPreferencePage extends AbstractPreferencePage { |
72 |
private JLabel jLabel = null; |
73 |
|
74 |
private JTextField jTxtTolerance = null; |
75 |
|
76 |
private JLabel jLabel1 = null; |
77 |
|
78 |
private JSeparator jSeparator = null; |
79 |
|
80 |
private JScrollPane jScrollPane = null; |
81 |
|
82 |
private JTable jTableSnapping = null; |
83 |
|
84 |
private JLabel jLabelCache = null; |
85 |
|
86 |
private JPanel jPanelNord = null; |
87 |
|
88 |
private JPanel jPanelCache = null; |
89 |
private boolean changed = false; |
90 |
|
91 |
private FLayers layers;
|
92 |
|
93 |
private MapContext mapContext;
|
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(getJSeparator(), BorderLayout.CENTER); |
244 |
|
245 |
this.add(getJPanelCache(), BorderLayout.CENTER); |
246 |
|
247 |
} |
248 |
|
249 |
public String getID() { |
250 |
return this.getClass().getName(); |
251 |
} |
252 |
|
253 |
public String getTitle() { |
254 |
return PluginServices.getText(this, "Edition"); |
255 |
} |
256 |
|
257 |
public JPanel getPanel() { |
258 |
return this; |
259 |
} |
260 |
|
261 |
/*
|
262 |
* (non-Javadoc)
|
263 |
*
|
264 |
* @see com.iver.cit.gvsig.gui.preferences.IPreference#initializeValues()
|
265 |
*/
|
266 |
public void initializeValues() { |
267 |
// /* Vamos a usar esto por ahora as?:
|
268 |
// * Al abrir el dialogo, miramos las capas que hay
|
269 |
// * en edici?n y las capas activas.
|
270 |
// * Las capas en edici?n nos las guardamos para
|
271 |
// * fijarles las propiedades, y las que est?n activas
|
272 |
// * las metemos en la tabla de configuraci?n de
|
273 |
// * snapping.
|
274 |
// */
|
275 |
// FLyrVect firstLyrVect = null;
|
276 |
// for (int i=0; i<layers.getLayersCount(); i++)
|
277 |
// {
|
278 |
// FLayer aux = layers.getLayer(i);
|
279 |
// if (aux.isActive())
|
280 |
// if (aux instanceof FLyrVect)
|
281 |
// {
|
282 |
// firstLyrVect = (FLyrVect) aux;
|
283 |
// }
|
284 |
// }
|
285 |
//
|
286 |
// TableModel tm = getJTableSnapping().getModel();
|
287 |
// for (int i=0; i < tm.getRowCount(); i++)
|
288 |
// {
|
289 |
// String layerName = (String) tm.getValueAt(i, 1);
|
290 |
// FLayer layer = layers.getLayer(layerName);
|
291 |
// FLyrVect lyr = (FLyrVect) layers.getLayer(layerName);
|
292 |
// Boolean bUseCache = (Boolean) tm.getValueAt(i,0);
|
293 |
// Integer maxFeat = (Integer) tm.getValueAt(i,2);
|
294 |
// lyr.setSpatialCacheEnabled(bUseCache.booleanValue());
|
295 |
// lyr.setMaxFeaturesInEditionCache(maxFeat.intValue());
|
296 |
// }
|
297 |
//
|
298 |
|
299 |
} |
300 |
|
301 |
public void storeValues() throws StoreException { |
302 |
TableModel tm = getJTableSnapping().getModel();
|
303 |
ArrayList layersToSnap = new ArrayList(); |
304 |
for (int i = 0; i < tm.getRowCount(); i++) { |
305 |
String layerName = (String) tm.getValueAt(i, 1); |
306 |
FLyrVect lyr = (FLyrVect) layers.getLayer(layerName); |
307 |
Boolean bUseCache = (Boolean) tm.getValueAt(i, 0); |
308 |
Integer maxFeat = (Integer) tm.getValueAt(i, 2); |
309 |
|
310 |
// Decidimos si vamos a habilitar el spatialCache DESPUES, justo
|
311 |
// antes de renderizar.
|
312 |
// Necesitamos un m?todo que explore las capas en edici?n y mire las
|
313 |
// capas sobre las
|
314 |
// que se necestia el cache. Aqu? lo que hacemos es a?adir las
|
315 |
// seleccionadas a la
|
316 |
// lista de capas asociadas al snapping de los temas activos en
|
317 |
// edici?n.
|
318 |
// Lo del m?ximo de features en cach?, tiene que ser para cada capa
|
319 |
// distinto. Pero no
|
320 |
// puedes "chafar" el que ya hay, porque puedes fastidiar a otra
|
321 |
// capa en edici?n.
|
322 |
// Como m?ximo, lo que podemos hacer es que si es mayor al que hay,
|
323 |
// lo subimos. Si
|
324 |
// se solicita uno menor, lo dejamos como est?.
|
325 |
// Otra opci?n ser?a no hacer caso de esto para cada capa, y ponerlo
|
326 |
// de forma global.
|
327 |
// lyr.setSpatialCacheEnabled(bUseCache.booleanValue());
|
328 |
lyr.setMaxFeaturesInEditionCache(maxFeat.intValue()); |
329 |
if (bUseCache.booleanValue())
|
330 |
layersToSnap.add(lyr); |
331 |
} |
332 |
SingleLayerIterator it = new SingleLayerIterator(layers);
|
333 |
EditionManager edManager = CADExtension.getEditionManager(); |
334 |
|
335 |
while (it.hasNext()) {
|
336 |
FLayer aux = it.next(); |
337 |
if (aux instanceof FLyrVect) |
338 |
{ |
339 |
FLyrVect lyrVect = (FLyrVect) aux; |
340 |
// Inicializamos todas
|
341 |
lyrVect.setSpatialCacheEnabled(false);
|
342 |
if (aux.isActive())
|
343 |
if (aux.isEditing()) {
|
344 |
// Sobre la capa en edici?n siempre se puede hacer snapping
|
345 |
lyrVect.setSpatialCacheEnabled(true);
|
346 |
VectorialLayerEdited lyrEd = (VectorialLayerEdited) edManager |
347 |
.getLayerEdited(aux); |
348 |
lyrEd.setLayersToSnap(layersToSnap); |
349 |
|
350 |
} |
351 |
} |
352 |
} // while
|
353 |
it.rewind(); |
354 |
/*
|
355 |
* Iteramos por las capas en edici?n y marcamos aquellas capas que
|
356 |
* necesitan trabajar con el cache habilitado
|
357 |
*/
|
358 |
while (it.hasNext()) {
|
359 |
FLayer aux = it.next(); |
360 |
if (aux.isEditing())
|
361 |
if (aux instanceof FLyrVect) { |
362 |
VectorialLayerEdited lyrEd = (VectorialLayerEdited) edManager |
363 |
.getLayerEdited(aux); |
364 |
for (int i=0; i<lyrEd.getLayersToSnap().size(); i++) |
365 |
{ |
366 |
FLyrVect lyrVect = (FLyrVect) lyrEd.getLayersToSnap().get(i); |
367 |
lyrVect.setSpatialCacheEnabled(true);
|
368 |
} |
369 |
|
370 |
} |
371 |
|
372 |
} // while
|
373 |
mapContext.redraw(); |
374 |
try{
|
375 |
SelectionCADTool.tolerance = Integer.parseInt(getJTxtTolerance().getText());
|
376 |
|
377 |
}catch (Exception e) { |
378 |
throw new StoreException(PluginServices.getText(this, "tolerancia_incorrecta"),e); |
379 |
} |
380 |
} |
381 |
|
382 |
public void initializeDefaults() { |
383 |
getJTxtTolerance().setText("4");
|
384 |
TableModel tm = getJTableSnapping().getModel();
|
385 |
for (int i = 0; i < tm.getRowCount(); i++) { |
386 |
String layerName = (String) tm.getValueAt(i, 1); |
387 |
FLyrVect lyr = (FLyrVect) layers.getLayer(layerName); |
388 |
Boolean bUseCache = (Boolean) tm.getValueAt(i, 0); |
389 |
Integer maxFeat = (Integer) tm.getValueAt(i, 2); |
390 |
lyr.setSpatialCacheEnabled(bUseCache.booleanValue()); |
391 |
lyr.setMaxFeaturesInEditionCache(maxFeat.intValue()); |
392 |
} |
393 |
|
394 |
} |
395 |
|
396 |
public ImageIcon getIcon() { |
397 |
return null; |
398 |
} |
399 |
|
400 |
public void setMapContext(MapContext mc) { |
401 |
// addLayer(layers);
|
402 |
this.mapContext = mc;
|
403 |
this.layers = mc.getLayers();
|
404 |
MyTableModel tm = new MyTableModel(layers);
|
405 |
getJTableSnapping().setModel(tm); |
406 |
getJTxtTolerance().setText(String.valueOf(SelectionCADTool.tolerance));
|
407 |
} |
408 |
|
409 |
/**
|
410 |
* This method initializes jTxtTolerance
|
411 |
*
|
412 |
* @return javax.swing.JTextField
|
413 |
*/
|
414 |
private JTextField getJTxtTolerance() { |
415 |
if (jTxtTolerance == null) { |
416 |
jTxtTolerance = new JTextField(); |
417 |
jTxtTolerance.setPreferredSize(new java.awt.Dimension(28, 20)); |
418 |
jTxtTolerance.setName("jTxtTolerance");
|
419 |
jTxtTolerance.setHorizontalAlignment(javax.swing.JTextField.RIGHT); |
420 |
jTxtTolerance.setText("4");
|
421 |
jTxtTolerance.setBounds(new java.awt.Rectangle(142, 8, 39, 15)); |
422 |
jTxtTolerance.addKeyListener(new KeyListener() { |
423 |
public void keyPressed(KeyEvent e) { changed = true; } |
424 |
public void keyReleased(KeyEvent e) { changed = true; } |
425 |
public void keyTyped(KeyEvent e){ changed = true; } |
426 |
}); |
427 |
} |
428 |
return jTxtTolerance;
|
429 |
} |
430 |
|
431 |
/**
|
432 |
* This method initializes jSeparator
|
433 |
*
|
434 |
* @return javax.swing.JSeparator
|
435 |
*/
|
436 |
private JSeparator getJSeparator() { |
437 |
if (jSeparator == null) { |
438 |
jSeparator = new JSeparator(); |
439 |
jSeparator.setPreferredSize(new java.awt.Dimension(200,2)); |
440 |
} |
441 |
return jSeparator;
|
442 |
} |
443 |
|
444 |
/**
|
445 |
* This method initializes jScrollPane
|
446 |
*
|
447 |
* @return javax.swing.JScrollPane
|
448 |
*/
|
449 |
private JScrollPane getJScrollPane() { |
450 |
if (jScrollPane == null) { |
451 |
jScrollPane = new JScrollPane(); |
452 |
jScrollPane.setPreferredSize(new java.awt.Dimension(500,419)); |
453 |
jScrollPane.setViewportView(getJTableSnapping()); |
454 |
} |
455 |
return jScrollPane;
|
456 |
} |
457 |
|
458 |
/**
|
459 |
* This method initializes jTableSnapping
|
460 |
*
|
461 |
* @return javax.swing.JTable
|
462 |
*/
|
463 |
private JTable getJTableSnapping() { |
464 |
if (jTableSnapping == null) { |
465 |
jTableSnapping = new JTable(); |
466 |
// TableColumnModel cm = new DefaultTableColumnModel();
|
467 |
// TableColumn checkCol = new TableColumn(0, 50);
|
468 |
// cm.addColumn(checkCol);
|
469 |
//
|
470 |
// TableColumn layerCol = new TableColumn(1, 250);
|
471 |
// cm.addColumn(layerCol);
|
472 |
//
|
473 |
// TableColumn maxFeatCol = new TableColumn(2, 50);
|
474 |
// cm.addColumn(maxFeatCol);
|
475 |
//
|
476 |
// JTableHeader head = new JTableHeader(cm);
|
477 |
// head.setVisible(true);
|
478 |
//
|
479 |
//
|
480 |
// TableModel tm = new DefaultTableModel(4,3);
|
481 |
// jTableSnapping.setModel(tm);
|
482 |
// jTableSnapping.setTableHeader(head);
|
483 |
jTableSnapping.addKeyListener(new KeyListener() { |
484 |
public void keyPressed(KeyEvent e) { changed = true; } |
485 |
public void keyReleased(KeyEvent e) { changed = true; } |
486 |
public void keyTyped(KeyEvent e){ changed = true; } |
487 |
}); |
488 |
} |
489 |
return jTableSnapping;
|
490 |
} |
491 |
|
492 |
/**
|
493 |
* This method initializes jPanelNord
|
494 |
*
|
495 |
* @return javax.swing.JPanel
|
496 |
*/
|
497 |
private JPanel getJPanelNord() { |
498 |
if (jPanelNord == null) { |
499 |
jPanelNord = new JPanel(); |
500 |
jPanelNord.setLayout(null);
|
501 |
jPanelNord |
502 |
.setComponentOrientation(java.awt.ComponentOrientation.UNKNOWN); |
503 |
jPanelNord.setPreferredSize(new java.awt.Dimension(30, 30)); |
504 |
jPanelNord.add(jLabel, null);
|
505 |
jPanelNord.add(getJTxtTolerance(), null);
|
506 |
jPanelNord.add(jLabel1, null);
|
507 |
|
508 |
} |
509 |
return jPanelNord;
|
510 |
} |
511 |
|
512 |
/**
|
513 |
* This method initializes jPanelCache
|
514 |
*
|
515 |
* @return javax.swing.JPanel
|
516 |
*/
|
517 |
private JPanel getJPanelCache() { |
518 |
if (jPanelCache == null) { |
519 |
jPanelCache = new JPanel(); |
520 |
jPanelCache.setLayout(new BorderLayout()); |
521 |
jPanelCache.add(jLabelCache, java.awt.BorderLayout.NORTH); |
522 |
jPanelCache.add(getJScrollPane(), java.awt.BorderLayout.EAST); |
523 |
} |
524 |
return jPanelCache;
|
525 |
} |
526 |
|
527 |
public boolean isValueChanged() { |
528 |
return changed;
|
529 |
} |
530 |
|
531 |
public void setChangesApplied() { |
532 |
changed = false;
|
533 |
} |
534 |
|
535 |
} // @jve:decl-index=0:visual-constraint="14,10"
|
536 |
|