commit-classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[commit-cp] classpath ChangeLog javax/swing/text/AbstractDo...


From: Roman Kennke
Subject: [commit-cp] classpath ChangeLog javax/swing/text/AbstractDo...
Date: Wed, 21 Jun 2006 17:04:42 +0000

CVSROOT:        /cvsroot/classpath
Module name:    classpath
Changes by:     Roman Kennke <rabbit78> 06/06/21 17:04:41

Modified files:
        .              : ChangeLog 
        javax/swing/text: AbstractDocument.java JTextComponent.java 
                          PlainDocument.java 
        javax/swing/text/rtf: RTFParser.java RTFScanner.java 

Log message:
        2006-06-21  Roman Kennke  <address@hidden>
        
                * javax/swing/text/AbstractDocument.java
                (BranchElement.numChildren): New field.
                (BranchElement.BranchElement): Initialize children array with
                one element (that's the least number of elements that makes 
sense).
                Initialize numChildren.
                (BranchElement.children): Use numChildren as boundary.
                (BranchElement.getElement): Use numChildren as boundary.
                (BranchElement.getElementCount): Use numChildren as boundary.
                (BranchElement.getElementIndex): Use numChildren as boundary.
                (BranchElement.getEndOffset): Use numChildren as boundary.
                (BranchElement.getStartOffset): Use numChildren as boundary.
                (BranchElement.positionToElement): Use numChildren as boundary.
                (BranchElement.replace): Handle the children array more 
efficiently
                by growing in blocks > 1, and reusing space from removed 
elements.
                (LeafElement.startDelta): Removed.
                (LeafElement.endDelta): Removed.
                (LeafElement.LeafElement): Removed handling of deltas.
                (LeafElement.getEndOffset): Likewise.
                (LeafElement.getStartOffset): Likewise.
                * javax/swing/text/JTextComponent.java
                (setDocument): Added locking of the old document to avoid 
dangling
                notification beeing delivered while the document is beeing
                disconnected.
                (getScrollableTracksViewportWidth): Fixed condition.
                * javax/swing/text/PlainDocument.java
                (createDefaultRoot): Create elements without AttributeSet.
                * javax/swing/text/rtf/RTFParser.java
                (parseFile): Handle slightly incorrect RTF gracefully.
                * javax/swing/text/rtf/RTFScanner.java
                (lastToken): New field.
                (readTokenImpl): New method.
                (peekToken): New method.
                (readToken): Changed to call readTokenImpl or return the 
lastToken
                if there's one present.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/classpath/ChangeLog?cvsroot=classpath&r1=1.7904&r2=1.7905
http://cvs.savannah.gnu.org/viewcvs/classpath/javax/swing/text/AbstractDocument.java?cvsroot=classpath&r1=1.57&r2=1.58
http://cvs.savannah.gnu.org/viewcvs/classpath/javax/swing/text/JTextComponent.java?cvsroot=classpath&r1=1.59&r2=1.60
http://cvs.savannah.gnu.org/viewcvs/classpath/javax/swing/text/PlainDocument.java?cvsroot=classpath&r1=1.21&r2=1.22
http://cvs.savannah.gnu.org/viewcvs/classpath/javax/swing/text/rtf/RTFParser.java?cvsroot=classpath&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/classpath/javax/swing/text/rtf/RTFScanner.java?cvsroot=classpath&r1=1.3&r2=1.4

Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/classpath/classpath/ChangeLog,v
retrieving revision 1.7904
retrieving revision 1.7905
diff -u -b -r1.7904 -r1.7905
--- ChangeLog   21 Jun 2006 16:11:37 -0000      1.7904
+++ ChangeLog   21 Jun 2006 17:04:41 -0000      1.7905
@@ -1,3 +1,40 @@
+2006-06-21  Roman Kennke  <address@hidden>
+
+       * javax/swing/text/AbstractDocument.java
+       (BranchElement.numChildren): New field.
+       (BranchElement.BranchElement): Initialize children array with
+       one element (that's the least number of elements that makes sense).
+       Initialize numChildren.
+       (BranchElement.children): Use numChildren as boundary.
+       (BranchElement.getElement): Use numChildren as boundary.
+       (BranchElement.getElementCount): Use numChildren as boundary.
+       (BranchElement.getElementIndex): Use numChildren as boundary.
+       (BranchElement.getEndOffset): Use numChildren as boundary.
+       (BranchElement.getStartOffset): Use numChildren as boundary.
+       (BranchElement.positionToElement): Use numChildren as boundary.
+       (BranchElement.replace): Handle the children array more efficiently
+       by growing in blocks > 1, and reusing space from removed elements.
+       (LeafElement.startDelta): Removed.
+       (LeafElement.endDelta): Removed.
+       (LeafElement.LeafElement): Removed handling of deltas.
+       (LeafElement.getEndOffset): Likewise.
+       (LeafElement.getStartOffset): Likewise.
+       * javax/swing/text/JTextComponent.java
+       (setDocument): Added locking of the old document to avoid dangling
+       notification beeing delivered while the document is beeing
+       disconnected.
+       (getScrollableTracksViewportWidth): Fixed condition.
+       * javax/swing/text/PlainDocument.java
+       (createDefaultRoot): Create elements without AttributeSet.
+       * javax/swing/text/rtf/RTFParser.java
+       (parseFile): Handle slightly incorrect RTF gracefully.
+       * javax/swing/text/rtf/RTFScanner.java
+       (lastToken): New field.
+       (readTokenImpl): New method.
+       (peekToken): New method.
+       (readToken): Changed to call readTokenImpl or return the lastToken
+       if there's one present.
+
 2006-06-21  Tania Bento  <address@hidden>
 
        * javax/swing/JMenu.java

Index: javax/swing/text/AbstractDocument.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/AbstractDocument.java,v
retrieving revision 1.57
retrieving revision 1.58
diff -u -b -r1.57 -r1.58
--- javax/swing/text/AbstractDocument.java      13 May 2006 23:11:13 -0000      
1.57
+++ javax/swing/text/AbstractDocument.java      21 Jun 2006 17:04:41 -0000      
1.58
@@ -1674,8 +1674,15 @@
     /** The serialization UID (compatible with JDK1.5). */
     private static final long serialVersionUID = -6037216547466333183L;
 
-    /** The child elements of this BranchElement. */
-    private Element[] children = new Element[0];
+    /**
+     * The child elements of this BranchElement.
+     */
+    private Element[] children;;
+
+    /**
+     * The number of children in the branch element.
+     */
+    private int numChildren;
 
     /**
      * The cached startOffset value. This is used in the case when a
@@ -1700,6 +1707,8 @@
     public BranchElement(Element parent, AttributeSet attributes)
     {
       super(parent, attributes);
+      children = new Element[1];
+      numChildren = 0;
       startOffset = -1;
       endOffset = -1;
     }
@@ -1716,7 +1725,7 @@
 
       Vector tmp = new Vector();
 
-      for (int index = 0; index < children.length; ++index)
+      for (int index = 0; index < numChildren; ++index)
        tmp.add(children[index]);
       
       return tmp.elements();
@@ -1743,7 +1752,7 @@
      */
     public Element getElement(int index)
     {
-      if (index < 0 || index >= children.length)
+      if (index < 0 || index >= numChildren)
        return null;
 
       return children[index];
@@ -1756,7 +1765,7 @@
      */
     public int getElementCount()
     {
-      return children.length;
+      return numChildren;
     }
 
     /**
@@ -1777,7 +1786,7 @@
 
       // XXX: There is surely a better algorithm
       // as beginning from first element each time.
-      for (int index = 0; index < children.length - 1; ++index)
+      for (int index = 0; index < numChildren - 1; ++index)
         {
           Element elem = children[index];
 
@@ -1814,13 +1823,13 @@
      */
     public int getEndOffset()
     {
-      if (children.length == 0)
+      if (numChildren == 0)
         {
           if (endOffset == -1)
             throw new NullPointerException("BranchElement has no children.");
         }
       else
-        endOffset = children[children.length - 1].getEndOffset();
+        endOffset = children[numChildren - 1].getEndOffset();
 
       return endOffset;
     }
@@ -1848,7 +1857,7 @@
      */
     public int getStartOffset()
     {
-      if (children.length == 0)
+      if (numChildren == 0)
         {
           if (startOffset == -1)
             throw new NullPointerException("BranchElement has no children.");
@@ -1884,7 +1893,7 @@
     {
       // XXX: There is surely a better algorithm
       // as beginning from first element each time.
-      for (int index = 0; index < children.length; ++index)
+      for (int index = 0; index < numChildren; ++index)
         {
          Element elem = children[index];
 
@@ -1905,15 +1914,28 @@
      */
     public void replace(int offset, int length, Element[] elements)
     {
-      Element[] target = new Element[children.length - length
-                                    + elements.length];
+      if (numChildren + elements.length - length > children.length)
+        {
+          // Gotta grow the array.
+          int newSize = Math.max(2 * children.length,
+                                 numChildren + elements.length - length);
+          Element[] target = new Element[newSize];
       System.arraycopy(children, 0, target, 0, offset);
       System.arraycopy(elements, 0, target, offset, elements.length);
       System.arraycopy(children, offset + length, target,
                       offset + elements.length,
-                      children.length - offset - length);
+                           numChildren - offset - length);
       children = target;
     }
+      else
+        {
+          System.arraycopy(children, offset + length, children,
+                           offset + elements.length,
+                           numChildren - offset - length);
+          System.arraycopy(elements, 0, children, offset, elements.length);
+        }
+      numChildren += elements.length - length;
+    }
 
     /**
      * Returns a string representation of this element.
@@ -2165,18 +2187,6 @@
     private Position endPos;
 
     /**
-     * This gets possible added to the startOffset when a startOffset
-     * outside the document range is requested.
-     */
-    private int startDelta;
-
-    /**
-     * This gets possible added to the endOffset when a endOffset
-     * outside the document range is requested.
-     */
-    private int endDelta;
-    
-    /**
      * Creates a new <code>LeafElement</code>.
      *
      * @param parent the parent of this <code>LeafElement</code>
@@ -2188,17 +2198,10 @@
                        int end)
     {
       super(parent, attributes);
-      int len = content.length();
-      startDelta = 0;
-      if (start > len)
-        startDelta = start - len;
-      endDelta = 0;
-      if (end > len)
-        endDelta = end - len;
       try
            {
-                 startPos = createPosition(start - startDelta);
-                 endPos = createPosition(end - endDelta);
+          startPos = createPosition(start);
+          endPos = createPosition(end);
                }
          catch (BadLocationException ex)
            {
@@ -2281,7 +2284,7 @@
      */
     public int getEndOffset()
     {
-      return endPos.getOffset() + endDelta;
+      return endPos.getOffset();
     }
 
     /**
@@ -2307,7 +2310,7 @@
      */
     public int getStartOffset()
     {
-      return startPos.getOffset() + startDelta;
+      return startPos.getOffset();
     }
 
     /**

Index: javax/swing/text/JTextComponent.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/JTextComponent.java,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -b -r1.59 -r1.60
--- javax/swing/text/JTextComponent.java        20 Jun 2006 18:24:14 -0000      
1.59
+++ javax/swing/text/JTextComponent.java        21 Jun 2006 17:04:41 -0000      
1.60
@@ -42,6 +42,7 @@
 
 import java.awt.AWTEvent;
 import java.awt.Color;
+import java.awt.Container;
 import java.awt.Dimension;
 import java.awt.Insets;
 import java.awt.Point;
@@ -1179,8 +1180,19 @@
   public void setDocument(Document newDoc)
   {
     Document oldDoc = doc;
+    try
+      {
+        if (oldDoc instanceof AbstractDocument)
+          ((AbstractDocument) oldDoc).readLock();
+
     doc = newDoc;
     firePropertyChange("document", oldDoc, newDoc);
+      }
+    finally
+      {
+        if (oldDoc instanceof AbstractDocument)
+          ((AbstractDocument) oldDoc).readUnlock();
+      }
     revalidate();
     repaint();
   }
@@ -1657,10 +1669,12 @@
 
   public boolean getScrollableTracksViewportWidth()
   {
-    if (getParent() instanceof JViewport)
-      return getParent().getWidth() > getPreferredSize().width;
+    boolean res = false;;
+    Container c = getParent();
+    if (c instanceof JViewport)
+      res = ((JViewport) c).getExtentSize().width > getPreferredSize().width;
 
-    return false;
+    return res;
   }
 
   /**

Index: javax/swing/text/PlainDocument.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/PlainDocument.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -b -r1.21 -r1.22
--- javax/swing/text/PlainDocument.java 6 Mar 2006 10:51:19 -0000       1.21
+++ javax/swing/text/PlainDocument.java 21 Jun 2006 17:04:41 -0000      1.22
@@ -105,10 +105,10 @@
   protected AbstractDocument.AbstractElement createDefaultRoot()
   {
     BranchElement root =
-      (BranchElement) createBranchElement(null, SimpleAttributeSet.EMPTY);
+      (BranchElement) createBranchElement(null, null);
 
     Element[] array = new Element[1];
-    array[0] = createLeafElement(root, SimpleAttributeSet.EMPTY, 0, 1);
+    array[0] = createLeafElement(root, null, 0, 1);
     root.replace(0, 0, array);
     
     return root;

Index: javax/swing/text/rtf/RTFParser.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/rtf/RTFParser.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- javax/swing/text/rtf/RTFParser.java 2 Jul 2005 20:32:51 -0000       1.3
+++ javax/swing/text/rtf/RTFParser.java 21 Jun 2006 17:04:41 -0000      1.4
@@ -140,9 +140,17 @@
     parseHeader();
     parseDocument();
   
-    Token t2 = scanner.readToken();
-    if (t2.type != Token.RCURLY)
-      throw new RTFParseException("expected right curly braces");
+    Token t2 = scanner.peekToken();
+    if (t2.type == Token.RCURLY)
+      {
+        // Eat the token.
+        scanner.readToken();
+      }
+    else
+      {
+        // Ignore this for maximum robustness when file is broken.
+        System.err.println("RTF warning: expected right curly braces");
+      }
 
   }
 

Index: javax/swing/text/rtf/RTFScanner.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/rtf/RTFScanner.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- javax/swing/text/rtf/RTFScanner.java        2 Jul 2005 20:32:51 -0000       
1.3
+++ javax/swing/text/rtf/RTFScanner.java        21 Jun 2006 17:04:41 -0000      
1.4
@@ -71,6 +71,11 @@
   private StringBuffer buffer;
 
   /**
+   * Lookahead token.
+   */
+  private Token lastToken;
+
+  /**
    * Constructs a new RTFScanner without initializing the address@hidden 
Reader}.
    */
   private RTFScanner()
@@ -120,7 +125,7 @@
    *
    * @throws IOException if the underlying stream has problems
    */
-  public Token readToken()
+  private Token readTokenImpl()
     throws IOException
   {
     Token token = null;
@@ -156,6 +161,27 @@
     return token;
   }
 
+  Token peekToken()
+    throws IOException
+  {
+    lastToken = readTokenImpl();
+    return lastToken;
+  }
+
+  Token readToken()
+    throws IOException
+  {
+    Token token;
+    if (lastToken != null)
+      {
+        token = lastToken;
+        lastToken = null;
+      }
+    else
+      token = readTokenImpl();
+    return token;
+  }
+
   /**
    * Reads in a control word and optional parameter.
    *




reply via email to

[Prev in Thread] Current Thread [Next in Thread]