Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / view / legend / gui / FThemeManagerWindow.java @ 12650

History | View | Annotate | Download (24.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.InputStreamReader;
56
import java.io.OutputStreamWriter;
57
import java.io.Reader;
58
import java.io.UnsupportedEncodingException;
59
import java.text.NumberFormat;
60
import java.text.ParseException;
61

    
62
import javax.swing.JButton;
63
import javax.swing.JDialog;
64
import javax.swing.JFileChooser;
65
import javax.swing.JOptionPane;
66
import javax.swing.JPanel;
67
import javax.swing.JTabbedPane;
68

    
69
import org.exolab.castor.xml.MarshalException;
70
import org.exolab.castor.xml.Marshaller;
71
import org.exolab.castor.xml.ValidationException;
72

    
73
import com.hardcode.gdbms.engine.data.DataSource;
74
import com.hardcode.gdbms.engine.instruction.FieldNotFoundException;
75
import com.iver.andami.PluginServices;
76
import com.iver.andami.messages.NotificationManager;
77
import com.iver.andami.ui.mdiManager.IWindow;
78
import com.iver.andami.ui.mdiManager.WindowInfo;
79
import com.iver.cit.gvsig.ProjectExtension;
80
import com.iver.cit.gvsig.fmap.DriverException;
81
import com.iver.cit.gvsig.fmap.MapContext;
82
import com.iver.cit.gvsig.fmap.drivers.DriverIOException;
83
import com.iver.cit.gvsig.fmap.layers.FLayer;
84
import com.iver.cit.gvsig.fmap.layers.FLayers;
85
import com.iver.cit.gvsig.fmap.layers.FLyrVect;
86
import com.iver.cit.gvsig.fmap.layers.XMLException;
87
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData;
88
import com.iver.cit.gvsig.fmap.layers.layerOperations.ClassifiableVectorial;
89
import com.iver.cit.gvsig.fmap.rendering.ClassifiedLegend;
90
import com.iver.cit.gvsig.fmap.rendering.Legend;
91
import com.iver.cit.gvsig.fmap.rendering.LegendFactory;
92
import com.iver.cit.gvsig.fmap.rendering.SingleSymbolLegend;
93
import com.iver.cit.gvsig.fmap.rendering.VectorialLegend;
94
import com.iver.cit.gvsig.gui.panels.LinkPanel;
95
import com.iver.cit.gvsig.project.documents.view.IProjectView;
96
import com.iver.cit.gvsig.project.documents.view.legend.CreateSpatialIndexMonitorableTask;
97
import com.iver.cit.gvsig.project.documents.view.legend.scale.gui.FPanelScaleManager;
98
import com.iver.utiles.GenericFileFilter;
99
import com.iver.utiles.XMLEntity;
100
import com.iver.utiles.swing.threads.IMonitorableTask;
101
import com.iver.utiles.xml.XMLEncodingUtils;
102
import com.iver.utiles.xmlEntity.generate.XmlTag;
103

    
104
/**
105
 * @author jmorell (jose.morell@gmail.com)
106
 * @version 24-ene-2005
107
 */
108
public final class FThemeManagerWindow extends AbstractPanel implements IWindow {
109
        private MapContext mapContext;
110
        private FLayer layer;
111
    private Legend renderer; // Le asignaremos la leyenda del primer tema activo.
112
        private FPanelScaleManager fPanelScaleManager;
113
    private FPanelLegendManager fPanelLegendManager;
114
    private LinkPanel linkPanel;
115
    private JTabbedPane organizador = new JTabbedPane();  //  @jve:decl-index=0:
116
    private ComandosListener m_actionListener = new ComandosListener(this);
117
        //private ProjectView view;
118
        private NumberFormat nf = NumberFormat.getInstance();
119

    
120
    /**
121
     * Creates new form JPanel
122
     */
123
    public FThemeManagerWindow() {
124
        initialize();
125
                this.setSize(650, 420);
126
    }
127

    
128
    /**
129
     * Sobrecarga del constructor. Este se utiliza cuando se llama a este
130
     * di?logo desde la barra de comandos.
131
     *
132
     */
133
    public FThemeManagerWindow(FLayer l, MapContext fMap) {
134
            initialize();
135
            layer = l;
136
            mapContext = fMap;
137
                try {
138
                        ClassifiableVectorial aux = (ClassifiableVectorial) layer;
139
                        renderer = (Legend) aux.getLegend().cloneLegend();
140
                        fPanelScaleManager.setMapContext(mapContext);
141
                        fPanelLegendManager.setMapContext(mapContext);
142
                } catch (XMLException e) {
143
                        // TODO Auto-generated catch block
144
                        e.printStackTrace();
145
                } catch (DriverException e1) {
146
                        // TODO Auto-generated catch block
147
                        e1.printStackTrace();
148
                }
149

    
150
        fPanelScaleManager.setLayer(layer, renderer);
151
        fPanelLegendManager.setLayer(layer, renderer);
152

    
153
        organizador.setSelectedIndex(0);
154

    
155
                this.setSize(650, 420);
156
    }
157

    
158
        /**
159
         * This method initializes this
160
         *
161
         * @return void
162
         */
163
        private  void initialize() {
164

    
165
                fPanelScaleManager = new FPanelScaleManager();
166
                fPanelLegendManager = new FPanelLegendManager();
167

    
168
                organizador.addTab(PluginServices.getText(this,"General"), fPanelScaleManager);
169
                organizador.addTab(PluginServices.getText(this,"Simbologia"), fPanelLegendManager);
170

    
171
        JPanel panelButtons = new JPanel();
172

    
173
        JButton btnAceptar = new JButton(PluginServices.getText(this,"Aceptar"));
174
        btnAceptar.setActionCommand("OK");
175
        btnAceptar.addActionListener(m_actionListener);
176

    
177
        JButton btnApply = new JButton(PluginServices.getText(this,"Aplicar"));
178
        btnApply.setActionCommand("APPLY");
179
        btnApply.addActionListener(m_actionListener);
180

    
181
        JButton btnSaveLegend = new JButton(PluginServices.getText(this,"Guardar_leyenda")+"...");
182
        btnSaveLegend.setActionCommand("SAVE_LEGEND");
183
        btnSaveLegend.addActionListener(m_actionListener);
184

    
185
        JButton btnLoadLegend = new JButton(PluginServices.getText(this,"Recuperar_leyenda")+"...");
186
        btnLoadLegend.setActionCommand("LOAD_LEGEND");
187
        btnLoadLegend.addActionListener(m_actionListener);
188

    
189
        JButton btnCancelar = new JButton(PluginServices.getText(this,"Cerrar"));
190
        btnCancelar.setActionCommand("CANCEL");
191
        btnCancelar.addActionListener(m_actionListener);
192

    
193
        panelButtons.add(btnApply, null);
194

    
195
                setLayout(new BorderLayout());
196
                panelButtons.setLayout(null);
197
                organizador.setPreferredSize(new java.awt.Dimension(640,390));
198
                btnAceptar.setBounds(9, 5, 89, 23);
199
                btnApply.setBounds(107, 5, 89, 23);
200
                btnSaveLegend.setBounds(205, 5, 159, 23);
201
                btnLoadLegend.setBounds(373, 5, 159, 23);
202
                btnCancelar.setBounds(541, 5, 89, 23);
203
                panelButtons.setPreferredSize(new java.awt.Dimension(493,33));
204
                add(organizador, java.awt.BorderLayout.NORTH);
205
                panelButtons.add(btnAceptar, null);
206
                add(panelButtons, java.awt.BorderLayout.SOUTH);
207
                panelButtons.add(btnSaveLegend, null);
208
                panelButtons.add(btnLoadLegend, null);
209
                panelButtons.add(btnCancelar, null);
210
        }
211

    
212

    
213

    
214
    /**
215
     * En esta funci?n se coge el primer tema activo del TOC y se usa su
216
     * renderer para inicializar. Hay que llamarla SIEMPRE que se abra el
217
     * cuadro de di?logo, en el  openLegendManager() de la vista.
218
     *
219
     * @param mapContext TOC que abre este cuadro de di?logo.
220
     * @throws DriverException
221
     */
222
    public void setMapContext(MapContext mapContext) throws DriverException {
223
        this.mapContext = mapContext;
224
        layer = getFirstActiveLayerVect(mapContext.getLayers());
225
                try {
226
                        ClassifiableVectorial aux = (ClassifiableVectorial) layer;
227
                        renderer = (Legend) aux.getLegend().cloneLegend();
228
                } catch (XMLException e) {
229
                        // TODO Auto-generated catch block
230
                        e.printStackTrace();
231
                }
232
                fPanelScaleManager.setMapContext(mapContext);
233
                fPanelLegendManager.setMapContext(mapContext);
234
        actualizar();
235
    }
236

    
237
    /**
238
     * DOCUMENT ME!
239
     */
240
    private void actualizar() {
241
            FLayer lyrSelected = getFirstActiveLayerVect(mapContext.getLayers());
242

    
243
        fPanelScaleManager.setLayer(lyrSelected, renderer);
244
        fPanelLegendManager.setLayer(lyrSelected, renderer);
245

    
246
        organizador.setSelectedIndex(0);
247
    }
248

    
249
    private void btnApply_actionPerformed(ActionEvent evt) {
250
       // ClassifiableVectorial aux = (ClassifiableVectorial) layer;
251

    
252
            switch (fPanelLegendManager.getVisibleCard()) {
253
        case 0: // default symbol
254
            renderer = fPanelLegendManager.getM_defaultLegendPanel().getLegend();
255
            fPanelLegendManager.getJComboBox().getModel().setSelectedItem(layer.getName() + PluginServices.getText(this,"_(Simbolo_unico)"));
256
            break;
257
        case 1: // Unique Values
258
            renderer = fPanelLegendManager.getM_valuesLegendPanel().getLegend();
259
            fPanelLegendManager.getJComboBox().getModel().setSelectedItem(layer.getName() + "_(Valores_unicos)");
260
            break;
261
        case 2:// break values
262
                   renderer = fPanelLegendManager.getM_breaksLegendPanel().getLegend();
263
            fPanelLegendManager.getJComboBox().getModel().setSelectedItem(layer.getName() + "_(Intervalos)");
264
                   break;
265
        case 3://text
266
                fPanelLegendManager.getJComboBox().getModel().setSelectedItem(layer.getName() + "_(Etiquetas_estandar)");
267
        }
268
        // System.out.println("Color punto 1 " + renderer.getDefaultSymbol().getColor().toString());
269
            // fPanelLegendManager.getM_labelsLegendPanel().setFSymbol(renderer.getDefaultSymbol());
270
            // boolean bShapesVisibles = renderer.getDefaultSymbol().isShapeVisible();
271
            fPanelLegendManager.getM_labelsLegendPanel().updateValuesFromControls((VectorialLegend)renderer);
272
            // renderer.getDefaultSymbol().setShapeVisible(bShapesVisibles);
273
        // System.out.println("Color punto 2 " + renderer.getDefaultSymbol().getColor().toString());
274
        try {
275
                        // Intentamos aplicar la leyenda a todas
276
            // las capas activas a las que se les pueda aplicar
277
            FLayer[] activeLyrs =  mapContext.getLayers().getActives();
278
            for (int i=0; i < activeLyrs.length; i++)
279
            {
280
                    FLayer laux=activeLyrs[i];
281
                    if (activeLyrs[i] instanceof FLayers){
282
                            laux=getFirstActiveLayerVect((FLayers)activeLyrs[i]);
283
                    }
284
                if (laux instanceof ClassifiableVectorial)
285
                {
286
                    ClassifiableVectorial aux2 = (ClassifiableVectorial) laux;
287
                    if (renderer instanceof ClassifiedLegend)
288
                    {
289
                        // Es una leyenda que necesita un recordset con un
290
                        // nombre de campo. Comprobamos que ese recordset
291
                        // tiene ese nombre de campo y es del tipo esperado
292
                        ClassifiedLegend cl = (ClassifiedLegend) renderer;
293
                        if (aux2 instanceof AlphanumericData)
294
                        {
295
                            DataSource rs = ((AlphanumericData) aux2).getRecordset();
296
                            if (cl.getValues().length==0) {
297
                                    JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this,"no_es_posible_aplicar_leyenda_vacia"));
298
                                    return;
299
                            }
300
                            int idField = rs.getFieldIndexByName(cl.getFieldName());
301
                            if (idField != -1)
302
                            {
303
                                //TODO: Aqu? deber?amos comprobar si el tipo de campo
304
                                // es el tipo de campo esperado.
305
                                    /*if (renderer instanceof VectorialUniqueValueLegend){
306
                                            ((VectorialUniqueValueLegend)renderer).setLabelHeightField(null);
307
                                            ((VectorialUniqueValueLegend)renderer).setLabelRotationField(null);
308
                                    }
309
                                    */
310
                                aux2.setLegend((VectorialLegend) renderer);
311
                            }
312

    
313
                        }
314
                    }
315
                    else if (renderer instanceof SingleSymbolLegend)
316
                        aux2.setLegend((VectorialLegend) renderer);
317
                }
318

    
319
            }
320
                        // aux.setLegend((VectorialLegend) m_Renderer);
321

    
322
                } catch (FieldNotFoundException e) {
323
                        NotificationManager.addError(e.getMessage(),e);
324
                } catch (DriverException e) {
325
                        NotificationManager.addError(e.getMessage(),e);
326
                } catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
327
            NotificationManager.addError(e.getMessage(),e);
328
        }
