This patch implements the caret blinking behavior that is usually
observed in the most of applications: after any change of the caret
position it immediately reappears and do no go down again earlier than
the full timer blinking interval. Under very intensive work, the caret
does not blink.
The text selection (shift+arrow keys) is also working better, despite
the default selection color is black for some strange reason.
2005-11-08 Audrius Meskauskas <[EMAIL PROTECTED]>
* javax/swing/DefaultCaret.java (BlinkTimerListener): added
ignoreNextEvent flag and its handling.
(blinkListener): New field. (initBlinkTimer): Initialise blinkListener
field.
(setDot, moveDot): Call appear() instead of repaint(). (appear): new method.
Index: javax/swing/text/DefaultCaret.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/DefaultCaret.java,v
retrieving revision 1.22
diff -u -r1.22 DefaultCaret.java
--- javax/swing/text/DefaultCaret.java 3 Nov 2005 23:19:34 -0000 1.22
+++ javax/swing/text/DefaultCaret.java 8 Nov 2005 23:38:08 -0000
@@ -74,19 +74,33 @@
* Controls the blinking of the caret.
*
* @author Roman Kennke ([EMAIL PROTECTED])
+ * @author Audrius Meskauskas ([EMAIL PROTECTED])
*/
private class BlinkTimerListener implements ActionListener
{
/**
+ * Forces the next event to be ignored. The next event should be ignored
+ * if we force the caret to appear. We do not know how long will it take
+ * to fire the comming event; this may be near immediately. Better to leave
+ * the caret visible one iteration longer.
+ */
+ boolean ignoreNextEvent;
+
+ /**
* Receives notification when the blink timer fires and updates the visible
* state of the caret.
- *
+ *
* @param event the action event
*/
public void actionPerformed(ActionEvent event)
{
- visible = !visible;
- repaint();
+ if (ignoreNextEvent)
+ ignoreNextEvent = false;
+ else
+ {
+ visible = !visible;
+ repaint();
+ }
}
}
@@ -274,6 +288,8 @@
private Object highlightEntry;
private Timer blinkTimer;
+
+ private BlinkTimerListener blinkListener;
/**
* Creates a new <code>DefaultCaret</code> instance.
@@ -768,7 +784,7 @@
this.dot = dot;
handleHighlight();
adjustVisibility(this);
- repaint();
+ appear();
}
/**
@@ -786,8 +802,44 @@
this.mark = dot;
handleHighlight();
adjustVisibility(this);
- repaint();
+ appear();
}
+
+ /**
+ * Show the caret (may be hidden due blinking) and adjust the timer not to
+ * hide it (possibly immediately).
+ *
+ * @author Audrius Meskauskas ([EMAIL PROTECTED])
+ */
+ void appear()
+ {
+ // All machinery is only required if the carret is blinking.
+ if (blinkListener != null)
+ {
+ blinkListener.ignoreNextEvent = true;
+
+ // If the caret is visible, erase the current position by repainting
+ // over.
+ if (visible)
+ repaint();
+
+ // Draw the caret in the new position.
+ visible = true;
+
+ Rectangle area = null;
+ try
+ {
+ area = getComponent().modelToView(getDot());
+ }
+ catch (BadLocationException ex)
+ {
+ assert false : "Unexpected bad caret location: " + getDot();
+ }
+ if (area != null)
+ damage(area);
+ }
+ repaint();
+ }
/**
* Returns <code>true</code> if this <code>Caret</code> is currently visible,
@@ -888,7 +940,8 @@
private void initBlinkTimer()
{
// Setup the blink timer.
- blinkTimer = new Timer(getBlinkRate(), new BlinkTimerListener());
+ blinkListener = new BlinkTimerListener();
+ blinkTimer = new Timer(getBlinkRate(), blinkListener);
blinkTimer.setRepeats(true);
}
}
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches