diff options
author | Thomas Fitzsimmons <fitzsim@redhat.com> | 2006-06-18 18:56:44 +0000 |
---|---|---|
committer | Thomas Fitzsimmons <fitzsim@redhat.com> | 2006-06-18 18:56:44 +0000 |
commit | 294b30730d5bcb8ddcb05a1229a2b04d9c3f0868 (patch) | |
tree | 229fdd60d53903b45451a69a99d78b31a2ad20fd /java | |
parent | 5a61703763e497d23bd07579ff0f9f56b9088813 (diff) | |
download | classpath-294b30730d5bcb8ddcb05a1229a2b04d9c3f0868.tar.gz |
2006-06-18 Thomas Fitzsimmons <fitzsim@redhat.com>
* java/awt/GridBagLayout.java (AdjustForGravity): Implement.
* java/awt/GridBagConstraints.java: Indent.
Diffstat (limited to 'java')
-rw-r--r-- | java/awt/GridBagConstraints.java | 139 | ||||
-rw-r--r-- | java/awt/GridBagLayout.java | 152 |
2 files changed, 228 insertions, 63 deletions
diff --git a/java/awt/GridBagConstraints.java b/java/awt/GridBagConstraints.java index 8d8b4fae5..a6a64c3bb 100644 --- a/java/awt/GridBagConstraints.java +++ b/java/awt/GridBagConstraints.java @@ -48,62 +48,99 @@ public class GridBagConstraints implements Cloneable, Serializable { static final long serialVersionUID = -1000070633030801713L; - /** Fill in both directions. */ - public static final int BOTH = 1; - /** Don't fill. */ + // Fill values. + /** + * Don't fill. + */ public static final int NONE = 0; - /** Fill horizontally. */ + + /** + * Fill in both directions. + */ + public static final int BOTH = 1; + + /** + * Fill horizontally. + */ public static final int HORIZONTAL = 2; - /** Fill vertically. */ + + /** + * Fill vertically. + */ public static final int VERTICAL = 3; - /** Position in the center. */ + // Anchor values. + /** + * Position in the center. + */ public static final int CENTER = 10; - /** Position to the east. */ - public static final int EAST = 13; - /** Position to the north. */ + + /** + * Position to the north. + */ public static final int NORTH = 11; - /** Position to the northeast. */ + + /** + * Position to the northeast. + */ public static final int NORTHEAST = 12; - /** Position to the northwest. */ - public static final int NORTHWEST = 18; - /** Position to the south. */ - public static final int SOUTH = 15; - /** Position to the southeast. */ + + /** + * Position to the east. + */ + public static final int EAST = 13; + + /** + * Position to the southeast. + */ public static final int SOUTHEAST = 14; - /** Position to the southwest. */ + + /** + * Position to the south. + */ + public static final int SOUTH = 15; + + /** + * Position to the southwest. + */ public static final int SOUTHWEST = 16; - /** Position to the west. */ + + /** + * Position to the west. + */ public static final int WEST = 17; - /** Occupy all remaining cells except last cell. */ + /** + * Position to the northwest. + */ + public static final int NORTHWEST = 18; + + // gridx and gridy values. + /** + * Occupy all remaining cells except last cell. + */ public static final int RELATIVE = -1; - /** Occupy all remaining cells. */ - public static final int REMAINDER = 0; /** - * Position to where the first text line would end. Equals to NORTHEAST for - * horizontal left-to-right orientations. + * Occupy all remaining cells. */ - public static final int FIRST_LINE_END = 24; + public static final int REMAINDER = 0; /** - * Position to where the first text line would start. Equals to NORTHWEST for - * horizontal left-to-right orientations. + * Position to where a page starts. Equals NORTH for horizontal orientations. */ - public static final int FIRST_LINE_START = 23; + public static final int PAGE_START = 19; /** - * Position to where the last text line would end. Equals to SOUTHEAST for - * horizontal left-to-right orientations. + * Position to where a page ends. Equals SOUTH for horizontal orientations. */ - public static final int LAST_LINE_END = 26; + public static final int PAGE_END = 20; /** - * Position to where the last text line would start. Equals to SOUTHWEST for - * horizontal left-to-right orientations. + * Position to where a text line would start. Equals to WEST for + * left-to-right orientations. */ - public static final int LAST_LINE_START = 25; + public static final int LINE_START = 21; /** * Position to where a text line would end. Equals to EAST for @@ -112,20 +149,28 @@ public class GridBagConstraints implements Cloneable, Serializable public static final int LINE_END = 22; /** - * Position to where a text line would start. Equals to WEST for - * left-to-right orientations. + * Position to where the first text line would start. Equals to NORTHWEST for + * horizontal left-to-right orientations. */ - public static final int LINE_START = 21; + public static final int FIRST_LINE_START = 23; /** - * Position to where a page ends. Equals SOUTH for horizontal orientations. + * Position to where the first text line would end. Equals to NORTHEAST for + * horizontal left-to-right orientations. */ - public static final int PAGE_END = 20; + public static final int FIRST_LINE_END = 24; /** - * Position to where a page starts. Equals NORTH for horizontal orientations. + * Position to where the last text line would start. Equals to SOUTHWEST for + * horizontal left-to-right orientations. */ - public static final int PAGE_START = 19; + public static final int LAST_LINE_START = 25; + + /** + * Position to where the last text line would end. Equals to SOUTHEAST for + * horizontal left-to-right orientations. + */ + public static final int LAST_LINE_END = 26; public int anchor; public int fill; @@ -139,7 +184,9 @@ public class GridBagConstraints implements Cloneable, Serializable public double weightx; public double weighty; - /** Create a copy of this object. */ + /** + * Create a copy of this object. + */ public Object clone () { try @@ -155,8 +202,10 @@ public class GridBagConstraints implements Cloneable, Serializable } } - /** Create a new GridBagConstraints object with the default - * parameters. */ + /** + * Create a new GridBagConstraints object with the default + * parameters. + */ public GridBagConstraints () { this.anchor = CENTER; @@ -172,8 +221,10 @@ public class GridBagConstraints implements Cloneable, Serializable this.weighty = 0; } - /** Create a new GridBagConstraints object with the indicated - * parameters. */ + /** + * Create a new GridBagConstraints object with the indicated + * parameters. + */ public GridBagConstraints (int gridx, int gridy, int gridwidth, int gridheight, double weightx, double weighty, diff --git a/java/awt/GridBagLayout.java b/java/awt/GridBagLayout.java index eb1c61c5b..e4711c71e 100644 --- a/java/awt/GridBagLayout.java +++ b/java/awt/GridBagLayout.java @@ -38,8 +38,6 @@ exception statement from your version. */ package java.awt; -import gnu.classpath.NotImplementedException; - import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; @@ -321,21 +319,129 @@ public class GridBagLayout return new Point (col, row); } - /** - * Obsolete. - */ - protected void AdjustForGravity (GridBagConstraints constraints, - Rectangle rect) - { - Insets insets = constraints.insets; - if (insets != null) - { - rect.x += insets.left; - rect.y += insets.top; - rect.width -= insets.left + insets.right; - rect.height -= insets.top + insets.bottom; - } - } + /** + * Move and resize a rectangle according to a set of grid bag + * constraints. The x, y, width and height fields of the + * rectangle argument are adjusted to the new values. + * + * @param constraints position and size constraints + * @param r rectangle to be moved and resized + */ + protected void AdjustForGravity (GridBagConstraints constraints, + Rectangle r) + { + Rectangle result = new Rectangle (0, 0, 0, 0); + + // Calculate width and height. + + // Adjust width and height for fill value. + switch (constraints.fill) + { + case GridBagConstraints.NONE: + result.width = 0; + result.height = 0; + break; + case GridBagConstraints.BOTH: + result.width = r.width; + result.height = r.height; + break; + case GridBagConstraints.HORIZONTAL: + result.width = r.width; + result.height = 0; + break; + case GridBagConstraints.VERTICAL: + result.width = 0; + result.height = r.height; + break; + } + + // Adjust width and height for insets, and clamp to minimum + // values of ipadx and ipady. + result.width = Math.max(result.width + - constraints.insets.left + - constraints.insets.right, + constraints.ipadx); + result.height = Math.max(result.height + - constraints.insets.top + - constraints.insets.bottom, + constraints.ipady); + + // Calculate x and y. + + // Do not account for the internal padding when setting the + // result rectangle's x and y co-ordinates. + int rect_width = r.width - constraints.ipadx; + int rect_height = r.height - constraints.ipady; + + int half_width = (rect_width + constraints.insets.left + - constraints.insets.right) / 2; + int half_height = (rect_height + constraints.insets.top + - constraints.insets.bottom) / 2; + + // Adjust x and y for anchor value. + switch (constraints.anchor) + { + case GridBagConstraints.CENTER: + result.x = r.x + half_width; + result.y = r.y + half_height; + break; + case GridBagConstraints.NORTH: + result.x = r.x + half_width; + result.y = r.y + constraints.insets.top; + break; + case GridBagConstraints.NORTHEAST: + result.x = r.x + rect_width - constraints.insets.right; + result.y = r.y + constraints.insets.top; + break; + case GridBagConstraints.EAST: + result.x = r.x + rect_width - constraints.insets.right; + result.y = r.y + half_height; + break; + case GridBagConstraints.SOUTHEAST: + result.x = r.x + rect_width - constraints.insets.right; + result.y = r.y + rect_height - constraints.insets.bottom; + break; + case GridBagConstraints.SOUTH: + result.x = r.x + half_width; + result.y = r.y + rect_height - constraints.insets.bottom; + break; + case GridBagConstraints.SOUTHWEST: + result.x = r.x + constraints.insets.left; + result.y = r.y + rect_height - constraints.insets.bottom; + break; + case GridBagConstraints.WEST: + result.x = r.x + constraints.insets.left; + result.y = r.y + half_height; + break; + case GridBagConstraints.NORTHWEST: + result.x = r.x + constraints.insets.left; + result.y = r.y + constraints.insets.top; + break; + } + + // Adjust x and y for fill, clamping values to the external + // padding boundaries where necessary. + switch (constraints.fill) + { + case GridBagConstraints.NONE: + break; + case GridBagConstraints.BOTH: + result.x = r.x + constraints.insets.left; + result.y = r.y + constraints.insets.top; + break; + case GridBagConstraints.HORIZONTAL: + result.x = r.x + constraints.insets.left; + break; + case GridBagConstraints.VERTICAL: + result.y = r.y + constraints.insets.top; + break; + } + + r.x = result.x; + r.y = result.y; + r.width = result.width; + r.height = result.height; + } /** * Obsolete. @@ -1081,10 +1187,18 @@ public class GridBagLayout } /** + * Move and resize a rectangle according to a set of grid bag + * constraints. The x, y, width and height fields of the + * rectangle argument are adjusted to the new values. + * + * @param constraints position and size constraints + * @param r rectangle to be moved and resized + * * @since 1.4 */ - protected void adjustForGravity (GridBagConstraints gbc, Rectangle rect) + protected void adjustForGravity (GridBagConstraints constraints, + Rectangle r) { - AdjustForGravity (gbc, rect); + AdjustForGravity (constraints, r); } } |