329

    
330
                if (fPanelScaleManager.getJRadioButton1().isSelected()) {
331
                        try
332
                        {
333
                                layer.setMinScale((nf.parse(fPanelScaleManager.getJTextField1().getText())).doubleValue());
334
                        }
335
                        catch (ParseException ex)
336
                        {
337
                            if (fPanelScaleManager.getJTextField1().getText().compareTo("") == 0)
338
                                layer.setMinScale(-1);
339
                            else
340
                                System.err.print(ex.getLocalizedMessage());
341
                        }
342
                        try
343
                        {
344
                            layer.setMaxScale((nf.parse(fPanelScaleManager.getJTextField2().getText())).doubleValue());
345
                        }
346
                        catch (ParseException ex)
347
                        {
348
                            if (fPanelScaleManager.getJTextField2().getText().compareTo("") == 0)
349
                                layer.setMaxScale(-1);
350
                            else
351
                                System.err.print(ex.getLocalizedMessage());
352
                        }
353

    
354
                } else {
355
                layer.setMinScale(-1);
356
                layer.setMaxScale(-1);
357
                }
358
                if (!fPanelScaleManager.getLayerName().equals(layer.getName())){
359
                        layer.setName(fPanelScaleManager.getLayerName());
360
                }
361
        if (layer instanceof FLyrVect)
