svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / FPanelLocConfig.java @ 1223
History | View | Annotate | Download (16.2 KB)
1 |
/*
|
---|---|
2 |
* Created on 18-jun-2004
|
3 |
*
|
4 |
* TODO To change the template for this generated file go to
|
5 |
* Window - Preferences - Java - Code Generation - Code and Comments
|
6 |
*/
|
7 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
8 |
*
|
9 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
10 |
*
|
11 |
* This program is free software; you can redistribute it and/or
|
12 |
* modify it under the terms of the GNU General Public License
|
13 |
* as published by the Free Software Foundation; either version 2
|
14 |
* of the License, or (at your option) any later version.
|
15 |
*
|
16 |
* This program is distributed in the hope that it will be useful,
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19 |
* GNU General Public License for more details.
|
20 |
*
|
21 |
* You should have received a copy of the GNU General Public License
|
22 |
* along with this program; if not, write to the Free Software
|
23 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
24 |
*
|
25 |
* For more information, contact:
|
26 |
*
|
27 |
* Generalitat Valenciana
|
28 |
* Conselleria d'Infraestructures i Transport
|
29 |
* Av. Blasco Ib??ez, 50
|
30 |
* 46010 VALENCIA
|
31 |
* SPAIN
|
32 |
*
|
33 |
* +34 963862235
|
34 |
* gvsig@gva.es
|
35 |
* www.gvsig.gva.es
|
36 |
*
|
37 |
* or
|
38 |
*
|
39 |
* IVER T.I. S.A
|
40 |
* Salamanca 50
|
41 |
* 46005 Valencia
|
42 |
* Spain
|
43 |
*
|
44 |
* +34 963163400
|
45 |
* dac@iver.es
|
46 |
*/
|
47 |
package com.iver.cit.gvsig.gui; |
48 |
|
49 |
import java.awt.Color; |
50 |
import java.awt.event.ActionEvent; |
51 |
import java.awt.event.ActionListener; |
52 |
import java.io.File; |
53 |
|
54 |
import javax.swing.BorderFactory; |
55 |
import javax.swing.DefaultListModel; |
56 |
import javax.swing.JDialog; |
57 |
import javax.swing.JOptionPane; |
58 |
import javax.swing.JPanel; |
59 |
|
60 |
import org.cresques.cts.IProjection; |
61 |
import org.cresques.cts.ProjectionPool; |
62 |
|
63 |
import com.hardcode.gdbms.engine.data.DBDriver; |
64 |
import com.iver.andami.PluginServices; |
65 |
import com.iver.andami.messages.NotificationManager; |
66 |
import com.iver.andami.ui.mdiManager.View; |
67 |
import com.iver.andami.ui.mdiManager.ViewInfo; |
68 |
import com.iver.cit.gvsig.fmap.DriverException; |
69 |
import com.iver.cit.gvsig.fmap.MapControl; |
70 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
71 |
import com.iver.cit.gvsig.fmap.drivers.GeorreferencedRasterDriver; |
72 |
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
73 |
import com.iver.cit.gvsig.fmap.layers.CancelationException; |
74 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
75 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
76 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
77 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
78 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable; |
79 |
import com.iver.cit.gvsig.gui.legendmanager.FLegendManagerWindow; |
80 |
|
81 |
/**
|
82 |
* @author FJP
|
83 |
*
|
84 |
* TODO To change the template for this generated type comment go to
|
85 |
* Window - Preferences - Java - Code Generation - Code and Comments
|
86 |
*/
|
87 |
public class FPanelLocConfig extends JPanel implements ActionListener,View { |
88 |
private javax.swing.JLabel jLabel = null; |
89 |
private javax.swing.JList jList = null; |
90 |
private javax.swing.JButton jBtnUp = null; |
91 |
private javax.swing.JButton jBtnDown = null; |
92 |
private javax.swing.JButton jBtnAddLayer = null; // |
93 |
private javax.swing.JButton jBtnRemoveLayer = null; |
94 |
private javax.swing.JButton jBtnEditLegend = null; |
95 |
private javax.swing.JButton jBtnCancel = null; |
96 |
|
97 |
//private JDialog m_Owner;
|
98 |
private MapControl mapCtrl;
|
99 |
private FLegendManagerWindow m_LegendEditor = new FLegendManagerWindow(); |
100 |
private ViewInfo m_viewinfo = null; |
101 |
/**
|
102 |
* This is the default constructor
|
103 |
*/
|
104 |
public FPanelLocConfig( MapControl mc) {
|
105 |
super();
|
106 |
mapCtrl = mc; |
107 |
initialize(); |
108 |
refreshList(); |
109 |
updateControls(null);
|
110 |
} |
111 |
|
112 |
private void refreshList() |
113 |
{ |
114 |
DefaultListModel lstModel = (DefaultListModel) getJList().getModel(); |
115 |
lstModel.clear(); |
116 |
for (int i=mapCtrl.getMapContext().getLayers().getLayersCount()-1; i >=0; i--) |
117 |
{ |
118 |
FLayer lyr = mapCtrl.getMapContext().getLayers().getLayer(i); |
119 |
lstModel.addElement(lyr.getName()); |
120 |
} |
121 |
} |
122 |
|
123 |
/**
|
124 |
* This method initializes this
|
125 |
*
|
126 |
* @return void
|
127 |
*/
|
128 |
private void initialize() { |
129 |
this.setLayout(null); |
130 |
this.setSize(370, 200); |
131 |
this.setPreferredSize(new java.awt.Dimension(370,200)); |
132 |
this.add(getJLabel(), null); |
133 |
this.add(getJList(), null); |
134 |
this.add(getJBtnUp(), null); |
135 |
this.add(getJBtnDown(), null); |
136 |
this.add(getJBtnAddLayer(), null); |
137 |
this.add(getJBtnRemoveLayer(), null); |
138 |
this.add(getJBtnEditLegend(), null); |
139 |
this.add(getJBtnCancel(), null); |
140 |
} |
141 |
/**
|
142 |
|
143 |
* This method initializes jLabel
|
144 |
|
145 |
*
|
146 |
|
147 |
* @return javax.swing.JLabel
|
148 |
|
149 |
*/
|
150 |
private javax.swing.JLabel getJLabel() {
|
151 |
if (jLabel == null) { |
152 |
jLabel = new javax.swing.JLabel();
|
153 |
jLabel.setText(PluginServices.getText(this,"Capas_del_localizador")+":"); |
154 |
jLabel.setBounds(22, 15, 132, 25); |
155 |
} |
156 |
return jLabel;
|
157 |
} |
158 |
|
159 |
/**
|
160 |
|
161 |
* This method initializes jList
|
162 |
|
163 |
*
|
164 |
|
165 |
* @return javax.swing.JList
|
166 |
|
167 |
*/
|
168 |
private javax.swing.JList getJList() {
|
169 |
if (jList == null) { |
170 |
jList = new javax.swing.JList(new DefaultListModel()); |
171 |
jList.setBounds(22, 49, 179, 139); |
172 |
jList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); |
173 |
jList.setBorder(BorderFactory.createLineBorder(Color.BLACK)); |
174 |
jList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
|
175 |
|
176 |
public void valueChanged(javax.swing.event.ListSelectionEvent e) { |
177 |
updateControls(e); |
178 |
} |
179 |
}); |
180 |
|
181 |
} |
182 |
return jList;
|
183 |
} |
184 |
|
185 |
private void updateControls(javax.swing.event.ListSelectionEvent e) |
186 |
{ |
187 |
System.out.println("valueChanged()"); // TODO Auto-generated Event stub valueChanged() |
188 |
DefaultListModel lstModel = (DefaultListModel) getJList().getModel(); |
189 |
int selIndex = jList.getSelectedIndex();
|
190 |
jBtnDown.setEnabled(false);
|
191 |
jBtnUp.setEnabled(false);
|
192 |
|
193 |
if (selIndex != -1) |
194 |
{ |
195 |
if (lstModel.getSize() > 1) |
196 |
{ |
197 |
if (selIndex < (lstModel.getSize()-1)) |
198 |
jBtnDown.setEnabled(true);
|
199 |
|
200 |
if (selIndex > 0) |
201 |
jBtnUp.setEnabled(true);
|
202 |
} |
203 |
|
204 |
} |
205 |
|
206 |
|
207 |
} |
208 |
|
209 |
/**
|
210 |
|
211 |
* This method initializes jBtnUp
|
212 |
|
213 |
*
|
214 |
|
215 |
* @return javax.swing.JButton
|
216 |
|
217 |
*/
|
218 |
private javax.swing.JButton getJBtnUp() {
|
219 |
if (jBtnUp == null) { |
220 |
jBtnUp = new javax.swing.plaf.basic.BasicArrowButton(
|
221 |
javax.swing.SwingConstants.NORTH); |
222 |
jBtnUp.setBounds(206, 49, 25, 23); |
223 |
jBtnUp.setToolTipText(PluginServices.getText(this,"Subir_capa")); |
224 |
jBtnUp.addActionListener(this);
|
225 |
jBtnUp.setActionCommand("UP");
|
226 |
|
227 |
} |
228 |
return jBtnUp;
|
229 |
} |
230 |
|
231 |
/**
|
232 |
|
233 |
* This method initializes jBtnDown
|
234 |
|
235 |
*
|
236 |
|
237 |
* @return javax.swing.JButton
|
238 |
|
239 |
*/
|
240 |
private javax.swing.JButton getJBtnDown() {
|
241 |
if (jBtnDown == null) { |
242 |
jBtnDown = new javax.swing.plaf.basic.BasicArrowButton(
|
243 |
javax.swing.SwingConstants.SOUTH); |
244 |
jBtnDown.setBounds(206, 164, 25, 23); |
245 |
jBtnDown.setToolTipText(PluginServices.getText(this,"Bajar_capa")); |
246 |
jBtnDown.setActionCommand("DOWN");
|
247 |
jBtnDown.addActionListener(this);
|
248 |
} |
249 |
return jBtnDown;
|
250 |
} |
251 |
|
252 |
/**
|
253 |
|
254 |
* This method initializes jButton2
|
255 |
|
256 |
*
|
257 |
|
258 |
* @return javax.swing.JButton
|
259 |
|
260 |
*/
|
261 |
private javax.swing.JButton getJBtnAddLayer() {
|
262 |
if (jBtnAddLayer == null) { |
263 |
jBtnAddLayer = new javax.swing.JButton();
|
264 |
jBtnAddLayer.setBounds(251, 49, 109, 23); |
265 |
jBtnAddLayer.setText(PluginServices.getText(this,"Anadir_capa")+"..."); |
266 |
jBtnAddLayer.addActionListener(this);
|
267 |
jBtnAddLayer.setActionCommand("ADD_LAYER");
|
268 |
} |
269 |
return jBtnAddLayer;
|
270 |
} |
271 |
|
272 |
/**
|
273 |
|
274 |
* This method initializes jBtnRemoveLayer
|
275 |
|
276 |
*
|
277 |
|
278 |
* @return javax.swing.JButton
|
279 |
|
280 |
*/
|
281 |
private javax.swing.JButton getJBtnRemoveLayer() {
|
282 |
if (jBtnRemoveLayer == null) { |
283 |
jBtnRemoveLayer = new javax.swing.JButton();
|
284 |
jBtnRemoveLayer.setBounds(251, 78, 109, 23); |
285 |
jBtnRemoveLayer.setText(PluginServices.getText(this,"Quitar_capa")+"..."); |
286 |
jBtnRemoveLayer.addActionListener(this);
|
287 |
jBtnRemoveLayer.setActionCommand("REMOVE_LAYER");
|
288 |
|
289 |
} |
290 |
return jBtnRemoveLayer;
|
291 |
} |
292 |
|
293 |
/**
|
294 |
|
295 |
* This method initializes jBtnEditLegend
|
296 |
|
297 |
*
|
298 |
|
299 |
* @return javax.swing.JButton
|
300 |
|
301 |
*/
|
302 |
private javax.swing.JButton getJBtnEditLegend() {
|
303 |
if (jBtnEditLegend == null) { |
304 |
jBtnEditLegend = new javax.swing.JButton();
|
305 |
jBtnEditLegend.setBounds(251, 113, 109, 23); |
306 |
jBtnEditLegend.setText(PluginServices.getText(this,"Editar_leyenda")+"..."); |
307 |
jBtnEditLegend.addActionListener(this);
|
308 |
jBtnEditLegend.setActionCommand("EDIT_LEGEND");
|
309 |
} |
310 |
return jBtnEditLegend;
|
311 |
} |
312 |
|
313 |
/**
|
314 |
|
315 |
* This method initializes jBtnCancel
|
316 |
|
317 |
*
|
318 |
|
319 |
* @return javax.swing.JButton
|
320 |
|
321 |
*/
|
322 |
private javax.swing.JButton getJBtnCancel() {
|
323 |
if (jBtnCancel == null) { |
324 |
jBtnCancel = new javax.swing.JButton();
|
325 |
jBtnCancel.setBounds(251, 162, 109, 23); |
326 |
jBtnCancel.setText(PluginServices.getText(this,"Cerrar")); |
327 |
jBtnCancel.setActionCommand("CANCEL");
|
328 |
jBtnCancel.addActionListener(this);
|
329 |
|
330 |
} |
331 |
return jBtnCancel;
|
332 |
} |
333 |
/* (non-Javadoc)
|
334 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
335 |
*/
|
336 |
public void actionPerformed(ActionEvent e) |
337 |
{ |
338 |
DefaultListModel lstModel = (DefaultListModel) getJList().getModel(); |
339 |
FLayers theLayers = mapCtrl.getMapContext().getLayers(); |
340 |
// TODO LWS Esto debe venir de fuera (proyeccion del fichero, o de la vista)
|
341 |
IProjection proj = ProjectionPool.get("EPSG:23030");
|
342 |
|
343 |
int numLayers = theLayers.getLayersCount()-1; |
344 |
|
345 |
if (e.getActionCommand() == "CANCEL") |
346 |
{ |
347 |
if (PluginServices.getMainFrame() != null) |
348 |
{ |
349 |
PluginServices.getMDIManager().closeView(FPanelLocConfig.this); |
350 |
} |
351 |
else
|
352 |
{ |
353 |
((JDialog) (getParent().getParent().getParent().getParent())).dispose();
|
354 |
} |
355 |
} |
356 |
if (e.getActionCommand() == "ADD_LAYER") |
357 |
{ |
358 |
FOpenDialog fopen = new FOpenDialog();
|
359 |
if (PluginServices.getMainFrame() != null) |
360 |
{ |
361 |
FileOpenDialog fileDlg = new FileOpenDialog(new Class[]{VectorialFileDriver.class, GeorreferencedRasterDriver.class}); |
362 |
DataBaseOpenDialog dbop = new DataBaseOpenDialog();
|
363 |
dbop.setClasses(new Class[] { DBDriver.class }); |
364 |
fopen.addTab("Fichero", fileDlg);
|
365 |
fopen.addTab("Base de datos", dbop);
|
366 |
PluginServices.getMDIManager().addView(fopen); |
367 |
|
368 |
if (fopen.isAccepted()) {
|
369 |
// TODO: Hacer lo de la capa WMS tambi?n.
|
370 |
if (fileDlg.getFiles() == null) { |
371 |
return;
|
372 |
} |
373 |
|
374 |
FLayer lyr = null;
|
375 |
File[] files = fileDlg.getFiles(); |
376 |
String[] driverNames = fileDlg.getDriverNames(); |
377 |
for (int iFile = 0; iFile < files.length; iFile++) { |
378 |
File fich = files[iFile];
|
379 |
String layerName = fich.getName();
|
380 |
String layerPath = fich.getAbsolutePath();
|
381 |
|
382 |
try {
|
383 |
lyr = LayerFactory.createLayer(layerName, driverNames[iFile], |
384 |
fich, proj); |
385 |
|
386 |
if (lyr != null) { |
387 |
try {
|
388 |
|
389 |
lyr.setVisible(true);
|
390 |
mapCtrl.getMapContext().getLayers() |
391 |
.addLayer(lyr); |
392 |
} catch (CancelationException ex) {
|
393 |
// TODO Auto-generated catch block
|
394 |
ex.printStackTrace(); |
395 |
} |
396 |
|
397 |
} |
398 |
} catch (DriverException ex) {
|
399 |
NotificationManager.addError("A?adiendo capa",ex);
|
400 |
} |
401 |
} // for
|
402 |
} |
403 |
|
404 |
} |
405 |
else
|
406 |
{ |
407 |
JDialog dlg = new JDialog(); |
408 |
dlg.setModal(true);
|
409 |
FileOpenDialog fileDlg = new FileOpenDialog(new Class[]{VectorialFileDriver.class}); |
410 |
DataBaseOpenDialog dbop = new DataBaseOpenDialog();
|
411 |
dbop.setClasses(new Class[]{DBDriver.class}); |
412 |
|
413 |
fopen = new FOpenDialog();
|
414 |
fopen.addTab("Fichero", fileDlg);
|
415 |
fopen.addTab("Base de datos", dbop);
|
416 |
// fileDlg.setPreferredSize(fopen.getSize());
|
417 |
dlg.setSize(fopen.getSize()); |
418 |
dlg.getContentPane().add(fopen); |
419 |
dlg.pack(); |
420 |
dlg.show(); |
421 |
|
422 |
|
423 |
// TODO: Hacer lo de la capa WMS tambi?n.
|
424 |
if (fileDlg.getFiles() == null) return; |
425 |
FLayer lyr = null;
|
426 |
File[] files = fileDlg.getFiles(); |
427 |
String[] driverNames = fileDlg.getDriverNames(); |
428 |
for (int iFile=0; iFile < files.length; iFile++) |
429 |
{ |
430 |
File fich = files[iFile];
|
431 |
String layerName = fich.getName();
|
432 |
String layerPath = fich.getAbsolutePath();
|
433 |
|
434 |
try {
|
435 |
lyr = LayerFactory.createLayer(layerName, driverNames[iFile], fich, proj); |
436 |
|
437 |
lyr.setVisible(true);
|
438 |
lyr.setName(layerName); |
439 |
if (lyr != null ) |
440 |
{ |
441 |
try {
|
442 |
mapCtrl.getMapContext().getLayers().addLayer(lyr); |
443 |
} catch (CancelationException ex) {
|
444 |
// TODO Auto-generated catch block
|
445 |
ex.printStackTrace(); |
446 |
} |
447 |
} |
448 |
|
449 |
} catch (DriverException ex) {
|
450 |
NotificationManager.addError("A?adiendo capa",ex);
|
451 |
} |
452 |
} // for
|
453 |
// lstModel.addElement(lyr.getName());
|
454 |
} |
455 |
refreshList(); |
456 |
updateControls(null);
|
457 |
|
458 |
} |
459 |
if (e.getActionCommand() == "REMOVE_LAYER") |
460 |
{ |
461 |
if (jList.getSelectedIndex() != -1) |
462 |
{ |
463 |
theLayers.removeLayer((String) lstModel.get(jList.getSelectedIndex()));
|
464 |
lstModel.remove(jList.getSelectedIndex()); |
465 |
///mapCtrl.drawMap();
|
466 |
updateControls(null);
|
467 |
} |
468 |
} |
469 |
if (e.getActionCommand() == "EDIT_LEGEND") |
470 |
{ |
471 |
int idSelec = jList.getSelectedIndex();
|
472 |
if (idSelec != -1) |
473 |
{ |
474 |
FLayer lyr = theLayers.getLayer((String) lstModel.get(idSelec));
|
475 |
if (lyr instanceof Classifiable) |
476 |
{ |
477 |
try {
|
478 |
theLayers.setActive(false);
|
479 |
lyr.setActive(true);
|
480 |
m_LegendEditor.setMapContext(mapCtrl.getMapContext()); |
481 |
} catch (DriverException e1) {
|
482 |
// TODO Auto-generated catch block
|
483 |
e1.printStackTrace(); |
484 |
} |
485 |
if (PluginServices.getMainFrame() == null) { |
486 |
JDialog dlg = new JDialog(); |
487 |
|
488 |
m_LegendEditor.setPreferredSize(m_LegendEditor.getSize()); |
489 |
dlg.getContentPane().add(m_LegendEditor); |
490 |
dlg.setModal(true);
|
491 |
dlg.pack(); |
492 |
dlg.show(); |
493 |
|
494 |
} else
|
495 |
PluginServices.getMDIManager().addView(m_LegendEditor); |
496 |
} |
497 |
else
|
498 |
{ |
499 |
JOptionPane.showMessageDialog(null, PluginServices.getText(this,"Solo para capas vectoriales")+"."); |
500 |
} |
501 |
|
502 |
} |
503 |
|
504 |
} |
505 |
if (e.getActionCommand() == "UP") |
506 |
{ |
507 |
int idSelec = jList.getSelectedIndex();
|
508 |
int fromIndex = idSelec;
|
509 |
int toIndex = idSelec-1; |
510 |
FLayer aux = theLayers.getLayer((String) lstModel.get(fromIndex));
|
511 |
try {
|
512 |
theLayers.moveTo(numLayers-fromIndex, numLayers-toIndex); |
513 |
} catch (CancelationException e1) {
|
514 |
e1.printStackTrace(); |
515 |
} |
516 |
|
517 |
lstModel.remove(fromIndex); |
518 |
lstModel.add(toIndex,aux.getName()); |
519 |
|
520 |
jList.setSelectedIndex(toIndex); |
521 |
|
522 |
///mapCtrl.drawMap();
|
523 |
} |
524 |
if (e.getActionCommand() == "DOWN") |
525 |
{ |
526 |
int idSelec = jList.getSelectedIndex();
|
527 |
int fromIndex = idSelec;
|
528 |
int toIndex = idSelec+1; |
529 |
FLayer aux = theLayers.getLayer((String) lstModel.get(fromIndex));
|
530 |
try {
|
531 |
theLayers.moveTo(numLayers-fromIndex, numLayers-toIndex); |
532 |
} catch (CancelationException e1) {
|
533 |
e1.printStackTrace(); |
534 |
} |
535 |
|
536 |
lstModel.remove(fromIndex); |
537 |
lstModel.add(toIndex,aux.getName()); |
538 |
|
539 |
jList.setSelectedIndex(toIndex); |
540 |
|
541 |
///mapCtrl.drawMap();
|
542 |
} |
543 |
|
544 |
|
545 |
} |
546 |
/* (non-Javadoc)
|
547 |
* @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
|
548 |
*/
|
549 |
public ViewInfo getViewInfo() {
|
550 |
if (m_viewinfo==null){ |
551 |
m_viewinfo=new ViewInfo(ViewInfo.MODALDIALOG);
|
552 |
m_viewinfo.setTitle(PluginServices.getText(this,"Configurar_localizador")); |
553 |
} |
554 |
return m_viewinfo;
|
555 |
} |
556 |
/**
|
557 |
* @see com.iver.mdiApp.ui.MDIManager.View#viewActivated()
|
558 |
*/
|
559 |
public void viewActivated() { |
560 |
} |
561 |
|
562 |
} // @jve:visual-info decl-index=0 visual-constraint="10,10"
|