[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[cp-patches] Patch: FYI: BorderLayout -vs- 1.5
From: |
Tom Tromey |
Subject: |
[cp-patches] Patch: FYI: BorderLayout -vs- 1.5 |
Date: |
21 Sep 2005 12:22:03 -0600 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.3.50 |
I'm checking this in.
This updates BorderLayout with the new 1.5 functionality. This also
fixes the serialization of this class.
I've added a Mauve test for the new methods.
Tom
Index: ChangeLog
from Tom Tromey <address@hidden>
* java/awt/BorderLayout.java (invalidateLayout): Updated comment.
(setBounds): Likewise.
(MIN, MAX, PREF): Moved nearer top of file.
(getLayoutComponent): New methods.
(getConstraints): New method.
(vgap, hgap, north, south, east, west): Reordered fields to conform
to serialization spec.
Index: java/awt/BorderLayout.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/BorderLayout.java,v
retrieving revision 1.18
diff -u -r1.18 BorderLayout.java
--- java/awt/BorderLayout.java 4 Aug 2005 18:10:44 -0000 1.18
+++ java/awt/BorderLayout.java 21 Sep 2005 18:23:55 -0000
@@ -38,6 +38,7 @@
package java.awt;
+
/**
* This class implements a layout manager that positions components
* in certain sectors of the parent container.
@@ -174,6 +175,16 @@
/**
+ * @serial The horizontal gap between components
+ */
+ private int hgap;
+
+ /**
+ * @serial The vertical gap between components
+ */
+ private int vgap;
+
+ /**
* @serial
*/
private Component north;
@@ -181,7 +192,7 @@
/**
* @serial
*/
- private Component south;
+ private Component west;
/**
* @serial
@@ -191,7 +202,7 @@
/**
* @serial
*/
- private Component west;
+ private Component south;
/**
* @serial
@@ -218,15 +229,11 @@
*/
private Component lastItem;
- /**
- * @serial The horizontal gap between components
- */
- private int hgap;
- /**
- * @serial The vertical gap between components
- */
- private int vgap;
+ // Some constants for use with calcSize().
+ private static final int MIN = 0;
+ private static final int MAX = 1;
+ private static final int PREF = 2;
/**
@@ -449,7 +456,7 @@
*/
public void invalidateLayout(Container parent)
{
- // FIXME: Implement this properly!
+ // Nothing to do here.
}
/**
@@ -560,7 +567,8 @@
}
/**
- * FIXME: Document me!
+ * This is a convenience method to set the bounds on a component.
+ * If the indicated component is null, nothing is done.
*/
private void setBounds(Component comp, int x, int y, int w, int h)
{
@@ -569,12 +577,6 @@
comp.setBounds(x, y, w, h);
}
- // 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;
-
private Dimension calcCompSize(Component comp, int what)
{
if (comp == null || !comp.isVisible())
@@ -659,5 +661,113 @@
return(new Dimension(width, height));
}
+ }
+
+ /**
+ * Return the component at the indicated location, or null if no component
+ * is at that location. The constraints argument must be one of the
+ * location constants specified by this class.
+ * @param constraints the location
+ * @return the component at that location, or null
+ * @throws IllegalArgumentException if the constraints argument is not
+ * recognized
+ * @since 1.5
+ */
+ public Component getLayoutComponent(Object constraints)
+ {
+ if (constraints == CENTER)
+ return center;
+ if (constraints == NORTH)
+ return north;
+ if (constraints == EAST)
+ return east;
+ if (constraints == SOUTH)
+ return south;
+ if (constraints == WEST)
+ return west;
+ if (constraints == PAGE_START)
+ return firstLine;
+ if (constraints == PAGE_END)
+ return lastLine;
+ if (constraints == LINE_START)
+ return firstItem;
+ if (constraints == LINE_END)
+ return lastItem;
+ throw new IllegalArgumentException("constraint " + constraints
+ + " is not recognized");
+ }
+
+ /**
+ * Return the component at the specified location, which must be one
+ * of the absolute constants such as CENTER or SOUTH. The container's
+ * orientation is used to map this location to the correct corresponding
+ * component, so for instance in a right-to-left container, a request
+ * for the EAST component could return the LINE_END component. This will
+ * return null if no component is available at the given location.
+ * @param container the container whose orientation is used
+ * @param constraints the absolute location of the component
+ * @return the component at the location, or null
+ * @throws IllegalArgumentException if the constraint is not recognized
+ */
+ public Component getLayoutComponent(Container container, Object constraints)
+ {
+ ComponentOrientation orient = container.getComponentOrientation();
+ if (constraints == CENTER)
+ return center;
+ // Note that we don't support vertical layouts.
+ if (constraints == NORTH)
+ return north;
+ if (constraints == SOUTH)
+ return south;
+ if (constraints == WEST)
+ {
+ // Note that relative layout takes precedence.
+ if (orient.isLeftToRight())
+ return firstItem == null ? west : firstItem;
+ return lastItem == null ? west : lastItem;
+ }
+ if (constraints == EAST)
+ {
+ // Note that relative layout takes precedence.
+ if (orient.isLeftToRight())
+ return lastItem == null ? east : lastItem;
+ return firstItem == null ? east : firstItem;
+ }
+ throw new IllegalArgumentException("constraint " + constraints
+ + " is not recognized");
+ }
+
+ /**
+ * Return the constraint corresponding to a component in this layout.
+ * If the component is null, or is not in this layout, returns null.
+ * Otherwise, this will return one of the constraint constants defined
+ * in this class.
+ * @param c the component
+ * @return the constraint, or null
+ * @since 1.5
+ */
+ public Object getConstraints(Component c)
+ {
+ if (c == null)
+ return null;
+ if (c == center)
+ return CENTER;
+ if (c == north)
+ return NORTH;
+ if (c == east)
+ return EAST;
+ if (c == south)
+ return SOUTH;
+ if (c == west)
+ return WEST;
+ if (c == firstLine)
+ return PAGE_START;
+ if (c == lastLine)
+ return PAGE_END;
+ if (c == firstItem)
+ return LINE_START;
+ if (c == lastItem)
+ return LINE_END;
+ return null;
}
}
- [cp-patches] Patch: FYI: BorderLayout -vs- 1.5,
Tom Tromey <=