All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class COM.taligent.widget.TextClipboardComponent

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Canvas
                   |
                   +----COM.taligent.widget.TextClipboardComponent

public abstract class TextClipboardComponent
extends Canvas
implements ClipboardOwner, ClipboardCapable
A component that allows text interaction with the clipboard. Classes that extend this class should listen to key events and call the appropriate methods. All instances of the this class share common key commands to initiate cut, copy, and paste actions.

Note: If you extend this class and perform special deserialization, make sure you call the init() method of TextClipboardComponent to get the system clipboard. If you do not, then make sure you initialize the clipboard variable yourself!

Version:
1.0
Author:
Andy Clark, Taligent Inc.

Variable Index

 o DEFAULT_COPY_CHAR
Default copy command character ('^c').
 o DEFAULT_COPY_MODIFIER
Default copy command modifier (InputEvent.CTRL_MASK).
 o DEFAULT_CUT_CHAR
Default cut command character ('^x').
 o DEFAULT_CUT_MODIFIER
Default cut command modifier (InputEvent.CTRL_MASK).
 o DEFAULT_PASTE_CHAR
Default paste command character ('^v').
 o DEFAULT_PASTE_MODIFIER
Default paste command modifier (InputEvent.CTRL_MASK).
 o DEFAULT_SELECTION_BACKGROUND
Selected text background (dark blue).
 o DEFAULT_SELECTION_FOREGROUND
Selected text foreground (Color.white).
 o fBegin
The starting index of the selection/caret start index.
 o fClipboard
The clipboard reference.
 o fEditable
Sets whether the component is editable by the user.
 o fEnd
The ending index of the selection.

Constructor Index

 o TextClipboardComponent()
Default constructor.

Method Index

 o addTextListener(TextListener)
Adds a text event listener.
 o clipboardCommand(KeyEvent)
Checks key event to see if the key typed signals a clipboard operation.
 o copy()
Copy contents to clipboard.
 o copyFromClipboard()
Returns the text on the clipboard or null if no text exists.
 o copyToClipboard(String)
Copies the specified string to clipboard.
 o cut()
Cut contents to clipboard.
 o getCaretPosition()
Returns the current position of the caret within the text.
 o getCopyCharacter()
Returns the copy command character.
 o getCopyModifier()
Returns the copy command modifier.
 o getCutCharacter()
Returns the cut command character.
 o getCutModifier()
Returns the cut command modifier.
 o getDisplayText()
Returns the display text.
 o getPasteCharacter()
Returns the paste command character.
 o getPasteModifier()
Returns the paste command modifier.
 o getSelectedText()
Returns the selection text.
 o getSelectionBackground()
Returns the current selected text background color.
 o getSelectionEnd()
Returns the ending index of the selection.
 o getSelectionForeground()
Returns the current selected text foreground color.
 o getSelectionStart()
Returns the starting index of the selection.
 o getText()
Returns the current text displayed in the component.
 o init()
Initialize transient data.
 o isEditable()
Returns whether this component is editable by the user.
 o lostOwnership(Clipboard, Transferable)
Another clipboard owner took control of the clipboard.
 o paste()
Paste clipboard contents.
 o removeTextListener(TextListener)
Removes a text event listener.
 o select(int, int)
Selects the text bounded by the specified beginning and ending indexes.
 o selectAll()
Selects the entire text.
 o setCaretPosition(int)
Moves the caret to the specified position within the text.
 o setCopyCharacter(char)
Sets the copy command character.
 o setCopyModifier(int)
Sets the copy command modifier.
 o setCutCharacter(char)
Sets the cut command character.
 o setCutModifier(int)
Sets the cut command modifier.
 o setEditable(boolean)
Sets whether this component is editable by the user.
 o setPasteCharacter(char)
Sets the paste command character.
 o setPasteModifier(int)
Sets the paste command modifier.
 o setSelectionBackground(Color)
Sets the selected text background color.
 o setSelectionEnd(int)
Sets the ending index of the selection.
 o setSelectionForeground(Color)
Sets the selected text foreground color.
 o setSelectionStart(int)
Sets the starting index of the selection.
 o setText(String)
Sets the text displayed in this component.

Variables

 o DEFAULT_CUT_CHAR
 public static final char DEFAULT_CUT_CHAR
Default cut command character ('^x').

 o DEFAULT_CUT_MODIFIER
 public static final int DEFAULT_CUT_MODIFIER
