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