The new (corrected) BoxLayout exposed some buggies with JSeparator that
broke menus in Swing in weird ways. I fixed the
getMinimum/Maximum/PreferredSize() methods and some smaller stuff and now
the menus work again.
2005-09-27 Roman Kennke <[EMAIL PROTECTED]>
* javax/swing/JSeparator.java
(updateUI): Removed invalidate call. This is unnecessary.
* javax/swing/plaf/basic/BasicSeparatorUI.java
(paint): Reworked painting so that it paints the separator
correctly.
(getPreferredSize): Fixed to return the correct values according
to the JDK.
(getMinimumSize): Likewise.
(getMaximumSize): Likewise.
/Roman
Index: javax/swing/JSeparator.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/JSeparator.java,v
retrieving revision 1.9
diff -u -r1.9 JSeparator.java
--- javax/swing/JSeparator.java 21 Jul 2005 14:59:31 -0000 1.9
+++ javax/swing/JSeparator.java 27 Sep 2005 20:51:37 -0000
@@ -131,7 +131,6 @@
public void updateUI()
{
setUI((SeparatorUI) UIManager.getUI(this));
- invalidate();
}
/**
Index: javax/swing/plaf/basic/BasicSeparatorUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicSeparatorUI.java,v
retrieving revision 1.6
diff -u -r1.6 BasicSeparatorUI.java
--- javax/swing/plaf/basic/BasicSeparatorUI.java 2 Jul 2005 20:32:50 -0000 1.6
+++ javax/swing/plaf/basic/BasicSeparatorUI.java 27 Sep 2005 20:51:37 -0000
@@ -57,6 +57,27 @@
*/
public class BasicSeparatorUI extends SeparatorUI
{
+ /**
+ * The standard minimum size.
+ */
+ static final Dimension minSize = new Dimension(0, 0);
+
+ /**
+ * The standard horizontal preferred size.
+ */
+ static final Dimension horizontalPrefSize = new Dimension(0, 2);
+
+ /**
+ * The standard vertical preferred size.
+ */
+ static final Dimension verticalPrefSize = new Dimension(2, 0);
+
+ /**
+ * The standard maxnimum size.
+ */
+ static final Dimension maxSize = new Dimension(Short.MAX_VALUE,
+ Short.MAX_VALUE);
+
/** The shadow color. */
protected Color shadow;
@@ -165,8 +186,8 @@
/**
* The separator is made of two lines. The top line will be
- * the highlight color (or left line if it's vertical). The bottom
- * or right line will be the shadow color. The two lines will
+ * the shadow color (or left line if it's vertical). The bottom
+ * or right line will be the highlight color. The two lines will
* be centered inside the bounds box. If the separator is horizontal,
* then it will be vertically centered, or if it's vertical, it will
* be horizontally centered.
@@ -180,9 +201,6 @@
SwingUtilities.calculateInnerArea(c, r);
Color saved = g.getColor();
- int midAB = r.width / 2 + r.x;
- int midAD = r.height / 2 + r.y;
-
JSeparator s;
if (c instanceof JSeparator)
s = (JSeparator) c;
@@ -190,21 +208,24 @@
return;
if (s.getOrientation() == JSeparator.HORIZONTAL)
- {
- g.setColor(highlight);
- g.drawLine(r.x, midAD, r.x + r.width, midAD);
-
- g.setColor(shadow);
- g.drawLine(r.x, midAD + 1, r.x + r.width, midAD + 1);
- }
- else
- {
- g.setColor(highlight);
- g.drawLine(midAB, r.y, midAB, r.y + r.height);
-
- g.setColor(shadow);
- g.drawLine(midAB + 1, r.y, midAB + 1, r.y + r.height);
- }
+ {
+ int midAB = r.height / 2;
+ g.setColor(shadow);
+ g.drawLine(r.x, r.y + midAB - 1, r.x + r.width, r.y + midAB - 1);
+
+ g.setColor(highlight);
+ g.fillRect(r.x, r.y + midAB, r.x + r.width, r.y + midAB);
+ }
+ else
+ {
+ int midAD = r.height / 2 + r.y;
+ g.setColor(shadow);
+ g.drawLine(r.x, r.y, r.x, r.y + r.height);
+
+ g.setColor(highlight);
+ g.fillRect(r.x + midAD, r.y + r.height, r.x + midAD, r.y + r.height);
+ }
+ g.setColor(saved);
}
/**
@@ -217,28 +238,14 @@
*/
public Dimension getPreferredSize(JComponent c)
{
- Dimension dims = new Dimension(0, 0);
- Insets insets = c.getInsets();
-
+ Dimension pref = verticalPrefSize;
if (c instanceof JSeparator)
{
JSeparator s = (JSeparator) c;
-
if (s.getOrientation() == JSeparator.HORIZONTAL)
- {
- dims.height = 2;
- dims.width = 40;
- }
- else
- {
- dims.width = 2;
- dims.height = 40;
- }
+ pref = horizontalPrefSize;
}
- dims.width += insets.left + insets.right;
- dims.height += insets.top + insets.bottom;
-
- return dims;
+ return pref;
}
/**
@@ -251,7 +258,7 @@
*/
public Dimension getMinimumSize(JComponent c)
{
- return getPreferredSize(c);
+ return minSize;
}
/**
@@ -264,6 +271,6 @@
*/
public Dimension getMaximumSize(JComponent c)
{
- return getPreferredSize(c);
+ return maxSize;
}
}_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches