KickJava   Java API By Example, From Geeks To Geeks.

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


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.ImageIcon JavaDoc;
11 import javax.swing.JPanel JavaDoc;
12 import javax.swing.JScrollPane JavaDoc;
13 import javax.swing.JTabbedPane JavaDoc;
14 import javax.swing.JTextArea JavaDoc;
15
16 public abstract class ConfigForm extends JPanel JavaDoc
17 {
18    protected final JTextArea JavaDoc _logTextArea = new JTextArea JavaDoc();
19    protected final TitledSeparator _logSeparator = new TitledSeparator();
20    protected final JTabbedPane JavaDoc _tab = new JTabbedPane JavaDoc();
21
22    /**
23     * Default constructor
24     */

25    public ConfigForm()
26    {
27       initializePanel();
28    }
29
30    /**
31     * Adds fill components to empty cells in the first row and first column of the grid.
32     * This ensures that the grid spacing will be the same as shown in the designer.
33     * @param cols an array of column indices in the first row where fill components should be added.
34     * @param rows an array of row indices in the first column where fill components should be added.
35     */

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

78    public ImageIcon JavaDoc loadImage( String JavaDoc imageName )
79    {
80       try
81       {
82          ClassLoader JavaDoc classloader = getClass().getClassLoader();
83          java.net.URL JavaDoc url = classloader.getResource( imageName );
84          if ( url != null )
85          {
86             ImageIcon JavaDoc icon = new ImageIcon JavaDoc( url );
87             return icon;
88          }
89       }
90       catch( Exception JavaDoc e )
91       {
92          e.printStackTrace();
93       }
94       throw new IllegalArgumentException JavaDoc( "Unable to load image: " + imageName );
95    }
96
97    public JPanel JavaDoc createPanel()
98    {
99       JPanel JavaDoc jpanel1 = new JPanel JavaDoc();
100       FormLayout formlayout1 = new FormLayout("FILL:7DLU:NONE,FILL:DEFAULT:GROW(1.0),FILL:7DLU:NONE","CENTER:3DLU:NONE,FILL:DEFAULT:NONE,CENTER:3DLU:NONE,CENTER:DEFAULT:NONE,CENTER:3DLU:NONE,FILL:DEFAULT:GROW(1.0),CENTER:9DLU:NONE");
101       CellConstraints cc = new CellConstraints();
102       jpanel1.setLayout(formlayout1);
103
104       _logTextArea.setName("logTextArea");
105       JScrollPane JavaDoc jscrollpane1 = new JScrollPane JavaDoc();
106       jscrollpane1.setViewportView(_logTextArea);
107       jscrollpane1.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED);
108       jscrollpane1.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
109       jpanel1.add(jscrollpane1,cc.xy(2,6));
110
111       _logSeparator.setName("logSeparator");
112       _logSeparator.setText(Messages.getString("log"));
113       jpanel1.add(_logSeparator,cc.xy(2,4));
114
115       _tab.setName("tab");
116       jpanel1.add(_tab,cc.xywh(1,2,3,1));
117
118       addFillComponents(jpanel1,new int[]{ 1,2,3 },new int[]{ 1,3,4,5,6,7 });
119       return jpanel1;
120    }
121
122    /**
123     * Initializer
124     */

125    protected void initializePanel()
126    {
127       setLayout(new BorderLayout JavaDoc());
128       add(createPanel(), BorderLayout.CENTER);
129    }
130
131
132 }
133
Popular Tags