svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / legend / gui / FThemeManagerWindow.java @ 10626
History | View | Annotate | Download (25.3 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.FileInputStream; |
52 |
import java.io.FileNotFoundException; |
53 |
import java.io.FileOutputStream; |
54 |
import java.io.FileWriter; |
55 |
import java.io.IOException; |
56 |
import java.io.InputStreamReader; |
57 |
import java.io.OutputStreamWriter; |
58 |
import java.io.Reader; |
59 |
import java.io.UnsupportedEncodingException; |
60 |
import java.text.NumberFormat; |
61 |
import java.text.ParseException; |
62 |
|
63 |
import javax.swing.JButton; |
64 |
import javax.swing.JDialog; |
65 |
import javax.swing.JFileChooser; |
66 |
import javax.swing.JOptionPane; |
67 |
import javax.swing.JPanel; |
68 |
import javax.swing.JTabbedPane; |
69 |
|
70 |
import org.exolab.castor.xml.MarshalException; |
71 |
import org.exolab.castor.xml.Marshaller; |
72 |
import org.exolab.castor.xml.ValidationException; |
73 |
|
74 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
75 |
import com.hardcode.gdbms.engine.data.DataSource; |
76 |
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException; |
77 |
import com.iver.andami.PluginServices; |
78 |
import com.iver.andami.Utilities; |
79 |
import com.iver.andami.messages.NotificationManager; |
80 |
import com.iver.andami.ui.mdiManager.IWindow; |
81 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
82 |
import com.iver.cit.gvsig.ProjectExtension; |
83 |
import com.iver.cit.gvsig.exceptions.layers.LegendLayerException; |
84 |
import com.iver.cit.gvsig.fmap.MapContext; |
85 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
86 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
87 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
88 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
89 |
import com.iver.cit.gvsig.fmap.layers.XMLException; |
90 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
91 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial; |
92 |
import com.iver.cit.gvsig.fmap.rendering.ClassifiedLegend; |
93 |
import com.iver.cit.gvsig.fmap.rendering.Legend; |
94 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
95 |
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend; |
96 |
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend; |
97 |
import com.iver.cit.gvsig.fmap.rendering.avl2sld.AVL2SLD; |
98 |
import com.iver.cit.gvsig.fmap.rendering.sld2gvl.SLD2GVL; |
99 |
import com.iver.cit.gvsig.project.documents.view.IProjectView; |
100 |
import com.iver.cit.gvsig.project.documents.view.legend.CreateSpatialIndexMonitorableTask; |
101 |
import com.iver.cit.gvsig.project.documents.view.legend.scale.gui.FPanelScaleManager; |
102 |
import com.iver.utiles.GenericFileFilter; |
103 |
import com.iver.utiles.XMLEntity; |
104 |
import com.iver.utiles.swing.threads.IMonitorableTask; |
105 |
import com.iver.utiles.xml.XMLEncodingUtils; |
106 |
import com.iver.utiles.xmlEntity.generate.XmlTag; |
107 |
|
108 |
/**
|
109 |
* @author jmorell (jose.morell@gmail.com)
|
110 |
* @version 24-ene-2005
|
111 |
*/
|
112 |
public final class FThemeManagerWindow extends AbstractPanel implements IWindow { |
113 |
private MapContext mapContext;
|
114 |
private FLayer layer;
|
115 |
private Legend renderer; // Le asignaremos la leyenda del primer tema activo. |
116 |
private FPanelScaleManager fPanelScaleManager;
|
117 |
private FPanelLegendManager fPanelLegendManager;
|
118 |
private JTabbedPane organizador = new JTabbedPane(); // @jve:decl-index=0: |
119 |
private ComandosListener m_actionListener = new ComandosListener(this); |
120 |
//private ProjectView view;
|
121 |
private NumberFormat nf = NumberFormat.getInstance(); |
122 |
|
123 |
/**
|
124 |
* Creates new form JPanel
|
125 |
*/
|
126 |
public FThemeManagerWindow() {
|
127 |
initialize(); |
128 |
this.setSize(650, 420); |
129 |
} |
130 |
|
131 |
/**
|
132 |
* Sobrecarga del constructor. Este se utiliza cuando se llama a este
|
133 |
* di?logo desde la barra de comandos.
|
134 |
*
|
135 |
*/
|
136 |
public FThemeManagerWindow(FLayer l, MapContext fMap) {
|
137 |
initialize(); |
138 |
layer = l; |
139 |
mapContext = fMap; |
140 |
try {
|
141 |
ClassifiableVectorial aux = (ClassifiableVectorial) layer; |
142 |
renderer = aux.getLegend().cloneLegend(); |
143 |
fPanelScaleManager.setMapContext(mapContext); |
144 |
fPanelLegendManager.setMapContext(mapContext); |
145 |
} catch (XMLException e) {
|
146 |
// TODO Auto-generated catch block
|
147 |
e.printStackTrace(); |
148 |
} catch (ReadDriverException e1) {
|
149 |
// TODO Auto-generated catch block
|
150 |
e1.printStackTrace(); |
151 |
} |
152 |
|
153 |
fPanelScaleManager.setLayer(layer, renderer); |
154 |
fPanelLegendManager.setLayer(layer, renderer); |
155 |
|
156 |
organizador.setSelectedIndex(0);
|
157 |
|
158 |
this.setSize(650, 420); |
159 |
} |
160 |
|
161 |
/**
|
162 |
* This method initializes this
|
163 |
*
|
164 |
* @return void
|
165 |
*/
|
166 |
private void initialize() { |
167 |
|
168 |
fPanelScaleManager = new FPanelScaleManager();
|
169 |
fPanelLegendManager = new FPanelLegendManager();
|
170 |
|
171 |
organizador.addTab(PluginServices.getText(this,"General"), fPanelScaleManager); |
172 |
organizador.addTab(PluginServices.getText(this,"Simbologia"), fPanelLegendManager); |
173 |
|
174 |
JPanel panelButtons = new JPanel(); |
175 |
|
176 |
JButton btnAceptar = new JButton(PluginServices.getText(this,"Aceptar")); |
177 |
btnAceptar.setActionCommand("OK");
|
178 |
btnAceptar.addActionListener(m_actionListener); |
179 |
|
180 |
JButton btnApply = new JButton(PluginServices.getText(this,"Aplicar")); |
181 |
btnApply.setActionCommand("APPLY");
|
182 |
btnApply.addActionListener(m_actionListener); |
183 |
|
184 |
JButton btnSaveLegend = new JButton(PluginServices.getText(this,"Guardar_leyenda")+"..."); |
185 |
btnSaveLegend.setActionCommand("SAVE_LEGEND");
|
186 |
btnSaveLegend.addActionListener(m_actionListener); |
187 |
|
188 |
JButton btnLoadLegend = new JButton(PluginServices.getText(this,"Recuperar_leyenda")+"..."); |
189 |
btnLoadLegend.setActionCommand("LOAD_LEGEND");
|
190 |
btnLoadLegend.addActionListener(m_actionListener); |
191 |
|
192 |
JButton btnCancelar = new JButton(PluginServices.getText(this,"Cerrar")); |
193 |
btnCancelar.setActionCommand("CANCEL");
|
194 |
btnCancelar.addActionListener(m_actionListener); |
195 |
|
196 |
panelButtons.add(btnApply, null);
|
197 |
|
198 |
setLayout(new BorderLayout()); |
199 |
panelButtons.setLayout(null);
|
200 |
organizador.setPreferredSize(new java.awt.Dimension(640,390)); |
201 |
btnAceptar.setBounds(9, 5, 89, 23); |
202 |
btnApply.setBounds(107, 5, 89, 23); |
203 |
btnSaveLegend.setBounds(205, 5, 159, 23); |
204 |
btnLoadLegend.setBounds(373, 5, 159, 23); |
205 |
btnCancelar.setBounds(541, 5, 89, 23); |
206 |
panelButtons.setPreferredSize(new java.awt.Dimension(493,33)); |
207 |
add(organizador, java.awt.BorderLayout.NORTH); |
208 |
panelButtons.add(btnAceptar, null);
|
209 |
add(panelButtons, java.awt.BorderLayout.SOUTH); |
210 |
panelButtons.add(btnSaveLegend, null);
|
211 |
panelButtons.add(btnLoadLegend, null);
|
212 |
panelButtons.add(btnCancelar, null);
|
213 |
} |
214 |
|
215 |
|
216 |
|
217 |
/**
|
218 |
* En esta funci?n se coge el primer tema activo del TOC y se usa su
|
219 |
* renderer para inicializar. Hay que llamarla SIEMPRE que se abra el
|
220 |
* cuadro de di?logo, en el openLegendManager() de la vista.
|
221 |
*
|
222 |
* @param mapContext TOC que abre este cuadro de di?logo.
|
223 |
* @throws DriverException
|
224 |
*/
|
225 |
public void setMapContext(MapContext mapContext) throws ReadDriverException { |
226 |
this.mapContext = mapContext;
|
227 |
layer = getFirstActiveLayerVect(mapContext.getLayers()); |
228 |
try {
|
229 |
ClassifiableVectorial aux = (ClassifiableVectorial) layer; |
230 |
renderer = aux.getLegend().cloneLegend(); |
231 |
} catch (XMLException e) {
|
232 |
// TODO Auto-generated catch block
|
233 |
e.printStackTrace(); |
234 |
} |
235 |
fPanelScaleManager.setMapContext(mapContext); |
236 |
fPanelLegendManager.setMapContext(mapContext); |
237 |
actualizar(); |
238 |
} |
239 |
|
240 |
/**
|
241 |
* DOCUMENT ME!
|
242 |
*/
|
243 |
private void actualizar() { |
244 |
FLayer lyrSelected = getFirstActiveLayerVect(mapContext.getLayers()); |
245 |
|
246 |
fPanelScaleManager.setLayer(lyrSelected, renderer); |
247 |
fPanelLegendManager.setLayer(lyrSelected, renderer); |
248 |
|
249 |
organizador.setSelectedIndex(0);
|
250 |
} |
251 |
|
252 |
private void btnApply_actionPerformed(ActionEvent evt) { |
253 |
// ClassifiableVectorial aux = (ClassifiableVectorial) layer;
|
254 |
|
255 |
switch (fPanelLegendManager.getVisibleCard()) {
|
256 |
case 0: // default symbol |
257 |
renderer = fPanelLegendManager.getM_defaultLegendPanel().getLegend(); |
258 |
fPanelLegendManager.getJComboBox().getModel().setSelectedItem(layer.getName() + PluginServices.getText(this,"_(Simbolo_unico)")); |
259 |
break;
|
260 |
case 1: // Unique Values |
261 |
renderer = fPanelLegendManager.getM_valuesLegendPanel().getLegend(); |
262 |
fPanelLegendManager.getJComboBox().getModel().setSelectedItem(layer.getName() + "_(Valores_unicos)");
|
263 |
break;
|
264 |
case 2:// break values |
265 |
renderer = fPanelLegendManager.getM_breaksLegendPanel().getLegend(); |
266 |
fPanelLegendManager.getJComboBox().getModel().setSelectedItem(layer.getName() + "_(Intervalos)");
|
267 |
break;
|
268 |
case 3://text |
269 |
fPanelLegendManager.getJComboBox().getModel().setSelectedItem(layer.getName() + "_(Etiquetas_estandar)");
|
270 |
} |
271 |
// System.out.println("Color punto 1 " + renderer.getDefaultSymbol().getColor().toString());
|
272 |
// fPanelLegendManager.getM_labelsLegendPanel().setFSymbol(renderer.getDefaultSymbol());
|
273 |
// boolean bShapesVisibles = renderer.getDefaultSymbol().isShapeVisible();
|
274 |
fPanelLegendManager.getM_labelsLegendPanel().updateValuesFromControls((VectorialLegend)renderer); |
275 |
// renderer.getDefaultSymbol().setShapeVisible(bShapesVisibles);
|
276 |
// System.out.println("Color punto 2 " + renderer.getDefaultSymbol().getColor().toString());
|
277 |
try {
|
278 |
// Intentamos aplicar la leyenda a todas
|
279 |
// las capas activas a las que se les pueda aplicar
|
280 |
FLayer[] activeLyrs = mapContext.getLayers().getActives();
|
281 |
for (int i=0; i < activeLyrs.length; i++) |
282 |
{ |
283 |
FLayer laux=activeLyrs[i]; |
284 |
if (activeLyrs[i] instanceof FLayers){ |
285 |
laux=getFirstActiveLayerVect((FLayers)activeLyrs[i]); |
286 |
} |
287 |
if (laux instanceof ClassifiableVectorial) |
288 |
{ |
289 |
ClassifiableVectorial aux2 = (ClassifiableVectorial) laux; |
290 |
if (renderer instanceof ClassifiedLegend) |
291 |
{ |
292 |
// Es una leyenda que necesita un recordset con un
|
293 |
// nombre de campo. Comprobamos que ese recordset
|
294 |
// tiene ese nombre de campo y es del tipo esperado
|
295 |
ClassifiedLegend cl = (ClassifiedLegend) renderer; |
296 |
if (aux2 instanceof AlphanumericData) |
297 |
{ |
298 |
DataSource rs = ((AlphanumericData) aux2).getRecordset();
|
299 |
if (cl.getValues().length==0) { |
300 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"no_es_posible_aplicar_leyenda_vacia")); |
301 |
return;
|
302 |
} |
303 |
int idField = rs.getFieldIndexByName(cl.getFieldName());
|
304 |
if (idField != -1) |
305 |
{ |
306 |
//TODO: Aqu? deber?amos comprobar si el tipo de campo
|
307 |
// es el tipo de campo esperado.
|
308 |
/*if (renderer instanceof VectorialUniqueValueLegend){
|
309 |
((VectorialUniqueValueLegend)renderer).setLabelHeightField(null);
|
310 |
((VectorialUniqueValueLegend)renderer).setLabelRotationField(null);
|
311 |
}
|
312 |
*/
|
313 |
aux2.setLegend((VectorialLegend) renderer); |
314 |
} |
315 |
|
316 |
} |
317 |
} |
318 |
else if (renderer instanceof SingleSymbolLegend) |
319 |
aux2.setLegend((VectorialLegend) renderer); |
320 |
} |
321 |
|
322 |
} |
323 |
// aux.setLegend((VectorialLegend) m_Renderer);
|
324 |
|
325 |
} catch (ReadDriverException e) {
|
326 |
e.printStackTrace(); |
327 |
} catch (LegendLayerException e) {
|
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 (ReadDriverException e) {
|
375 |
e.printStackTrace(); |
376 |
} |
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 ReadDriverException{ |
405 |
|
406 |
// FIXME REVISAR ESTO (Quizas lanzar TaskException)
|
407 |
return new CreateSpatialIndexMonitorableTask((FLyrVect)layer); |
408 |
} |
409 |
|
410 |
/**
|
411 |
* DOCUMENT ME!
|
412 |
*
|
413 |
* @author Fernando Gonz?lez Cort?s
|
414 |
*/
|
415 |
private class ComandosListener implements ActionListener { |
416 |
private FThemeManagerWindow fLayerPropertiesWindow;
|
417 |
|
418 |
/**
|
419 |
* Creates a new ComandosListener object.
|
420 |
*
|
421 |
* @param lg DOCUMENT ME!
|
422 |
*/
|
423 |
public ComandosListener(FThemeManagerWindow fLayerPropertiesWindow) {
|
424 |
this.fLayerPropertiesWindow = fLayerPropertiesWindow;
|
425 |
} |
426 |
|
427 |
/* (non-Javadoc)
|
428 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
429 |
*/
|
430 |
public void actionPerformed(ActionEvent e) { |
431 |
if (e.getActionCommand() == "OK") { |
432 |
// Implementaci?n para hacer funcionar el hyperlink ...
|
433 |
//com.iver.cit.gvsig.gui.View theView = (com.iver.cit.gvsig.gui.View)PluginServices.getMDIManager().getActiveView();
|
434 |
//ProjectView view = theView.getModel();
|
435 |
if (PluginServices.getMainFrame() != null) |
436 |
{ |
437 |
IProjectView view = fPanelScaleManager.getView(); |
438 |
view.setTypeLink(fPanelScaleManager.getLinkType()); |
439 |
if (fPanelScaleManager.getSelectedLinkField()!=null) |
440 |
{ |
441 |
view.setSelectedField(fPanelScaleManager.getSelectedLinkField().toString().trim()); |
442 |
view.setExtLink(fPanelScaleManager.getExtensionLink()); |
443 |
} |
444 |
} |
445 |
//
|
446 |
fLayerPropertiesWindow.btnApply_actionPerformed(e); |
447 |
if (PluginServices.getMainFrame() == null) |
448 |
((JDialog) (getParent().getParent().getParent().getParent())).dispose();
|
449 |
else
|
450 |
PluginServices.getMDIManager().closeWindow(FThemeManagerWindow.this); |
451 |
System.out.println("Ok"); |
452 |
} else if (e.getActionCommand() == "CANCEL") { |
453 |
if (PluginServices.getMainFrame() == null) |
454 |
((JDialog) (getParent().getParent().getParent().getParent())).dispose();
|
455 |
else
|
456 |
PluginServices.getMDIManager().closeWindow(FThemeManagerWindow.this); |
457 |
System.out.println("CANCEL"); |
458 |
} else if (e.getActionCommand() == "APPLY") { |
459 |
fLayerPropertiesWindow.btnApply_actionPerformed(e); |
460 |
System.out.println("APPLY"); |
461 |
} else if (e.getActionCommand() == "LOAD_LEGEND") { |
462 |
JFileChooser jfc = new JFileChooser(); |
463 |
jfc.addChoosableFileFilter(new GenericFileFilter("avl","Files AVL")); |
464 |
jfc.addChoosableFileFilter(new GenericFileFilter("sld","Files SLD")); |
465 |
jfc.addChoosableFileFilter(new GenericFileFilter("gvl","Files GVL")); |
466 |
|
467 |
|
468 |
|
469 |
if (jfc.showOpenDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
470 |
File file=jfc.getSelectedFile();
|
471 |
if (jfc.getFileFilter().getDescription().equals("Files GVL")) { |
472 |
if(!(file.getPath().toUpperCase().endsWith(".GVL"))){ |
473 |
file=new File(file.getPath()+".gvl"); |
474 |
} |
475 |
readLegend(file); |
476 |
} else if (jfc.getFileFilter().getDescription().equals("Files SLD")) { |
477 |
if(!(file.getPath().toUpperCase().endsWith(".SLD"))) { |
478 |
file=new File(file.getPath()+".sld"); |
479 |
} |
480 |
importFromSLD(file); |
481 |
} else if (jfc.getFileFilter().getDescription().equals("Files AVL")) { |
482 |
if(!(file.getPath().toUpperCase().endsWith(".AVL"))) { |
483 |
file=new File(file.getPath()+".avl"); |
484 |
} |
485 |
importFromAVL(file); |
486 |
} |
487 |
|
488 |
fPanelLegendManager.setRenderer(renderer); |
489 |
fPanelLegendManager.actualizar(); |
490 |
} |
491 |
} else if (e.getActionCommand() == "SAVE_LEGEND") { |
492 |
fLayerPropertiesWindow.btnApply_actionPerformed(e); |
493 |
JFileChooser jfc = new JFileChooser(); |
494 |
jfc.addChoosableFileFilter(new GenericFileFilter("sld","File SLD")); |
495 |
jfc.addChoosableFileFilter(new GenericFileFilter("gvl","File GVL")); |
496 |
|
497 |
|
498 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) |
499 |
{ |
500 |
File file=jfc.getSelectedFile();
|
501 |
if (jfc.getFileFilter().accept(new File("dummy.sld"))) |
502 |
{ |
503 |
if (!(file.getPath().toLowerCase().endsWith(".sld"))){ |
504 |
file=new File(file.getPath()+".sld"); |
505 |
} |
506 |
export2SLD(file); |
507 |
} |
508 |
else{
|
509 |
if (!(file.getPath().toLowerCase().endsWith(".gvl"))){ |
510 |
file=new File(file.getPath()+".gvl"); |
511 |
} |
512 |
writeLegend(file); |
513 |
} |
514 |
} |
515 |
} else {}
|
516 |
} |
517 |
} |
518 |
private void importFromAVL(File avlFile) { |
519 |
File temp=new File(Utilities.TEMPDIRECTORYPATH); |
520 |
if (!temp.exists())
|
521 |
temp.mkdir(); |
522 |
File sldFile = new File(Utilities.TEMPDIRECTORYPATH+"/sldFile.sld"); |
523 |
|
524 |
if (!sldFile.exists())
|
525 |
try {
|
526 |
sldFile.createNewFile(); |
527 |
} catch (IOException e) { |
528 |
e.printStackTrace(); |
529 |
} |
530 |
|
531 |
sldFile.deleteOnExit(); |
532 |
temp.deleteOnExit(); |
533 |
try {
|
534 |
AVL2SLD.avl2sld(avlFile, sldFile,((FLyrVect)layer).getShapeType()); |
535 |
} catch (ReadDriverException e) {
|
536 |
e.printStackTrace(); |
537 |
} |
538 |
importFromSLD(sldFile); |
539 |
} |
540 |
private void export2SLD(File file) { |
541 |
try {
|
542 |
FileWriter writer = new FileWriter(file.getAbsolutePath()); |
543 |
writer.write( renderer.getSLDString(layer.getName())); |
544 |
writer.close(); |
545 |
|
546 |
// Marshaller m = new Marshaller(writer);
|
547 |
// m.setEncoding("ISO-8859-1");
|
548 |
// m.marshal(renderer.getSLDString());
|
549 |
} catch (Exception e) { |
550 |
NotificationManager.addError(PluginServices.getText(this, "Error_exportando_SLD"), e); |
551 |
} |
552 |
} |
553 |
private void importFromSLD(File file) { |
554 |
renderer =SLD2GVL.sld2gvl(file); |
555 |
} |
556 |
private void writeLegend(File file) { |
557 |
try {
|
558 |
FileOutputStream fos = new FileOutputStream(file.getAbsolutePath()); |
559 |
OutputStreamWriter writer = new OutputStreamWriter(fos, ProjectExtension.PROJECTENCODING); |
560 |
Marshaller m = new Marshaller(writer);
|
561 |
m.setEncoding(ProjectExtension.PROJECTENCODING); |
562 |
XMLEntity xml = renderer.getXMLEntity(); |
563 |
xml.putProperty("followHeaderEncoding", true); |
564 |
m.marshal(xml.getXmlTag()); |
565 |
} catch (Exception e) { |
566 |
NotificationManager.addError(PluginServices.getText(this, "Error_guardando_la_leyenda"), e); |
567 |
} |
568 |
} |
569 |
|
570 |
public void readLegend(File file) { |
571 |
File xmlFile = new File(file.getAbsolutePath()); |
572 |
try {
|
573 |
String encoding = XMLEncodingUtils.getEncoding(new FileInputStream(xmlFile)); |
574 |
InputStreamReader reader=null; |
575 |
if (encoding!=null) { |
576 |
try {
|
577 |
reader = new InputStreamReader(new FileInputStream(xmlFile), encoding); |
578 |
renderer= readLegend(reader, true);
|
579 |
} catch (UnsupportedEncodingException e) { |
580 |
reader = new InputStreamReader(new FileInputStream(xmlFile),"ISO-8859-1"); |
581 |
try {
|
582 |
renderer= readLegend(reader, false);
|
583 |
} catch (UnsupportedEncodingException e1) { |
584 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this, e1.getLocalizedMessage())); |
585 |
return;
|
586 |
} |
587 |
} |
588 |
} |
589 |
else {
|
590 |
reader = new InputStreamReader(new FileInputStream(xmlFile),"UTF-8"); |
591 |
try {
|
592 |
renderer= readLegend(reader, false);
|
593 |
} catch (UnsupportedEncodingException e1) { |
594 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this, e1.getLocalizedMessage())); |
595 |
return;
|
596 |
} |
597 |
} |
598 |
} catch (FileNotFoundException e) { |
599 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this, "fichero_incorrecto")); |
600 |
return;
|
601 |
} catch (UnsupportedEncodingException e) { |
602 |
e.printStackTrace(); |
603 |
} |
604 |
} |
605 |
public Legend readLegend(Reader reader, boolean encodingFollowed) throws UnsupportedEncodingException { |
606 |
Legend legend = null;
|
607 |
|
608 |
try {
|
609 |
XmlTag tag = (XmlTag) XmlTag.unmarshal(reader); |
610 |
XMLEntity xml=new XMLEntity(tag);
|
611 |
if (encodingFollowed) {
|
612 |
if (xml.contains("followHeaderEncoding")) { |
613 |
boolean useEncoding = xml.getBooleanProperty("followHeaderEncoding"); |
614 |
if (!useEncoding) {
|
615 |
throw new UnsupportedEncodingException("the encoding specified in the xml header is not safe"); |
616 |
} |
617 |
} |
618 |
else {
|
619 |
// Old projects didn't contain followHeaderEncoding and they were
|
620 |
// not correctly encoded. We throw an exception now, and we'll try
|
621 |
// to reopen the project
|
622 |
// using the default system encoding.
|
623 |
throw new UnsupportedEncodingException("the encoding specified in the xml header is not safe"); |
624 |
} |
625 |
} |
626 |
|
627 |
legend = LegendFactory.createFromXML(xml); |
628 |
return legend;
|
629 |
} catch (MarshalException e) { |
630 |
PluginServices.getLogger().error(PluginServices.getText(this, "formato_incorrecto"),e); |
631 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this, "formato_incorrecto")); |
632 |
//NotificationManager.addError("Al leer el proyecto", e);
|
633 |
} catch (ValidationException e) {
|
634 |
PluginServices.getLogger().error(PluginServices.getText(this, "formato_incorrecto"),e); |
635 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this, "formato_incorrecto")); |
636 |
//NotificationManager.addError("Al leer el proyecto", e);
|
637 |
} catch (XMLException e) {
|
638 |
PluginServices.getLogger().error(PluginServices.getText(this, "formato_incorrecto"),e); |
639 |
JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this, "formato_incorrecto")); |
640 |
//NotificationManager.addError("Al leer el proyecto", e);
|
641 |
} |
642 |
return null; |
643 |
} |
644 |
/* (non-Javadoc)
|
645 |
* @see com.iver.andami.ui.mdiManager.View#getViewInfo()
|
646 |
*/
|
647 |
public WindowInfo getWindowInfo() {
|
648 |
// Solo se llama una vez
|
649 |
WindowInfo viewInfo = new WindowInfo(WindowInfo.MODELESSDIALOG);
|
650 |
viewInfo.setWidth(650);
|
651 |
viewInfo.setHeight(420);
|
652 |
viewInfo.setTitle(PluginServices.getText(this,"propiedades_de_la_capa")); |
653 |
return viewInfo;
|
654 |
} |
655 |
|
656 |
/**
|
657 |
* @see com.iver.mdiApp.ui.MDIManager.View#viewActivated()
|
658 |
*/
|
659 |
/*public void viewActivated() {
|
660 |
}
|
661 |
|
662 |
public FMap getMapContext() {
|
663 |
return mapContext;
|
664 |
}
|
665 |
public FLayer getLayer() {
|
666 |
return layer;
|
667 |
}
|
668 |
public Legend getRenderer() {
|
669 |
return renderer;
|
670 |
}*/
|
671 |
|
672 |
/**
|
673 |
* @return Returns the organizador.
|
674 |
*/
|
675 |
public JTabbedPane getOrganizador() { |
676 |
return organizador;
|
677 |
} |
678 |
/**
|
679 |
* @param organizador The organizador to set.
|
680 |
*/
|
681 |
public void setOrganizador(JTabbedPane organizador) { |
682 |
this.organizador = organizador;
|
683 |
} |
684 |
} |