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 / execution / panel / SelectBundlesPanel.java @ 33982

History | View | Annotate | Download (7 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.execution.panel;
29

    
30
import java.awt.BorderLayout;
31
import java.awt.GridBagConstraints;
32
import java.awt.GridBagLayout;
33
import java.awt.Insets;
34
import java.awt.event.ItemEvent;
35
import java.awt.event.ItemListener;
36
import java.io.File;
37
import java.net.MalformedURLException;
38
import java.net.URL;
39

    
40
import javax.swing.ButtonGroup;
41
import javax.swing.JPanel;
42
import javax.swing.JRadioButton;
43
import javax.swing.JTextField;
44
import javax.swing.event.DocumentEvent;
45
import javax.swing.event.DocumentListener;
46

    
47
import org.gvsig.gui.beans.openfile.FileTextField;
48
import org.gvsig.installer.swing.api.SwingInstallerLocator;
49
import org.gvsig.installer.swing.impl.DefaultSwingInstallerManager;
50

    
51
/**
52
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodr&aacute;</a>
53
 */
54
public class SelectBundlesPanel extends JPanel implements ItemListener,
55
    DocumentListener {
56

    
57
    /**
58
     * 
59
     */
60
    private static final long serialVersionUID = -6580729307001414868L;
61
    protected DefaultSwingInstallerManager swingInstallerManager = null;
62
    private JRadioButton fileRadioButton;
63
    private ButtonGroup buttonGroup;
64
    private JPanel northPanel;
65
    private FileTextField selectFileText;
66
    private JRadioButton standardRadioButton;
67
    private JTextField urlText;
68
    private JRadioButton urlRadioButton;
69

    
70
    public SelectBundlesPanel() {
71
        super();
72
        swingInstallerManager =
73
            (DefaultSwingInstallerManager) SwingInstallerLocator
74
                .getSwingInstallerManager();
75
        initComponents();
76
        initListeners();
77
        standardRadioButton.setSelected(true);
78
    }
79

    
80
    private void initListeners() {
81
        standardRadioButton.addItemListener(this);
82
        fileRadioButton.addItemListener(this);
83
        urlRadioButton.addItemListener(this);
84
        Object obj = selectFileText.getComponent(0);
85
        if ((obj != null) && (obj instanceof JTextField)) {
86
            ((JTextField) obj).getDocument().addDocumentListener(this);
87
        }
88
        urlText.getDocument().addDocumentListener(this);
89
    }
90

    
91
    private void initComponents() {
92
        java.awt.GridBagConstraints gridBagConstraints;
93

    
94
        northPanel = new JPanel();
95
        standardRadioButton = new JRadioButton();
96
        fileRadioButton = new JRadioButton();
97
        urlRadioButton = new JRadioButton();
98
        selectFileText = new FileTextField();
99
        urlText = new JTextField();
100
        buttonGroup = new ButtonGroup();
101

    
102
        buttonGroup.add(standardRadioButton);
103
        buttonGroup.add(fileRadioButton);
104
        buttonGroup.add(urlRadioButton);
105

    
106
        setLayout(new BorderLayout());
107

    
108
        northPanel.setLayout(new GridBagLayout());
109

    
110
        standardRadioButton.setText(swingInstallerManager
111
            .getText("standard_installation"));
112
        gridBagConstraints = new GridBagConstraints();
113
        gridBagConstraints.anchor = GridBagConstraints.WEST;
114
        gridBagConstraints.insets = new Insets(2, 2, 2, 2);
115
        northPanel.add(standardRadioButton, gridBagConstraints);
116

    
117
        fileRadioButton.setText(swingInstallerManager
118
            .getText("installation_from_file"));
119
        gridBagConstraints = new GridBagConstraints();
120
        gridBagConstraints.gridx = 0;
121
        gridBagConstraints.gridy = 1;
122
        gridBagConstraints.anchor = GridBagConstraints.WEST;
123
        gridBagConstraints.insets = new Insets(2, 2, 2, 2);
124
        northPanel.add(fileRadioButton, gridBagConstraints);
125
        gridBagConstraints = new GridBagConstraints();
126
        gridBagConstraints.gridx = 0;
127
        gridBagConstraints.gridy = 2;
128
        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
129
        gridBagConstraints.weightx = 1.0;
130
        gridBagConstraints.insets = new Insets(2, 20, 2, 2);
131
        northPanel.add(selectFileText, gridBagConstraints);
132

    
133
        urlRadioButton.setText(swingInstallerManager
134
            .getText("installation_from_url"));
135
        gridBagConstraints = new GridBagConstraints();
136
        gridBagConstraints.gridx = 0;
137
        gridBagConstraints.gridy = 3;
138
        gridBagConstraints.anchor = GridBagConstraints.WEST;
139
        gridBagConstraints.insets = new Insets(2, 2, 2, 2);
140
        northPanel.add(urlRadioButton, gridBagConstraints);
141
        gridBagConstraints = new GridBagConstraints();
142
        gridBagConstraints.gridx = 0;
143
        gridBagConstraints.gridy = 4;
144
        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
145
        gridBagConstraints.weightx = 1.0;
146
        gridBagConstraints.insets = new Insets(2, 20, 2, 2);
147
        northPanel.add(urlText, gridBagConstraints);
148

    
149
        add(northPanel, java.awt.BorderLayout.NORTH);
150
    }
151

    
152
    public void itemStateChanged(ItemEvent e) {
153
        selectFileText.setEnabled(fileRadioButton.isSelected());
154
        checkNextButtonEnabled();
155
    }
156

    
157
    protected File getSelectedFile() {
158
        return selectFileText.getSelectedFile();
159
    }
160

    
161
    protected URL getSelectedURL() throws MalformedURLException {
162
        return new URL(urlText.getText());
163
    }
164

    
165
    protected boolean isStandardSelected() {
166
        return standardRadioButton.isSelected();
167
    }
168

    
169
    protected boolean isFileSelected() {
170
        return fileRadioButton.isSelected();
171
    }
172

    
173
    protected boolean isURLSelected() {
174
        return urlRadioButton.isSelected();
175
    }
176

    
177
    protected boolean isNextButtonEnabled() {
178
        if (isStandardSelected()) {
179
            return true;
180
        }
181
        if (isFileSelected()) {
182
            File file = selectFileText.getSelectedFile();
183
            if (file == null) {
184
                return false;
185
            }
186
            return file.exists();
187
        }
188
        if (isURLSelected()) {
189
            try {
190
                getSelectedURL();
191
                return true;
192
            } catch (MalformedURLException e) {
193
                return false;
194
            }
195
        }
196
        return false;
197
    }
198

    
199
    protected void checkNextButtonEnabled() {
200

    
201
    }
202

    
203
    public void changedUpdate(DocumentEvent e) {
204
        checkNextButtonEnabled();
205
    }
206

    
207
    public void insertUpdate(DocumentEvent e) {
208
        checkNextButtonEnabled();
209
    }
210

    
211
    public void removeUpdate(DocumentEvent e) {
212
        checkNextButtonEnabled();
213
    }
214

    
215
}