[kaffe] CVS kaffe (robilad): Resynced with GNU Classpath: graydon's swing fixes

Kaffe CVS cvs-commits at kaffe.org
Sat Nov 13 17:14:19 PST 2004


PatchSet 5454 
Date: 2004/11/14 01:10:07
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
Resynced with GNU Classpath: graydon's swing fixes

2004-11-13  Dalibor Topic  <robilad at kaffe.org>

        * libraries/javalib/javax/swing/plaf/basic/BasicTextUI.java,
        libraries/javalib/javax/swing/text/GapContent.java,
        libraries/javalib/javax/swing/text/PlainDocument.java,
        libraries/javalib/javax/swing/text/Utilities.java:
        Resynced with GNU Classpath.

        2004-11-11  Graydon Hoare  <graydon at redhat.com>

        * javax/swing/plaf/basic/BasicTextUI.java:
        Listen to focus events, indicate focus via caret.
        * javax/swing/text/GapContent.java (getString): Return substring.
        * javax/swing/text/PlainDocument.java (reindex): New method.
        (createDefaultRoot): Call it.
        (insertUpdate): Likewise.
        (removeUpdate): Likewise.
        * javax/swing/text/Utilities.java (drawTabbedText): Always advance
        on tab and newline, even if no painting happens.

Members: 
	ChangeLog:1.3000->1.3001 
	libraries/javalib/javax/swing/plaf/basic/BasicTextUI.java:1.7->1.8 
	libraries/javalib/javax/swing/text/GapContent.java:1.1->1.2 
	libraries/javalib/javax/swing/text/PlainDocument.java:1.2->1.3 
	libraries/javalib/javax/swing/text/Utilities.java:1.2->1.3 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.3000 kaffe/ChangeLog:1.3001
--- kaffe/ChangeLog:1.3000	Sat Nov 13 23:58:05 2004
+++ kaffe/ChangeLog	Sun Nov 14 01:10:07 2004
@@ -1,5 +1,25 @@
 2004-11-13  Dalibor Topic  <robilad at kaffe.org>
 
+	* libraries/javalib/javax/swing/plaf/basic/BasicTextUI.java,
+	libraries/javalib/javax/swing/text/GapContent.java,
+	libraries/javalib/javax/swing/text/PlainDocument.java,
+	libraries/javalib/javax/swing/text/Utilities.java:
+	Resynced with GNU Classpath.
+
+	2004-11-11  Graydon Hoare  <graydon at redhat.com>
+
+        * javax/swing/plaf/basic/BasicTextUI.java:
+        Listen to focus events, indicate focus via caret.
+        * javax/swing/text/GapContent.java (getString): Return substring.
+        * javax/swing/text/PlainDocument.java (reindex): New method.
+        (createDefaultRoot): Call it.
+        (insertUpdate): Likewise.
+        (removeUpdate): Likewise.
+        * javax/swing/text/Utilities.java (drawTabbedText): Always advance
+        on tab and newline, even if no painting happens.
+
+2004-11-13  Dalibor Topic  <robilad at kaffe.org>
+
 	* libraries/clib/awt/classpath-gtk/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c:
 	Resynced with GNU Classpath.
 
Index: kaffe/libraries/javalib/javax/swing/plaf/basic/BasicTextUI.java
diff -u kaffe/libraries/javalib/javax/swing/plaf/basic/BasicTextUI.java:1.7 kaffe/libraries/javalib/javax/swing/plaf/basic/BasicTextUI.java:1.8
--- kaffe/libraries/javalib/javax/swing/plaf/basic/BasicTextUI.java:1.7	Sat Nov 13 02:17:46 2004
+++ kaffe/libraries/javalib/javax/swing/plaf/basic/BasicTextUI.java	Sun Nov 14 01:10:10 2004
@@ -45,6 +45,8 @@
 import java.awt.Point;
 import java.awt.Rectangle;
 import java.awt.Shape;
+import java.awt.event.FocusEvent;
+import java.awt.event.FocusListener;
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
 
@@ -228,9 +230,20 @@
     caret.setBlinkRate(defaults.getInt(prefix + ".caretBlinkRate"));
   }
 
+  private FocusListener focuslistener = new FocusListener() {
+      public void focusGained(FocusEvent e)
+      {
+        textComponent.repaint();
+      }
+      public void focusLost(FocusEvent e)
+      {
+        textComponent.repaint();
+      }
+    };
+
   protected void installListeners()
   {
-    // Do nothing here.
+    textComponent.addFocusListener(focuslistener);
   }
 
   protected String getKeymapName()
@@ -328,7 +341,7 @@
 
   protected void uninstallListeners()
   {
-    // Do nothing here.
+    textComponent.removeFocusListener(focuslistener);
   }
 
   protected void uninstallKeyboardActions()
@@ -367,7 +380,7 @@
 
     rootView.paint(g, getVisibleEditorRect());
 
-    if (caret != null)
+    if (caret != null && textComponent.hasFocus())
       caret.paint(g);
   }
 
Index: kaffe/libraries/javalib/javax/swing/text/GapContent.java
diff -u kaffe/libraries/javalib/javax/swing/text/GapContent.java:1.1 kaffe/libraries/javalib/javax/swing/text/GapContent.java:1.2
--- kaffe/libraries/javalib/javax/swing/text/GapContent.java:1.1	Thu Jul 22 19:37:40 2004
+++ kaffe/libraries/javalib/javax/swing/text/GapContent.java	Sun Nov 14 01:10:10 2004
@@ -93,7 +93,7 @@
 
   public String getString(int where, int len) throws BadLocationException
   {
-    return buf.toString();
+    return buf.substring(where, where+len);
   }
 
   public void getChars(int where, int len, Segment txt)
Index: kaffe/libraries/javalib/javax/swing/text/PlainDocument.java
diff -u kaffe/libraries/javalib/javax/swing/text/PlainDocument.java:1.2 kaffe/libraries/javalib/javax/swing/text/PlainDocument.java:1.3
--- kaffe/libraries/javalib/javax/swing/text/PlainDocument.java:1.2	Sun Jul 25 06:37:52 2004
+++ kaffe/libraries/javalib/javax/swing/text/PlainDocument.java	Sun Nov 14 01:10:10 2004
@@ -37,6 +37,8 @@
 
 package javax.swing.text;
 
+import java.util.ArrayList;
+
 public class PlainDocument extends AbstractDocument
 {
   private static final long serialVersionUID = 4758290289196893664L;
@@ -59,14 +61,53 @@
     rootElement = createDefaultRoot();
   }
 
-  protected AbstractDocument.AbstractElement createDefaultRoot()
+  protected void reindex()
   {
-    BranchElement rootElement =
-      (BranchElement) createBranchElement(null, null);
-    Element[] lines = new Element[1];
+    Element[] lines;
+    try
+      {
+        String str = content.getString(0, content.length());
+
+        ArrayList elts = new ArrayList();
+        int j = 0;
+        for (int i = str.indexOf('\n', 0); i != -1; i = str.indexOf('\n', i+1))
+          {
+            elts.add(createLeafElement(rootElement, null, j, i));
+            j = i;
+          }
+
+        if (j < content.length())
+          elts.add(createLeafElement(rootElement, null, j, content.length()));
+
+        lines = new Element[elts.size()];
+        for (int i = 0; i < elts.size(); ++i)
+          lines[i] = (Element) elts.get(i);
+
+      }
+    catch (BadLocationException e)
+  {
+        lines = new Element[1];
     lines[0] = createLeafElement(rootElement, null, 0, 1);
-    rootElement.replace(0, 0, lines);
-    return rootElement;
+      }
+
+    ((BranchElement) rootElement).replace(0, rootElement.getElementCount(), lines);
+  }
+
+  protected AbstractDocument.AbstractElement createDefaultRoot()
+  {
+    rootElement = createBranchElement(null, null);
+    reindex();
+    return (AbstractElement) rootElement;
+  }
+
+  protected void insertUpdate(DefaultDocumentEvent chng, AttributeSet attr)
+  {
+    reindex();
+  }
+
+  protected void removeUpdate(DefaultDocumentEvent chng)
+  {
+    reindex();
   }
 
   public Element getDefaultRootElement()
Index: kaffe/libraries/javalib/javax/swing/text/Utilities.java
diff -u kaffe/libraries/javalib/javax/swing/text/Utilities.java:1.2 kaffe/libraries/javalib/javax/swing/text/Utilities.java:1.3
--- kaffe/libraries/javalib/javax/swing/text/Utilities.java:1.2	Sat Oct  9 22:18:56 2004
+++ kaffe/libraries/javalib/javax/swing/text/Utilities.java	Sun Nov 14 01:10:10 2004
@@ -98,15 +98,17 @@
     for (int offset = s.offset; offset < (s.offset + s.count); ++offset)
       {
         char c = buffer[offset];
-        if (len > 0 && (c == '\t' || c == '\n'))
+        if (c == '\t' || c == '\n')
           {
-	    g.drawChars(buffer, pos, len, pixelX, pixelY + ascent);            
-            pixelX += pixelWidth;
-            pixelWidth = 0;
+            if (len > 0) {
+              g.drawChars(buffer, pos, len, pixelX, pixelY + ascent);            
+              pixelX += pixelWidth;
+              pixelWidth = 0;
+            }
             pos = offset+1;
             len = 0;
           }
-          
+        
 	switch (c)
 	  {
 	  case '\t':



More information about the kaffe mailing list