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 @ 33725

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

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

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

    
49
/**
50
 * @author <a href="mailto:jpiera@gvsig.org">Jorge Piera Llodr&aacute;</a>
51
 */
52
public class SelectBundlesPanel extends JPanel implements ItemListener, DocumentListener{
53
        protected DefaultSwingInstallerManager swingInstallerManager = null;
54
        private JRadioButton fileRadioButton;
55
        private ButtonGroup buttonGroup;
56
    private JPanel northPanel;
57
    private FileTextField selectFileText;
58
    private JRadioButton standardRadionButton;
59
    
60
    public SelectBundlesPanel() {
61
                super();
62
                swingInstallerManager = (DefaultSwingInstallerManager)SwingInstallerLocator.getSwingInstallerManager();
63
                initComponents();
64
                initListeners();
65
                standardRadionButton.setSelected(true);
66
        }
67
    
68
    private void initListeners() {
69
                standardRadionButton.addItemListener(this);
70
                fileRadioButton.addItemListener(this);
71
                Object obj = selectFileText.getComponent(0);
72
                if ((obj != null) && (obj instanceof JTextField)) {
73
                        ((JTextField)obj).getDocument().addDocumentListener(this);        
74
                }
75
        }
76

    
77
        private void initComponents() {
78
             java.awt.GridBagConstraints gridBagConstraints;
79

    
80
         northPanel = new JPanel();
81
         standardRadionButton = new JRadioButton();
82
         fileRadioButton = new JRadioButton();
83
         selectFileText = new FileTextField();
84
         buttonGroup = new ButtonGroup();
85
         
86
         buttonGroup.add(standardRadionButton);
87
         buttonGroup.add(fileRadioButton);
88

    
89
         setLayout(new BorderLayout());
90

    
91
         northPanel.setLayout(new GridBagLayout());
92

    
93
         standardRadionButton.setText(swingInstallerManager.getText("standard_installation"));
94
         gridBagConstraints = new GridBagConstraints();
95
         gridBagConstraints.anchor = GridBagConstraints.WEST;
96
         gridBagConstraints.insets = new Insets(2, 2, 2, 2);
97
         northPanel.add(standardRadionButton, gridBagConstraints);
98

    
99
         fileRadioButton.setText(swingInstallerManager.getText("installation_from_file"));
100
         gridBagConstraints = new GridBagConstraints();
101
         gridBagConstraints.gridx = 0;
102
         gridBagConstraints.gridy = 1;
103
         gridBagConstraints.anchor = GridBagConstraints.WEST;
104
         gridBagConstraints.insets = new Insets(2, 2, 2, 2);
105
         northPanel.add(fileRadioButton, gridBagConstraints);
106
         gridBagConstraints = new GridBagConstraints();
107
         gridBagConstraints.gridx = 0;
108
         gridBagConstraints.gridy = 2;
109
         gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
110
         gridBagConstraints.weightx = 1.0;
111
         gridBagConstraints.insets = new Insets(2, 20, 2, 2);
112
         northPanel.add(selectFileText, gridBagConstraints);
113

    
114
         add(northPanel, java.awt.BorderLayout.NORTH);
115
    }
116
        
117
        public void itemStateChanged(ItemEvent e) {
118
                selectFileText.setEnabled(fileRadioButton.isSelected());        
119
                checkNextButtonEnabled();
120
        }
121
        
122
        protected File getSelectedFile(){
123
                return selectFileText.getSelectedFile();
124
        }
125
        
126
        protected boolean isStandardSelected(){
127
                return standardRadionButton.isSelected();
128
        }
129
        
130
        protected boolean isNextButtonEnabled(){
131
                if (isStandardSelected()){
132
                    return true;
133
            }
134
            File file = selectFileText.getSelectedFile();
135
            if (file == null){
136
                    return false;
137
            }
138
                return file.exists();
139
        }
140
        
141
    protected void checkNextButtonEnabled(){
142
            
143
    }
144

    
145
        public void changedUpdate(DocumentEvent e) {
146
                checkNextButtonEnabled();                
147
        }
148

    
149
        public void insertUpdate(DocumentEvent e) {
150
                checkNextButtonEnabled();                        
151
        }
152

    
153
        public void removeUpdate(DocumentEvent e) {
154
                checkNextButtonEnabled();                        
155
        }   
156
    
157
}
158