svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / view / gui / FPanelLocConfig.java @ 40331
History | View | Annotate | Download (14.3 KB)
1 | 36475 | cordinyana | /* gvSIG. Geographic Information System of the Valencian Government
|
---|---|---|---|
2 | 7304 | caballero | *
|
3 | 36475 | cordinyana | * Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 | * of the Valencian Government (CIT)
|
||
5 | *
|
||
6 | 7304 | caballero | * 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 2
|
||
9 | * of the License, or (at your option) any later version.
|
||
10 | 36475 | cordinyana | *
|
11 | 7304 | caballero | * 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 | 36475 | cordinyana | *
|
16 | 7304 | caballero | * 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 | 36475 | cordinyana | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 | * MA 02110-1301, USA.
|
||
20 | *
|
||
21 | 7304 | caballero | */
|
22 | 29596 | jpiera | package org.gvsig.app.project.documents.view.gui; |
23 | 7304 | caballero | |
24 | import java.awt.Color; |
||
25 | import java.awt.FlowLayout; |
||
26 | import java.awt.event.ActionEvent; |
||
27 | import java.awt.event.ActionListener; |
||
28 | |||
29 | import javax.swing.BorderFactory; |
||
30 | import javax.swing.DefaultListModel; |
||
31 | 36475 | cordinyana | import javax.swing.JButton; |
32 | 7304 | caballero | import javax.swing.JDialog; |
33 | import javax.swing.JOptionPane; |
||
34 | import javax.swing.JPanel; |
||
35 | import javax.swing.plaf.basic.BasicArrowButton; |
||
36 | |||
37 | 29596 | jpiera | import org.gvsig.andami.PluginServices; |
38 | import org.gvsig.andami.ui.mdiManager.IWindow; |
||
39 | import org.gvsig.andami.ui.mdiManager.WindowInfo; |
||
40 | import org.gvsig.app.extension.AddLayer; |
||
41 | import org.gvsig.app.project.documents.view.MapOverview; |
||
42 | import org.gvsig.app.project.documents.view.legend.gui.ThemeManagerWindow; |
||
43 | 20994 | jmvivo | import org.gvsig.fmap.mapcontext.layers.CancelationException; |
44 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
45 | import org.gvsig.fmap.mapcontext.layers.FLayers; |
||
46 | import org.gvsig.fmap.mapcontext.layers.operations.Classifiable; |
||
47 | import org.gvsig.fmap.mapcontrol.MapControl; |
||
48 | 36475 | cordinyana | import org.gvsig.tools.swing.api.ToolsSwingLocator; |
49 | 7304 | caballero | |
50 | /**
|
||
51 | * @author FJP
|
||
52 | 36475 | cordinyana | *
|
53 | * TODO To change the template for this generated type comment go to
|
||
54 | * Window - Preferences - Java - Code Generation - Code and Comments
|
||
55 | 7304 | caballero | */
|
56 | 36475 | cordinyana | public class FPanelLocConfig extends JPanel implements ActionListener, IWindow { |
57 | 7304 | caballero | |
58 | 36475 | cordinyana | private static final long serialVersionUID = -3331364698732098356L; |
59 | private javax.swing.JLabel jLabel = null; |
||
60 | private javax.swing.JList jList = null; // @jve:decl-index=0:visual-constraint="390,10" |
||
61 | private JButton jBtnAddLayer = null; // |
||
62 | private JButton jBtnRemoveLayer = null; |
||
63 | private JButton jBtnEditLegend = null; |
||
64 | private JButton jBtnCancel = null; |
||
65 | 7304 | caballero | |
66 | 36475 | cordinyana | private MapControl mapCtrl;
|
67 | private WindowInfo m_viewinfo = null; |
||
68 | private JPanel pnlButtons = null; // @jve:decl-index=0:visual-constraint="10,159" |
||
69 | private BasicArrowButton jBtnUp; |
||
70 | private BasicArrowButton jBtnDown; |
||
71 | 7304 | caballero | |
72 | 36475 | cordinyana | /**
|
73 | * This is the default constructor
|
||
74 | */
|
||
75 | public FPanelLocConfig(MapControl mc) {
|
||
76 | super();
|
||
77 | mapCtrl = mc; |
||
78 | initialize(); |
||
79 | refreshList(); |
||
80 | updateControls(null);
|
||
81 | } |
||
82 | 7304 | caballero | |
83 | 36475 | cordinyana | private void refreshList() { |
84 | DefaultListModel lstModel = (DefaultListModel) getJList().getModel(); |
||
85 | lstModel.clear(); |
||
86 | for (int i = mapCtrl.getMapContext().getLayers().getLayersCount() - 1; i >= 0; i--) { |
||
87 | FLayer lyr = mapCtrl.getMapContext().getLayers().getLayer(i); |
||
88 | lstModel.addElement(lyr.getName()); |
||
89 | } |
||
90 | } |
||
91 | 7304 | caballero | |
92 | 36475 | cordinyana | /**
|
93 | * This method initializes this
|
||
94 | *
|
||
95 | * @return void
|
||
96 | */
|
||
97 | private void initialize() { |
||
98 | this.setLayout(null); |
||
99 | this.setSize(550, 200); |
||
100 | this.add(getJLabel(), null); |
||
101 | this.add(getJList(), null); |
||
102 | this.add(getJBtnUp(), null); |
||
103 | this.add(getJBtnDown(), null); |
||
104 | this.add(getJPanel(), null); |
||
105 | } |
||
106 | 7304 | caballero | |
107 | 36475 | cordinyana | /**
|
108 | * This method initializes jLabel
|
||
109 | *
|
||
110 | * @return javax.swing.JLabel
|
||
111 | */
|
||
112 | private javax.swing.JLabel getJLabel() {
|
||
113 | if (jLabel == null) { |
||
114 | jLabel = new javax.swing.JLabel();
|
||
115 | jLabel.setText(PluginServices |
||
116 | .getText(this, "Capas_del_localizador") + ":"); |
||
117 | jLabel.setBounds(10, 15, 132, 25); |
||
118 | } |
||
119 | return jLabel;
|
||
120 | } |
||
121 | 7304 | caballero | |
122 | 36475 | cordinyana | /**
|
123 | * This method initializes jList
|
||
124 | *
|
||
125 | * @return javax.swing.JList
|
||
126 | */
|
||
127 | public javax.swing.JList getJList() {
|
||
128 | if (jList == null) { |
||
129 | jList = new javax.swing.JList(new DefaultListModel()); |
||
130 | jList.setBounds(10, 49, 357, 139); |
||
131 | jList |
||
132 | .setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); |
||
133 | jList.setBorder(BorderFactory.createLineBorder(Color.BLACK)); |
||
134 | jList |
||
135 | .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
|
||
136 | 7304 | caballero | |
137 | 36475 | cordinyana | public void valueChanged( |
138 | javax.swing.event.ListSelectionEvent e) { |
||
139 | updateControls(e); |
||
140 | } |
||
141 | }); |
||
142 | 7304 | caballero | |
143 | 36475 | cordinyana | } |
144 | return jList;
|
||
145 | } |
||
146 | 7304 | caballero | |
147 | 36475 | cordinyana | private void updateControls(javax.swing.event.ListSelectionEvent e) { |
148 | System.out.println("valueChanged()"); // TODO Auto-generated Event stub |
||
149 | // valueChanged()
|
||
150 | DefaultListModel lstModel = (DefaultListModel) getJList().getModel(); |
||
151 | int selIndex = jList.getSelectedIndex();
|
||
152 | jBtnDown.setEnabled(false);
|
||
153 | jBtnUp.setEnabled(false);
|
||
154 | 7304 | caballero | |
155 | 36475 | cordinyana | if (selIndex != -1) { |
156 | if (lstModel.getSize() > 1) { |
||
157 | if (selIndex < (lstModel.getSize() - 1)) { |
||
158 | jBtnDown.setEnabled(true);
|
||
159 | } |
||
160 | 7304 | caballero | |
161 | 36475 | cordinyana | if (selIndex > 0) { |
162 | jBtnUp.setEnabled(true);
|
||
163 | } |
||
164 | } |
||
165 | 7304 | caballero | |
166 | 36475 | cordinyana | } |
167 | 7304 | caballero | |
168 | 36475 | cordinyana | } |
169 | 7304 | caballero | |
170 | 36475 | cordinyana | /**
|
171 | * This method initializes jBtnUp
|
||
172 | *
|
||
173 | * @return JButton
|
||
174 | */
|
||
175 | private BasicArrowButton getJBtnUp() { |
||
176 | if (jBtnUp == null) { |
||
177 | jBtnUp = |
||
178 | new javax.swing.plaf.basic.BasicArrowButton(
|
||
179 | javax.swing.SwingConstants.NORTH); |
||
180 | jBtnUp.setBounds(374, 49, 25, 23); |
||
181 | jBtnUp.setToolTipText(PluginServices.getText(this, "Subir_capa")); |
||
182 | jBtnUp.addActionListener(this);
|
||
183 | jBtnUp.setActionCommand("UP");
|
||
184 | 7304 | caballero | |
185 | 36475 | cordinyana | } |
186 | return jBtnUp;
|
||
187 | } |
||
188 | 7304 | caballero | |
189 | 36475 | cordinyana | /**
|
190 | * This method initializes jBtnDown
|
||
191 | *
|
||
192 | * @return JButton
|
||
193 | */
|
||
194 | private BasicArrowButton getJBtnDown() { |
||
195 | if (jBtnDown == null) { |
||
196 | jBtnDown = |
||
197 | new javax.swing.plaf.basic.BasicArrowButton(
|
||
198 | javax.swing.SwingConstants.SOUTH); |
||
199 | jBtnDown.setBounds(374, 164, 25, 23); |
||
200 | jBtnDown.setToolTipText(PluginServices.getText(this, "Bajar_capa")); |
||
201 | jBtnDown.setActionCommand("DOWN");
|
||
202 | jBtnDown.addActionListener(this);
|
||
203 | } |
||
204 | return jBtnDown;
|
||
205 | } |
||
206 | 7304 | caballero | |
207 | 36475 | cordinyana | /**
|
208 | * This method initializes jButton2
|
||
209 | *
|
||
210 | * @return JButton
|
||
211 | */
|
||
212 | private JButton getJBtnAddLayer() { |
||
213 | if (jBtnAddLayer == null) { |
||
214 | jBtnAddLayer = |
||
215 | ToolsSwingLocator.getUsabilitySwingManager().createJButton(); |
||
216 | jBtnAddLayer.setText(PluginServices.getText(this, "Anadir_capa") |
||
217 | + "...");
|
||
218 | jBtnAddLayer.addActionListener(this);
|
||
219 | jBtnAddLayer.setActionCommand("ADD_LAYER");
|
||
220 | } |
||
221 | return jBtnAddLayer;
|
||
222 | } |
||
223 | 7304 | caballero | |
224 | 36475 | cordinyana | /**
|
225 | * This method initializes jBtnRemoveLayer
|
||
226 | *
|
||
227 | * @return JButton
|
||
228 | */
|
||
229 | private JButton getJBtnRemoveLayer() { |
||
230 | if (jBtnRemoveLayer == null) { |
||
231 | jBtnRemoveLayer = |
||
232 | ToolsSwingLocator.getUsabilitySwingManager().createJButton(); |
||
233 | jBtnRemoveLayer.setText(PluginServices.getText(this, "Quitar_capa") |
||
234 | + "...");
|
||
235 | jBtnRemoveLayer.addActionListener(this);
|
||
236 | jBtnRemoveLayer.setActionCommand("REMOVE_LAYER");
|
||
237 | 7304 | caballero | |
238 | 36475 | cordinyana | } |
239 | return jBtnRemoveLayer;
|
||
240 | } |
||
241 | 7304 | caballero | |
242 | 36475 | cordinyana | /**
|
243 | * This method initializes jBtnEditLegend
|
||
244 | *
|
||
245 | * @return JButton
|
||
246 | */
|
||
247 | private JButton getJBtnEditLegend() { |
||
248 | if (jBtnEditLegend == null) { |
||
249 | jBtnEditLegend = |
||
250 | ToolsSwingLocator.getUsabilitySwingManager().createJButton(); |
||
251 | jBtnEditLegend.setText(PluginServices.getText(this,
|
||
252 | "Editar_leyenda") + "..."); |
||
253 | jBtnEditLegend.addActionListener(this);
|
||
254 | jBtnEditLegend.setActionCommand("EDIT_LEGEND");
|
||
255 | } |
||
256 | return jBtnEditLegend;
|
||
257 | } |
||
258 | 7304 | caballero | |
259 | 36475 | cordinyana | /**
|
260 | * This method initializes jBtnCancel
|
||
261 | *
|
||
262 | * @return JButton
|
||
263 | */
|
||
264 | private JButton getJBtnCancel() { |
||
265 | if (jBtnCancel == null) { |
||
266 | jBtnCancel = |
||
267 | ToolsSwingLocator.getUsabilitySwingManager().createJButton(); |
||
268 | jBtnCancel.setText(PluginServices.getText(this, "Cerrar")); |
||
269 | jBtnCancel.setActionCommand("CANCEL");
|
||
270 | jBtnCancel.addActionListener(this);
|
||
271 | 7304 | caballero | |
272 | 36475 | cordinyana | } |
273 | return jBtnCancel;
|
||
274 | } |
||
275 | 7304 | caballero | |
276 | 36475 | cordinyana | public void actionPerformed(ActionEvent e) { |
277 | DefaultListModel lstModel = (DefaultListModel) getJList().getModel(); |
||
278 | FLayers theLayers = mapCtrl.getMapContext().getLayers(); |
||
279 | 7304 | caballero | |
280 | 36475 | cordinyana | int numLayers = theLayers.getLayersCount() - 1; |
281 | 7304 | caballero | |
282 | 36475 | cordinyana | if (e.getActionCommand() == "CANCEL") { |
283 | if (PluginServices.getMainFrame() != null) { |
||
284 | PluginServices.getMDIManager() |
||
285 | .closeWindow(FPanelLocConfig.this); |
||
286 | } else {
|
||
287 | ((JDialog) (getParent().getParent().getParent().getParent()))
|
||
288 | .dispose(); |
||
289 | } |
||
290 | } |
||
291 | if (e.getActionCommand() == "ADD_LAYER") { |
||
292 | AddLayer addLayer = |
||
293 | (AddLayer) PluginServices.getExtension(AddLayer.class);// new
|
||
294 | // AddLayer();
|
||
295 | // addLayer.initialize();
|
||
296 | 7304 | caballero | if (addLayer.addLayers(mapCtrl)) {
|
297 | 36475 | cordinyana | refreshList(); |
298 | updateControls(null);
|
||
299 | 7304 | caballero | } |
300 | 36475 | cordinyana | if (mapCtrl instanceof MapOverview) { |
301 | ((MapOverview) mapCtrl).refreshExtent(); |
||
302 | 9439 | caballero | } |
303 | 7304 | caballero | |
304 | 36475 | cordinyana | } |
305 | if (e.getActionCommand() == "REMOVE_LAYER") { |
||
306 | if (jList.getSelectedIndex() != -1) { |
||
307 | theLayers.removeLayer((String) lstModel.get(jList
|
||
308 | .getSelectedIndex())); |
||
309 | lstModel.remove(jList.getSelectedIndex()); |
||
310 | // /mapCtrl.drawMap();
|
||
311 | updateControls(null);
|
||
312 | if (mapCtrl instanceof MapOverview) { |
||
313 | ((MapOverview) mapCtrl).refreshExtent(); |
||
314 | 7304 | caballero | } |
315 | 36475 | cordinyana | } |
316 | } |
||
317 | if (e.getActionCommand() == "EDIT_LEGEND") { |
||
318 | int idSelec = jList.getSelectedIndex();
|
||
319 | if (idSelec != -1) { |
||
320 | FLayer lyr = theLayers.getLayer((String) lstModel.get(idSelec));
|
||
321 | if (lyr instanceof Classifiable) { |
||
322 | ThemeManagerWindow m_LegendEditor = |
||
323 | new ThemeManagerWindow(lyr/* , mapCtrl.getMapContext() */); |
||
324 | theLayers.setActive(false);
|
||
325 | lyr.setActive(true);
|
||
326 | if (PluginServices.getMainFrame() == null) { |
||
327 | JDialog dlg = new JDialog(); |
||
328 | 7304 | caballero | |
329 | 36475 | cordinyana | m_LegendEditor.setPreferredSize(m_LegendEditor |
330 | .getSize()); |
||
331 | dlg.getContentPane().add(m_LegendEditor); |
||
332 | dlg.setModal(true);
|
||
333 | dlg.pack(); |
||
334 | dlg.setVisible(true);
|
||
335 | 7304 | caballero | |
336 | 36475 | cordinyana | } else {
|
337 | PluginServices.getMDIManager() |
||
338 | .addWindow(m_LegendEditor); |
||
339 | } |
||
340 | } else {
|
||
341 | JOptionPane.showMessageDialog(
|
||
342 | null,
|
||
343 | PluginServices.getText(this,
|
||
344 | "Solo_para_capas_vectoriales") + "."); |
||
345 | } |
||
346 | 7304 | caballero | |
347 | 36475 | cordinyana | } |
348 | 7304 | caballero | |
349 | 36475 | cordinyana | } |
350 | if (e.getActionCommand() == "UP") { |
||
351 | int idSelec = jList.getSelectedIndex();
|
||
352 | int fromIndex = idSelec;
|
||
353 | int toIndex = idSelec - 1; |
||
354 | FLayer aux = theLayers.getLayer((String) lstModel.get(fromIndex));
|
||
355 | try {
|
||
356 | theLayers.moveTo(numLayers - fromIndex, numLayers - toIndex); |
||
357 | } catch (CancelationException e1) {
|
||
358 | e1.printStackTrace(); |
||
359 | } |
||
360 | 7304 | caballero | |
361 | 36475 | cordinyana | lstModel.remove(fromIndex); |
362 | lstModel.add(toIndex, aux.getName()); |
||
363 | 7304 | caballero | |
364 | 36475 | cordinyana | jList.setSelectedIndex(toIndex); |
365 | } |
||
366 | if (e.getActionCommand() == "DOWN") { |
||
367 | int idSelec = jList.getSelectedIndex();
|
||
368 | int fromIndex = idSelec;
|
||
369 | int toIndex = idSelec + 1; |
||
370 | FLayer aux = theLayers.getLayer((String) lstModel.get(fromIndex));
|
||
371 | try {
|
||
372 | theLayers.moveTo(numLayers - fromIndex, numLayers - toIndex); |
||
373 | } catch (CancelationException e1) {
|
||
374 | e1.printStackTrace(); |
||
375 | } |
||
376 | 7304 | caballero | |
377 | 36475 | cordinyana | lstModel.remove(fromIndex); |
378 | lstModel.add(toIndex, aux.getName()); |
||
379 | 7304 | caballero | |
380 | 36475 | cordinyana | jList.setSelectedIndex(toIndex); |
381 | } |
||
382 | 7304 | caballero | |
383 | 36475 | cordinyana | } |
384 | 7304 | caballero | |
385 | 36475 | cordinyana | public WindowInfo getWindowInfo() {
|
386 | if (m_viewinfo == null) { |
||
387 | m_viewinfo = new WindowInfo(WindowInfo.MODALDIALOG);
|
||
388 | m_viewinfo.setTitle(PluginServices.getText(this,
|
||
389 | "Configurar_localizador"));
|
||
390 | m_viewinfo.setWidth(this.getWidth() + 8); |
||
391 | m_viewinfo.setHeight(this.getHeight() + 8); |
||
392 | } |
||
393 | return m_viewinfo;
|
||
394 | } |
||
395 | 7304 | caballero | |
396 | 36475 | cordinyana | /**
|
397 | * @see com.iver.mdiApp.ui.MDIManager.IWindow#windowActivated()
|
||
398 | */
|
||
399 | public void viewActivated() { |
||
400 | } |
||
401 | 7304 | caballero | |
402 | 36475 | cordinyana | /**
|
403 | * This method initializes jPanel
|
||
404 | *
|
||
405 | * @return javax.swing.JPanel
|
||
406 | */
|
||
407 | private JPanel getJPanel() { |
||
408 | if (pnlButtons == null) { |
||
409 | pnlButtons = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 5)); |
||
410 | pnlButtons.setBounds(new java.awt.Rectangle(0, 200, |
||
411 | this.getWidth(), 37)); |
||
412 | pnlButtons.add(getJBtnAddLayer(), null);
|
||
413 | pnlButtons.add(getJBtnRemoveLayer(), null);
|
||
414 | pnlButtons.add(getJBtnEditLegend(), null);
|
||
415 | pnlButtons.add(getJBtnCancel(), null);
|
||
416 | } |
||
417 | return pnlButtons;
|
||
418 | } |
||
419 | 7304 | caballero | |
420 | 36475 | cordinyana | /**
|
421 | * Obtiene el MapControl asociado al localizador
|
||
422 | *
|
||
423 | * @return MapControl
|
||
424 | */
|
||
425 | public MapControl getMapCtrl() {
|
||
426 | return mapCtrl;
|
||
427 | } |
||
428 | 7304 | caballero | |
429 | 36475 | cordinyana | public Object getWindowProfile() { |
430 | return WindowInfo.DIALOG_PROFILE;
|
||
431 | } |
||
432 | 12183 | nacho | |
433 | 36475 | cordinyana | } // @jve:visual-info decl-index=0 visual-constraint="10,10" |