SUGGESTED FIX
/**
* Get the component that was added using the given constraint
*
* @param constraints The desired constraint,
* one of NORTH, SOUTH, WEST, EAST, CENTER,
* PAGE_START, PAGE_END, LINE_START, LINE_END.
* @return the component at the given location, or </code>null</code> if
* the location is empty.
* @see @addLayoutComponent(java.awt.Component, java.lang.Object)
* @exception IllegalArgumentException if the constraint object is
* not one of the nine specified constants.
*/
public Component getLayoutComponent(Object constraints) {
if (CENTER.equals(constraints)) {
return center;
} else if (NORTH.equals(constraints)) {
return north;
} else if (SOUTH.equals(constraints)) {
return south;
} else if (WEST.equals(constraints)) {
return west;
} else if (EAST.equals(constraints)) {
return east;
} else if (PAGE_START.equals(constraints)) {
return firstLine;
} else if (PAGE_END.equals(constraints)) {
return lastLine;
} else if (LINE_START.equals(constraints)) {
return firstItem;
} else if (LINE_END.equals(constraints)) {
return lastItem;
} else {
throw new IllegalArgumentException("cannot get component: unknown constraint: " + constraints);
}
}
/**
* Get the component that corresponds to the given constraint location
* based on the target Container's component orientation.
*
* @param constraints The desired absolute position,
* one of NORTH, SOUTH, EAST, WEST, CENTER.
* @param target The <code>Container</code> using this <code>BorderLayout</code>
* @return the component at the given location, or </code>null</code> if
* the location is empty.
* @see @addLayoutComponent(java.awt.Component, java.lang.Object)
* @exception IllegalArgumentException if the constraint object is
* not one of the five specified constants.
*/
public Component getLayoutComponent(Container target, Object constraints) {
boolean ltr = target.getComponentOrientation().isLeftToRight();
Component result = null;
if (NORTH.equals(constraints)) {
result = (firstLine != null) ? firstLine : north;
} else if (SOUTH.equals(constraints)) {
result = (lastLine != null) ? lastLine : south;
} else if (WEST.equals(constraints)) {
result = ltr ? firstItem : lastItem;
if (result == null) {
result = west;
}
} else if (EAST.equals(constraints)) {
result = ltr ? lastItem : firstItem;
if (result == null) {
result = east;
}
} else if (CENTER.equals(constraints)) {
result = center;
} else {
throw new IllegalArgumentException("cannot get component: invalid constraint: " + constraints);
}
return result;
}
/**
* Get the constraints for the specified component.
*
* @param comp the component to be queried
* @return the component at the given location, or </code>null</code> if
* the location is empty.
* @see @addLayoutComponent(java.awt.Component, java.lang.Object)
* @return the constraint for the specified component,
* or null if component is not present in this layout.
*/
public Object getConstraints(Component comp) {
if (comp == center) {
return CENTER;
} else if (comp == north) {
return NORTH;
} else if (comp == south) {
return SOUTH;
} else if (comp == west) {
return WEST;
} else if (comp == east) {
return EAST;
} else if (comp == firstLine) {
return PAGE_START;
} else if (comp == lastLine) {
return PAGE_END;
} else if (comp == firstItem) {
return LINE_START;
} else if (comp == lastItem) {
return LINE_END;
}
return null;
}
###@###.### 2003-07-17
|
EVALUATION
Sounds reasonable.
michael.martak@Eng 2000-01-03
Adding three methods to BorderLayout, one to get the constraints for a
component, and two slightly different ways to get the component for
a given constraint (taking component orientation into account or not).
###@###.### 2003-07-17
|