svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / gui / thememanager / FThemeManagerWindow.java @ 5258
History | View | Annotate | Download (22.1 KB)
1 |
/*
|
---|---|
2 |
* Created on 24-ene-2005
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 |
*
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
21 |
*
|
22 |
* For more information, contact:
|
23 |
*
|
24 |
* Generalitat Valenciana
|
25 |
* Conselleria d'Infraestructures i Transport
|
26 |
* Av. Blasco Ib??ez, 50
|
27 |
* 46010 VALENCIA
|
28 |
* SPAIN
|
29 |
*
|
30 |
* +34 963862235
|
31 |
* gvsig@gva.es
|
32 |
* www.gvsig.gva.es
|
33 |
*
|
34 |
* or
|
35 |
*
|
36 |
* IVER T.I. S.A
|
37 |
* Salamanca 50
|
38 |
* 46005 Valencia
|
39 |
* Spain
|
40 |
*
|
41 |
* +34 963163400
|
42 |
* dac@iver.es
|
43 |
*/
|
44 |
package com.iver.cit.gvsig.gui.thememanager; |
45 |
|
46 |
import java.awt.BorderLayout; |
47 |
import java.awt.Component; |
48 |
import java.awt.event.ActionEvent; |
49 |
import java.awt.event.ActionListener; |
50 |
import java.awt.geom.Rectangle2D; |
51 |
import java.io.File; |
52 |
import java.io.FileNotFoundException; |
53 |
import java.io.FileReader; |
54 |
import java.io.FileWriter; |
55 |
import java.io.IOException; |
56 |
import java.text.NumberFormat; |
57 |
import java.text.ParseException; |
58 |
|
59 |
import javax.swing.JButton; |
60 |
import javax.swing.JDialog; |
61 |
import javax.swing.JFileChooser; |
62 |
import javax.swing.JPanel; |
63 |
import javax.swing.JTabbedPane; |
64 |
|
65 |
import org.cresques.cts.ICoordTrans; |
66 |
import org.exolab.castor.xml.MarshalException; |
67 |
import org.exolab.castor.xml.Marshaller; |
68 |
import org.exolab.castor.xml.ValidationException; |
69 |
|
70 |
import com.hardcode.gdbms.engine.data.DataSource; |
71 |
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
72 |
import com.iver.andami.PluginServices; |
73 |
import com.iver.andami.messages.NotificationManager; |
74 |
import com.iver.andami.ui.mdiManager.View; |
75 |
import com.iver.andami.ui.mdiManager.ViewInfo; |
76 |
import com.iver.cit.gvsig.fmap.DriverException; |
77 |
import com.iver.cit.gvsig.fmap.FMap; |
78 |
import com.iver.cit.gvsig.fmap.drivers.BoundedShapes; |
79 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
80 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
81 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
82 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
83 |
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial; |
84 |
import com.iver.cit.gvsig.fmap.layers.VectorialFileAdapter; |
85 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
86 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
87 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
88 |
import com.iver.cit.gvsig.fmap.operations.CancellableMonitorable; |
89 |
import com.iver.cit.gvsig.fmap.operations.DefaultCancellableMonitorable; |
90 |
import com.iver.cit.gvsig.fmap.rendering.ClassifiedLegend; |
91 |
import com.iver.cit.gvsig.fmap.rendering.Legend; |
92 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
93 |
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend; |
94 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
95 |
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend; |
96 |
import com.iver.cit.gvsig.fmap.spatialindex.RTreeSptLib; |
97 |
import com.iver.cit.gvsig.fmap.spatialindex.SpatialIndexException; |
98 |
import com.iver.cit.gvsig.gui.Panels.LinkPanel; |
99 |
import com.iver.cit.gvsig.gui.thememanager.legendmanager.FPanelLegendManager; |
100 |
import com.iver.cit.gvsig.gui.thememanager.legendmanager.panels.AbstractPanel; |
101 |
import com.iver.cit.gvsig.gui.thememanager.scalemanager.FPanelScaleManager; |
102 |
import com.iver.cit.gvsig.project.ProjectView; |
103 |
import com.iver.utiles.FileUtils; |
104 |
import com.iver.utiles.GenericFileFilter; |
105 |
import com.iver.utiles.XMLEntity; |
106 |
import com.iver.utiles.swing.threads.IMonitorableTask; |
107 |
import com.iver.utiles.xmlEntity.generate.XmlTag; |
108 |
|
109 |
/**
|
110 |
* @author jmorell (jose.morell@gmail.com)
|
111 |
* @version 24-ene-2005
|
112 |
*/
|
113 |
public final class FThemeManagerWindow extends AbstractPanel implements View { |
114 |
private FMap mapContext;
|
115 |
private FLayer layer;
|
116 |
private Legend renderer; // Le asignaremos la leyenda del primer tema activo. |
117 |
private FPanelScaleManager fPanelScaleManager;
|
118 |
private FPanelLegendManager fPanelLegendManager;
|
119 |
private LinkPanel linkPanel;
|
120 |
private JTabbedPane organizador = new JTabbedPane(); // @jve:decl-index=0: |
121 |
private ComandosListener m_actionListener = new ComandosListener(this); |
122 |
//private ProjectView view;
|
123 |
private NumberFormat nf = NumberFormat.getInstance(); |
124 |
|
125 |
/**
|
126 |
* Creates new form JPanel
|
127 |
*/
|
128 |
public FThemeManagerWindow() {
|
129 |
initialize(); |
130 |
this.setSize(650, 420); |
131 |
} |
132 |
|
133 |
/**
|
134 |
* Sobrecarga del constructor. Este se utiliza cuando se llama a este
|
135 |
* di?logo desde la barra de comandos.
|
136 |
*
|
137 |
*/
|
138 |
public FThemeManagerWindow(FLayer l, FMap fMap) {
|
139 |
initialize(); |
140 |
layer = l; |
141 |
mapContext = fMap; |
142 |
try {
|
143 |
ClassifiableVectorial aux = (ClassifiableVectorial) layer; |
144 |
renderer = (Legend) aux.getLegend().cloneLegend(); |
145 |
fPanelScaleManager.setMapContext(mapContext); |
146 |
fPanelLegendManager.setMapContext(mapContext); |
147 |
} catch (XMLException e) {
|
148 |
// TODO Auto-generated catch block
|
149 |
e.printStackTrace(); |
150 |
} catch (DriverException e1) {
|
151 |
// TODO Auto-generated catch block
|
152 |
e1.printStackTrace(); |
153 |
} |
154 |
|
155 |
fPanelScaleManager.setLayer(layer, renderer); |
156 |
fPanelLegendManager.setLayer(layer, renderer); |
157 |
|
158 |
organizador.setSelectedIndex(0);
|
159 |
|
160 |
this.setSize(650, 420); |
161 |
} |
162 |
|
163 |
/**
|
164 |
* This method initializes this
|
165 |
*
|
166 |
* @return void
|
167 |
*/
|
168 |
private void initialize() { |
169 |
|
170 |
fPanelScaleManager = new FPanelScaleManager();
|
171 |
fPanelLegendManager = new FPanelLegendManager();
|
172 |
|
173 |
organizador.addTab(PluginServices.getText(this,"General"), fPanelScaleManager); |
174 |
organizador.addTab(PluginServices.getText(this,"Simbologia"), fPanelLegendManager); |
175 |
|
176 |
JPanel panelButtons = new JPanel(); |
177 |
|
178 |
JButton btnAceptar = new JButton(PluginServices.getText(this,"Aceptar")); |
179 |
btnAceptar.setActionCommand("OK");
|
180 |
btnAceptar.addActionListener(m_actionListener); |
181 |
|
182 |
JButton btnApply = new JButton(PluginServices.getText(this,"Aplicar")); |
183 |
btnApply.setActionCommand("APPLY");
|
184 |
btnApply.addActionListener(m_actionListener); |
185 |
|
186 |
JButton btnSaveLegend = new JButton(PluginServices.getText(this,"Guardar_leyenda")+"..."); |
187 |
btnSaveLegend.setActionCommand("SAVE_LEGEND");
|
188 |
btnSaveLegend.addActionListener(m_actionListener); |
189 |
|
190 |
JButton btnLoadLegend = new JButton(PluginServices.getText(this,"Recuperar_leyenda")+"..."); |
191 |
btnLoadLegend.setActionCommand("LOAD_LEGEND");
|
192 |
btnLoadLegend.addActionListener(m_actionListener); |
193 |
|
194 |
JButton btnCancelar = new JButton(PluginServices.getText(this,"Cerrar")); |
195 |
btnCancelar.setActionCommand("CANCEL");
|
196 |
btnCancelar.addActionListener(m_actionListener); |
197 |
|
198 |
panelButtons.add(btnApply, null);
|
199 |
|
200 |
setLayout(new BorderLayout()); |
201 |
panelButtons.setLayout(null);
|
202 |
organizador.setPreferredSize(new java.awt.Dimension(640,390)); |
203 |
btnAceptar.setBounds(9, 5, 89, 23); |
204 |
btnApply.setBounds(107, 5, 89, 23); |
205 |
btnSaveLegend.setBounds(205, 5, 159, 23); |
206 |
btnLoadLegend.setBounds(373, 5, 159, 23); |
207 |
btnCancelar.setBounds(541, 5, 89, 23); |
208 |
panelButtons.setPreferredSize(new java.awt.Dimension(493,33)); |
209 |
add(organizador, java.awt.BorderLayout.NORTH); |
210 |
panelButtons.add(btnAceptar, null);
|
211 |
add(panelButtons, java.awt.BorderLayout.SOUTH); |
212 |
panelButtons.add(btnSaveLegend, null);
|
213 |
panelButtons.add(btnLoadLegend, null);
|
214 |
panelButtons.add(btnCancelar, null);
|
215 |
} |
216 |
|
217 |
|
218 |
|
219 |
/**
|
220 |
* En esta funci?n se coge el primer tema activo del TOC y se usa su
|
221 |
* renderer para inicializar. Hay que llamarla SIEMPRE que se abra el
|
222 |
* cuadro de di?logo, en el openLegendManager() de la vista.
|
223 |
*
|
224 |
* @param mapContext TOC que abre este cuadro de di?logo.
|
225 |
* @throws DriverException
|
226 |
*/
|
227 |
public void setMapContext(FMap mapContext) throws DriverException { |
228 |
this.mapContext = mapContext;
|
229 |
layer = getFirstActiveLayerVect(mapContext.getLayers()); |
230 |
try {
|
231 |
ClassifiableVectorial aux = (ClassifiableVectorial) layer; |
232 |
renderer = (Legend) aux.getLegend().cloneLegend(); |
233 |
} catch (XMLException e) {
|
234 |
// TODO Auto-generated catch block
|
235 |
e.printStackTrace(); |
236 |
} |
237 |
fPanelScaleManager.setMapContext(mapContext); |
238 |
fPanelLegendManager.setMapContext(mapContext); |
239 |
actualizar(); |
240 |
} |
241 |
|
242 |
/**
|
243 |
* DOCUMENT ME!
|
244 |
*/
|
245 |
private void actualizar() { |
246 |
FLayer lyrSelected = getFirstActiveLayerVect(mapContext.getLayers()); |
247 |
|
248 |
fPanelScaleManager.setLayer(lyrSelected, renderer); |
249 |
fPanelLegendManager.setLayer(lyrSelected, renderer); |
250 |
|
251 |
organizador.setSelectedIndex(0);
|
252 |
} |
253 |
|
254 |
private void btnApply_actionPerformed(ActionEvent evt) { |
255 |
// ClassifiableVectorial aux = (ClassifiableVectorial) layer;
|
256 |
|
257 |
switch (fPanelLegendManager.getVisibleCard()) {
|
258 |
case 0: // default symbol |
259 |
renderer = fPanelLegendManager.getM_defaultLegendPanel().getLegend(); |
260 |
fPanelLegendManager.getJComboBox().getModel().setSelectedItem(layer.getName() + PluginServices.getText(this,"_(Simbolo_unico)")); |
261 |
break;
|
262 |
case 1: // Unique Values |
263 |
renderer = fPanelLegendManager.getM_valuesLegendPanel().getLegend(); |
264 |
fPanelLegendManager.getJComboBox().getModel().setSelectedItem(layer.getName() + "_(Valores_unicos)");
|
265 |
break;
|
266 |
case 2:// break values |
267 |
renderer = fPanelLegendManager.getM_breaksLegendPanel().getLegend(); |
268 |
fPanelLegendManager.getJComboBox().getModel().setSelectedItem(layer.getName() + "_(Intervalos)");
|
269 |
break;
|
270 |
case 3://text |
271 |
fPanelLegendManager.getJComboBox().getModel().setSelectedItem(layer.getName() + "_(Etiquetas_estandar)");
|
272 |
} |
273 |
// System.out.println("Color punto 1 " + renderer.getDefaultSymbol().getColor().toString());
|
274 |
// fPanelLegendManager.getM_labelsLegendPanel().setFSymbol(renderer.getDefaultSymbol());
|
275 |
// boolean bShapesVisibles = renderer.getDefaultSymbol().isShapeVisible();
|
276 |
fPanelLegendManager.getM_labelsLegendPanel().updateValuesFromControls((VectorialLegend)renderer); |
277 |
// renderer.getDefaultSymbol().setShapeVisible(bShapesVisibles);
|
278 |
// System.out.println("Color punto 2 " + renderer.getDefaultSymbol().getColor().toString());
|
279 |
try {
|
280 |
// Intentamos aplicar la leyenda a todas
|
281 |
// las capas activas a las que se les pueda aplicar
|
282 |
FLayer[] activeLyrs = mapContext.getLayers().getActives();
|
283 |
for (int i=0; i < activeLyrs.length; i++) |
284 |
{ |
285 |
FLayer laux=activeLyrs[i]; |
286 |
if (activeLyrs[i] instanceof FLayers){ |
287 |
laux=getFirstActiveLayerVect((FLayers)activeLyrs[i]); |
288 |
} |
289 |
if (laux instanceof ClassifiableVectorial) |
290 |
{ |
291 |
ClassifiableVectorial aux2 = (ClassifiableVectorial) laux; |
292 |
if (renderer instanceof ClassifiedLegend) |
293 |
{ |
294 |
// Es una leyenda que necesita un recordset con un
|
295 |
// nombre de campo. Comprobamos que ese recordset
|
296 |
// tiene ese nombre de campo y es del tipo esperado
|
297 |
ClassifiedLegend cl = (ClassifiedLegend) renderer; |
298 |
if (aux2 instanceof AlphanumericData) |
299 |
{ |
300 |
DataSource rs = ((AlphanumericData) aux2).getRecordset();
|
301 |
int idField = rs.getFieldIndexByName(cl.getFieldName());
|
302 |
if (idField != -1) |
303 |
{ |
304 |
//TODO: Aqu? deber?amos comprobar si el tipo de campo
|
305 |
// es el tipo de campo esperado.
|
306 |
if (renderer instanceof VectorialUniqueValueLegend){ |
307 |
((VectorialUniqueValueLegend)renderer).setLabelHeightField(null);
|
308 |
((VectorialUniqueValueLegend)renderer).setLabelRotationField(null);
|
309 |
} |
310 |
|
311 |
aux2.setLegend((VectorialLegend) renderer); |
312 |
} |
313 |
|
314 |
} |
315 |
} |
316 |
else if (renderer instanceof SingleSymbolLegend) |
317 |
aux2.setLegend((VectorialLegend) renderer); |
318 |
} |
319 |
|
320 |
} |
321 |
// aux.setLegend((VectorialLegend) m_Renderer);
|
322 |
|
323 |
} catch (FieldNotFoundException e) {
|
324 |
// TODO Auto-generated catch block
|
325 |
e.printStackTrace(); |
326 |
} catch (DriverException e) {
|
327 |
// TODO Auto-generated catch block
|
328 |
e.printStackTrace(); |
329 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
330 |
// TODO Auto-generated catch block
|
331 |
e.printStackTrace(); |
332 |
} |
333 |
|
334 |
if (fPanelScaleManager.getJRadioButton1().isSelected()) {
|
335 |
try
|
336 |
{ |
337 |
layer.setMinScale((nf.parse(fPanelScaleManager.getJTextField1().getText())).doubleValue()); |
338 |
} |
339 |
catch (ParseException ex) |
340 |
{ |
341 |
if (fPanelScaleManager.getJTextField1().getText().compareTo("") == 0) |
342 |
layer.setMinScale(-1);
|
343 |
else
|
344 |
System.err.print(ex.getLocalizedMessage());
|
345 |
} |
346 |
try
|
347 |
{ |
348 |
layer.setMaxScale((nf.parse(fPanelScaleManager.getJTextField2().getText())).doubleValue()); |
349 |
} |
350 |
catch (ParseException ex) |
351 |
{ |
352 |
if (fPanelScaleManager.getJTextField2().getText().compareTo("") == 0) |
353 |
layer.setMaxScale(-1);
|
354 |
else
|
355 |
System.err.print(ex.getLocalizedMessage());
|
356 |
} |
357 |
|
358 |
} else {
|
359 |
layer.setMinScale(-1);
|
360 |
layer.setMaxScale(-1);
|
361 |
} |
362 |
if (!fPanelScaleManager.getLayerName().equals(layer.getName())){
|
363 |
layer.setName(fPanelScaleManager.getLayerName()); |
364 |
} |
365 |
if (layer instanceof FLyrVect) |
366 |
{ |
367 |
FLyrVect lyrVect = (FLyrVect) layer; |
368 |
if (fPanelScaleManager.isSpatialIndexSelected())
|
369 |
{ |
370 |
// if (lyrVect.getSpatialIndex() == null)
|
371 |
if(lyrVect.getISpatialIndex() == null) |
372 |
{ |
373 |
//AZABALA
|
374 |
try {
|
375 |
PluginServices. |
376 |
cancelableBackgroundExecution(getCreateSpatialIndexTask()); |
377 |
} catch (DriverIOException e) {
|
378 |
// TODO Auto-generated catch block
|
379 |
e.printStackTrace(); |
380 |
} catch (DriverException e) {
|
381 |
// TODO Auto-generated catch block
|
382 |
e.printStackTrace(); |
383 |
} |
384 |
// lyrVect.createSpatialIndex();
|
385 |
} |
386 |
} |
387 |
//AZABALA
|
388 |
/*
|
389 |
* If we unselect the spatial index checkbox...Must we delete
|
390 |
* spatial index file, or we only have to put Spatial Index
|
391 |
* reference to null?. I have followed the second choice
|
392 |
*/
|
393 |
else{
|
394 |
lyrVect.deleteSpatialIndex(); |
395 |
} |
396 |
|
397 |
|
398 |
} |
399 |
//layer.getFMap().invalidate();
|
400 |
layer.getFMap().callLegendChanged(); |
401 |
} |
402 |
|
403 |
|
404 |
/**
|
405 |
* Instanciates a ITask (@see com.iver.utiles.swing.threads.ITask)
|
406 |
* to create a spatial index for the selected layer in background.
|
407 |
* This task also allow to monitor process evolution, and to cancel
|
408 |
* this process.
|
409 |
* @throws DriverException
|
410 |
* @throws DriverIOException
|
411 |
*/
|
412 |
public IMonitorableTask getCreateSpatialIndexTask() throws DriverIOException, |
413 |
DriverException{ |
414 |
|
415 |
// FIXME REVISAR ESTO (Quizas lanzar TaskException)
|
416 |
return new CreateSpatialIndexMonitorableTask((FLyrVect)layer); |
417 |
} |
418 |
|
419 |
/**
|
420 |
* DOCUMENT ME!
|
421 |
*
|
422 |
* @author Fernando Gonz?lez Cort?s
|
423 |
*/
|
424 |
private class ComandosListener implements ActionListener { |
425 |
private FThemeManagerWindow fLayerPropertiesWindow;
|
426 |
|
427 |
/**
|
428 |
* Creates a new ComandosListener object.
|
429 |
*
|
430 |
* @param lg DOCUMENT ME!
|
431 |
*/
|
432 |
public ComandosListener(FThemeManagerWindow fLayerPropertiesWindow) {
|
433 |
this.fLayerPropertiesWindow = fLayerPropertiesWindow;
|
434 |
} |
435 |
|
436 |
/* (non-Javadoc)
|
437 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
438 |
*/
|
439 |
public void actionPerformed(ActionEvent e) { |
440 |
if (e.getActionCommand() == "OK") { |
441 |
// Implementaci?n para hacer funcionar el hyperlink ...
|
442 |
//com.iver.cit.gvsig.gui.View theView = (com.iver.cit.gvsig.gui.View)PluginServices.getMDIManager().getActiveView();
|
443 |
//ProjectView view = theView.getModel();
|
444 |
if (PluginServices.getMainFrame() != null) |
445 |
{ |
446 |
ProjectView view = fPanelScaleManager.getView(); |
447 |
view.setTypeLink(fPanelScaleManager.getLinkType()); |
448 |
if (fPanelScaleManager.getSelectedLinkField()!=null) |
449 |
{ |
450 |
view.setSelectedField(fPanelScaleManager.getSelectedLinkField().toString().trim()); |
451 |
view.setExtLink(fPanelScaleManager.getExtensionLink()); |
452 |
} |
453 |
} |
454 |
//
|
455 |
fLayerPropertiesWindow.btnApply_actionPerformed(e); |
456 |
if (PluginServices.getMainFrame() == null) |
457 |
((JDialog) (getParent().getParent().getParent().getParent())).dispose();
|
458 |
else
|
459 |
PluginServices.getMDIManager().closeView(FThemeManagerWindow.this); |
460 |
System.out.println("Ok"); |
461 |
} else if (e.getActionCommand() == "CANCEL") { |
462 |
if (PluginServices.getMainFrame() == null) |
463 |
((JDialog) (getParent().getParent().getParent().getParent())).dispose();
|
464 |
else
|
465 |
PluginServices.getMDIManager().closeView(FThemeManagerWindow.this); |
466 |
System.out.println("CANCEL"); |
467 |
} else if (e.getActionCommand() == "APPLY") { |
468 |
fLayerPropertiesWindow.btnApply_actionPerformed(e); |
469 |
System.out.println("APPLY"); |
470 |
} else if (e.getActionCommand() == "LOAD_LEGEND") { |
471 |
JFileChooser jfc = new JFileChooser(); |
472 |
jfc.addChoosableFileFilter(new GenericFileFilter("gvl", |
473 |
PluginServices.getText(this, "tipo_de_leyenda"))); |
474 |
jfc.addChoosableFileFilter(new GenericFileFilter("sld","sld")); |
475 |
|
476 |
if (jfc.showOpenDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
477 |
File file=jfc.getSelectedFile();
|
478 |
|
479 |
if (!(file.getPath().endsWith(".gvl") || file.getPath().endsWith(".GVL"))) |
480 |
{ |
481 |
file=new File(file.getPath()+".gvl"); |
482 |
} |
483 |
readLegend(file); |
484 |
fPanelLegendManager.setRenderer(renderer); |
485 |
fPanelLegendManager.actualizar(); |
486 |
} |
487 |
} else if (e.getActionCommand() == "SAVE_LEGEND") { |
488 |
fLayerPropertiesWindow.btnApply_actionPerformed(e); |
489 |
JFileChooser jfc = new JFileChooser(); |
490 |
jfc.addChoosableFileFilter(new GenericFileFilter("gvl", |
491 |
PluginServices.getText(this, "tipo_de_leyenda"))); |
492 |
jfc.addChoosableFileFilter(new GenericFileFilter("sld","*.sld")); |
493 |
|
494 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) |
495 |
{ |
496 |
File file=jfc.getSelectedFile();
|
497 |
if (jfc.getFileFilter().accept(new File("dummy.sld"))) |
498 |
{ |
499 |
if (!(file.getPath().toLowerCase().endsWith(".sld"))){ |
500 |
file=new File(file.getPath()+".sld"); |
501 |
} |
502 |
export2SLD(file); |
503 |
} |
504 |
else{
|
505 |
if (!(file.getPath().toLowerCase().endsWith(".gvl"))){ |
506 |
file=new File(file.getPath()+".gvl"); |
507 |
} |
508 |
writeLegend(file); |
509 |
} |
510 |
} |
511 |
} else {}
|
512 |
} |
513 |
} |
514 |
|
515 |
private void export2SLD(File file) { |
516 |
try {
|
517 |
FileWriter writer = new FileWriter(file.getAbsolutePath()); |
518 |
writer.write( renderer.getSLDString(layer.getName())); |
519 |
writer.close(); |
520 |
|
521 |
// Marshaller m = new Marshaller(writer);
|
522 |
// m.setEncoding("ISO-8859-1");
|
523 |
// m.marshal(renderer.getSLDString());
|
524 |
} catch (Exception e) { |
525 |
NotificationManager.addError(PluginServices.getText(this, "Error_exportando_SLD"), e); |
526 |
} |
527 |
} |
528 |
|
529 |
private void writeLegend(File file) { |
530 |
try {
|
531 |
FileWriter writer = new FileWriter(file.getAbsolutePath()); |
532 |
Marshaller m = new Marshaller(writer);
|
533 |
m.setEncoding("ISO-8859-1");
|
534 |
m.marshal(renderer.getXMLEntity().getXmlTag()); |
535 |
} catch (Exception e) { |
536 |
NotificationManager.addError(PluginServices.getText(this, "Error_guardando_la_leyenda"), e); |
537 |
} |
538 |
} |
539 |
|
540 |
public void readLegend(File file) { |
541 |
try {
|
542 |
File xmlFile = new File(file.getAbsolutePath()); |
543 |
FileReader reader;
|
544 |
reader = new FileReader(xmlFile); |
545 |
|
546 |
XmlTag tag = (XmlTag) XmlTag.unmarshal(reader); |
547 |
renderer = LegendFactory.createFromXML(new XMLEntity(tag));
|
548 |
//fPanelLegendManager.setRenderer(LegendFactory.createFromXML(new XMLEntity(tag)));
|
549 |
} catch (FileNotFoundException e) { |
550 |
NotificationManager.addError(PluginServices.getText(this, "Al_leer_la_leyenda"), e); |
551 |
} catch (MarshalException e) { |
552 |
NotificationManager.addError(PluginServices.getText(this, "Al leer la leyenda"), e); |
553 |
} catch (ValidationException e) {
|
554 |
NotificationManager.addError(PluginServices.getText(this, "Al leer la leyenda"), e); |
555 |
} catch (XMLException e) {
|
556 |
NotificationManager.addError(PluginServices.getText(this, "Al leer la leyenda"), e); |
557 |
} |
558 |
} |
559 |
|
560 |
/* (non-Javadoc)
|
561 |
* @see com.iver.andami.ui.mdiManager.View#getViewInfo()
|
562 |
*/
|
563 |
public ViewInfo getViewInfo() {
|
564 |
// Solo se llama una vez
|
565 |
ViewInfo viewInfo = new ViewInfo(ViewInfo.MODELESSDIALOG);
|
566 |
viewInfo.setWidth(650);
|
567 |
viewInfo.setHeight(420);
|
568 |
viewInfo.setTitle(PluginServices.getText(this,"propiedades_de_la_capa")); |
569 |
return viewInfo;
|
570 |
} |
571 |
|
572 |
/**
|
573 |
* @see com.iver.mdiApp.ui.MDIManager.View#viewActivated()
|
574 |
*/
|
575 |
/*public void viewActivated() {
|
576 |
}
|
577 |
|
578 |
public FMap getMapContext() {
|
579 |
return mapContext;
|
580 |
}
|
581 |
public FLayer getLayer() {
|
582 |
return layer;
|
583 |
}
|
584 |
public Legend getRenderer() {
|
585 |
return renderer;
|
586 |
}*/
|
587 |
|
588 |
/**
|
589 |
* @return Returns the organizador.
|
590 |
*/
|
591 |
public JTabbedPane getOrganizador() { |
592 |
return organizador;
|
593 |
} |
594 |
/**
|
595 |
* @param organizador The organizador to set.
|
596 |
*/
|
597 |
public void setOrganizador(JTabbedPane organizador) { |
598 |
this.organizador = organizador;
|
599 |
} |
600 |
} |