Hi there,
This fixes BasicTextUI.paint and related methods to conform with the
specs. Most importantly, paint() must acquire a read lock on the
document to prevent bad things to happen while painting. Also, update()
must be overridden and paintBackground() implemented, so that the
background painting is also thread safe. (Recall that while Swing is
generally not threadsafe, their is some locking required in the text
package).
2006-02-07 Roman Kennke <[EMAIL PROTECTED]>
* javax/swing/plaf/basic/BasicTextUI.java
(paint): Acquire read lock on the document before calling
paintSafely.
(paintSafely): Added comment about what this method does.
(paintBackground): Implemented to actually paint the background.
(update): Overridden to _not_ paint the background. This is done
in paintBackground in this UI.
/Roman
Index: javax/swing/plaf/basic/BasicTextUI.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/plaf/basic/BasicTextUI.java,v
retrieving revision 1.65
diff -u -r1.65 BasicTextUI.java
--- javax/swing/plaf/basic/BasicTextUI.java 7 Feb 2006 11:55:29 -0000 1.65
+++ javax/swing/plaf/basic/BasicTextUI.java 7 Feb 2006 15:32:21 -0000
@@ -66,6 +66,7 @@
import javax.swing.plaf.InputMapUIResource;
import javax.swing.plaf.TextUI;
import javax.swing.plaf.UIResource;
+import javax.swing.text.AbstractDocument;
import javax.swing.text.BadLocationException;
import javax.swing.text.Caret;
import javax.swing.text.DefaultCaret;
@@ -816,18 +817,49 @@
}
/**
- * Paints the text component.
+ * Paints the text component. This acquires a read lock on the model and then
+ * calls [EMAIL PROTECTED] #paintSafely(Graphics)} in order to actually perform the
+ * painting.
*
* @param g the <code>Graphics</code> context to paint to
* @param c not used here
*/
public final void paint(Graphics g, JComponent c)
{
- paintSafely(g);
+ try
+ {
+ Document doc = textComponent.getDocument();
+ if (doc instanceof AbstractDocument)
+ {
+ AbstractDocument aDoc = (AbstractDocument) doc;
+ aDoc.readLock();
+ }
+
+ paintSafely(g);
+ }
+ finally
+ {
+ Document doc = textComponent.getDocument();
+ if (doc instanceof AbstractDocument)
+ {
+ AbstractDocument aDoc = (AbstractDocument) doc;
+ aDoc.readUnlock();
+ }
+ }
}
/**
- * Actually performs the painting.
+ * This paints the text component while beeing sure that the model is not
+ * modified while painting.
+ *
+ * The following is performed in this order:
+ * <ol>
+ * <li>If the text component is opaque, the background is painted by
+ * calling [EMAIL PROTECTED] #paintBackground(Graphics)}.</li>
+ * <li>If there is a highlighter, the highlighter is painted.</li>
+ * <li>The view hierarchy is painted.</li>
+ * <li>The Caret is painter.</li>
+ * </ol>
*
* @param g the <code>Graphics</code> context to paint to
*/
@@ -840,7 +872,7 @@
paintBackground(g);
if (highlighter != null
- && textComponent.getSelectionStart() != textComponent.getSelectionEnd())
+ && textComponent.getSelectionStart() != textComponent.getSelectionEnd())
highlighter.paint(g);
rootView.paint(g, getVisibleEditorRect());
@@ -856,10 +888,23 @@
*/
protected void paintBackground(Graphics g)
{
- // This method does nothing. All the background filling is done by the
- // ComponentUI update method. However, the method is called by paint
- // to provide a way for subclasses to draw something different (e.g.
- // background images etc) on the background.
+ Color old = g.getColor();
+ g.setColor(textComponent.getBackground());
+ g.fillRect(0, 0, textComponent.getWidth(), textComponent.getHeight());
+ g.setColor(old);
+ }
+
+ /**
+ * Overridden for better control over background painting. This now simply
+ * calls [EMAIL PROTECTED] #paint} and this delegates the background painting to
+ * [EMAIL PROTECTED] #paintBackground}.
+ *
+ * @param g the graphics to use
+ * @param c the component to be painted
+ */
+ public void update(Graphics g, JComponent c)
+ {
+ paint(g, c);
}
/**