I l@ve RuBoard |
![]() ![]() |
22.7 The NavigationFilter ClassThe 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 View object instead. See Section 22.5.2 earlier in this chapter.) There is no FilterBypass involved with this method.
22.7.1 Constructor
22.7.1.1 MethodsNavigationFilter's methods reproduce the default caret movement behavior, so you override only the ones you want to behave differently.
22.7.1.2 NavigationFilter.FilterBypass methods
This was a long chapter, but now you know all about Swing's handling of styled text. You have only one more chapter to go, and then the Swing text components will no longer hold any mysteries for you. In the next chapter we cover the last of the Swing text components: the flexible and powerful JEditorPane. |
I l@ve RuBoard |
![]() ![]() |