All Packages Class Hierarchy This Package Previous Next Index
Class com.sun.java.swing.text.JTextController
java.lang.Object
|
+----com.sun.java.swing.text.JTextController
- public class JTextController
- extends Object
- implements TextController
A class for binding events to manipulations on
JTextComponent implementations. To facilitate
flexible use of the keyboard, support for
creating keymaps and binding various keystrokes
to some kind of action is provided. In order
to allow keymaps to be shared across multiple
text components, they can use actions that
extend JTextAction. JTextAction can determine
which JTextComponent (using a JTextController)
has focus and therefore is the subject of the
action. JTextController creates a minimal
keymap (named DEFAULT_KEYMAP) that is
shared by all JTextController instances as the
default keymap. Typically a look-and-feel
implementation will install a different keymap
that resolves to the default keymap for those
bindings not found in the different keymap.
The minimal bindings include:
- inserting content into the editor for the
printable keys.
- removing content with the backspace and del
keys.
- caret movement forward and backward
- jumping to the beginning and end of the
text stream using the home and end keys.
Focus and mouse event behavior are directly
implemented. To change these types of event
this class must be subclassed.
- See Also:
- JTextAction, TextController
-
DEFAULT_KEYMAP
- This is the name of the default keymap that will be shared by all
JTextController instances unless they have had a different
keymap set.
-
JTextController(JTextComponent)
-
-
addKeymap(String, Keymap)
- Add a new keymap into the keymap hierarchy.
-
caretOff()
-
-
caretOn()
-
-
focusGained(FocusEvent)
- Stashes the current focused JTextComponent reference
for JTextAction instances to use, and sets the caret
to be visible.
-
focusLost(FocusEvent)
- Removes reference to focused text component that
instances of JTextAction use and turns off the
caret visibility.
-
getEditor()
- Editor associated with the controller.
-
getKeymap()
- Fetch the keymap being used on this controller
-
getKeymap(String)
- Fetch a named keymap previously added to the document.
-
keyPressed(KeyEvent)
-
Trys to map the event to an action using the
current keymap.
-
keyReleased(KeyEvent)
-
-
keyTyped(KeyEvent)
-
Trys to map the event to an action using the
current keymap.
-
loadKeymap(Keymap, JTextController. KeyBinding[], Action[])
-
Convenience function to load a keymap with a bunch of
bindings.
-
mouseClicked(MouseEvent)
-
-
mouseDragged(MouseEvent)
- Implemented to move the caret position
according to the mouse pointers current
location.
-
mouseEntered(MouseEvent)
-
-
mouseExited(MouseEvent)
-
-
mouseMoved(MouseEvent)
-
-
mousePressed(MouseEvent)
- Implemented to request focus on the associated
text component, and try to set the cursor position.
-
mouseReleased(MouseEvent)
-
-
moveCursor(MouseEvent)
- Trys to move the position of the caret from
the coordinates of the mouse event.
-
positionCursor(MouseEvent)
- Trys to set the position of the caret from
the coordinates of the mouse event.
-
removeKeymap(String)
- Remove a named keymap previously added to the document.
-
setKeymap(Keymap)
- Set the keymap to use on this controller
DEFAULT_KEYMAP
public static final String DEFAULT_KEYMAP
- This is the name of the default keymap that will be shared by all
JTextController instances unless they have had a different
keymap set.
JTextController
public JTextController(JTextComponent editor)
addKeymap
public static Keymap addKeymap(String nm,
Keymap parent)
- Add a new keymap into the keymap hierarchy. Keymap bindings
resolve from bottom up so an attribute specified in a child
will override an attribute specified in the parent.
- Parameters:
- nm - The name of the keymap (must be unique within the
collection of named keymaps in the document). The name may
be null if the keymap is unnamed, but the caller is responsible
for managing the reference returned as an unnamed keymap can't
be fetched by name.
- parent - The parent keymap. This may be null if unspecified
bindings need not be resolved in some other keymap.
removeKeymap
public static Keymap removeKeymap(String nm)
- Remove a named keymap previously added to the document.
- Parameters:
- nm - The name of the keymap to remove
getKeymap
public static Keymap getKeymap(String nm)
- Fetch a named keymap previously added to the document.
- Parameters:
- nm - The name of the keymap
loadKeymap
public static void loadKeymap(Keymap map,
JTextController. KeyBinding bindings[],
Action actions[])
-
Convenience function to load a keymap with a bunch of
bindings. This can be used to take a static table of
definitions and load them into some keymap. The following
example illustrates an example of binding some keys to
the cut, copy, and paste actions associated with a
JTextComponent. It also binds tab to insert the tab
into the text component. A code fragment to accomplish
this might look as follows:
JTextComponent c = new JTextPane();
Keymap k = c.getKeymap();
JTextController.loadKeymap(k, c.getActions(), defaultBindings);
static final JTextController.KeyBinding[] defaultBindings = {
new JTextController.KeyBinding(
JKeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK),
JTextComponent.copyAction),
new JTextController.KeyBinding(
JKeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK),
JTextComponent.pasteAction),
new JTextController.KeyBinding(
JKeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK),
JTextComponent.cutAction),
new JTextController.KeyBinding(
JKeyStroke.getKeyStroke('\t'),
JTextComponent.insertContentAction)
};
positionCursor
protected void positionCursor(MouseEvent e)
- Trys to set the position of the caret from
the coordinates of the mouse event.
moveCursor
protected void moveCursor(MouseEvent e)
- Trys to move the position of the caret from
the coordinates of the mouse event. This
will cause a selection if the dot and mark
are different.
caretOn
protected void caretOn()
caretOff
protected void caretOff()
getEditor
protected final JTextComponent getEditor()
- Editor associated with the controller.
setKeymap
public void setKeymap(Keymap map)
- Set the keymap to use on this controller
getKeymap
public Keymap getKeymap()
- Fetch the keymap being used on this controller
mouseClicked
public void mouseClicked(MouseEvent e)
- See Also:
- mouseClicked
mousePressed
public void mousePressed(MouseEvent e)
- Implemented to request focus on the associated
text component, and try to set the cursor position.
- See Also:
- mousePressed
mouseReleased
public void mouseReleased(MouseEvent e)
- See Also:
- mouseReleased
mouseEntered
public void mouseEntered(MouseEvent e)
- See Also:
- mouseEntered
mouseExited
public void mouseExited(MouseEvent e)
- See Also:
- mouseExited
mouseDragged
public void mouseDragged(MouseEvent e)
- Implemented to move the caret position
according to the mouse pointers current
location. This effectively extends the
selection.
- See Also:
- mouseDragged
mouseMoved
public void mouseMoved(MouseEvent e)
- See Also:
- mouseMoved
focusGained
public void focusGained(FocusEvent e)
- Stashes the current focused JTextComponent reference
for JTextAction instances to use, and sets the caret
to be visible.
- See Also:
- JTextAction, focusGained
focusLost
public void focusLost(FocusEvent e)
- Removes reference to focused text component that
instances of JTextAction use and turns off the
caret visibility.
- See Also:
- JTextAction, focusLost
keyTyped
public void keyTyped(KeyEvent e)
-
Trys to map the event to an action using the
current keymap. If an action is found it will
be executed and the event consumed.
- See Also:
- keyTyped, getKeyStroke
keyPressed
public void keyPressed(KeyEvent e)
-
Trys to map the event to an action using the
current keymap. If an action is found it will
be executed and the event consumed.
- See Also:
- keyPressed, getKeyStroke
keyReleased
public void keyReleased(KeyEvent e)
- See Also:
- keyReleased
All Packages Class Hierarchy This Package Previous Next Index