Statistics
| Revision:

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

History | View | Annotate | Download (16.7 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.Font;
50
import java.awt.event.ActionListener;
51
import java.awt.geom.Rectangle2D;
52
import java.util.ArrayList;
53

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

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

    
65
import com.iver.andami.PluginServices;
66
import com.iver.andami.ui.mdiManager.WindowInfo;
67
import com.iver.cit.gvsig.fmap.layers.FLayer;
68
import com.iver.cit.gvsig.fmap.layers.FLayers;
69
import com.iver.cit.gvsig.gui.utils.FontChooser;
70
import com.iver.cit.gvsig.project.documents.layout.FLayoutUtilities;
71
import com.iver.cit.gvsig.project.documents.layout.fframes.FFrameLegend;
72
import com.iver.cit.gvsig.project.documents.layout.fframes.FFrameView;
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
import com.iver.cit.gvsig.project.documents.layout.gui.Layout;
77

    
78

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

    
112

    
113
        /**
114
         * This is the default constructor
115
         *
116
         * @param layout Referencia al Layout.
117
         * @param fframe Referencia al FFrameLegend.
118
         */
119
        public FFrameLegendDialog(Layout layout, FFrameLegend fframe) {
120
                super();
121
                m_layout = layout;
122
                fframelegend = fframe;
123
                font=fframelegend.getFont();
124
                fframeDependence=fframelegend.getFFrameDependence()[0];
125
                initialize();
126
        }
127

    
128
        /**
129
         * Inserta el rect?ngulo que ocupar? el fframe de leyenda.
130
         *
131
         * @param r extent.
132
         */
133
        public void setRectangle(Rectangle2D r) {
134
                rect.setRect(r);
135
        }
136

    
137
        /**
138
         * This method initializes this
139
         */
140
        private void initialize() {
141
                this.setLayout(null);
142
                this.add(getJContentPane(), null);
143
                this.setSize(616, 199);
144
                this.setSize(new java.awt.Dimension(616,189));
145
                getPRotation().setRotation(fframelegend.getRotation());
146
        }
147

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

    
174
                return jContentPane;
175
        }
176

    
177
        /**
178
         * This method initializes lMarcoVista
179
         *
180
         * @return javax.swing.JLabel
181
         */
182
        private javax.swing.JLabel getLMarcoVista() {
183
                if (lMarcoVista == null) {
184
                        lMarcoVista = new javax.swing.JLabel();
185
                        lMarcoVista.setSize(115, 63);
186
                        lMarcoVista.setText(PluginServices.getText(this, "marco_vista"));
187
                        lMarcoVista.setLocation(5, 10);
188
                }
189

    
190
                return lMarcoVista;
191
        }
192

    
193
        /**
194
         * This method initializes jScrollPane
195
         *
196
         * @return javax.swing.JScrollPane
197
         */
198
        private javax.swing.JScrollPane getJScrollPane() {
199
                if (jScrollPane == null) {
200
                        jScrollPane = new javax.swing.JScrollPane();
201
                        jScrollPane.setViewportView(getLiVistas());
202
                        jScrollPane.setSize(179, 65);
203
                        jScrollPane.setPreferredSize(new java.awt.Dimension(70, 60));
204
                        jScrollPane.setLocation(129, 10);
205
                }
206

    
207
                return jScrollPane;
208
        }
209

    
210
        /**
211
         * This method initializes lVisualizacion
212
         *
213
         * @return javax.swing.JLabel
214
         */
215
        private javax.swing.JLabel getLVisualizacion() {
216
                if (lVisualizacion == null) {
217
                        lVisualizacion = new javax.swing.JLabel();
218
                        lVisualizacion.setSize(115, 16);
219
                        lVisualizacion.setText(PluginServices.getText(this, "visualizacion"));
220
                        lVisualizacion.setLocation(6, 83);
221
                        lVisualizacion.setVisible(false);
222
                }
223

    
224
                return lVisualizacion;
225
        }
226

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

    
245
                return cbVisualizacion;
246
        }
247

    
248
        /**
249
         * This method initializes lCalidad
250
         *
251
         * @return javax.swing.JLabel
252
         */
253
        private javax.swing.JLabel getLCalidad() {
254
                if (lCalidad == null) {
255
                        lCalidad = new javax.swing.JLabel();
256
                        lCalidad.setSize(115, 20);
257
                        lCalidad.setText(PluginServices.getText(this, "calidad"));
258
                        lCalidad.setLocation(6, 103);
259
                }
260

    
261
                return lCalidad;
262
        }
263

    
264
        /**
265
         * This method initializes cbCalidad
266
         *
267
         * @return javax.swing.JComboBox
268
         */
269
        private javax.swing.JComboBox getCbCalidad() {
270
                if (cbCalidad == null) {
271
                        cbCalidad = new javax.swing.JComboBox();
272
                        cbCalidad.addItem(PluginServices.getText(this, "presentacion"));
273
                        cbCalidad.addItem(PluginServices.getText(this, "borrador"));
274
                        cbCalidad.setSelectedIndex(fframelegend.getQuality());
275
                        cbCalidad.setSize(179, 20);
276
                        cbCalidad.setPreferredSize(new java.awt.Dimension(200, 20));
277
                        cbCalidad.setLocation(129, 103);
278
                }
279

    
280
                return cbCalidad;
281
        }
