KickJava   Java API By Example, From Geeks To Geeks.

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


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.JPanel JavaDoc;
14 import javax.swing.JTextField JavaDoc;
15
16 public abstract class SplashForm extends JPanel JavaDoc
17 {
18    protected final JLabel JavaDoc _splashFileLabel = new JLabel JavaDoc();
19    protected final JLabel JavaDoc _waitForWindowLabel = new JLabel JavaDoc();
20    protected final JLabel JavaDoc _timeoutLabel = new JLabel JavaDoc();
21    protected final JCheckBox JavaDoc _timeoutErrCheck = new JCheckBox JavaDoc();
22    protected final JTextField JavaDoc _splashFileField = new JTextField JavaDoc();
23    protected final JTextField JavaDoc _timeoutField = new JTextField JavaDoc();
24    protected final JButton JavaDoc _splashFileButton = new JButton JavaDoc();
25    protected final JCheckBox JavaDoc _splashCheck = new JCheckBox JavaDoc();
26    protected final JCheckBox JavaDoc _waitForWindowCheck = new JCheckBox JavaDoc();
27
28    /**
29     * Default constructor
30     */

31    public SplashForm()
32    {
33       initializePanel();
34    }
35
36    /**
37     * Adds fill components to empty cells in the first row and first column of the grid.
38     * This ensures that the grid spacing will be the same as shown in the designer.
39     * @param cols an array of column indices in the first row where fill components should be added.
40     * @param rows an array of row indices in the first column where fill components should be added.
41     */

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

84    public ImageIcon JavaDoc loadImage( String JavaDoc imageName )
85    {
86       try
87       {
88          ClassLoader JavaDoc classloader = getClass().getClassLoader();
89          java.net.URL JavaDoc url = classloader.getResource( imageName );
90          if ( url != null )
91          {
92             ImageIcon JavaDoc icon = new ImageIcon JavaDoc( url );
93             return icon;
94          }
95       }
96       catch( Exception JavaDoc e )
97       {
98          e.printStackTrace();
99       }
100       throw new IllegalArgumentException JavaDoc( "Unable to load image: " + imageName );
101    }
102
103    public JPanel JavaDoc createPanel()
104    {
105       JPanel JavaDoc jpanel1 = new JPanel JavaDoc();
106       FormLayout formlayout1 = new FormLayout("FILL:7DLU:NONE,RIGHT:MAX(65DLU;DEFAULT):NONE,FILL:3DLU:NONE,FILL:60DLU: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:9DLU:NONE");
107       CellConstraints cc = new CellConstraints();
108       jpanel1.setLayout(formlayout1);
109
110       _splashFileLabel.setIcon(loadImage("images/asterix.gif"));
111       _splashFileLabel.setName("splashFileLabel");
112       _splashFileLabel.setText(Messages.getString("splashFile"));
113       jpanel1.add(_splashFileLabel,cc.xy(2,4));
114
115       _waitForWindowLabel.setName("waitForWindowLabel");
116       _waitForWindowLabel.setText(Messages.getString("waitForWindow"));
117       jpanel1.add(_waitForWindowLabel,cc.xy(2,6));
118
119       _timeoutLabel.setIcon(loadImage("images/asterix.gif"));
120       _timeoutLabel.setName("timeoutLabel");
121       _timeoutLabel.setText(Messages.getString("timeout"));
122       jpanel1.add(_timeoutLabel,cc.xy(2,8));
123
124       _timeoutErrCheck.setActionCommand("Signal error on timeout");
125       _timeoutErrCheck.setName("timeoutErrCheck");
126       _timeoutErrCheck.setText(Messages.getString("timeoutErr"));
127       _timeoutErrCheck.setToolTipText(Messages.getString("timeoutErrTip"));
128       jpanel1.add(_timeoutErrCheck,cc.xywh(4,10,2,1));
129
130       _splashFileField.setName("splashFileField");
131       _splashFileField.setToolTipText(Messages.getString("splashFileTip"));
132       jpanel1.add(_splashFileField,cc.xywh(4,4,2,1));
133
134       _timeoutField.setName("timeoutField");
135       _timeoutField.setToolTipText(Messages.getString("timeoutTip"));
136       jpanel1.add(_timeoutField,cc.xy(4,8));
137
138       _splashFileButton.setIcon(loadImage("images/open16.png"));
139       _splashFileButton.setName("splashFileButton");
140       jpanel1.add(_splashFileButton,cc.xy(7,4));
141
142       _splashCheck.setActionCommand("Enable splash screen");
143       _splashCheck.setName("splashCheck");
144       _splashCheck.setText(Messages.getString("enableSplash"));
145       jpanel1.add(_splashCheck,cc.xywh(4,2,2,1));
146
147       _waitForWindowCheck.setActionCommand("Close splash screen when an application window appears");
148       _waitForWindowCheck.setName("waitForWindowCheck");
149       _waitForWindowCheck.setText(Messages.getString("waitForWindowText"));
150       jpanel1.add(_waitForWindowCheck,cc.xywh(4,6,2,1));
151
152       addFillComponents(jpanel1,new int[]{ 1,2,3,4,5,6,7,8 },new int[]{ 1,2,3,4,5,6,7,8,9,10,11 });
153       return jpanel1;
154    }
155
156    /**
157     * Initializer
158     */

159    protected void initializePanel()
160    {
161       setLayout(new BorderLayout JavaDoc());
162       add(createPanel(), BorderLayout.CENTER);
163    }
164
165
166 }
167
Popular Tags