root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / gui / FPanelLocConfig.java @ 7738
History | View | Annotate | Download (12.3 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.project.documents.view.gui; |
48 |
|
49 |
import java.awt.Color; |
50 |
import java.awt.FlowLayout; |
51 |
import java.awt.event.ActionEvent; |
52 |
import java.awt.event.ActionListener; |
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 |
import javax.swing.plaf.basic.BasicArrowButton; |
60 |
|
61 |
import org.cresques.cts.IProjection; |
62 |
import org.gvsig.gui.beans.swing.JButton; |
63 |
|
64 |
import com.iver.andami.PluginServices; |
65 |
import com.iver.andami.ui.mdiManager.IWindow; |
66 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
67 |
import com.iver.cit.gvsig.AddLayer; |
68 |
import com.iver.cit.gvsig.fmap.DriverException; |
69 |
import com.iver.cit.gvsig.fmap.MapControl; |
70 |
import com.iver.cit.gvsig.fmap.layers.CancelationException; |
71 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
72 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
73 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable; |
74 |
import com.iver.cit.gvsig.project.documents.view.MapOverview; |
75 |
import com.iver.cit.gvsig.project.documents.view.legend.gui.FThemeManagerWindow; |
76 |
|
77 |
/**
|
78 |
* @author FJP
|
79 |
*
|
80 |
* TODO To change the template for this generated type comment go to
|
81 |
* Window - Preferences - Java - Code Generation - Code and Comments
|
82 |
*/
|
83 |
public class FPanelLocConfig extends JPanel implements ActionListener,IWindow { |
84 |
private javax.swing.JLabel jLabel = null; |
85 |
private javax.swing.JList jList = null; // @jve:decl-index=0:visual-constraint="390,10" |
86 |
private JButton jBtnAddLayer = null; // |
87 |
private JButton jBtnRemoveLayer = null; |
88 |
private JButton jBtnEditLegend = null; |
89 |
private JButton jBtnCancel = null; |
90 |
|
91 |
//private JDialog m_Owner;
|
92 |
private MapControl mapCtrl;
|
93 |
private WindowInfo m_viewinfo = null; |
94 |
private JPanel pnlButtons = null; // @jve:decl-index=0:visual-constraint="10,159" |
95 |
private BasicArrowButton jBtnUp; |
96 |
private BasicArrowButton jBtnDown; |
97 |
/**
|
98 |
* This is the default constructor
|
99 |
*/
|
100 |
public FPanelLocConfig( MapControl mc) {
|
101 |
super();
|
102 |
mapCtrl = mc; |
103 |
initialize(); |
104 |
refreshList(); |
105 |
updateControls(null);
|
106 |
} |
107 |
|
108 |
private void refreshList() |
109 |
{ |
110 |
DefaultListModel lstModel = (DefaultListModel) getJList().getModel(); |
111 |
lstModel.clear(); |
112 |
for (int i=mapCtrl.getMapContext().getLayers().getLayersCount()-1; i >=0; i--) |
113 |
{ |
114 |
FLayer lyr = mapCtrl.getMapContext().getLayers().getLayer(i); |
115 |
lstModel.addElement(lyr.getName()); |
116 |
} |
117 |
} |
118 |
|
119 |
/**
|
120 |
* This method initializes this
|
121 |
*
|
122 |
* @return void
|
123 |
*/
|
124 |
private void initialize() { |
125 |
this.setLayout(null); |
126 |
this.setSize(550, 200); |
127 |
// this.setPreferredSize(new java.awt.Dimension(370,200));
|
128 |
this.add(getJLabel(), null); |
129 |
this.add(getJList(), null); |
130 |
this.add(getJBtnUp(), null); |
131 |
this.add(getJBtnDown(), null); |
132 |
this.add(getJPanel(), null); |
133 |
} |
134 |
/**
|
135 |
|
136 |
* This method initializes jLabel
|
137 |
|
138 |
*
|
139 |
|
140 |
* @return javax.swing.JLabel
|
141 |
|
142 |
*/
|
143 |
private javax.swing.JLabel getJLabel() {
|
144 |
if (jLabel == null) { |
145 |
jLabel = new javax.swing.JLabel();
|
146 |
jLabel.setText(PluginServices.getText(this,"Capas_del_localizador")+":"); |
147 |
jLabel.setBounds(10, 15, 132, 25); |
148 |
} |
149 |
return jLabel;
|
150 |
} |
151 |
|
152 |
/**
|
153 |
|
154 |
* This method initializes jList
|
155 |
|
156 |
*
|
157 |
|
158 |
* @return javax.swing.JList
|
159 |
|
160 |
*/
|
161 |
private javax.swing.JList getJList() {
|
162 |
if (jList == null) { |
163 |
jList = new javax.swing.JList(new DefaultListModel()); |
164 |
jList.setBounds(10, 49, 357, 139); |
165 |
jList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); |
166 |
jList.setBorder(BorderFactory.createLineBorder(Color.BLACK)); |
167 |
jList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
|
168 |
|
169 |
public void valueChanged(javax.swing.event.ListSelectionEvent e) { |
170 |
updateControls(e); |
171 |
} |
172 |
}); |
173 |
|
174 |
} |
175 |
return jList;
|
176 |
} |
177 |
|
178 |
private void updateControls(javax.swing.event.ListSelectionEvent e) |
179 |
{ |
180 |
System.out.println("valueChanged()"); // TODO Auto-generated Event stub valueChanged() |
181 |
DefaultListModel lstModel = (DefaultListModel) getJList().getModel(); |
182 |
int selIndex = jList.getSelectedIndex();
|
183 |
jBtnDown.setEnabled(false);
|
184 |
jBtnUp.setEnabled(false);
|
185 |
|
186 |
if (selIndex != -1) |
187 |
{ |
188 |
if (lstModel.getSize() > 1) |
189 |
{ |
190 |
if (selIndex < (lstModel.getSize()-1)) |
191 |
jBtnDown.setEnabled(true);
|
192 |
|
193 |
if (selIndex > 0) |
194 |
jBtnUp.setEnabled(true);
|
195 |
} |
196 |
|
197 |
} |
198 |
|
199 |
|
200 |
} |
201 |
|
202 |
/**
|
203 |
|
204 |
* This method initializes jBtnUp
|
205 |
|
206 |
*
|
207 |
|
208 |
* @return JButton
|
209 |
|
210 |
*/
|
211 |
private BasicArrowButton getJBtnUp() { |
212 |
if (jBtnUp == null) { |
213 |
jBtnUp = new javax.swing.plaf.basic.BasicArrowButton(
|
214 |
javax.swing.SwingConstants.NORTH); |
215 |
jBtnUp.setBounds(374, 49, 25, 23); |
216 |
jBtnUp.setToolTipText(PluginServices.getText(this,"Subir_capa")); |
217 |
jBtnUp.addActionListener(this);
|
218 |
jBtnUp.setActionCommand("UP");
|
219 |
|
220 |
} |
221 |
return jBtnUp;
|
222 |
} |
223 |
|
224 |
/**
|
225 |
|
226 |
* This method initializes jBtnDown
|
227 |
|
228 |
*
|
229 |
|
230 |
* @return JButton
|
231 |
|
232 |
*/
|
233 |
private BasicArrowButton getJBtnDown() { |
234 |
if (jBtnDown == null) { |
235 |
jBtnDown = new javax.swing.plaf.basic.BasicArrowButton(
|
236 |
javax.swing.SwingConstants.SOUTH); |
237 |
jBtnDown.setBounds(374, 164, 25, 23); |
238 |
jBtnDown.setToolTipText(PluginServices.getText(this,"Bajar_capa")); |
239 |
jBtnDown.setActionCommand("DOWN");
|
240 |
jBtnDown.addActionListener(this);
|
241 |
} |
242 |
return jBtnDown;
|
243 |
} |
244 |
|
245 |
/**
|
246 |
|
247 |
* This method initializes jButton2
|
248 |
|
249 |
*
|
250 |
|
251 |
* @return JButton
|
252 |
|
253 |
*/
|
254 |
private JButton getJBtnAddLayer() { |
255 |
if (jBtnAddLayer == null) { |
256 |
jBtnAddLayer = new JButton(); |
257 |
jBtnAddLayer.setText(PluginServices.getText(this,"Anadir_capa")+"..."); |
258 |
jBtnAddLayer.addActionListener(this);
|
259 |
jBtnAddLayer.setActionCommand("ADD_LAYER");
|
260 |
} |
261 |
return jBtnAddLayer;
|
262 |
} |
263 |
|
264 |
/**
|
265 |
|
266 |
* This method initializes jBtnRemoveLayer
|
267 |
|
268 |
*
|
269 |
|
270 |
* @return JButton
|
271 |
|
272 |
*/
|
273 |
private JButton getJBtnRemoveLayer() { |
274 |
if (jBtnRemoveLayer == null) { |
275 |
jBtnRemoveLayer = new JButton(); |
276 |
jBtnRemoveLayer.setText(PluginServices.getText(this,"Quitar_capa")+"..."); |
277 |
jBtnRemoveLayer.addActionListener(this);
|
278 |
jBtnRemoveLayer.setActionCommand("REMOVE_LAYER");
|
279 |
|
280 |
} |
281 |
return jBtnRemoveLayer;
|
282 |
} |
283 |
|
284 |
/**
|
285 |
|
286 |
* This method initializes jBtnEditLegend
|
287 |
|
288 |
*
|
289 |
|
290 |
* @return JButton
|
291 |
|
292 |
*/
|
293 |
private JButton getJBtnEditLegend() { |
294 |
if (jBtnEditLegend == null) { |
295 |
jBtnEditLegend = new JButton(); |
296 |
jBtnEditLegend.setText(PluginServices.getText(this,"Editar_leyenda")+"..."); |
297 |
jBtnEditLegend.addActionListener(this);
|
298 |
jBtnEditLegend.setActionCommand("EDIT_LEGEND");
|
299 |
} |
300 |
return jBtnEditLegend;
|
301 |
} |
302 |
|
303 |
/**
|
304 |
|
305 |
* This method initializes jBtnCancel
|
306 |
|
307 |
*
|
308 |
|
309 |
* @return JButton
|
310 |
|
311 |
*/
|
312 |
private JButton getJBtnCancel() { |
313 |
if (jBtnCancel == null) { |
314 |
jBtnCancel = new JButton(); |
315 |
jBtnCancel.setText(PluginServices.getText(this,"Cerrar")); |
316 |
jBtnCancel.setActionCommand("CANCEL");
|
317 |
jBtnCancel.addActionListener(this);
|
318 |
|
319 |
} |
320 |
return jBtnCancel;
|
321 |
} |
322 |
|
323 |
/* (non-Javadoc)
|
324 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
325 |
*/
|
326 |
public void actionPerformed(ActionEvent e) |
327 |
{ |
328 |
DefaultListModel lstModel = (DefaultListModel) getJList().getModel(); |
329 |
FLayers theLayers = mapCtrl.getMapContext().getLayers(); |
330 |
IProjection proj = null;
|
331 |
|
332 |
int numLayers = theLayers.getLayersCount()-1; |
333 |
|
334 |
if (e.getActionCommand() == "CANCEL") |
335 |
{ |
336 |
if (PluginServices.getMainFrame() != null) |
337 |
{ |
338 |
PluginServices.getMDIManager().closeWindow(FPanelLocConfig.this); |
339 |
} |
340 |
else
|
341 |
{ |
342 |
((JDialog) (getParent().getParent().getParent().getParent())).dispose();
|
343 |
} |
344 |
} |
345 |
if (e.getActionCommand() == "ADD_LAYER") |
346 |
{ |
347 |
AddLayer addLayer = (AddLayer)PluginServices.getExtension( AddLayer.class);//new AddLayer();
|
348 |
//addLayer.initialize();
|
349 |
if (addLayer.addLayers(mapCtrl)) {
|
350 |
refreshList(); |
351 |
updateControls(null);
|
352 |
} |
353 |
|
354 |
|
355 |
} |
356 |
if (e.getActionCommand() == "REMOVE_LAYER") |
357 |
{ |
358 |
if (jList.getSelectedIndex() != -1) |
359 |
{ |
360 |
theLayers.removeLayer((String) lstModel.get(jList.getSelectedIndex()));
|
361 |
lstModel.remove(jList.getSelectedIndex()); |
362 |
///mapCtrl.drawMap();
|
363 |
updateControls(null);
|
364 |
if (mapCtrl instanceof MapOverview){ |
365 |
((MapOverview)mapCtrl).refreshExtent(); |
366 |
} |
367 |
} |
368 |
} |
369 |
if (e.getActionCommand() == "EDIT_LEGEND") |
370 |
{ |
371 |
int idSelec = jList.getSelectedIndex();
|
372 |
if (idSelec != -1) |
373 |
{ |
374 |
FLayer lyr = theLayers.getLayer((String) lstModel.get(idSelec));
|
375 |
if (lyr instanceof Classifiable) |
376 |
{ |
377 |
FThemeManagerWindow m_LegendEditor = new FThemeManagerWindow();
|
378 |
try {
|
379 |
theLayers.setActive(false);
|
380 |
lyr.setActive(true);
|
381 |
m_LegendEditor.setMapContext(mapCtrl.getMapContext()); |
382 |
} catch (DriverException e1) {
|
383 |
// TODO Auto-generated catch block
|
384 |
e1.printStackTrace(); |
385 |
} |
386 |
if (PluginServices.getMainFrame() == null) { |
387 |
JDialog dlg = new JDialog(); |
388 |
|
389 |
m_LegendEditor.setPreferredSize(m_LegendEditor.getSize()); |
390 |
dlg.getContentPane().add(m_LegendEditor); |
391 |
dlg.setModal(true);
|
392 |
dlg.pack(); |
393 |
dlg.show(); |
394 |
|
395 |
} else {
|
396 |
PluginServices.getMDIManager().addWindow(m_LegendEditor); |
397 |
} |
398 |
} |
399 |
else
|
400 |
{ |
401 |
JOptionPane.showMessageDialog(null, PluginServices.getText(this,"Solo_para_capas_vectoriales")+"."); |
402 |
} |
403 |
|
404 |
} |
405 |
|
406 |
} |
407 |
if (e.getActionCommand() == "UP") |
408 |
{ |
409 |
int idSelec = jList.getSelectedIndex();
|
410 |
int fromIndex = idSelec;
|
411 |
int toIndex = idSelec-1; |
412 |
FLayer aux = theLayers.getLayer((String) lstModel.get(fromIndex));
|
413 |
try {
|
414 |
theLayers.moveTo(numLayers-fromIndex, numLayers-toIndex); |
415 |
} catch (CancelationException e1) {
|
416 |
e1.printStackTrace(); |
417 |
} |
418 |
|
419 |
lstModel.remove(fromIndex); |
420 |
lstModel.add(toIndex,aux.getName()); |
421 |
|
422 |
jList.setSelectedIndex(toIndex); |
423 |
|
424 |
///mapCtrl.drawMap();
|
425 |
} |
426 |
if (e.getActionCommand() == "DOWN") |
427 |
{ |
428 |
int idSelec = jList.getSelectedIndex();
|
429 |
int fromIndex = idSelec;
|
430 |
int toIndex = idSelec+1; |
431 |
FLayer aux = theLayers.getLayer((String) lstModel.get(fromIndex));
|
432 |
try {
|
433 |
theLayers.moveTo(numLayers-fromIndex, numLayers-toIndex); |
434 |
} catch (CancelationException e1) {
|
435 |
e1.printStackTrace(); |
436 |
} |
437 |
|
438 |
lstModel.remove(fromIndex); |
439 |
lstModel.add(toIndex,aux.getName()); |
440 |
|
441 |
jList.setSelectedIndex(toIndex); |
442 |
|
443 |
///mapCtrl.drawMap();
|
444 |
} |
445 |
|
446 |
|
447 |
} |
448 |
/* (non-Javadoc)
|
449 |
* @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
|
450 |
*/
|
451 |
public WindowInfo getWindowInfo() {
|
452 |
if (m_viewinfo==null){ |
453 |
m_viewinfo=new WindowInfo(WindowInfo.MODALDIALOG);
|
454 |
m_viewinfo.setTitle(PluginServices.getText(this,"Configurar_localizador")); |
455 |
m_viewinfo.setWidth(this.getWidth()+8); |
456 |
m_viewinfo.setHeight(this.getHeight()+8); |
457 |
} |
458 |
return m_viewinfo;
|
459 |
} |
460 |
/**
|
461 |
* @see com.iver.mdiApp.ui.MDIManager.IWindow#windowActivated()
|
462 |
*/
|
463 |
public void viewActivated() { |
464 |
} |
465 |
|
466 |
/**
|
467 |
* This method initializes jPanel
|
468 |
*
|
469 |
* @return javax.swing.JPanel
|
470 |
*/
|
471 |
private JPanel getJPanel() { |
472 |
if (pnlButtons == null) { |
473 |
pnlButtons = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 5)); |
474 |
pnlButtons.setBounds(new java.awt.Rectangle(0,200, this.getWidth(),37)); |
475 |
pnlButtons.add(getJBtnAddLayer(), null);
|
476 |
pnlButtons.add(getJBtnRemoveLayer(), null);
|
477 |
pnlButtons.add(getJBtnEditLegend(), null);
|
478 |
pnlButtons.add(getJBtnCancel(), null);
|
479 |
} |
480 |
return pnlButtons;
|
481 |
} |
482 |
|
483 |
} // @jve:visual-info decl-index=0 visual-constraint="10,10"
|