Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.app.document.layout.app / org.gvsig.app.document.layout.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / fframes / gui / dialogs / FFrameLegendDialog.java @ 36648

History | View | Annotate | Download (21.2 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.app.project.documents.layout.fframes.gui.dialogs;
23

    
24
import java.awt.Component;
25
import java.awt.Dimension;
26
import java.awt.Font;
27
import java.awt.event.ActionListener;
28
import java.awt.geom.Rectangle2D;
29
import java.util.ArrayList;
30
import java.util.List;
31

    
32
import javax.swing.BoxLayout;
33
import javax.swing.JButton;
34
import javax.swing.JCheckBox;
35
import javax.swing.JList;
36
import javax.swing.JPanel;
37
import javax.swing.JScrollPane;
38
import javax.swing.event.ChangeEvent;
39
import javax.swing.event.ChangeListener;
40

    
41
import org.gvsig.andami.PluginServices;
42
import org.gvsig.andami.ui.mdiManager.WindowInfo;
43
import org.gvsig.app.gui.utils.FontChooser;
44
import org.gvsig.app.project.documents.layout.FLayoutUtilities;
45
import org.gvsig.app.project.documents.layout.fframes.FFrameLegend;
46
import org.gvsig.app.project.documents.layout.fframes.FFrameView;
47
import org.gvsig.app.project.documents.layout.fframes.IFFrame;
48
import org.gvsig.app.project.documents.layout.fframes.ListViewModel;
49
import org.gvsig.app.project.documents.layout.fframes.gui.JPRotation;
50
import org.gvsig.app.project.documents.layout.gui.LayoutPanel;
51
import org.gvsig.fmap.mapcontext.layers.FLayer;
52
import org.gvsig.fmap.mapcontext.layers.FLayers;
53
import org.gvsig.gui.beans.AcceptCancelPanel;
54
import org.gvsig.tools.swing.api.ToolsSwingLocator;
55

    
56
/**
57
 * Dialogo para a?adir la leyenda de alguna vista al Layout.
58
 * 
59
 * @author Vicente Caballero Navarro
60
 */
61
public class FFrameLegendDialog extends AbstractFFrameDialog implements
62
    IFFrameDialog {
63

    
64
    private static final long serialVersionUID = -4661317813255825195L;
65
    private javax.swing.JPanel jContentPane = null;
66
    private javax.swing.JLabel lMarcoVista = null;
67
    private javax.swing.JScrollPane jScrollPane = null;
68
    private javax.swing.JLabel lVisualizacion = null;
69
    private javax.swing.JComboBox cbVisualizacion = null;
70
    private javax.swing.JLabel lCalidad = null;
71
    private javax.swing.JComboBox cbCalidad = null;
72
    private javax.swing.JList liVistas = null;
73
    private Rectangle2D rect = new Rectangle2D.Double();
74
    private FFrameLegend fframelegend = null; // new FFrameLegend();
75
    private List<String> nameLayers = new ArrayList<String>();
76
    private List<Boolean> areVisible = new ArrayList<Boolean>();
77
    private boolean isAcepted = false;
78
    private JButton bFuente = null;
79
    private FFrameView fframeview = null;
80
    private JPRotation pRotation = null;
81
    // private JLabel lblNumColum = null;
82
    // private JTextField txtNumColum = null;
83
    // private ColumPanel pNumColum = null;
84
    private JScrollPane jScrollPane1 = null;
85
    private JPanel jPanel = null;
86
    private AcceptCancelPanel accept;
87
    private IFFrame fframeDependence;
88
    private Font font;
89
    private FFrameLegend newFFrameLegend;
90

    
91
    /**
92
     * This is the default constructor
93
     * 
94
     * @param layoutPanel
95
     *            Referencia al Layout.
96
     * @param fframe
97
     *            Referencia al FFrameLegend.
98
     */
99
    public FFrameLegendDialog(LayoutPanel layoutPanel, IFFrame frame) {
100
        super(layoutPanel, frame);
101
        fframelegend = (FFrameLegend) frame;
102
        font = fframelegend.getFont();
103
        fframeDependence = fframelegend.getFFrameDependence()[0];
104
        initialize();
105
    }
106

    
107
    /**
108
     * Inserta el rect?ngulo que ocupar? el fframe de leyenda.
109
     * 
110
     * @param r
111
     *            extent.
112
     */
113
    public void setRectangle(Rectangle2D r) {
114
        rect.setRect(r);
115
    }
116

    
117
    /**
118
     * This method initializes this
119
     */
120
    private void initialize() {
121
        this.setLayout(null);
122
        this.add(getJContentPane(), null);
123
        this.setSize(616, 199);
124
        this.setSize(new java.awt.Dimension(616, 189));
125
        getPRotation().setRotation(fframelegend.getRotation());
126
    }
127

    
128
    /**
129
     * This method initializes jContentPane
130
     * 
131
     * @return javax.swing.JPanel
132
     */
133
    private javax.swing.JPanel getJContentPane() {
134
        if (jContentPane == null) {
135
            jContentPane = new javax.swing.JPanel();
136
            jContentPane.setLayout(null);
137
            jContentPane.setBounds(new java.awt.Rectangle(3, 1, 609, 183));
138
            jContentPane.add(getLMarcoVista(), null);
139
            jContentPane.add(getJScrollPane(), null);
140
            jContentPane.add(getLVisualizacion(), null);
141
            jContentPane.add(getCbVisualizacion(), null);
142
            jContentPane.add(getLCalidad(), null);
143
            jContentPane.add(getCbCalidad(), null);
144
            // jContentPane.add(getBAceptar(), null);
145
            // jContentPane.add(getBCancelar(), null);
146
            jContentPane.add(getAcceptCancelPanel(), null);
147
            jContentPane.add(getBFuente(), null);
148
            jContentPane.setBounds(3, 1, 609, 241);
149
            jContentPane.add(getPRotation(), null);
150
            // jContentPane.add(lblNumColum, null);
151
            jContentPane.add(getJScrollPane1(), null);
152
        }
153

    
154
        return jContentPane;
155
    }
156

    
157
    /**
158
     * This method initializes lMarcoVista
159
     * 
160
     * @return javax.swing.JLabel
161
     */
162
    private javax.swing.JLabel getLMarcoVista() {
163
        if (lMarcoVista == null) {
164
            lMarcoVista = new javax.swing.JLabel();
165
            lMarcoVista.setSize(115, 63);
166
            lMarcoVista.setText(PluginServices.getText(this, "marco_vista"));
167
            lMarcoVista.setLocation(5, 10);
168
        }
169

    
170
        return lMarcoVista;
171
    }
172

    
173
    /**
174
     * This method initializes jScrollPane
175
     * 
176
     * @return javax.swing.JScrollPane
177
     */
178
    private javax.swing.JScrollPane getJScrollPane() {
179
        if (jScrollPane == null) {
180
            jScrollPane = new javax.swing.JScrollPane();
181
            jScrollPane.setViewportView(getLiVistas());
182
            jScrollPane.setSize(179, 65);
183
            jScrollPane.setPreferredSize(new java.awt.Dimension(70, 60));
184
            jScrollPane.setLocation(129, 10);
185
        }
186

    
187
        return jScrollPane;
188
    }
189

    
190
    /**
191
     * This method initializes lVisualizacion
192
     * 
193
     * @return javax.swing.JLabel
194
     */
195
    private javax.swing.JLabel getLVisualizacion() {
196
        if (lVisualizacion == null) {
197
            lVisualizacion = new javax.swing.JLabel();
198
            lVisualizacion.setSize(115, 16);
199
            lVisualizacion.setText(PluginServices
200
                .getText(this, "visualizacion"));
201
            lVisualizacion.setLocation(6, 83);
202
            lVisualizacion.setVisible(false);
203
        }
204

    
205
        return lVisualizacion;
206
    }
207

    
208
    /**
209
     * This method initializes cbVisualizacion
210
     * 
211
     * @return javax.swing.JComboBox
212
     */
213
    private javax.swing.JComboBox getCbVisualizacion() {
214
        if (cbVisualizacion == null) {
215
            cbVisualizacion = new javax.swing.JComboBox();
216
            cbVisualizacion.addItem(PluginServices.getText(this,
217
                "cuando_activo"));
218
            cbVisualizacion.addItem(PluginServices.getText(this, "siempre"));
219
            cbVisualizacion.setSelectedIndex(fframelegend.getViewing());
220
            cbVisualizacion.setSize(179, 20);
221
            cbVisualizacion.setPreferredSize(new java.awt.Dimension(200, 20));
222
            cbVisualizacion.setLocation(129, 83);
223
            cbVisualizacion.setEnabled(false);
224
            cbVisualizacion.setVisible(false);
225
        }
226

    
227
        return cbVisualizacion;
228
    }
229

    
230
    /**
231
     * This method initializes lCalidad
232
     * 
233
     * @return javax.swing.JLabel
234
     */
235
    private javax.swing.JLabel getLCalidad() {
236
        if (lCalidad == null) {
237
            lCalidad = new javax.swing.JLabel();
238
            lCalidad.setSize(115, 20);
239
            lCalidad.setText(PluginServices.getText(this, "calidad"));
240
            lCalidad.setLocation(6, 103);
241
        }
242

    
243
        return lCalidad;
244
    }
245

    
246
    /**
247
     * This method initializes cbCalidad
248
     * 
249
     * @return javax.swing.JComboBox
250
     */
251
    private javax.swing.JComboBox getCbCalidad() {
252
        if (cbCalidad == null) {
253
            cbCalidad = new javax.swing.JComboBox();
254
            cbCalidad.addItem(PluginServices.getText(this, "presentacion"));
255
            cbCalidad.addItem(PluginServices.getText(this, "borrador"));
256
            cbCalidad.setSelectedIndex(fframelegend.getQuality());
257
            cbCalidad.setSize(179, 20);
258
            cbCalidad.setPreferredSize(new java.awt.Dimension(200, 20));
259
            cbCalidad.setLocation(129, 103);
260
        }
261

    
262
        return cbCalidad;
263
    }
264

    
265
    private AcceptCancelPanel getAcceptCancelPanel() {
266
        if (accept == null) {
267
            ActionListener okAction, cancelAction;
268
            okAction = new java.awt.event.ActionListener() {
269

    
270
                public void actionPerformed(java.awt.event.ActionEvent e) {
271
                    // IFFrame[] fframes=m_layout.getFFrames();
272
                    // for (int i = 0; i < fframes.length;
273
                    // i++) {
274
                    // IFFrame f = fframes[i];
275
                    //
276
                    // if (f instanceof FFrameView &&
277
                    // (fframeview != null)) {
278
                    // fframelegend.setName("Leyenda de " +
279
                    // ((FFrameView) f).toString());
280
                    //
281
                    //
282
                    // }
283
                    // }
284
                    try {
285
                        newFFrameLegend = (FFrameLegend) fframelegend.clone();
286
                        newFFrameLegend.setFFrameDependence(fframeDependence);
287
                        newFFrameLegend.setFont(font);
288

    
289
                        /*
290
                         * if (m_projectView!=null){
291
                         * fframelegend.setLayers(m_projectView.getMapContext().
292
                         * getLayers());
293
                         * }
294
                         */
295
                        newFFrameLegend.setNameLayers(nameLayers);
296
                        newFFrameLegend.setAreVisible(areVisible);
297
                        newFFrameLegend.setViewing(cbVisualizacion
298
                            .getSelectedIndex());
299
                        newFFrameLegend
300
                            .setQuality(cbCalidad.getSelectedIndex());
301
                        newFFrameLegend.setBoundBox(FLayoutUtilities
302
                            .toSheetRect(rect, layoutPanel.getLayoutControl()
303
                                .getAT()));
304
                        newFFrameLegend.setRotation(getPRotation()
305
                            .getRotation());
306

    
307
                    } catch (CloneNotSupportedException e1) {
308
                        LOG.error("It is not possible clonate the object", e);
309
                    }
310

    
311
                    PluginServices.getMDIManager().closeWindow(
312
                        FFrameLegendDialog.this);
313
                    // m_layout.refresh();
314
                    isAcepted = true;
315
                }
316
            };
317
            cancelAction = new java.awt.event.ActionListener() {
318

    
319
                public void actionPerformed(java.awt.event.ActionEvent e) {
320
                    newFFrameLegend = null;
321
                    PluginServices.getMDIManager().closeWindow(
322
                        FFrameLegendDialog.this);
323
                }
324
            };
325
            accept = new AcceptCancelPanel(okAction, cancelAction);
326
            accept.setPreferredSize(new java.awt.Dimension(300, 34));
327
            accept.setBounds(new java.awt.Rectangle(5, 140, 200, 30));
328
            // accept.setLocation(5, 200);
329
        }
330
        return accept;
331
    }
332

    
333
    /**
334
     * This method initializes liVistas
335
     * 
336
     * @return javax.swing.JList
337
     */
338
    private javax.swing.JList getLiVistas() {
339
        if (liVistas == null) {
340
            ListViewModel listmodel = new ListViewModel();
341

    
342
            // listmodel.addViews();
343
            listmodel.addViews(layoutPanel);
344

    
345
            // /ArrayList list = listmodel.getViews();
346
            liVistas = new javax.swing.JList();
347
            liVistas.setModel(listmodel);
348

    
349
            for (int i = 0; i < liVistas.getModel().getSize(); i++) {
350
                if (fframeDependence != null) {
351
                    fframeview =
352
                        (FFrameView) liVistas.getModel().getElementAt(i);
353

    
354
                    if (fframeview == fframelegend.getFFrameDependence()[0]) {
355
                        liVistas.setSelectedIndex(i);
356
                        nameLayers = fframelegend.getNameLayers();
357
                        areVisible = fframelegend.getAreVisible();
358
                        refreshLayerPanel();
359
                    }
360

    
361
                    /*
362
                     * m_projectView=(ProjectView)liVistas.getModel().getElementAt
363
                     * (i);
364
                     * if
365
                     * (m_projectView.getMapContext()==fframelegend.getFMap()){
366
                     * liVistas.setSelectedIndex(i);
367
                     * }
368
                     */
369
                }
370
            }
371

    
372
            liVistas
373
                .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
374

    
375
                    private int selectIndex = -1;
376

    
377
                    public void valueChanged(
378
                        javax.swing.event.ListSelectionEvent e) {
379
                        IFFrame[] fframes =
380
                            layoutPanel.getLayoutContext().getFFrames();
381
                        int selectInt =
382
                            ((JList) e.getSource()).getSelectedIndex();
383
                        if (selectInt != selectIndex) {
384
                            selectIndex = selectInt;
385
                            if (selectIndex == -1) {
386
                                return;
387
                            }
388
                            fframeview =
389
                                (FFrameView) liVistas.getModel().getElementAt(
390
                                    selectInt);
391

    
392
                            for (int i = 0; i < fframes.length; i++) {
393
                                IFFrame f = fframes[i];
394

    
395
                                if (f instanceof FFrameView) {
396
                                    if (((FFrameView) f).getView() == fframeview
397
                                        .getView()) {
398
                                        fframeDependence = fframeview;
399
                                        // fframelegend
400
                                        // .setFFrameDependence(fframeview);
401
                                        refreshLayerPanel();
402
                                    }
403
                                }
404
                            }
405

    
406
                            // fframelegend.setFFrameView(fframeview);
407
                        }
408
                    }
409

    
410
                });
411
        }
412

    
413
        return liVistas;
414
    }
