Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.normalization.extension / src / org / gvsig / normalization / preferences / PreferencesNormPanel.java @ 32523

History | View | Annotate | Download (5.12 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

    
23
/*
24
 * AUTHORS (In addition to CIT):
25
 * 2008 Prodevelop S.L. main developer
26
 */
27
package org.gvsig.normalization.preferences;
28

    
29
import java.awt.Component;
30
import java.awt.Dimension;
31
import java.io.File;
32

    
33
import javax.swing.BorderFactory;
34
import javax.swing.JButton;
35
import javax.swing.JFileChooser;
36
import javax.swing.JLabel;
37
import javax.swing.JPanel;
38
import javax.swing.JTextField;
39

    
40
import org.gvsig.andami.PluginServices;
41
import org.slf4j.Logger;
42
import org.slf4j.LoggerFactory;
43

    
44

    
45
/**
46
 * Panel of preferences
47
 * 
48
 * @author <a href="mailto:jsanz@prodevelop.es"> Jorge Gaspar Sanz Salinas</a>
49
 * @author <a href="mailto:vsanjaime@prodevelop.es"> Vicent Sanjaime Calvet</a>
50
 */
51
public class PreferencesNormPanel extends JPanel {
52

    
53
        private static final long serialVersionUID = 1L;
54
        private static final Logger log = LoggerFactory
55
        .getLogger(NormPreferences.class);
56

    
57
        private JButton jButAdd;
58
        private JLabel jLabFile;
59
        private JTextField jTextPath;
60
        private String folder = "";
61

    
62
        /**
63
         * Cnstructor
64
         * 
65
         * @param fol
66
         */
67
        public PreferencesNormPanel(String fol) {
68
                initComponents();
69
                updateLabels();
70
                folder = fol;
71
                setFolderPattern(folder);
72
        }
73

    
74
        /**
75
         * Initialize panel components
76
         */
77
        private void initComponents() {
78
                java.awt.GridBagConstraints gridBagConstraints;
79

    
80
                jLabFile = new javax.swing.JLabel();
81
                jTextPath = new javax.swing.JTextField();
82
                jButAdd = new javax.swing.JButton();
83

    
84
                setLayout(new java.awt.GridBagLayout());
85
                setBorder(javax.swing.BorderFactory
86
                                .createTitledBorder("folder path of normalization patterns"));
87
                setMinimumSize(new Dimension(500, 100));
88

    
89
                jLabFile.setText("path pattern folder");
90
                jLabFile.setMinimumSize(new java.awt.Dimension(200, 20));
91
                gridBagConstraints = new java.awt.GridBagConstraints();
92
                gridBagConstraints.gridx = 0;
93
                gridBagConstraints.gridy = 0;
94
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
95
                gridBagConstraints.weightx = 1.0;
96
                gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
97
                add(jLabFile, gridBagConstraints);
98
                jTextPath.setMinimumSize(new java.awt.Dimension(200, 20));
99
                gridBagConstraints = new java.awt.GridBagConstraints();
100
                gridBagConstraints.gridx = 0;
101
                gridBagConstraints.gridy = 1;
102
                gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
103
                gridBagConstraints.weightx = 1.0;
104
                gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 5);
105
                add(jTextPath, gridBagConstraints);
106

    
107
                jButAdd.setText("Change");
108
                jButAdd.addActionListener(new java.awt.event.ActionListener() {
109
                        public void actionPerformed(java.awt.event.ActionEvent evt) {
110
                                evtChangeFile(evt);
111
                        }
112
                });
113
                gridBagConstraints = new java.awt.GridBagConstraints();
114
                gridBagConstraints.gridx = 1;
115
                gridBagConstraints.gridy = 1;
116
                gridBagConstraints.insets = new java.awt.Insets(5, 0, 5, 5);
117
                add(jButAdd, gridBagConstraints);
118
        }
119

    
120
        /**
121
         * Event of change file
122
         * 
123
         * @param evt
124
         */
125
        private void evtChangeFile(java.awt.event.ActionEvent evt) {
126
                File fol = loadFolder();
127
                if (folder != null) {
128
                        folder = fol.getAbsolutePath();
129
                        setFolderPattern(folder);
130
                } else {
131
                        log.debug("Folder null");
132
                }
133
        }
134

    
135
        /**
136
         * Change the panel string (Internationalization)
137
         */
138
        private void updateLabels() {
139

    
140
                jLabFile.setText(PluginServices.getText(this, "pref_path_folder"));
141
                jButAdd.setText(PluginServices.getText(this, "pref_change_folder"));
142

    
143
                this.setBorder(BorderFactory.createTitledBorder(PluginServices.getText(
144
                                this, "pref_title_folder")));
145
        }
146

    
147
        /**
148
         * Set the file
149
         * 
150
         * @param file
151
         */
152
        public void setFolderPattern(String file) {
153
                jTextPath.setText(file);
154
        }
155

    
156
        /**
157
         * Get the file
158
         * 
159
         * @return
160
         */
161
        public String getFolderPattern() {
162

    
163
                return jTextPath.getText().trim();
164
        }
165

    
166
        /**
167
         * This method loads a folder where you save the Normalization pattern
168
         * 
169
         * @return File folder
170
         */
171
        private File loadFolder() {
172

    
173
                File thefolder = null;
174

    
175
                JFileChooser jfc = new JFileChooser();
176
                jfc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
177
                jfc.setDialogTitle(PluginServices.getText(this, "pref_dialog_forder"));
178

    
179
                int returnval = jfc.showOpenDialog((Component) PluginServices
180
                                .getMainFrame());
181

    
182
                if (returnval == JFileChooser.APPROVE_OPTION) {
183
                        thefolder = jfc.getSelectedFile();
184
                        log.debug("Open folder: " + thefolder.toString());
185
                } else {
186
                        return null;
187
                }
188

    
189
                return thefolder;
190
        }
191

    
192
}