KickJava   Java API By Example, From Geeks To Geeks.

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


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.JLabel JavaDoc;
11 import javax.swing.JPanel JavaDoc;
12 import javax.swing.JScrollPane JavaDoc;
13 import javax.swing.JTextArea JavaDoc;
14
15 public abstract class EnvironmentVarsForm extends JPanel JavaDoc
16 {
17    protected final JTextArea JavaDoc _envVarsTextArea = new JTextArea JavaDoc();
18    protected final JLabel JavaDoc _envVarsLabel = new JLabel JavaDoc();
19
20    /**
21     * Default constructor
22     */

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

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

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

120    protected void initializePanel()
121    {
122       setLayout(new BorderLayout JavaDoc());
123       add(createPanel(), BorderLayout.CENTER);
124    }
125
126
127 }
128
Popular Tags