Statistics
| Revision:

svn-document-layout / trunk / org.gvsig.app.document.layout2.app / org.gvsig.app.document.layout2.app.mainplugin / src / main / java / org / gvsig / app / project / documents / layout / fframes / gui / dialogs / FFrameLegendDialog.java @ 717

History | View | Annotate | Download (20.7 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.ActionEvent;
28
import java.awt.event.ActionListener;
29
import java.awt.geom.Rectangle2D;
30
import java.util.ArrayList;
31
import java.util.List;
32

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

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

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

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

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

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

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

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

    
155
        return jContentPane;
156
    }
157

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

    
171
        return lMarcoVista;
172
    }
173

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

    
188
        return jScrollPane;
189
    }
190

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

    
206
        return lVisualizacion;
207
    }
208

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

    
228
        return cbVisualizacion;
229
    }
230

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

    
244
        return lCalidad;
245
    }
246

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

    
263
        return cbCalidad;
264
    }
265

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

    
271
                public void actionPerformed(java.awt.event.ActionEvent e) {
272
                    try {
273
                        newFFrameLegend = (FFrameLegend) fframelegend.clone();
274
                        newFFrameLegend.setFFrameDependence(fframeDependence);
275
                        newFFrameLegend.setFont(font);
276
                        newFFrameLegend.setNameLayers(nameLayers);
277
                        newFFrameLegend.setAreVisible(areVisible);
278
                        newFFrameLegend.setViewing(cbVisualizacion
279
                            .getSelectedIndex());
280
                        newFFrameLegend
281
                            .setQuality(cbCalidad.getSelectedIndex());
282
                        newFFrameLegend.setBoundBox(FLayoutUtilities
283
                            .toSheetRect(rect, layoutPanel.getLayoutControl()
284
                                .getAT()));
285
                        newFFrameLegend.setRotation(getPRotation()
286
                            .getRotation());
287

    
288
                    } catch (CloneNotSupportedException e1) {
289
                        LOG.error("It is not possible clonate the object", e);
290
                    }
291

    
292
                    PluginServices.getMDIManager().closeWindow(
293
                        FFrameLegendDialog.this);
294
                    notifyDialogClosed();
295
                    layoutPanel.getLayoutControl().setDefaultTool();
296
                    isAcepted = true;
297
                    fireActionEvent(new ActionEvent(FFrameLegendDialog.this, 1, "accept"));
298
                }
299
            };
300
            cancelAction = new java.awt.event.ActionListener() {
301

    
302
                public void actionPerformed(java.awt.event.ActionEvent e) {
303
                    newFFrameLegend = null;
304
                    PluginServices.getMDIManager().closeWindow(
305
                        FFrameLegendDialog.this);
306
                    notifyDialogClosed();
307
                }
308
            };
309
            accept = new AcceptCancelPanel(okAction, cancelAction);
310
            accept.setPreferredSize(new java.awt.Dimension(300, 34));
311
            accept.setBounds(new java.awt.Rectangle(5, 140, 200, 30));
312
            // accept.setLocation(5, 200);
313
        }
314
        return accept;
315
    }
316

    
317
    /**
318
     * This method initializes liVistas
319
     * 
320
     * @return javax.swing.JList
321
     */
322
    private javax.swing.JList getLiVistas() {
323
        if (liVistas == null) {
324
            ListViewModel listmodel = new ListViewModel();
325

    
326
            // listmodel.addViews();
327
            listmodel.addViews(layoutPanel);
328

    
329
            // /ArrayList list = listmodel.getViews();
330
            liVistas = new javax.swing.JList();
331
            liVistas.setModel(listmodel);
332

    
333
            for (int i = 0; i < liVistas.getModel().getSize(); i++) {
334
                if (fframeDependence != null) {
335
                    fframeview =
336
                        (FFrameView) liVistas.getModel().getElementAt(i);
337

    
338
                    if (fframeview == fframelegend.getFFrameDependence()[0]) {
339
                        liVistas.setSelectedIndex(i);
340
                        nameLayers = fframelegend.getNameLayers();
341
                        areVisible = fframelegend.getAreVisible();
342
                        refreshLayerPanel();
343
                    }
344

    
345
                    /*
346
                     * m_projectView=(ProjectView)liVistas.getModel().getElementAt
347
                     * (i);
348
                     * if
349
                     * (m_projectView.getMapContext()==fframelegend.getFMap()){
350
                     * liVistas.setSelectedIndex(i);
351
                     * }
352
                     */
353
                }
354
            }
355

    
356
            liVistas
357
                .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
358

    
359
                    private int selectIndex = -1;
360

    
361
                    public void valueChanged(
362
                        javax.swing.event.ListSelectionEvent e) {
363
                        IFFrame[] fframes =
364
                            layoutPanel.getLayoutContext().getFFrames();
365
                        int selectInt =
366
                            ((JList) e.getSource()).getSelectedIndex();
367
                        if (selectInt != selectIndex) {
368
                            selectIndex = selectInt;
369
                            if (selectIndex == -1) {
370
                                return;
371
                            }
372
                            fframeview =
373
                                (FFrameView) liVistas.getModel().getElementAt(
374
                                    selectInt);
375

    
376
                            for (int i = 0; i < fframes.length; i++) {
377
                                IFFrame f = fframes[i];
378

    
379
                                if (f instanceof FFrameView) {
380
                                    if (((FFrameView) f).getView() == fframeview
381
                                        .getView()) {
382
                                        fframeDependence = fframeview;
383
                                        // fframelegend
384
                                        // .setFFrameDependence(fframeview);
385
                                        refreshLayerPanel();
386
                                    }
387
                                }
388
                            }
389

    
390
                            // fframelegend.setFFrameView(fframeview);
391
                        }
392
                    }
393

    
394
                });
395
        }
396

    
397
        return liVistas;
398
    }
399

    
400
    private void refreshLayerPanel() {
401
        getJPanel().removeAll();
402
        if (fframeview == null || fframeview.getMapContext() == null) {
403
            return;
404
        }
405
        FLayers layers = fframeview.getMapContext().getLayers();
406
        refreshLayers(layers, true);
407
    }
408

    
409
    private void refreshLayers(FLayers layers, boolean first) {
410
        boolean clear = false;
411
        // //Comprobar si ha variado
412
        if (layers.getLayersCount() != nameLayers.size()) {
413
            clear = true;
414
        } else {
415
            int j = 0;
416
            for (int i = layers.getLayersCount() - 1; i >= 0; i--) {
417
                String name = (String) nameLayers.get(j);
418
                if (!(nameLayers.size() > j && nameLayers.get(j).equals(name))) {
419
                    clear = true;
420
                    break;
421
                }
422
                j++;
423
            }
424
        }
425
        // //
426
        if (clear && first) {
427
            nameLayers.clear();
428
            areVisible.clear();
429
        }
430
        int j = 0;
431
        for (int i = layers.getLayersCount() - 1; i >= 0; i--) {
432
            FLayer layer = layers.getLayer(i);
433
            String name = layer.getName();
434

    
435
            /*
436
             * if (layer instanceof FLayers) {
437
             * //refreshLayers((FLayers)layer,false);
438
             * }else
439
             */
440
            {
441

    
442
                if (nameLayers.size() > j && nameLayers.get(j).equals(name)) {
443
                    boolean b = ((Boolean) areVisible.get(j)).booleanValue();
444
                    addLayer(name, j, b);
445
                    nameLayers.set(j, name);
446
                    areVisible.set(j, new Boolean(b));
447
                } else {
448
                    addLayer(name, j, layer.isVisible());
449
                    nameLayers.add(name);
450
                    areVisible.add(new Boolean(layers.getLayer(i).isVisible()));
451

    
452
                }
453
            }
454
            j++;
455

    
456
        }
457
        getJPanel().setSize(new Dimension(100, 100));
458
    }
