svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / project / documents / view / gui / FPanelLocConfig.java @ 47799
History | View | Annotate | Download (15.7 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
package org.gvsig.app.project.documents.view.gui; |
25 |
|
26 |
import java.awt.BorderLayout; |
27 |
import java.awt.Color; |
28 |
import java.awt.GridLayout; |
29 |
import java.awt.event.ActionEvent; |
30 |
import java.awt.event.ActionListener; |
31 |
|
32 |
import javax.swing.BorderFactory; |
33 |
import javax.swing.DefaultListModel; |
34 |
import javax.swing.JButton; |
35 |
import javax.swing.JDialog; |
36 |
import javax.swing.JLabel; |
37 |
import javax.swing.JOptionPane; |
38 |
import javax.swing.JPanel; |
39 |
import javax.swing.SwingUtilities; |
40 |
import javax.swing.plaf.basic.BasicArrowButton; |
41 |
|
42 |
import org.slf4j.Logger; |
43 |
import org.slf4j.LoggerFactory; |
44 |
|
45 |
import org.gvsig.andami.PluginServices; |
46 |
import org.gvsig.andami.ui.mdiManager.IWindow; |
47 |
import org.gvsig.andami.ui.mdiManager.WindowInfo; |
48 |
import org.gvsig.app.extension.AddLayer; |
49 |
import org.gvsig.app.project.documents.view.MapOverview; |
50 |
import org.gvsig.app.project.documents.view.ViewDocument; |
51 |
import org.gvsig.fmap.mapcontext.layers.CancelationException; |
52 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
53 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
54 |
import org.gvsig.fmap.mapcontext.layers.operations.Classifiable; |
55 |
import org.gvsig.fmap.mapcontrol.MapControl; |
56 |
import org.gvsig.tools.ToolsLocator; |
57 |
import org.gvsig.tools.swing.api.ToolsSwingLocator; |
58 |
import org.gvsig.tools.swing.api.windowmanager.WindowManager; |
59 |
|
60 |
/**
|
61 |
* @author FJP
|
62 |
*
|
63 |
* TODO To change the template for this generated type comment go to
|
64 |
* Window - Preferences - Java - Code Generation - Code and Comments
|
65 |
*/
|
66 |
public class FPanelLocConfig extends JPanel implements ActionListener, IWindow { |
67 |
|
68 |
private static Logger logger = LoggerFactory.getLogger(FPanelLocConfig.class); |
69 |
private static final long serialVersionUID = -3331364698732098356L; |
70 |
private javax.swing.JLabel jLabel = null; |
71 |
private javax.swing.JList jList = null; // @jve:decl-index=0:visual-constraint="390,10" |
72 |
private JButton jBtnAddLayer = null; // |
73 |
private JButton jBtnRemoveLayer = null; |
74 |
private JButton jBtnEditLegend = null; |
75 |
private JButton jBtnCancel = null; |
76 |
|
77 |
private MapControl mapCtrl;
|
78 |
private WindowInfo m_viewinfo = null; |
79 |
private JPanel pnlButtons = null; // @jve:decl-index=0:visual-constraint="10,159" |
80 |
private BasicArrowButton jBtnUp; |
81 |
private BasicArrowButton jBtnDown; |
82 |
|
83 |
/**
|
84 |
* This is the default constructor
|
85 |
*/
|
86 |
public FPanelLocConfig(MapControl mc) {
|
87 |
super();
|
88 |
mapCtrl = mc; |
89 |
initialize(); |
90 |
refreshList(); |
91 |
updateControls(null);
|
92 |
} |
93 |
|
94 |
private void refreshList() { |
95 |
|
96 |
DefaultListModel listModel = (DefaultListModel) getJList().getModel(); |
97 |
listModel.removeAllElements(); |
98 |
|
99 |
int index = 0; |
100 |
for (int i = mapCtrl.getMapContext().getLayers().getLayersCount() - 1; i >= 0; i--) { |
101 |
FLayer lyr = mapCtrl.getMapContext().getLayers().getLayer(i); |
102 |
listModel.add(index++, new LayerListItem(lyr));
|
103 |
} |
104 |
} |
105 |
|
106 |
|
107 |
/**
|
108 |
* This method initializes this
|
109 |
*
|
110 |
* @return void
|
111 |
*/
|
112 |
private void initialize() { |
113 |
|
114 |
this.setLayout(new BorderLayout()); |
115 |
|
116 |
this.add(getJLabel(), BorderLayout.NORTH); |
117 |
this.add(getJList(), BorderLayout.CENTER); |
118 |
|
119 |
JPanel eastp = new JPanel(new BorderLayout()); |
120 |
eastp.add(getJBtnUp(), BorderLayout.NORTH);
|
121 |
eastp.add(getJBtnDown(), BorderLayout.SOUTH);
|
122 |
this.add(eastp, BorderLayout.EAST); |
123 |
|
124 |
this.add(getJPanel(), BorderLayout.SOUTH); |
125 |
} |
126 |
|
127 |
/**
|
128 |
* This method initializes jLabel
|
129 |
*
|
130 |
* @return javax.swing.JLabel
|
131 |
*/
|
132 |
private javax.swing.JLabel getJLabel() {
|
133 |
if (jLabel == null) { |
134 |
jLabel = new javax.swing.JLabel();
|
135 |
|
136 |
jLabel.setBorder(BorderFactory.createEmptyBorder(8,4,8,8)); |
137 |
|
138 |
jLabel.setText(PluginServices |
139 |
.getText(this, "Capas_del_localizador") + ":"); |
140 |
} |
141 |
return jLabel;
|
142 |
} |
143 |
|
144 |
/**
|
145 |
* This method initializes jList
|
146 |
*
|
147 |
* @return javax.swing.JList
|
148 |
*/
|
149 |
public javax.swing.JList getJList() {
|
150 |
if (jList == null) { |
151 |
|
152 |
jList = new javax.swing.JList(new DefaultListModel()); |
153 |
jList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); |
154 |
jList.setBorder(BorderFactory.createLineBorder(Color.BLACK)); |
155 |
jList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
|
156 |
|
157 |
public void valueChanged( |
158 |
javax.swing.event.ListSelectionEvent e) { |
159 |
updateControls(e); |
160 |
} |
161 |
}); |
162 |
|
163 |
} |
164 |
return jList;
|
165 |
} |
166 |
|
167 |
private void updateControls(javax.swing.event.ListSelectionEvent e) { |
168 |
|
169 |
DefaultListModel lstModel = (DefaultListModel) getJList().getModel(); |
170 |
|
171 |
int selIndex = jList.getSelectedIndex();
|
172 |
jBtnDown.setEnabled(false);
|
173 |
jBtnUp.setEnabled(false);
|
174 |
|
175 |
if (selIndex != -1) { |
176 |
if (lstModel.getSize() > 1) { |
177 |
if (selIndex < (lstModel.getSize() - 1)) { |
178 |
jBtnDown.setEnabled(true);
|
179 |
} |
180 |
|
181 |
if (selIndex > 0) { |
182 |
jBtnUp.setEnabled(true);
|
183 |
} |
184 |
} |
185 |
} |
186 |
|
187 |
jBtnRemoveLayer.setEnabled(selIndex != -1);
|
188 |
jBtnEditLegend.setEnabled(selIndex != -1);
|
189 |
} |
190 |
|
191 |
/**
|
192 |
* This method initializes jBtnUp
|
193 |
*
|
194 |
* @return JButton
|
195 |
*/
|
196 |
private BasicArrowButton getJBtnUp() { |
197 |
if (jBtnUp == null) { |
198 |
jBtnUp = |
199 |
new javax.swing.plaf.basic.BasicArrowButton(
|
200 |
javax.swing.SwingConstants.NORTH); |
201 |
jBtnUp.setToolTipText(PluginServices.getText(this, "Subir_capa")); |
202 |
jBtnUp.addActionListener(this);
|
203 |
jBtnUp.setActionCommand("UP");
|
204 |
|
205 |
} |
206 |
return jBtnUp;
|
207 |
} |
208 |
|
209 |
/**
|
210 |
* This method initializes jBtnDown
|
211 |
*
|
212 |
* @return JButton
|
213 |
*/
|
214 |
private BasicArrowButton getJBtnDown() { |
215 |
if (jBtnDown == null) { |
216 |
jBtnDown = |
217 |
new javax.swing.plaf.basic.BasicArrowButton(
|
218 |
javax.swing.SwingConstants.SOUTH); |
219 |
jBtnDown.setToolTipText(PluginServices.getText(this, "Bajar_capa")); |
220 |
jBtnDown.setActionCommand("DOWN");
|
221 |
jBtnDown.addActionListener(this);
|
222 |
} |
223 |
return jBtnDown;
|
224 |
} |
225 |
|
226 |
/**
|
227 |
* This method initializes jButton2
|
228 |
*
|
229 |
* @return JButton
|
230 |
*/
|
231 |
private JButton getJBtnAddLayer() { |
232 |
if (jBtnAddLayer == null) { |
233 |
jBtnAddLayer = |
234 |
ToolsSwingLocator.getUsabilitySwingManager().createJButton(); |
235 |
jBtnAddLayer.setText(PluginServices.getText(this, "Anadir_capa") |
236 |
+ "...");
|
237 |
jBtnAddLayer.addActionListener(this);
|
238 |
jBtnAddLayer.setActionCommand("ADD_LAYER");
|
239 |
} |
240 |
return jBtnAddLayer;
|
241 |
} |
242 |
|
243 |
/**
|
244 |
* This method initializes jBtnRemoveLayer
|
245 |
*
|
246 |
* @return JButton
|
247 |
*/
|
248 |
private JButton getJBtnRemoveLayer() { |
249 |
if (jBtnRemoveLayer == null) { |
250 |
jBtnRemoveLayer = |
251 |
ToolsSwingLocator.getUsabilitySwingManager().createJButton(); |
252 |
jBtnRemoveLayer.setText(PluginServices.getText(this, "Quitar_capa")); |
253 |
jBtnRemoveLayer.addActionListener(this);
|
254 |
jBtnRemoveLayer.setActionCommand("REMOVE_LAYER");
|
255 |
|
256 |
} |
257 |
return jBtnRemoveLayer;
|
258 |
} |
259 |
|
260 |
/**
|
261 |
* This method initializes jBtnEditLegend
|
262 |
*
|
263 |
* @return JButton
|
264 |
*/
|
265 |
private JButton getJBtnEditLegend() { |
266 |
if (jBtnEditLegend == null) { |
267 |
jBtnEditLegend = |
268 |
ToolsSwingLocator.getUsabilitySwingManager().createJButton(); |
269 |
jBtnEditLegend.setText(PluginServices.getText(this,
|
270 |
"Editar_leyenda") + "..."); |
271 |
jBtnEditLegend.addActionListener(this);
|
272 |
jBtnEditLegend.setActionCommand("EDIT_LEGEND");
|
273 |
} |
274 |
return jBtnEditLegend;
|
275 |
} |
276 |
|
277 |
/**
|
278 |
* This method initializes jBtnCancel
|
279 |
*
|
280 |
* @return JButton
|
281 |
*/
|
282 |
private JButton getJBtnCancel() { |
283 |
if (jBtnCancel == null) { |
284 |
jBtnCancel = |
285 |
ToolsSwingLocator.getUsabilitySwingManager().createJButton(); |
286 |
jBtnCancel.setText(PluginServices.getText(this, "Cerrar")); |
287 |
jBtnCancel.setActionCommand("CANCEL");
|
288 |
jBtnCancel.addActionListener(this);
|
289 |
|
290 |
} |
291 |
return jBtnCancel;
|
292 |
} |
293 |
|
294 |
public void actionPerformed(ActionEvent e) { |
295 |
DefaultListModel lstModel = (DefaultListModel) getJList().getModel(); |
296 |
FLayers theLayers = mapCtrl.getMapContext().getLayers(); |
297 |
|
298 |
int numLayers = theLayers.getLayersCount() - 1; |
299 |
|
300 |
if (e.getActionCommand() == "CANCEL") { |
301 |
if (PluginServices.getMainFrame() != null) { |
302 |
PluginServices.getMDIManager() |
303 |
.closeWindow(FPanelLocConfig.this); |
304 |
} else {
|
305 |
((JDialog) (getParent().getParent().getParent().getParent()))
|
306 |
.dispose(); |
307 |
} |
308 |
} |
309 |
if (e.getActionCommand() == "ADD_LAYER") { |
310 |
AddLayer addLayer = |
311 |
(AddLayer) PluginServices.getExtension(AddLayer.class); |
312 |
|
313 |
addLayer.addLayers(mapCtrl, true);
|
314 |
// if (addLayer.addLayers(mapCtrl, true)) {
|
315 |
// RefreshThread st = new RefreshThread(500);
|
316 |
// st.start();
|
317 |
// }
|
318 |
try {
|
319 |
refreshList(); |
320 |
updateControls(null);
|
321 |
} catch (Exception exc) { |
322 |
logger.info("Error while refreshing components.", exc);
|
323 |
} |
324 |
|
325 |
if (mapCtrl instanceof MapOverview) { |
326 |
((MapOverview) mapCtrl).refreshExtent(); |
327 |
} |
328 |
|
329 |
} |
330 |
if (e.getActionCommand() == "REMOVE_LAYER") { |
331 |
if (jList.getSelectedIndex() != -1) { |
332 |
|
333 |
LayerListItem lli = (LayerListItem) |
334 |
lstModel.get(jList.getSelectedIndex()); |
335 |
|
336 |
theLayers.removeLayer(lli.getLayer()); |
337 |
|
338 |
lstModel.remove(jList.getSelectedIndex()); |
339 |
|
340 |
updateControls(null);
|
341 |
if (mapCtrl instanceof MapOverview) { |
342 |
((MapOverview) mapCtrl).refreshExtent(); |
343 |
} |
344 |
} |
345 |
} |
346 |
if (e.getActionCommand() == "EDIT_LEGEND") { |
347 |
int idSelec = jList.getSelectedIndex();
|
348 |
if (idSelec != -1) { |
349 |
|
350 |
LayerListItem lli = (LayerListItem) lstModel.get(idSelec); |
351 |
FLayer lyr = lli.getLayer(); |
352 |
|
353 |
if (lyr instanceof Classifiable) { |
354 |
LayerProperties dlg = new LayerProperties(lyr);
|
355 |
WindowManager wm = ToolsSwingLocator.getWindowManager(); |
356 |
wm.showWindow( |
357 |
dlg.asJComponent(), |
358 |
ToolsLocator.getI18nManager().getTranslation("propiedades_de_la_capa"),
|
359 |
WindowManager.MODE.DIALOG |
360 |
); |
361 |
|
362 |
} else {
|
363 |
JOptionPane.showMessageDialog(
|
364 |
null,
|
365 |
PluginServices.getText(this,
|
366 |
"Solo_para_capas_vectoriales") + "."); |
367 |
} |
368 |
|
369 |
} |
370 |
|
371 |
} |
372 |
if (e.getActionCommand() == "UP") { |
373 |
int idSelec = jList.getSelectedIndex();
|
374 |
int fromIndex = idSelec;
|
375 |
int toIndex = idSelec - 1; |
376 |
|
377 |
LayerListItem lli = (LayerListItem) lstModel.get(fromIndex); |
378 |
|
379 |
try {
|
380 |
theLayers.moveTo(numLayers - fromIndex, numLayers - toIndex); |
381 |
} catch (CancelationException e1) {
|
382 |
e1.printStackTrace(); |
383 |
} |
384 |
|
385 |
lstModel.remove(fromIndex); |
386 |
lstModel.add(toIndex, lli); |
387 |
|
388 |
jList.setSelectedIndex(toIndex); |
389 |
} |
390 |
if (e.getActionCommand() == "DOWN") { |
391 |
int idSelec = jList.getSelectedIndex();
|
392 |
int fromIndex = idSelec;
|
393 |
int toIndex = idSelec + 1; |
394 |
|
395 |
LayerListItem lli = (LayerListItem) lstModel.get(fromIndex); |
396 |
|
397 |
try {
|
398 |
theLayers.moveTo(numLayers - fromIndex, numLayers - toIndex); |
399 |
} catch (CancelationException e1) {
|
400 |
e1.printStackTrace(); |
401 |
} |
402 |
|
403 |
lstModel.remove(fromIndex); |
404 |
lstModel.add(toIndex, lli); |
405 |
|
406 |
jList.setSelectedIndex(toIndex); |
407 |
} |
408 |
|
409 |
} |
410 |
|
411 |
public WindowInfo getWindowInfo() {
|
412 |
if (m_viewinfo == null) { |
413 |
m_viewinfo = new WindowInfo(WindowInfo.MODELESSDIALOG);
|
414 |
m_viewinfo.setTitle(PluginServices.getText(this,
|
415 |
"Configurar_localizador"));
|
416 |
|
417 |
m_viewinfo.setWidth(400);
|
418 |
m_viewinfo.setHeight(200);
|
419 |
} |
420 |
return m_viewinfo;
|
421 |
} |
422 |
|
423 |
/**
|
424 |
* @see com.iver.mdiApp.ui.MDIManager.IWindow#windowActivated()
|
425 |
*/
|
426 |
public void viewActivated() { |
427 |
} |
428 |
|
429 |
/**
|
430 |
* This method initializes jPanel
|
431 |
*
|
432 |
* @return javax.swing.JPanel
|
433 |
*/
|
434 |
private JPanel getJPanel() { |
435 |
if (pnlButtons == null) { |
436 |
pnlButtons = new JPanel(new GridLayout(2, 3, 8, 4)); |
437 |
pnlButtons.setBorder(BorderFactory.createEmptyBorder(8,8,8,8)); |
438 |
|
439 |
pnlButtons.add(getJBtnAddLayer()); |
440 |
pnlButtons.add(new JLabel()); |
441 |
pnlButtons.add(new JLabel()); |
442 |
|
443 |
pnlButtons.add(getJBtnRemoveLayer()); |
444 |
pnlButtons.add(getJBtnEditLegend()); |
445 |
pnlButtons.add(getJBtnCancel()); |
446 |
} |
447 |
return pnlButtons;
|
448 |
} |
449 |
|
450 |
/**
|
451 |
* Obtiene el MapControl asociado al localizador
|
452 |
*
|
453 |
* @return MapControl
|
454 |
*/
|
455 |
public MapControl getMapCtrl() {
|
456 |
return mapCtrl;
|
457 |
} |
458 |
|
459 |
public Object getWindowProfile() { |
460 |
return WindowInfo.DIALOG_PROFILE;
|
461 |
} |
462 |
|
463 |
|
464 |
class RefreshThread extends Thread { |
465 |
|
466 |
private int waitt = 0; |
467 |
|
468 |
public RefreshThread(int t) { |
469 |
waitt = t; |
470 |
} |
471 |
public void run() { |
472 |
|
473 |
try {
|
474 |
/*
|
475 |
* We might need to wait a bit because the GUI thread needs
|
476 |
* some time to update (this is because we have used a modal dialog
|
477 |
* and we refresh after that dialog is closed)
|
478 |
*/
|
479 |
Thread.sleep(waitt);
|
480 |
} catch (Exception exc) { |
481 |
|
482 |
} |
483 |
|
484 |
SwingUtilities.invokeLater(new Runnable() { |
485 |
public void run() { |
486 |
try {
|
487 |
refreshList(); |
488 |
updateControls(null);
|
489 |
} catch (Exception exc) { |
490 |
logger.info("Error while refreshing components.", exc);
|
491 |
} |
492 |
} |
493 |
}); |
494 |
} |
495 |
} |
496 |
|
497 |
} |
498 |
|
499 |
// @jve:visual-info decl-index=0 visual-constraint="10,10"
|