01: package jimm.datavision.gui;
02:
03: import java.awt.*;
04:
05: /**
06: * A custom layout manager for the section widgets inside a design window.
07: *
08: * @author Jim Menard, <a href="mailto:jimm@io.com">jimm@io.com</a>
09: */
10: class DesignWinLayout implements LayoutManager {
11:
12: /**
13: * Adds the specified component with the specified name to the layout.
14: *
15: * @param name the component name
16: * @param comp the component to be added
17: */
18: public void addLayoutComponent(String name, Component comp) {
19: }
20:
21: /**
22: * Removes the specified component from the layout.
23: *
24: * @param comp the component to be removed
25: */
26: public void removeLayoutComponent(Component comp) {
27: }
28:
29: /**
30: * Calculates the preferred size dimensions for the specified panel given
31: * the components in the specified parent container.
32: *
33: * @param parent the component to be laid out
34: * @see #minimumLayoutSize
35: */
36: public Dimension preferredLayoutSize(Container parent) {
37: return minimumLayoutSize(parent);
38: }
39:
40: /**
41: * Calculates the minimum size dimensions for the specified panel given the
42: * components in the specified parent container.
43: *
44: * @param parent the component to be laid out
45: * @see #preferredLayoutSize
46: */
47: public Dimension minimumLayoutSize(Container parent) {
48: int width = 0;
49: int height = 0;
50: Component[] components = parent.getComponents();
51: for (int i = 0; i < components.length; ++i) {
52: Component c = components[i];
53: if (c instanceof SectionWidget) { // Ignore floating widgets
54: Dimension dim = c.getPreferredSize();
55: if (width == 0)
56: width = dim.width;
57: height += dim.height;
58: }
59: }
60: return new Dimension(width, height);
61: }
62:
63: /**
64: * Lays out the container in the specified panel.
65: *
66: * @param parent the component which needs to be laid out
67: */
68: public void layoutContainer(Container parent) {
69: int y = 0;
70: Component[] components = parent.getComponents();
71: for (int i = 0; i < components.length; ++i) {
72: Component c = components[i];
73: if (c instanceof SectionWidget) { // Ignore floating widgets
74: Dimension dim = c.getPreferredSize();
75: c.setBounds(0, y, dim.width, dim.height);
76: y += dim.height;
77: }
78: }
79: }
80:
81: }
|