01: /*
02: * FlowLayoutMapping.java
03: *
04: * Copyright (c) 1997-2003 Sun Microsystems, Inc. All Rights Reserved.
05: *
06: * See the file "LICENSE.txt" for information on usage and redistribution
07: * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
08: */
09: package pnuts.awt;
10:
11: import java.awt.*;
12:
13: /**
14: * FlowLayout mapping of <a href="/pnuts/doc/hierarchicalLayout.html">Hierarchical Layout</a>.
15: *
16: * @author Toyokazu Tomatsu
17: * @author Nathan Sweet (misc@n4te.com)
18: */
19: public class FlowLayoutMapping extends Layout {
20:
21: public Container createContainer(Container container,
22: Object[] format) {
23: if (!(format[1] instanceof Object[])) {
24: throw new LayoutException(
25: "Element after the FlowLayout class must be an array of constructor arguments: "
26: + format[1]);
27: }
28: Object args[] = (Object[]) format[1];
29: FlowLayout lm = null;
30: if (args.length == 0) {
31: lm = new FlowLayout();
32: } else if (args.length == 1) {
33: lm = new FlowLayout(((Integer) args[0]).intValue());
34: } else if (args.length == 3) {
35: lm = new FlowLayout(((Integer) args[0]).intValue(),
36: ((Integer) args[1]).intValue(), ((Integer) args[2])
37: .intValue());
38: }
39: container.setLayout(lm);
40: for (int i = 2; i < format.length; i++) {
41: Object a = format[i];
42: if (a == null) {
43: container.add("", makePanel(container));
44: } else if (isArray(a)) {
45: Object nestedArray[] = (Object[]) format[i];
46: if (nestedArray[0] instanceof Class)
47: container.add("", Layout.layout(
48: makePanel(container), (Object[]) a));
49: else if (nestedArray[0] instanceof Container) {
50: if (!(nestedArray[1] instanceof Object[]))
51: throw new LayoutException(
52: "Second element must be an array: "
53: + nestedArray[1]);
54: container.add("", (Container) nestedArray[0]);
55: Layout.layout((Container) nestedArray[0],
56: (Object[]) nestedArray[1]);
57: } else {
58: throw new LayoutException(
59: "FlowLayout requires an array element to start with a Class or Container: "
60: + nestedArray[0]);
61: }
62: } else if (a instanceof Component) {
63: container.add("", (Component) a);
64: } else {
65: throw new LayoutException(
66: "FlowLayout requires elements to be a Component, array, or null.");
67: }
68: }
69: return container;
70: }
71: }
|