Hi, the attached patch integrates the NavigationFilter stuff into DefaultCaret[0]. I will add a demonstration to the Swing Activity board soon.
The ChangeLog:
2006-04-14 Robert Schuster <[EMAIL PROTECTED]>
* javax/swing/text/DefaultCaret.java:
(getBypass): New method.
(moveDot): Rewritten.
(moveDotImpl): New method.
(setDot): Rewritten.
(setDotImpl): New method.
(DefaultCaret.Bypass): New class.
cya
Robert
[0] - http://gcc.gnu.org/bugzilla/show_bug.cgi?id=27165
Index: javax/swing/text/DefaultCaret.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/DefaultCaret.java,v
retrieving revision 1.37
diff -u -r1.37 DefaultCaret.java
--- javax/swing/text/DefaultCaret.java 27 Mar 2006 15:25:12 -0000 1.37
+++ javax/swing/text/DefaultCaret.java 14 Apr 2006 19:29:47 -0000
@@ -59,6 +59,7 @@
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.event.EventListenerList;
+import javax.swing.text.Position.Bias;
/**
* The default implementation of the [EMAIL PROTECTED] Caret} interface.
@@ -75,6 +76,31 @@
*/
static JTextComponent componentWithSelection;
+ /** An implementation of NavigationFilter.FilterBypass which delegates
+ * to the corresponding methods of the <code>DefaultCaret</code>.
+ *
+ * @author Robert Schuster ([EMAIL PROTECTED])
+ */
+ class Bypass extends NavigationFilter.FilterBypass
+ {
+
+ public Caret getCaret()
+ {
+ return DefaultCaret.this;
+ }
+
+ public void moveDot(int dot, Bias bias)
+ {
+ DefaultCaret.this.moveDotImpl(dot);
+ }
+
+ public void setDot(int dot, Bias bias)
+ {
+ DefaultCaret.this.setDot(dot);
+ }
+
+ }
+
/**
* Controls the blinking of the caret.
*
@@ -299,12 +325,29 @@
private BlinkTimerListener blinkListener;
/**
+ * A <code>NavigationFilter.FilterBypass</code> instance which
+ * is provided to the a <code>NavigationFilter</code> to
+ * unconditionally set or move the caret.
+ */
+ NavigationFilter.FilterBypass bypass;
+
+ /**
* Creates a new <code>DefaultCaret</code> instance.
*/
public DefaultCaret()
{
// Nothing to do here.
}
+
+ /** Returns the caret's <code>NavigationFilter.FilterBypass</code> instance
+ * and creates it if it does not yet exist.
+ *
+ * @return The caret's <code>NavigationFilter.FilterBypass</code> instance.
+ */
+ private NavigationFilter.FilterBypass getBypass()
+ {
+ return (bypass == null) ? bypass = new Bypass() : bypass;
+ }
/**
* Sets the Caret update policy.
@@ -946,12 +989,24 @@
* Moves the <code>dot</code> location without touching the
* <code>mark</code>. This is used when making a selection.
*
+ * <p>If the underlying text component has a [EMAIL PROTECTED] NavigationFilter}
+ * installed the caret will call the corresponding method of that object.</p>
+ *
* @param dot the location where to move the dot
*
* @see #setDot(int)
*/
public void moveDot(int dot)
{
+ NavigationFilter filter = textComponent.getNavigationFilter();
+ if (filter != null)
+ filter.moveDot(getBypass(), dot, Bias.Forward);
+ else
+ moveDotImpl(dot);
+ }
+
+ void moveDotImpl(int dot)
+ {
if (dot >= 0)
{
Document doc = textComponent.getDocument();
@@ -970,12 +1025,24 @@
* <code>Document</code>. This also sets the <code>mark</code> to the new
* location.
*
+ * <p>If the underlying text component has a [EMAIL PROTECTED] NavigationFilter}
+ * installed the caret will call the corresponding method of that object.</p>
+ *
* @param dot
* the new position to be set
* @see #moveDot(int)
*/
public void setDot(int dot)
{
+ NavigationFilter filter = textComponent.getNavigationFilter();
+ if (filter != null)
+ filter.setDot(getBypass(), dot, Bias.Forward);
+ else
+ setDotImpl(dot);
+ }
+
+ void setDotImpl(int dot)
+ {
if (dot >= 0)
{
Document doc = textComponent.getDocument();
@@ -1135,4 +1202,5 @@
blinkTimer = new Timer(getBlinkRate(), blinkListener);
blinkTimer.setRepeats(true);
}
+
}
signature.asc
Description: OpenPGP digital signature
