KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > launch4j > form > BasicForm


1 package net.sf.launch4j.form;
2
3 import com.jeta.forms.components.separator.TitledSeparator;
4 import com.jgoodies.forms.layout.CellConstraints;
5 import com.jgoodies.forms.layout.FormLayout;
6 import java.awt.BorderLayout JavaDoc;
7 import java.awt.Container JavaDoc;
8 import java.awt.Dimension JavaDoc;
9 import javax.swing.Box JavaDoc;
10 import javax.swing.ButtonGroup JavaDoc;
11 import javax.swing.ImageIcon JavaDoc;
12 import javax.swing.JButton JavaDoc;
13 import javax.swing.JCheckBox JavaDoc;
14 import javax.swing.JLabel JavaDoc;
15 import javax.swing.JPanel JavaDoc;
16 import javax.swing.JRadioButton JavaDoc;
17 import javax.swing.JTextField JavaDoc;
18
19 public abstract class BasicForm extends JPanel JavaDoc
20 {
21    protected final JButton JavaDoc _outfileButton = new JButton JavaDoc();
22    protected final JLabel JavaDoc _outfileLabel = new JLabel JavaDoc();
23    protected final JLabel JavaDoc _iconLabel = new JLabel JavaDoc();
24    protected final JLabel JavaDoc _jarLabel = new JLabel JavaDoc();
25    protected final JButton JavaDoc _jarButton = new JButton JavaDoc();
26    protected final JButton JavaDoc _iconButton = new JButton JavaDoc();
27    protected final JLabel JavaDoc _cmdLineLabel = new JLabel JavaDoc();
28    protected final JLabel JavaDoc _optionsLabel = new JLabel JavaDoc();
29    protected final JLabel JavaDoc _chdirLabel = new JLabel JavaDoc();
30    protected final JLabel JavaDoc _processPriorityLabel = new JLabel JavaDoc();
31    protected final JRadioButton JavaDoc _normalPriorityRadio = new JRadioButton JavaDoc();
32    protected final ButtonGroup JavaDoc _buttongroup1 = new ButtonGroup JavaDoc();
33    protected final JRadioButton JavaDoc _idlePriorityRadio = new JRadioButton JavaDoc();
34    protected final JRadioButton JavaDoc _highPriorityRadio = new JRadioButton JavaDoc();
35    protected final JCheckBox JavaDoc _customProcNameCheck = new JCheckBox JavaDoc();
36    protected final JCheckBox JavaDoc _stayAliveCheck = new JCheckBox JavaDoc();
37    protected final JTextField JavaDoc _cmdLineField = new JTextField JavaDoc();
38    protected final JTextField JavaDoc _chdirField = new JTextField JavaDoc();
39    protected final JTextField JavaDoc _iconField = new JTextField JavaDoc();
40    protected final JCheckBox JavaDoc _dontWrapJarCheck = new JCheckBox JavaDoc();
41    protected final JTextField JavaDoc _jarField = new JTextField JavaDoc();
42    protected final JTextField JavaDoc _outfileField = new JTextField JavaDoc();
43    protected final JLabel JavaDoc _errorTitleLabel = new JLabel JavaDoc();
44    protected final JTextField JavaDoc _errorTitleField = new JTextField JavaDoc();
45    protected final JLabel JavaDoc _downloadUrlLabel = new JLabel JavaDoc();
46    protected final JTextField JavaDoc _downloadUrlField = new JTextField JavaDoc();
47    protected final JLabel JavaDoc _supportUrlLabel = new JLabel JavaDoc();
48    protected final JTextField JavaDoc _supportUrlField = new JTextField JavaDoc();
49
50    /**
51     * Default constructor
52     */

53    public BasicForm()
54    {
55       initializePanel();
56    }
57
58    /**
59     * Adds fill components to empty cells in the first row and first column of the grid.
60     * This ensures that the grid spacing will be the same as shown in the designer.
61     * @param cols an array of column indices in the first row where fill components should be added.
62     * @param rows an array of row indices in the first column where fill components should be added.
63     */

64    void addFillComponents( Container JavaDoc panel, int[] cols, int[] rows )
65    {
66       Dimension JavaDoc filler = new Dimension JavaDoc(10,10);
67
68       boolean filled_cell_11 = false;
69       CellConstraints cc = new CellConstraints();
70       if ( cols.length > 0 && rows.length > 0 )
71       {
72          if ( cols[0] == 1 && rows[0] == 1 )
73          {
74             /** add a rigid area */
75             panel.add( Box.createRigidArea( filler ), cc.xy(1,1) );
76             filled_cell_11 = true;
77          }
78       }
79
80       for( int index = 0; index < cols.length; index++ )
81       {
82          if ( cols[index] == 1 && filled_cell_11 )
83          {
84             continue;
85          }
86          panel.add( Box.createRigidArea( filler ), cc.xy(cols[index],1) );
87       }
88
89       for( int index = 0; index < rows.length; index++ )
90       {
91          if ( rows[index] == 1 && filled_cell_11 )
92          {
93             continue;
94          }
95          panel.add( Box.createRigidArea( filler ), cc.xy(1,rows[index]) );
96       }
97
98    }
99
100    /**
101     * Helper method to load an image file from the CLASSPATH
102     * @param imageName the package and name of the file to load relative to the CLASSPATH
103     * @return an ImageIcon instance with the specified image file
104     * @throws IllegalArgumentException if the image resource cannot be loaded.
105     */

106    public ImageIcon JavaDoc loadImage( String JavaDoc imageName )
107    {
108       try
109       {
110          ClassLoader JavaDoc classloader = getClass().getClassLoader();
111          java.net.URL JavaDoc url = classloader.getResource( imageName );
112          if ( url != null )
113          {
114             ImageIcon JavaDoc icon = new ImageIcon JavaDoc( url );
115             return icon;
116          }
117       }
118       catch( Exception JavaDoc e )
119       {
120          e.printStackTrace();
121       }
122       throw new IllegalArgumentException JavaDoc( "Unable to load image: " + imageName );
123    }
124
125    public JPanel JavaDoc createPanel()
126    {
127       JPanel JavaDoc jpanel1 = new JPanel JavaDoc();
128       FormLayout formlayout1 = new FormLayout("FILL:7DLU:NONE,RIGHT:MAX(65DLU;DEFAULT):NONE,FILL:3DLU:NONE,FILL:DEFAULT:NONE,FILL:7DLU:NONE,FILL:DEFAULT:NONE,FILL:7DLU:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:NONE,FILL:DEFAULT:GROW(1.0),FILL:3DLU:NONE,FILL:26PX:NONE,FILL:7DLU:NONE","CENTER:9DLU:NONE,CENTER:DEFAULT:NONE,CENTER:3DLU:NONE,CENTER:DEFAULT:NONE,CENTER:3DLU:NONE,CENTER:DEFAULT:NONE,CENTER:3DLU:NONE,CENTER:DEFAULT:NONE,CENTER:3DLU:NONE,CENTER:DEFAULT:NONE,CENTER:3DLU:NONE,CENTER:DEFAULT:NONE,CENTER:3DLU:NONE,CENTER:DEFAULT:NONE,CENTER:3DLU:NONE,CENTER:DEFAULT:NONE,CENTER:3DLU:NONE,CENTER:DEFAULT:NONE,CENTER:9DLU:NONE,CENTER:DEFAULT:NONE,CENTER:3DLU:NONE,CENTER:DEFAULT:NONE,CENTER:3DLU:NONE,CENTER:DEFAULT:NONE,CENTER:3DLU:NONE,CENTER:DEFAULT:NONE,CENTER:9DLU:NONE");
129       CellConstraints cc = new CellConstraints();
130       jpanel1.setLayout(formlayout1);
131
132       _outfileButton.setIcon(loadImage("images/open16.png"));
133       _outfileButton.setName("outfileButton");
134       jpanel1.add(_outfileButton,cc.xy(12,2));
135
136       _outfileLabel.setIcon(loadImage("images/asterix.gif"));
137       _outfileLabel.setName("outfileLabel");
138       _outfileLabel.setText(Messages.getString("outfile"));
139       jpanel1.add(_outfileLabel,cc.xy(2,2));
140
141       _iconLabel.setName("iconLabel");
142       _iconLabel.setText(Messages.getString("icon"));
143       jpanel1.add(_iconLabel,cc.xy(2,8));
144
145       _jarLabel.setIcon(loadImage("images/asterix.gif"));
146       _jarLabel.setName("jarLabel");
147       _jarLabel.setText(Messages.getString("jar"));
148       jpanel1.add(_jarLabel,cc.xy(2,4));
149
150       _jarButton.setIcon(loadImage("images/open16.png"));
151       _jarButton.setName("jarButton");
152       jpanel1.add(_jarButton,cc.xy(12,4));
153
154       _iconButton.setIcon(loadImage("images/open16.png"));
155       _iconButton.setName("iconButton");
156       jpanel1.add(_iconButton,cc.xy(12,8));
157
158       _cmdLineLabel.setName("cmdLineLabel");
159       _cmdLineLabel.setText(Messages.getString("cmdLine"));
160       _cmdLineLabel.setToolTipText("");
161       jpanel1.add(_cmdLineLabel,cc.xy(2,12));
162
163       _optionsLabel.setName("optionsLabel");
164       _optionsLabel.setText(Messages.getString("options"));
165       jpanel1.add(_optionsLabel,cc.xy(2,16));
166
167       _chdirLabel.setName("chdirLabel");
168       _chdirLabel.setText(Messages.getString("chdir"));
169       jpanel1.add(_chdirLabel,cc.xy(2,10));
170
171       _processPriorityLabel.setName("processPriorityLabel");
172       _processPriorityLabel.setText(Messages.getString("priority"));
173       jpanel1.add(_processPriorityLabel,cc.xy(2,14));
174
175       _normalPriorityRadio.setActionCommand(Messages.getString("normalPriority"));
176       _normalPriorityRadio.setName("normalPriorityRadio");
177       _normalPriorityRadio.setText(Messages.getString("normalPriority"));
178       _buttongroup1.add(_normalPriorityRadio);
179       jpanel1.add(_normalPriorityRadio,cc.xy(4,14));
180
181       _idlePriorityRadio.setActionCommand(Messages.getString("idlePriority"));
182       _idlePriorityRadio.setName("idlePriorityRadio");
183       _idlePriorityRadio.setText(Messages.getString("idlePriority"));
184       _buttongroup1.add(_idlePriorityRadio);
185       jpanel1.add(_idlePriorityRadio,cc.xy(6,14));
186
187       _highPriorityRadio.setActionCommand(Messages.getString("highPriority"));
188       _highPriorityRadio.setName("highPriorityRadio");
189       _highPriorityRadio.setText(Messages.getString("highPriority"));
190       _buttongroup1.add(_highPriorityRadio);
191       jpanel1.add(_highPriorityRadio,cc.xy(8,14));
192
193       _customProcNameCheck.setActionCommand("Custom process name");
194       _customProcNameCheck.setName("customProcNameCheck");
195       _customProcNameCheck.setText(Messages.getString("customProcName"));
196       jpanel1.add(_customProcNameCheck,cc.xywh(4,16,7,1));
197
198       _stayAliveCheck.setActionCommand("Stay alive after launching a GUI application");
199       _stayAliveCheck.setName("stayAliveCheck");
200       _stayAliveCheck.setText(Messages.getString("stayAlive"));
201       jpanel1.add(_stayAliveCheck,cc.xywh(4,18,7,1));
202
203       _cmdLineField.setName("cmdLineField");
204       _cmdLineField.setToolTipText(Messages.getString("cmdLineTip"));
205       jpanel1.add(_cmdLineField,cc.xywh(4,12,7,1));
206
207       _chdirField.setName("chdirField");
208       _chdirField.setToolTipText(Messages.getString("chdirTip"));
209       jpanel1.add(_chdirField,cc.xywh(4,10,7,1));
210
211       _iconField.setName("iconField");
212       _iconField.setToolTipText(Messages.getString("iconTip"));
213       jpanel1.add(_iconField,cc.xywh(4,8,7,1));
214
215       _dontWrapJarCheck.setActionCommand("Don't wrap the jar, launch it only");
216       _dontWrapJarCheck.setName("dontWrapJarCheck");
217       _dontWrapJarCheck.setText(Messages.getString("dontWrapJar"));
218       jpanel1.add(_dontWrapJarCheck,cc.xywh(4,6,7,1));
219
220       _jarField.setName("jarField");
221       _jarField.setToolTipText(Messages.getString("jarTip"));
222       jpanel1.add(_jarField,cc.xywh(4,4,7,1));
223
224       _outfileField.setName("outfileField");
225       _outfileField.setToolTipText(Messages.getString("outfileTip"));
226       jpanel1.add(_outfileField,cc.xywh(4,2,7,1));
227
228       TitledSeparator titledseparator1 = new TitledSeparator();
229       titledseparator1.setText(Messages.getString("downloadAndSupport"));
230       jpanel1.add(titledseparator1,cc.xywh(2,20,11,1));
231
232       _errorTitleLabel.setName("errorTitleLabel");
233       _errorTitleLabel.setText(Messages.getString("errorTitle"));
234       jpanel1.add(_errorTitleLabel,cc.xy(2,22));
235
236       _errorTitleField.setName("errorTitleField");
237       _errorTitleField.setToolTipText(Messages.getString("errorTitleTip"));
238       jpanel1.add(_errorTitleField,cc.xywh(4,22,7,1));
239
240       _downloadUrlLabel.setIcon(loadImage("images/asterix.gif"));
241       _downloadUrlLabel.setName("downloadUrlLabel");
242       _downloadUrlLabel.setText(Messages.getString("downloadUrl"));
243       jpanel1.add(_downloadUrlLabel,cc.xy(2,24));
244
245       _downloadUrlField.setName("downloadUrlField");
246       jpanel1.add(_downloadUrlField,cc.xywh(4,24,7,1));
247
248       _supportUrlLabel.setName("supportUrlLabel");
249       _supportUrlLabel.setText(Messages.getString("supportUrl"));
250       jpanel1.add(_supportUrlLabel,cc.xy(2,26));
251
252       _supportUrlField.setName("supportUrlField");
253       jpanel1.add(_supportUrlField,cc.xywh(4,26,7,1));
254
255       addFillComponents(jpanel1,new int[]{ 1,2,3,4,5,6,7,8,9,10,11,12,13 },new int[]{ 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27 });
256       return jpanel1;
257    }
258
259    /**
260     * Initializer
261     */

262    protected void initializePanel()
263    {
264       setLayout(new BorderLayout JavaDoc());
265       add(createPanel(), BorderLayout.CENTER);
266    }
267
268
269 }
270
Popular Tags