Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extGPE-gvSIG / src / org / gvsig / gpe / gui / dialogs / SelectVersionPanel.java @ 27067

History | View | Annotate | Download (14.7 KB)

1 27067 jpiera
package org.gvsig.gpe.gui.dialogs;
2
3
import java.awt.Color;
4
import java.io.File;
5
6
import javax.swing.ImageIcon;
7
import javax.swing.JCheckBox;
8
import javax.swing.JLabel;
9
import javax.swing.JPanel;
10
import javax.swing.JTextField;
11
12
import org.gvsig.gpe.writer.GPEWriterHandler;
13
import org.gvsig.gui.beans.swing.JButton;
14
15
import com.iver.andami.PluginServices;
16
import com.iver.cit.gvsig.project.documents.view.gui.View;
17
import com.iver.utiles.FileUtils;
18
import com.iver.utiles.swing.JComboBox;
19
20
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
21
 *
22
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
23
 *
24
 * This program is free software; you can redistribute it and/or
25
 * modify it under the terms of the GNU General Public License
26
 * as published by the Free Software Foundation; either version 2
27
 * of the License, or (at your option) any later version.
28
 *
29
 * This program is distributed in the hope that it will be useful,
30
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
31
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
32
 * GNU General Public License for more details.
33
 *
34
 * You should have received a copy of the GNU General Public License
35
 * along with this program; if not, write to the Free Software
36
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
37
 *
38
 * For more information, contact:
39
 *
40
 *  Generalitat Valenciana
41
 *   Conselleria d'Infraestructures i Transport
42
 *   Av. Blasco Ib??ez, 50
43
 *   46010 VALENCIA
44
 *   SPAIN
45
 *
46
 *      +34 963862235
47
 *   gvsig@gva.es
48
 *      www.gvsig.gva.es
49
 *
50
 *    or
51
 *
52
 *   IVER T.I. S.A
53
 *   Salamanca 50
54
 *   46005 Valencia
55
 *   Spain
56
 *
57
 *   +34 963163400
58
 *   dac@iver.es
59
 */
60
/* CVS MESSAGES:
61
 *
62
 * $Id$
63
 * $Log$
64
 *
65
 */
66
/**
67
 * @author Jorge Piera LLodr? (jorge.piera@iver.es)
68
 */
