Revision 37574 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

View differences:

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

  
60
    /**
60
	/**
61 61
     * 
62 62
     */
63
    private static final long serialVersionUID = -6580729307001414868L;
64
    protected DefaultSwingInstallerManager swingInstallerManager = null;
65
    private JRadioButton fileRadioButton;
66
    private ButtonGroup buttonGroup;
67
    private JPanel northPanel;
68
    private FileTextField selectFileText;
69
    private JRadioButton standardRadioButton;
70
    private JComboBox downloadURL;
71
    private JRadioButton urlRadioButton;
72
    private final List<URL> defaultDownloadURL;
63
	private static final long serialVersionUID = -6580729307001414868L;
64
	protected DefaultSwingInstallerManager swingInstallerManager = null;
65
	private JRadioButton fileRadioButton;
66
	private ButtonGroup buttonGroup;
67
	private JPanel northPanel;
68
	private FileTextField selectFileText;
69
	private JRadioButton standardRadioButton;
70
	private JComboBox downloadURL;
71
	private JRadioButton urlRadioButton;
72
	private final List<URL> defaultDownloadURL;
73 73

  
74
    public SelectBundlesPanel(List<URL> defaultDownloadURL) {
75
        super();
76
        this.defaultDownloadURL = defaultDownloadURL;
77
        swingInstallerManager =
78
            (DefaultSwingInstallerManager) SwingInstallerLocator
79
                .getSwingInstallerManager();
80
        initComponents();
81
        initListeners();
82
        // Standard installation mode is selected by default
83
        standardRadioButton.setSelected(true);
84
    }
74
	public SelectBundlesPanel(List<URL> defaultDownloadURL) {
75
		super();
76
		this.defaultDownloadURL = defaultDownloadURL;
77
		swingInstallerManager = (DefaultSwingInstallerManager) SwingInstallerLocator
78
				.getSwingInstallerManager();
79
		initComponents();
80
		initListeners();
81
		// Standard installation mode is selected by default
82
		standardRadioButton.setSelected(true);
83
	}
85 84

  
86
    private void initListeners() {
87
        standardRadioButton.addItemListener(this);
88
        fileRadioButton.addItemListener(this);
89
        urlRadioButton.addItemListener(this);
90
        Object obj = selectFileText.getComponent(0);
91
        if ((obj != null) && (obj instanceof JTextField)) {
92
            ((JTextField) obj).getDocument().addDocumentListener(this);
93
        }
94
//        urlText.getDocument().addDocumentListener(this);
95
    }
85
	private void initListeners() {
86
		standardRadioButton.addItemListener(this);
87
		fileRadioButton.addItemListener(this);
88
		urlRadioButton.addItemListener(this);
89
		Object obj = selectFileText.getComponent(0);
90
		if ((obj != null) && (obj instanceof JTextField)) {
91
			((JTextField) obj).getDocument().addDocumentListener(this);
92
		}
93
		// urlText.getDocument().addDocumentListener(this);
94
	}
