37 |
|
|
38 |
package javax.swing; |
package javax.swing; |
39 |
|
|
40 |
|
import java.awt.AWTError; |
41 |
import java.awt.Component; |
import java.awt.Component; |
42 |
import java.awt.Container; |
import java.awt.Container; |
43 |
import java.awt.Dimension; |
import java.awt.Dimension; |
79 |
private SizeRequirements yTotal; |
private SizeRequirements yTotal; |
80 |
|
|
81 |
/** |
/** |
82 |
|
* The offsets of the child components in the X direction. |
83 |
|
*/ |
84 |
|
private int[] offsetsX; |
85 |
|
|
86 |
|
/** |
87 |
|
* The offsets of the child components in the Y direction. |
88 |
|
*/ |
89 |
|
private int[] offsetsY; |
90 |
|
|
91 |
|
/** |
92 |
|
* The spans of the child components in the X direction. |
93 |
|
*/ |
94 |
|
private int[] spansX; |
95 |
|
|
96 |
|
/** |
97 |
|
* The spans of the child components in the Y direction. |
98 |
|
*/ |
99 |
|
private int[] spansY; |
100 |
|
|
101 |
|
/** |
102 |
* Constructor OverlayLayout |
* Constructor OverlayLayout |
103 |
* @param target TODO |
* @param target TODO |
104 |
*/ |
*/ |
105 |
public OverlayLayout(Container target) |
public OverlayLayout(Container target) |
106 |
{ |
{ |
107 |
// TODO |
this.target = target; |
108 |
} |
} |
109 |
|
|
110 |
/** |
/** |
113 |
*/ |
*/ |
114 |
public void invalidateLayout(Container target) |
public void invalidateLayout(Container target) |
115 |
{ |
{ |
116 |
// TODO |
xChildren = null; |
117 |
|
yChildren = null; |
118 |
|
xTotal = null; |
119 |
|
yTotal = null; |
120 |
|
offsetsX = null; |
121 |
|
offsetsY = null; |
122 |
|
spansX = null; |
123 |
|
spansY = null; |
124 |
} |
} |
125 |
|
|
126 |
/** |
/** |
130 |
*/ |
*/ |
131 |
public void addLayoutComponent(String string, Component component) |
public void addLayoutComponent(String string, Component component) |
132 |
{ |
{ |
133 |
// TODO |
// Nothing to do here. |
134 |
} |
} |
135 |
|
|
136 |
/** |
/** |
140 |
*/ |
*/ |
141 |
public void addLayoutComponent(Component component, Object constraints) |
public void addLayoutComponent(Component component, Object constraints) |
142 |
{ |
{ |
143 |
// TODO |
// Nothing to do here. |
144 |
} |
} |
145 |
|
|
146 |
/** |
/** |
149 |
*/ |
*/ |
150 |
public void removeLayoutComponent(Component component) |
public void removeLayoutComponent(Component component) |
151 |
{ |
{ |
152 |
// TODO |
// Nothing to do here. |
153 |
} |
} |
154 |
|
|
155 |
/** |
/** |
159 |
*/ |
*/ |
160 |
public Dimension preferredLayoutSize(Container target) |
public Dimension preferredLayoutSize(Container target) |
161 |
{ |
{ |
162 |
return null; // TODO |
if (target != this.target) |
163 |
|
throw new AWTError("OverlayLayout can't be shared"); |
164 |
|
|
165 |
|
checkTotalRequirements(); |
166 |
|
return new Dimension(xTotal.preferred, yTotal.preferred); |
167 |
} |
} |
168 |
|
|
169 |
/** |
/** |
173 |
*/ |
*/ |
174 |
public Dimension minimumLayoutSize(Container target) |
public Dimension minimumLayoutSize(Container target) |
175 |
{ |
{ |
176 |
return null; // TODO |
if (target != this.target) |
177 |
|
throw new AWTError("OverlayLayout can't be shared"); |
178 |
|
|
179 |
|
checkTotalRequirements(); |
180 |
|
return new Dimension(xTotal.minimum, yTotal.minimum); |
181 |
} |
} |
182 |
|
|
183 |
/** |
/** |
187 |
*/ |
*/ |
188 |
public Dimension maximumLayoutSize(Container target) |
public Dimension maximumLayoutSize(Container target) |
189 |
{ |
{ |
190 |
return null; // TODO |
if (target != this.target) |
191 |
|
throw new AWTError("OverlayLayout can't be shared"); |
192 |
|
|
193 |
|
checkTotalRequirements(); |
194 |
|
return new Dimension(xTotal.maximum, yTotal.maximum); |
195 |
} |
} |
196 |
|
|
197 |
/** |
/** |
201 |
*/ |
*/ |
202 |
public float getLayoutAlignmentX(Container target) |
public float getLayoutAlignmentX(Container target) |
203 |
{ |
{ |
204 |
return (float) 0.0; // TODO |
if (target != this.target) |
205 |
|
throw new AWTError("OverlayLayout can't be shared"); |
206 |
|
|
207 |
|
checkTotalRequirements(); |
208 |
|
return xTotal.alignment; |
209 |
} |
} |
210 |
|
|
211 |
/** |
/** |
215 |
*/ |
*/ |
216 |
public float getLayoutAlignmentY(Container target) |
public float getLayoutAlignmentY(Container target) |
217 |
{ |
{ |
218 |
return (float) 0.0; // TODO |
if (target != this.target) |
219 |
|
throw new AWTError("OverlayLayout can't be shared"); |
220 |
|
|
221 |
|
checkTotalRequirements(); |
222 |
|
return yTotal.alignment; |
223 |
} |
} |
224 |
|
|
225 |
/** |
/** |
228 |
*/ |
*/ |
229 |
public void layoutContainer(Container target) |
public void layoutContainer(Container target) |
230 |
{ |
{ |
231 |
// TODO |
if (target != this.target) |
232 |
} |
throw new AWTError("OverlayLayout can't be shared"); |
233 |
|
|
234 |
|
checkLayout(); |
235 |
|
Component[] children = target.getComponents(); |
236 |
|
for (int i = 0; i < children.length; i++) |
237 |
|
children[i].setBounds(offsetsX[i], offsetsY[i], spansX[i], spansY[i]); |
238 |
|
} |
239 |
|
|
240 |
|
/** |
241 |
|
* Makes sure that the xChildren and yChildren fields are correctly set up. |
242 |
|
* A call to {@link #invalidateLayout(Container)} sets these fields to null, |
243 |
|
* so they have to be set up again. |
244 |
|
*/ |
245 |
|
private void checkRequirements() |
246 |
|
{ |
247 |
|
if (xChildren == null || yChildren == null) |
248 |
|
{ |
249 |
|
Component[] children = target.getComponents(); |
250 |
|
xChildren = new SizeRequirements[children.length]; |
251 |
|
yChildren = new SizeRequirements[children.length]; |
252 |
|
for (int i = 0; i < children.length; i++) |
253 |
|
{ |
254 |
|
if (! children[i].isVisible()) |
255 |
|
{ |
256 |
|
xChildren[i] = new SizeRequirements(); |
257 |
|
yChildren[i] = new SizeRequirements(); |
258 |
|
} |
259 |
|
else |
260 |
|
{ |
261 |
|
xChildren[i] = |
262 |
|
new SizeRequirements(children[i].getMinimumSize().width, |
263 |
|
children[i].getPreferredSize().width, |
264 |
|
children[i].getMaximumSize().width, |
265 |
|
children[i].getAlignmentX()); |
266 |
|
yChildren[i] = |
267 |
|
new SizeRequirements(children[i].getMinimumSize().height, |
268 |
|
children[i].getPreferredSize().height, |
269 |
|
children[i].getMaximumSize().height, |
270 |
|
children[i].getAlignmentY()); |
271 |
|
} |
272 |
|
} |
273 |
|
} |
274 |
|
} |
275 |
|
|
276 |
|
/** |
277 |
|
* Makes sure that the xTotal and yTotal fields are set up correctly. A call |
278 |
|
* to {@link #invalidateLayout} sets these fields to null and they have to be |
279 |
|
* recomputed. |
280 |
|
*/ |
281 |
|
private void checkTotalRequirements() |
282 |
|
{ |
283 |
|
if (xTotal == null || yTotal == null) |
284 |
|
{ |
285 |
|
checkRequirements(); |
286 |
|
xTotal = SizeRequirements.getAlignedSizeRequirements(xChildren); |
287 |
|
yTotal = SizeRequirements.getAlignedSizeRequirements(yChildren); |
288 |
|
} |
289 |
|
} |
290 |
|
|
291 |
|
/** |
292 |
|
* Makes sure that the offsetsX, offsetsY, spansX and spansY fields are set |
293 |
|
* up correctly. A call to {@link #invalidateLayout} sets these fields |
294 |
|
* to null and they have to be recomputed. |
295 |
|
*/ |
296 |
|
private void checkLayout() |
297 |
|
{ |
298 |
|
if (offsetsX == null || offsetsY == null || spansX == null |
299 |
|
|| spansY == null) |
300 |
|
{ |
301 |
|
checkRequirements(); |
302 |
|
checkTotalRequirements(); |
303 |
|
int len = target.getComponents().length; |
304 |
|
offsetsX = new int[len]; |
305 |
|
offsetsY = new int[len]; |
306 |
|
spansX = new int[len]; |
307 |
|
spansY = new int[len]; |
308 |
|
SizeRequirements.calculateAlignedPositions(target.getWidth(), xTotal, |
309 |
|
xChildren, offsetsX, spansX); |
310 |
|
SizeRequirements.calculateAlignedPositions(target.getHeight(), yTotal, |
311 |
|
yChildren, offsetsY, spansY); |
312 |
|
} |
313 |
|
} |
314 |
} |
} |