1 package fr.ove.openmath.mfd2;
2
3 import java.awt.*;
4 import java.io.Serializable;
5 import java.lang.IllegalArgumentException;
6
7 /***
8 * A layout manager to display the component of the container laid by the
9 * instance vertically.
10 *
11 * @author © 1999 DIRAT Laurent
12 * @version 1.0 01/06/99
13 */
14 public class OneColumnLayout implements LayoutManager2, Serializable {
15
16
17 /***
18 * Adds the specified component with the specified name to
19 * the layout.
20 * @param name the component name
21 * @param comp the component to be added
22 */
23 public void addLayoutComponent(String name, Component comp) {
24 }
25
26 /***
27 * Removes the specified component from the layout.
28 * @param comp the component ot be removed
29 */
30 public void removeLayoutComponent(Component comp) {
31 }
32
33 /***
34 * Calculates the minimum size dimensions for the specified
35 * panel given the components in the specified parent container.
36 * @param parent the component to be laid out
37 * @see #preferredLayoutSize
38 */
39 public Dimension minimumLayoutSize(Container parent) {
40 return preferredLayoutSize(parent);
41 }
42
43
44
45 /***
46 * Adds the specified component to the layout, using the specified
47 * constraint object.
48 * @param comp the component to be added
49 * @param constraints where/how the component is added to the layout.
50 */
51 public void addLayoutComponent(Component comp, Object constraints) {
52 }
53
54 /***
55 * Returns the maximum size of this component.
56 * @see java.awt.Component#getMinimumSize()
57 * @see java.awt.Component#getPreferredSize()
58 * @see LayoutManager
59 */
60 public Dimension maximumLayoutSize(Container target) {
61 return preferredLayoutSize(target);
62 }
63
64 /***
65 * Returns the alignment along the x axis. This specifies how
66 * the component would like to be aligned relative to other
67 * components. The value should be a number between 0 and 1
68 * where 0 represents alignment along the origin, 1 is aligned
69 * the furthest away from the origin, 0.5 is centered, etc.
70 */
71 public float getLayoutAlignmentX(Container target) {
72 return 0.0f;
73 }
74
75 /***
76 * Returns the alignment along the y axis. This specifies how
77 * the component would like to be aligned relative to other
78 * components. The value should be a number between 0 and 1
79 * where 0 represents alignment along the origin, 1 is aligned
80 * the furthest away from the origin, 0.5 is centered, etc.
81 */
82 public float getLayoutAlignmentY(Container target) {
83 return 0.0f;
84 }
85
86 /***
87 * Invalidates the layout, indicating that if the layout manager
88 * has cached information it should be discarded.
89 */
90 public void invalidateLayout(Container target) {
91 }
92
93 /***
94 * Calculates the preferred size dimensions for the specified
95 * panel given the components in the specified parent container.
96 * @param parent the component to be laid out
97 *
98 * @see #minimumLayoutSize
99 */
100 public Dimension preferredLayoutSize(Container parent) {
101 int width = 0;
102 int height = 0;
103 Component tmp;
104 Dimension size;
105
106 for (int i = 0; i < parent.getComponentCount(); i++ ) {
107 tmp = parent.getComponent(i);
108 size = tmp.getPreferredSize();
109 tmp.setSize(size);
110
111 width = (int) Math.max(size.width, width);
112 height += size.height;
113 }
114
115 Component father = parent.getParent();
116 width = (int) Math.max(width, (father.getSize()).width - 5);
117
118 for (int i = 0; i < parent.getComponentCount(); i++ ) {
119 tmp = parent.getComponent(i);
120 size = tmp.getSize();
121 tmp.setSize(width, size.height);
122 }
123
124 return new Dimension(width, height);
125 }
126
127
128
129
130
131 public void layoutContainer(Container parent) {
132 Component current, previous = null;
133 Rectangle bounds;
134
135 for (int i = 0; i < parent.getComponentCount(); i++) {
136 current = parent.getComponent(i);
137
138 if (i == 0 )
139 current.setLocation(0, 0);
140 else {
141 bounds = previous.getBounds();
142 current.setLocation(0, bounds.y + bounds.height);
143 }
144
145 previous = current;
146 }
147
148 }
149 }
150