48 |
public class BorderLayout implements LayoutManager2, java.io.Serializable |
public class BorderLayout implements LayoutManager2, java.io.Serializable |
49 |
{ |
{ |
50 |
|
|
51 |
/* |
/** |
52 |
* Static Variables |
* Constant indicating the top of the container |
53 |
*/ |
*/ |
54 |
|
public static final String NORTH = "North"; |
|
/** |
|
|
* Constant indicating the top of the container |
|
|
*/ |
|
|
public static final String NORTH = "North"; |
|
55 |
|
|
56 |
/** |
/** |
57 |
* Constant indicating the bottom of the container |
* Constant indicating the bottom of the container |
58 |
*/ |
*/ |
59 |
public static final String SOUTH = "South"; |
public static final String SOUTH = "South"; |
60 |
|
|
61 |
/** |
/** |
62 |
* Constant indicating the right side of the container |
* Constant indicating the right side of the container |
63 |
*/ |
*/ |
64 |
public static final String EAST = "East"; |
public static final String EAST = "East"; |
65 |
|
|
66 |
/** |
/** |
67 |
* Constant indicating the left side of the container |
* Constant indicating the left side of the container |
68 |
*/ |
*/ |
69 |
public static final String WEST = "West"; |
public static final String WEST = "West"; |
70 |
|
|
71 |
/** |
/** |
72 |
* Constant indicating the center of the container |
* Constant indicating the center of the container |
73 |
*/ |
*/ |
74 |
public static final String CENTER = "Center"; |
public static final String CENTER = "Center"; |
75 |
|
|
76 |
|
|
77 |
/** |
/** |
87 |
*/ |
*/ |
88 |
public static final String BEFORE_FIRST_LINE = "First"; |
public static final String BEFORE_FIRST_LINE = "First"; |
89 |
|
|
|
|
|
90 |
/** |
/** |
91 |
* The constant indicating the position after the last line of the |
* The constant indicating the position after the last line of the |
92 |
* layout. The exact position depends on the writing system: For a |
* layout. The exact position depends on the writing system: For a |
100 |
*/ |
*/ |
101 |
public static final String AFTER_LAST_LINE = "Last"; |
public static final String AFTER_LAST_LINE = "Last"; |
102 |
|
|
|
|
|
103 |
/** |
/** |
104 |
* The constant indicating the position before the first item of the |
* The constant indicating the position before the first item of the |
105 |
* layout. The exact position depends on the writing system: For a |
* layout. The exact position depends on the writing system: For a |
113 |
*/ |
*/ |
114 |
public static final String BEFORE_LINE_BEGINS = "Before"; |
public static final String BEFORE_LINE_BEGINS = "Before"; |
115 |
|
|
|
|
|
116 |
/** |
/** |
117 |
* The constant indicating the position after the last item of the |
* The constant indicating the position after the last item of the |
118 |
* layout. The exact position depends on the writing system: For a |
* layout. The exact position depends on the writing system: For a |
126 |
*/ |
*/ |
127 |
public static final String AFTER_LINE_ENDS = "After"; |
public static final String AFTER_LINE_ENDS = "After"; |
128 |
|
|
|
|
|
129 |
/** |
/** |
130 |
* The constant indicating the position before the first line of the |
* The constant indicating the position before the first line of the |
131 |
* layout. The exact position depends on the writing system: For a |
* layout. The exact position depends on the writing system: For a |
136 |
*/ |
*/ |
137 |
public static final String PAGE_START = BEFORE_FIRST_LINE; |
public static final String PAGE_START = BEFORE_FIRST_LINE; |
138 |
|
|
|
|
|
139 |
/** |
/** |
140 |
* The constant indicating the position after the last line of the |
* The constant indicating the position after the last line of the |
141 |
* layout. The exact position depends on the writing system: For a |
* layout. The exact position depends on the writing system: For a |
146 |
*/ |
*/ |
147 |
public static final String PAGE_END = AFTER_LAST_LINE; |
public static final String PAGE_END = AFTER_LAST_LINE; |
148 |
|
|
|
|
|
149 |
/** |
/** |
150 |
* The constant indicating the position before the first item of the |
* The constant indicating the position before the first item of the |
151 |
* layout. The exact position depends on the writing system: For a |
* layout. The exact position depends on the writing system: For a |
156 |
*/ |
*/ |
157 |
public static final String LINE_START = BEFORE_LINE_BEGINS; |
public static final String LINE_START = BEFORE_LINE_BEGINS; |
158 |
|
|
|
|
|
159 |
/** |
/** |
160 |
* The constant indicating the position after the last item of the |
* The constant indicating the position after the last item of the |
161 |
* layout. The exact position depends on the writing system: For a |
* layout. The exact position depends on the writing system: For a |
167 |
public static final String LINE_END = AFTER_LINE_ENDS; |
public static final String LINE_END = AFTER_LINE_ENDS; |
168 |
|
|
169 |
|
|
170 |
|
/** |
171 |
|
* Serialization constant. |
172 |
|
*/ |
173 |
|
private static final long serialVersionUID = -8658291919501921765L; |
174 |
|
|
|
// Serialization constant |
|
|
private static final long serialVersionUID = -8658291919501921765L; |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/* |
|
|
* Instance Variables |
|
|
*/ |
|
|
|
|
|
/** |
|
|
* @serial |
|
|
*/ |
|
|
private Component north; |
|
|
|
|
|
/** |
|
|
* @serial |
|
|
*/ |
|
|
private Component south; |
|
|
|
|
|
/** |
|
|
* @serial |
|
|
*/ |
|
|
private Component east; |
|
|
|
|
|
/** |
|
|
* @serial |
|
|
*/ |
|
|
private Component west; |
|
|
|
|
|
/** |
|
|
* @serial |
|
|
*/ |
|
|
private Component center; |
|
|
|
|
|
/** |
|
|
* @serial |
|
|
*/ |
|
|
private Component firstLine; |
|
|
|
|
|
/** |
|
|
* @serial |
|
|
*/ |
|
|
private Component lastLine; |
|
|
|
|
|
/** |
|
|
* @serial |
|
|
*/ |
|
|
private Component firstItem; |
|
|
|
|
|
/** |
|
|
* @serial |
|
|
*/ |
|
|
private Component lastItem; |
|
|
|
|
|
/** |
|
|
* @serial The horizontal gap between components |
|
|
*/ |
|
|
private int hgap; |
|
|
|
|
|
/** |
|
|
* @serial The vertical gap between components |
|
|
*/ |
|
|
private int vgap; |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/* |
|
|
* Constructors |
|
|
*/ |
|
|
|
|
|
/** |
|
|
* Initializes a new instance of <code>BorderLayout</code> with no |
|
|
* horiztonal or vertical gaps between components. |
|
|
*/ |
|
|
public |
|
|
BorderLayout() |
|
|
{ |
|
|
this(0,0); |
|
|
} |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/** |
|
|
* Initializes a new instance of <code>BorderLayout</code> with the |
|
|
* specified horiztonal and vertical gaps between components. |
|
|
* |
|
|
* @param hgap The horizontal gap between components. |
|
|
* @param vgap The vertical gap between components. |
|
|
*/ |
|
|
public |
|
|
BorderLayout(int hgap, int vgap) |
|
|
{ |
|
|
this.hgap = hgap; |
|
|
this.vgap = vgap; |
|
|
} |
|
|
|
|
|
/*************************************************************************/ |
|
175 |
|
|
176 |
/* |
/** |
177 |
* Instance Variables |
* @serial |
178 |
*/ |
*/ |
179 |
|
private Component north; |
|
/** |
|
|
* Returns the horitzontal gap value. |
|
|
* |
|
|
* @return The horitzontal gap value. |
|
|
*/ |
|
|
public int |
|
|
getHgap() |
|
|
{ |
|
|
return(hgap); |
|
|
} |
|
180 |
|
|
181 |
/*************************************************************************/ |
/** |
182 |
|
* @serial |
183 |
|
*/ |
184 |
|
private Component south; |
185 |
|
|
186 |
/** |
/** |
187 |
* Sets the horizontal gap to the specified value. |
* @serial |
188 |
* |
*/ |
189 |
* @param hgap The new horizontal gap. |
private Component east; |
|
*/ |
|
|
public void |
|
|
setHgap(int hgap) |
|
|
{ |
|
|
this.hgap = hgap; |
|
|
} |
|
190 |
|
|
191 |
/*************************************************************************/ |
/** |
192 |
|
* @serial |
193 |
|
*/ |
194 |
|
private Component west; |
195 |
|
|
196 |
/** |
/** |
197 |
* Returns the vertical gap value. |
* @serial |
|
* |
|
|
* @return The vertical gap value. |
|
198 |
*/ |
*/ |
199 |
public int |
private Component center; |
|
getVgap() |
|
|
{ |
|
|
return(vgap); |
|
|
} |
|
200 |
|
|
201 |
/*************************************************************************/ |
/** |
202 |
|
* @serial |
203 |
|
*/ |
204 |
|
private Component firstLine; |
205 |
|
|
206 |
/** |
/** |
207 |
* Sets the vertical gap to the specified value. |
* @serial |
208 |
* |
*/ |
209 |
* @param vgap The new vertical gap value. |
private Component lastLine; |
|
*/ |
|
|
public void |
|
|
setVgap(int vgap) |
|
|
{ |
|
|
this.vgap = vgap; |
|
|
} |
|
210 |
|
|
211 |
/*************************************************************************/ |
/** |
212 |
|
* @serial |
213 |
|
*/ |
214 |
|
private Component firstItem; |
215 |
|
|
216 |
/** |
/** |
217 |
* Adds a component to the layout in the specified constraint position, |
* @serial |
218 |
* which must be one of the string constants defined in this class. |
*/ |
219 |
* |
private Component lastItem; |
|
* @param component The component to add. |
|
|
* @param constraints The constraint string. |
|
|
* |
|
|
* @exception IllegalArgumentException If the constraint object is not |
|
|
* a string, or is not one of the specified constants in this class. |
|
|
*/ |
|
|
public void |
|
|
addLayoutComponent(Component component, Object constraints) |
|
|
{ |
|
|
if (constraints != null && ! (constraints instanceof String)) |
|
|
throw new IllegalArgumentException("Constraint must be a string"); |
|
220 |
|
|
221 |
addLayoutComponent((String) constraints, component); |
/** |
222 |
} |
* @serial The horizontal gap between components |
223 |
|
*/ |
224 |
|
private int hgap; |
225 |
|
|
226 |
/*************************************************************************/ |
/** |
227 |
|
* @serial The vertical gap between components |
228 |
|
*/ |
229 |
|
private int vgap; |
230 |
|
|
|
/** |
|
|
* Adds a component to the layout in the specified constraint position, |
|
|
* which must be one of the string constants defined in this class. |
|
|
* |
|
|
* @param constraints The constraint string. |
|
|
* @param component The component to add. |
|
|
* |
|
|
* @exception IllegalArgumentException If the constraint object is not |
|
|
* one of the specified constants in this class. |
|
|
* |
|
|
* @deprecated This method is deprecated in favor of |
|
|
* <code>addLayoutComponent(Component, Object)</code>. |
|
|
*/ |
|
|
public void |
|
|
addLayoutComponent(String constraints, Component component) |
|
|
{ |
|
|
String str = constraints; |
|
231 |
|
|
232 |
if (str == null || str.equals(CENTER)) |
/** |
233 |
center = component; |
* Initializes a new instance of <code>BorderLayout</code> with no |
234 |
else if (str.equals(NORTH)) |
* horiztonal or vertical gaps between components. |
235 |
north = component; |
*/ |
236 |
else if (str.equals(SOUTH)) |
public BorderLayout() |
237 |
south = component; |
{ |
238 |
else if (str.equals(EAST)) |
this(0,0); |
239 |
east = component; |
} |
|
else if (str.equals(WEST)) |
|
|
west = component; |
|
|
else if (str.equals(BEFORE_FIRST_LINE)) |
|
|
firstLine = component; |
|
|
else if (str.equals(AFTER_LAST_LINE)) |
|
|
lastLine = component; |
|
|
else if (str.equals(BEFORE_LINE_BEGINS)) |
|
|
firstItem = component; |
|
|
else if (str.equals(AFTER_LINE_ENDS)) |
|
|
lastItem = component; |
|
|
else |
|
|
throw new IllegalArgumentException("Constraint value not valid: " + str); |
|
|
} |
|
240 |
|
|
241 |
/*************************************************************************/ |
/** |
242 |
|
* Initializes a new instance of <code>BorderLayout</code> with the |
243 |
|
* specified horiztonal and vertical gaps between components. |
244 |
|
* |
245 |
|
* @param hgap The horizontal gap between components. |
246 |
|
* @param vgap The vertical gap between components. |
247 |
|
*/ |
248 |
|
public BorderLayout(int hgap, int vgap) |
249 |
|
{ |
250 |
|
this.hgap = hgap; |
251 |
|
this.vgap = vgap; |
252 |
|
} |
253 |
|
|
254 |
/** |
/** |
255 |
* Removes the specified component from the layout. |
* Returns the horitzontal gap value. |
256 |
* |
* |
257 |
* @param component The component to remove from the layout. |
* @return The horitzontal gap value. |
258 |
*/ |
*/ |
259 |
public void |
public int getHgap() |
260 |
removeLayoutComponent(Component component) |
{ |
261 |
{ |
return(hgap); |
262 |
if (north == component) |
} |
|
north = null; |
|
|
if (south == component) |
|
|
south = null; |
|
|
if (east == component) |
|
|
east = null; |
|
|
if (west == component) |
|
|
west = null; |
|
|
if (center == component) |
|
|
center = null; |
|
|
if (firstItem == component) |
|
|
firstItem = null; |
|
|
if (lastItem == component) |
|
|
lastItem = null; |
|
|
if (firstLine == component) |
|
|
firstLine = null; |
|
|
if (lastLine == component) |
|
|
lastLine = null; |
|
|
} |
|
263 |
|
|
264 |
/*************************************************************************/ |
/** |
265 |
|
* Sets the horizontal gap to the specified value. |
266 |
|
* |
267 |
|
* @param hgap The new horizontal gap. |
268 |
|
*/ |
269 |
|
public void setHgap(int hgap) |
270 |
|
{ |
271 |
|
this.hgap = hgap; |
272 |
|
} |
273 |
|
|
274 |
/** |
/** |
275 |
* Returns the minimum size of the specified container using this layout. |
* Returns the vertical gap value. |
276 |
* |
* |
277 |
* @param target The container to calculate the minimum size for. |
* @return The vertical gap value. |
278 |
* |
*/ |
279 |
* @return The minimum size of the container |
public int getVgap() |
280 |
*/ |
{ |
281 |
public Dimension |
return(vgap); |
282 |
minimumLayoutSize(Container target) |
} |
|
{ |
|
|
return calcSize(target, MIN); |
|
|
} |
|
283 |
|
|
284 |
/*************************************************************************/ |
/** |
285 |
|
* Sets the vertical gap to the specified value. |
286 |
|
* |
287 |
|
* @param vgap The new vertical gap value. |
288 |
|
*/ |
289 |
|
public void setVgap(int vgap) |
290 |
|
{ |
291 |
|
this.vgap = vgap; |
292 |
|
} |
293 |
|
|
294 |
/** |
/** |
295 |
* Returns the preferred size of the specified container using this layout. |
* Adds a component to the layout in the specified constraint position, |
296 |
* |
* which must be one of the string constants defined in this class. |
297 |
* @param target The container to calculate the preferred size for. |
* |
298 |
* |
* @param component The component to add. |
299 |
* @return The preferred size of the container |
* @param constraints The constraint string. |
300 |
*/ |
* |
301 |
public Dimension |
* @exception IllegalArgumentException If the constraint object is not |
302 |
preferredLayoutSize(Container target) |
* a string, or is not one of the specified constants in this class. |
303 |
{ |
*/ |
304 |
return calcSize(target, PREF); |
public void addLayoutComponent(Component component, Object constraints) |
305 |
} |
{ |
306 |
|
if (constraints != null && ! (constraints instanceof String)) |
307 |
|
throw new IllegalArgumentException("Constraint must be a string"); |
308 |
|
|
309 |
/*************************************************************************/ |
addLayoutComponent((String) constraints, component); |
310 |
|
} |
311 |
|
|
312 |
/** |
/** |
313 |
* Returns the maximum size of the specified container using this layout. |
* Adds a component to the layout in the specified constraint position, |
314 |
* |
* which must be one of the string constants defined in this class. |
315 |
* @param target The container to calculate the maximum size for. |
* |
316 |
* |
* @param constraints The constraint string. |
317 |
* @return The maximum size of the container |
* @param component The component to add. |
318 |
*/ |
* |
319 |
public Dimension |
* @exception IllegalArgumentException If the constraint object is not |
320 |
maximumLayoutSize(Container target) |
* one of the specified constants in this class. |
321 |
{ |
* |
322 |
return calcSize(target, MAX); |
* @deprecated This method is deprecated in favor of |
323 |
} |
* <code>addLayoutComponent(Component, Object)</code>. |
324 |
|
*/ |
325 |
|
public void addLayoutComponent(String constraints, Component component) |
326 |
|
{ |
327 |
|
String str = constraints; |
328 |
|
|
329 |
|
if (str == null || str.equals(CENTER)) |
330 |
|
center = component; |
331 |
|
else if (str.equals(NORTH)) |
332 |
|
north = component; |
333 |
|
else if (str.equals(SOUTH)) |
334 |
|
south = component; |
335 |
|
else if (str.equals(EAST)) |
336 |
|
east = component; |
337 |
|
else if (str.equals(WEST)) |
338 |
|
west = component; |
339 |
|
else if (str.equals(BEFORE_FIRST_LINE)) |
340 |
|
firstLine = component; |
341 |
|
else if (str.equals(AFTER_LAST_LINE)) |
342 |
|
lastLine = component; |
343 |
|
else if (str.equals(BEFORE_LINE_BEGINS)) |
344 |
|
firstItem = component; |
345 |
|
else if (str.equals(AFTER_LINE_ENDS)) |
346 |
|
lastItem = component; |
347 |
|
else |
348 |
|
throw new IllegalArgumentException("Constraint value not valid: " + str); |
349 |
|
} |
350 |
|
|
351 |
/*************************************************************************/ |
/** |
352 |
|
* Removes the specified component from the layout. |
353 |
|
* |
354 |
|
* @param component The component to remove from the layout. |
355 |
|
*/ |
356 |
|
public void removeLayoutComponent(Component component) |
357 |
|
{ |
358 |
|
if (north == component) |
359 |
|
north = null; |
360 |
|
if (south == component) |
361 |
|
south = null; |
362 |
|
if (east == component) |
363 |
|
east = null; |
364 |
|
if (west == component) |
365 |
|
west = null; |
366 |
|
if (center == component) |
367 |
|
center = null; |
368 |
|
if (firstItem == component) |
369 |
|
firstItem = null; |
370 |
|
if (lastItem == component) |
371 |
|
lastItem = null; |
372 |
|
if (firstLine == component) |
373 |
|
firstLine = null; |
374 |
|
if (lastLine == component) |
375 |
|
lastLine = null; |
376 |
|
} |
377 |
|
|
378 |
/** |
/** |
379 |
* Returns the X axis alignment, which is a <code>float</code> indicating |
* Returns the minimum size of the specified container using this layout. |
380 |
* where along the X axis this container wishs to position its layout. |
* |
381 |
* 0 indicates align to the left, 1 indicates align to the right, and 0.5 |
* @param target The container to calculate the minimum size for. |
382 |
* indicates align to the center. |
* |
383 |
* |
* @return The minimum size of the container |
384 |
* @param parent The parent container. |
*/ |
385 |
* |
public Dimension minimumLayoutSize(Container target) |
386 |
* @return The X alignment value. |
{ |
387 |
*/ |
return calcSize(target, MIN); |
388 |
public float |
} |
|
getLayoutAlignmentX(Container parent) |
|
|
{ |
|
|
return(parent.getAlignmentX()); |
|
|
} |
|
389 |
|
|
390 |
/*************************************************************************/ |
/** |
391 |
|
* Returns the preferred size of the specified container using this layout. |
392 |
|
* |
393 |
|
* @param target The container to calculate the preferred size for. |
394 |
|
* |
395 |
|
* @return The preferred size of the container |
396 |
|
*/ |
397 |
|
public Dimension preferredLayoutSize(Container target) |
398 |
|
{ |
399 |
|
return calcSize(target, PREF); |
400 |
|
} |
401 |
|
|
402 |
/** |
/** |
403 |
* Returns the Y axis alignment, which is a <code>float</code> indicating |
* Returns the maximum size of the specified container using this layout. |
404 |
* where along the Y axis this container wishs to position its layout. |
* |
405 |
* 0 indicates align to the top, 1 indicates align to the bottom, and 0.5 |
* @param target The container to calculate the maximum size for. |
406 |
* indicates align to the center. |
* |
407 |
* |
* @return The maximum size of the container |
408 |
* @param parent The parent container. |
*/ |
409 |
* |
public Dimension maximumLayoutSize(Container target) |
410 |
* @return The Y alignment value. |
{ |
411 |
*/ |
return calcSize(target, MAX); |
412 |
public float |
} |
|
getLayoutAlignmentY(Container parent) |
|
|
{ |
|
|
return(parent.getAlignmentY()); |
|
|
} |
|
413 |
|
|
414 |
/*************************************************************************/ |
/** |
415 |
|
* Returns the X axis alignment, which is a <code>float</code> indicating |
416 |
|
* where along the X axis this container wishs to position its layout. |
417 |
|
* 0 indicates align to the left, 1 indicates align to the right, and 0.5 |
418 |
|
* indicates align to the center. |
419 |
|
* |
420 |
|
* @param parent The parent container. |
421 |
|
* |
422 |
|
* @return The X alignment value. |
423 |
|
*/ |
424 |
|
public float getLayoutAlignmentX(Container parent) |
425 |
|
{ |
426 |
|
return(parent.getAlignmentX()); |
427 |
|
} |
428 |
|
|
429 |
/** |
/** |
430 |
* Instructs this object to discard any layout information it might |
* Returns the Y axis alignment, which is a <code>float</code> indicating |
431 |
* have cached. |
* where along the Y axis this container wishs to position its layout. |
432 |
* |
* 0 indicates align to the top, 1 indicates align to the bottom, and 0.5 |
433 |
* @param parent The parent container. |
* indicates align to the center. |
434 |
*/ |
* |
435 |
public void |
* @param parent The parent container. |
436 |
invalidateLayout(Container parent) |
* |
437 |
{ |
* @return The Y alignment value. |
438 |
} |
*/ |
439 |
|
public float getLayoutAlignmentY(Container parent) |
440 |
|
{ |
441 |
|
return(parent.getAlignmentY()); |
442 |
|
} |
443 |
|
|
444 |
/*************************************************************************/ |
/** |
445 |
|
* Instructs this object to discard any layout information it might |
446 |
|
* have cached. |
447 |
|
* |
448 |
|
* @param parent The parent container. |
449 |
|
*/ |
450 |
|
public void invalidateLayout(Container parent) |
451 |
|
{ |
452 |
|
// FIXME: Implement this properly! |
453 |
|
} |
454 |
|
|
455 |
/** |
/** |
456 |
* Lays out the specified container according to the constraints |
* Lays out the specified container according to the constraints |
457 |
* in this object. |
* in this object. |
458 |
* |
* |
459 |
* @param target The container to lay out. |
* @param target The container to lay out. |
460 |
*/ |
*/ |
461 |
public void |
public void layoutContainer(Container target) |
462 |
layoutContainer(Container target) |
{ |
463 |
{ |
synchronized (target.getTreeLock ()) |
464 |
synchronized (target.getTreeLock ()) |
{ |
465 |
{ |
Insets i = target.getInsets(); |
466 |
Insets i = target.getInsets(); |
|
467 |
|
ComponentOrientation orient = target.getComponentOrientation (); |
468 |
ComponentOrientation orient = target.getComponentOrientation (); |
boolean left_to_right = orient.isLeftToRight (); |
469 |
boolean left_to_right = orient.isLeftToRight (); |
|
470 |
|
Component my_north = north; |
471 |
Component my_north = north; |
Component my_east = east; |
472 |
Component my_east = east; |
Component my_south = south; |
473 |
Component my_south = south; |
Component my_west = west; |
474 |
Component my_west = west; |
|
475 |
|
// Note that we currently don't handle vertical layouts. Neither |
476 |
// Note that we currently don't handle vertical layouts. Neither |
// does JDK 1.3. |
477 |
// does JDK 1.3. |
if (firstLine != null) |
478 |
if (firstLine != null) |
my_north = firstLine; |
479 |
my_north = firstLine; |
if (lastLine != null) |
480 |
if (lastLine != null) |
my_south = lastLine; |
481 |
my_south = lastLine; |
if (firstItem != null) |
482 |
if (firstItem != null) |
{ |
483 |
{ |
if (left_to_right) |
484 |
if (left_to_right) |
my_west = firstItem; |
485 |
my_west = firstItem; |
else |
486 |
else |
my_east = firstItem; |
487 |
my_east = firstItem; |
} |
488 |
} |
if (lastItem != null) |
489 |
if (lastItem != null) |
{ |
490 |
{ |
if (left_to_right) |
491 |
if (left_to_right) |
my_east = lastItem; |
492 |
my_east = lastItem; |
else |
493 |
else |
my_west = lastItem; |
494 |
my_west = lastItem; |
} |
495 |
} |
|
496 |
|
Dimension c = calcCompSize(center, PREF); |
497 |
Dimension c = calcCompSize(center, PREF); |
Dimension n = calcCompSize(my_north, PREF); |
498 |
Dimension n = calcCompSize(my_north, PREF); |
Dimension s = calcCompSize(my_south, PREF); |
499 |
Dimension s = calcCompSize(my_south, PREF); |
Dimension e = calcCompSize(my_east, PREF); |
500 |
Dimension e = calcCompSize(my_east, PREF); |
Dimension w = calcCompSize(my_west, PREF); |
501 |
Dimension w = calcCompSize(my_west, PREF); |
int targetWidth = target.getWidth(); |
502 |
int targetWidth = target.getWidth(); |
int targetHeight = target.getHeight(); |
|
int targetHeight = target.getHeight(); |
|
503 |
|
|
504 |
/* |
/* |
505 |
<-> hgap <-> hgap |
<-> hgap <-> hgap |
506 |
+----------------------------+ } |
+----------------------------+ } |
507 |
|t | } i.top |
|t | } i.top |
520 |
<----------------------> |
<----------------------> |
521 |
<--> ww <--> |
<--> ww <--> |
522 |
i.left i.right |
i.left i.right |
523 |
*/ |
*/ |
|
|
|
|
int x1 = i.left; |
|
|
int x2 = x1 + w.width + (w.width == 0 ? 0 : hgap); |
|
|
int x3; |
|
|
if (targetWidth <= i.right + e.width) |
|
|
x3 = x2 + w.width + (w.width == 0 ? 0 : hgap); |
|
|
else |
|
|
x3 = targetWidth - i.right - e.width; |
|
|
int ww = targetWidth - i.right - i.left; |
|
|
|
|
|
int y1 = i.top; |
|
|
int y2 = y1 + n.height + (n.height == 0 ? 0 : vgap); |
|
|
int midh = Math.max(e.height, Math.max(w.height, c.height)); |
|
|
int y3; |
|
|
if (targetHeight <= i.bottom + s.height) |
|
|
y3 = y2 + midh + vgap; |
|
|
else |
|
|
y3 = targetHeight - i.bottom - s.height; |
|
|
int hh = y3-y2-(s.height == 0 ? 0 : vgap); |
|
|
|
|
|
setBounds(center, x2, y2, x3-x2-(w.width == 0 ? 0 : hgap), hh); |
|
|
setBounds(my_north, x1, y1, ww, n.height); |
|
|
setBounds(my_south, x1, y3, ww, s.height); |
|
|
setBounds(my_west, x1, y2, w.width, hh); |
|
|
setBounds(my_east, x3, y2, e.width, hh); |
|
|
} |
|
|
} |
|
|
|
|
|
/*************************************************************************/ |
|
|
|
|
|
/** |
|
|
* Returns a string representation of this layout manager. |
|
|
* |
|
|
* @return A string representation of this object. |
|
|
*/ |
|
|
public String |
|
|
toString() |
|
|
{ |
|
|
return getClass().getName() + "[hgap=" + hgap + ",vgap=" + vgap + "]"; |
|
|
} |
|
524 |
|
|
525 |
private void |
int x1 = i.left; |
526 |
setBounds(Component comp, int x, int y, int w, int h) |
int x2 = x1 + w.width + (w.width == 0 ? 0 : hgap); |
527 |
{ |
int x3; |
528 |
if (comp == null) |
if (targetWidth <= i.right + e.width) |
529 |
return; |
x3 = x2 + w.width + (w.width == 0 ? 0 : hgap); |
530 |
comp.setBounds(x, y, w, h); |
else |
531 |
} |
x3 = targetWidth - i.right - e.width; |
532 |
|
int ww = targetWidth - i.right - i.left; |
533 |
|
|
534 |
|
int y1 = i.top; |
535 |
|
int y2 = y1 + n.height + (n.height == 0 ? 0 : vgap); |
536 |
|
int midh = Math.max(e.height, Math.max(w.height, c.height)); |
537 |
|
int y3; |
538 |
|
if (targetHeight <= i.bottom + s.height) |
539 |
|
y3 = y2 + midh + vgap; |
540 |
|
else |
541 |
|
y3 = targetHeight - i.bottom - s.height; |
542 |
|
int hh = y3-y2-(s.height == 0 ? 0 : vgap); |
543 |
|
|
544 |
|
setBounds(center, x2, y2, x3-x2-(w.width == 0 ? 0 : hgap), hh); |
545 |
|
setBounds(my_north, x1, y1, ww, n.height); |
546 |
|
setBounds(my_south, x1, y3, ww, s.height); |
547 |
|
setBounds(my_west, x1, y2, w.width, hh); |
548 |
|
setBounds(my_east, x3, y2, e.width, hh); |
549 |
|
} |
550 |
|
} |
551 |
|
|
552 |
// Some constants for use with calcSize(). |
/** |
553 |
private static final int MIN = 0; |
* Returns a string representation of this layout manager. |
554 |
private static final int MAX = 1; |
* |
555 |
private static final int PREF = 2; |
* @return A string representation of this object. |
556 |
|
*/ |
557 |
|
public String toString() |
558 |
|
{ |
559 |
|
return getClass().getName() + "[hgap=" + hgap + ",vgap=" + vgap + "]"; |
560 |
|
} |
561 |
|
|
562 |
private Dimension |
/** |
563 |
calcCompSize(Component comp, int what) |
* FIXME: Document me! |
564 |
{ |
*/ |
565 |
if (comp == null || !comp.isVisible()) |
private void setBounds(Component comp, int x, int y, int w, int h) |
566 |
return new Dimension(0, 0); |
{ |
567 |
if (what == MIN) |
if (comp == null) |
568 |
return comp.getMinimumSize(); |
return; |
569 |
else if (what == MAX) |
comp.setBounds(x, y, w, h); |
570 |
return comp.getMaximumSize(); |
} |
571 |
return comp.getPreferredSize(); |
|
572 |
} |
// FIXME: Maybe move to top of file. |
573 |
|
// Some constants for use with calcSize(). |
574 |
|
private static final int MIN = 0; |
575 |
|
private static final int MAX = 1; |
576 |
|
private static final int PREF = 2; |
577 |
|
|
578 |
|
private Dimension calcCompSize(Component comp, int what) |
579 |
|
{ |
580 |
|
if (comp == null || !comp.isVisible()) |
581 |
|
return new Dimension(0, 0); |
582 |
|
if (what == MIN) |
583 |
|
return comp.getMinimumSize(); |
584 |
|
else if (what == MAX) |
585 |
|
return comp.getMaximumSize(); |
586 |
|
return comp.getPreferredSize(); |
587 |
|
} |
588 |
|
|
589 |
// This is a helper function used to compute the various sizes for |
/** |
590 |
// this layout. |
* This is a helper function used to compute the various sizes for |
591 |
private Dimension |
* this layout. |
592 |
calcSize(Container target, int what) |
*/ |
593 |
{ |
private Dimension calcSize(Container target, int what) |
594 |
synchronized (target.getTreeLock ()) |
{ |
595 |
{ |
synchronized (target.getTreeLock ()) |
596 |
Insets ins = target.getInsets(); |
{ |
597 |
|
Insets ins = target.getInsets(); |
598 |
ComponentOrientation orient = target.getComponentOrientation (); |
|
599 |
boolean left_to_right = orient.isLeftToRight (); |
ComponentOrientation orient = target.getComponentOrientation (); |
600 |
|
boolean left_to_right = orient.isLeftToRight (); |
601 |
Component my_north = north; |
|
602 |
Component my_east = east; |
Component my_north = north; |
603 |
Component my_south = south; |
Component my_east = east; |
604 |
Component my_west = west; |
Component my_south = south; |
605 |
|
Component my_west = west; |
606 |
// Note that we currently don't handle vertical layouts. Neither |
|
607 |
// does JDK 1.3. |
// Note that we currently don't handle vertical layouts. Neither |
608 |
if (firstLine != null) |
// does JDK 1.3. |
609 |
my_north = firstLine; |
if (firstLine != null) |
610 |
if (lastLine != null) |
my_north = firstLine; |
611 |
my_south = lastLine; |
if (lastLine != null) |
612 |
if (firstItem != null) |
my_south = lastLine; |
613 |
{ |
if (firstItem != null) |
614 |
if (left_to_right) |
{ |
615 |
my_west = firstItem; |
if (left_to_right) |
616 |
else |
my_west = firstItem; |
617 |
my_east = firstItem; |
else |
618 |
} |
my_east = firstItem; |
619 |
if (lastItem != null) |
} |
620 |
{ |
if (lastItem != null) |
621 |
if (left_to_right) |
{ |
622 |
my_east = lastItem; |
if (left_to_right) |
623 |
else |
my_east = lastItem; |
624 |
my_west = lastItem; |
else |
625 |
} |
my_west = lastItem; |
626 |
|
} |
627 |
Dimension ndim = calcCompSize(my_north, what); |
|
628 |
Dimension sdim = calcCompSize(my_south, what); |
Dimension ndim = calcCompSize(my_north, what); |
629 |
Dimension edim = calcCompSize(my_east, what); |
Dimension sdim = calcCompSize(my_south, what); |
630 |
Dimension wdim = calcCompSize(my_west, what); |
Dimension edim = calcCompSize(my_east, what); |
631 |
Dimension cdim = calcCompSize(center, what); |
Dimension wdim = calcCompSize(my_west, what); |
632 |
|
Dimension cdim = calcCompSize(center, what); |
633 |
int width = edim.width + cdim.width + wdim.width + (hgap * 2); |
|
634 |
// check for overflow |
int width = edim.width + cdim.width + wdim.width + (hgap * 2); |
635 |
if (width < edim.width || width < cdim.width || width < cdim.width) |
// Check for overflow. |
636 |
|
if (width < edim.width || width < cdim.width || width < cdim.width) |
637 |
width = Integer.MAX_VALUE; |
width = Integer.MAX_VALUE; |
638 |
|
|
639 |
if (ndim.width > width) |
if (ndim.width > width) |
640 |
width = ndim.width; |
width = ndim.width; |
641 |
if (sdim.width > width) |
if (sdim.width > width) |
642 |
width = sdim.width; |
width = sdim.width; |
643 |
|
|
644 |
width += (ins.left + ins.right); |
width += (ins.left + ins.right); |
645 |
|
|
646 |
int height = edim.height; |
int height = edim.height; |
647 |
if (cdim.height > height) |
if (cdim.height > height) |
648 |
height = cdim.height; |
height = cdim.height; |
649 |
if (wdim.height > height) |
if (wdim.height > height) |
650 |
height = wdim.height; |
height = wdim.height; |
651 |
|
|
652 |
int addedHeight = height + (ndim.height + sdim.height + (vgap * 2) |
int addedHeight = height + (ndim.height + sdim.height + (vgap * 2) |
653 |
+ ins.top + ins.bottom); |
+ ins.top + ins.bottom); |
654 |
// check for overflow |
// Check for overflow. |
655 |
if (addedHeight < height) |
if (addedHeight < height) |
656 |
height = Integer.MAX_VALUE; |
height = Integer.MAX_VALUE; |
657 |
else |
else |
658 |
height = addedHeight; |
height = addedHeight; |
659 |
|
|
660 |
return(new Dimension(width, height)); |
return(new Dimension(width, height)); |
661 |
} |
} |
662 |
|
} |
663 |
} |
} |
|
} // class BorderLayout |
|