KickJava   Java API By Example, From Geeks To Geeks.

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


1 package net.sf.launch4j.form;
2
3 import com.jgoodies.forms.layout.CellConstraints;
4 import com.jgoodies.forms.layout.FormLayout;
5 import java.awt.BorderLayout JavaDoc;
6 import java.awt.Container JavaDoc;
7 import java.awt.Dimension JavaDoc;
8 import javax.swing.Box JavaDoc;
9 import javax.swing.ImageIcon JavaDoc;
10 import javax.swing.JButton JavaDoc;
11 import javax.swing.JCheckBox JavaDoc;
12 import javax.swing.JLabel JavaDoc;
13 import javax.swing.JList JavaDoc;
14 import javax.swing.JPanel JavaDoc;
15 import javax.swing.JScrollPane JavaDoc;
16 import javax.swing.JTextField JavaDoc;
17
18 public abstract class ClassPathForm extends JPanel JavaDoc
19 {
20    protected final JTextField JavaDoc _classpathField = new JTextField JavaDoc();
21    protected final JLabel JavaDoc _classpathFieldLabel = new JLabel JavaDoc();
22    protected final JLabel JavaDoc _classpathListLabel = new JLabel JavaDoc();
23    protected final JList JavaDoc _classpathList = new JList JavaDoc();
24    protected final JLabel JavaDoc _mainclassLabel = new JLabel JavaDoc();
25    protected final JTextField JavaDoc _mainclassField = new JTextField JavaDoc();
26    protected final JButton JavaDoc _acceptClasspathButton = new JButton JavaDoc();
27    protected final JButton JavaDoc _removeClasspathButton = new JButton JavaDoc();
28    protected final JButton JavaDoc _importClasspathButton = new JButton JavaDoc();
29    protected final JButton JavaDoc _classpathUpButton = new JButton JavaDoc();
30    protected final JButton JavaDoc _classpathDownButton = new JButton JavaDoc();
31    protected final JCheckBox JavaDoc _classpathCheck = new JCheckBox JavaDoc();
32    protected final JButton JavaDoc _newClasspathButton = new JButton JavaDoc();
33
34    /**
35     * Default constructor
36     */

37    public ClassPathForm()
38    {
39       initializePanel();
40    }
41
42    /**
43     * Adds fill components to empty cells in the first row and first column of the grid.
44     * This ensures that the grid spacing will be the same as shown in the designer.
45     * @param cols an array of column indices in the first row where fill components should be added.
46     * @param rows an array of row indices in the first column where fill components should be added.
47     */

48    void addFillComponents( Container JavaDoc panel, int[] cols, int[] rows )
49    {
50       Dimension JavaDoc filler = new Dimension JavaDoc(10,10);
51
52       boolean filled_cell_11 = false;
53       CellConstraints cc = new CellConstraints();
54       if ( cols.length > 0 && rows.length > 0 )
55       {
56          if ( cols[0] == 1 && rows[0] == 1 )
57          {
58             /** add a rigid area */
59             panel.add( Box.createRigidArea( filler ), cc.xy(1,1) );
60             filled_cell_11 = true;
61          }
62       }
63
64       for( int index = 0; index < cols.length; index++ )
65       {
66          if ( cols[index] == 1 && filled_cell_11 )
67          {
68             continue;
69          }
70          panel.add( Box.createRigidArea( filler ), cc.xy(cols[index],1) );
71       }
72
73       for( int index = 0; index < rows.length; index++ )
74       {
75          if ( rows[index] == 1 && filled_cell_11 )
76          {
77             continue;
78          }
79          panel.add( Box.createRigidArea( filler ), cc.xy(1,rows[index]) );
80       }
81
82    }
83
84    /**
85     * Helper method to load an image file from the CLASSPATH
86     * @param imageName the package and name of the file to load relative to the CLASSPATH
87     * @return an ImageIcon instance with the specified image file
88     * @throws IllegalArgumentException if the image resource cannot be loaded.
89     */

90    public ImageIcon JavaDoc loadImage( String JavaDoc imageName )
91    {
92       try
93       {
94          ClassLoader JavaDoc classloader = getClass().getClassLoader();
95          java.net.URL JavaDoc url = classloader.getResource( imageName );
96          if ( url != null )
97          {
98             ImageIcon JavaDoc icon = new ImageIcon JavaDoc( url );
99             return icon;
100          }
101       }
102       catch( Exception JavaDoc e )
103       {
104          e.printStackTrace();
105       }
106       throw new IllegalArgumentException JavaDoc( "Unable to load image: " + imageName );
107    }
108
109    public JPanel JavaDoc createPanel()
110    {
111       JPanel JavaDoc jpanel1 = new JPanel JavaDoc();
112       FormLayout formlayout1 = new FormLayout("FILL:7DLU:NONE,RIGHT:MAX(65DLU;DEFAULT):NONE,FILL:3DLU:NONE,FILL:DEFAULT:GROW(1.0),FILL:3DLU:NONE,FILL:DEFAULT:NONE,FILL:3DLU:NONE,FILL:DEFAULT:NONE,FILL:3DLU:NONE,FILL:DEFAULT:NONE,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:DEFAULT:GROW(1.0),CENTER:3DLU:NONE,CENTER:DEFAULT:NONE,CENTER:3DLU:NONE,CENTER:DEFAULT:NONE,CENTER:9DLU:NONE");
113       CellConstraints cc = new CellConstraints();
114       jpanel1.setLayout(formlayout1);
115
116       _classpathField.setName("classpathField");
117       jpanel1.add(_classpathField,cc.xywh(4,11,7,1));
118
119       _classpathFieldLabel.setIcon(loadImage("images/asterix.gif"));
120       _classpathFieldLabel.setName("classpathFieldLabel");
121       _classpathFieldLabel.setText(Messages.getString("editClassPath"));
122       jpanel1.add(_classpathFieldLabel,cc.xy(2,11));
123
124       _classpathListLabel.setName("classpathListLabel");
125       _classpathListLabel.setText(Messages.getString("classPath"));
126       jpanel1.add(_classpathListLabel,cc.xy(2,6));
127
128       _classpathList.setName("classpathList");
129       JScrollPane JavaDoc jscrollpane1 = new JScrollPane JavaDoc();
130       jscrollpane1.setViewportView(_classpathList);
131       jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
132       jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
133       jpanel1.add(jscrollpane1,cc.xywh(4,6,7,4));
134
135       _mainclassLabel.setIcon(loadImage("images/asterix.gif"));
136       _mainclassLabel.setName("mainclassLabel");
137       _mainclassLabel.setText(Messages.getString("mainClass"));
138       jpanel1.add(_mainclassLabel,cc.xy(2,4));
139
140       _mainclassField.setName("mainclassField");
141       jpanel1.add(_mainclassField,cc.xywh(4,4,7,1));
142
143       _acceptClasspathButton.setActionCommand("Add");
144       _acceptClasspathButton.setIcon(loadImage("images/ok16.png"));
145       _acceptClasspathButton.setName("acceptClasspathButton");
146       _acceptClasspathButton.setText(Messages.getString("accept"));
147       jpanel1.add(_acceptClasspathButton,cc.xy(8,13));
148
149       _removeClasspathButton.setActionCommand("Remove");
150       _removeClasspathButton.setIcon(loadImage("images/cancel16.png"));
151       _removeClasspathButton.setName("removeClasspathButton");
152       _removeClasspathButton.setText(Messages.getString("remove"));
153       jpanel1.add(_removeClasspathButton,cc.xy(10,13));
154
155       _importClasspathButton.setIcon(loadImage("images/open16.png"));
156       _importClasspathButton.setName("importClasspathButton");
157       _importClasspathButton.setToolTipText(Messages.getString("importClassPath"));
158       jpanel1.add(_importClasspathButton,cc.xy(12,4));
159
160       _classpathUpButton.setIcon(loadImage("images/up16.png"));
161       _classpathUpButton.setName("classpathUpButton");
162       jpanel1.add(_classpathUpButton,cc.xy(12,6));
163
164       _classpathDownButton.setIcon(loadImage("images/down16.png"));
165       _classpathDownButton.setName("classpathDownButton");
166       jpanel1.add(_classpathDownButton,cc.xy(12,8));
167
168       _classpathCheck.setActionCommand("Custom classpath");
169       _classpathCheck.setName("classpathCheck");
170       _classpathCheck.setText(Messages.getString("customClassPath"));
171       jpanel1.add(_classpathCheck,cc.xy(4,2));
172
173       _newClasspathButton.setActionCommand("New");
174       _newClasspathButton.setIcon(loadImage("images/new16.png"));
175       _newClasspathButton.setName("newClasspathButton");
176       _newClasspathButton.setText(Messages.getString("new"));
177       jpanel1.add(_newClasspathButton,cc.xy(6,13));
178
179       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 });
180       return jpanel1;
181    }
182
183    /**
184     * Initializer
185     */

186    protected void initializePanel()
187    {
188       setLayout(new BorderLayout JavaDoc());
189       add(createPanel(), BorderLayout.CENTER);
190    }
191
192
193 }
194
Popular Tags