01: package net.xoetrope.swing;
02:
03: import java.awt.Component;
04: import javax.swing.JSplitPane;
05:
06: import net.xoetrope.xui.XAttributedComponent;
07:
08: /**
09: * <p>A wrapper for the Swing JSplitPane class</p>
10: * <p>Copyright: Copyright (c) Xoetrope Ltd., 1998-2003<br>
11: * License: see license.txt
12: * @version 1.0
13: */
14: public class XSplitPane extends JSplitPane implements
15: XAttributedComponent {
16: public XSplitPane() {
17: setTopComponent(null);
18: setBottomComponent(null);
19: }
20:
21: /**
22: * Add a new child to the split panel. If the orientation is vertical then
23: * the first component added is the top component and the next the bottom
24: * component. Similarly for a horizontal split the left and then the right
25: * components are added by successive calls to this method.
26: * @param name the name/caption of the tab component
27: * @param panel the content
28: */
29: public Component add(Component comp) {
30: if (getOrientation() == JSplitPane.VERTICAL_SPLIT) {
31: if (getTopComponent() == null)
32: setTopComponent(comp);
33: else
34: setBottomComponent(comp);
35: } else {
36: if (getLeftComponent() == null)
37: setLeftComponent(comp);
38: else
39: setRightComponent(comp);
40: }
41: return comp;
42: }
43:
44: /**
45: * Set one or more attributes of the component.
46: * <UL>
47: * <LI>orientation=horz|vert, set the orientation of the splitter</LI>
48: * <LI>location=int|double, set the location of the splitter as a pixel count or as a percentage of the width/height</LI>
49: * <LI>size=int, set the size of the splitter</LI>
50: * </UL>
51: * @param attribName the name of the attribute
52: * @param attribValue the value of the attribute
53: */
54: public void setAttribute(String attribName, String attribValue) {
55: String attribNameLwr = attribName.toLowerCase();
56: String attribValueLwr = attribValue.toLowerCase();
57: if (attribNameLwr.compareTo("orientation") == 0)
58: setOrientation(attribValueLwr.equals("horz") ? JSplitPane.HORIZONTAL_SPLIT
59: : JSplitPane.VERTICAL_SPLIT);
60: else if (attribNameLwr.compareTo("location") == 0) {
61: if (attribValueLwr.indexOf('.') >= 0)
62: setDividerLocation(new Double(attribValueLwr)
63: .doubleValue());
64: else
65: setDividerLocation(new Integer(attribValueLwr)
66: .intValue());
67: } else if (attribNameLwr.compareTo("size") == 0)
68: setDividerSize(new Integer(attribValueLwr).intValue());
69: }
70: }
|