362
        {
363
            FLyrVect lyrVect = (FLyrVect) layer;
364
            if (fPanelScaleManager.isSpatialIndexSelected())
365
            {
366
//                if (lyrVect.getSpatialIndex() == null)
367
                    if(lyrVect.getISpatialIndex() == null)
368
                {
369
                        //AZABALA
370
                        try {
371
                                                PluginServices.
372
                                                        cancelableBackgroundExecution(getCreateSpatialIndexTask());
373
                                        } catch (DriverIOException e) {
374
                                                // TODO Auto-generated catch block
375
                                                e.printStackTrace();
376
                                        } catch (DriverException e) {
377
                                                // TODO Auto-generated catch block
378
                                                e.printStackTrace();
379
                                        }
380
//                    lyrVect.createSpatialIndex();
381
                }
382
            }
383
            //AZABALA
384
            /*
385
             * If we unselect the spatial index checkbox...Must we delete
386
             * spatial index file, or we only have to put Spatial Index
387
             * reference to null?. I have followed the second choice
388
             */
389
            else{
390
                lyrVect.deleteSpatialIndex();
391
            }
392

    
393

    
394
        }
395
                //layer.getFMap().invalidate();
396
                layer.getMapContext().callLegendChanged();
397
    }
398

    
399

    
400
    /**
401
     * Instanciates a ITask (@see com.iver.utiles.swing.threads.ITask)
402
     * to create a spatial index for the selected layer in background.
403
     * This task also allow to monitor process evolution, and to cancel
404
     * this process.
405
     * @throws DriverException
406
     * @throws DriverIOException
407
     */
408
    public IMonitorableTask getCreateSpatialIndexTask() throws DriverIOException,
409
                                                                                                                            DriverException{
410

    
411
//              FIXME REVISAR ESTO (Quizas lanzar TaskException)
412
                        return new CreateSpatialIndexMonitorableTask((FLyrVect)layer);
413
    }
414

    
415
    /**
416
     * DOCUMENT ME!
417
     *
418
     * @author Fernando Gonz?lez Cort?s
419
     */
420
    private class ComandosListener implements ActionListener {
421
        private FThemeManagerWindow fLayerPropertiesWindow;
422

    
423
        /**
424
         * Creates a new ComandosListener object.
425
         *
426
         * @param lg DOCUMENT ME!
427
         */
428
        public ComandosListener(FThemeManagerWindow fLayerPropertiesWindow) {
429
                this.fLayerPropertiesWindow = fLayerPropertiesWindow;
430
        }
431

    
432
        /* (non-Javadoc)
433
         * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
434
         */
435
        public void actionPerformed(ActionEvent e) {
436
            if (e.getActionCommand() == "OK") {
437
                // Implementaci?n para hacer funcionar el hyperlink ...
438
                //com.iver.cit.gvsig.gui.View theView = (com.iver.cit.gvsig.gui.View)PluginServices.getMDIManager().getActiveView();
439
                //ProjectView view = theView.getModel();
440
                    if (PluginServices.getMainFrame() != null)
441
                    {
442
                            IProjectView view = fPanelScaleManager.getView();
443
                            view.setTypeLink(fPanelScaleManager.getLinkType());
444
                            if (fPanelScaleManager.getSelectedLinkField()!=null)
445
                            {
446
                                    view.setSelectedField(fPanelScaleManager.getSelectedLinkField().toString().trim());
447
                                    view.setExtLink(fPanelScaleManager.getExtensionLink());
448
                            }
449
                    }
450
                //
451
                fLayerPropertiesWindow.btnApply_actionPerformed(e);
452
                    if (PluginServices.getMainFrame() == null)
453
                            ((JDialog) (getParent().getParent().getParent().getParent())).dispose();
454
                    else
455
                            PluginServices.getMDIManager().closeWindow(FThemeManagerWindow.this);
456
                System.out.println("Ok");
457
            } else if (e.getActionCommand() == "CANCEL") {
458
                    if (PluginServices.getMainFrame() == null)
459
                            ((JDialog) (getParent().getParent().getParent().getParent())).dispose();
460
                    else
461
                            PluginServices.getMDIManager().closeWindow(FThemeManagerWindow.this);
462
                System.out.println("CANCEL");
463
            } else if (e.getActionCommand() == "APPLY") {
464
                fLayerPropertiesWindow.btnApply_actionPerformed(e);
465
                System.out.println("APPLY");
466
            } else if (e.getActionCommand() == "LOAD_LEGEND") {
467
                        JFileChooser jfc = new JFileChooser();
468
                            jfc.addChoosableFileFilter(new GenericFileFilter("gvl",
469
                                            PluginServices.getText(this, "tipo_de_leyenda")));
470
                            //jfc.addChoosableFileFilter(new GenericFileFilter("sld","sld"));
471

    
472
                            if (jfc.showOpenDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) {
473
                                    File file=jfc.getSelectedFile();
474
                                    if (!(file.getPath().endsWith(".gvl") || file.getPath().endsWith(".GVL")))
475
                                    {
476
                                            file=new File(file.getPath()+".gvl");
477
                                    }
478
                                    readLegend(file);
479
                                    fPanelLegendManager.setRenderer(renderer);
480
                                    fPanelLegendManager.actualizar();
481
                            }
482
            } else if (e.getActionCommand() == "SAVE_LEGEND") {
483
                                fLayerPropertiesWindow.btnApply_actionPerformed(e);
484
                                JFileChooser jfc = new JFileChooser();
485
                                jfc.addChoosableFileFilter(new GenericFileFilter("sld","*.sld"));
486
                                jfc.addChoosableFileFilter(new GenericFileFilter("gvl",
487
                                                PluginServices.getText(this, "tipo_de_leyenda")));
488

    
489

    
490
                                if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION)
491
                                {
492
                                        File file=jfc.getSelectedFile();
493
                                        if (jfc.getFileFilter().accept(new File("dummy.sld")))
494
                                        {
495
                                                if (!(file.getPath().toLowerCase().endsWith(".sld"))){
496
                                                        file=new File(file.getPath()+".sld");
497
                                                }
498
                                                export2SLD(file);
499
                                        }
500
                                        else{
501
                                                if (!(file.getPath().toLowerCase().endsWith(".gvl"))){
502
                                                        file=new File(file.getPath()+".gvl");
503
                                                }
504
                                                writeLegend(file);
505
                                        }
506
                                }
507
            } else {}
508
        }
