2005-04-19 Roman Kennke <roman@kennke.org>
authormkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 19 Apr 2005 10:55:12 +0000 (10:55 +0000)
committermkoch <mkoch@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 19 Apr 2005 10:55:12 +0000 (10:55 +0000)
* javax/swing/text/JTextComponent.java
(JTextComponent): Added repaintListener which issues repaint
requests when the underlying document changes.
(setDocument): Adds repaintListener to document when the
document is changed.
* javax/swing/text/DefaultEditorKit.java:
Removed repaint calls on JTextComponent. This is now handled
through a DocumentListener in JTextComponent that repaints
the component when needed.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@98403 138bc75d-0d04-0410-961f-82ee72b054a4

libjava/ChangeLog
libjava/javax/swing/text/DefaultEditorKit.java
libjava/javax/swing/text/JTextComponent.java

index 686453d..49677a3 100644 (file)
@@ -1,5 +1,17 @@
 2005-04-19  Roman Kennke  <roman@kennke.org>
 
+       * javax/swing/text/JTextComponent.java
+       (JTextComponent): Added repaintListener which issues repaint
+       requests when the underlying document changes.
+       (setDocument): Adds repaintListener to document when the
+       document is changed.
+       * javax/swing/text/DefaultEditorKit.java:
+       Removed repaint calls on JTextComponent. This is now handled
+       through a DocumentListener in JTextComponent that repaints
+       the component when needed.
+
+2005-04-19  Roman Kennke  <roman@kennke.org>
+
        PR libgcj/21064
        * javax/swing/text/StyleContext.java
        (NamedStyle.setResolveParent): Added null
index ecec707..891731f 100644 (file)
@@ -110,7 +110,6 @@ public class DefaultEditorKit extends EditorKit
               t.getDocument().insertString(t.getCaret().getDot(), event.getActionCommand(), null);
               t.getCaret().setDot(Math.min(t.getCaret().getDot() + 1,
                                            t.getDocument().getEndPosition().getOffset()));
-              t.repaint();
             }
           catch (BadLocationException be)
             {
@@ -251,7 +250,6 @@ public class DefaultEditorKit extends EditorKit
                 if (pos < t.getDocument().getEndPosition().getOffset())
                   {
                     t.getDocument().remove(t.getCaret().getDot(), 1);
-                    t.repaint();
                   }
               }
             catch (BadLocationException e)
@@ -275,7 +273,6 @@ public class DefaultEditorKit extends EditorKit
                   {
                     t.getDocument().remove(pos - 1, 1);
                     t.getCaret().setDot(pos - 1);
-                    t.repaint();
                   }
               }
             catch (BadLocationException e)
index f3721a8..fa0040b 100644 (file)
@@ -894,11 +894,30 @@ public abstract class JTextComponent extends JComponent
   private Insets margin;
   private boolean dragEnabled;
 
+  /** Issues repaint request on document changes. */
+  private DocumentListener repaintListener;
+
   /**
    * Creates a new <code>JTextComponent</code> instance.
    */
   public JTextComponent()
   {
+    repaintListener = new DocumentListener()
+      {
+       public void changedUpdate(DocumentEvent ev)
+       {
+         repaint();
+       }
+       public void insertUpdate(DocumentEvent ev)
+       {
+         repaint();
+       }
+       public void removeUpdate(DocumentEvent ev)
+       {
+         repaint();
+       }
+      };
+
     Keymap defkeymap = getKeymap(DEFAULT_KEYMAP);
     boolean creatingKeymap = false;
     if (defkeymap == null)
@@ -932,6 +951,13 @@ public abstract class JTextComponent extends JComponent
   {
     Document oldDoc = doc;
     doc = newDoc;
+
+    // setup document listener
+    if (oldDoc != null)
+      oldDoc.removeDocumentListener(repaintListener);
+    if (newDoc != null)
+      newDoc.addDocumentListener(repaintListener);
+
     firePropertyChange("document", oldDoc, newDoc);
     revalidate();
     repaint();