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