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: * To change the template for this generated file go to
23: * Window>Preferences>Java>Code Generation>Code and Comments
24: */
25: package org.apache.jmeter.gui.util;
26:
27: import java.awt.Color;
28: import java.awt.BorderLayout;
29: import java.awt.Component;
30:
31: import javax.swing.Box;
32: import javax.swing.JComponent;
33: import javax.swing.JPanel;
34:
35: /**
36: * @author ano ano
37: * @version $Revision: 493779 $
38: */
39: public class VerticalPanel extends JPanel {
40: private Box subPanel = Box.createVerticalBox();
41:
42: private float horizontalAlign;
43:
44: private int vgap;
45:
46: public VerticalPanel() {
47: this (5, LEFT_ALIGNMENT);
48: }
49:
50: public VerticalPanel(Color bkg) {
51: this ();
52: subPanel.setBackground(bkg);
53: this .setBackground(bkg);
54: }
55:
56: public VerticalPanel(int vgap, float horizontalAlign) {
57: super (new BorderLayout());
58: add(subPanel, BorderLayout.NORTH);
59: this .vgap = vgap;
60: this .horizontalAlign = horizontalAlign;
61: }
62:
63: /*
64: * (non-Javadoc)
65: *
66: * @see java.awt.Container#add(java.awt.Component)
67: */
68: public Component add(Component c) {
69: // This won't work right if we remove components. But we don't, so I'm
70: // not going to worry about it right now.
71: if (vgap > 0 && subPanel.getComponentCount() > 0) {
72: subPanel.add(Box.createVerticalStrut(vgap));
73: }
74:
75: if (c instanceof JComponent) {
76: ((JComponent) c).setAlignmentX(horizontalAlign);
77: }
78:
79: return subPanel.add(c);
80: }
81: }
|