aboutsummaryrefslogtreecommitdiff
path: root/libjava/classpath/javax/swing/text/DefaultCaret.java
diff options
context:
space:
mode:
Diffstat (limited to 'libjava/classpath/javax/swing/text/DefaultCaret.java')
-rw-r--r--libjava/classpath/javax/swing/text/DefaultCaret.java64
1 files changed, 54 insertions, 10 deletions
diff --git a/libjava/classpath/javax/swing/text/DefaultCaret.java b/libjava/classpath/javax/swing/text/DefaultCaret.java
index c9369af..4ad204c 100644
--- a/libjava/classpath/javax/swing/text/DefaultCaret.java
+++ b/libjava/classpath/javax/swing/text/DefaultCaret.java
@@ -216,13 +216,26 @@ public class DefaultCaret extends Rectangle
*/
public void propertyChange(PropertyChangeEvent e)
{
- if (e.getPropertyName().equals("document"))
+ String name = e.getPropertyName();
+
+ if (name.equals("document"))
{
Document oldDoc = (Document) e.getOldValue();
oldDoc.removeDocumentListener(documentListener);
Document newDoc = (Document) e.getNewValue();
newDoc.addDocumentListener(documentListener);
}
+ else if (name.equals("editable"))
+ {
+ active = (((Boolean) e.getNewValue()).booleanValue()
+ && textComponent.isEnabled());
+ }
+ else if (name.equals("enabled"))
+ {
+ active = (((Boolean) e.getNewValue()).booleanValue()
+ && textComponent.isEditable());
+ }
+
}
}
@@ -281,8 +294,10 @@ public class DefaultCaret extends Rectangle
/**
* The text component in which this caret is installed.
+ *
+ * (Package private to avoid synthetic accessor method.)
*/
- private JTextComponent textComponent;
+ JTextComponent textComponent;
/**
* Indicates if the selection should be visible or not.
@@ -314,6 +329,12 @@ public class DefaultCaret extends Rectangle
* package private to avoid an accessor method.
*/
boolean visible = false;
+
+ /** Indicates whether the text component where the caret is installed is
+ * editable and enabled. If either of these properties is <code>false</code>
+ * the caret is not drawn.
+ */
+ boolean active = true;
/**
* The current highlight entry.
@@ -388,14 +409,23 @@ public class DefaultCaret extends Rectangle
/**
* Moves the caret position when the mouse is dragged over the text
- * component, modifying the selection accordingly.
+ * component, modifying the selectiony.
+ *
+ * <p>When the text component where the caret is installed is disabled,
+ * the selection is not change but you can still scroll the text and
+ * update the caret's location.</p>
*
* @param event the <code>MouseEvent</code> describing the drag operation
*/
public void mouseDragged(MouseEvent event)
{
if (event.getButton() == MouseEvent.BUTTON1)
- moveCaret(event);
+ {
+ if (textComponent.isEnabled())
+ moveCaret(event);
+ else
+ positionCaret(event);
+ }
}
/**
@@ -426,6 +456,10 @@ public class DefaultCaret extends Rectangle
*/
public void mouseClicked(MouseEvent event)
{
+ // Do not modify selection if component is disabled.
+ if (!textComponent.isEnabled())
+ return;
+
int count = event.getClickCount();
if (event.getButton() == MouseEvent.BUTTON1 && count >= 2)
@@ -523,7 +557,7 @@ public class DefaultCaret extends Rectangle
// implemented (in regard to text components):
// - a left-click moves the caret
// - a left-click when shift is held down expands the selection
- // - a right-click or click with any additionaly mouse button
+ // - a right-click or click with any additional mouse button
// on a text component is ignored
// - a middle-click positions the caret and pastes the clipboard
// contents.
@@ -540,6 +574,7 @@ public class DefaultCaret extends Rectangle
else
{
positionCaret(event);
+
textComponent.paste();
}
else
@@ -564,8 +599,11 @@ public class DefaultCaret extends Rectangle
*/
public void focusGained(FocusEvent event)
{
- setVisible(true);
- updateTimerStatus();
+ if (textComponent.isEditable())
+ {
+ setVisible(true);
+ updateTimerStatus();
+ }
}
/**
@@ -575,9 +613,10 @@ public class DefaultCaret extends Rectangle
*/
public void focusLost(FocusEvent event)
{
- if (event.isTemporary() == false)
+ if (textComponent.isEditable() && event.isTemporary() == false)
{
setVisible(false);
+
// Stop the blinker, if running.
if (blinkTimer != null && blinkTimer.isRunning())
blinkTimer.stop();
@@ -670,6 +709,7 @@ public class DefaultCaret extends Rectangle
textComponent.addPropertyChangeListener(propertyChangeListener);
documentListener = new DocumentHandler();
textComponent.getDocument().addDocumentListener(documentListener);
+ active = textComponent.isEditable() && textComponent.isEnabled();
repaint();
}
@@ -872,7 +912,7 @@ public class DefaultCaret extends Rectangle
}
// Now draw the caret on the new position if visible.
- if (visible)
+ if (visible && active)
{
g.setColor(textComponent.getCaretColor());
g.drawLine(rect.x, rect.y, rect.x, rect.y + rect.height - 1);
@@ -1013,7 +1053,9 @@ public class DefaultCaret extends Rectangle
this.dot = Math.max(this.dot, 0);
handleHighlight();
+
appear();
+
adjustVisibility(this);
}
}
@@ -1050,7 +1092,9 @@ public class DefaultCaret extends Rectangle
this.mark = this.dot;
clearHighlight();
+
appear();
+
adjustVisibility(this);
}
}
@@ -1104,7 +1148,7 @@ public class DefaultCaret extends Rectangle
*/
public boolean isVisible()
{
- return visible;
+ return visible && active;
}
/**