Hi,

I am adding these last minute patches from Robert to the 0.90 and
generics branch.

2006-03-06  Robert Schuster  <[EMAIL PROTECTED]>

    * javax/swing/text/GapContent.java:
    (insertString): Throw exception when argument is below
    zero.

2006-03-06  Robert Schuster  <[EMAIL PROTECTED]>

    * javax/swing/text/PlainDocument.java:
    (insertUpdate): Extended if-expression, added
    code to generate another Element when newly inserted characters
    and old ones will be on the same line.

2006-03-06  Robert Schuster  <[EMAIL PROTECTED]>

    * javax/swing/text/DefaultCaret.java:
    (mouseDragged): Do selection when shift is pressed.
    (mouseClicked): Implemented.

2006-03-06  Robert Schuster  <[EMAIL PROTECTED]>

    * javax/swing/text/PlainDocument.java: Fix copyright header,
    added author tags.
    (insertUpdate): Do not copy the whole document any more, added some
    more variables to prevent needless method calls.

These will most likely be the last patches to the branches before the
release. Except for some typo patches and final version update. Unless I
can find a way to fix:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26568

Cheers,

Mark
Index: javax/swing/text/DefaultCaret.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/DefaultCaret.java,v
retrieving revision 1.32
diff -u -r1.32 DefaultCaret.java
--- javax/swing/text/DefaultCaret.java	1 Mar 2006 20:39:49 -0000	1.32
+++ javax/swing/text/DefaultCaret.java	6 Mar 2006 15:24:28 -0000
@@ -366,7 +366,8 @@
    * <ul>
    * <li>If we receive a double click, the caret position (dot) is set
    *   to the position associated to the mouse click and the word at
-   *   this location is selected.</li>
+   *   this location is selected. If there is no word at the pointer
+   *   the gap is selected instead.</li>
    * <li>If we receive a triple click, the caret position (dot) is set
    *   to the position associated to the mouse click and the line at
    *   this location is selected.</li>