415

    
416
    private void refreshLayerPanel() {
417
        getJPanel().removeAll();
418
        if (fframeview == null || fframeview.getMapContext() == null) {
419
            return;
420
        }
421
        FLayers layers = fframeview.getMapContext().getLayers();
422
        refreshLayers(layers, true);
423
    }
424

    
425
    private void refreshLayers(FLayers layers, boolean first) {
426
        boolean clear = false;
427
        // //Comprobar si ha variado
428
        if (layers.getLayersCount() != nameLayers.size()) {
429
            clear = true;
430
        } else {
431
            int j = 0;
432
            for (int i = layers.getLayersCount() - 1; i >= 0; i--) {
433
                String name = (String) nameLayers.get(j);
434
                if (!(nameLayers.size() > j && nameLayers.get(j).equals(name))) {
435
                    clear = true;
436
                    break;
437
                }
438
                j++;
439
            }
440
        }
441
        // //
442
        if (clear && first) {
443
            nameLayers.clear();
444
            areVisible.clear();
445
        }
446
        int j = 0;
447
        for (int i = layers.getLayersCount() - 1; i >= 0; i--) {
448
            FLayer layer = layers.getLayer(i);
449
            String name = layer.getName();
450

    
451
            /*
452
             * if (layer instanceof FLayers) {
453
             * //refreshLayers((FLayers)layer,false);
454
             * }else
455
             */
456
            {
457

    
458
                if (nameLayers.size() > j && nameLayers.get(j).equals(name)) {
459
                    boolean b = ((Boolean) areVisible.get(j)).booleanValue();
460
                    addLayer(name, j, b);
461
                    nameLayers.set(j, name);
462
                    areVisible.set(j, new Boolean(b));
463
                } else {
464
                    addLayer(name, j, layer.isVisible());
465
                    nameLayers.add(name);
466
                    areVisible.add(new Boolean(layers.getLayer(i).isVisible()));
467

    
468
                }
469
            }
470
            j++;
471

    
472
        }
473
        getJPanel().setSize(new Dimension(100, 100));
474
    }
