[cp-patches] FYI: SizeRequirements fix

2005-11-04 Thread Roman Kennke
Hi,

I discovered an overflow problem in SizeRequirements. I added a Mauve
test for that problem (to BoxLayout testsuite) and this patch makes this
test PASS.

2005-11-04  Roman Kennke  [EMAIL PROTECTED]

* javax/swing/SizeRequirements.java
(getTiledSizeRequirements): Added check for overflows.
(adjustGreater): Fixed overflow handling through usage of long
instead of int.

/Roman
Index: javax/swing/SizeRequirements.java
===
RCS file: /cvsroot/classpath/classpath/javax/swing/SizeRequirements.java,v
retrieving revision 1.19
diff -u -r1.19 SizeRequirements.java
--- javax/swing/SizeRequirements.java	13 Oct 2005 20:02:29 -	1.19
+++ javax/swing/SizeRequirements.java	4 Nov 2005 11:23:48 -
@@ -142,13 +142,26 @@
   public static SizeRequirements
   getTiledSizeRequirements(SizeRequirements[] children)
   {
-SizeRequirements result = new SizeRequirements();
-for (int i = 0; i  children.length; i++)
-  {
-result.minimum += children[i].minimum;
-result.preferred += children[i].preferred;
-result.maximum += children[i].maximum;
-  }
+long minimum = 0;
+long preferred = 0;
+long maximum = 0;
+for (int i = 0; i  children.length; i++)
+  {
+minimum += children[i].minimum;
+preferred += children[i].preferred;
+maximum += children[i].maximum;
+  }
+// Overflow check.
+if (minimum  Integer.MAX_VALUE)
+  minimum = Integer.MAX_VALUE;
+if (preferred  Integer.MAX_VALUE)
+  preferred = Integer.MAX_VALUE;
+if (maximum  Integer.MAX_VALUE)
+  maximum = Integer.MAX_VALUE;
+SizeRequirements result = new SizeRequirements((int) minimum,
+   (int) preferred,
+   (int) maximum,
+   0.5F);
 return result;
   }
 
@@ -338,12 +351,10 @@
 int[] spans, int span)
   {
 // Sum up (maxSize - prefSize) over all children
-int sumDelta = 0;
+long sumDelta = 0;
 for (int i = 0; i  children.length; i++)
   {
 sumDelta += children[i].maximum - children[i].preferred;
-if (sumDelta  0)
-  sumDelta = Integer.MAX_VALUE;
   }
 
 // If we have sumDelta == 0, then all components have prefSize == maxSize
@@ -356,7 +367,7 @@
   {
 double factor = ((double) (children[i].maximum - children[i].preferred))
 / ((double) sumDelta);
-spans[i] -= factor * (span - allocated);
+spans[i] += factor * (allocated - span);
   }
   }
 
___
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches


[cp-patches] FYI: SizeRequirements fix

2005-10-13 Thread Roman Kennke
I discovered another problem with the SizeRequirements. The method
calculateAlignedPositions handled the minimumSize incorrectly, this is
fixed. Mauve testcase following soon.

2005-10-13  Roman Kennke  [EMAIL PROTECTED]

* javax/swing/SizeRequirements.java
(calculateAlignedPositions): Determine baseline using the total
requirements argument.
(adjustFromRight): Use float instead of int for baseline argument.
Don't handle the minimum case.
(adjustFromLeft): Likewise.

