Chapter 24. EditorKits and TextActions
Over the last five chapters we’ve covered just about all of the
classes and interfaces that make up the Swing text framework. In this
chapter, we’ll look at a class that ties everything together:
EditorKit is used
to pull together the document model, document view, document editing
actions, and document I/O strategy, serving as a central reference
point for a given document type.
In addition to looking at
EditorKit and its
subclasses, this chapter also introduces the
TextAction class (an abstract extension of
AbstractAction) and the many useful concrete
action classes available as inner classes of the
EditorKit subclasses. These actions are used for
tasks such as copying and pasting text as well as style-oriented
tasks such as changing font characteristics.
Throughout the course of the chapter, we’ll be building simple but powerful editors for working with increasingly complex document types.
Overview of the Editor Kits
The following sections give an overview of the components of various editor kits.
The EditorKit Class
This is the abstract base class for all
editor kits. It defines a number of methods that define the model
createDefaultDocument()), the view (e.g.,
getViewFactory()), the capabilities
getActions()), and the I/O strategy
write()) for some
type of document content. Figure 24.1 shows the
EditorKit class and the many classes and
interfaces it interacts with.
Figure 24-1. EditorKit and related classes ...