Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / project / documents / gui / ProjectGeneralPropertiesPage.java @ 41350

History | View | Annotate | Download (10.7 KB)

1
package org.gvsig.app.project.documents.gui;
2

    
3
import java.awt.Color;
4
import java.awt.Dimension;
5
import java.awt.FlowLayout;
6
import java.awt.GridBagConstraints;
7
import java.awt.GridBagLayout;
8
import java.awt.GridLayout;
9
import java.awt.Insets;
10
import java.io.File;
11
import javax.swing.JButton;
12
import javax.swing.JColorChooser;
13
import javax.swing.JComponent;
14
import javax.swing.JLabel;
15
import javax.swing.JPanel;
16
import javax.swing.JScrollPane;
17
import javax.swing.JTextArea;
18
import javax.swing.JTextField;
19
import org.gvsig.andami.PluginServices;
20
import org.gvsig.app.extension.ProjectExtension;
21
import org.gvsig.app.project.Project;
22
import org.gvsig.propertypage.PropertiesPage;
23
import org.gvsig.tools.ToolsLocator;
24
import org.gvsig.tools.i18n.I18nManager;
25
import org.gvsig.tools.swing.api.ToolsSwingLocator;
26

    
27
public class ProjectGeneralPropertiesPage extends JPanel implements PropertiesPage {
28

    
29
    private Project project = null;
30

    
31
    private JPanel jPanel = null;
32
    private JLabel jLabel = null;
33
    private JLabel jLabel1 = null;
34
    private JLabel jLabel2 = null;
35
    private JLabel jLabel3 = null;
36
    private JLabel jLabel4 = null;
37
    private JTextField txtName = null;
38
    private JTextField txtPath = null;
39
    private JTextField txtCreationDate = null;
40
    private JTextField txtModificationDate = null;
41
    private JTextField txtOwner = null;
42
    private JLabel jLabel5 = null;
43
    private JTextArea txtComments = null;
44
    private JLabel jLabel6 = null;
45
    private JLabel lblColor = null;
46
    private JButton btnColor = null;
47
    private JScrollPane jScrollPane = null;
48

    
49
    public ProjectGeneralPropertiesPage(Project project) {
50
        this.project = project;
51
        initComponents();
52
    }
53

    
54
    public boolean whenAccept() {
55
        return whenApply();
56
    }
57

    
58
    public boolean whenApply() {
59
        project.setName(txtName.getText());
60
        project.setOwner(txtOwner.getText());
61
        project.setComments(txtComments.getText());
62
        project.setSelectionColor(lblColor.getBackground());
63

    
64
        return true;
65
    }
66

    
67
    public boolean whenCancel() {
68
        return true;
69
    }
70

    
71
    public String getTitle() {
72
        I18nManager i18nManager = ToolsLocator.getI18nManager();
73
        return i18nManager.getTranslation("General");
74
    }
75

    
76
    public int getPriority() {
77
        return 1000;
78
    }
79

    
80
    public JComponent asJComponent() {
81
        return this;
82
    }
83

    
84
    private void initComponents() {
85
        setLayout(new GridLayout(1, 1, 0, 0));
86
        add(getJPanel());
87

    
88
        getTxtName().setText(project.getName());
89

    
90
        String path = ProjectExtension.getPath();
91

    
92
        if ( path != null ) {
93
            File f = new File(path);
94
            getTxtPath().setText(f.toString());
95
        } else {
96
            getTxtPath().setText("");
97
        }
98

    
99
        getTxtOwner().setText(project.getOwner());
100
        getTxtComments().setText(project.getComments());
101
        getTxtCreationDate().setText(project.getCreationDate());
102
        getTxtModificationDate().setText(project.getModificationDate());
103

    
104
        getLblColor().setBackground(project.getSelectionColor());
105
    }
106

    
107
    /**
108
     * This method initializes jPanel
109
     *
110
     * @return JPanel
111
     */
112
    private JPanel getJPanel() {
113
        if ( jPanel == null ) {
114

    
115
            jPanel = new JPanel(new GridBagLayout());
116
            GridBagConstraints c = new GridBagConstraints();
117
            c.insets = new Insets(2, 5, 0, 5);
118
            c.gridy = -1;
119

    
120
            addRow(c, getJLabel(), getTxtName());
121
            addRow(c, getJLabel1(), getTxtPath());
122
            addRow(c, getJLabel2(), getTxtCreationDate());
123
            addRow(c, getJLabel3(), getTxtModificationDate());
124
            addRow(c, getJLabel4(), getTxtOwner());
125

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

    
132
            JPanel colorPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
133
            colorPanel.add(getLblColor());
134
            colorPanel.add(getBtnColor());
135

    
136
            c.fill = GridBagConstraints.HORIZONTAL;
137
            c.weightx = 1.0d;
138
            c.gridx = 1;
139
            jPanel.add(colorPanel, c);
140

    
141
            c.anchor = GridBagConstraints.WEST;
142
            c.weightx = 0.0d;
143
            c.gridx = 0;
144
            c.gridy++;
145
            jPanel.add(getJLabel5(), c);
146

    
147
            c.fill = GridBagConstraints.BOTH;
148
            c.weightx = 1.0d;
149
            c.gridy++;
150
            c.gridwidth = 2;
151
            jPanel.add(getJScrollPane(), c);
152

    
153
            c.anchor = GridBagConstraints.EAST;
154
            c.gridx = 0;
155
            c.gridwidth = 2;
156
            c.gridy++;
157
            c.weightx = 1.0d;
158
        }
159

    
160
        return jPanel;
161
    }
162

    
163
    private void addRow(GridBagConstraints c, JComponent label, JComponent text) {
164
        c.anchor = GridBagConstraints.WEST;
165
        c.weightx = 0.0d;
166
        c.gridx = 0;
167
        c.gridy++;
168
        jPanel.add(label, c);
169

    
170
        c.fill = GridBagConstraints.HORIZONTAL;
171
        c.weightx = 1.0d;
172
        c.gridx = 1;
173
        jPanel.add(text, c);
174
    }
175

    
176
    /**
177
     * This method initializes jLabel
178
     *
179
     * @return JLabel
180
     */
181
    private JLabel getJLabel() {
182
        if ( jLabel == null ) {
183
            jLabel = new JLabel();
184
            jLabel.setText(PluginServices.getText(this, "nombre_sesion") + ":");
185
        }
186

    
187
        return jLabel;
188
    }
189

    
190
    /**
191
     * This method initializes jLabel1
192
     *
193
     * @return JLabel
194
     */
195
    private JLabel getJLabel1() {
196
        if ( jLabel1 == null ) {
197
            jLabel1 = new JLabel();
198
            jLabel1.setText(PluginServices.getText(this, "path") + ":");
199
        }
200

    
201
        return jLabel1;
202
    }
203

    
204
    /**
205
     * This method initializes jLabel2
206
     *
207
     * @return JLabel
208
     */
209
    private JLabel getJLabel2() {
210
        if ( jLabel2 == null ) {
211
            jLabel2 = new JLabel();
212
            jLabel2
213
                    .setText(PluginServices.getText(this, "creation_date") + ":");
214
        }
215

    
216
        return jLabel2;
217
    }
218

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

    
231
        return jLabel3;
232
    }
