1 | /*
|
---|
2 | Launch4j (http://launch4j.sourceforge.net/)
|
---|
3 | Cross-platform Java application wrapper for creating Windows native executables.
|
---|
4 |
|
---|
5 | Copyright (C) 2004, 2006 Grzegorz Kowal
|
---|
6 |
|
---|
7 | This program is free software; you can redistribute it and/or modify
|
---|
8 | it under the terms of the GNU General Public License as published by
|
---|
9 | the Free Software Foundation; either version 2 of the License, or
|
---|
10 | (at your option) any later version.
|
---|
11 |
|
---|
12 | This program is distributed in the hope that it will be useful,
|
---|
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | GNU General Public License for more details.
|
---|
16 |
|
---|
17 | You should have received a copy of the GNU General Public License
|
---|
18 | along with this program; if not, write to the Free Software
|
---|
19 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
---|
20 | */
|
---|
21 |
|
---|
22 | /*
|
---|
23 | * Created on May 10, 2005
|
---|
24 | */
|
---|
25 | package net.sf.launch4j.formimpl;
|
---|
26 |
|
---|
27 | import java.awt.Color;
|
---|
28 | import java.awt.event.ActionEvent;
|
---|
29 | import java.awt.event.ActionListener;
|
---|
30 | import java.io.File;
|
---|
31 |
|
---|
32 | import javax.swing.JFileChooser;
|
---|
33 | import javax.swing.JRadioButton;
|
---|
34 | import javax.swing.JTextArea;
|
---|
35 | import javax.swing.JTextField;
|
---|
36 | import javax.swing.event.ChangeEvent;
|
---|
37 | import javax.swing.event.ChangeListener;
|
---|
38 |
|
---|
39 | import net.sf.launch4j.FileChooserFilter;
|
---|
40 | import net.sf.launch4j.binding.Binding;
|
---|
41 | import net.sf.launch4j.binding.Bindings;
|
---|
42 | import net.sf.launch4j.binding.IValidatable;
|
---|
43 | import net.sf.launch4j.binding.Validator;
|
---|
44 | import net.sf.launch4j.config.Config;
|
---|
45 | import net.sf.launch4j.config.ConfigPersister;
|
---|
46 | import net.sf.launch4j.config.Splash;
|
---|
47 | import net.sf.launch4j.config.VersionInfo;
|
---|
48 | import net.sf.launch4j.form.ConfigForm;
|
---|
49 |
|
---|
50 | /**
|
---|
51 | * @author Copyright (C) 2005 Grzegorz Kowal
|
---|
52 | */
|
---|
53 | public class ConfigFormImpl extends ConfigForm {
|
---|
54 | private final JFileChooser _fileChooser = new JFileChooser();
|
---|
55 | private final Bindings _bindings = new Bindings();
|
---|
56 |
|
---|
57 | public ConfigFormImpl() {
|
---|
58 | _tab.setTitleAt(0, Messages.getString("tab.basic"));
|
---|
59 | _tab.setTitleAt(1, Messages.getString("tab.header"));
|
---|
60 | _tab.setTitleAt(2, Messages.getString("tab.jre"));
|
---|
61 | _tab.setTitleAt(3, Messages.getString("tab.splash"));
|
---|
62 | _tab.setTitleAt(4, Messages.getString("tab.version"));
|
---|
63 |
|
---|
64 | _logSeparator.setText(Messages.getString("log"));
|
---|
65 | _outfileLabel.setText(Messages.getString("outfile"));
|
---|
66 | _outfileField.setToolTipText(Messages.getString("outfileTip"));
|
---|
67 | _errorTitleLabel.setText(Messages.getString("errorTitle"));
|
---|
68 | _errorTitleField.setToolTipText(Messages.getString("errorTitleTip"));
|
---|
69 | _customProcNameCheck.setText(Messages.getString("customProcName"));
|
---|
70 | _stayAliveCheck.setText(Messages.getString("stayAlive"));
|
---|
71 | _iconLabel.setText(Messages.getString("icon"));
|
---|
72 | _iconField.setToolTipText(Messages.getString("iconTip"));
|
---|
73 | _jarLabel.setText(Messages.getString("jar"));
|
---|
74 | _jarField.setToolTipText(Messages.getString("jarTip"));
|
---|
75 | _dontWrapJarCheck.setText(Messages.getString("dontWrapJar"));
|
---|
76 | _jarArgsLabel.setText(Messages.getString("jarArgs"));
|
---|
77 | _jarArgsField.setToolTipText(Messages.getString("jarArgsTip"));
|
---|
78 | _optionsLabel.setText(Messages.getString("options"));
|
---|
79 | _chdirLabel.setText(Messages.getString("chdir"));
|
---|
80 | _chdirField.setToolTipText(Messages.getString("chdirTip"));
|
---|
81 |
|
---|
82 | _headerTypeLabel.setText(Messages.getString("headerType"));
|
---|
83 | _guiHeaderRadio.setText(Messages.getString("gui"));
|
---|
84 | _consoleHeaderRadio.setText(Messages.getString("console"));
|
---|
85 | _headerObjectsCheck.setText(Messages.getString("objectFiles"));
|
---|
86 | _libsCheck.setText(Messages.getString("libs"));
|
---|
87 | _linkerOptionsSeparator.setText(Messages.getString("linkerOptions"));
|
---|
88 | _jrePathLabel.setText(Messages.getString("jrePath"));
|
---|
89 | _jrePathField.setToolTipText(Messages.getString("jrePathTip"));
|
---|
90 | _jreMinLabel.setText(Messages.getString("jreMin"));
|
---|
91 | _jreMaxLabel.setText(Messages.getString("jreMax"));
|
---|
92 | _jvmArgsTextLabel.setText(Messages.getString("jvmArgs"));
|
---|
93 | _jvmArgsTextArea.setToolTipText(Messages.getString("jvmArgsTip"));
|
---|
94 | _initialHeapSizeLabel.setText(Messages.getString("initialHeapSize"));
|
---|
95 | _maxHeapSizeLabel.setText(Messages.getString("maxHeapSize"));
|
---|
96 | _addVarsLabel.setText(Messages.getString("addVariables"));
|
---|
97 | _addVarsLabel.setToolTipText(Messages.getString("addVariablesTip"));
|
---|
98 | _exeDirRadio.setToolTipText(Messages.getString("exeDirVarTip"));
|
---|
99 | _exeFileRadio.setToolTipText(Messages.getString("exeFileVarTip"));
|
---|
100 | _otherVarRadio.setText(Messages.getString("other"));
|
---|
101 | _otherVarRadio.setToolTipText(Messages.getString("otherTip"));
|
---|
102 | _otherVarField.setToolTipText(Messages.getString("otherVarTip"));
|
---|
103 | _addVarButton.setText(Messages.getString("add"));
|
---|
104 | _addVarButton.setToolTipText(Messages.getString("addVariablesTip"));
|
---|
105 |
|
---|
106 | _splashCheck.setText(Messages.getString("enableSplash"));
|
---|
107 | _splashFileLabel.setText(Messages.getString("splashFile"));
|
---|
108 | _splashFileField.setToolTipText(Messages.getString("splashFileTip"));
|
---|
109 | _waitForWindowLabel.setText(Messages.getString("waitForWindow"));
|
---|
110 | _waitForWindowCheck.setText(Messages.getString("waitForWindowText"));
|
---|
111 | _timeoutLabel.setText(Messages.getString("timeout"));
|
---|
112 | _timeoutField.setToolTipText(Messages.getString("timeoutTip"));
|
---|
113 | _timeoutErrCheck.setText(Messages.getString("timeoutErr"));
|
---|
114 | _timeoutErrCheck.setToolTipText(Messages.getString("timeoutErrTip"));
|
---|
115 |
|
---|
116 | _versionInfoCheck.setText(Messages.getString("addVersionInfo"));
|
---|
117 | _fileVersionLabel.setText(Messages.getString("fileVersion"));
|
---|
118 | _fileVersionField.setToolTipText(Messages.getString("fileVersionTip"));
|
---|
119 | _addVersionInfoSeparator.setText(Messages.getString("additionalInfo"));
|
---|
120 | _productVersionLabel.setText(Messages.getString("productVersion"));
|
---|
121 | _productVersionField.setToolTipText(Messages.getString("productVersionTip"));
|
---|
122 | _fileDescriptionLabel.setText(Messages.getString("fileDescription"));
|
---|
123 | _fileDescriptionField.setToolTipText(Messages.getString("fileDescriptionTip"));
|
---|
124 | _copyrightLabel.setText(Messages.getString("copyright"));
|
---|
125 | _txtFileVersionLabel.setText(Messages.getString("txtFileVersion"));
|
---|
126 | _txtFileVersionField.setToolTipText(Messages.getString("txtFileVersionTip"));
|
---|
127 | _txtProductVersionLabel.setText(Messages.getString("txtProductVersion"));
|
---|
128 | _txtProductVersionField.setToolTipText(Messages.getString("txtProductVersionTip"));
|
---|
129 | _productNameLabel.setText(Messages.getString("productName"));
|
---|
130 | _originalFilenameLabel.setText(Messages.getString("originalFilename"));
|
---|
131 | _originalFilenameField.setToolTipText(Messages.getString("originalFilenameTip"));
|
---|
132 | _internalNameLabel.setText(Messages.getString("internalName"));
|
---|
133 | _internalNameField.setToolTipText(Messages.getString("internalNameTip"));
|
---|
134 | _companyNameLabel.setText(Messages.getString("companyName"));
|
---|
135 |
|
---|
136 | _dontWrapJarCheck.addChangeListener(new DontWrapJarChangeListener());
|
---|
137 |
|
---|
138 | _outfileButton.addActionListener(new BrowseActionListener(
|
---|
139 | _outfileField, new FileChooserFilter("Windows executables (.exe)", ".exe")));
|
---|
140 | _jarButton.addActionListener(new BrowseActionListener(
|
---|
141 | _jarField, new FileChooserFilter("Jar files", ".jar")));
|
---|
142 | _iconButton.addActionListener(new BrowseActionListener(
|
---|
143 | _iconField, new FileChooserFilter("Icon files (.ico)", ".ico")));
|
---|
144 | _splashFileButton.addActionListener(new BrowseActionListener(
|
---|
145 | _splashFileField, new FileChooserFilter("Bitmap files (.bmp)", ".bmp")));
|
---|
146 |
|
---|
147 | ActionListener al = new VariableActionListener();
|
---|
148 | _exeDirRadio.addActionListener(al);
|
---|
149 | _exeFileRadio.addActionListener(al);
|
---|
150 | _otherVarRadio.addActionListener(al);
|
---|
151 | _exeDirRadio.setSelected(true);
|
---|
152 | al.actionPerformed(null);
|
---|
153 | _addVarButton.addActionListener(new AddVariableActionListener());
|
---|
154 |
|
---|
155 | _guiHeaderRadio.addChangeListener(new HeaderTypeChangeListener());
|
---|
156 | _headerObjectsCheck.addActionListener(new HeaderObjectsActionListener());
|
---|
157 | _libsCheck.addActionListener(new LibsActionListener());
|
---|
158 |
|
---|
159 | _bindings.add("outfile", _outfileField)
|
---|
160 | .add("dontWrapJar", _dontWrapJarCheck)
|
---|
161 | .add("jar", _jarField)
|
---|
162 | .add("icon", _iconField)
|
---|
163 | .add("jarArgs", _jarArgsField)
|
---|
164 | .add("errTitle", _errorTitleField)
|
---|
165 | .add("chdir", _chdirField)
|
---|
166 | .add("customProcName", _customProcNameCheck)
|
---|
167 | .add("stayAlive", _stayAliveCheck)
|
---|
168 | .add("headerType", new JRadioButton[] {_guiHeaderRadio, _consoleHeaderRadio})
|
---|
169 | .add("headerObjects", "customHeaderObjects", _headerObjectsCheck, _headerObjectsTextArea)
|
---|
170 | .add("libs", "customLibs", _libsCheck, _libsTextArea)
|
---|
171 | .add("jre.path", _jrePathField)
|
---|
172 | .add("jre.minVersion", _jreMinField)
|
---|
173 | .add("jre.maxVersion", _jreMaxField)
|
---|
174 | .add("jre.initialHeapSize", _initialHeapSizeField)
|
---|
175 | .add("jre.maxHeapSize", _maxHeapSizeField)
|
---|
176 | .add("jre.args", _jvmArgsTextArea)
|
---|
177 | .addOptComponent("splash", Splash.class, _splashCheck)
|
---|
178 | .add("splash.file", _splashFileField)
|
---|
179 | .add("splash.waitForWindow", _waitForWindowCheck, true)
|
---|
180 | .add("splash.timeout", _timeoutField, "60")
|
---|
181 | .add("splash.timeoutErr", _timeoutErrCheck, true)
|
---|
182 | .addOptComponent("versionInfo", VersionInfo.class, _versionInfoCheck)
|
---|
183 | .add("versionInfo.fileVersion", _fileVersionField)
|
---|
184 | .add("versionInfo.productVersion", _productVersionField)
|
---|
185 | .add("versionInfo.fileDescription", _fileDescriptionField)
|
---|
186 | .add("versionInfo.internalName", _internalNameField)
|
---|
187 | .add("versionInfo.originalFilename", _originalFilenameField)
|
---|
188 | .add("versionInfo.productName", _productNameField)
|
---|
189 | .add("versionInfo.txtFileVersion", _txtFileVersionField)
|
---|
190 | .add("versionInfo.txtProductVersion", _txtProductVersionField)
|
---|
191 | .add("versionInfo.companyName", _companyNameField)
|
---|
192 | .add("versionInfo.copyright", _copyrightField);
|
---|
193 | }
|
---|
194 |
|
---|
195 | private class DontWrapJarChangeListener implements ChangeListener {
|
---|
196 | public void stateChanged(ChangeEvent e) {
|
---|
197 | boolean dontWrap = _dontWrapJarCheck.isSelected();
|
---|
198 | _jarLabel.setText(dontWrap ? Messages.getString("jarPath")
|
---|
199 | : Messages.getString("jar"));
|
---|
200 | _jarField.setToolTipText(dontWrap ? Messages.getString("jarPathTip")
|
---|
201 | : Messages.getString("jarTip"));
|
---|
202 | _jarButton.setEnabled(!dontWrap);
|
---|
203 | }
|
---|
204 | }
|
---|
205 |
|
---|
206 | private class BrowseActionListener implements ActionListener {
|
---|
207 | private final JTextField _field;
|
---|
208 | private final FileChooserFilter _filter;
|
---|
209 |
|
---|
210 | public BrowseActionListener(JTextField field, FileChooserFilter filter) {
|
---|
211 | _field = field;
|
---|
212 | _filter = filter;
|
---|
213 | }
|
---|
214 |
|
---|
215 | public void actionPerformed(ActionEvent e) {
|
---|
216 | if (!_field.isEnabled()) {
|
---|
217 | return;
|
---|
218 | }
|
---|
219 | _fileChooser.setFileFilter(_filter);
|
---|
220 | _fileChooser.setSelectedFile(new File(""));
|
---|
221 | int result = _field.equals(_outfileField)
|
---|
222 | ? _fileChooser.showSaveDialog(MainFrame.getInstance())
|
---|
223 | : _fileChooser.showOpenDialog(MainFrame.getInstance());
|
---|
224 | if (result == JFileChooser.APPROVE_OPTION) {
|
---|
225 | _field.setText(_fileChooser.getSelectedFile().getPath());
|
---|
226 | }
|
---|
227 | }
|
---|
228 | }
|
---|
229 |
|
---|
230 | private class HeaderTypeChangeListener implements ChangeListener {
|
---|
231 | public void stateChanged(ChangeEvent e) {
|
---|
232 | Config c = ConfigPersister.getInstance().getConfig();
|
---|
233 | c.setHeaderType(_guiHeaderRadio.isSelected() ? Config.GUI_HEADER : Config.CONSOLE_HEADER);
|
---|
234 | if (!_headerObjectsCheck.isSelected()) {
|
---|
235 | Binding b = getBinding("headerObjects");
|
---|
236 | b.put(c);
|
---|
237 | }
|
---|
238 | }
|
---|
239 | }
|
---|
240 |
|
---|
241 | private class HeaderObjectsActionListener implements ActionListener {
|
---|
242 | public void actionPerformed(ActionEvent e) {
|
---|
243 | if (!_headerObjectsCheck.isSelected()) {
|
---|
244 | ConfigPersister.getInstance().getConfig().setHeaderObjects(null);
|
---|
245 | Binding b = getBinding("headerObjects");
|
---|
246 | b.put(ConfigPersister.getInstance().getConfig());
|
---|
247 | }
|
---|
248 | }
|
---|
249 | }
|
---|
250 |
|
---|
251 | private class LibsActionListener implements ActionListener {
|
---|
252 | public void actionPerformed(ActionEvent e) {
|
---|
253 | if (!_libsCheck.isSelected()) {
|
---|
254 | ConfigPersister.getInstance().getConfig().setLibs(null);
|
---|
255 | Binding b = getBinding("libs");
|
---|
256 | b.put(ConfigPersister.getInstance().getConfig());
|
---|
257 | }
|
---|
258 | }
|
---|
259 | }
|
---|
260 |
|
---|
261 | private class VariableActionListener implements ActionListener {
|
---|
262 | public void actionPerformed(ActionEvent e) {
|
---|
263 | _otherVarField.setEnabled(_otherVarRadio.isSelected());
|
---|
264 | }
|
---|
265 | }
|
---|
266 |
|
---|
267 | private class AddVariableActionListener implements ActionListener {
|
---|
268 | private final Color _validColor = _otherVarField.getBackground();
|
---|
269 |
|
---|
270 | public void actionPerformed(ActionEvent e) {
|
---|
271 | final int pos = _jvmArgsTextArea.getCaretPosition();
|
---|
272 | if (_exeDirRadio.isSelected()) {
|
---|
273 | _jvmArgsTextArea.insert("-Dlaunch4j.exedir=\"%EXEDIR%\"\n", pos);
|
---|
274 | } else if (_exeFileRadio.isSelected()) {
|
---|
275 | _jvmArgsTextArea.insert("-Dlaunch4j.exefile=\"%EXEFILE%\"\n", pos);
|
---|
276 | } else {
|
---|
277 | final String var = _otherVarField.getText()
|
---|
278 | .replaceAll("\"", "")
|
---|
279 | .replaceAll("%", "");
|
---|
280 | if (Validator.isEmpty(var)) {
|
---|
281 | signalViolation("specifyVar");
|
---|
282 | return;
|
---|
283 | }
|
---|
284 | final String prop = var.replaceAll(" ", ".")
|
---|
285 | .replaceAll("_", ".")
|
---|
286 | .toLowerCase();
|
---|
287 | _jvmArgsTextArea.insert("-Denv." + prop + "=\"%" + var + "%\"\n", pos);
|
---|
288 | }
|
---|
289 | }
|
---|
290 |
|
---|
291 | private void signalViolation(String code) {
|
---|
292 | _otherVarField.setBackground(Binding.INVALID_COLOR);
|
---|
293 | MainFrame.getInstance().warn(Messages.getString(code));
|
---|
294 | _otherVarField.setBackground(_validColor);
|
---|
295 | _otherVarField.requestFocusInWindow();
|
---|
296 | }
|
---|
297 | }
|
---|
298 |
|
---|
299 | public void clear(IValidatable bean) {
|
---|
300 | _bindings.clear(bean);
|
---|
301 | }
|
---|
302 |
|
---|
303 | public void put(IValidatable bean) {
|
---|
304 | _bindings.put(bean);
|
---|
305 | }
|
---|
306 |
|
---|
307 | public void get(IValidatable bean) {
|
---|
308 | _bindings.get(bean);
|
---|
309 | }
|
---|
310 |
|
---|
311 | public boolean isModified() {
|
---|
312 | return _bindings.isModified();
|
---|
313 | }
|
---|
314 |
|
---|
315 | public JTextArea getLogTextArea() {
|
---|
316 | return _logTextArea;
|
---|
317 | }
|
---|
318 |
|
---|
319 | public Binding getBinding(String property) {
|
---|
320 | return _bindings.getBinding(property);
|
---|
321 | }
|
---|
322 | }
|
---|