The NavigationFilter Class
The NavigationFilter class is similar to the DocumentFilter class except that it oversees
caret positioning instead of edits to the Document. Like DocumentFilter, NavigationFilter was introduced in SDK 1.4.
Unlike DocumentFilter, you can easily
install a NavigationFilter on any
Swing text component without having to perform a cast. Just pass your
NavigationFilter into the component’s
setNavigationFilter( ) method, and
the component’s Caret will filter all
movement through it. NavigationFilters can also be specified by
subclasses of AbstractFormatter (see
Chapter 20).
Two of NavigationFilter’s
methods work just like DocumentFilter’s methods. The Caret’s moveDot(
) and setDot( ) methods
check for the existence of a NavigationFilter. If there is one, they
forward the call to the like-named method of the NavigationFilter object. But the NavigationFilter methods are passed an extra
parameter called the FilterBypass.
The FilterBypass object has its own
moveDot( ) and setDot( ) methods, and these actually change
the position of the Caret. FilterBypass also provides access to the
Caret via its getCaret( ) method.
A third method, getNextVisualPositionFrom( ), is called by the
default caret movement Actions[28] when they are acting on a component that has a NavigationFilter. Thus, a NavigationFilter can completely control how
the caret reacts to the arrow keys. (If no NavigationFilter exists, the default caret
movement Actions call the like-named method of the appropriate ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access