459

    
460
    private void addLayer(String name, int i, boolean b) {
461
        JCheckBox chbox = new JCheckBox(name, b);
462
        // if (nameLayers.size()>i) {
463
        // nameLayers.set(i,name);
464
        // areVisible.set(i,new Boolean(b));
465
        // }else {
466
        // nameLayers.add(name);
467
        // areVisible.add(new Boolean(b));
468
        // }
469

    
470
        chbox.addChangeListener(new ChangeListener() {
471

    
472
            public void stateChanged(ChangeEvent arg0) {
473
                JCheckBox ckb = (JCheckBox) arg0.getSource();
474
                Component[] components = getJPanel().getComponents();
475
                for (int i = components.length - 1; i >= 0; i--) {
476
                    if (components[i].equals(ckb)) {
477
                        areVisible.set(i, new Boolean(ckb.isSelected()));
478
                    }
479
                }
480
                // hashVisible.put(ckb.getLabel(),new
481
                // Boolean(ckb.isSelected()));
482
            }
483

    
484
        });
485
        getJPanel().add(name, chbox);
486
    }
487

    
488
    /*
489
     * (non-Javadoc)
490
     * 
491
     * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
492
     */
493
    public WindowInfo getWindowInfo() {
494
        WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODALDIALOG);
495
        m_viewinfo.setTitle(PluginServices.getText(this,
496
            "propiedades_marco_leyenda"));
497

    
498
        return m_viewinfo;
499
    }
500

    
501
    /**
502
     * @see org.gvsig.app.project.documents.layout.fframes.gui.dialogs.IFFrameDialog#getIsAcepted()
503
     */
504
    public boolean getIsAcepted() {
505
        return isAcepted;
506
    }
507

    
508
    /**
509
     * @see com.iver.mdiApp.ui.MDIManager.IWindow#windowActivated()
510
     */
511
    public void viewActivated() {
512
    }
513

    
514
    /**
515
     * This method initializes bFuente
516
     * 
517
     * @return javax.swing.JButton
518
     */
519
    private JButton getBFuente() {
520
        if (bFuente == null) {
521
            bFuente =
522
                ToolsSwingLocator.getUsabilitySwingManager().createJButton();
523
            bFuente.setSize(90, 23);
524
            bFuente.setText(PluginServices.getText(this, "fuente"));
525
            bFuente.setLocation(217, 146);
526
            bFuente.addActionListener(new java.awt.event.ActionListener() {
527

    
528
                public void actionPerformed(java.awt.event.ActionEvent e) {
529
                        Font selectedFont = null;
530
                    if (font != null) {
531
                            selectedFont =
532
                            FontChooser.showDialog(PluginServices.getText(this,
533
                                "seleccion_fuente"), font);
534
                    } else {
535
                            selectedFont =
536
                            FontChooser.showDialog(PluginServices.getText(this,
537
                                "seleccion_fuente"), getFont());
538
                    }
539
                    if (selectedFont!=null) {
540
                            font = selectedFont;
541
                    }
542
                }
543
            });
544
        }
545

    
546
        return bFuente;
547
    }
548

    
549
    /**
550
     * This method initializes pRotation
551
     * 
552
     * @return javax.swing.JPanel
553
     */
554
    private JPRotation getPRotation() {
555
        if (pRotation == null) {
556
            pRotation = new JPRotation();
557
            pRotation.setBounds(470, 19, 120, 120);
558
        }
559
        return pRotation;
560
    }
561

    
562
    /**
563
     * This method initializes jScrollPane1
564
     * 
565
     * @return javax.swing.JScrollPane
566
     */
567
    private JScrollPane getJScrollPane1() {
568
        if (jScrollPane1 == null) {
569
            jScrollPane1 = new JScrollPane();
570
            jScrollPane1.setBounds(new java.awt.Rectangle(314, 10, 137, 158));
571
            jScrollPane1
572
                .setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
573
            jScrollPane1
574
                .setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
575
            jScrollPane1.setViewportView(getJPanel());
576
        }
577
        return jScrollPane1;
578
    }
579

    
580
    /**
581
     * This method initializes jPanel
582
     * 
583
     * @return javax.swing.JPanel
584
     */
585
    private JPanel getJPanel() {
586
        if (jPanel == null) {
587
            jPanel = new JPanel();
588
            jPanel.setLayout(new BoxLayout(getJPanel(), BoxLayout.Y_AXIS));
589
        }
590
        return jPanel;
591
    }
592

    
593
    public IFFrame getFFrame() {
594
        return newFFrameLegend;
595
    }
596

    
597
    public Object getWindowProfile() {
598
        return WindowInfo.DIALOG_PROFILE;
599
    }
600

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