Hi,

I adjusted the BasicOptionPaneUI to work properly with Lillian's
reworked Graphics.drawString. The problem here is that JLabel is not
able to display multiline strings, so we have to split this over
multiple JLabels.

2005-11-22  Roman Kennke  <[EMAIL PROTECTED]>

        * javax/swing/plaf/basic/BasicOptionPaneUI.java
        (addMessageComponents): Also burst the string if there are
newlines
        in it.
        (burstStringInto): Improved algorithm to also handle newlines.

/Roman
Index: javax/swing/plaf/basic/BasicOptionPaneUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicOptionPaneUI.java,v
retrieving revision 1.27
diff -u -r1.27 BasicOptionPaneUI.java
--- javax/swing/plaf/basic/BasicOptionPaneUI.java	18 Oct 2005 22:10:32 -0000	1.27
+++ javax/swing/plaf/basic/BasicOptionPaneUI.java	22 Nov 2005 15:14:35 -0000
@@ -774,7 +774,7 @@
 	// it will create a box and burst the string.
 	// otherwise, it will just create a label and re-call 
 	// this method with the label o.O
-	if (msg.toString().length() > maxll)
+	if (msg.toString().length() > maxll || msg.toString().contains("\n"))
 	  {
 	    Box tmp = new Box(BoxLayout.Y_AXIS);
 	    burstStringInto(tmp, msg.toString(), maxll);
@@ -796,17 +796,35 @@
    */
   protected void burstStringInto(Container c, String d, int maxll)
   {
-    // FIXME: Verify that this is the correct behaviour.
-    // One interpretation of the spec is that this method
-    // should recursively call itself to create (and add) 
-    // JLabels to the container if the length of the String d
-    // is greater than maxll.
-    // but in practice, even with a really long string, this is 
-    // all that happens.
     if (d == null || c == null)
       return;
-    JLabel label = new JLabel(d);
+
+    int newlineIndex = d.indexOf('\n');
+    String line;
+    String remainder;
+    if (newlineIndex >= 0 && newlineIndex < maxll)
+      {
+        line = d.substring(0, newlineIndex);
+        remainder = d.substring(newlineIndex + 1);
+      }
+    else
+      {
+        line = d.substring(0, maxll);
+        remainder = d.substring(maxll);
+      }
+    JLabel label = new JLabel(line);
     c.add(label);
+
+    // If there is nothing left to burst, then we can stop.
+    if (remainder.length() == 0)
+      return;
+
+    // Recursivly call ourselves to burst the remainder of the string, 
+    if ((remainder.length() > maxll || remainder.contains("\n")))
+      burstStringInto(c, remainder, maxll);
+    else
+      // Add the remainder to the container and be done.
+      c.add(new JLabel(remainder)); 
   }
 
   /**
_______________________________________________
Classpath-patches mailing list
Classpath-patches@gnu.org
http://lists.gnu.org/mailman/listinfo/classpath-patches

Reply via email to