diff options
Diffstat (limited to 'libjava/classpath/java/awt/GridBagLayout.java')
-rw-r--r-- | libjava/classpath/java/awt/GridBagLayout.java | 233 |
1 files changed, 125 insertions, 108 deletions
diff --git a/libjava/classpath/java/awt/GridBagLayout.java b/libjava/classpath/java/awt/GridBagLayout.java index 714e080..f827d21 100644 --- a/libjava/classpath/java/awt/GridBagLayout.java +++ b/libjava/classpath/java/awt/GridBagLayout.java @@ -38,6 +38,8 @@ exception statement from your version. */ package java.awt; +import gnu.classpath.NotImplementedException; + import java.io.Serializable; import java.util.ArrayList; import java.util.HashMap; @@ -323,6 +325,7 @@ public class GridBagLayout * Obsolete. */ protected void AdjustForGravity (GridBagConstraints gbc, Rectangle rect) + throws NotImplementedException { // FIXME throw new Error ("Not implemented"); @@ -349,107 +352,121 @@ public class GridBagLayout // be invalidated, clearing the layout information cache, // layoutInfo. So we wait until after this for loop to set // layoutInfo. - for(int i = 0; i < components.length; i++) - { - Component component = components [i]; - - // If component is not visible we dont have to care about it. - if (!component.isVisible()) - continue; - - GridBagConstraints constraints = - lookupInternalConstraints(component); - - int cellx = sumIntArray(info.colWidths, constraints.gridx); - int celly = sumIntArray(info.rowHeights, constraints.gridy); - int cellw = sumIntArray(info.colWidths, - constraints.gridx + constraints.gridwidth) - cellx; - int cellh = sumIntArray(info.rowHeights, - constraints.gridy + constraints.gridheight) - celly; - - Insets insets = constraints.insets; - if (insets != null) - { - cellx += insets.left; - celly += insets.top; - cellw -= insets.left + insets.right; - cellh -= insets.top + insets.bottom; - } - - Dimension dim = component.getPreferredSize(); - - // Note: Documentation says that padding is added on both sides, but - // visual inspection shows that the Sun implementation only adds it - // once, so we do the same. - dim.width += constraints.ipadx; - dim.height += constraints.ipady; - - switch(constraints.fill) - { - case GridBagConstraints.HORIZONTAL: - dim.width = cellw; - break; - case GridBagConstraints.VERTICAL: - dim.height = cellh; - break; - case GridBagConstraints.BOTH: - dim.width = cellw; - dim.height = cellh; - break; - } - - int x; - int y; - - switch(constraints.anchor) - { - case GridBagConstraints.NORTH: - x = cellx + (cellw - dim.width) / 2; - y = celly; - break; - case GridBagConstraints.SOUTH: - x = cellx + (cellw - dim.width) / 2; - y = celly + cellh - dim.height; - break; - case GridBagConstraints.WEST: - x = cellx; - y = celly + (cellh - dim.height) / 2; - break; - case GridBagConstraints.EAST: - x = cellx + cellw - dim.width; - y = celly + (cellh - dim.height) / 2; - break; - case GridBagConstraints.NORTHEAST: - x = cellx + cellw - dim.width; - y = celly; - break; - case GridBagConstraints.NORTHWEST: - x = cellx; - y = celly; - break; - case GridBagConstraints.SOUTHEAST: - x = cellx + cellw - dim.width; - y = celly + cellh - dim.height; - break; - case GridBagConstraints.SOUTHWEST: - x = cellx; - y = celly + cellh - dim.height; - break; - default: - x = cellx + (cellw - dim.width) / 2; - y = celly + (cellh - dim.height) / 2; - break; - } - - component.setBounds(info.pos_x + x, info.pos_y + y, dim.width, dim.height); - } - - // DEBUG - //dumpLayoutInfo (info); - - // Cache layout information. - layoutInfo = getLayoutInfo (parent, PREFERREDSIZE); - } + Component lastComp = null; + int cellx = 0; + int celly = 0; + int cellw = 0; + int cellh = 0; + for (int i = 0; i < components.length; i++) + { + Component component = components[i]; + + // If component is not visible we dont have to care about it. + if (! component.isVisible()) + continue; + + Dimension dim = component.getPreferredSize(); + GridBagConstraints constraints = lookupInternalConstraints(component); + + if (lastComp != null + && constraints.gridheight == GridBagConstraints.REMAINDER) + celly += cellh; + else + celly = sumIntArray(info.rowHeights, constraints.gridy); + + if (lastComp != null + && constraints.gridwidth == GridBagConstraints.REMAINDER) + cellx += cellw; + else + cellx = sumIntArray(info.colWidths, constraints.gridx); + + cellw = sumIntArray(info.colWidths, constraints.gridx + + constraints.gridwidth) - cellx; + cellh = sumIntArray(info.rowHeights, constraints.gridy + + constraints.gridheight) - celly; + + Insets insets = constraints.insets; + if (insets != null) + { + cellx += insets.left; + celly += insets.top; + cellw -= insets.left + insets.right; + cellh -= insets.top + insets.bottom; + } + + // Note: Documentation says that padding is added on both sides, but + // visual inspection shows that the Sun implementation only adds it + // once, so we do the same. + dim.width += constraints.ipadx; + dim.height += constraints.ipady; + + switch (constraints.fill) + { + case GridBagConstraints.HORIZONTAL: + dim.width = cellw; + break; + case GridBagConstraints.VERTICAL: + dim.height = cellh; + break; + case GridBagConstraints.BOTH: + dim.width = cellw; + dim.height = cellh; + break; + } + + int x = 0; + int y = 0; + + switch (constraints.anchor) + { + case GridBagConstraints.NORTH: + x = cellx + (cellw - dim.width) / 2; + y = celly; + break; + case GridBagConstraints.SOUTH: + x = cellx + (cellw - dim.width) / 2; + y = celly + cellh - dim.height; + break; + case GridBagConstraints.WEST: + x = cellx; + y = celly + (cellh - dim.height) / 2; + break; + case GridBagConstraints.EAST: + x = cellx + cellw - dim.width; + y = celly + (cellh - dim.height) / 2; + break; + case GridBagConstraints.NORTHEAST: + x = cellx + cellw - dim.width; + y = celly; + break; + case GridBagConstraints.NORTHWEST: + x = cellx; + y = celly; + break; + case GridBagConstraints.SOUTHEAST: + x = cellx + cellw - dim.width; + y = celly + cellh - dim.height; + break; + case GridBagConstraints.SOUTHWEST: + x = cellx; + y = celly + cellh - dim.height; + break; + default: + x = cellx + (cellw - dim.width) / 2; + y = celly + (cellh - dim.height) / 2; + break; + } + component.setBounds(info.pos_x + x, info.pos_y + y, dim.width, + dim.height); + lastComp = component; + } + + // DEBUG + //dumpLayoutInfo(info); + + // Cache layout information. + layoutInfo = getLayoutInfo(parent, PREFERREDSIZE); + } /** * Obsolete. @@ -485,11 +502,10 @@ public class GridBagLayout for (int i = 0; i < components.length; i++) { Component component = components [i]; - // If component is not visible we dont have to care about it. if (!component.isVisible()) continue; - + // When looking up the constraint for the first time, check the // original unmodified constraint. After the first time, always // refer to the internal modified constraint. @@ -516,7 +532,6 @@ public class GridBagLayout // // nothing to check; just add it - // cases 1 and 2 if(constraints.gridx == GridBagConstraints.RELATIVE) { @@ -560,7 +575,9 @@ public class GridBagLayout // this column. We want to add this component below it. // If this column is empty, add to the 0 position. if (!lastInCol.containsKey(new Integer(constraints.gridx))) - y = 0; + { + y = current_y; + } else { Component lastComponent = (Component)lastInCol.get(new Integer(constraints.gridx)); @@ -596,7 +613,7 @@ public class GridBagLayout // Update our reference points for RELATIVE gridx and gridy. if(constraints.gridwidth == GridBagConstraints.REMAINDER) { - current_y = constraints.gridy + Math.max(1, constraints.gridheight); + current_y = constraints.gridy + Math.max(1, constraints.gridheight); } else if (constraints.gridwidth != GridBagConstraints.REMAINDER) { @@ -788,7 +805,7 @@ public class GridBagLayout height += constraints.insets.top + constraints.insets.bottom; height += constraints.ipady; - + distributeSizeAndWeight(height, constraints.weighty, constraints.gridy, @@ -918,7 +935,7 @@ public class GridBagLayout sizes[start] = Math.max(sizes[start], size); weights[start] = Math.max(weights[start], weight); } - else if (span > 1) + else { int numOccupied = span; int lastOccupied = -1; |