Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / fframes / gui / dialogs / FFrameLegendDialog.java @ 7304

History | View | Annotate | Download (16 KB)

1
/*
2
 * Created on 02-jun-2004
3
 *
4
 */
5
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
6
 *
7
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
8
 *
9
 * This program is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU General Public License
11
 * as published by the Free Software Foundation; either version 2
12
 * of the License, or (at your option) any later version.
13
 *
14
 * This program is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 * GNU General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU General Public License
20
 * along with this program; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
22
 *
23
 * For more information, contact:
24
 *
25
 *  Generalitat Valenciana
26
 *   Conselleria d'Infraestructures i Transport
27
 *   Av. Blasco Ib??ez, 50
28
 *   46010 VALENCIA
29
 *   SPAIN
30
 *
31
 *      +34 963862235
32
 *   gvsig@gva.es
33
 *      www.gvsig.gva.es
34
 *
35
 *    or
36
 *
37
 *   IVER T.I. S.A
38
 *   Salamanca 50
39
 *   46005 Valencia
40
 *   Spain
41
 *
42
 *   +34 963163400
43
 *   dac@iver.es
44
 */
45
package com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs;
46

    
47
import java.awt.Component;
48
import java.awt.Dimension;
49
import java.awt.event.ActionListener;
50
import java.awt.geom.Rectangle2D;
51
import java.util.ArrayList;
52

    
53
import javax.swing.BoxLayout;
54
import javax.swing.JCheckBox;
55
import javax.swing.JList;
56
import javax.swing.JPanel;
57
import javax.swing.JScrollPane;
58
import javax.swing.event.ChangeEvent;
59
import javax.swing.event.ChangeListener;
60

    
61
import org.gvsig.gui.beans.AcceptCancelPanel;
62
import org.gvsig.gui.beans.swing.JButton;
63

    
64
import com.iver.andami.PluginServices;
65
import com.iver.andami.ui.mdiManager.WindowInfo;
66
import com.iver.cit.gvsig.fmap.layers.FLayer;
67
import com.iver.cit.gvsig.fmap.layers.FLayers;
68
import com.iver.cit.gvsig.gui.layout.Layout;
69
import com.iver.cit.gvsig.gui.layout.fframes.FFrameLegend;
70
import com.iver.cit.gvsig.gui.layout.fframes.FFrameView;
71
import com.iver.cit.gvsig.gui.utils.FontChooser;
72
import com.iver.cit.gvsig.project.documents.layout.FLayoutUtilities;
73
import com.iver.cit.gvsig.project.documents.layout.fframes.IFFrame;
74
import com.iver.cit.gvsig.project.documents.layout.fframes.ListViewModel;
75
import com.iver.cit.gvsig.project.documents.layout.fframes.gui.JPRotation;
76

    
77

    
78
/**
79
 * Dialogo para a?adir la leyenda de alguna vista al Layout.
80
 *
81
 * @author Vicente Caballero Navarro
82
 */
83
public class FFrameLegendDialog extends JPanel implements IFFrameDialog {
84
        private javax.swing.JPanel jContentPane = null;
85
        private javax.swing.JLabel lMarcoVista = null;
86
        private javax.swing.JScrollPane jScrollPane = null;
87
        private javax.swing.JLabel lVisualizacion = null;
88
        private javax.swing.JComboBox cbVisualizacion = null;
89
        private javax.swing.JLabel lCalidad = null;
90
        private javax.swing.JComboBox cbCalidad = null;
91
        private javax.swing.JList liVistas = null;
92
        private Rectangle2D rect = new Rectangle2D.Double();
93
        private Layout m_layout = null; //  @jve:visual-info  decl-index=0 visual-constraint="393,10"
94
        private FFrameLegend fframelegend = null; //new FFrameLegend();
95
        private ArrayList nameLayers=new ArrayList();
96
        private ArrayList areVisible=new ArrayList();
97
        private boolean isAcepted = false;
98
        private JButton bFuente = null;
99
        private FFrameView fframeview = null;
100
        private JPRotation pRotation = null;
101
        //private JLabel lblNumColum = null;
102
        //private JTextField txtNumColum = null;
103
        //private ColumPanel pNumColum = null;
104
        private JScrollPane jScrollPane1 = null;
105
        private JPanel jPanel = null;
106
        private AcceptCancelPanel accept;
107

    
108
        /**
109
         * This is the default constructor
110
         *
111
         * @param layout Referencia al Layout.
112
         * @param fframe Referencia al FFrameLegend.
113
         */
114
        public FFrameLegendDialog(Layout layout, FFrameLegend fframe) {
115
                super();
116
                m_layout = layout;
117
                fframelegend = fframe;
118
                initialize();
119
        }
120

    
121
        /**
122
         * Inserta el rect?ngulo que ocupar? el fframe de leyenda.
123
         *
124
         * @param r extent.
125
         */
126
        public void setRectangle(Rectangle2D r) {
127
                rect.setRect(r);
128
        }
129

    
130
        /**
131
         * This method initializes this
132
         */
133
        private void initialize() {
134
                this.setLayout(null);
135
                this.add(getJContentPane(), null);
136
                this.setSize(616, 199);
137
                this.setSize(new java.awt.Dimension(616,189));
138
                getPRotation().setRotation(fframelegend.getRotation());
139
        }
140

    
141
        /**
142
         * This method initializes jContentPane
143
         *
144
         * @return javax.swing.JPanel
145
         */
146
        private javax.swing.JPanel getJContentPane() {
147
                if (jContentPane == null) {
148
                        jContentPane = new javax.swing.JPanel();
149
                        jContentPane.setLayout(null);
150
                        jContentPane.setBounds(new java.awt.Rectangle(3,1,609,183));
151
                        jContentPane.add(getLMarcoVista(), null);
152
                        jContentPane.add(getJScrollPane(), null);
153
                        jContentPane.add(getLVisualizacion(), null);
154
                        jContentPane.add(getCbVisualizacion(), null);
155
                        jContentPane.add(getLCalidad(), null);
156
                        jContentPane.add(getCbCalidad(), null);
157
                        //jContentPane.add(getBAceptar(), null);
158
                        //jContentPane.add(getBCancelar(), null);
159
                        jContentPane.add(getAcceptCancelPanel(),null);
160
                        jContentPane.add(getBFuente(), null);
161
                        jContentPane.setBounds(3, 1, 609, 241);
162
                        jContentPane.add(getPRotation(), null);
163
                        //jContentPane.add(lblNumColum, null);
164
                        jContentPane.add(getJScrollPane1(), null);
165
                }
166

    
167
                return jContentPane;
168
        }
169

    
170
        /**
171
         * This method initializes lMarcoVista
172
         *
173
         * @return javax.swing.JLabel
174
         */
175
        private javax.swing.JLabel getLMarcoVista() {
176
                if (lMarcoVista == null) {
177
                        lMarcoVista = new javax.swing.JLabel();
178
                        lMarcoVista.setSize(115, 63);
179
                        lMarcoVista.setText(PluginServices.getText(this, "marco_vista"));
180
                        lMarcoVista.setLocation(5, 10);
181
                }
182

    
183
                return lMarcoVista;
184
        }
185

    
186
        /**
187
         * This method initializes jScrollPane
188
         *
189
         * @return javax.swing.JScrollPane
190
         */
191
        private javax.swing.JScrollPane getJScrollPane() {
192
                if (jScrollPane == null) {
193
                        jScrollPane = new javax.swing.JScrollPane();
194
                        jScrollPane.setViewportView(getLiVistas());
195
                        jScrollPane.setSize(179, 65);
196
                        jScrollPane.setPreferredSize(new java.awt.Dimension(70, 60));
197
                        jScrollPane.setLocation(129, 10);
198
                }
199

    
200
                return jScrollPane;
201
        }
202

    
203
        /**
204
         * This method initializes lVisualizacion
205
         *
206
         * @return javax.swing.JLabel
207
         */
208
        private javax.swing.JLabel getLVisualizacion() {
209
                if (lVisualizacion == null) {
210
                        lVisualizacion = new javax.swing.JLabel();
211
                        lVisualizacion.setSize(115, 16);
212
                        lVisualizacion.setText(PluginServices.getText(this, "visualizacion"));
213
                        lVisualizacion.setLocation(6, 83);
214
                }
215

    
216
                return lVisualizacion;
217
        }
218

    
219
        /**
220
         * This method initializes cbVisualizacion
221
         *
222
         * @return javax.swing.JComboBox
223
         */
224
        private javax.swing.JComboBox getCbVisualizacion() {
225
                if (cbVisualizacion == null) {
226
                        cbVisualizacion = new javax.swing.JComboBox();
227
                        cbVisualizacion.addItem(PluginServices.getText(this, "cuando_activo"));
228
                        cbVisualizacion.addItem(PluginServices.getText(this, "siempre"));
229
                        cbVisualizacion.setSelectedIndex(fframelegend.getViewing());
230
                        cbVisualizacion.setSize(179, 20);
231
                        cbVisualizacion.setPreferredSize(new java.awt.Dimension(200, 20));
232
                        cbVisualizacion.setLocation(129, 83);
233
                        cbVisualizacion.setEnabled(false);
234
                }
235

    
236
                return cbVisualizacion;
237
        }
238

    
239
        /**
240
         * This method initializes lCalidad
241
         *
242
         * @return javax.swing.JLabel
243
         */
244
        private javax.swing.JLabel getLCalidad() {
245
                if (lCalidad == null) {
246
                        lCalidad = new javax.swing.JLabel();
247
                        lCalidad.setSize(115, 16);
248
                        lCalidad.setText(PluginServices.getText(this, "calidad"));
249
                        lCalidad.setLocation(6, 103);
250
                }
251

    
252
                return lCalidad;
253
        }
254

    
255
        /**
256
         * This method initializes cbCalidad
257
         *
258
         * @return javax.swing.JComboBox
259
         */
260
        private javax.swing.JComboBox getCbCalidad() {
261
                if (cbCalidad == null) {
262
                        cbCalidad = new javax.swing.JComboBox();
263
                        cbCalidad.addItem(PluginServices.getText(this, "presentacion"));
264
                        cbCalidad.addItem(PluginServices.getText(this, "borrador"));
265
                        cbCalidad.setSelectedIndex(fframelegend.getQuality());
266
                        cbCalidad.setSize(179, 20);
267
                        cbCalidad.setPreferredSize(new java.awt.Dimension(200, 20));
268
                        cbCalidad.setLocation(129, 103);
269
                }
270

    
271
                return cbCalidad;
272
        }
273
        private AcceptCancelPanel getAcceptCancelPanel() {
274
                if (accept == null) {
275
                        ActionListener okAction, cancelAction;
276
                        okAction = new java.awt.event.ActionListener() {
277
                                public void actionPerformed(java.awt.event.ActionEvent e) {
278
                                        IFFrame[] fframes=m_layout.getFFrames();
279
                                        for (int i = 0; i < fframes.length;
280
                                                        i++) {
281
                                                IFFrame f = fframes[i];
282

    
283
                                                if (f instanceof FFrameView &&
284
                                                                (fframeview != null)) {
285
                                                        fframelegend.setName("Leyenda de " +
286
                                                                ((FFrameView) f).toString());
287

    
288

    
289
                                                }
290
                                        }
291

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

    
304
                                        PluginServices.getMDIManager().closeWindow(FFrameLegendDialog.this);
305
                                        m_layout.refresh();
306
                                        isAcepted = true;
307
                                }
308
                                };
309
                        cancelAction = new java.awt.event.ActionListener() {
310
                                public void actionPerformed(java.awt.event.ActionEvent e) {
311
                                        PluginServices.getMDIManager().closeWindow(FFrameLegendDialog.this);
312
                                }
313
                        };
314
                        accept = new AcceptCancelPanel(okAction, cancelAction);
315
                        accept.setPreferredSize(new java.awt.Dimension(300,34));
316
                        accept.setBounds(new java.awt.Rectangle(5,140,200,30));
317
                        //accept.setLocation(5, 200);
318
                }
319
                return accept;
320
        }
321

    
322
        /**
323
         * This method initializes liVistas
324
         *
325
         * @return javax.swing.JList
326
         */
327
        private javax.swing.JList getLiVistas() {
328
                if (liVistas == null) {
329
                        ListViewModel listmodel = new ListViewModel();
330

    
331
                        //listmodel.addViews();
332
                        listmodel.addViews(m_layout);
333

    
334
                        ///ArrayList list = listmodel.getViews();
335
                        liVistas = new javax.swing.JList();
336
                        liVistas.setModel(listmodel);
337

    
338
                        for (int i = 0; i < liVistas.getModel().getSize(); i++) {
339
                                if (fframelegend.getFFrameDependence() != null) {
340
                                        fframeview = (FFrameView) liVistas.getModel().getElementAt(i);
341

    
342
                                        if (fframeview == fframelegend.getFFrameDependence()) {
343
                                                liVistas.setSelectedIndex(i);
344
                                                nameLayers=fframelegend.getNameLayers();
345
                                                areVisible=fframelegend.getAreVisible();
346
                                                refreshLayerPanel();
347
                                        }
348

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

    
357
                        liVistas.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
358
                                        private int selectIndex=-1;
359
                                        public void valueChanged(
360
                                                                javax.swing.event.ListSelectionEvent e) {
361
                                                        IFFrame[] fframes=m_layout.getFFrames();
362
                                                        int selectInt =((JList) e.getSource())
363
                                                                        .getSelectedIndex();
364
                                                        if (selectInt != selectIndex) {
365
                                                                selectIndex = selectInt;
366
                                                                if (selectIndex == -1)
367
                                                                        return;
368
                                                                fframeview = (FFrameView) liVistas.getModel()
369
                                                                                .getElementAt(selectInt);
370

    
371
                                                                for (int i = 0; i < fframes.length; i++) {
372
                                                                        IFFrame f = fframes[i];
373

    
374
                                                                        if (f instanceof FFrameView) {
375
                                                                                if (((FFrameView) f).getView() == fframeview
376
                                                                                                .getView()) {
377
                                                                                        fframelegend
378
                                                                                                        .setFFrameDependence(fframeview);
379
                                                                                        refreshLayerPanel();
380
                                                                                }
381
                                                                        }
382
                                                                }
383

    
384
                                                                // fframelegend.setFFrameView(fframeview);
385
                                                        }
386
                                                }
387

    
388
                                        });
389
                }
390

    
391
                return liVistas;
392
        }
393
        private void refreshLayerPanel() {
394
                getJPanel().removeAll();
395
                if (fframeview==null)
396
                        return;
397
                FLayers layers=fframeview.getMapContext().getLayers();
398
                refreshLayers(layers,true);
399
        }
400
        private void refreshLayers(FLayers layers,boolean first) {
401
                boolean clear=false;
402
                ////Comprobar si ha variado
403
                if (layers.getLayersCount()!=nameLayers.size()) {
404
                        clear=true;
405
                }else {
406
                        int j=0;
407
                        for (int i=layers.getLayersCount()-1;i>=0;i--) {
408
                                String name=(String)nameLayers.get(j);
409
                                if (!(nameLayers.size()>j && nameLayers.get(j).equals(name))) {
410
                                        clear=true;
411
                                        break;
412
                                }
413
                                j++;
414
                        }
415
                }
416
                ////
417
                if (clear && first) {
418
                        nameLayers.clear();
419
                        areVisible.clear();
420
                }
421
                int j=0;
422
                for (int i=layers.getLayersCount()-1;i>=0;i--) {
423
                        FLayer layer=layers.getLayer(i);
424
                        String name=layer.getName();
425

    
426
                        /*if (layer instanceof FLayers) {
427
                                //refreshLayers((FLayers)layer,false);
428
                        }else*/
429
                        {
430

    
431
                        if (nameLayers.size()>j && nameLayers.get(j).equals(name)) {
432
                                boolean b=((Boolean)areVisible.get(j)).booleanValue();
433
                                 addLayer(name,j,b);
434
                                 nameLayers.set(j,name);
435
                                 areVisible.set(j,new Boolean(b));
436
                        }else {
437
                                addLayer(name,j,layers.getLayer(j).isVisible());
438
                                nameLayers.add(name);
439
                                areVisible.add(new Boolean(layers.getLayer(i).isVisible()));
440

    
441
                        }
442
                        }
443
                        j++;
444

    
445
                }
446
                getJPanel().setSize(new Dimension(100,100));
447
        }
448
        private void addLayer(String name,int i,boolean b) {
449
                JCheckBox chbox=new JCheckBox(name,b);
450
//                if (nameLayers.size()>i) {
451
//                        nameLayers.set(i,name);
452
//                        areVisible.set(i,new Boolean(b));
453
//                }else {
454
//                        nameLayers.add(name);
455
//                        areVisible.add(new Boolean(b));
456
//                }
457

    
458
                chbox.addChangeListener(new ChangeListener() {
459

    
460
                        public void stateChanged(ChangeEvent arg0) {
461
                                JCheckBox ckb=(JCheckBox)arg0.getSource();
462
                                Component[] components=getJPanel().getComponents();
463
                                int j=0;
464
                                for (int i=components.length-1;i>=0;i--) {
465
                                        if (components[i].equals(ckb)) {
466
                                                areVisible.set(i,new Boolean(ckb.isSelected()));
467
                                        }
468
                                        j++;
469
                                }
470
                                //hashVisible.put(ckb.getLabel(),new Boolean(ckb.isSelected()));
471
                        }
472

    
473
                });
474
                getJPanel().add(name,chbox);
475
        }
476
        /* (non-Javadoc)
477
         * @see com.iver.mdiApp.ui.MDIManager.View#getViewInfo()
478
         */
479
        public WindowInfo getWindowInfo() {
480
                WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODALDIALOG);
481
                m_viewinfo.setTitle(PluginServices.getText(this,
482
                                "propiedades_marco_leyenda"));
483

    
484
                return m_viewinfo;
485
        }
486

    
487
        /**
488
         * @see com.iver.cit.gvsig.project.documents.layout.fframes.gui.dialogs.IFFrameDialog#getIsAcepted()
489
         */
490
        public boolean getIsAcepted() {
491
                return isAcepted;
492
        }
493

    
494
        /**
495
         * @see com.iver.mdiApp.ui.MDIManager.IWindow#windowActivated()
496
         */
497
        public void viewActivated() {
498
        }
499

    
500
        /**
501
         * This method initializes bFuente
502
         *
503
         * @return javax.swing.JButton
504
         */
505
        private JButton getBFuente() {
506
                if (bFuente == null) {
507
                        bFuente = new JButton();
508
                        bFuente.setSize(90, 23);
509
                        bFuente.setText(PluginServices.getText(this, "fuente"));
510
                        bFuente.setLocation(217, 146);
511
                        bFuente.addActionListener(new java.awt.event.ActionListener() {
512
                                        public void actionPerformed(java.awt.event.ActionEvent e) {
513
                                                if (fframelegend.getFont() != null) {
514
                                                        fframelegend.setFont(FontChooser.showDialog(
515
                                                                        PluginServices.getText(this,
516
                                                                                "seleccion_fuente"),
517
                                                                        fframelegend.getFont())); // fchoser=new FontChooser();
518
                                                } else {
519
                                                        fframelegend.setFont(FontChooser.showDialog(
520
                                                                        PluginServices.getText(this,
521
                                                                                "seleccion_fuente"), getFont()));
522
                                                }
523
                                        }
524
                                });
525
                }
526

    
527
                return bFuente;
528
        }
529

    
530
        /**
531
         * This method initializes pRotation
532
         *
533
         * @return javax.swing.JPanel
534
         */
535
        private JPRotation getPRotation() {
536
                if (pRotation == null) {
537
                        pRotation = new JPRotation();
538
                        pRotation.setBounds(470, 19, 120, 120);
539
                }
540
                return pRotation;
541
        }
542

    
543
        /**
544
         * This method initializes jScrollPane1
545
         *
546
         * @return javax.swing.JScrollPane
547
         */
548
        private JScrollPane getJScrollPane1() {
549
                if (jScrollPane1 == null) {
550
                        jScrollPane1 = new JScrollPane();
551
                        jScrollPane1.setBounds(new java.awt.Rectangle(314,10,137,158));
552
                        jScrollPane1.setVerticalScrollBarPolicy(javax.swing.JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
553
                        jScrollPane1.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
554
                        jScrollPane1.setViewportView(getJPanel());
555
                }
556
                return jScrollPane1;
557
        }
558

    
559
        /**
560
         * This method initializes jPanel
561
         *
562
         * @return javax.swing.JPanel
563
         */
564
        private JPanel getJPanel() {
565
                if (jPanel == null) {
566
                        jPanel = new JPanel();
567
                        jPanel.setLayout(new BoxLayout(getJPanel(), BoxLayout.Y_AXIS));
568
                }
569
                return jPanel;
570
        }
571

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