@@ -376,7 +377,50 @@
    */
   public void mouseClicked(MouseEvent event)
   {
-    // TODO: Implement double- and triple-click behaviour here.
+    int count = event.getClickCount();
+    
+    if (count >= 2)
+      {
+        int newDot = getComponent().viewToModel(event.getPoint());
+        JTextComponent t = getComponent();
+
+        try
+          {
+            if (count == 3)
+              t.select(Utilities.getRowStart(t, newDot), Utilities.getRowEnd(t, newDot));
+            else
+              {
+                int nextWord = Utilities.getNextWord(t, newDot);
+                
+                // When the mouse points at the offset of the first character
+                // in a word Utilities().getPreviousWord will not return that
+                // word but we want to select that. We have to use
+                // Utilities.nextWord() to get it.
+                if (newDot == nextWord)
+                  t.select(nextWord, Utilities.getNextWord(t, nextWord));
+                else
+                  {
+                    int previousWord = Utilities.getPreviousWord(t, newDot);
+                    int previousWordEnd = Utilities.getWordEnd(t, previousWord);
+                    
+                    // If the user clicked in the space between two words,
+                    // then select the space.
+                    if (newDot >= previousWordEnd && newDot <= nextWord)
+                      t.select(previousWordEnd, nextWord);
+                    // Otherwise select the word under the mouse pointer.
+                    else
+                      t.select(previousWord, previousWordEnd);
+                  }
+              }
+          }
+        catch(BadLocationException ble)
+          {
+            // TODO: Swallowing ok here?
+          }
+        
+        dot = newDot;
+      }
+    
   }
 
   /**
@@ -411,7 +455,10 @@
    */
   public void mousePressed(MouseEvent event)
   {
-    positionCaret(event);
+    if (event.isShiftDown())
+      moveCaret(event);
+    else
+      positionCaret(event);
   }
 
   /**
Index: javax/swing/text/GapContent.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/GapContent.java,v
retrieving revision 1.41
diff -u -r1.41 GapContent.java
--- javax/swing/text/GapContent.java	4 Mar 2006 06:25:02 -0000	1.41
+++ javax/swing/text/GapContent.java	6 Mar 2006 15:24:28 -0000
@@ -347,8 +347,12 @@
     int length = length();
     int strLen = str.length();
 
+    if (where < 0)
+      throw new BadLocationException("The where argument cannot be smaller"
+                                     + " than the zero", where);
+
     if (where >= length)
-      throw new BadLocationException("the where argument cannot be greater"
+      throw new BadLocationException("The where argument cannot be greater"
           + " than the content length", where);
 
     replace(where, 0, str.toCharArray(), strLen);
Index: javax/swing/text/PlainDocument.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/PlainDocument.java,v
retrieving revision 1.19
diff -u -r1.19 PlainDocument.java
--- javax/swing/text/PlainDocument.java	9 Jan 2006 21:55:39 -0000	1.19
+++ javax/swing/text/PlainDocument.java	6 Mar 2006 15:24:28 -0000
@@ -1,5 +1,5 @@
 /* PlainDocument.java --
-   Copyright (C) 2002, 2004  Free Software Foundation, Inc.
+   Copyright (C) 2002, 2004, 2006  Free Software Foundation, Inc.
 
 This file is part of GNU Classpath.
 
@@ -40,6 +40,15 @@
 
 import java.util.ArrayList;
 
+/**
+ * A simple document class which maps lines to [EMAIL PROTECTED] Element}s.
+ *
+ * @author Anthony Balkissoon ([EMAIL PROTECTED])
+ * @author Graydon Hoare ([EMAIL PROTECTED])
+ * @author Roman Kennke ([EMAIL PROTECTED])
+ * @author Michael Koch ([EMAIL PROTECTED])
+ * @author Robert Schuster ([EMAIL PROTECTED])
+ */
 public class PlainDocument extends AbstractDocument
 {
   private static final long serialVersionUID = 4758290289196893664L;
@@ -109,18 +118,21 @@
                               AttributeSet attributes)
   {
     int offset = event.getOffset();
+    int eventLength = event.getLength();
     int end = offset + event.getLength();
-    int elementIndex = rootElement.getElementIndex(offset);
+    int oldElementIndex, elementIndex = rootElement.getElementIndex(offset);
     Element firstElement = rootElement.getElement(elementIndex);
-    
+    oldElementIndex = elementIndex;
+        
     // If we're inserting immediately after a newline we have to fix the 
-    // Element structure.
-    if (offset > 0)
+    // Element structure (but only if we are dealing with a line which
+    // has not existed as Element before).
+    if (offset > 0 && firstElement.getStartOffset() != offset)
       {
         try
         {
           String s = getText(offset - 1, 1);
-          if (s.equals("\n"))
+          if (s.equals("\n") )
             {
               int newEl2EndOffset = end;
               boolean replaceNext = false;
@@ -159,33 +171,43 @@
     Element[] added;
     try 
       {
-        String str = content.getString(0, content.length());
+        String str = content.getString(offset, eventLength);
         ArrayList elts = new ArrayList();
 
         // Determine how many NEW lines were added by finding the newline
         // characters within the newly inserted text
         int j = firstElement.getStartOffset();
-        int i = str.indexOf('\n', offset);
-        while (i != -1 && i <= end)
+        int i = str.indexOf('\n', 0);
+        int contentLength = content.length();
+          
+        while (i != -1 && i <= eventLength)
           {            
             // For each new line, create a new element
             elts.add(createLeafElement(rootElement, SimpleAttributeSet.EMPTY,
-                                       j, i + 1));
-            j = i + 1;
-            if (j >= str.length())
-              break;
-            i = str.indexOf('\n', j);
+                                       j, offset + i + 1));
+                  
+            j = offset + i + 1;
+            if (j >= contentLength)
+                break;
+            i = str.indexOf('\n', i + 1);
           }
+
         // If there were new lines added we have to add an ElementEdit to 
         // the DocumentEvent and we have to call rootElement.replace to 
         // insert the new lines
         if (elts.size() != 0)
           {
+            // If we have created new lines test whether there are remaining
+            // characters in firstElement after the inserted text and if so
+            // create a new element for them.
+            if (j < firstElement.getEndOffset())
+              elts.add(createLeafElement(rootElement, SimpleAttributeSet.EMPTY, j, firstElement.getEndOffset()));
+
             // Set up the ElementEdit by filling the added and removed 
             // arrays with the proper Elements
             added = new Element[elts.size()];
-            for (int k = 0; k < elts.size(); ++k)
-              added[k] = (Element) elts.get(k);
+            elts.toArray(added);
+            
             removed[0] = firstElement;
             
             // Now create and add the ElementEdit
@@ -204,6 +226,7 @@
         ae.initCause(e);
         throw ae;
       }
+    
     super.insertUpdate(event, attributes);
   }
 

Attachment: signature.asc
Description: This is a digitally signed message part

Reply via email to