Statistics
| Revision:

svn-gvsig-desktop / branches / v2_0_0_prep / extensions / org.gvsig.installer / org.gvsig.installer.swing / org.gvsig.installer.swing.impl / src / main / java / org / gvsig / installer / swing / impl / creation / panel / DefaultOutputPanel.java @ 37590

History | View | Annotate | Download (7.17 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
 * 2010 {Prodevelop}   {Task}
26
 */
27

    
28
package org.gvsig.installer.swing.impl.creation.panel;
29

    
30
import java.awt.BorderLayout;
31
import java.awt.GridBagConstraints;
32
import java.awt.GridBagLayout;
33
import java.awt.event.ActionEvent;
34
import java.awt.event.ActionListener;
35
import java.io.File;
36
import java.net.MalformedURLException;
37
import java.net.URL;
38

    
39
import javax.swing.JCheckBox;
40
import javax.swing.JLabel;
41
import javax.swing.JOptionPane;
42
import javax.swing.JPanel;
43
import javax.swing.JTextField;
44

    
45
import org.slf4j.Logger;
46
import org.slf4j.LoggerFactory;
47

    
48
import org.gvsig.gui.beans.openfile.FileTextField;
49
import org.gvsig.installer.swing.api.SwingInstallerLocator;
50
import org.gvsig.installer.swing.api.creation.JOutputPanel;
51
import org.gvsig.installer.swing.impl.DefaultSwingInstallerManager;
52

    
53
/**
54
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodr&aacute;</a>
55
 */
56
public class DefaultOutputPanel extends JOutputPanel {
57

    
58
        private static final Logger LOG = LoggerFactory
59
                        .getLogger(DefaultOutputPanel.class);
60
        private static final long serialVersionUID = 1219577194134960697L;
61

    
62
        protected DefaultSwingInstallerManager swingInstallerManager = null;
63
        private JLabel fileLabel;
64
        protected FileTextField fileTextField;
65
        private JLabel createPackageIndexLabel;
66
        private JCheckBox createPackageIndexCheckBox;
67
        private JLabel packageURLLabel;
68
        protected JTextField packageURLTextField;
69
        private JLabel indexFileLabel;
70
        protected FileTextField indexFileTextField;
71
        private javax.swing.JPanel northPanel;
72

    
73
        public DefaultOutputPanel() {
74
                super();
75
                swingInstallerManager = (DefaultSwingInstallerManager) SwingInstallerLocator
76
                                .getSwingInstallerManager();
77
                initComponents();
78
        }
79

    
80
        private void initComponents() {
81
                GridBagConstraints gridBagConstraints;
82

    
83
                northPanel = new JPanel();
84
                fileLabel = new JLabel(swingInstallerManager.getText("package_file")
85
                                + ":");
86
                fileTextField = new FileTextField("package.file");
87
                indexFileLabel = new JLabel(swingInstallerManager
88
                                .getText("package_index_file")
89
                                + ":");
90

    
91
                packageURLLabel = new JLabel(swingInstallerManager
92
                                .getText("download_url")
93
                                + ":");
94
                packageURLTextField = new JTextField();
95
                packageURLTextField.setEnabled(false);
96

    
97
                indexFileTextField = new FileTextField("package.index.file");
98
                indexFileTextField.setEnabled(false);
99
                createPackageIndexLabel = new JLabel(swingInstallerManager
100
                                .getText("create_package_index")
101
                                + ":");
102
                createPackageIndexCheckBox = new JCheckBox();
103
                createPackageIndexCheckBox.addActionListener(new ActionListener() {
104

    
105
                        public void actionPerformed(ActionEvent e) {
106
                                if (createPackageIndexCheckBox.isSelected()) {
107
                                        packageURLTextField.setEnabled(true);
108
                                        indexFileTextField.setEnabled(true);
109
                                } else {
110
                                        packageURLTextField.setEnabled(false);
111
                                        indexFileTextField.setEnabled(false);
112
                                }
113

    
114
                        }
115
                });
116

    
117
                setLayout(new BorderLayout());
118

    
119
                northPanel.setLayout(new GridBagLayout());
120

    
121
                // Package file
122
                gridBagConstraints = new GridBagConstraints();
123
                gridBagConstraints.gridx = 0;
124
                gridBagConstraints.gridy = 0;
125
                gridBagConstraints.anchor = GridBagConstraints.EAST;
126
                northPanel.add(fileLabel, gridBagConstraints);
127

    
128
                gridBagConstraints.gridx = 1;
129
                gridBagConstraints.gridy = 0;
130
                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
131
                gridBagConstraints.weightx = 1.0;
132
                gridBagConstraints.anchor = GridBagConstraints.WEST;
133
                northPanel.add(fileTextField, gridBagConstraints);
134

    
135
                // Package index check
136
                gridBagConstraints = new GridBagConstraints();
137
                gridBagConstraints.gridx = 0;
138
                gridBagConstraints.gridy = 1;
139
                gridBagConstraints.anchor = GridBagConstraints.EAST;
140
                northPanel.add(createPackageIndexLabel, gridBagConstraints);
141

    
142
                gridBagConstraints.gridx = 1;
143
                gridBagConstraints.gridy = 1;
144
                gridBagConstraints.anchor = GridBagConstraints.WEST;
145
                createPackageIndexCheckBox.setAlignmentX(LEFT_ALIGNMENT);
146
                northPanel.add(createPackageIndexCheckBox, gridBagConstraints);
147

    
148
                // Package download URL
149
                gridBagConstraints = new GridBagConstraints();
150
                gridBagConstraints.gridx = 0;
151
                gridBagConstraints.gridy = 2;
152
                gridBagConstraints.anchor = GridBagConstraints.EAST;
153
                northPanel.add(packageURLLabel, gridBagConstraints);
154

    
155
                gridBagConstraints.gridx = 1;
156
                gridBagConstraints.gridy = 2;
157
                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
158
                gridBagConstraints.weightx = 1.0;
159
                gridBagConstraints.anchor = GridBagConstraints.WEST;
160
                northPanel.add(packageURLTextField, gridBagConstraints);
161

    
162
                // Package index file
163
                gridBagConstraints = new GridBagConstraints();
164
                gridBagConstraints.gridx = 0;
165
                gridBagConstraints.gridy = 3;
166
                gridBagConstraints.anchor = GridBagConstraints.EAST;
167
                northPanel.add(indexFileLabel, gridBagConstraints);
168

    
169
                gridBagConstraints.gridx = 1;
170
                gridBagConstraints.gridy = 3;
171
                gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
172
                gridBagConstraints.weightx = 1.0;
173
                gridBagConstraints.anchor = GridBagConstraints.WEST;
174
                northPanel.add(indexFileTextField, gridBagConstraints);
175

    
176
                add(northPanel, BorderLayout.NORTH);
177
        }
178

    
179
        @Override
180
        public File getPackageFile() {
181
                return fileTextField.getSelectedFile();
182
        }
183

    
184
        @Override
185
        public void setPackageFile(File selectedFile) {
186
                fileTextField.setSelectedFile(selectedFile);
187
        }
188

    
189
        @Override
190
        public boolean isCreatePackageIndex() {
191
                return createPackageIndexCheckBox.isSelected();
192
        }
193

    
194
        @Override
195
        public void setCreatePackageIndex(boolean create) {
196
                createPackageIndexCheckBox.setSelected(create);
197
        }
198

    
199
        @Override
200
        public File getPackageIndexFile() {
201
                if (isCreatePackageIndex()) {
202
                        return indexFileTextField.getSelectedFile();
203
                } else {
204
                        return null;
205
                }
206
        }
207

    
208
        @Override
209
        public void setPackageIndexFile(File selectedIndexFile) {
210
                indexFileTextField.setSelectedFile(selectedIndexFile);
211
        }
212

    
213
        @Override
214
        public URL getDownloadURL() {
215
                if (isCreatePackageIndex()) {
216
                        try {
217
                                return new URL(packageURLTextField.getText());
218
                        } catch (MalformedURLException e) {
219
                                LOG.info("Invalid download URL: "
220
                                                + packageURLTextField.getText(), e);
221
                                JOptionPane.showMessageDialog(null, swingInstallerManager
222
                                                .getText("Invalid download URL: "
223
                                                                + packageURLTextField.getText()));
224
                                return null;
225
                        }
226
                } else {
227
                        return null;
228
                }
229
        }
230

    
231
        // public String getDownloadURL() {
232
        // return packageURLTextField.getText();
233
        // }
234

    
235
        @Override
236
        public void setDownloadURL(URL downloadURL) {
237
                packageURLTextField.setText(downloadURL.toString());
238
        }
239
}