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.
-
DEFAULT_COPY_CHAR
- Default copy command character ('^c').
-
DEFAULT_COPY_MODIFIER
- Default copy command modifier (InputEvent.CTRL_MASK).
-
DEFAULT_CUT_CHAR
- Default cut command character ('^x').
-
DEFAULT_CUT_MODIFIER
- Default cut command modifier (InputEvent.CTRL_MASK).
-
DEFAULT_PASTE_CHAR
- Default paste command character ('^v').
-
DEFAULT_PASTE_MODIFIER
- Default paste command modifier (InputEvent.CTRL_MASK).
-
DEFAULT_SELECTION_BACKGROUND
- Selected text background (dark blue).
-
DEFAULT_SELECTION_FOREGROUND
- Selected text foreground (Color.white).
-
fBegin
- The starting index of the selection/caret start index.
-
fClipboard
- The clipboard reference.
-
fEditable
- Sets whether the component is editable by the user.
-
fEnd
- The ending index of the selection.
-
TextClipboardComponent()
- Default constructor.
-
addTextListener(TextListener)
- Adds a text event listener.
-
clipboardCommand(KeyEvent)
- Checks key event to see if the key typed signals a
clipboard operation.
-
copy()
- Copy contents to clipboard.
-
copyFromClipboard()
- Returns the text on the clipboard or null if no text
exists.
-
copyToClipboard(String)
- Copies the specified string to clipboard.
-
cut()
- Cut contents to clipboard.
-
getCaretPosition()
- Returns the current position of the caret within the text.
-
getCopyCharacter()
- Returns the copy command character.
-
getCopyModifier()
- Returns the copy command modifier.
-
getCutCharacter()
- Returns the cut command character.
-
getCutModifier()
- Returns the cut command modifier.
-
getDisplayText()
- Returns the display text.
-
getPasteCharacter()
- Returns the paste command character.
-
getPasteModifier()
- Returns the paste command modifier.
-
getSelectedText()
- Returns the selection text.
-
getSelectionBackground()
- Returns the current selected text background color.
-
getSelectionEnd()
- Returns the ending index of the selection.
-
getSelectionForeground()
- Returns the current selected text foreground color.
-
getSelectionStart()
- Returns the starting index of the selection.
-
getText()
- Returns the current text displayed in the component.
-
init()
- Initialize transient data.
-
isEditable()
- Returns whether this component is editable by the user.
-
lostOwnership(Clipboard, Transferable)
- Another clipboard owner took control of the clipboard.
-
paste()
- Paste clipboard contents.
-
removeTextListener(TextListener)
- Removes a text event listener.
-
select(int, int)
- Selects the text bounded by the specified beginning and
ending indexes.
-
selectAll()
- Selects the entire text.
-
setCaretPosition(int)
- Moves the caret to the specified position within the text.
-
setCopyCharacter(char)
- Sets the copy command character.
-
setCopyModifier(int)
- Sets the copy command modifier.
-
setCutCharacter(char)
- Sets the cut command character.
-
setCutModifier(int)
- Sets the cut command modifier.
-
setEditable(boolean)
- Sets whether this component is editable by the user.
-
setPasteCharacter(char)
- Sets the paste command character.
-
setPasteModifier(int)
- Sets the paste command modifier.
-
setSelectionBackground(Color)
- Sets the selected text background color.
-
setSelectionEnd(int)
- Sets the ending index of the selection.
-
setSelectionForeground(Color)
- Sets the selected text foreground color.
-
setSelectionStart(int)
- Sets the starting index of the selection.
-
setText(String)
- Sets the text displayed in this component.
DEFAULT_CUT_CHAR
public static final char DEFAULT_CUT_CHAR
- Default cut command character ('^x').
DEFAULT_CUT_MODIFIER
public static final int DEFAULT_CUT_MODIFIER
- Default cut command modifier (InputEvent.CTRL_MASK).
DEFAULT_COPY_CHAR
public static final char DEFAULT_COPY_CHAR
- Default copy command character ('^c').
DEFAULT_COPY_MODIFIER
public static final int DEFAULT_COPY_MODIFIER
- Default copy command modifier (InputEvent.CTRL_MASK).
DEFAULT_PASTE_CHAR
public static final char DEFAULT_PASTE_CHAR
- Default paste command character ('^v').
DEFAULT_PASTE_MODIFIER
public static final int DEFAULT_PASTE_MODIFIER
- Default paste command modifier (InputEvent.CTRL_MASK).
DEFAULT_SELECTION_BACKGROUND
public static final Color DEFAULT_SELECTION_BACKGROUND
- Selected text background (dark blue).
DEFAULT_SELECTION_FOREGROUND
public static final Color DEFAULT_SELECTION_FOREGROUND
- Selected text foreground (Color.white).
fClipboard
protected static transient Clipboard fClipboard
- The clipboard reference.
fBegin
protected int fBegin
- The starting index of the selection/caret start index.
fEnd
protected int fEnd
- The ending index of the selection.
fEditable
protected boolean fEditable
- Sets whether the component is editable by the user. This
variable is true by default.
TextClipboardComponent
public TextClipboardComponent()
- Default constructor.
init
public void init()
- Initialize transient data.
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
getCutCharacter
public static char getCutCharacter()
- Returns the cut command character.
- See Also:
- setCutCharacter
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
getCutModifier
public static int getCutModifier()
- Returns the cut command modifier.
- See Also:
- setCutModifier
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
getCopyCharacter
public static char getCopyCharacter()
- Returns the copy command character.
- See Also:
- setCopyCharacter
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
getCopyModifier
public static int getCopyModifier()
- Returns the copy command modifier.
- See Also:
- setCopyModifier
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
getPasteCharacter
public static char getPasteCharacter()
- Returns the paste command character.
- See Also:
- setPasteCharacter
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
getPasteModifier
public static int getPasteModifier()
- Returns the paste command modifier.
- See Also:
- setPasteModifier
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.
cut
public void cut()
- Cut contents to clipboard. Override this method to provide
functionality.
copy
public void copy()
- Copy contents to clipboard. Override this method to provide
functionality.
paste
public void paste()
- Paste clipboard contents. Override this method to provide
functionality.
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
copyFromClipboard
public String copyFromClipboard()
- Returns the text on the clipboard or null if no text
exists.
- See Also:
- copyToClipboard
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.
setSelectionBackground
public void setSelectionBackground(Color color)
- Sets the selected text background color.
- Parameters:
- color - The new color.
- See Also:
- getSelectionBackground, DEFAULT_SELECTION_BACKGROUND, setSelectionForeground
getSelectionBackground
public Color getSelectionBackground()
- Returns the current selected text background color.
- See Also:
- setSelectionBackground, DEFAULT_SELECTION_BACKGROUND
setSelectionForeground
public void setSelectionForeground(Color color)
- Sets the selected text foreground color.
- Parameters:
- color - The new color.
- See Also:
- getSelectionForeground, DEFAULT_SELECTION_FOREGROUND, setSelectionBackground
getSelectionForeground
public Color getSelectionForeground()
- Returns the current selected text foreground color.
- See Also:
- setSelectionForeground, DEFAULT_SELECTION_FOREGROUND
getDisplayText
protected abstract String getDisplayText()
- Returns the display text. This method is not used by
the user of this component. Use getText() instead.
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
getText
public abstract String getText()
- Returns the current text displayed in the component.
This metohd must be overridden to provide functionality.
- See Also:
- setText
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
isEditable
public boolean isEditable()
- Returns whether this component is editable by the user.
- See Also:
- setEditable
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
getCaretPosition
public int getCaretPosition()
- Returns the current position of the caret within the text.
- See Also:
- setCaretPosition
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
selectAll
public synchronized void selectAll()
- Selects the entire text.
- See Also:
- select
getSelectedText
public synchronized String getSelectedText()
- Returns the selection text.
- See Also:
- select
setSelectionStart
public synchronized void setSelectionStart(int begin)
- Sets the starting index of the selection.
- Parameters:
- begin - The start index.
- See Also:
- getSelectionStart, setSelectionEnd
getSelectionStart
public int getSelectionStart()
- Returns the starting index of the selection.
- See Also:
- setSelectionStart
setSelectionEnd
public synchronized void setSelectionEnd(int end)
- Sets the ending index of the selection.
- Parameters:
- end - The end index.
- See Also:
- getSelectionEnd, setSelectionStart
getSelectionEnd
public int getSelectionEnd()
- Returns the ending index of the selection.
- See Also:
- setSelectionEnd
addTextListener
public abstract void addTextListener(TextListener listener)
- Adds a text event listener.
- Parameters:
- listener - The new listener.
- See Also:
- removeTextListener
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