69
public class SelectVersionPanel extends JPanel{
70
        private static final String defaultDir = System.getProperty("user.home") +
71
                File.separatorChar;
72
        private static final String defaultFile = "output";
73
        private JPanel buttonsPanel;
74
        private JButton cancelButton;
75
        private JPanel componentsPanel;
76
        private JButton exportButton;
77
        private javax.swing.JButton fileButton;
78
        private JLabel fileLabel;
79
        private JTextField fileText;
80
        private JComboBox formatCombo;
81
        private JLabel formatLabel;
82
        private javax.swing.JButton schemaButton;
83
        private JCheckBox schemaCheck;
84
        private JLabel schemaLabel;
85
        private JTextField schemaText;
86
        private JComboBox writerCombo;
87
        private JLabel writerLabel;
88
89
        public SelectVersionPanel(){
90
                initComponents();
91
                initLabels();
92
                initCombos();
93
        }
94
95
        /**
96
         * Initializes all the components
97
         */
98
        private void initComponents() {
99
                setLayout(new java.awt.BorderLayout());
100
                add(getComponentsPanel(), java.awt.BorderLayout.CENTER);
101
                add(getButtonsPanel(), java.awt.BorderLayout.SOUTH);
102
        }
103
104
        /**
105
         * Initializes all the labels
106
         */
107
        private void initLabels(){
108
                //Labels
109
                fileLabel.setText(PluginServices.getText(this, "gpe_select_file") + ":");
110
                formatLabel.setText(PluginServices.getText(this, "gpe_select_format") + ":");
111
                writerLabel.setText(PluginServices.getText(this, "gpe_select_writer") + ":");
112
                schemaLabel.setText(PluginServices.getText(this, "gpe_select_schema") + ":");
113
                schemaCheck.setText(PluginServices.getText(this, "gpe_create_default_schema"));
114
                //Combo colors
115
                formatCombo.setBackground(Color.WHITE);
116
                writerCombo.setBackground(Color.WHITE);
117
                //Buttons
118
                cancelButton.setText(PluginServices.getText(this, "cancel"));
119
                exportButton.setText(PluginServices.getText(this, "export"));
120
                //images
121
                fileButton.setText(null);
122
                schemaButton.setText(null);
123
                try{
124
                        fileButton.setIcon(new ImageIcon(View.class.getClassLoader().getResource("images/open.png")));
125
                        schemaButton.setIcon(new ImageIcon(View.class.getClassLoader().getResource("images/open.png")));
126
                }catch(NullPointerException exception){
127
                        fileButton.setText("...");
128
                        schemaButton.setText("...");
129
                }
130
                setSchemaEnabled(true);
131
        }
132
133
        /**
134
         * removes all the items
135
         */
136
        private void initCombos(){
137
                formatCombo.removeAllItems();
138
                writerCombo.removeAllItems();
139
        }
140
141
        /**
142
         * removes all the items
143
         */
144
        public void initializeSelection(){
145
                formatCombo.removeAllItems();
146
        }
147
148
        /**
149
         * Sets the listener for the buttons
150
         * @param listener
151
         * The listener to set
152
         */
153
        public void addListener(SelectVersionListener listener){
154
                cancelButton.setActionCommand(listener.CANCEL_BUTTON);
155
                cancelButton.addActionListener(listener);
156
                exportButton.setActionCommand(listener.EXPORT_BUTTON);
157
                exportButton.addActionListener(listener);
158
                writerCombo.setActionCommand(listener.WRITER_COMBO);
159
                writerCombo.addActionListener(listener);
160
                fileButton.setActionCommand(listener.FILE_BUTTON);
161
                fileButton.addActionListener(listener);
162
                schemaButton.setActionCommand(listener.SCHEMA_BUTTON);
163
                schemaButton.addActionListener(listener);
164
                schemaCheck.addItemListener(listener);
165
        }
166
167
        /**
168
         * @return the selected writer
169
         */
170
        public GPEWriterHandler getSelectedWriter(){
171
                if (writerCombo.getItemCount() > 0){
172
                        return (GPEWriterHandler)writerCombo.getSelectedItem();
173
                }
174
                return null;
175
        }
176
177
        /**
178
         * @return the selected writer
179
         */
180
        public String getSelectedFile(){
181
                return fileText.getText();
182
        }
183
184
        /**
185
         * @return the selected XML schema
186
         */
187
        public String getSelectedXMLSchema(){
188
                return schemaText.getText();
189
        }
190
191
        /**
192
         * @return the selected format
193
         */
194
        public String getSelectedFormat(){
195
                if (getFormatCombo().getItemCount() > 0){
196
                        return (String)formatCombo.getSelectedItem();
197
                }
198
                return null;
199
        }
200
201
        /**
202
         * Set a XML schema
203
         */
204
        public void setXMLSchema(String schema){
205
                schemaText.setText(schema);
206
        }
207
208
        /**
209
         * Select a format
210
         */
211
        public void setSelectedFormat(String format){
212
                formatCombo.setSelectedItem(format);
213
        }
214
215
        /**
216
         * Sets a file
217
         */
218
        public void setFile(String file){
219
                fileText.setText(file);
220
        }
221
222
        /**
223
         * Adds a new writer
224
         * @param writer
225
         * The writer to add
226
         */
227
        public void addWriter(GPEWriterHandler writer){
228
                writerCombo.addItem(writer);
229
        }
230
231
        /**
232
         * Adds a new format
233
         * @param format
234
         * The format to add
235
         */
236
        public void addFormat(String format){
237
                formatCombo.addItem(format);
238
        }
239
240
        /**
241
         * @return If the XML schema has to be created
242
         */
243
        public boolean isXMLSchemaCreated(){
244
                return schemaCheck.isSelected();
245
        }
246
247
        /**
248
         * Enable or disable the XML schema generation
249
         * @param isEnabled
250
         * If is or not is enabled
251
         */
252
        public void setSchemaEnabled(boolean isEnabled){
253
                getSchemaCheck().setEnabled(isEnabled);
254
                getSchemaCheck().setSelected(isEnabled);
255
                getSchemaButton().setEnabled(isEnabled);
256
                getSchemaText().setEnabled(isEnabled);
257
                if (isEnabled){
258
                        getSchemaText().setText(getDefaultSchema());
259
                }
260
        }
261
262
        /**
263
         * @return the buttonsPanel
264
         */
265
        private JPanel getButtonsPanel() {
266
                if (buttonsPanel == null){
267
                        buttonsPanel = new JPanel();
268
                        buttonsPanel.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
269
                        buttonsPanel.add(getCancelButton());
270
                        buttonsPanel.add(getExportButton());
271
                }
272
                return buttonsPanel;
273
        }
274
275
        /**
276
         * @return the cancelButton
277
         */
278
        private JButton getCancelButton() {
279
                if (cancelButton == null){
280
                        cancelButton = new JButton();
281
                }
282
                return cancelButton;
283
        }
284
285
        /**
286
         * @return the componentsPanel
287
         */
288
        private JPanel getComponentsPanel() {
289
                if (componentsPanel == null){
290
                        componentsPanel = new JPanel();
291
                        componentsPanel.setLayout(new java.awt.GridBagLayout());
292
                        java.awt.GridBagConstraints gridBagConstraints;
293
                        gridBagConstraints = new java.awt.GridBagConstraints();
294
                        gridBagConstraints.gridx = 0;
295
                        gridBagConstraints.gridy = 10;
296
                        gridBagConstraints.gridwidth = 2;
297
                        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
298
                        gridBagConstraints.weightx = 1.0;
299
                        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
300
301
                        gridBagConstraints = new java.awt.GridBagConstraints();
302
                        gridBagConstraints.gridx = 0;
303
                        gridBagConstraints.gridy = 7;
304
                        gridBagConstraints.gridwidth = 2;
305
                        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
306
                        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
307
                        componentsPanel.add(getFormatLabel(), gridBagConstraints);
308
309
                        gridBagConstraints = new java.awt.GridBagConstraints();
310
                        gridBagConstraints.gridx = 0;
311
                        gridBagConstraints.gridy = 8;
312
                        gridBagConstraints.gridwidth = 2;
313
                        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
314
                        gridBagConstraints.weightx = 1.0;
315
                        gridBagConstraints.insets = new java.awt.Insets(2, 2, 5, 2);
316
                        componentsPanel.add(getFormatCombo(), gridBagConstraints);
317
318
                        gridBagConstraints = new java.awt.GridBagConstraints();
319
                        gridBagConstraints.gridx = 0;
320
                        gridBagConstraints.gridy = 9;
321
                        gridBagConstraints.gridwidth = 2;
322
                        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
323
                        gridBagConstraints.insets = new java.awt.Insets(5, 2, 2, 2);
324
325
                        gridBagConstraints = new java.awt.GridBagConstraints();
326
                        gridBagConstraints.gridx = 0;
327
                        gridBagConstraints.gridy = 5;
328
                        gridBagConstraints.gridwidth = 2;
329
                        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
330
                        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
331
                        componentsPanel.add(getWriterLabel(), gridBagConstraints);
332
333
                        gridBagConstraints = new java.awt.GridBagConstraints();
334
                        gridBagConstraints.gridx = 0;
335
                        gridBagConstraints.gridy = 6;
336
                        gridBagConstraints.gridwidth = 2;
337
                        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
338
                        gridBagConstraints.weightx = 1.0;
339
                        gridBagConstraints.insets = new java.awt.Insets(2, 2, 5, 2);
340
                        componentsPanel.add(getWriterCombo(), gridBagConstraints);
341
342
                        gridBagConstraints = new java.awt.GridBagConstraints();
343
                        gridBagConstraints.gridx = 0;
344
                        gridBagConstraints.gridy = 0;
345
                        gridBagConstraints.gridwidth = 2;
346
                        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
347
                        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
348
                        componentsPanel.add(getFileLabel(), gridBagConstraints);
349
350
                        gridBagConstraints = new java.awt.GridBagConstraints();
351
                        gridBagConstraints.gridx = 0;
352
                        gridBagConstraints.gridy = 1;
353
                        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
354
                        gridBagConstraints.weightx = 1.0;
355
                        gridBagConstraints.insets = new java.awt.Insets(2, 2, 5, 2);
356
                        componentsPanel.add(getFileText(), gridBagConstraints);
357
358
                        gridBagConstraints = new java.awt.GridBagConstraints();
359
                        gridBagConstraints.gridx = 1;
360
                        gridBagConstraints.gridy = 1;
361
                        gridBagConstraints.insets = new java.awt.Insets(2, 2, 5, 2);
362
                        componentsPanel.add(getFileButton(), gridBagConstraints);
363
364
                        gridBagConstraints = new java.awt.GridBagConstraints();
365
                        gridBagConstraints.gridx = 0;
366
                        gridBagConstraints.gridy = 2;
367
                        gridBagConstraints.gridwidth = 2;
368
                        gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
369
                        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
370
                        componentsPanel.add(getSchemaLabel(), gridBagConstraints);
371
372
                        gridBagConstraints = new java.awt.GridBagConstraints();
373
                        gridBagConstraints.gridx = 0;
374
                        gridBagConstraints.gridy = 4;
375
                        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
376
                        gridBagConstraints.weightx = 1.0;
377
                        gridBagConstraints.insets = new java.awt.Insets(2, 2, 5, 2);
378
                        componentsPanel.add(getSchemaText(), gridBagConstraints);
379
380
                        gridBagConstraints = new java.awt.GridBagConstraints();
381
                        gridBagConstraints.gridx = 1;
382
                        gridBagConstraints.gridy = 4;
383
                        gridBagConstraints.insets = new java.awt.Insets(2, 2, 5, 2);
384
                        componentsPanel.add(getSchemaButton(), gridBagConstraints);
385
386
                        gridBagConstraints = new java.awt.GridBagConstraints();
387
                        gridBagConstraints.gridx = 0;
388
                        gridBagConstraints.gridy = 3;
389
                        gridBagConstraints.gridwidth = 2;
390
                        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
391
                        gridBagConstraints.weightx = 1.0;
392
                        gridBagConstraints.insets = new java.awt.Insets(2, 2, 2, 2);
393
                        componentsPanel.add(getSchemaCheck(), gridBagConstraints);
394
                }
395
                return componentsPanel;
396
        }
397
398
        /**
399
         * @return the exportButton
400
         */
401
        private JButton getExportButton() {
402
                if (exportButton == null){
403
                        exportButton = new JButton();
404
                }
405
                return exportButton;
406
        }
407
408
        /**
409
         * @return the fileButton
410
         */
411
        private javax.swing.JButton getFileButton() {
412
                if (fileButton == null){
413
                        fileButton = new javax.swing.JButton();
414
                        fileButton.setMaximumSize(new java.awt.Dimension(25, 25));
415
                        fileButton.setMinimumSize(new java.awt.Dimension(25, 25));
416
                        fileButton.setPreferredSize(new java.awt.Dimension(25, 25));
417
                }
418
                return fileButton;
419
        }
420
421
        /**
422
         * @return the fileLabel
423
         */
424
        private JLabel getFileLabel() {
425
                if (fileLabel == null){
426
                        fileLabel = new JLabel();
427
                }
428
                return fileLabel;
429
        }
430
431
        /**
432
         * @return the fileText
433
         */
434
        private JTextField getFileText() {
435
                if (fileText == null){
436
                        fileText = new JTextField();
437
                        fileText.setText(getDefaultFileName());
438
                }
439
                return fileText;
440
        }
441
442
        /**
443
         * @return the formatCombo
444
         */
445
        private JComboBox getFormatCombo() {
446
                if (formatCombo == null){
447
                        formatCombo = new JComboBox();
448
                }
449
                return formatCombo;
450
        }
451
452
        /**
453
         * @return the formatLabel
454
         */
455
        private JLabel getFormatLabel() {
456
                if (formatLabel == null){
457
                        formatLabel = new JLabel();
458
                }
459
                return formatLabel;
460
        }
461
462
        /**
463
         * @return the schemaButton
464
         */
465
        private javax.swing.JButton getSchemaButton() {
466
                if (schemaButton == null){
467
                        schemaButton = new javax.swing.JButton();
468
                        schemaButton.setPreferredSize(new java.awt.Dimension(25, 25));
469
                }
470
                return schemaButton;
471
        }
472
473
        /**
474
         * @return the schemaCheck
475
         */
476
        private JCheckBox getSchemaCheck() {
477
                if (schemaCheck == null){
478
                        schemaCheck = new JCheckBox();
479
                        schemaCheck.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
480
                        schemaCheck.setMargin(new java.awt.Insets(0, 0, 0, 0));
481
                }
482
                return schemaCheck;
483
        }
484
485
        /**
486
         * @return the schemaLabel
487
         */
488
        private JLabel getSchemaLabel() {
489
                if (schemaLabel == null){
490
                        schemaLabel = new JLabel();
491
                }
492
                return schemaLabel;
493
        }
494
495
        /**
496
         * @return the schemaText
497
         */
498
        private JTextField getSchemaText() {
499
                if (schemaText == null){
500
                        schemaText = new JTextField();
501
                }
502
                return schemaText;
503
        }
504
505
        /**
506
         * @return the writerCombo
507
         */
508
        private JComboBox getWriterCombo() {
509
                if (writerCombo == null){
510
                        writerCombo = new JComboBox();
511
                }
512
                return writerCombo;
513
        }
514
515
        /**
516
         * @return the writerLabel
517
         */
518
        private JLabel getWriterLabel() {
519
                if (writerLabel == null){
520
                        writerLabel = new JLabel();
521
                }
522
                return writerLabel;
523
        }
524
525
        /**
526
         * @return the defaultFile
527
         */
528
        public String getDefaultFileName() {
529
                if (getSelectedFormat() != null){
530
                        return defaultDir + defaultFile + "." + getSelectedWriter().getFileExtension().toLowerCase();
531
                }else{
532
                        return defaultDir + defaultFile;
533
                }
534
        }
535
536
        /**
537
         * @return the defaultSchema
538
         */
539
        private String getDefaultSchema() {
540
                String sFile = getSelectedFile();
541
                if (sFile.length() > 0){
542
                        File file = new File(sFile);
543
                        String extension = FileUtils.getFileExtension(file);
544
                        sFile = sFile.substring(0, sFile.length() - extension.length());
545
                        sFile = sFile + ".xsd";
546
                        return sFile;
547
                }else{
548
                        return defaultDir + defaultFile + ".xsd";
549
                }
550
        }
551
}