summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Schuster <theBohemian@gmx.net>2006-03-06 02:17:05 +0000
committerRobert Schuster <theBohemian@gmx.net>2006-03-06 02:17:05 +0000
commitb492b85ef9e5135cdcf4dffdc194d85b15add5ad (patch)
tree5c2aff902f3f3c0b31fc44ba17e9d2626fa655ad
parente3469239533dc0f689eb4d98f67a29a7319c9ce5 (diff)
downloadclasspath-b492b85ef9e5135cdcf4dffdc194d85b15add5ad.tar.gz
Fixes PR 26416.
2006-03-06 Robert Schuster <robertschuster@fsfe.org> * javax/swing/text/DefaultCaret.java: (mouseDragged): Do selection when shift is pressed. (mouseClicked): Implemented.
-rw-r--r--ChangeLog6
-rw-r--r--javax/swing/text/DefaultCaret.java53
2 files changed, 56 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 4bff5068d..e9e5a4ca8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2006-03-06 Robert Schuster <robertschuster@fsfe.org>
+
+ * javax/swing/text/DefaultCaret.java:
+ (mouseDragged): Do selection when shift is pressed.
+ (mouseClicked): Implemented.
+
2006-03-06 Dalibor Topic <robilad@kaffe.org>
* libraries/javalib/external/classpath/java/net/URI.java (quote):
diff --git a/javax/swing/text/DefaultCaret.java b/javax/swing/text/DefaultCaret.java
index 241338602..f2a68c00d 100644
--- a/javax/swing/text/DefaultCaret.java
+++ b/javax/swing/text/DefaultCaret.java
@@ -366,7 +366,8 @@ public class DefaultCaret extends Rectangle
* <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 class DefaultCaret extends Rectangle
*/
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 class DefaultCaret extends Rectangle
*/
public void mousePressed(MouseEvent event)
{
- positionCaret(event);
+ if (event.isShiftDown())
+ moveCaret(event);
+ else
+ positionCaret(event);
}
/**