Statistics
| Revision:

root / tags / v2_0_0_Build_2050 / applications / appgvSIG / src / org / gvsig / app / project / documents / view / gui / ViewProperties.java @ 38653

History | View | Annotate | Download (20.6 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 * 
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 * 
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 * 
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
19
 * MA  02110-1301, USA.
20
 * 
21
 */
22
package org.gvsig.app.project.documents.view.gui;
23

    
24
import java.awt.Color;
25
import java.awt.Component;
26
import java.awt.Dimension;
27
import java.awt.FlowLayout;
28
import java.awt.GridBagConstraints;
29
import java.awt.GridBagLayout;
30
import java.awt.Insets;
31
import java.awt.event.ActionListener;
32
import java.util.List;
33

    
34
import javax.swing.BorderFactory;
35
import javax.swing.JButton;
36
import javax.swing.JColorChooser;
37
import javax.swing.JComboBox;
38
import javax.swing.JComponent;
39
import javax.swing.JOptionPane;
40
import javax.swing.JPanel;
41

    
42
import org.cresques.cts.IProjection;
43

    
44
import org.gvsig.andami.PluginServices;
45
import org.gvsig.andami.ui.mdiManager.SingletonWindow;
46
import org.gvsig.andami.ui.mdiManager.WindowInfo;
47
import org.gvsig.app.gui.JComboBoxUnits;
48
import org.gvsig.app.gui.panels.CRSSelectPanel;
49
import org.gvsig.app.project.Project;
50
import org.gvsig.app.project.ProjectManager;
51
import org.gvsig.app.project.documents.Document;
52
import org.gvsig.app.project.documents.view.DefaultViewDocument;
53
import org.gvsig.app.project.documents.view.ViewManager;
54
import org.gvsig.fmap.mapcontext.MapContext;
55
import org.gvsig.gui.beans.AcceptCancelPanel;
56
import org.gvsig.i18n.Messages;
57
import org.gvsig.tools.swing.api.ToolsSwingLocator;
58

    
59
/**
60
 * Dialogo donde se muestran las propiedades de una vista
61
 * 
62
 * @author Fernando Gonz?lez Cort?s
63
 * @author gvSIG Team
64
 */
65
public class ViewProperties extends JPanel implements SingletonWindow {
66

    
67
    private static final long serialVersionUID = 5328865370833315385L;
68
    private javax.swing.JLabel jLabelName = null;
69
    private javax.swing.JTextField txtName = null;
70
    private javax.swing.JLabel jLabelDate = null;
71
    private javax.swing.JTextField txtDate = null;
72
    private javax.swing.JLabel jLabelOwner = null;
73
    private javax.swing.JTextField txtOwner = null;
74
    private javax.swing.JLabel jLabelMapUnits = null;
75
    private javax.swing.JComboBox cmbMapUnits = null;
76
    private javax.swing.JLabel jLabelDistanceUnits = null;
77
    private javax.swing.JComboBox cmbDistanceUnits = null;
78
    private javax.swing.JLabel jLabelAreaUnits = null;
79
    private javax.swing.JTextArea txtComments = null;
80
    private javax.swing.JLabel jLabelColor = null;
81
    private javax.swing.JLabel jLabelComments = null;
82
    private javax.swing.JLabel lblColor = null;
83

    
84
    private Color backColor = null;
85

    
86
    private JButton btnColor = null;
87
    private DefaultViewDocument view = null;
88
    private javax.swing.JScrollPane jScrollPane = null;
89
    protected CRSSelectPanel jPanelProj = null;
90
    private AcceptCancelPanel okCancelPanel = null;
91
    private boolean isAcceppted = false;
92
    private JComboBox cmbDistanceArea = null;
93

    
94
    /**
95
     * This is the default constructor
96
     * 
97
     * @param f
98
     *            Frame padre del dialogo
99
     * @param v
100
     *            Vista que se representa
101
     */
102
    public ViewProperties(DefaultViewDocument v) {
103
        view = v;
104
        initialize();
105
    }
106

    
107
    /**
108
     * This method initializes this
109
     */
110
    private void initialize() {
111
        setLayout(new GridBagLayout());
112
        setBorder(BorderFactory.createEmptyBorder(4, 5, 4, 5));
113

    
114
        GridBagConstraints c = new GridBagConstraints();
115
        c.insets = new Insets(2, 5, 2, 5);
116
        c.gridy = -1;
117

    
118
        addRow(c, getJLabelName(), getTxtName());
119
        addRow(c, getJLabelDate(), getTxtDate());
120
        addRow(c, getJLabelOwner(), getTxtOwner());
121
        addRow(c, getJLabelMapUnits(), getCmbMapUnits());
122
        addRow(c, getJLabelDistanceUnits(), getCmbDistanceUnits());
123
        addRow(c, getJLabelAreaUnits(), getCmbDistanceArea());
124
        addRow(c, getJLabelColor(), getJPanelColor());
125

    
126
        c.anchor = GridBagConstraints.WEST;
127
        c.weightx = 0.0d;
128
        c.gridx = 0;
129
        c.gridy++;
130
        add(getJLabelColor(), c);
131

    
132
        c.fill = GridBagConstraints.HORIZONTAL;
133
        c.weightx = 1.0d;
134
        c.gridx = 1;
135
        add(getJPanelColor(), c);
136

    
137
        c.anchor = GridBagConstraints.WEST;
138
        c.weightx = 0.0d;
139
        c.gridx = 0;
140
        c.gridwidth = GridBagConstraints.REMAINDER;
141
        c.gridy++;
142
        c.weightx = 1.0d;
143
        c.fill = GridBagConstraints.HORIZONTAL;
144
        add(getJPanelProj(), c);
145

    
146
        c.anchor = GridBagConstraints.WEST;
147
        c.weightx = 0.0d;
148
        c.gridx = 0;
149
        c.gridy++;
150
        add(getJLabelComments(), c);
151

    
152
        c.fill = GridBagConstraints.BOTH;
153
        c.weightx = 1.0d;
154
        c.gridy++;
155
        c.gridwidth = 2;
156
        add(getJScrollPaneComments(), c);
157

    
158
        c.anchor = GridBagConstraints.EAST;
159
        c.gridx = 0;
160
        c.gridwidth = 2;
161
        c.gridy++;
162
        c.weightx = 1.0d;
163

    
164
        add(getOkCancelPanel(), c);
165
    }
166

    
167
    private JComponent getJPanelColor() {
168
        JPanel colorPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
169
        colorPanel.add(getLblColor());
170
        colorPanel.add(getBtnColor());
171

    
172
        return colorPanel;
173
    }
174

    
175
    private void addRow(GridBagConstraints c, JComponent label, JComponent text) {
176
        c.anchor = GridBagConstraints.WEST;
177
        c.weightx = 0.0d;
178
        c.gridx = 0;
179
        c.gridy++;
180
        add(label, c);
181

    
182
        c.fill = GridBagConstraints.HORIZONTAL;
183
        c.weightx = 1.0d;
184
        c.gridx = 1;
185
        add(text, c);
186
    }
187

    
188
    /**
189
     * This method initializes jLabel
190
     * 
191
     * @return javax.swing.JLabel
192
     */
193
    private javax.swing.JLabel getJLabelName() {
194
        if (jLabelName == null) {
195
            jLabelName =
196
                new javax.swing.JLabel(Messages.getText("nombre") + ":");
197
        }
198

    
199
        return jLabelName;
200
    }
201

    
202
    /**
203
     * This method initializes txtName
204
     * 
205
     * @return javax.swing.JTextField
206
     */
207
    private javax.swing.JTextField getTxtName() {
208
        if (txtName == null) {
209
            txtName = new javax.swing.JTextField(view.getName());
210
        }
211

    
212
        return txtName;
213
    }
214

    
215
    /**
216
     * This method initializes jLabel1
217
     * 
218
     * @return javax.swing.JLabel
219
     */
220
    private javax.swing.JLabel getJLabelDate() {
221
        if (jLabelDate == null) {
222
            jLabelDate =
223
                new javax.swing.JLabel(Messages.getText("creation_date") + ":");
224
        }
225

    
226
        return jLabelDate;
227
    }
228

    
229
    /**
230
     * This method initializes txtDate
231
     * 
232
     * @return javax.swing.JTextField
233
     */
234
    private javax.swing.JTextField getTxtDate() {
235
        if (txtDate == null) {
236
            txtDate = new javax.swing.JTextField(view.getCreationDate());
237
            txtDate.setEditable(false);
238
            txtDate.setBackground(java.awt.Color.white);
239
        }
240

    
241
        return txtDate;
242
    }
243

    
244
    /**
245
     * This method initializes jLabel2
246
     * 
247
     * @return javax.swing.JLabel
248
     */
249
    private javax.swing.JLabel getJLabelOwner() {
250
        if (jLabelOwner == null) {
251
            jLabelOwner =
252
                new javax.swing.JLabel(Messages.getText("owner") + ":");
253
        }
254

    
255
        return jLabelOwner;
256
    }
257

    
258
    /**
259
     * This method initializes txtOwner
260
     * 
261
     * @return javax.swing.JTextField
262
     */
263
    private javax.swing.JTextField getTxtOwner() {
264
        if (txtOwner == null) {
265
            txtOwner = new javax.swing.JTextField(view.getOwner());
266
        }
267

    
268
        return txtOwner;
269
    }
270

    
271
    /**
272
     * This method initializes jLabel4
273
     * 
274
     * @return javax.swing.JLabel
275
     */
276
    private javax.swing.JLabel getJLabelMapUnits() {
277
        if (jLabelMapUnits == null) {
278
            jLabelMapUnits =
279
                new javax.swing.JLabel(Messages.getText("map_units") + ":");
280
        }
281

    
282
        return jLabelMapUnits;
283
    }
284

    
285
    /**
286
     * This method initializes cmbMapUnits
287
     * 
288
     * @return javax.swing.JComboBox
289
     */
290
    private javax.swing.JComboBox getCmbMapUnits() {
291
        if (cmbMapUnits == null
292
            || MapContext.getDistanceNames().length > cmbMapUnits
293
                .getItemCount()) {
294
            cmbMapUnits = new JComboBoxUnits(false);
295

    
296
            IProjection proj = view.getProjection();
297
            if (!proj.isProjected()) {
298
                cmbMapUnits.setSelectedItem(Messages.getText("Grados")); // deegree
299
                cmbMapUnits.setEnabled(false);
300
            } else {
301
                if (!(cmbMapUnits.getItemCount() == MapContext
302
                    .getDistanceNames().length)) {
303
                    cmbMapUnits.removeItem(Messages.getText("Grados")); // deegree
304
                    view.getMapContext().getViewPort().setMapUnits(1);
305
                }
306
                cmbMapUnits.setSelectedIndex(view.getMapContext().getViewPort()
307
                    .getMapUnits());
308
                cmbMapUnits.setEnabled(true);
309
            }
310
            cmbMapUnits.setSelectedIndex(view.getMapContext().getViewPort()
311
                .getMapUnits());
312
        }
313

    
314
        return cmbMapUnits;
315
    }
316

    
317
    /**
318
     * This method initializes jLabel5
319
     * 
320
     * @return javax.swing.JLabel
321
     */
322
    private javax.swing.JLabel getJLabelDistanceUnits() {
323
        if (jLabelDistanceUnits == null) {
324
            jLabelDistanceUnits =
325
                new javax.swing.JLabel(Messages.getText("distance_units") + ":");
326
        }
327

    
328
        return jLabelDistanceUnits;
329
    }
330

    
331
    /**
332
     * This method initializes jLabel6
333
     * 
334
     * @return javax.swing.JLabel
335
     */
336
    private javax.swing.JLabel getJLabelAreaUnits() {
337
        if (jLabelAreaUnits == null) {
338
            jLabelAreaUnits =
339
                new javax.swing.JLabel(Messages.getText("unidades_area") + ":");
340
        }
341

    
342
        return jLabelAreaUnits;
343
    }
344

    
345
    /**
346
     * This method initializes cmbDistanceUnits
347
     * 
348
     * @return javax.swing.JComboBox
349
     */
350
    private javax.swing.JComboBox getCmbDistanceUnits() {
351
        if (cmbDistanceUnits == null
352
            || MapContext.getDistanceNames().length > cmbDistanceUnits
353
                .getItemCount()) {
354
            cmbDistanceUnits = new JComboBoxUnits(false);
355
            cmbDistanceUnits.setSelectedIndex(view.getMapContext()
356
                .getViewPort().getDistanceUnits());
357
        }
358

    
359
        return cmbDistanceUnits;
360
    }
361

    
362
    /**
363
     * This method initializes jLabel6
364
     * 
365
     * @return javax.swing.JLabel
366
     */
367
    private javax.swing.JLabel getJLabelComments() {
368
        if (jLabelComments == null) {
369
            jLabelComments =
370
                new javax.swing.JLabel(Messages.getText("comentarios") + ":");
371
            jLabelComments
372
                .setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
373
            jLabelComments
374
                .setHorizontalTextPosition(javax.swing.SwingConstants.LEFT);
375
        }
376

    
377
        return jLabelComments;
378
    }
379

    
380
    /**
381
     * This method initializes txtComments
382
     * 
383
     * @return javax.swing.JTextArea
384
     */
385
    private javax.swing.JTextArea getTxtComments() {
386
        if (txtComments == null) {
387
            txtComments = new javax.swing.JTextArea(view.getComment());
388
            txtComments.setRows(3);
389
            txtComments.setColumns(20);
390
        }
391

    
392
        return txtComments;
393
    }
394

    
395
    /**
396
     * This method initializes jLabel7
397
     * 
398
     * @return javax.swing.JLabel
399
     */
400
    private javax.swing.JLabel getJLabelColor() {
401
        if (jLabelColor == null) {
402
            jLabelColor =
403
                new javax.swing.JLabel(Messages.getText("background_color")
404
                    + ":");
405
        }
406

    
407
        return jLabelColor;
408
    }
409

    
410
    /**
411
     * This method initializes lblColor
412
     * 
413
     * @return javax.swing.JLabel
414
     */
415
    private javax.swing.JLabel getLblColor() {
416
        if (lblColor == null) {
417
            lblColor = new javax.swing.JLabel("");
418
            lblColor.setPreferredSize(new java.awt.Dimension(30, 16));
419
            Color theColor = view.getMapContext().getViewPort().getBackColor();
420
            backColor = theColor;
421
            if (theColor == null) {
422
                theColor = Color.WHITE;
423
            }
424
            lblColor.setBackground(theColor);
425
            lblColor.setOpaque(true);
426
        }
427

    
428
        return lblColor;
429
    }
430

    
431
    /**
432
     * This method initializes btnColor
433
     * 
434
     * @return javax.swing.JButton
435
     */
436
    private JButton getBtnColor() {
437
        if (btnColor == null) {
438
            btnColor =
439
                ToolsSwingLocator.getUsabilitySwingManager().createJButton();
440

    
441
            btnColor.setText("...");
442

    
443
            btnColor.addActionListener(new java.awt.event.ActionListener() {
444

    
445
                public void actionPerformed(java.awt.event.ActionEvent e) {
446
                    Color ret =
447
                        JColorChooser.showDialog(ViewProperties.this,
448
                            Messages.getText("background_color"),
449
                            lblColor.getBackground());
450

    
451
                    if (ret != null) {
452
                        lblColor.setBackground(ret);
453
                        backColor = ret;
454
                    } else {
455
                        lblColor.setBackground(Color.WHITE);
456
                    }
457
                }
458
            });
459
        }
460

    
461
        return btnColor;
462
    }
463

    
464
    /**
465
     * This method initializes jScrollPane
466
     * 
467
     * @return javax.swing.JScrollPane
468
     */
469
    private javax.swing.JScrollPane getJScrollPaneComments() {
470
        if (jScrollPane == null) {
471
            jScrollPane = new javax.swing.JScrollPane();
472
            jScrollPane.setViewportView(getTxtComments());
473
            Dimension dim = getTxtComments().getPreferredSize();
474
            jScrollPane
475
                .setMinimumSize(new Dimension(dim.width, dim.height + 10));
476
        }
477

    
478
        return jScrollPane;
479
    }
480

    
481
    /**
482
     * @see com.iver.mdiApp.ui.MDIManager.IWindow#getWindowInfo()
483
     */
484
    public WindowInfo getWindowInfo() {
485
        WindowInfo m_viewinfo = new WindowInfo();
486
        this.validate();
487
        m_viewinfo.setTitle(Messages.getText("propiedades_vista"));
488
        Dimension dim = getPreferredSize();
489
        m_viewinfo.setWidth(dim.width);
490
        m_viewinfo.setHeight(dim.height
491
            + getOkCancelPanel().getPreferredSize().height);
492
        return m_viewinfo;
493
    }
494

    
495
    /**
496
     * This method initializes jPanel4
497
     * 
498
     * @return javax.swing.JPanel
499
     */
500
    private CRSSelectPanel getJPanelProj() {
501
        if (jPanelProj == null) {
502
            IProjection proj = view.getProjection();
503
            jPanelProj = CRSSelectPanel.getPanel(proj);
504
            jPanelProj.addActionListener(new java.awt.event.ActionListener() {
505

    
506
                public void actionPerformed(java.awt.event.ActionEvent e) {
507
                    if (jPanelProj.isOkPressed()) {
508
                        if (!jPanelProj.getCurProj().isProjected()) {
509
                            getCmbMapUnits().setSelectedItem(
510
                                PluginServices
511
                                    .getText(this, "Grados"));
512
                            getCmbMapUnits().setEnabled(false);
513
                        } else {
514
                            if (getCmbMapUnits().getSelectedItem().equals(
515
                                PluginServices
516
                                    .getText(this, "Grados"))) {
517
                                getCmbMapUnits().setSelectedIndex(1);
518
                            }
519
                            getCmbMapUnits().setEnabled(true);
520
                        }
521
                        view.setProjection(jPanelProj.getCurProj());
522
                    }
523
                }
524
            });
525
        }
526
        return jPanelProj;
527
    }
528

    
529
    /**
530
     * @see org.gvsig.andami.ui.mdiManager.SingletonWindow#getWindowModel()
531
     */
532
    public Object getWindowModel() {
533
        return view;
534
    }
535

    
536
    /**
537
     * This method initializes okCancelPanel
538
     * 
539
     * @return javax.swing.JPanel
540
     */
541
    private AcceptCancelPanel getOkCancelPanel() {
542
        if (okCancelPanel == null) {
543
            ActionListener okAction, cancelAction;
544
            okAction = new java.awt.event.ActionListener() {
545

    
546
                public void actionPerformed(java.awt.event.ActionEvent e) {
547
                    String name = txtName.getText();
548
                    if (name == null || name.length() == 0) {
549
                        return;
550
                    }
551
                    Project project =
552
                        ProjectManager.getInstance().getCurrentProject();
553
                    List<Document> views =
554
                        project.getDocuments(ViewManager.TYPENAME);
555
                    for (Document theView : views) {
556
                        if (view.equals(theView)) {
557
                            continue;
558
                        }
559
                        if (theView.getName().equals(name)) {
560
                            JOptionPane.showMessageDialog(
561
                                (Component) PluginServices.getMainFrame(),
562
                                Messages.getText("elemento_ya_existe"));
563
                            return;
564
                        }
565
                    }
566

    
567
                    view.setName(name);
568
                    view.setCreationDate(txtDate.getText());
569
                    view.setOwner(txtOwner.getText());
570
                    view.setComment(txtComments.getText());
571
                    view.getMapContext().getViewPort()
572
                        .setMapUnits(cmbMapUnits.getSelectedIndex());
573
                    view.getMapContext().getViewPort()
574
                        .setDistanceUnits(cmbDistanceUnits.getSelectedIndex());
575
                    view.getMapContext().getViewPort()
576
                        .setDistanceArea(cmbDistanceArea.getSelectedIndex());
577
                    view.setBackColor(backColor);
578

    
579
                    // Select the projection
580
                    if (jPanelProj.isOkPressed()) {
581
                        if (!jPanelProj.getCurProj().isProjected()) {
582
                            getCmbMapUnits().setSelectedItem(
583
                                Messages.getText("Grados"));
584
                            getCmbMapUnits().setEnabled(false);
585
                        } else {
586
                            if (getCmbMapUnits().getSelectedItem().equals(
587
                                Messages.getText("Grados"))) {
588
                                getCmbMapUnits().setSelectedIndex(1);
589
                            }
590
                            getCmbMapUnits().setEnabled(true);
591
                        }
592
                        view.setProjection(jPanelProj.getCurProj());
593
                    }
594

    
595
                    isAcceppted = true;
596
                    PluginServices.getMDIManager().closeWindow(
597
                        ViewProperties.this);
598
                }
599
            };
600
            cancelAction = new java.awt.event.ActionListener() {
601

    
602
                public void actionPerformed(java.awt.event.ActionEvent e) {
603
                    isAcceppted = false;
604
                    PluginServices.getMDIManager().closeWindow(
605
                        ViewProperties.this);
606
                }
607
            };
608
            okCancelPanel = new AcceptCancelPanel(okAction, cancelAction);
609
        }
610
        return okCancelPanel;
611
    }
612

    
613
    public boolean isAcceppted() {
614
        return isAcceppted;
615
    }
616

    
617
    /**
618
     * This method initializes jComboBox
619
     * 
620
     * @return javax.swing.JComboBox
621
     */
622
    private JComboBox getCmbDistanceArea() {
623
        String[] names = MapContext.getAreaNames();
624
        if (cmbDistanceArea == null
625
            || names.length > cmbDistanceArea.getItemCount()) {
626
            for (int i = 0; i < names.length; i++) {
627
                names[i] =
628
                    Messages.getText(names[i]) + MapContext.getOfLinear(i);
629
            }
630
            cmbDistanceArea = new javax.swing.JComboBox(names);
631
            cmbDistanceArea.setEditable(false);
632
            cmbDistanceArea.setSelectedIndex(view.getMapContext().getViewPort()
633
                .getDistanceArea());
634
            cmbDistanceArea
635
                .addActionListener(new java.awt.event.ActionListener() {
636

    
637
                    public void actionPerformed(java.awt.event.ActionEvent e) {
638
                        // view.getMapContext().getViewPort().setDistanceUnits(cmbDistanceUnits.getSelectedIndex());
639
                    }
640
                });
641
        }
642

    
643
        return cmbDistanceArea;
644

    
645
    }
646

    
647
    public Object getWindowProfile() {
648
        return WindowInfo.PROPERTIES_PROFILE;
649
    }
650

    
651
}