Statistics
| Revision:

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

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();
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
                                        newFFrameLegend.setName("Leyenda de " +
305
                                                                fframeDependence.toString());
306
                                        /*if (m_projectView!=null){
307
                                           fframelegend.setLayers(m_projectView.getMapContext().getLayers());
308
                                           }
309
                                         */
310
                                        newFFrameLegend.setNameLayers(nameLayers);
311
                                        newFFrameLegend.setAreVisible(areVisible);
312
                                        newFFrameLegend.setViewing(cbVisualizacion.getSelectedIndex());
313
                                        newFFrameLegend.setQuality(cbCalidad.getSelectedIndex());
314
                                        newFFrameLegend.setBoundBox(FLayoutUtilities.toSheetRect(
315
                                                        rect, m_layout.getLayoutControl().getAT()));
316
                                        newFFrameLegend.setRotation(getPRotation().getRotation());
317

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

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

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

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

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

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

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

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

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

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

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

    
404
                                        });
405
                }
406

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

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

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

    
457
                        }
458
                        }
459
                        j++;
460

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

    
474
                chbox.addChangeListener(new ChangeListener() {
475

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

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

    
500
                return m_viewinfo;
501
        }
502

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

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

    
516
        /**
517
         * This method initializes bFuente
518
         *
519
         * @return javax.swing.JButton
520
         */
521
        private JButton getBFuente() {
522
                if (bFuente == null) {
523
                        bFuente = new JButton();
524
                        bFuente.setSize(90, 23);
525
                        bFuente.setText(PluginServices.getText(this, "fuente"));
526
                        bFuente.setLocation(217, 146);
527
                        bFuente.addActionListener(new java.awt.event.ActionListener() {
528
                                        public void actionPerformed(java.awt.event.ActionEvent e) {
529
                                                if (font != null) {
530
                                                        font=FontChooser.showDialog(
531
                                                                        PluginServices.getText(this,
532
                                                                                "seleccion_fuente"),
533
                                                                        font); // fchoser=new FontChooser();
534
                                                } else {
535
                                                        font=FontChooser.showDialog(
536
                                                                        PluginServices.getText(this,
537
                                                                                "seleccion_fuente"), getFont());
538
                                                }
539
                                        }
540
                                });
541
                }
542

    
543
                return bFuente;
544
        }
545

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

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

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

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

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