01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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.Color;
26: import java.awt.BorderLayout;
27: import java.awt.Component;
28:
29: import javax.swing.Box;
30: import javax.swing.JComponent;
31: import javax.swing.JPanel;
32:
33: /**
34: * @author ano ano
35: * @version $Revision: 493779 $
36: */
37: public class HorizontalPanel extends JPanel {
38: private Box subPanel = Box.createHorizontalBox();
39:
40: private float verticalAlign;
41:
42: private int hgap;
43:
44: public HorizontalPanel() {
45: this (5, CENTER_ALIGNMENT);
46: }
47:
48: public HorizontalPanel(Color bk) {
49: this ();
50: subPanel.setBackground(bk);
51: this .setBackground(bk);
52: }
53:
54: public HorizontalPanel(int hgap, float verticalAlign) {
55: super (new BorderLayout());
56: add(subPanel, BorderLayout.WEST);
57: this .hgap = hgap;
58: this .verticalAlign = verticalAlign;
59: }
60:
61: /*
62: * (non-Javadoc)
63: *
64: * @see java.awt.Container#add(java.awt.Component)
65: */
66: public Component add(Component c) {
67: // This won't work right if we remove components. But we don't, so I'm
68: // not going to worry about it right now.
69: if (hgap > 0 && subPanel.getComponentCount() > 0) {
70: subPanel.add(Box.createHorizontalStrut(hgap));
71: }
72:
73: if (c instanceof JComponent) {
74: ((JComponent) c).setAlignmentY(verticalAlign);
75: }
76: return subPanel.add(c);
77: }
78: }
|