Default cut command modifier (InputEvent.CTRL_MASK).

 o DEFAULT_COPY_CHAR
 public static final char DEFAULT_COPY_CHAR
Default copy command character ('^c').

 o DEFAULT_COPY_MODIFIER
 public static final int DEFAULT_COPY_MODIFIER
Default copy command modifier (InputEvent.CTRL_MASK).

 o DEFAULT_PASTE_CHAR
 public static final char DEFAULT_PASTE_CHAR
Default paste command character ('^v').

 o DEFAULT_PASTE_MODIFIER
 public static final int DEFAULT_PASTE_MODIFIER
Default paste command modifier (InputEvent.CTRL_MASK).

 o DEFAULT_SELECTION_BACKGROUND
 public static final Color DEFAULT_SELECTION_BACKGROUND
Selected text background (dark blue).

 o DEFAULT_SELECTION_FOREGROUND
 public static final Color DEFAULT_SELECTION_FOREGROUND
Selected text foreground (Color.white).

 o fClipboard
 protected static transient Clipboard fClipboard
The clipboard reference.

 o fBegin
 protected int fBegin
The starting index of the selection/caret start index.

 o fEnd
 protected int fEnd
The ending index of the selection.

 o fEditable
 protected boolean fEditable
Sets whether the component is editable by the user. This variable is true by default.

Constructors

 o TextClipboardComponent
 public TextClipboardComponent()
Default constructor.

Methods

 o init
 public void init()
Initialize transient data.

 o setCutCharacter
 public static void setCutCharacter(char ch)
Sets the cut command character. This character is used in conjunction with the cut modifier to tell when a clipboard cut should be performed.

Parameters:
ch - The command character.
See Also:
getCutCharacter, setCutModifier, DEFAULT_CUT_CHAR
 o getCutCharacter
 public static char getCutCharacter()
Returns the cut command character.

See Also:
setCutCharacter
 o setCutModifier
 public static void setCutModifier(int mod)
Sets the cut command modifier. This modifier is used in conjunction with the cut character to tell when a clipboard cut should be performed.

Parameters:
mod - The command modifier.
See Also:
getCutModifier, setCutCharacter, DEFAULT_CUT_MODIFIER
 o getCutModifier
 public static int getCutModifier()
Returns the cut command modifier.

See Also:
setCutModifier
 o setCopyCharacter
 public static void setCopyCharacter(char ch)
Sets the copy command character. This character is used in conjunction with the copy modifier to tell when a clipboard copy should be performed.

Parameters:
ch - The command character.
See Also:
getCopyCharacter, DEFAULT_COPY_CHAR
 o getCopyCharacter
 public static char getCopyCharacter()
Returns the copy command character.

See Also:
setCopyCharacter
 o setCopyModifier
 public static void setCopyModifier(int mod)
Sets the copy command modifier. This modifier is used in conjunction with the copy character to tell when a clipboard copy should be performed.

Parameters:
mod - The command modifier.
See Also:
getCopyModifier, setCopyCharacter, DEFAULT_COPY_MODIFIER
 o getCopyModifier
 public static int getCopyModifier()
Returns the copy command modifier.

See Also:
setCopyModifier
 o setPasteCharacter
 public static void setPasteCharacter(char ch)
Sets the paste command character. This character is used in conjunction with the paste modifier to tell when a clipboard paste should be performed.

Parameters:
ch - The command character.
See Also:
getPasteCharacter, DEFAULT_PASTE_CHAR
 o getPasteCharacter
 public static char getPasteCharacter()
Returns the paste command character.

See Also:
setPasteCharacter
 o setPasteModifier
 public static void setPasteModifier(int mod)
Sets the paste command modifier. This modifier is used in conjunction with the paste character to tell when a clipboard paste should be performed.

Parameters:
mod - The command modifier.
See Also:
getPasteModifier, setPasteCharacter, DEFAULT_PASTE_MODIFIER
 o getPasteModifier
 public static int getPasteModifier()
Returns the paste command modifier.

See Also:
setPasteModifier
 o lostOwnership
 public void lostOwnership(Clipboard cb,
                           Transferable t)
Another clipboard owner took control of the clipboard. Override this method if you need to perform special handling in this event.

 o cut
 public void cut()
Cut contents to clipboard. Override this method to provide functionality.

 o copy
 public void copy()