282
        private AcceptCancelPanel getAcceptCancelPanel() {
283
                if (accept == null) {
284
                        ActionListener okAction, cancelAction;
285
                        okAction = new java.awt.event.ActionListener() {
286

    
287
                                public void actionPerformed(java.awt.event.ActionEvent e) {
288
//                                        IFFrame[] fframes=m_layout.getFFrames();
289
//                                        for (int i = 0; i < fframes.length;
290
//                                                        i++) {
291
//                                                IFFrame f = fframes[i];
292
//
293
//                                                if (f instanceof FFrameView &&
294
//                                                                (fframeview != null)) {
295
//                                                        fframelegend.setName("Leyenda de " +
296
//                                                                ((FFrameView) f).toString());
297
//
298
//
299
//                                                }
300
//                                        }
301
                                        newFFrameLegend=(FFrameLegend)fframelegend.cloneFFrame(m_layout);
302
                                        newFFrameLegend.setFFrameDependence(fframeDependence);
303
                                        newFFrameLegend.setFont(font);
304

    
305
                                        /*if (m_projectView!=null){
306
                                           fframelegend.setLayers(m_projectView.getMapContext().getLayers());
307
                                           }
308
                                         */
309
                                        newFFrameLegend.setNameLayers(nameLayers);
310
                                        newFFrameLegend.setAreVisible(areVisible);
311
                                        newFFrameLegend.setViewing(cbVisualizacion.getSelectedIndex());
312
                                        newFFrameLegend.setQuality(cbCalidad.getSelectedIndex());
313
                                        newFFrameLegend.setBoundBox(FLayoutUtilities.toSheetRect(
314
                                                        rect, m_layout.getLayoutControl().getAT()));
315
                                        newFFrameLegend.setRotation(getPRotation().getRotation());
316

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

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

    
345
                        //listmodel.addViews();
346
                        listmodel.addViews(m_layout);
347

    
348
                        ///ArrayList list = listmodel.getViews();
349
                        liVistas = new javax.swing.JList();
350
                        liVistas.setModel(listmodel);
351

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

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

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

    
371
                        liVistas.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
372
                                        private int selectIndex=-1;
373
                                        public void valueChanged(
374
                                                                javax.swing.event.ListSelectionEvent e) {
375
                                                        IFFrame[] fframes=m_layout.getLayoutContext().getFFrames();
376
                                                        int selectInt =((JList) e.getSource())
377
                                                                        .getSelectedIndex();
378
                                                        if (selectInt != selectIndex) {
379
                                                                selectIndex = selectInt;
380
                                                                if (selectIndex == -1)
381
                                                                        return;
382
                                                                fframeview = (FFrameView) liVistas.getModel()
383
                                                                                .getElementAt(selectInt);
384

    
385
                                                                for (int i = 0; i < fframes.length; i++) {
386
                                                                        IFFrame f = fframes[i];
387

    
388
                                                                        if (f instanceof FFrameView) {
389
                                                                                if (((FFrameView) f).getView() == fframeview
390
                                                                                                .getView()) {
391
                                                                                        fframeDependence=fframeview;
392
//                                                                                        fframelegend
393
//                                                                                                        .setFFrameDependence(fframeview);
394
                                                                                        refreshLayerPanel();
395
                                                                                }
396
                                                                        }
397
                                                                }
398

    
399
                                                                // fframelegend.setFFrameView(fframeview);
400
                                                        }
401
                                                }
402

    
403
                                        });
404
                }
405

    
406
                return liVistas;
407
        }
408
        private void refreshLayerPanel() {
409
                getJPanel().removeAll();
410
                if (fframeview==null || fframeview.getMapContext()==null)
411
                        return;
412
                FLayers layers=fframeview.getMapContext().getLayers();
413
                refreshLayers(layers,true);
414
        }
415
        private void refreshLayers(FLayers layers,boolean first) {
416
                boolean clear=false;
417
                ////Comprobar si ha variado
418
                if (layers.getLayersCount()!=nameLayers.size()) {
419
                        clear=true;
420
                }else {
421
                        int j=0;
422
                        for (int i=layers.getLayersCount()-1;i>=0;i--) {
423
                                String name=(String)nameLayers.get(j);
424
                                if (!(nameLayers.size()>j && nameLayers.get(j).equals(name))) {
425
                                        clear=true;
426
                                        break;
427
                                }
428
                                j++;
429
                        }
430
                }
431
                ////
432
                if (clear && first) {
433
                        nameLayers.clear();
434
                        areVisible.clear();
435
                }
436
                int j=0;
437
                for (int i=layers.getLayersCount()-1;i>=0;i--) {
438
                        FLayer layer=layers.getLayer(i);
439
                        String name=layer.getName();
440

    
441
                        /*if (layer instanceof FLayers) {
442
                                //refreshLayers((FLayers)layer,false);
443
                        }else*/
444
                        {
445

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

    
456
                        }
457
                        }
458
                        j++;
459

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

    
473
                chbox.addChangeListener(new ChangeListener() {
474

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

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

    
499
                return m_viewinfo;
500
        }
501

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

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

    
515
        /**
516
         * This method initializes bFuente
517
         *
518
         * @return javax.swing.JButton
519
         */
520
        private JButton getBFuente() {
521
                if (bFuente == null) {
522
                        bFuente = new JButton();
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
                                        public void actionPerformed(java.awt.event.ActionEvent e) {
528
                                                if (font != null) {
529
                                                        font=FontChooser.showDialog(
530
                                                                        PluginServices.getText(this,
531
                                                                                "seleccion_fuente"),
532
                                                                        font); // fchoser=new FontChooser();
533
                                                } else {
534
                                                        font=FontChooser.showDialog(
535
                                                                        PluginServices.getText(this,
536
                                                                                "seleccion_fuente"), getFont());
537
                                                }
538
                                        }
539
                                });
540
                }
541

    
542
                return bFuente;
543
        }
544

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

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

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

    
587
        public IFFrame getFFrame() {
588
                return newFFrameLegend;
589
        }
590

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