A Register is string of text indexed by a single character. Typically the text is taken from selected buffer text and the index character is a keyboard character selected by the user.
The application maintains a single Registers object consisting of an dynamically sized array of Register objects. The Registers class defines a number of methods that give each register the properties of a virtual clipboard.
The following methods provide a clipboard operations for register objects:
public static void copy( | JEditTextArea | textArea, |
char | register) ; |
Saves the selected text in the designated textArea to the register indexed at register. This will replace the existing contents of the designated register.
public static void cut( | JEditTextArea | textArea, |
char | register) ; |
Saves the selected text in the designated textArea to the register indexed at register, and removes the text from the text area. This will replace the existing contents of the designated register.
public static void append( | JEditTextArea | textArea, |
char | register, | |
String | separator, | |
boolean | cut) ; |
public static void append( | JEditTextArea | textArea, |
char | register, | |
String | separator) ; |
public static void append( | JEditTextArea | textArea, |
char | register) ; |
These three methods append the selected text in the textArea to the designated register. If the cut parameter is not specified, the selected text remains in the text area. If the separator parameter is not specified, a newline character is used to separate the appended text from any existing register text.
The following methods provide a lower-level interface for working with registers:
public static void setRegister( | char | name, |
Registers.Register | register) ; |
public static void setRegister( | char | name, |
Registers.Register | newRegister) ; |
public static void clearRegister( | char | name) ; |
Sets the text of the designated register to null. If the register is one of the two registers reserved by the application (as discussed in the next section), the text value is set to an empty string.
public static Registers.Register getRegister( | char | name) ; |
public static Registers.Register[] getRegisters( | void) ; |
This interface requires implementation of two methods: setValue(), which takes a String parameter, and toString(), which return a textual representation of the register's contents. Two classes implement this interface. A ClipboardRegister is tied to the contents of the application's clipboard. The application assigns a ClipboardRegister to the register indexed under the character $. A StringRegister is created for registers assigned by the user. In addition, the application assigns to the StringRegister indexed under % the last text segment selected in the text area.
A Register object does not maintain a copy of its index key. Indexing is performed by the Registers object.