Copy contents to clipboard. Override this method to provide functionality.

 o paste
 public void paste()
Paste clipboard contents. Override this method to provide functionality.

 o copyToClipboard
 public void copyToClipboard(String text)
Copies the specified string to clipboard. If the text is null or empty, the copy is not done.

Parameters:
text - The text to copy.
See Also:
copyFromClipboard
 o copyFromClipboard
 public String copyFromClipboard()
Returns the text on the clipboard or null if no text exists.

See Also:
copyToClipboard
 o clipboardCommand
 public boolean clipboardCommand(KeyEvent evt)
Checks key event to see if the key typed signals a clipboard operation. If so, the appropriate command is performed. The default command for a cut, copy, and paste is to call cut(), copy(), and paste(), respectively.

This class does not listen to key events. Instead, the extended class should listen for the events and call this method if the default behaviour is needed.

This method returns true if a clipboard operation was performed, false otherwise.

 o setSelectionBackground
 public void setSelectionBackground(Color color)
Sets the selected text background color.

Parameters:
color - The new color.
See Also:
getSelectionBackground, DEFAULT_SELECTION_BACKGROUND, setSelectionForeground
 o getSelectionBackground
 public Color getSelectionBackground()
Returns the current selected text background color.

See Also:
setSelectionBackground, DEFAULT_SELECTION_BACKGROUND
 o setSelectionForeground
 public void setSelectionForeground(Color color)
Sets the selected text foreground color.

Parameters:
color - The new color.
See Also:
getSelectionForeground, DEFAULT_SELECTION_FOREGROUND, setSelectionBackground
 o getSelectionForeground
 public Color getSelectionForeground()
Returns the current selected text foreground color.

See Also:
setSelectionForeground, DEFAULT_SELECTION_FOREGROUND
 o getDisplayText
 protected abstract String getDisplayText()
Returns the display text. This method is not used by the user of this component. Use getText() instead.

 o setText
 public abstract void setText(String text)
Sets the text displayed in this component. This method must be overridden to provide functionality.

See Also:
getText
 o getText
 public abstract String getText()
Returns the current text displayed in the component. This metohd must be overridden to provide functionality.

See Also:
setText
 o setEditable
 public void setEditable(boolean editable)
Sets whether this component is editable by the user.

Parameters:
editable - True if editable, false if not.
See Also:
isEditable
 o isEditable
 public boolean isEditable()
Returns whether this component is editable by the user.

See Also:
setEditable
 o setCaretPosition
 public synchronized void setCaretPosition(int begin)
Moves the caret to the specified position within the text. A value less than 0 is considered to be 0 and a value greater than the length of the text is set to the end of the text.

Parameters:
begin - The new index position of the caret.
See Also:
getCaretPosition
 o getCaretPosition
 public int getCaretPosition()
Returns the current position of the caret within the text.

See Also:
setCaretPosition
 o select
 public synchronized void select(int begin,
                                 int end)
Selects the text bounded by the specified beginning and ending indexes.

Parameters:
begin - The start index.
end - The end index.
See Also:
selectAll, setSelectionStart, setSelectionEnd, getSelectedText
 o selectAll
 public synchronized void selectAll()
Selects the entire text.

See Also:
select
 o getSelectedText
 public synchronized String getSelectedText()
Returns the selection text.

See Also:
select
 o setSelectionStart
 public synchronized void setSelectionStart(int begin)
Sets the starting index of the selection.

Parameters:
begin - The start index.
See Also:
getSelectionStart, setSelectionEnd
 o getSelectionStart
 public int getSelectionStart()
Returns the starting index of the selection.

See Also:
setSelectionStart
 o setSelectionEnd
 public synchronized void setSelectionEnd(int end)
Sets the ending index of the selection.

Parameters:
end - The end index.
See Also:
getSelectionEnd, setSelectionStart
 o getSelectionEnd
 public int getSelectionEnd()
Returns the ending index of the selection.

See Also:
setSelectionEnd
 o addTextListener
 public abstract void addTextListener(TextListener listener)
Adds a text event listener.

Parameters:
listener - The new listener.
See Also:
removeTextListener
 o removeTextListener
 public abstract void removeTextListener(TextListener listener)
Removes a text event listener.

Parameters:
listener - The listener to remove.
See Also:
addTextListener

All Packages  Class Hierarchy  This Package  Previous  Next  Index