475

    
476
    private void addLayer(String name, int i, boolean b) {
477
        JCheckBox chbox = new JCheckBox(name, b);
478
        // if (nameLayers.size()>i) {
479
        // nameLayers.set(i,name);
480
        // areVisible.set(i,new Boolean(b));
481
        // }else {
482
        // nameLayers.add(name);
483
        // areVisible.add(new Boolean(b));
484
        // }
485

    
486
        chbox.addChangeListener(new ChangeListener() {
487

    
488
            public void stateChanged(ChangeEvent arg0) {
489
                JCheckBox ckb = (JCheckBox) arg0.getSource();
490
                Component[] components = getJPanel().getComponents();
491
                for (int i = components.length - 1; i >= 0; i--) {
492
                    if (components[i].equals(ckb)) {
493
                        areVisible.set(i, new Boolean(ckb.isSelected()));
494
                    }
495
                }
496
                // hashVisible.put(ckb.getLabel(),new
497
                // Boolean(ckb.isSelected()));
498
            }
499

    
500
        });
501
        getJPanel().add(name, chbox);
502
    }
503

    
504
    /*
505
     * (non-Javadoc)
506
     * 
507
     * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
508
     */
509
    public WindowInfo getWindowInfo() {
510
        WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODALDIALOG);
511
        m_viewinfo.setTitle(PluginServices.getText(this,
512
            "propiedades_marco_leyenda"));
