In the BasicArrowButton class, the getMax/Min/PreferredSize() methods should return
a new Dimension instance every time, even though the dimensions never change,
because Dimension is not immutable - the existing code allows the caller to modify
the cached value. This is fixed by this patch (already committed):
2006-07-07 David Gilbert <[EMAIL PROTECTED]>
* javax/swing/plaf/basic/BasicArrowButton.java
(MAXIMUM_SIZE): Removed field,
(MINIMUM_SIZE): Likewise,
(PREFERRED_SIZE): Likewise,
(getMaximumSize): Return new instance every time,
(getMinimumSize): Likewise,
(getPreferredSize): Likewise.
Mauve tests to follow.
Regards,
Dave
Index: javax/swing/plaf/basic/BasicArrowButton.java
===================================================================
RCS file:
/sources/classpath/classpath/javax/swing/plaf/basic/BasicArrowButton.java,v
retrieving revision 1.21
diff -u -r1.21 BasicArrowButton.java
--- javax/swing/plaf/basic/BasicArrowButton.java 5 Jul 2006 13:37:51
-0000 1.21
+++ javax/swing/plaf/basic/BasicArrowButton.java 7 Jul 2006 13:22:46
-0000
@@ -42,7 +42,6 @@
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Polygon;
-import java.awt.Rectangle;
import javax.swing.ButtonModel;
import javax.swing.JButton;
@@ -86,7 +85,9 @@
transient Color highlight = Color.WHITE;
/**
- * Creates a new <code>BasicArrowButton</code> object.
+ * Creates a new <code>BasicArrowButton</code> object with an arrow pointing
+ * in the specified direction. If the <code>direction</code> is not one of
+ * the specified constants, no arrow is drawn.
*
* @param direction The direction the arrow points in (one of:
* [EMAIL PROTECTED] #NORTH}, [EMAIL PROTECTED] #SOUTH}, [EMAIL PROTECTED]
#EAST} and [EMAIL PROTECTED] #WEST}).
@@ -178,16 +179,6 @@
paintTriangle(g, x, y, size, direction, isEnabled());
}
-
- /** The preferred size for the button. */
- private static final Dimension PREFERRED_SIZE = new Dimension(16, 16);
-
- /** The minimum size for the button. */
- private static final Dimension MINIMUM_SIZE = new Dimension(5, 5);
-
- /** The maximum size for the button. */
- private static final Dimension MAXIMUM_SIZE
- = new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
/**
* Returns the preferred size of the arrow button.
@@ -196,7 +187,10 @@
*/
public Dimension getPreferredSize()
{
- return PREFERRED_SIZE;
+ // since Dimension is NOT immutable, we must return a new instance
+ // every time (if we return a cached value, the caller might modify it)
+ // - tests show that the reference implementation does the same.
+ return new Dimension(16, 16);
}
/**
@@ -206,17 +200,23 @@
*/
public Dimension getMinimumSize()
{
- return MINIMUM_SIZE;
+ // since Dimension is NOT immutable, we must return a new instance
+ // every time (if we return a cached value, the caller might modify it)
+ // - tests show that the reference implementation does the same.
+ return new Dimension(5, 5);
}
/**
* Returns the maximum size of the arrow button.
*
- * @return The maximum size.
+ * @return The maximum size (always Integer.MAX_VALUE x Integer.MAX_VALUE).
*/
public Dimension getMaximumSize()
{
- return MAXIMUM_SIZE;
+ // since Dimension is NOT immutable, we must return a new instance
+ // every time (if we return a cached value, the caller might modify it)
+ // - tests show that the reference implementation does the same.
+ return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
}
/**