svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / FPanelLocConfig.java @ 403
History | View | Annotate | Download (12.7 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 |
package com.iver.cit.gvsig.gui; |
8 |
|
9 |
import java.awt.Color; |
10 |
import java.awt.event.ActionEvent; |
11 |
import java.awt.event.ActionListener; |
12 |
|
13 |
import javax.swing.BorderFactory; |
14 |
import javax.swing.DefaultListModel; |
15 |
import javax.swing.JDialog; |
16 |
import javax.swing.JOptionPane; |
17 |
import javax.swing.JPanel; |
18 |
|
19 |
import org.cresques.cts.IProjection; |
20 |
import org.cresques.cts.ProjectionPool; |
21 |
|
22 |
import com.iver.cit.gvsig.fmap.NewMapControl; |
23 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
24 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
25 |
import com.iver.cit.gvsig.fmap.layers.FLyrRaster; |
26 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
27 |
import com.iver.mdiApp.App; |
28 |
import com.iver.mdiApp.Utilities; |
29 |
import com.iver.mdiApp.ui.MDIManager.View; |
30 |
import com.iver.mdiApp.ui.MDIManager.ViewInfo; |
31 |
|
32 |
/**
|
33 |
* @author FJP
|
34 |
*
|
35 |
* TODO To change the template for this generated type comment go to
|
36 |
* Window - Preferences - Java - Code Generation - Code and Comments
|
37 |
*/
|
38 |
public class FPanelLocConfig extends JPanel implements ActionListener,View { |
39 |
private javax.swing.JLabel jLabel = null; |
40 |
private javax.swing.JList jList = null; |
41 |
private javax.swing.JButton jBtnUp = null; |
42 |
private javax.swing.JButton jBtnDown = null; |
43 |
private javax.swing.JButton jBtnAddLayer = null; // |
44 |
private javax.swing.JButton jBtnRemoveLayer = null; |
45 |
private javax.swing.JButton jBtnEditLegend = null; |
46 |
private javax.swing.JButton jBtnCancel = null; |
47 |
|
48 |
//private JDialog m_Owner;
|
49 |
private NewMapControl mapCtrl;
|
50 |
private FLegendManagerWindow m_LegendEditor = new FLegendManagerWindow(); |
51 |
private ViewInfo m_viewinfo = null; |
52 |
/**
|
53 |
* This is the default constructor
|
54 |
*/
|
55 |
public FPanelLocConfig( NewMapControl mc) {
|
56 |
super();
|
57 |
mapCtrl = mc; |
58 |
initialize(); |
59 |
refreshList(); |
60 |
updateControls(null);
|
61 |
} |
62 |
|
63 |
private void refreshList() |
64 |
{ |
65 |
DefaultListModel lstModel = (DefaultListModel) getJList().getModel(); |
66 |
lstModel.clear(); |
67 |
for (int i=0; i < mapCtrl.getMapContext().getLayers().getLayersCount(); i++) |
68 |
{ |
69 |
FLayer lyr = mapCtrl.getMapContext().getLayers().getLayer(i); |
70 |
lstModel.addElement(lyr.getName()); |
71 |
} |
72 |
} |
73 |
|
74 |
/**
|
75 |
* This method initializes this
|
76 |
*
|
77 |
* @return void
|
78 |
*/
|
79 |
private void initialize() { |
80 |
this.setLayout(null); |
81 |
this.setSize(370, 200); |
82 |
this.setPreferredSize(new java.awt.Dimension(370,200)); |
83 |
this.add(getJLabel(), null); |
84 |
this.add(getJList(), null); |
85 |
this.add(getJBtnUp(), null); |
86 |
this.add(getJBtnDown(), null); |
87 |
this.add(getJBtnAddLayer(), null); |
88 |
this.add(getJBtnRemoveLayer(), null); |
89 |
this.add(getJBtnEditLegend(), null); |
90 |
this.add(getJBtnCancel(), null); |
91 |
} |
92 |
/**
|
93 |
|
94 |
* This method initializes jLabel
|
95 |
|
96 |
*
|
97 |
|
98 |
* @return javax.swing.JLabel
|
99 |
|
100 |
*/
|
101 |
private javax.swing.JLabel getJLabel() {
|
102 |
if (jLabel == null) { |
103 |
jLabel = new javax.swing.JLabel();
|
104 |
jLabel.setText(Utilities.getMessage(this,"Capas_del_localizador")+":"); |
105 |
jLabel.setBounds(22, 15, 132, 25); |
106 |
} |
107 |
return jLabel;
|
108 |
} |
109 |
|
110 |
/**
|
111 |
|
112 |
* This method initializes jList
|
113 |
|
114 |
*
|
115 |
|
116 |
* @return javax.swing.JList
|
117 |
|
118 |
*/
|
119 |
private javax.swing.JList getJList() {
|
120 |
if (jList == null) { |
121 |
jList = new javax.swing.JList(new DefaultListModel()); |
122 |
jList.setBounds(22, 49, 179, 139); |
123 |
jList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); |
124 |
jList.setBorder(BorderFactory.createLineBorder(Color.BLACK)); |
125 |
jList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
|
126 |
|
127 |
public void valueChanged(javax.swing.event.ListSelectionEvent e) { |
128 |
updateControls(e); |
129 |
} |
130 |
}); |
131 |
|
132 |
} |
133 |
return jList;
|
134 |
} |
135 |
|
136 |
private void updateControls(javax.swing.event.ListSelectionEvent e) |
137 |
{ |
138 |
System.out.println("valueChanged()"); // TODO Auto-generated Event stub valueChanged() |
139 |
DefaultListModel lstModel = (DefaultListModel) getJList().getModel(); |
140 |
int selIndex = jList.getSelectedIndex();
|
141 |
jBtnDown.setEnabled(false);
|
142 |
jBtnUp.setEnabled(false);
|
143 |
|
144 |
if (selIndex != -1) |
145 |
{ |
146 |
if (lstModel.getSize() > 1) |
147 |
{ |
148 |
if (selIndex < (lstModel.getSize()-1)) |
149 |
jBtnDown.setEnabled(true);
|
150 |
|
151 |
if (selIndex > 0) |
152 |
jBtnUp.setEnabled(true);
|
153 |
} |
154 |
|
155 |
} |
156 |
|
157 |
|
158 |
} |
159 |
|
160 |
/**
|
161 |
|
162 |
* This method initializes jBtnUp
|
163 |
|
164 |
*
|
165 |
|
166 |
* @return javax.swing.JButton
|
167 |
|
168 |
*/
|
169 |
private javax.swing.JButton getJBtnUp() {
|
170 |
if (jBtnUp == null) { |
171 |
jBtnUp = new javax.swing.plaf.basic.BasicArrowButton(
|
172 |
javax.swing.SwingConstants.NORTH); |
173 |
jBtnUp.setBounds(206, 49, 25, 23); |
174 |
jBtnUp.setToolTipText(Utilities.getMessage(this,"Subir_capa")); |
175 |
jBtnUp.addActionListener(this);
|
176 |
jBtnUp.setActionCommand("UP");
|
177 |
|
178 |
} |
179 |
return jBtnUp;
|
180 |
} |
181 |
|
182 |
/**
|
183 |
|
184 |
* This method initializes jBtnDown
|
185 |
|
186 |
*
|
187 |
|
188 |
* @return javax.swing.JButton
|
189 |
|
190 |
*/
|
191 |
private javax.swing.JButton getJBtnDown() {
|
192 |
if (jBtnDown == null) { |
193 |
jBtnDown = new javax.swing.plaf.basic.BasicArrowButton(
|
194 |
javax.swing.SwingConstants.SOUTH); |
195 |
jBtnDown.setBounds(206, 164, 25, 23); |
196 |
jBtnDown.setToolTipText(Utilities.getMessage(this,"Bajar_capa")); |
197 |
jBtnDown.setActionCommand("DOWN");
|
198 |
jBtnDown.addActionListener(this);
|
199 |
} |
200 |
return jBtnDown;
|
201 |
} |
202 |
|
203 |
/**
|
204 |
|
205 |
* This method initializes jButton2
|
206 |
|
207 |
*
|
208 |
|
209 |
* @return javax.swing.JButton
|
210 |
|
211 |
*/
|
212 |
private javax.swing.JButton getJBtnAddLayer() {
|
213 |
if (jBtnAddLayer == null) { |
214 |
jBtnAddLayer = new javax.swing.JButton();
|
215 |
jBtnAddLayer.setBounds(251, 49, 109, 23); |
216 |
jBtnAddLayer.setText(Utilities.getMessage(this,"Anadir_capa")+"..."); |
217 |
jBtnAddLayer.addActionListener(this);
|
218 |
jBtnAddLayer.setActionCommand("ADD_LAYER");
|
219 |
} |
220 |
return jBtnAddLayer;
|
221 |
} |
222 |
|
223 |
/**
|
224 |
|
225 |
* This method initializes jBtnRemoveLayer
|
226 |
|
227 |
*
|
228 |
|
229 |
* @return javax.swing.JButton
|
230 |
|
231 |
*/
|
232 |
private javax.swing.JButton getJBtnRemoveLayer() {
|
233 |
if (jBtnRemoveLayer == null) { |
234 |
jBtnRemoveLayer = new javax.swing.JButton();
|
235 |
jBtnRemoveLayer.setBounds(251, 78, 109, 23); |
236 |
jBtnRemoveLayer.setText(Utilities.getMessage(this,"Quitar_capa")+"..."); |
237 |
jBtnRemoveLayer.addActionListener(this);
|
238 |
jBtnRemoveLayer.setActionCommand("REMOVE_LAYER");
|
239 |
|
240 |
} |
241 |
return jBtnRemoveLayer;
|
242 |
} |
243 |
|
244 |
/**
|
245 |
|
246 |
* This method initializes jBtnEditLegend
|
247 |
|
248 |
*
|
249 |
|
250 |
* @return javax.swing.JButton
|
251 |
|
252 |
*/
|
253 |
private javax.swing.JButton getJBtnEditLegend() {
|
254 |
if (jBtnEditLegend == null) { |
255 |
jBtnEditLegend = new javax.swing.JButton();
|
256 |
jBtnEditLegend.setBounds(251, 113, 109, 23); |
257 |
jBtnEditLegend.setText(Utilities.getMessage(this,"Editar_leyenda")+"..."); |
258 |
jBtnEditLegend.addActionListener(this);
|
259 |
jBtnEditLegend.setActionCommand("EDIT_LEGEND");
|
260 |
} |
261 |
return jBtnEditLegend;
|
262 |
} |
263 |
|
264 |
/**
|
265 |
|
266 |
* This method initializes jBtnCancel
|
267 |
|
268 |
*
|
269 |
|
270 |
* @return javax.swing.JButton
|
271 |
|
272 |
*/
|
273 |
private javax.swing.JButton getJBtnCancel() {
|
274 |
if (jBtnCancel == null) { |
275 |
jBtnCancel = new javax.swing.JButton();
|
276 |
jBtnCancel.setBounds(251, 162, 109, 23); |
277 |
jBtnCancel.setText(Utilities.getMessage(this,"Cerrar")); |
278 |
jBtnCancel.setActionCommand("CANCEL");
|
279 |
jBtnCancel.addActionListener(this);
|
280 |
|
281 |
} |
282 |
return jBtnCancel;
|
283 |
} |
284 |
/* (non-Javadoc)
|
285 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
286 |
*/
|
287 |
public void actionPerformed(ActionEvent e) |
288 |
{ |
289 |
DefaultListModel lstModel = (DefaultListModel) getJList().getModel(); |
290 |
FLayers theLayers = m_View.getMapOverview().getLayers(); |
291 |
// TODO LWS Esto debe venir de fuera (proyeccion del fichero, o de la vista)
|
292 |
IProjection proj = ProjectionPool.get("ed50utm30");
|
293 |
|
294 |
if (e.getActionCommand() == "CANCEL") |
295 |
{ |
296 |
if (App.instance != null) |
297 |
{ |
298 |
App.instance.getMDIContext().closeView(FPanelLocConfig.this); |
299 |
} |
300 |
else
|
301 |
{ |
302 |
((JDialog) (getParent().getParent().getParent().getParent())).dispose();
|
303 |
} |
304 |
} |
305 |
if (e.getActionCommand() == "ADD_LAYER") |
306 |
{ |
307 |
FOpenDialog fopen = new FOpenDialog(m_View, m_View.getMapOverview());
|
308 |
if (App.instance != null) |
309 |
{ |
310 |
App.instance.getMDIContext().addView(fopen); |
311 |
} |
312 |
else
|
313 |
{ |
314 |
JDialog dlg = new JDialog(); |
315 |
dlg.setModal(true);
|
316 |
fopen.setPreferredSize(fopen.getSize()); |
317 |
dlg.setSize(fopen.getSize()); |
318 |
dlg.getContentPane().add(fopen); |
319 |
dlg.pack(); |
320 |
dlg.show(); |
321 |
IFLayer lyr = null;
|
322 |
for (int iFile=0; iFile < fopen.getFiles().length; iFile++) |
323 |
{ |
324 |
String layerName = fopen.getFiles()[iFile].getName();
|
325 |
String layerPath = fopen.getFiles()[iFile].getAbsolutePath();
|
326 |
// Capas Raster
|
327 |
if (layerName.endsWith(".ecw") || layerName.endsWith(".ECW") || |
328 |
layerName.endsWith(".jpg") ||
|
329 |
layerName.endsWith(".png") ||
|
330 |
layerName.endsWith(".tif")) {
|
331 |
|
332 |
// Miramos por si es un ecwp:
|
333 |
int test = layerPath.indexOf("ecwp:"); |
334 |
if (test != -1) { |
335 |
String urlECW = layerPath.substring(test + 6); |
336 |
urlECW.replaceAll("/", "//"); |
337 |
layerPath = "ecwp://" + urlECW;
|
338 |
} |
339 |
|
340 |
// TODO LWS solo crea la capa raster si no hay o la ?ltima creada (activa) ...
|
341 |
// TODO LWS ... no es raster. as? metemos varios raster en una sola capa
|
342 |
// TODO LWS deber?a guardar la capa raster activa para crearla solo cuando no exista
|
343 |
// TODO LWS (en la primera carga de raster; las siguientes van en la actual, de momento)
|
344 |
if (lyr == null || !(lyr instanceof FLyrRaster)) |
345 |
lyr = new FLyrRaster(proj, layerName, true); |
346 |
((FLyrRaster) lyr).addRasterFile(layerName, layerPath); |
347 |
} else { // Capas vectoriales |
348 |
if (layerName.endsWith(".shp")){ |
349 |
lyr = new FLyrShp(proj, layerName, layerPath, true); |
350 |
// lyrLoc = new FLyrShp(fopen.getText(), fopen.getText());
|
351 |
} else if ((layerName.endsWith(".dgn")) || (layerName.endsWith(".DGN"))) { |
352 |
lyr = new FLyrDgnG(proj, layerName, layerPath, true); |
353 |
} else if (layerName.endsWith(".dxf")){ |
354 |
lyr = new FLyrDxfG(proj, layerName, layerPath, true); |
355 |
//lyr = new FLyrDxf(proj, layerName, layerPath);
|
356 |
} |
357 |
if (e.getActionCommand() == "ADD_MEMORY_LAYER") |
358 |
((FLyrVect) lyr).copyToMemory(); |
359 |
|
360 |
} |
361 |
} // for
|
362 |
m_View.getMapOverview().getMapContext().getLayers().addLayer(lyr); |
363 |
} // Fin de la parte de SingleView
|
364 |
|
365 |
m_View.getMapOverview().drawMap(); |
366 |
// lstModel.addElement(lyr.getName());
|
367 |
refreshList(); |
368 |
updateControls(null);
|
369 |
|
370 |
} |
371 |
if (e.getActionCommand() == "REMOVE_LAYER") |
372 |
{ |
373 |
if (jList.getSelectedIndex() != -1) |
374 |
{ |
375 |
theLayers.removeLayer((String) lstModel.get(jList.getSelectedIndex()));
|
376 |
lstModel.remove(jList.getSelectedIndex()); |
377 |
mapCtrl.drawMap(); |
378 |
updateControls(null);
|
379 |
} |
380 |
} |
381 |
if (e.getActionCommand() == "EDIT_LEGEND") |
382 |
{ |
383 |
int idSelec = jList.getSelectedIndex();
|
384 |
if (idSelec != -1) |
385 |
{ |
386 |
FLayer lyr = theLayers.getLayer((String) lstModel.get(idSelec));
|
387 |
if (lyr instanceof FLyrVect) |
388 |
{ |
389 |
FLyrVect lyrVect = (FLyrVect) lyr; |
390 |
m_LegendEditor.setMapControl(mapCtrl, lyrVect); |
391 |
App.instance.getMDIContext().addView(m_LegendEditor); |
392 |
} |
393 |
else
|
394 |
{ |
395 |
JOptionPane.showMessageDialog(null, Utilities.getMessage(this,"Solo para capas vectoriales")+"."); |
396 |
} |
397 |
|
398 |
} |
399 |
|
400 |
} |
401 |
if (e.getActionCommand() == "UP") |
402 |
{ |
403 |
int idSelec = jList.getSelectedIndex();
|
404 |
int fromIndex = idSelec;
|
405 |
int toIndex = idSelec-1; |
406 |
FLayer aux = theLayers.getLayer(fromIndex); |
407 |
theLayers.moveTo(fromIndex, toIndex); |
408 |
|
409 |
lstModel.remove(fromIndex); |
410 |
lstModel.add(toIndex,aux.getName()); |
411 |
|
412 |
jList.setSelectedIndex(toIndex); |
413 |
|
414 |
m_View.getMapOverview().drawMap(); |
415 |
} |
416 |
if (e.getActionCommand() == "DOWN") |
417 |
{ |
418 |
int idSelec = jList.getSelectedIndex();
|
419 |
int fromIndex = idSelec;
|
420 |
int toIndex = idSelec+1; |
421 |
IFLayer aux = theLayers.getLayer(fromIndex); |
422 |
theLayers.moveTo(fromIndex, toIndex); |
423 |
|
424 |
lstModel.remove(fromIndex); |
425 |
lstModel.add(toIndex,aux.getName()); |
426 |
|
427 |
jList.setSelectedIndex(toIndex); |
428 |
|
429 |
m_View.getMapOverview().drawMap(); |
430 |
} |
431 |
|
432 |
|
433 |
} |
434 |
/* (non-Javadoc)
|
435 |
* @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
|
436 |
*/
|
437 |
public ViewInfo getViewInfo() {
|
438 |
if (m_viewinfo==null){ |
439 |
m_viewinfo=new ViewInfo();
|
440 |
//vi.setFeatures(ViewInfo.MODAL);
|
441 |
m_viewinfo.setResizable(false);
|
442 |
m_viewinfo.setTitle(Utilities.getMessage(this,"Configurar_localizador")); |
443 |
} |
444 |
return m_viewinfo;
|
445 |
} |
446 |
/**
|
447 |
* @see com.iver.mdiApp.ui.MDIManager.View#viewActivated()
|
448 |
*/
|
449 |
public void viewActivated() { |
450 |
} |
451 |
|
452 |
} // @jve:visual-info decl-index=0 visual-constraint="10,10"
|