233

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

    
245
        return jLabel4;
246
    }
247

    
248
    /**
249
     * This method initializes txtName
250
     *
251
     * @return JTextField
252
     */
253
    private JTextField getTxtName() {
254
        if ( txtName == null ) {
255
            txtName = new JTextField(20);
256
        }
257

    
258
        return txtName;
259
    }
260

    
261
    /**
262
     * This method initializes txtPath
263
     *
264
     * @return JTextField
265
     */
266
    private JTextField getTxtPath() {
267
        if ( txtPath == null ) {
268
            txtPath = new JTextField(20);
269
            txtPath.setEditable(false);
270
            txtPath.setBackground(java.awt.Color.white);
271
        }
272

    
273
        return txtPath;
274
    }
275

    
276
    /**
277
     * This method initializes txtCreationDate
278
     *
279
     * @return JTextField
280
     */
281
    private JTextField getTxtCreationDate() {
282
        if ( txtCreationDate == null ) {
283
            txtCreationDate = new JTextField(20);
284
            txtCreationDate.setEditable(false);
285
            txtCreationDate.setBackground(java.awt.Color.white);
286
        }
287

    
288
        return txtCreationDate;
289
    }
290

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

    
303
        return txtModificationDate;
304
    }
305

    
306
    /**
307
     * This method initializes txtOwner
308
     *
309
     * @return JTextField
310
     */
311
    private JTextField getTxtOwner() {
312
        if ( txtOwner == null ) {
313
            txtOwner = new JTextField(20);
314
        }
315

    
316
        return txtOwner;
317
    }
318

    
319
    /**
320
     * This method initializes jLabel5
321
     *
322
     * @return JLabel
323
     */
324
    private JLabel getJLabel5() {
325
        if ( jLabel5 == null ) {
326
            jLabel5 = new JLabel();
327
            jLabel5.setText(PluginServices.getText(this, "comentarios") + ":");
328
        }
329

    
330
        return jLabel5;
331
    }
332

    
333
    /**
334
     * This method initializes txtComments
335
     *
336
     * @return JTextArea
337
     */
338
    private JTextArea getTxtComments() {
339
        if ( txtComments == null ) {
340
            txtComments = new JTextArea();
341
            txtComments.setRows(4);
342
            txtComments.setColumns(20);
343
        }
344

    
345
        return txtComments;
346
    }
347

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

    
360
        return jLabel6;
361
    }
362

    
363
    /**
364
     * This method initializes lblColor
365
     *
366
     * @return JLabel
367
     */
368
    private JLabel getLblColor() {
369
        if ( lblColor == null ) {
370
            lblColor = new JLabel();
371

    
372
            lblColor.setPreferredSize(getBtnColor().getPreferredSize());
373
            lblColor.setOpaque(true);
374
        }
375

    
376
        return lblColor;
377
    }
378

    
379
    /**
380
     * This method initializes btnColor
381
     *
382
     * @return JButton
383
     */
384
    private JButton getBtnColor() {
385
        if ( btnColor == null ) {
386
            btnColor
387
                    = ToolsSwingLocator.getUsabilitySwingManager().createJButton(
388
                            "...");
389

    
390
            btnColor.addActionListener(new java.awt.event.ActionListener() {
391

    
392
                public void actionPerformed(java.awt.event.ActionEvent e) {
393
                    Color ret
394
                            = JColorChooser.showDialog(ProjectGeneralPropertiesPage.this,
395
                                    PluginServices.getText(this, "selection_color"),
396
                                    lblColor.getBackground());
397

    
398
                    if ( ret != null ) {
399
                        lblColor.setBackground(ret);
400
                    }
401
                }
402
            });
403
        }
404

    
405
        return btnColor;
406
    }
407

    
408
    /**
409
     * This method initializes jScrollPane
410
     *
411
     * @return JScrollPane
412
     */
413
    private JScrollPane getJScrollPane() {
414
        if ( jScrollPane == null ) {
415
            jScrollPane = new JScrollPane(getTxtComments());
416
            Dimension dim = getTxtComments().getPreferredSize();
417
            jScrollPane
418
                    .setMinimumSize(new Dimension(dim.width, dim.height + 10));
419
        }
420

    
421
        return jScrollPane;
422
    }
423

    
424
}