509
    }
510

    
511
    private void export2SLD(File file) {
512
                try {
513
                        FileWriter writer = new FileWriter(file.getAbsolutePath());
514
                        writer.write( renderer.getSLDString(layer.getName()));
515
                        writer.close();
516

    
517
//                        Marshaller m = new Marshaller(writer);
518
//                        m.setEncoding("ISO-8859-1");
519
//                        m.marshal(renderer.getSLDString());
520
                } catch (Exception e) {
521
                        NotificationManager.addError(PluginServices.getText(this, "Error_exportando_SLD"), e);
522
                }
523
        }
524

    
525
    private void writeLegend(File file) {
526
                try {
527
                        FileOutputStream fos = new FileOutputStream(file.getAbsolutePath());
528
            OutputStreamWriter writer = new OutputStreamWriter(fos, ProjectExtension.PROJECTENCODING);
529
                        Marshaller m = new Marshaller(writer);
530
                        m.setEncoding(ProjectExtension.PROJECTENCODING);
531
                        XMLEntity xml = renderer.getXMLEntity();
532
                        xml.putProperty("followHeaderEncoding", true);
533
                        m.marshal(xml.getXmlTag());
534
                } catch (Exception e) {
535
                        NotificationManager.addError(PluginServices.getText(this, "Error_guardando_la_leyenda"), e);
536
                }
537
        }