/Roman
Index: javax/swing/SizeRequirements.java
===
RCS file: /cvsroot/classpath/classpath/javax/swing/SizeRequirements.java,v
retrieving revision 1.18
diff -u -r1.18 SizeRequirements.java
--- javax/swing/SizeRequirements.java	4 Oct 2005 14:50:31 -	1.18
+++ javax/swing/SizeRequirements.java	13 Oct 2005 20:01:46 -
@@ -424,16 +424,8 @@
boolean forward)
   {
 // First we compute the position of the baseline.
-float left = 0;
-float right = 0;
-for (int i = 0; i  children.length; i++)
-  {
-float myLeft = children[i].preferred * children[i].alignment;
-float myRight = children[i].preferred - myLeft;
-left = Math.max(myLeft, left);
-right = Math.max(myRight, right);
-  }
-int baseline = (int) ((left / (left + right)) * allocated);
+float baseline = allocated * total.alignment;
+
 // Now we can layout the components along the baseline.
 for (int i = 0; i  children.length; i++)
   {
@@ -457,7 +449,7 @@
* @param allocated
* @param spanAndOffset
*/
-  private static void adjustFromRight(SizeRequirements reqs, int baseline,
+  private static void adjustFromRight(SizeRequirements reqs, float baseline,
   int allocated, int[] spanAndOffset)
   {
 float right = allocated - baseline;
@@ -470,14 +462,9 @@
 if (right / (1.F - reqs.alignment) * reqs.alignment  allocated - baseline)
   right = ((float) (allocated - baseline))
  / reqs.alignment * (1.F - reqs.alignment);
-// If we are below the minimum, then adjust upwards.
-  float minRight = ((float) reqs.minimum) * (1.F - reqs.alignment);
-if (right / (1.F - reqs.alignment)  reqs.minimum)
-  right = Math.max(minRight, maxRight);
 
 spanAndOffset[0] = (int) (right / (1.F - reqs.alignment));
-spanAndOffset[1] = baseline -
-   (int) (((float) spanAndOffset[0]) * reqs.alignment);
+spanAndOffset[1] = (int) (baseline - spanAndOffset[0] * reqs.alignment);
   }
 
   /**
@@ -488,7 +475,7 @@
* @param allocated
* @param spanAndOffset
*/
-  private static void adjustFromLeft(SizeRequirements reqs, int baseline,
+  private static void adjustFromLeft(SizeRequirements reqs, float baseline,
  int allocated, int[] spanAndOffset)
   {
 float left = baseline;
@@ -502,14 +489,8 @@
   left = ((float) (allocated - baseline))
  / (1.F - reqs.alignment) * reqs.alignment;
 
-// If we are below the minimum, then adjust upwards.
-float minLeft = ((float) reqs.minimum) * reqs.alignment;
-if (left / reqs.alignment  reqs.minimum)
-  left = Math.max(minLeft, maxLeft);
-
 spanAndOffset[0] = (int) (left / reqs.alignment);
-spanAndOffset[1] = baseline -
-   (int) (((float) spanAndOffset[0]) * reqs.alignment);
+spanAndOffset[1] = (int) (baseline - spanAndOffset[0] * reqs.alignment);
   }
 
   /**
___
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches


[cp-patches] FYI: SizeRequirements fix

2005-09-29 Thread Roman Kennke
Hi,

the work on the OverlayLayout exposed some buggies in the
SizeRequirements, which are fixed by this patch. This should also affect
the BoxLayout, since BoxLayout also relies on the SizeRequirements
methods. The OverlayLayout testcases confirm that this is now behaving
(more) correctly.

2005-09-29  Roman Kennke  [EMAIL PROTECTED]

* javax/swing/SizeRequirements.java
(getAlignedSizeRequirements): Fixed calculation of preferred and
maximum size as well as the alignment.

/RomanIndex: javax/swing/SizeRequirements.java
===
RCS file: /cvsroot/classpath/classpath/javax/swing/SizeRequirements.java,v
retrieving revision 1.16
diff -u -r1.16 SizeRequirements.java
--- javax/swing/SizeRequirements.java	27 Sep 2005 20:44:10 -	1.16
+++ javax/swing/SizeRequirements.java	29 Sep 2005 22:08:09 -
@@ -179,18 +179,21 @@
 minLeft = Math.max(myMinLeft, minLeft);
 minRight = Math.max(myMinRight, minRight);
 float myPrefLeft = children[i].preferred * children[i].alignment;
-float myPrefRight = children[i].preferred - myMinLeft;
+float myPrefRight = children[i].preferred - myPrefLeft;
 prefLeft = Math.max(myPrefLeft, prefLeft);
 prefRight = Math.max(myPrefRight, prefRight);
 float myMaxLeft = children[i].maximum * children[i].alignment;
-float myMaxRight = children[i].maximum - myMinLeft;
+float myMaxRight = children[i].maximum - myMaxLeft;
 maxLeft = Math.max(myMaxLeft, maxLeft);
 maxRight = Math.max(myMaxRight, maxRight);
   }
 int minSize = (int) (minLeft + minRight);
 int prefSize = (int) (prefLeft + prefRight);
 int maxSize = (int) (maxLeft + maxRight);
-return new SizeRequirements(minSize, prefSize, maxSize, 0.5F);
+float align = prefLeft / (prefRight + prefLeft);
+if (Float.isNaN(align))
+  align = 0;
+return new SizeRequirements(minSize, prefSize, maxSize, align);
   }
 
   /**___
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches


[cp-patches] FYI: SizeRequirements fix

2005-09-27 Thread Roman Kennke
Hi,

this fixes a layout problems with JMenu's and JOptionPanes.

2005-09-27  Roman Kennke  [EMAIL PROTECTED]

* javax/swing/SizeRequirements.java
(adjustGreater): Special handle the case when the components have
no spare room for adjustment.
(adjustSmaller): Special handle the case when the components have
no spare room for adjustment.

/Roman
Index: javax/swing/SizeRequirements.java
===
RCS file: /cvsroot/classpath/classpath/javax/swing/SizeRequirements.java,v
retrieving revision 1.14
diff -u -r1.14 SizeRequirements.java
--- javax/swing/SizeRequirements.java	26 Sep 2005 13:02:30 -	1.14
+++ javax/swing/SizeRequirements.java	27 Sep 2005 14:29:42 -
@@ -314,6 +314,11 @@
 for (int i = 0; i  children.length; i++)
   sumDelta += children[i].preferred - children[i].minimum;
 
+// If we have sumDelta == 0, then all components have prefSize == maxSize
+// and we can't do anything about it.
+if (sumDelta == 0)
+  return;
+
 // Adjust all sizes according to their preferred and minimum sizes.
 for (int i = 0; i  children.length; i++)
   {
@@ -333,6 +338,11 @@
 int sumDelta = 0;
 for (int i = 0; i  children.length; i++)
   sumDelta += children[i].maximum - children[i].preferred;
+
+// If we have sumDelta == 0, then all components have prefSize == maxSize
+// and we can't do anything about it.
+if (sumDelta == 0)
+  return;
 
 // Adjust all sizes according to their preferred and minimum sizes.
 for (int i = 0; i  children.length; i++)___
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches


[cp-patches] FYI: SizeRequirements fix

2005-09-13 Thread Roman Kennke

2005-09-13  Roman Kennke  [EMAIL PROTECTED]

* javax/swing/SizeRequirements.java
(toString): Implemented this method.
(calculateAlignedPositions): Partly implemented this method.

/RomanIndex: javax/swing/SizeRequirements.java
===
RCS file: /cvsroot/classpath/classpath/javax/swing/SizeRequirements.java,v
retrieving revision 1.10
diff -u -r1.10 SizeRequirements.java
--- javax/swing/SizeRequirements.java	23 Jul 2005 19:47:14 -	1.10
+++ javax/swing/SizeRequirements.java	13 Sep 2005 10:21:39 -
@@ -116,7 +116,17 @@
*/
   public String toString()
   {
-return null; // TODO
+StringBuilder b = new StringBuilder();
+b.append([);
+b.append(minimum);
+b.append(',');
+b.append(preferred);
+b.append(',');
+b.append(maximum);
+b.append(]@);
+b.append(alignment);
+b.append('');
+return b.toString();
   }
 
   /**
@@ -271,7 +281,8 @@
SizeRequirements[] children,
int[] offsets, int[] spans)
   {
-calculateTiledPositions(allocated, total, children, offsets, spans, true);
+calculateAlignedPositions(allocated, total, children, offsets, spans,
+  true);
   }
 
   /**
@@ -306,7 +317,12 @@
int[] offset, int[] spans,
boolean forward)
   {
-// TODO
+// TODO: Implement this correctly.
+for (int i = 0; i  children.length; ++i)
+  {
+// This is only a hack to make things work a little.
+spans[i] = Math.min(allocated, children[i].maximum);
+  }
   }
 
   /**___
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches