Hi, by clicking around in our Free Swing Demo I found out that my patch to implement word and line selection in DefaultCaret.mouseListener was not quite correct: If you double clicked on "Hello" in "Hello World!" in the jtextarea or jtextfield with a custom selected text color it would have painted that text wrong (as wrong values for getSelectionStart() and getSelectionEnd() were returned).
This patch fixes that.
The ChangeLog:
2006-03-17 Robert Schuster <[EMAIL PROTECTED]>
* javax/swing/text/DefaultCaret.java:
(mouseClicked) Use setDot() and moveDot() instead of
JTextComponent.select().
cya
Robert
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 20:35:53 -0000
@@ -387,7 +387,10 @@
try
{
if (count == 3)
- t.select(Utilities.getRowStart(t, newDot), Utilities.getRowEnd(t, newDot));
+ {
+ setDot(Utilities.getRowStart(t, newDot));
+ moveDot( Utilities.getRowEnd(t, newDot));
+ }
else
{
int nextWord = Utilities.getNextWord(t, newDot);
@@ -397,7 +400,10 @@
// 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));
+ {
+ setDot(nextWord);
+ moveDot(Utilities.getNextWord(t, nextWord));
+ }
else
{
int previousWord = Utilities.getPreviousWord(t, newDot);
@@ -406,10 +412,16 @@
// If the user clicked in the space between two words,
// then select the space.
if (newDot >= previousWordEnd && newDot <= nextWord)
- t.select(previousWordEnd, nextWord);
+ {
+ setDot(previousWordEnd);
+ moveDot(nextWord);
+ }
// Otherwise select the word under the mouse pointer.
else
- t.select(previousWord, previousWordEnd);
+ {
+ setDot(previousWord);
+ moveDot(previousWordEnd);
+ }
}
}
}
@@ -417,8 +429,6 @@
{
// TODO: Swallowing ok here?
}
-
- dot = newDot;
}
}
signature.asc
Description: OpenPGP digital signature
