svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / gui / FPanelLocConfig.java @ 35756
History | View | Annotate | Download (10.7 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.project.documents.view.gui; |
42 |
|
43 |
import java.awt.Color; |
44 |
import java.awt.FlowLayout; |
45 |
import java.awt.event.ActionEvent; |
46 |
import java.awt.event.ActionListener; |
47 |
|
48 |
import javax.swing.BorderFactory; |
49 |
import javax.swing.DefaultListModel; |
50 |
import javax.swing.JDialog; |
51 |
import javax.swing.JOptionPane; |
52 |
import javax.swing.JPanel; |
53 |
import javax.swing.plaf.basic.BasicArrowButton; |
54 |
|
55 |
import org.gvsig.gui.beans.swing.JButton; |
56 |
|
57 |
import com.iver.andami.PluginServices; |
58 |
import com.iver.andami.ui.mdiManager.IWindow; |
59 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
60 |
import com.iver.cit.gvsig.AddLayer; |
61 |
import com.iver.cit.gvsig.fmap.MapControl; |
62 |
import com.iver.cit.gvsig.fmap.layers.CancelationException; |
63 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
64 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
65 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.Classifiable; |
66 |
import com.iver.cit.gvsig.project.documents.view.MapOverview; |
67 |
import com.iver.cit.gvsig.project.documents.view.legend.gui.ThemeManagerWindow; |
68 |
|
69 |
/**
|
70 |
* @author FJP
|
71 |
*
|
72 |
* Dialog to config the locator
|
73 |
*/
|
74 |
public class FPanelLocConfig extends JPanel implements ActionListener,IWindow { |
75 |
|
76 |
private static final long serialVersionUID = -2271914332135260143L; |
77 |
private javax.swing.JLabel jLabel = null; |
78 |
private javax.swing.JList jList = null; |
79 |
private JButton jBtnAddLayer = null; |
80 |
private JButton jBtnRemoveLayer = null; |
81 |
private JButton jBtnEditLegend = null; |
82 |
private JButton jBtnCancel = null; |
83 |
|
84 |
private MapControl mapCtrl;
|
85 |
private WindowInfo m_viewinfo = null; |
86 |
private JPanel pnlButtons = null; |
87 |
private BasicArrowButton jBtnUp; |
88 |
private BasicArrowButton jBtnDown; |
89 |
|
90 |
public FPanelLocConfig( MapControl mc) {
|
91 |
super();
|
92 |
mapCtrl = mc; |
93 |
initialize(); |
94 |
refreshList(); |
95 |
updateControls(null);
|
96 |
} |
97 |
|
98 |
private void refreshList() |
99 |
{ |
100 |
DefaultListModel lstModel = (DefaultListModel) getJList().getModel(); |
101 |
lstModel.clear(); |
102 |
for (int i=mapCtrl.getMapContext().getLayers().getLayersCount()-1; i >=0; i--) |
103 |
{ |
104 |
FLayer lyr = mapCtrl.getMapContext().getLayers().getLayer(i); |
105 |
lstModel.addElement(lyr.getName()); |
106 |
} |
107 |
} |
108 |
|
109 |
private void initialize() { |
110 |
this.setLayout(null); |
111 |
this.setSize(555, 210); |
112 |
this.add(getJLabel(), null); |
113 |
this.add(getJList(), null); |
114 |
this.add(getJBtnUp(), null); |
115 |
this.add(getJBtnDown(), null); |
116 |
this.add(getJPanel(), null); |
117 |
} |
118 |
|
119 |
private javax.swing.JLabel getJLabel() {
|
120 |
if (jLabel == null) { |
121 |
jLabel = new javax.swing.JLabel();
|
122 |
jLabel.setText(PluginServices.getText(this,"Capas_del_localizador")+":"); |
123 |
jLabel.setBounds(10, 15, 132, 25); |
124 |
} |
125 |
return jLabel;
|
126 |
} |
127 |
|
128 |
|
129 |
public javax.swing.JList getJList() {
|
130 |
if (jList == null) { |
131 |
jList = new javax.swing.JList(new DefaultListModel()); |
132 |
jList.setBounds(10, 49, 357, 139); |
133 |
jList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); |
134 |
jList.setBorder(BorderFactory.createLineBorder(Color.BLACK)); |
135 |
jList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
|
136 |
|
137 |
public void valueChanged(javax.swing.event.ListSelectionEvent e) { |
138 |
updateControls(e); |
139 |
} |
140 |
}); |
141 |
|
142 |
} |
143 |
return jList;
|
144 |
} |
145 |
|
146 |
private void updateControls(javax.swing.event.ListSelectionEvent e) |
147 |
{ |
148 |
DefaultListModel lstModel = (DefaultListModel) getJList().getModel(); |
149 |
int selIndex = jList.getSelectedIndex();
|
150 |
jBtnDown.setEnabled(false);
|
151 |
jBtnUp.setEnabled(false);
|
152 |
|
153 |
if (selIndex != -1) |
154 |
{ |
155 |
if (lstModel.getSize() > 1) |
156 |
{ |
157 |
if (selIndex < (lstModel.getSize()-1)) |
158 |
jBtnDown.setEnabled(true);
|
159 |
|
160 |
if (selIndex > 0) |
161 |
jBtnUp.setEnabled(true);
|
162 |
} |
163 |
|
164 |
} |
165 |
|
166 |
|
167 |
} |
168 |
|
169 |
private BasicArrowButton getJBtnUp() { |
170 |
if (jBtnUp == null) { |
171 |
jBtnUp = new javax.swing.plaf.basic.BasicArrowButton(
|
172 |
javax.swing.SwingConstants.NORTH); |
173 |
jBtnUp.setBounds(374, 49, 25, 23); |
174 |
jBtnUp.setToolTipText(PluginServices.getText(this,"Subir_capa")); |
175 |
jBtnUp.addActionListener(this);
|
176 |
jBtnUp.setActionCommand("UP");
|
177 |
|
178 |
} |
179 |
return jBtnUp;
|
180 |
} |
181 |
|
182 |
|
183 |
private BasicArrowButton getJBtnDown() { |
184 |
if (jBtnDown == null) { |
185 |
jBtnDown = new javax.swing.plaf.basic.BasicArrowButton(
|
186 |
javax.swing.SwingConstants.SOUTH); |
187 |
jBtnDown.setBounds(374, 164, 25, 23); |
188 |
jBtnDown.setToolTipText(PluginServices.getText(this,"Bajar_capa")); |
189 |
jBtnDown.setActionCommand("DOWN");
|
190 |
jBtnDown.addActionListener(this);
|
191 |
} |
192 |
return jBtnDown;
|
193 |
} |
194 |
|
195 |
private JButton getJBtnAddLayer() { |
196 |
if (jBtnAddLayer == null) { |
197 |
jBtnAddLayer = new JButton(); |
198 |
jBtnAddLayer.setText(PluginServices.getText(this,"Anadir_capa")+"..."); |
199 |
jBtnAddLayer.addActionListener(this);
|
200 |
jBtnAddLayer.setActionCommand("ADD_LAYER");
|
201 |
} |
202 |
return jBtnAddLayer;
|
203 |
} |
204 |
|
205 |
private JButton getJBtnRemoveLayer() { |
206 |
if (jBtnRemoveLayer == null) { |
207 |
jBtnRemoveLayer = new JButton(); |
208 |
jBtnRemoveLayer.setText(PluginServices.getText(this,"Quitar_capa")+"..."); |
209 |
jBtnRemoveLayer.addActionListener(this);
|
210 |
jBtnRemoveLayer.setActionCommand("REMOVE_LAYER");
|
211 |
|
212 |
} |
213 |
return jBtnRemoveLayer;
|
214 |
} |
215 |
|
216 |
|
217 |
private JButton getJBtnEditLegend() { |
218 |
if (jBtnEditLegend == null) { |
219 |
jBtnEditLegend = new JButton(); |
220 |
jBtnEditLegend.setText(PluginServices.getText(this,"Editar_leyenda")+"..."); |
221 |
jBtnEditLegend.addActionListener(this);
|
222 |
jBtnEditLegend.setActionCommand("EDIT_LEGEND");
|
223 |
} |
224 |
return jBtnEditLegend;
|
225 |
} |
226 |
|
227 |
private JButton getJBtnCancel() { |
228 |
if (jBtnCancel == null) { |
229 |
jBtnCancel = new JButton(); |
230 |
jBtnCancel.setText(PluginServices.getText(this,"Cerrar")); |
231 |
jBtnCancel.setActionCommand("CANCEL");
|
232 |
jBtnCancel.addActionListener(this);
|
233 |
|
234 |
} |
235 |
return jBtnCancel;
|
236 |
} |
237 |
|
238 |
|
239 |
public void actionPerformed(ActionEvent e) |
240 |
{ |
241 |
DefaultListModel lstModel = (DefaultListModel) getJList().getModel(); |
242 |
FLayers theLayers = mapCtrl.getMapContext().getLayers(); |
243 |
// IProjection proj = null;
|
244 |
|
245 |
int numLayers = theLayers.getLayersCount()-1; |
246 |
|
247 |
if (e.getActionCommand() == "CANCEL") |
248 |
{ |
249 |
if (PluginServices.getMainFrame() != null) |
250 |
{ |
251 |
PluginServices.getMDIManager().closeWindow(FPanelLocConfig.this); |
252 |
} |
253 |
else
|
254 |
{ |
255 |
((JDialog) (getParent().getParent().getParent().getParent())).dispose();
|
256 |
} |
257 |
} |
258 |
if (e.getActionCommand() == "ADD_LAYER") |
259 |
{ |
260 |
AddLayer addLayer = (AddLayer)PluginServices.getExtension( AddLayer.class);//new AddLayer();
|
261 |
//addLayer.initialize();
|
262 |
if (addLayer.addLayers(mapCtrl)) {
|
263 |
refreshList(); |
264 |
updateControls(null);
|
265 |
} |
266 |
if (mapCtrl instanceof MapOverview){ |
267 |
((MapOverview)mapCtrl).refreshExtent(); |
268 |
} |
269 |
|
270 |
} |
271 |
if (e.getActionCommand() == "REMOVE_LAYER") |
272 |
{ |
273 |
if (jList.getSelectedIndex() != -1) |
274 |
{ |
275 |
theLayers.removeLayer((String) lstModel.get(jList.getSelectedIndex()));
|
276 |
lstModel.remove(jList.getSelectedIndex()); |
277 |
///mapCtrl.drawMap();
|
278 |
updateControls(null);
|
279 |
if (mapCtrl instanceof MapOverview){ |
280 |
((MapOverview)mapCtrl).refreshExtent(); |
281 |
} |
282 |
PluginServices.getMainFrame().enableControls(); |
283 |
} |
284 |
} |
285 |
if (e.getActionCommand() == "EDIT_LEGEND") |
286 |
{ |
287 |
int idSelec = jList.getSelectedIndex();
|
288 |
if (idSelec != -1) |
289 |
{ |
290 |
FLayer lyr = theLayers.getLayer((String) lstModel.get(idSelec));
|
291 |
if (lyr instanceof Classifiable) |
292 |
{ |
293 |
ThemeManagerWindow m_LegendEditor = new ThemeManagerWindow(lyr/*, mapCtrl.getMapContext()*/); |
294 |
theLayers.setActive(false);
|
295 |
lyr.setActive(true);
|
296 |
if (PluginServices.getMainFrame() == null) { |
297 |
JDialog dlg = new JDialog(); |
298 |
|
299 |
m_LegendEditor.setPreferredSize(m_LegendEditor.getSize()); |
300 |
dlg.getContentPane().add(m_LegendEditor); |
301 |
dlg.setModal(true);
|
302 |
dlg.pack(); |
303 |
dlg.show(); |
304 |
|
305 |
} else {
|
306 |
PluginServices.getMDIManager().addWindow(m_LegendEditor); |
307 |
} |
308 |
} |
309 |
else
|
310 |
{ |
311 |
JOptionPane.showMessageDialog(null, PluginServices.getText(this,"Solo_para_capas_vectoriales")+"."); |
312 |
} |
313 |
|
314 |
} |
315 |
|
316 |
} |
317 |
if (e.getActionCommand() == "UP") |
318 |
{ |
319 |
int idSelec = jList.getSelectedIndex();
|
320 |
int fromIndex = idSelec;
|
321 |
int toIndex = idSelec-1; |
322 |
FLayer aux = theLayers.getLayer((String) lstModel.get(fromIndex));
|
323 |
try {
|
324 |
theLayers.moveTo(numLayers-fromIndex, numLayers-toIndex); |
325 |
} catch (CancelationException e1) {
|
326 |
e1.printStackTrace(); |
327 |
} |
328 |
|
329 |
lstModel.remove(fromIndex); |
330 |
lstModel.add(toIndex,aux.getName()); |
331 |
|
332 |
jList.setSelectedIndex(toIndex); |
333 |
|
334 |
///mapCtrl.drawMap();
|
335 |
} |
336 |
if (e.getActionCommand() == "DOWN") |
337 |
{ |
338 |
int idSelec = jList.getSelectedIndex();
|
339 |
int fromIndex = idSelec;
|
340 |
int toIndex = idSelec+1; |
341 |
FLayer aux = theLayers.getLayer((String) lstModel.get(fromIndex));
|
342 |
try {
|
343 |
theLayers.moveTo(numLayers-fromIndex, numLayers-toIndex); |
344 |
} catch (CancelationException e1) {
|
345 |
e1.printStackTrace(); |
346 |
} |
347 |
|
348 |
lstModel.remove(fromIndex); |
349 |
lstModel.add(toIndex,aux.getName()); |
350 |
|
351 |
jList.setSelectedIndex(toIndex); |
352 |
|
353 |
///mapCtrl.drawMap();
|
354 |
} |
355 |
|
356 |
|
357 |
} |
358 |
|
359 |
public WindowInfo getWindowInfo() {
|
360 |
if (m_viewinfo==null){ |
361 |
m_viewinfo=new WindowInfo(WindowInfo.MODELESSDIALOG);
|
362 |
m_viewinfo.setTitle(PluginServices.getText(this,"Configurar_localizador")); |
363 |
m_viewinfo.setWidth(this.getWidth()+8); |
364 |
m_viewinfo.setHeight(this.getHeight()+8); |
365 |
} |
366 |
return m_viewinfo;
|
367 |
} |
368 |
|
369 |
public void viewActivated() { |
370 |
} |
371 |
|
372 |
|
373 |
private JPanel getJPanel() { |
374 |
if (pnlButtons == null) { |
375 |
pnlButtons = new JPanel(new FlowLayout(FlowLayout.RIGHT, 5, 5)); |
376 |
pnlButtons.setBounds(new java.awt.Rectangle(0,200, this.getWidth(),37)); |
377 |
pnlButtons.add(getJBtnAddLayer(), null);
|
378 |
pnlButtons.add(getJBtnRemoveLayer(), null);
|
379 |
pnlButtons.add(getJBtnEditLegend(), null);
|
380 |
pnlButtons.add(getJBtnCancel(), null);
|
381 |
} |
382 |
return pnlButtons;
|
383 |
} |
384 |
|
385 |
|
386 |
public MapControl getMapCtrl() {
|
387 |
return mapCtrl;
|
388 |
} |
389 |
|
390 |
public Object getWindowProfile() { |
391 |
return WindowInfo.DIALOG_PROFILE;
|
392 |
} |
393 |
|
394 |
} |