net.atlanticbb.tantlinger.ui.text
Class TextEditPopupManager

java.lang.Object
  extended by net.atlanticbb.tantlinger.ui.text.TextEditPopupManager

public class TextEditPopupManager
extends java.lang.Object

Manages an application-wide popup menu for JTextComponents. Any JTextComponent registered with the manager will have a right-click invokable popup menu, which provides options to undo, redo, cut, copy, paste, and select-all. The popup manager is a singleton and must be retrieved with the getInstance() method:


 JTextField textField = new JTextField(20);
 TextEditPopupManager.getInstance().registerJTextComponent(textField);
 

Author:
Bob Tantlinger TODO Internationalize, add mnemonics, etc

Field Summary
static java.lang.String COPY
           
static java.lang.String CUT
           
static java.lang.String PASTE
           
static java.lang.String REDO
           
static java.lang.String SELECT_ALL
           
static java.lang.String UNDO
           
 
Method Summary
 javax.swing.Action getAction(java.lang.String name)
           
protected  int getIndexOfJTextComponent(javax.swing.text.JTextComponent tc)
          Gets the index of a registered JTextComponent
static TextEditPopupManager getInstance()
          Gets the singleton instance of TextEditPopupManager
 void registerJTextComponent(javax.swing.text.JTextComponent tc)
          Registers a JTextComponent with the manager.
 void registerJTextComponent(javax.swing.text.JTextComponent tc, javax.swing.undo.UndoManager um)
          Registers a JTextComponent and UndoManager with the manager.
 void unregisterJTextComponent(javax.swing.text.JTextComponent tc)
          Unregisters a JTextComponent from the manager.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CUT

public static final java.lang.String CUT
See Also:
Constant Field Values

COPY

public static final java.lang.String COPY
See Also:
Constant Field Values

PASTE

public static final java.lang.String PASTE
See Also:
Constant Field Values

SELECT_ALL

public static final java.lang.String SELECT_ALL
See Also:
Constant Field Values

UNDO

public static final java.lang.String UNDO
See Also:
Constant Field Values

REDO

public static final java.lang.String REDO
See Also:
Constant Field Values
Method Detail

getInstance

public static TextEditPopupManager getInstance()
Gets the singleton instance of TextEditPopupManager

Returns:
The one and only TextEditPopupManager

getAction

public javax.swing.Action getAction(java.lang.String name)

registerJTextComponent

public void registerJTextComponent(javax.swing.text.JTextComponent tc)
                            throws java.lang.IllegalArgumentException
Registers a JTextComponent with the manager. Note that if you change the document of the JTextComponent, you should unregister it with method unregisterJTextComponent, and then re-register it with this method. e.g...

 TextEditPopupManager.getInstance().registerJTextComponent(comp);
 ...
 ...
 TextEditPopupManager.getInstance().unregisterJTextComponent(comp);
 comp.setDocument(new PlainDocument());
 TextEditPopupManager.getInstance().registerJTextComponent(comp);
 

Parameters:
tc - The JTextComponent to register
Throws:
java.lang.IllegalArgumentException - If the component is null, or already registered

registerJTextComponent

public void registerJTextComponent(javax.swing.text.JTextComponent tc,
                                   javax.swing.undo.UndoManager um)
                            throws java.lang.IllegalArgumentException
Registers a JTextComponent and UndoManager with the manager. This is useful if you wish to supply a custom UndoManager

Parameters:
tc - The JTextComponent to register
um - The UndoManger to register
Throws:
java.lang.IllegalArgumentException - If the component is null, or already registered

unregisterJTextComponent

public void unregisterJTextComponent(javax.swing.text.JTextComponent tc)
Unregisters a JTextComponent from the manager.

Parameters:
tc - The JTextComponent to unregister

getIndexOfJTextComponent

protected int getIndexOfJTextComponent(javax.swing.text.JTextComponent tc)
Gets the index of a registered JTextComponent

Parameters:
tc -
Returns: