Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / project / documents / layout / fframes / gui / dialogs / FFrameLegendDialog.java @ 7906

History | View | Annotate | Download (16.1 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
                        lVisualizacion.setVisible(false);
215
                }
216

    
217
                return lVisualizacion;
218
        }
219

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

    
238
                return cbVisualizacion;
239
        }
240

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

    
254
                return lCalidad;
255
        }
256

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

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

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

    
290

    
291
                                                }
292
                                        }
293

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

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

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

    
333
                        //listmodel.addViews();
334
                        listmodel.addViews(m_layout);
335

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

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

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

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

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

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

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

    
386
                                                                // fframelegend.setFFrameView(fframeview);
387
                                                        }
388
                                                }
389

    
390
                                        });
391
                }
392

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

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

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

    
443
                        }
444
                        }
445
                        j++;
446

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

    
460
                chbox.addChangeListener(new ChangeListener() {
461

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

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

    
486
                return m_viewinfo;
487
        }
488

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

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

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

    
529
                return bFuente;
530
        }
531

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

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

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

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