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