96 95

  
97
    private void initComponents() {
98
        java.awt.GridBagConstraints gridBagConstraints;
96
	private void initComponents() {
97
		java.awt.GridBagConstraints gridBagConstraints;
99 98

  
100
        northPanel = new JPanel();
101
        standardRadioButton = new JRadioButton();
102
        fileRadioButton = new JRadioButton();
103
        urlRadioButton = new JRadioButton();
104
        selectFileText = new FileTextField();
105
        selectFileText.setFileFilter(new FileFilter() {
99
		northPanel = new JPanel();
100
		standardRadioButton = new JRadioButton();
101
		fileRadioButton = new JRadioButton();
102
		urlRadioButton = new JRadioButton();
103
		selectFileText = new FileTextField();
104
		selectFileText.setFileFilter(new FileFilter() {
106 105

  
107
            private String packageExt =
108
                swingInstallerManager.getInstallerManager()
109
                    .getDefaultPackageFileExtension();
110
            private String packageSetExt =
111
                swingInstallerManager.getInstallerManager()
112
                    .getDefaultPackageSetFileExtension();
113
            private String indexSetExt =
114
                swingInstallerManager.getInstallerManager()
115
                    .getDefaultIndexSetFileExtension();
106
			private String packageExt = swingInstallerManager
107
					.getInstallerManager().getDefaultPackageFileExtension();
108
			private String packageSetExt = swingInstallerManager
109
					.getInstallerManager().getDefaultPackageSetFileExtension();
110
			private String indexSetExt = swingInstallerManager
111
					.getInstallerManager().getDefaultIndexSetFileExtension();
116 112

  
117
            @Override
118
            public String getDescription() {
119
                return "gvSIG packags and package and index sets (*." + packageExt
120
                    + ", *." + packageSetExt + ", *." + indexSetExt + ")";
121
            }
113
			@Override
114
			public String getDescription() {
115
				return "gvSIG packags and package and index sets (*."
116
						+ packageExt + ", *." + packageSetExt + ", *."
117
						+ indexSetExt + ")";
118
			}
122 119

  
123
            @Override
124
            public boolean accept(File file) {
125
                if (file.isFile()) {
126
                    String name = file.getName().toLowerCase();
127
                    return name.endsWith(packageExt)
128
                        || name.endsWith(packageSetExt)
129
                        || name.endsWith(indexSetExt);
130
                }
131
                return true;
132
            }
120
			@Override
121
			public boolean accept(File file) {
122
				if (file.isFile()) {
123
					String name = file.getName().toLowerCase();
124
					return name.endsWith(packageExt)
125
							|| name.endsWith(packageSetExt)
126
							|| name.endsWith(indexSetExt);
127
				}
128
				return true;
129
			}
133 130

  
134
            @Override
135
            public String getDefaultExtension() {
136
                return packageSetExt;
137
            }
138
        });
139
        
140
//        MouseListener l = new MouseListener() {
141
//
142
//            public void mouseClicked(MouseEvent e) {
143
//                System.out.println("Here I am");
144
//                urlRadioButton.setSelected(true);
145
//            }
146
//
147
//            public void mouseEntered(MouseEvent e) {}
148
//            public void mouseExited(MouseEvent e) {}
149
//            public void mousePressed(MouseEvent e) {}
150
//            public void mouseReleased(MouseEvent e) {}
151
//        };
131
			@Override
132
			public String getDefaultExtension() {
133
				return packageSetExt;
134
			}
135
		});
152 136

  
153
        downloadURL = new JComboBox();
154
        downloadURL.setEditable(true);
155
        if (defaultDownloadURL != null) {
156
        	for (int i=0; i<defaultDownloadURL.size(); i++){
137
		downloadURL = new JComboBox();
138
		downloadURL.setEditable(true);
139
		if (defaultDownloadURL != null) {
140
			for (int i = 0; i < defaultDownloadURL.size(); i++) {
157 141
				downloadURL.addItem(defaultDownloadURL.get(i));
158 142
			}
159
        }
160
        
161
//        downloadURL.addMouseListener(l);
162
        
163
        buttonGroup = new ButtonGroup();
143
		}
164 144

  
165
        buttonGroup.add(standardRadioButton);
166
        buttonGroup.add(fileRadioButton);
167
        buttonGroup.add(urlRadioButton);
145
		buttonGroup = new ButtonGroup();
168 146

  
169
        setLayout(new BorderLayout());
147
		buttonGroup.add(standardRadioButton);
148
		buttonGroup.add(fileRadioButton);
149
		buttonGroup.add(urlRadioButton);
170 150

  
171
        northPanel.setLayout(new GridBagLayout());
151
		setLayout(new BorderLayout());
172 152

  
173
        standardRadioButton.setText(swingInstallerManager
174
            .getText("standard_installation"));
175
        gridBagConstraints = new GridBagConstraints();
176
        gridBagConstraints.anchor = GridBagConstraints.WEST;
177
        gridBagConstraints.insets = new Insets(2, 2, 2, 2);
178
        northPanel.add(standardRadioButton, gridBagConstraints);
153
		northPanel.setLayout(new GridBagLayout());
179 154

  
180
        fileRadioButton.setText(swingInstallerManager
181
            .getText("installation_from_file"));
182
        gridBagConstraints = new GridBagConstraints();
183
        gridBagConstraints.gridx = 0;
184
        gridBagConstraints.gridy = 1;
185
        gridBagConstraints.anchor = GridBagConstraints.WEST;
186
        gridBagConstraints.insets = new Insets(2, 2, 2, 2);
187
        northPanel.add(fileRadioButton, gridBagConstraints);
188
        gridBagConstraints = new GridBagConstraints();
189
        gridBagConstraints.gridx = 0;
190
        gridBagConstraints.gridy = 2;
191
        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
192
        gridBagConstraints.weightx = 1.0;
193
        gridBagConstraints.insets = new Insets(2, 20, 2, 2);
194
        northPanel.add(selectFileText, gridBagConstraints);
155
		standardRadioButton.setText(swingInstallerManager
156
				.getText("standard_installation"));
157
		gridBagConstraints = new GridBagConstraints();
158
		gridBagConstraints.anchor = GridBagConstraints.WEST;
159
		gridBagConstraints.insets = new Insets(2, 2, 2, 2);
160
		northPanel.add(standardRadioButton, gridBagConstraints);
195 161

  
196
        urlRadioButton.setText(swingInstallerManager
197
            .getText("installation_from_url"));
198
        gridBagConstraints = new GridBagConstraints();
199
        gridBagConstraints.gridx = 0;
200
        gridBagConstraints.gridy = 3;
201
        gridBagConstraints.anchor = GridBagConstraints.WEST;
202
        gridBagConstraints.insets = new Insets(2, 2, 2, 2);
203
        northPanel.add(urlRadioButton, gridBagConstraints);
204
        gridBagConstraints = new GridBagConstraints();
205
        gridBagConstraints.gridx = 0;
206
        gridBagConstraints.gridy = 4;
207
        gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
208
        gridBagConstraints.weightx = 1.0;
209
        gridBagConstraints.insets = new Insets(2, 20, 2, 2);
210
        northPanel.add(downloadURL, gridBagConstraints);
162
		fileRadioButton.setText(swingInstallerManager
163
				.getText("installation_from_file"));
164
		gridBagConstraints = new GridBagConstraints();
165
		gridBagConstraints.gridx = 0;
166
		gridBagConstraints.gridy = 1;
167
		gridBagConstraints.anchor = GridBagConstraints.WEST;
168
		gridBagConstraints.insets = new Insets(2, 2, 2, 2);
169
		northPanel.add(fileRadioButton, gridBagConstraints);
170
		gridBagConstraints = new GridBagConstraints();
171
		gridBagConstraints.gridx = 0;
172
		gridBagConstraints.gridy = 2;
173
		gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
174
		gridBagConstraints.weightx = 1.0;
175
		gridBagConstraints.insets = new Insets(2, 20, 2, 2);
176
		northPanel.add(selectFileText, gridBagConstraints);
211 177

  
212
        add(northPanel, java.awt.BorderLayout.NORTH);
213
    }
178
		urlRadioButton.setText(swingInstallerManager
179
				.getText("installation_from_url"));
180
		gridBagConstraints = new GridBagConstraints();
181
		gridBagConstraints.gridx = 0;
182
		gridBagConstraints.gridy = 3;
183
		gridBagConstraints.anchor = GridBagConstraints.WEST;
184
		gridBagConstraints.insets = new Insets(2, 2, 2, 2);
185
		northPanel.add(urlRadioButton, gridBagConstraints);
186
		gridBagConstraints = new GridBagConstraints();
187
		gridBagConstraints.gridx = 0;
188
		gridBagConstraints.gridy = 4;
189
		gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
190
		gridBagConstraints.weightx = 1.0;
191
		gridBagConstraints.insets = new Insets(2, 20, 2, 2);
192
		northPanel.add(downloadURL, gridBagConstraints);
214 193

  
215
    public void itemStateChanged(ItemEvent e) {
216
        selectFileText.setEnabled(fileRadioButton.isSelected());
217
        checkNextButtonEnabled();
218
    }
194
		add(northPanel, java.awt.BorderLayout.NORTH);
195
	}
219 196

  
220
    protected File getSelectedFile() {
221
        return selectFileText.getSelectedFile();
222
    }
197
	public void itemStateChanged(ItemEvent e) {
198
		selectFileText.setEnabled(fileRadioButton.isSelected());
199
		checkNextButtonEnabled();
200
	}
223 201

  
224
    protected URL getSelectedURL() throws MalformedURLException {
225
        if (downloadURL.getSelectedItem() instanceof URL) {
226
            return (URL)downloadURL.getSelectedItem();    
227
        } 
228
        return new URL(downloadURL.getSelectedItem().toString());
229
        
230
    }
202
	protected File getSelectedFile() {
203
		return selectFileText.getSelectedFile();
204
	}
231 205

  
232
    protected boolean isStandardSelected() {
233
        return standardRadioButton.isSelected();
234
    }
206
	protected URL getSelectedURL() throws MalformedURLException {
207
		if (downloadURL.getSelectedItem() instanceof URL) {
208
			return (URL) downloadURL.getSelectedItem();
209
		}
210
		return new URL(downloadURL.getSelectedItem().toString());
235 211

  
236
    protected boolean isFileSelected() {
237
        return fileRadioButton.isSelected();
238
    }
212
	}
239 213

  
240
    protected boolean isURLSelected() {
241
        return urlRadioButton.isSelected();
242
    }
214
	protected boolean isStandardSelected() {
215
		return standardRadioButton.isSelected();
216
	}
243 217

  
244
    protected boolean isNextButtonEnabled() {
245
        if (isStandardSelected()) {
246
            return true;
247
        }
248
        if (isFileSelected()) {
249
            File file = selectFileText.getSelectedFile();
250
            if (file == null) {
251
                return false;
252
            }
253
            return file.exists();
254
        }
255
        if (isURLSelected()) {
256
            try {
257
                getSelectedURL();
258
                return true;
259
            } catch (MalformedURLException e) {
260
                return false;
261
            }
262
        }
263
        return false;
264
    }
218
	protected boolean isFileSelected() {
219
		return fileRadioButton.isSelected();
220
	}
265 221

  
266
    protected void checkNextButtonEnabled() {
222
	protected boolean isURLSelected() {
223
		return urlRadioButton.isSelected();
224
	}
267 225

  
268
    }
226
	protected boolean isNextButtonEnabled() {
227
		if (isStandardSelected()) {
228
			return true;
229
		}
230
		if (isFileSelected()) {
231
			File file = selectFileText.getSelectedFile();
232
			if (file == null) {
233
				return false;
234
			}
235
			return file.exists();
236
		}
237
		if (isURLSelected()) {
238
			try {
239
				getSelectedURL();
240
				return true;
241
			} catch (MalformedURLException e) {
242
				return false;
243
			}
244
		}
245
		return false;
246
	}
269 247

  
270
    public void changedUpdate(DocumentEvent e) {
271
        checkNextButtonEnabled();
272
    }
248
	protected void checkNextButtonEnabled() {
273 249

  
274
    public void insertUpdate(DocumentEvent e) {
275
        checkNextButtonEnabled();
276
    }
250
	}
277 251

  
278
    public void removeUpdate(DocumentEvent e) {
279
        checkNextButtonEnabled();
280
    }
252
	public void changedUpdate(DocumentEvent e) {
253
		checkNextButtonEnabled();
254
	}
281 255

  
256
	public void insertUpdate(DocumentEvent e) {
257
		checkNextButtonEnabled();
258
	}
259

  
260
	public void removeUpdate(DocumentEvent e) {
261
		checkNextButtonEnabled();
262
	}
263

  
282 264
}

Also available in: Unified diff