summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Wielaard <mark@klomp.org>2006-03-06 15:43:51 +0000
committerMark Wielaard <mark@klomp.org>2006-03-06 15:43:51 +0000
commit3ce4ec1c16fffe1daffdf502286f8d50654c9951 (patch)
treebe9ee8e2c892f2f74df5d88c25295fc1a82662a0
parent17f20b960d160cad7083d7bd95309f4c5b8936af (diff)
downloadclasspath-3ce4ec1c16fffe1daffdf502286f8d50654c9951.tar.gz
2006-03-06 Robert Schuster <robertschuster@fsfe.org>
* javax/swing/text/GapContent.java: (insertString): Throw exception when argument is below zero. 2006-03-06 Robert Schuster <robertschuster@fsfe.org> * 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 <robertschuster@fsfe.org> * javax/swing/text/DefaultCaret.java: (mouseDragged): Do selection when shift is pressed. (mouseClicked): Implemented. 2006-03-06 Robert Schuster <robertschuster@fsfe.org> * 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.
-rw-r--r--ChangeLog26
-rw-r--r--javax/swing/text/DefaultCaret.java53
-rw-r--r--javax/swing/text/GapContent.java6
-rw-r--r--javax/swing/text/PlainDocument.java55
4 files changed, 120 insertions, 20 deletions
diff --git a/ChangeLog b/ChangeLog
index 9fc3d261d..3dd2d7883 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,29 @@
+2006-03-06 Robert Schuster <robertschuster@fsfe.org>
+
+ * javax/swing/text/GapContent.java:
+ (insertString): Throw exception when argument is below
+ zero.
+
+2006-03-06 Robert Schuster <robertschuster@fsfe.org>
+
+ * 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 <robertschuster@fsfe.org>
+
+ * javax/swing/text/DefaultCaret.java:
+ (mouseDragged): Do selection when shift is pressed.
+ (mouseClicked): Implemented.
+
+2006-03-06 Robert Schuster <robertschuster@fsfe.org>
+
+ * 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.
+
2006-03-06 Christian Thalinger <twisti@complang.tuwien.ac.at>
* configure.ac: Check for FREETYPE2. This is a reverted patch and
diff --git a/javax/swing/text/DefaultCaret.java b/javax/swing/text/DefaultCaret.java
index e1ddddda3..91307285b 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);
}
/**
diff --git a/javax/swing/text/GapContent.java b/javax/swing/text/GapContent.java
index f5ab7f2b2..28d1d6ee0 100644
--- a/javax/swing/text/GapContent.java
+++ b/javax/swing/text/GapContent.java
@@ -347,8 +347,12 @@ public class GapContent
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);
diff --git a/javax/swing/text/PlainDocument.java b/javax/swing/text/PlainDocument.java
index 2200cae80..c699dcad2 100644
--- a/javax/swing/text/PlainDocument.java
+++ b/javax/swing/text/PlainDocument.java
@@ -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 @@ package javax.swing.text;
import java.util.ArrayList;
+/**
+ * A simple document class which maps lines to {@link Element}s.
+ *
+ * @author Anthony Balkissoon (abalkiss@redhat.com)
+ * @author Graydon Hoare (graydon@redhat.com)
+ * @author Roman Kennke (roman@kennke.org)
+ * @author Michael Koch (konqueror@gmx.de)
+ * @author Robert Schuster (robertschuster@fsfe.org)
+ */
public class PlainDocument extends AbstractDocument
{
private static final long serialVersionUID = 4758290289196893664L;
@@ -109,18 +118,21 @@ public class PlainDocument extends AbstractDocument
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 @@ public class PlainDocument extends AbstractDocument
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 @@ public class PlainDocument extends AbstractDocument
ae.initCause(e);
throw ae;
}
+
super.insertUpdate(event, attributes);
}