Hi,
this patch enforces that Free Swing paints only one selection for all of the
textcomponents it manages within the current runtime.

Any objections, ideas, ... ?

Corresponding PR is 26677[0].

ChangeLog would be:
2006-03-17  Robert Schuster  <[EMAIL PROTECTED]>

        * javax/swing/text/DefaultCaret.java: Added class variable denoting
        the text component having a selection.
        (clearSelection): Clear 'componentWithSelection' variable.
        (handleSelection): Clear selection of current component having a
        selection before setting a new selection in another component.

cya
Robert

[0] - http://gcc.gnu.org/bugzilla/show_bug.cgi?id=26677
Index: javax/swing/text/DefaultCaret.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/DefaultCaret.java,v
retrieving revision 1.33
diff -u -r1.33 DefaultCaret.java
--- javax/swing/text/DefaultCaret.java	6 Mar 2006 02:17:06 -0000	1.33
+++ javax/swing/text/DefaultCaret.java	17 Mar 2006 19:54:48 -0000
@@ -63,12 +63,17 @@
 /**
  * The default implementation of the [EMAIL PROTECTED] Caret} interface.
  *
- * @author orgininal author unknown
+ * @author original author unknown
  * @author Roman Kennke ([EMAIL PROTECTED])
  */
 public class DefaultCaret extends Rectangle
   implements Caret, FocusListener, MouseListener, MouseMotionListener
 {
+  
+  /** A text component in the current VM which currently has a
+   * text selection or <code>null</code>.
+   */ 
+  static JTextComponent componentWithSelection;
 
   /**
    * Controls the blinking of the caret.
@@ -640,6 +645,11 @@
           highlightEntry = highlighter.addHighlight(0, 0, getSelectionPainter());
         else
           highlighter.changeHighlight(highlightEntry, 0, 0);
+        
+        // Free the global variable which stores the text component with an active
+        // selection.
+        if (componentWithSelection == textComponent)
+          componentWithSelection = null;
       }
     catch (BadLocationException e)
       {
@@ -675,6 +685,17 @@
 	      highlightEntry = highlighter.addHighlight(p0, p1, getSelectionPainter());
 	    else
 	      highlighter.changeHighlight(highlightEntry, p0, p1);
+            
+            // If another component currently has a text selection clear that selection
+            // first.
+            if (componentWithSelection != null)
+              if (componentWithSelection != textComponent)
+                {
+                  Caret c = componentWithSelection.getCaret();
+                  c.setDot(c.getDot());
+                }
+            componentWithSelection = textComponent;
+            
 	  }
 	catch (BadLocationException e)
 	  {

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to