38 |
|
|
39 |
package java.awt; |
package java.awt; |
40 |
|
|
41 |
|
|
42 |
/** |
/** |
43 |
* This class implements a layout manager that positions components |
* This class implements a layout manager that positions components |
44 |
* in certain sectors of the parent container. |
* in certain sectors of the parent container. |
175 |
|
|
176 |
|
|
177 |
/** |
/** |
178 |
|
* @serial The horizontal gap between components |
179 |
|
*/ |
180 |
|
private int hgap; |
181 |
|
|
182 |
|
/** |
183 |
|
* @serial The vertical gap between components |
184 |
|
*/ |
185 |
|
private int vgap; |
186 |
|
|
187 |
|
/** |
188 |
* @serial |
* @serial |
189 |
*/ |
*/ |
190 |
private Component north; |
private Component north; |
192 |
/** |
/** |
193 |
* @serial |
* @serial |
194 |
*/ |
*/ |
195 |
private Component south; |
private Component west; |
196 |
|
|
197 |
/** |
/** |
198 |
* @serial |
* @serial |
202 |
/** |
/** |
203 |
* @serial |
* @serial |
204 |
*/ |
*/ |
205 |
private Component west; |
private Component south; |
206 |
|
|
207 |
/** |
/** |
208 |
* @serial |
* @serial |
229 |
*/ |
*/ |
230 |
private Component lastItem; |
private Component lastItem; |
231 |
|
|
|
/** |
|
|
* @serial The horizontal gap between components |
|
|
*/ |
|
|
private int hgap; |
|
232 |
|
|
233 |
/** |
// Some constants for use with calcSize(). |
234 |
* @serial The vertical gap between components |
private static final int MIN = 0; |
235 |
*/ |
private static final int MAX = 1; |
236 |
private int vgap; |
private static final int PREF = 2; |
237 |
|
|
238 |
|
|
239 |
/** |
/** |
456 |
*/ |
*/ |
457 |
public void invalidateLayout(Container parent) |
public void invalidateLayout(Container parent) |
458 |
{ |
{ |
459 |
// FIXME: Implement this properly! |
// Nothing to do here. |
460 |
} |
} |
461 |
|
|
462 |
/** |
/** |
567 |
} |
} |
568 |
|
|
569 |
/** |
/** |
570 |
* FIXME: Document me! |
* This is a convenience method to set the bounds on a component. |
571 |
|
* If the indicated component is null, nothing is done. |
572 |
*/ |
*/ |
573 |
private void setBounds(Component comp, int x, int y, int w, int h) |
private void setBounds(Component comp, int x, int y, int w, int h) |
574 |
{ |
{ |
577 |
comp.setBounds(x, y, w, h); |
comp.setBounds(x, y, w, h); |
578 |
} |
} |
579 |
|
|
|
// FIXME: Maybe move to top of file. |
|
|
// Some constants for use with calcSize(). |
|
|
private static final int MIN = 0; |
|
|
private static final int MAX = 1; |
|
|
private static final int PREF = 2; |
|
|
|
|
580 |
private Dimension calcCompSize(Component comp, int what) |
private Dimension calcCompSize(Component comp, int what) |
581 |
{ |
{ |
582 |
if (comp == null || !comp.isVisible()) |
if (comp == null || !comp.isVisible()) |
662 |
return(new Dimension(width, height)); |
return(new Dimension(width, height)); |
663 |
} |
} |
664 |
} |
} |
665 |
|
|
666 |
|
/** |
667 |
|
* Return the component at the indicated location, or null if no component |
668 |
|
* is at that location. The constraints argument must be one of the |
669 |
|
* location constants specified by this class. |
670 |
|
* @param constraints the location |
671 |
|
* @return the component at that location, or null |
672 |
|
* @throws IllegalArgumentException if the constraints argument is not |
673 |
|
* recognized |
674 |
|
* @since 1.5 |
675 |
|
*/ |
676 |
|
public Component getLayoutComponent(Object constraints) |
677 |
|
{ |
678 |
|
if (constraints == CENTER) |
679 |
|
return center; |
680 |
|
if (constraints == NORTH) |
681 |
|
return north; |
682 |
|
if (constraints == EAST) |
683 |
|
return east; |
684 |
|
if (constraints == SOUTH) |
685 |
|
return south; |
686 |
|
if (constraints == WEST) |
687 |
|
return west; |
688 |
|
if (constraints == PAGE_START) |
689 |
|
return firstLine; |
690 |
|
if (constraints == PAGE_END) |
691 |
|
return lastLine; |
692 |
|
if (constraints == LINE_START) |
693 |
|
return firstItem; |
694 |
|
if (constraints == LINE_END) |
695 |
|
return lastItem; |
696 |
|
throw new IllegalArgumentException("constraint " + constraints |
697 |
|
+ " is not recognized"); |
698 |
|
} |
699 |
|
|
700 |
|
/** |
701 |
|
* Return the component at the specified location, which must be one |
702 |
|
* of the absolute constants such as CENTER or SOUTH. The container's |
703 |
|
* orientation is used to map this location to the correct corresponding |
704 |
|
* component, so for instance in a right-to-left container, a request |
705 |
|
* for the EAST component could return the LINE_END component. This will |
706 |
|
* return null if no component is available at the given location. |
707 |
|
* @param container the container whose orientation is used |
708 |
|
* @param constraints the absolute location of the component |
709 |
|
* @return the component at the location, or null |
710 |
|
* @throws IllegalArgumentException if the constraint is not recognized |
711 |
|
*/ |
712 |
|
public Component getLayoutComponent(Container container, Object constraints) |
713 |
|
{ |
714 |
|
ComponentOrientation orient = container.getComponentOrientation(); |
715 |
|
if (constraints == CENTER) |
716 |
|
return center; |
717 |
|
// Note that we don't support vertical layouts. |
718 |
|
if (constraints == NORTH) |
719 |
|
return north; |
720 |
|
if (constraints == SOUTH) |
721 |
|
return south; |
722 |
|
if (constraints == WEST) |
723 |
|
{ |
724 |
|
// Note that relative layout takes precedence. |
725 |
|
if (orient.isLeftToRight()) |
726 |
|
return firstItem == null ? west : firstItem; |
727 |
|
return lastItem == null ? west : lastItem; |
728 |
|
} |
729 |
|
if (constraints == EAST) |
730 |
|
{ |
731 |
|
// Note that relative layout takes precedence. |
732 |
|
if (orient.isLeftToRight()) |
733 |
|
return lastItem == null ? east : lastItem; |
734 |
|
return firstItem == null ? east : firstItem; |
735 |
|
} |
736 |
|
throw new IllegalArgumentException("constraint " + constraints |
737 |
|
+ " is not recognized"); |
738 |
|
} |
739 |
|
|
740 |
|
/** |
741 |
|
* Return the constraint corresponding to a component in this layout. |
742 |
|
* If the component is null, or is not in this layout, returns null. |
743 |
|
* Otherwise, this will return one of the constraint constants defined |
744 |
|
* in this class. |
745 |
|
* @param c the component |
746 |
|
* @return the constraint, or null |
747 |
|
* @since 1.5 |
748 |
|
*/ |
749 |
|
public Object getConstraints(Component c) |
750 |
|
{ |
751 |
|
if (c == null) |
752 |
|
return null; |
753 |
|
if (c == center) |
754 |
|
return CENTER; |
755 |
|
if (c == north) |
756 |
|
return NORTH; |
757 |
|
if (c == east) |
758 |
|
return EAST; |
759 |
|
if (c == south) |
760 |
|
return SOUTH; |
761 |
|
if (c == west) |
762 |
|
return WEST; |
763 |
|
if (c == firstLine) |
764 |
|
return PAGE_START; |
765 |
|
if (c == lastLine) |
766 |
|
return PAGE_END; |
767 |
|
if (c == firstItem) |
768 |
|
return LINE_START; |
769 |
|
if (c == lastItem) |
770 |
|
return LINE_END; |
771 |
|
return null; |
772 |
|
} |
773 |
} |
} |