KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > gui > util > HorizontalPanel


1 // $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/gui/util/HorizontalPanel.java,v 1.5 2004/02/14 03:34:29 sebb Exp $
2
/*
3  * Copyright 2003-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17 */

18
19 /*
20  * Created on Apr 25, 2003
21  *
22  */

23 package org.apache.jmeter.gui.util;
24
25 import java.awt.BorderLayout JavaDoc;
26 import java.awt.Component JavaDoc;
27
28 import javax.swing.Box JavaDoc;
29 import javax.swing.JComponent JavaDoc;
30 import javax.swing.JPanel JavaDoc;
31
32 /**
33  * @author ano ano
34  * @version $Revision: 1.5 $
35  */

36 public class HorizontalPanel extends JPanel JavaDoc
37 {
38     private Box JavaDoc subPanel = Box.createHorizontalBox();
39     private float verticalAlign;
40     private int hgap;
41
42     public HorizontalPanel()
43     {
44         this(5, CENTER_ALIGNMENT);
45     }
46
47     public HorizontalPanel(int hgap, float verticalAlign)
48     {
49         super(new BorderLayout JavaDoc());
50         add(subPanel, BorderLayout.WEST);
51         this.hgap = hgap;
52         this.verticalAlign = verticalAlign;
53     }
54
55     /* (non-Javadoc)
56      * @see java.awt.Container#add(java.awt.Component)
57      */

58     public Component JavaDoc add(Component JavaDoc c)
59     {
60         // This won't work right if we remove components. But we don't, so I'm
61
// not going to worry about it right now.
62
if (hgap > 0 && subPanel.getComponentCount() > 0)
63         {
64             subPanel.add(Box.createHorizontalStrut(hgap));
65         }
66
67         if (c instanceof JComponent JavaDoc)
68         {
69             ((JComponent JavaDoc) c).setAlignmentY(verticalAlign);
70         }
71         return subPanel.add(c);
72     }
73 }
74
Popular Tags