01: /*
02: * Copyright 2006 Ethan Nicholas. All rights reserved.
03: * Use is subject to license terms.
04: */
05: package jaxx.runtime.swing;
06:
07: import java.awt.*;
08: import javax.swing.*;
09:
10: /** Panel which uses a {@link VBoxLayout} by default.
11: *
12: *@author Ethan Nicholas
13: */
14: public class VBox extends JPanel {
15: public static final String SPACING_PROPERTY = "spacing";
16: public static final String MARGIN_PROPERTY = "margin";
17: public static final String HORIZONTAL_ALIGNMENT_PROPERTY = "horizontalAlignment";
18: public static final String VERTICAL_ALIGNMENT_PROPERTY = "verticalAlignment";
19:
20: private Insets margin;
21:
22: public VBox() {
23: super (new VBoxLayout());
24: }
25:
26: /** Returns the spacing between components, in pixels. Spacing is applied between components only,
27: * not to the top or bottom of the container.
28: *
29: * @return spacing between components
30: */
31: public int getSpacing() {
32: return ((VBoxLayout) getLayout()).getSpacing();
33: }
34:
35: /** Sets the spacing between components. Spacing is applied between components only,
36: * not to the top or bottom of the container.
37: *
38: * @param spacing new spacing value
39: */
40: public void setSpacing(int spacing) {
41: int oldValue = getSpacing();
42: ((VBoxLayout) getLayout()).setSpacing(spacing);
43: firePropertyChange(SPACING_PROPERTY, oldValue, spacing);
44: revalidate();
45: }
46:
47: public int getHorizontalAlignment() {
48: return ((VBoxLayout) getLayout()).getHorizontalAlignment();
49: }
50:
51: public void setHorizontalAlignment(int horizontalAlignment) {
52: int oldValue = getHorizontalAlignment();
53: ((VBoxLayout) getLayout())
54: .setHorizontalAlignment(horizontalAlignment);
55: firePropertyChange(HORIZONTAL_ALIGNMENT_PROPERTY, oldValue,
56: horizontalAlignment);
57: revalidate();
58: }
59:
60: public int getVerticalAlignment() {
61: return ((VBoxLayout) getLayout()).getVerticalAlignment();
62: }
63:
64: public void setVerticalAlignment(int verticalAlignment) {
65: int oldValue = getVerticalAlignment();
66: ((VBoxLayout) getLayout())
67: .setVerticalAlignment(verticalAlignment);
68: firePropertyChange(VERTICAL_ALIGNMENT_PROPERTY, oldValue,
69: verticalAlignment);
70: revalidate();
71: }
72:
73: public Insets getMargin() {
74: return margin;
75: }
76:
77: public void setMargin(Insets margin) {
78: Insets oldValue = this .margin;
79: this .margin = (Insets) margin.clone();
80: firePropertyChange(MARGIN_PROPERTY, oldValue, margin);
81: }
82:
83: public Insets getInsets() {
84: Insets result = super.getInsets();
85: if (margin != null) {
86: result.top += margin.top;
87: result.left += margin.left;
88: result.right += margin.right;
89: result.bottom += margin.bottom;
90: }
91: return result;
92: }
93: }
|