Hey,
This patch fixes a couple of bugs in the setValues, setBlockIncrement
and setUnitIncrement methods. This patch fixes a few bugs exposed by
Intel's test suite and others that I came across while fixing the
others.
I have committed mauve tests that support these changes. Could someone
kindly approve or comment this patch.
In the setValues method, the following changes were made:
1. If the value of visibleAmount is 0, then visibleAmount should be set
to 1 and not 0.
2. If the value of maximum is <= minimum, then maximum should be set to
minimum + 1.
3. According to the API, the actual value of maximum is maximum -
visibleAmount. So, instead of checking if value < maximum, we have to
check if value < maximum - visibleAmount.
4. I removed the two bigger if-clauses that deals with the range because
(a) it will never happen that the range = 0 because we know that maximum
will never equal minimum) and (b) it doesn't matter if lineIncrement is
> the range - it won't effect the value of lineIncrement. The same
applies for pageIncrement.
The changes in the setUnitIncrement method were made for similar
reasons: the bigger if-clause is not necessary (refer to (4) above) and
if the value of lineIncrement is 0, then lineIncrement should be set to
1 and not 0. These changes also applied to setBlockIncrement.
Again, could someone kindly comment on or approve this patch.
Thanks,
Tania
2006-10-20 Tania Bento <[EMAIL PROTECTED]>
* java/awt/Scrollbar.java:
(setLineIncrement): Removed unnecessary if-clause and if
lineIncrement == 0, then it should be set to 1, not 0.
(setPageIncrement): Removed unnecessary if-clause and if
pageIncrement == 0, then it should be set to 1, not 0.
(setValues): If visibleAmount <= 0, it should be set to 1, not
0.
If maximum <= minimum, maximum should be set to mininum + 1. The
actual value of maximum is maximum - visibleAmount, so I made
this change to the appropriate if-check. Remove the two
unneccessary
if-clauses.
Index: java/awt/Scrollbar.java
===================================================================
RCS file: /cvsroot/classpath/classpath/java/awt/Scrollbar.java,v
retrieving revision 1.28
diff -u -r1.28 Scrollbar.java
--- java/awt/Scrollbar.java 21 Feb 2006 16:37:31 -0000 1.28
+++ java/awt/Scrollbar.java 20 Oct 2006 17:17:37 -0000
@@ -341,17 +341,22 @@
public synchronized void setValues(int value, int visibleAmount,
int minimum, int maximum)
{
- if (maximum < minimum)
- maximum = minimum;
+ if (visibleAmount <= 0)
+ visibleAmount = 1;
+
+ if (maximum <= minimum)
+ maximum = minimum + 1;
if (value < minimum)
value = minimum;
- if (value > maximum)
- value = maximum;
-
if (visibleAmount > maximum - minimum)
visibleAmount = maximum - minimum;
+
+ // According to documentation, the actual maximum
+ // value is (maximum - visibleAmount)
+ if (value > maximum - visibleAmount)
+ value = maximum - visibleAmount;
ScrollbarPeer peer = (ScrollbarPeer) getPeer();
if (peer != null
@@ -362,30 +367,7 @@
this.value = value;
this.visibleAmount = visibleAmount;
this.minimum = minimum;
- this.maximum = maximum;
-
- int range = maximum - minimum;
- if (lineIncrement > range)
- {
- if (range == 0)
- lineIncrement = 1;
- else
- lineIncrement = range;
-
- if (peer != null)
- peer.setLineIncrement(lineIncrement);
- }
-
- if (pageIncrement > range)
- {
- if (range == 0)
- pageIncrement = 1;
- else
- pageIncrement = range;
-
- if (peer != null)
- peer.setPageIncrement(pageIncrement);
- }
+ this.maximum = maximum;
}
/**
@@ -437,19 +419,13 @@
{
if (lineIncrement < 0)
throw new IllegalArgumentException("Unit increment less than zero.");
-
- int range = maximum - minimum;
- if (lineIncrement > range)
- {
- if (range == 0)
- lineIncrement = 1;
- else
- lineIncrement = range;
- }
-
- if (lineIncrement == this.lineIncrement)
+
+ if (lineIncrement == 0)
+ lineIncrement = 1;
+
+ if (lineIncrement == this.lineIncrement)
return;
-
+
this.lineIncrement = lineIncrement;
ScrollbarPeer peer = (ScrollbarPeer) getPeer();
@@ -507,15 +483,9 @@
if (pageIncrement < 0)
throw new IllegalArgumentException("Block increment less than zero.");
- int range = maximum - minimum;
- if (pageIncrement > range)
- {
- if (range == 0)
- pageIncrement = 1;
- else
- pageIncrement = range;
- }
-
+ if (pageIncrement == 0)
+ pageIncrement = 1;
+
if (pageIncrement == this.pageIncrement)
return;