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 @ 250

History | View | Annotate | Download (20.6 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
                    try {
272
                        newFFrameLegend = (FFrameLegend) fframelegend.clone();
273
                        newFFrameLegend.setFFrameDependence(fframeDependence);
274
                        newFFrameLegend.setFont(font);
275
                        newFFrameLegend.setNameLayers(nameLayers);
276
                        newFFrameLegend.setAreVisible(areVisible);
277
                        newFFrameLegend.setViewing(cbVisualizacion
278
                            .getSelectedIndex());
279
                        newFFrameLegend
280
                            .setQuality(cbCalidad.getSelectedIndex());
281
                        newFFrameLegend.setBoundBox(FLayoutUtilities
282
                            .toSheetRect(rect, layoutPanel.getLayoutControl()
283
                                .getAT()));
284
                        newFFrameLegend.setRotation(getPRotation()
285
                            .getRotation());
286

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

    
291
                    PluginServices.getMDIManager().closeWindow(
292
                        FFrameLegendDialog.this);
293
                    notifyDialogClosed();
294
                    layoutPanel.getLayoutControl().setDefaultTool();
295
                    isAcepted = true;
296
                }
297
            };
298
            cancelAction = new java.awt.event.ActionListener() {
299

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

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

    
324
            // listmodel.addViews();
325
            listmodel.addViews(layoutPanel);
326

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

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

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

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

    
354
            liVistas
355
                .addListSelectionListener(new javax.swing.event.ListSelectionListener() {
356

    
357
                    private int selectIndex = -1;
358

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

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

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

    
388
                            // fframelegend.setFFrameView(fframeview);
389
                        }
390
                    }
391

    
392
                });
393
        }
394

    
395
        return liVistas;
396
    }
397

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

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

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

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

    
450
                }
451
            }
452
            j++;
453

    
454
        }
455
        getJPanel().setSize(new Dimension(100, 100));
456
    }
457

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

    
468
        chbox.addChangeListener(new ChangeListener() {
469

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

    
482
        });
483
        getJPanel().add(name, chbox);
484
    }
485

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

    
496
        return m_viewinfo;
497
    }
498

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

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

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

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

    
544
        return bFuente;
545
    }
546

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

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

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

    
591
    public IFFrame getFFrame() {
592
        return newFFrameLegend;
593
    }
594

    
595
    public Object getWindowProfile() {
596
        return WindowInfo.DIALOG_PROFILE;
597
    }
598

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