538

    
539
        public void readLegend(File file) {
540
                File xmlFile = new File(file.getAbsolutePath());
541
                try {
542
                        String encoding = XMLEncodingUtils.getEncoding(new FileInputStream(xmlFile));
543
                        InputStreamReader reader=null;
544
                        if (encoding!=null) {
545
                                try {
546
                                        reader = new InputStreamReader(new FileInputStream(xmlFile), encoding);
547
                                        renderer= readLegend(reader, true);
548
                                } catch (UnsupportedEncodingException e) {
549
                                        reader = new InputStreamReader(new FileInputStream(xmlFile),"ISO-8859-1");
550
                                        try {
551
                                                renderer= readLegend(reader, false);
552
                                        } catch (UnsupportedEncodingException e1) {
553
                                                JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this, e1.getLocalizedMessage()));
554
                                                return;
555
                                        }
556
                                }
557
                        }
558
                        else {
559
                                reader = new InputStreamReader(new FileInputStream(xmlFile),"UTF-8");
560
                                try {
561
                                        renderer= readLegend(reader, false);
562
                                } catch (UnsupportedEncodingException e1) {
563
                                        JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this, e1.getLocalizedMessage()));
564
                                        return;
565
                                }
566
                        }
567
                } catch (FileNotFoundException e) {
568
                        JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this, "fichero_incorrecto"));
