KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > launch4j > formimpl > JreFormImpl


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 1, 2006
24  */

25 package net.sf.launch4j.formimpl;
26
27 import java.awt.event.ActionEvent JavaDoc;
28 import java.awt.event.ActionListener JavaDoc;
29
30 import javax.swing.DefaultComboBoxModel JavaDoc;
31 import javax.swing.JFileChooser JavaDoc;
32 import javax.swing.JTextField JavaDoc;
33
34 import net.sf.launch4j.binding.Bindings;
35 import net.sf.launch4j.binding.Validator;
36 import net.sf.launch4j.form.JreForm;
37
38 /**
39  * @author Copyright (C) 2006 Grzegorz Kowal
40  */

41 public class JreFormImpl extends JreForm {
42
43     public JreFormImpl(Bindings bindings, JFileChooser JavaDoc fc) {
44         bindings .add("jre.path", _jrePathField)
45                 .add("jre.minVersion", _jreMinField)
46                 .add("jre.maxVersion", _jreMaxField)
47                 .add("jre.dontUsePrivateJres", _dontUsePrivateJresCheck)
48                 .add("jre.initialHeapSize", _initialHeapSizeField)
49                 .add("jre.maxHeapSize", _maxHeapSizeField)
50                 .add("jre.options", _jvmOptionsTextArea);
51
52         _varCombo.setModel(new DefaultComboBoxModel JavaDoc(new String JavaDoc[] {
53                 "EXEDIR", "EXEFILE", "PWD", "OLDPWD",
54                 "HKEY_CLASSES_ROOT", "HKEY_CURRENT_USER", "HKEY_LOCAL_MACHINE",
55                 "HKEY_USERS", "HKEY_CURRENT_CONFIG" }));
56
57         _varCombo.addActionListener(new VarComboActionListener());
58         _varCombo.setSelectedIndex(0);
59
60         _propertyButton.addActionListener(new PropertyActionListener());
61         _optionButton.addActionListener(new OptionActionListener());
62
63         _envPropertyButton.addActionListener(new EnvPropertyActionListener(_envVarField));
64         _envOptionButton.addActionListener(new EnvOptionActionListener(_envVarField));
65     }
66
67     private class VarComboActionListener implements ActionListener JavaDoc {
68         public void actionPerformed(ActionEvent JavaDoc e) {
69             _optionButton.setEnabled(((String JavaDoc) _varCombo.getSelectedItem())
70                     .startsWith("HKEY_"));
71         }
72     }
73
74     private class PropertyActionListener implements ActionListener JavaDoc {
75         public void actionPerformed(ActionEvent JavaDoc e) {
76             final int pos = _jvmOptionsTextArea.getCaretPosition();
77             final String JavaDoc var = (String JavaDoc) _varCombo.getSelectedItem();
78             if (var.startsWith("HKEY_")) {
79                 _jvmOptionsTextArea.insert("-Dreg.key=\"%"
80                         + var + "\\\\...%\"\n", pos);
81             } else {
82                 _jvmOptionsTextArea.insert("-Dlaunch4j." + var.toLowerCase()
83                         + "=\"%" + var + "%\"\n", pos);
84             }
85         }
86     }
87
88     private class OptionActionListener implements ActionListener JavaDoc {
89         public void actionPerformed(ActionEvent JavaDoc e) {
90             final int pos = _jvmOptionsTextArea.getCaretPosition();
91             final String JavaDoc var = (String JavaDoc) _varCombo.getSelectedItem();
92             if (var.startsWith("HKEY_")) {
93                 _jvmOptionsTextArea.insert("%" + var + "\\\\...%\n", pos);
94             } else {
95                 _jvmOptionsTextArea.insert("%" + var + "%\n", pos);
96             }
97         }
98     }
99
100     private abstract class EnvActionListener extends AbstractAcceptListener {
101         public EnvActionListener(JTextField JavaDoc f, boolean listen) {
102             super(f, listen);
103         }
104
105         public void actionPerformed(ActionEvent JavaDoc e) {
106             final int pos = _jvmOptionsTextArea.getCaretPosition();
107             final String JavaDoc var = getText()
108                     .replaceAll("\"", "")
109                     .replaceAll("%", "");
110             if (Validator.isEmpty(var)) {
111                 signalViolation(Messages.getString("specifyVar"));
112                 return;
113             }
114             add(var, pos);
115             clear();
116         }
117
118         protected abstract void add(String JavaDoc var, int pos);
119     }
120
121     private class EnvPropertyActionListener extends EnvActionListener {
122         public EnvPropertyActionListener(JTextField JavaDoc f) {
123             super(f, true);
124         }
125
126         protected void add(String JavaDoc var, int pos) {
127             final String JavaDoc prop = var
128                     .replaceAll(" ", ".")
129                     .replaceAll("_", ".")
130                     .toLowerCase();
131             _jvmOptionsTextArea.insert("-Denv." + prop + "=\"%" + var
132                     + "%\"\n", pos);
133         }
134     }
135
136     private class EnvOptionActionListener extends EnvActionListener {
137         public EnvOptionActionListener(JTextField JavaDoc f) {
138             super(f, false);
139         }
140
141         protected void add(String JavaDoc var, int pos) {
142             _jvmOptionsTextArea.insert("%" + var + "%\n", pos);
143         }
144     }
145 }
146
Popular Tags