KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jimm > datavision > gui > DesignWinLayout


1 package jimm.datavision.gui;
2 import java.awt.*;
3
4 /**
5  * A custom layout manager for the section widgets inside a design window.
6  *
7  * @author Jim Menard, <a HREF="mailto:jimm@io.com">jimm@io.com</a>
8  */

9 class DesignWinLayout implements LayoutManager {
10
11 /**
12  * Adds the specified component with the specified name to the layout.
13  *
14  * @param name the component name
15  * @param comp the component to be added
16  */

17 public void addLayoutComponent(String JavaDoc name, Component comp) {
18 }
19
20 /**
21  * Removes the specified component from the layout.
22  *
23  * @param comp the component to be removed
24  */

25 public void removeLayoutComponent(Component comp) {
26 }
27
28 /**
29  * Calculates the preferred size dimensions for the specified panel given
30  * the components in the specified parent container.
31  *
32  * @param parent the component to be laid out
33  * @see #minimumLayoutSize
34  */

35 public Dimension preferredLayoutSize(Container parent) {
36     return minimumLayoutSize(parent);
37 }
38
39 /**
40  * Calculates the minimum size dimensions for the specified panel given the
41  * components in the specified parent container.
42  *
43  * @param parent the component to be laid out
44  * @see #preferredLayoutSize
45  */

46 public Dimension minimumLayoutSize(Container parent) {
47     int width = 0;
48     int height = 0;
49     Component[] components = parent.getComponents();
50     for (int i = 0; i < components.length; ++i) {
51     Component c = components[i];
52     if (c instanceof SectionWidget) { // Ignore floating widgets
53
Dimension dim = c.getPreferredSize();
54         if (width == 0) width = dim.width;
55         height += dim.height;
56     }
57     }
58     return new Dimension(width, height);
59 }
60
61 /**
62  * Lays out the container in the specified panel.
63  *
64  * @param parent the component which needs to be laid out
65  */

66 public void layoutContainer(Container parent) {
67     int y = 0;
68     Component[] components = parent.getComponents();
69     for (int i = 0; i < components.length; ++i) {
70     Component c = components[i];
71     if (c instanceof SectionWidget) { // Ignore floating widgets
72
Dimension dim = c.getPreferredSize();
73         c.setBounds(0, y, dim.width, dim.height);
74         y += dim.height;
75     }
76     }
77 }
78
79 }
80
Popular Tags