513

    
514
        return m_viewinfo;
515
    }
516

    
517
    /**
518
     * @see org.gvsig.app.project.documents.layout.fframes.gui.dialogs.IFFrameDialog#getIsAcepted()
519
     */
520
    public boolean getIsAcepted() {
521
        return isAcepted;
522
    }
523

    
524
    /**
525
     * @see com.iver.mdiApp.ui.MDIManager.IWindow#windowActivated()
526
     */
527
    public void viewActivated() {
528
    }
529

    
530
    /**
531
     * This method initializes bFuente
532
     * 
533
     * @return javax.swing.JButton
534
     */
535
    private JButton getBFuente() {
536
        if (bFuente == null) {
537
            bFuente =
538
                ToolsSwingLocator.getUsabilitySwingManager().createJButton();
539
            bFuente.setSize(90, 23);
540
            bFuente.setText(PluginServices.getText(this, "fuente"));
541
            bFuente.setLocation(217, 146);
542
            bFuente.addActionListener(new java.awt.event.ActionListener() {
543

    
544
                public void actionPerformed(java.awt.event.ActionEvent e) {
545
                    if (font != null) {
546
                        font =
547
                            FontChooser.showDialog(PluginServices.getText(this,
548
                                "seleccion_fuente"), font); // fchoser=new
549
                                                            // FontChooser();
550
                    } else {
551
                        font =
552
                            FontChooser.showDialog(PluginServices.getText(this,
553
                                "seleccion_fuente"), getFont());
554
                    }
555
                }
556
            });
557
        }
558

    
559
        return bFuente;
560
    }
