Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / project / documents / gui / ProjectProperties.java @ 37840

History | View | Annotate | Download (12.9 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.gui;
23

    
24
import java.awt.Color;
25
import java.awt.Dimension;
26
import java.awt.FlowLayout;
27
import java.awt.GridBagConstraints;
28
import java.awt.GridBagLayout;
29
import java.awt.GridLayout;
30
import java.awt.Insets;
31
import java.io.File;
32

    
33
import javax.swing.JButton;
34
import javax.swing.JColorChooser;
35
import javax.swing.JComponent;
36
import javax.swing.JLabel;
37
import javax.swing.JPanel;
38
import javax.swing.JScrollPane;
39
import javax.swing.JTextArea;
40
import javax.swing.JTextField;
41

    
42
import org.gvsig.andami.PluginServices;
43
import org.gvsig.andami.ui.mdiManager.IWindow;
44
import org.gvsig.andami.ui.mdiManager.WindowInfo;
45
import org.gvsig.app.extension.ProjectExtension;
46
import org.gvsig.app.project.Project;
47
import org.gvsig.gui.beans.AcceptCancelPanel;
48
import org.gvsig.tools.swing.api.ToolsSwingLocator;
49

    
50
/**
51
 * Propiedades del proyecto
52
 * 
53
 * @author Fernando Gonz?lez Cort?s
54
 * @author gvSIG team
55
 */
56
public class ProjectProperties extends JPanel implements IWindow {
57

    
58
    private static final long serialVersionUID = 8952351479171919349L;
59
    private Project project = null;
60
    private JPanel jPanel = null;
61
    private JLabel jLabel = null;
62
    private JLabel jLabel1 = null;
63
    private JLabel jLabel2 = null;
64
    private JLabel jLabel3 = null;
65
    private JLabel jLabel4 = null;
66
    private JTextField txtName = null;
67
    private JTextField txtPath = null;
68
    private JTextField txtCreationDate = null;
69
    private JTextField txtModificationDate = null;
70
    private JTextField txtOwner = null;
71
    private JLabel jLabel5 = null;
72
    private JTextArea txtComments = null;
73
    private JLabel jLabel6 = null;
74
    private JLabel lblColor = null;
75
    private JButton btnColor = null;
76
    private JScrollPane jScrollPane = null;
77

    
78
    /**
79
     * This is the default constructor
80
     * 
81
     * @param owner
82
     *            Frame padre del di?logo
83
     * @param p
84
     *            Proyecto cuyos datos se muestran en el di?logo
85
     */
86
    public ProjectProperties(Project p) {
87
        project = p;
88
        initialize();
89
    }
90

    
91
    /**
92
     * This method initializes this
93
     */
94
    private void initialize() {
95
        setLayout(new GridLayout(1, 1, 0, 0));
96
        add(getJPanel());
97

    
98
        getTxtName().setText(project.getName());
99

    
100
        String path = ProjectExtension.getPath();
101

    
102
        if (path != null) {
103
            File f = new File(path);
104
            getTxtPath().setText(f.toString());
105
        } else {
106
            getTxtPath().setText("");
107
        }
108

    
109
        getTxtOwner().setText(project.getOwner());
110
        getTxtComments().setText(project.getComments());
111
        getTxtCreationDate().setText(project.getCreationDate());
112
        getTxtModificationDate().setText(project.getModificationDate());
113

    
114
        getLblColor().setBackground(project.getSelectionColor());
115
    }
116

    
117
    /**
118
     * This method initializes jPanel
119
     * 
120
     * @return JPanel
121
     */
122
    private JPanel getJPanel() {
123
        if (jPanel == null) {
124

    
125
            jPanel = new JPanel(new GridBagLayout());
126
            GridBagConstraints c = new GridBagConstraints();
127
            c.insets = new Insets(2, 5, 0, 5);
128
            c.gridy = -1;
129

    
130
            addRow(c, getJLabel(), getTxtName());
131
            addRow(c, getJLabel1(), getTxtPath());
132
            addRow(c, getJLabel2(), getTxtCreationDate());
133
            addRow(c, getJLabel3(), getTxtModificationDate());
134
            addRow(c, getJLabel4(), getTxtOwner());
135

    
136
            c.anchor = GridBagConstraints.WEST;
137
            c.weightx = 0.0d;
138
            c.gridx = 0;
139
            c.gridy++;
140
            jPanel.add(getJLabel6(), c);
141

    
142
            JPanel colorPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
143
            colorPanel.add(getLblColor());
144
            colorPanel.add(getBtnColor());
145

    
146
            c.fill = GridBagConstraints.HORIZONTAL;
147
            c.weightx = 1.0d;
148
            c.gridx = 1;
149
            jPanel.add(colorPanel, c);
150

    
151
            c.anchor = GridBagConstraints.WEST;
152
            c.weightx = 0.0d;
153
            c.gridx = 0;
154
            c.gridy++;
155
            jPanel.add(getJLabel5(), c);
156

    
157
            c.fill = GridBagConstraints.BOTH;
158
            c.weightx = 1.0d;
159
            c.gridy++;
160
            c.gridwidth = 2;
161
            jPanel.add(getJScrollPane(), c);
162

    
163
            java.awt.event.ActionListener okAction =
164
                new java.awt.event.ActionListener() {
165

    
166
                    public void actionPerformed(java.awt.event.ActionEvent e) {
167
                        project.setName(txtName.getText());
168
                        project.setOwner(txtOwner.getText());
169
                        project.setComments(txtComments.getText());
170
                        project.setSelectionColor(lblColor.getBackground());
171
                        PluginServices.getMDIManager().closeWindow(
172
                            ProjectProperties.this);
173
                    }
174
                }, cancelAction = new java.awt.event.ActionListener() {
175

    
176
                public void actionPerformed(java.awt.event.ActionEvent e) {
177
                    PluginServices.getMDIManager().closeWindow(
178
                        ProjectProperties.this);
179
                }
180
            };
181

    
182
            c.anchor = GridBagConstraints.EAST;
183
            c.gridx = 0;
184
            c.gridwidth = 2;
185
            c.gridy++;
186
            c.weightx = 1.0d;
187

    
188
            jPanel.add(new AcceptCancelPanel(okAction, cancelAction), c);
189
        }
190

    
191
        return jPanel;
192
    }
193

    
194
    private void addRow(GridBagConstraints c, JComponent label, JComponent text) {
195
        c.anchor = GridBagConstraints.WEST;
196
        c.weightx = 0.0d;
197
        c.gridx = 0;
198
        c.gridy++;
199
        jPanel.add(label, c);
200

    
201
        c.fill = GridBagConstraints.HORIZONTAL;
202
        c.weightx = 1.0d;
203
        c.gridx = 1;
204
        jPanel.add(text, c);
205
    }
206

    
207
    /**
208
     * This method initializes jLabel
209
     * 
210
     * @return JLabel
211
     */
212
    private JLabel getJLabel() {
213
        if (jLabel == null) {
214
            jLabel = new JLabel();
215
            jLabel.setText(PluginServices.getText(this, "nombre_sesion") + ":");
216
        }
217

    
218
        return jLabel;
219
    }
220

    
221
    /**
222
     * This method initializes jLabel1
223
     * 
224
     * @return JLabel
225
     */
226
    private JLabel getJLabel1() {
227
        if (jLabel1 == null) {
228
            jLabel1 = new JLabel();
229
            jLabel1.setText(PluginServices.getText(this, "path") + ":");
230
        }
231

    
232
        return jLabel1;
233
    }
234

    
235
    /**
236
     * This method initializes jLabel2
237
     * 
238
     * @return JLabel
239
     */
240
    private JLabel getJLabel2() {
241
        if (jLabel2 == null) {
242
            jLabel2 = new JLabel();
243
            jLabel2
244
                .setText(PluginServices.getText(this, "creation_date") + ":");
245
        }
246

    
247
        return jLabel2;
248
    }
249

    
250
    /**
251
     * This method initializes jLabel3
252
     * 
253
     * @return JLabel
254
     */
255
    private JLabel getJLabel3() {
256
        if (jLabel3 == null) {
257
            jLabel3 = new JLabel();
258
            jLabel3.setText(PluginServices.getText(this, "modification_date")
259
                + ":");
260
        }
261

    
262
        return jLabel3;
263
    }
264

    
265
    /**
266
     * This method initializes jLabel4
267
     * 
268
     * @return JLabel
269
     */
270
    private JLabel getJLabel4() {
271
        if (jLabel4 == null) {
272
            jLabel4 = new JLabel();
273
            jLabel4.setText(PluginServices.getText(this, "owner") + ":");
274
        }
275

    
276
        return jLabel4;
277
    }
278

    
279
    /**
280
     * This method initializes txtName
281
     * 
282
     * @return JTextField
283
     */
284
    private JTextField getTxtName() {
285
        if (txtName == null) {
286
            txtName = new JTextField(20);
287
        }
288

    
289
        return txtName;
290
    }
291

    
292
    /**
293
     * This method initializes txtPath
294
     * 
295
     * @return JTextField
296
     */
297
    private JTextField getTxtPath() {
298
        if (txtPath == null) {
299
            txtPath = new JTextField(20);
300
            txtPath.setEditable(false);
301
            txtPath.setBackground(java.awt.Color.white);
302
        }
303

    
304
        return txtPath;
305
    }
306

    
307
    /**
308
     * This method initializes txtCreationDate
309
     * 
310
     * @return JTextField
311
     */
312
    private JTextField getTxtCreationDate() {
313
        if (txtCreationDate == null) {
314
            txtCreationDate = new JTextField(20);
315
            txtCreationDate.setEditable(false);
316
            txtCreationDate.setBackground(java.awt.Color.white);
317
        }
318

    
319
        return txtCreationDate;
320
    }
321

    
322
    /**
323
     * This method initializes txtModificationDate
324
     * 
325
     * @return JTextField
326
     */
327
    private JTextField getTxtModificationDate() {
328
        if (txtModificationDate == null) {
329
            txtModificationDate = new JTextField(20);
330
            txtModificationDate.setEditable(false);
331
            txtModificationDate.setBackground(java.awt.Color.white);
332
        }
333

    
334
        return txtModificationDate;
335
    }
336

    
337
    /**
338
     * This method initializes txtOwner
339
     * 
340
     * @return JTextField
341
     */
342
    private JTextField getTxtOwner() {
343
        if (txtOwner == null) {
344
            txtOwner = new JTextField(20);
345
        }
346

    
347
        return txtOwner;
348
    }
349

    
350
    /**
351
     * This method initializes jLabel5
352
     * 
353
     * @return JLabel
354
     */
355
    private JLabel getJLabel5() {
356
        if (jLabel5 == null) {
357
            jLabel5 = new JLabel();
358
            jLabel5.setText(PluginServices.getText(this, "comentarios") + ":");
359
        }
360

    
361
        return jLabel5;
362
    }
363

    
364
    /**
365
     * This method initializes txtComments
366
     * 
367
     * @return JTextArea
368
     */
369
    private JTextArea getTxtComments() {
370
        if (txtComments == null) {
371
            txtComments = new JTextArea();
372
            txtComments.setRows(4);
373
            txtComments.setColumns(20);
374
        }
375

    
376
        return txtComments;
377
    }
378

    
379
    /**
380
     * This method initializes jLabel6
381
     * 
382
     * @return JLabel
383
     */
384
    private JLabel getJLabel6() {
385
        if (jLabel6 == null) {
386
            jLabel6 = new JLabel();
387
            jLabel6.setText(PluginServices.getText(this, "selection_color")
388
                + ":");
389
        }
390

    
391
        return jLabel6;
392
    }
393

    
394
    /**
395
     * This method initializes lblColor
396
     * 
397
     * @return JLabel
398
     */
399
    private JLabel getLblColor() {
400
        if (lblColor == null) {
401
            lblColor = new JLabel();
402

    
403
            lblColor.setPreferredSize(getBtnColor().getPreferredSize());
404
            lblColor.setOpaque(true);
405
        }
406

    
407
        return lblColor;
408
    }
409

    
410
    /**
411
     * This method initializes btnColor
412
     * 
413
     * @return JButton
414
     */
415
    private JButton getBtnColor() {
416
        if (btnColor == null) {
417
            btnColor =
418
                ToolsSwingLocator.getUsabilitySwingManager().createJButton(
419
                    "...");
420

    
421
            btnColor.addActionListener(new java.awt.event.ActionListener() {
422

    
423
                public void actionPerformed(java.awt.event.ActionEvent e) {
424
                    Color ret =
425
                        JColorChooser.showDialog(ProjectProperties.this,
426
                            PluginServices.getText(this, "selection_color"),
427
                            lblColor.getBackground());
428

    
429
                    if (ret != null) {
430
                        lblColor.setBackground(ret);
431
                    }
432
                }
433
            });
434
        }
435

    
436
        return btnColor;
437
    }
438

    
439
    /**
440
     * This method initializes jScrollPane
441
     * 
442
     * @return JScrollPane
443
     */
444
    private JScrollPane getJScrollPane() {
445
        if (jScrollPane == null) {
446
            jScrollPane = new JScrollPane(getTxtComments());
447
            Dimension dim = getTxtComments().getPreferredSize();
448
            jScrollPane
449
                .setMinimumSize(new Dimension(dim.width, dim.height + 10));
450
        }
451

    
452
        return jScrollPane;
453
    }
454

    
455
    /**
456
     * @see com.iver.mdiApp.ui.MDIManager.IWindow#getWindowInfo()
457
     */
458
    public WindowInfo getWindowInfo() {
459
        WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODALDIALOG);
460
        this.validate();
461
        Dimension dim = getPreferredSize();
462
        m_viewinfo.setWidth(dim.width);
463
        m_viewinfo.setHeight(dim.height);
464
        m_viewinfo.setTitle(PluginServices.getText(this, "propiedades_sesion"));
465
        return m_viewinfo;
466
    }
467

    
468
    /**
469
     * @see com.iver.mdiApp.ui.MDIManager.IWindow#windowActivated()
470
     */
471
    public void viewActivated() {
472
    }
473

    
474
    public Object getWindowProfile() {
475
        return WindowInfo.DIALOG_PROFILE;
476
    }
477

    
478
}