569
                        return;
570
                } catch (UnsupportedEncodingException e) {
571
                        e.printStackTrace();
572
                }
573
        }
574
        public Legend readLegend(Reader reader, boolean encodingFollowed) throws UnsupportedEncodingException {
575
                Legend legend = null;
576

    
577
                try {
578
                        XmlTag tag = (XmlTag) XmlTag.unmarshal(reader);
579
                        XMLEntity xml=new XMLEntity(tag);
580
                        if (encodingFollowed) {
581
                                if (xml.contains("followHeaderEncoding")) {
582
                                        boolean useEncoding = xml.getBooleanProperty("followHeaderEncoding");
583
                                        if (!useEncoding) {
584
                                                throw new UnsupportedEncodingException("the encoding specified in the xml header is not safe");
585
                                        }
586
                                }
587
                                else {
588
                                        // Old projects didn't contain followHeaderEncoding and they were
589
                                        // not correctly encoded. We throw an exception now, and we'll try
590
                                        // to reopen the project
591
                                        // using the default system encoding.
592
                                        throw new UnsupportedEncodingException("the encoding specified in the xml header is not safe");
593
                                }
594
                        }
595

    
596
                        legend = LegendFactory.createFromXML(xml);
597
                        return legend;
598
                }  catch (MarshalException e) {
599
                        PluginServices.getLogger().error(PluginServices.getText(this, "formato_incorrecto"),e);
600
                        JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this, "formato_incorrecto"));
601
                        //NotificationManager.addError("Al leer el proyecto", e);
602
                } catch (ValidationException e) {
603
                        PluginServices.getLogger().error(PluginServices.getText(this, "formato_incorrecto"),e);
604
                        JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this, "formato_incorrecto"));
605
                        //NotificationManager.addError("Al leer el proyecto", e);
606
                } catch (XMLException e) {
607
                        PluginServices.getLogger().error(PluginServices.getText(this, "formato_incorrecto"),e);
608
                        JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(),PluginServices.getText(this, "formato_incorrecto"));
609
                        //NotificationManager.addError("Al leer el proyecto", e);
610
                }
611
                return null;
612
        }
613
        /* (non-Javadoc)
614
         * @see com.iver.andami.ui.mdiManager.View#getViewInfo()
615
         */
616
        public WindowInfo getWindowInfo() {
617
                // Solo se llama una vez
618
                WindowInfo viewInfo = new WindowInfo(WindowInfo.MODELESSDIALOG);
619
                viewInfo.setWidth(650);
620
                viewInfo.setHeight(420);
621
                viewInfo.setTitle(PluginServices.getText(this,"propiedades_de_la_capa"));
622
                return viewInfo;
623
        }
624

    
625
        /**
626
         * @see com.iver.mdiApp.ui.MDIManager.View#viewActivated()
627
         */
628
        /*public void viewActivated() {
629
        }
630

631
        public FMap getMapContext() {
632
                return mapContext;
633
        }
634
        public FLayer getLayer() {
635
                return layer;
636
        }
637
        public Legend getRenderer() {
638
                return renderer;
639
        }*/
640

    
641
        /**
642
         * @return Returns the organizador.
643
         */
644
        public JTabbedPane getOrganizador() {
645
                return organizador;
646
        }
647
        /**
648
         * @param organizador The organizador to set.
649
         */
650
        public void setOrganizador(JTabbedPane organizador) {
651
                this.organizador = organizador;
652
        }
653
}