561

    
562
    /**
563
     * This method initializes pRotation
564
     * 
565
     * @return javax.swing.JPanel
566
     */
567
    private JPRotation getPRotation() {
568
        if (pRotation == null) {
569
            pRotation = new JPRotation();
570
            pRotation.setBounds(470, 19, 120, 120);
571
        }
572
        return pRotation;
573
    }
574

    
575
    /**
576
     * This method initializes jScrollPane1
577
     * 
578
     * @return javax.swing.JScrollPane
579
     */
580
    private JScrollPane getJScrollPane1() {
581
        if (jScrollPane1 == null) {
582
            jScrollPane1 = new JScrollPane();
583
            jScrollPane1.setBounds(new java.awt.Rectangle(314, 10, 137, 158));
584
            jScrollPane1
585
                .setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
586
            jScrollPane1
587
                .setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
588
            jScrollPane1.setViewportView(getJPanel());
589
        }
590
        return jScrollPane1;
591
    }
592

    
593
    /**
594
     * This method initializes jPanel
595
     * 
596
     * @return javax.swing.JPanel
597
     */
598
    private JPanel getJPanel() {
599
        if (jPanel == null) {
600
            jPanel = new JPanel();
601
            jPanel.setLayout(new BoxLayout(getJPanel(), BoxLayout.Y_AXIS));
602
        }
603
        return jPanel;
604
    }
605

    
606
    public IFFrame getFFrame() {
607
        return newFFrameLegend;
608
    }
609

    
610
    public Object getWindowProfile() {
611
        return WindowInfo.DIALOG_PROFILE;
612
    }
613

    
614
} // @jve:decl-index=0:visual-constraint="10,10"