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:

Focus and mouse event behavior are directly implemented. To change these types of event this class must be subclassed.

See Also:
JTextAction, TextController

Variable Index

 o 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.

Constructor Index

 o JTextController(JTextComponent)

Method Index

 o addKeymap(String, Keymap)
Add a new keymap into the keymap hierarchy.
 o caretOff()
 o caretOn()
 o focusGained(FocusEvent)
Stashes the current focused JTextComponent reference for JTextAction instances to use, and sets the caret to be visible.
 o focusLost(FocusEvent)
Removes reference to focused text component that instances of JTextAction use and turns off the caret visibility.
 o getEditor()
Editor associated with the controller.
 o getKeymap()
Fetch the keymap being used on this controller
 o getKeymap(String)
Fetch a named keymap previously added to the document.
 o keyPressed(KeyEvent)

Trys to map the event to an action using the current keymap.

 o keyReleased(KeyEvent)
 o keyTyped(KeyEvent)

Trys to map the event to an action using the current keymap.

 o loadKeymap(Keymap, JTextController. KeyBinding[], Action[])

Convenience function to load a keymap with a bunch of bindings.

 o mouseClicked(MouseEvent)
 o mouseDragged(MouseEvent)
Implemented to move the caret position according to the mouse pointers current location.
 o mouseEntered(MouseEvent)
 o mouseExited(MouseEvent)
 o mouseMoved(MouseEvent)
 o mousePressed(MouseEvent)
Implemented to request focus on the associated text component, and try to set the cursor position.
 o mouseReleased(MouseEvent)
 o moveCursor(MouseEvent)
Trys to move the position of the caret from the coordinates of the mouse event.
 o positionCursor(MouseEvent)
Trys to set the position of the caret from the coordinates of the mouse event.
 o removeKeymap(String)
Remove a named keymap previously added to the document.
 o setKeymap(Keymap)
Set the keymap to use on this controller

Variables

 o 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.

Constructors

 o JTextController
 public JTextController(JTextComponent editor)

Methods

 o 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.
 o 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
 o getKeymap
 public static Keymap getKeymap(String nm)
Fetch a named keymap previously added to the document.

Parameters:
nm - The name of the keymap
 o 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)
    };
 

 o positionCursor
 protected void positionCursor(MouseEvent e)
Trys to set the position of the caret from the coordinates of the mouse event.

 o 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.

 o caretOn
 protected void caretOn()
 o caretOff
 protected void caretOff()
 o getEditor
 protected final JTextComponent getEditor()
Editor associated with the controller.

 o setKeymap
 public void setKeymap(Keymap map)
Set the keymap to use on this controller

 o getKeymap
 public Keymap getKeymap()
Fetch the keymap being used on this controller

 o mouseClicked
 public void mouseClicked(MouseEvent e)
See Also:
mouseClicked
 o 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
 o mouseReleased
 public void mouseReleased(MouseEvent e)
See Also:
mouseReleased
 o mouseEntered
 public void mouseEntered(MouseEvent e)
See Also:
mouseEntered
 o mouseExited
 public void mouseExited(MouseEvent e)
See Also:
mouseExited
 o 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
 o mouseMoved
 public void mouseMoved(MouseEvent e)
See Also:
mouseMoved
 o 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
 o 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
 o 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
 o 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
 o keyReleased
 public void keyReleased(KeyEvent e)
See Also:
keyReleased

All Packages  Class Hierarchy  This Package  Previous  Next  Index