com.ibm.richtext.textpanel
Class JTextPanel

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--com.ibm.richtext.textpanel.JTextPanel
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, MTextPanel, java.io.Serializable

public final class JTextPanel
extends javax.swing.JPanel
implements MTextPanel

JTextPanel is an implementation of MTextPanel in a Swing JPanel.

See Also:
MTextPanel, Serialized Form

Inner classes inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Inner classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Inner classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface com.ibm.richtext.textpanel.MTextPanel
COPYRIGHT, MULTIPLE_VALUES
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
JTextPanel(MConstText initialText, java.awt.datatransfer.Clipboard clipboard)
          Create a new JTextPanel with the default settings.
JTextPanel(TextPanelSettings settings, MConstText initialText, java.awt.datatransfer.Clipboard clipboard)
          Create a new JTextPanel.
 
Method Summary
 void addListener(TextPanelListener listener)
          Add the given TextPanelListener to the listeners which will receive update notifications from this JTextPanel.
 void append(MConstText newText)
          Append the given text to the end of the document.
 boolean canRedo()
          Return true if there is a change which can be redone.
 boolean canUndo()
          Return true if there is a change which can be undone.
 void clear()
          Remove selected text from the document, without altering the clipboard.
 void clearCommandLog()
          Remove all commands from the command log.
 boolean clipboardNotEmpty()
          Return true if the clipboard contains contents which could be transfered into the text.
 void copy()
          Place the selected text on the clipboard.
 void cut()
          Remove the selected text from the document and place it on the clipboard.
 java.lang.Object getCharacterStyleOverSelection(java.lang.Object key)
          This method inspects the character style runs in the selection range (or the typing style at the insertion point).
 int getCommandLogSize()
          Return the number of commands the command log can hold.
static TextPanelSettings getDefaultSettings()
          Return a TextPanelSettings instance with all settings set to the default values.
 AttributeMap getDefaultValues()
          Return an AttributeMap of keys with default values.
 int getFormatWidth()
          Return the total format width, in pixels.
 KeyRemap getKeyRemap()
          Return the KeyRemap used to process key events.
 java.lang.Object getParagraphStyleOverSelection(java.lang.Object key)
          This method inspects the paragraph style runs in the selection range (or the typing style at the insertion point).
 int getSelectionEnd()
          Return the offset of the end of the selection.
 int getSelectionStart()
          Return the offset of the start of the selection.
 MConstText getText()
          Return the text document in the JTextPanel.
 int getTextLength()
          Return the length of the text document in the JTextPanel.
 void insert(MConstText newText, int position)
          Insert the given text into the document at the given position.
 boolean isModified()
          Return the modification flag of the current text change.
 void modifyCharacterStyleOnSelection(StyleModifier modifier)
          Modify the character styles on the selected characters.
 void modifyParagraphStyleOnSelection(StyleModifier modifier)
          Modify the paragraph styles in paragraphs containing selected characters, or the paragraph containing the insertion point.
 boolean paragraphIsLeftToRight(int offset)
          Return true if the paragraph at the given offset is left-to-right.
 void paste()
          Replace the currently selected text with the text on the clipboard.
 void redo()
          Redo the most recent text change.
 void removeListener(TextPanelListener listener)
          Remove the given TextPanelListener from the listeners which will receive update notifications from this JTextPanel.
 void replaceRange(MConstText newText, int start, int end)
          Replace the given range with newText.
 void select(int selectionStart, int selectionEnd)
          Set the selection range to the given range.
 void selectAll()
          Select all of the text in the document.
 void setBackground(java.awt.Color color)
           
 void setCaretPosition(int position)
          Set the selection range to an insertion point at the given offset.
 void setCommandLogSize(int size)
          Set the number of commands the command log can hold.
 void setKeyRemap(KeyRemap remap)
          Use the given KeyRemap to map key events to characters.
 void setModified(boolean modified)
          Set the modification flag of the current text change.
 void setSelectionEnd(int selectionEnd)
          Set the end of the selection range.
 void setSelectionStart(int selectionStart)
          Set the beginning of the selection range.
 void setText(MConstText newText)
          Set the document to newText.
 void undo()
          Undo the most recent text change.
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUIClassID, paramString, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getVerifyInputWhenFocusTarget, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, hide, isDoubleBuffered, isFocusCycleRoot, isFocusTraversable, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processFocusEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

JTextPanel

public JTextPanel(MConstText initialText,
                  java.awt.datatransfer.Clipboard clipboard)
Create a new JTextPanel with the default settings.
Parameters:
initialText - the text document. If null document text is empty.
clipboard - the clipboard to use for cut, copy, and paste operations. If null this panel will use a private clipboard.

JTextPanel

public JTextPanel(TextPanelSettings settings,
                  MConstText initialText,
                  java.awt.datatransfer.Clipboard clipboard)
Create a new JTextPanel.
Parameters:
settings - the settings for this JTextPanel
initialText - the text document. If null document text is empty.
clipboard - the clipboard to use for cut, copy, and paste operations. If null this panel will use a private clipboard.
See Also:
TextPanelSettings
Method Detail

getDefaultSettings

public static TextPanelSettings getDefaultSettings()
Return a TextPanelSettings instance with all settings set to the default values. Clients can modify this object; modifications will not affect the default values.
Returns:
a TextPanelSettings instance set to default values
See Also:
TextPanelSettings

addListener

public void addListener(TextPanelListener listener)
Add the given TextPanelListener to the listeners which will receive update notifications from this JTextPanel.
Specified by:
addListener in interface MTextPanel
Parameters:
listener - the listener to add

removeListener

public void removeListener(TextPanelListener listener)
Remove the given TextPanelListener from the listeners which will receive update notifications from this JTextPanel.
Specified by:
removeListener in interface MTextPanel
Parameters:
listener - the listener to remove

setText

public void setText(MConstText newText)
Set the document to newText. This operation modifies the text in the JTextPanel. It does not modify or adopt newText. This method sets the selection an insertion point at the end of the text.
Specified by:
setText in interface MTextPanel
Parameters:
newText - the text which will replace the current text.

append

public void append(MConstText newText)
Append the given text to the end of the document. Equivalent to insert(newText, getTextLength()).
Specified by:
append in interface MTextPanel
Parameters:
newText - the text to append to the document

insert

public void insert(MConstText newText,
                   int position)
Insert the given text into the document at the given position. Equivalent to replaceRange(newText, position, position).
Specified by:
insert in interface MTextPanel
Parameters:
newText - the text to insert into the document.
position - the position in the document where the text will be inserted

replaceRange

public void replaceRange(MConstText newText,
                         int start,
                         int end)
Replace the given range with newText. After this operation the selection range is an insertion point at the end of the new text.
Specified by:
replaceRange in interface MTextPanel
Parameters:
newText - the text with which to replace the range
start - the beginning of the range to replace
end - the end of the range to replace

getTextLength

public int getTextLength()
Return the length of the text document in the JTextPanel.
Specified by:
getTextLength in interface MTextPanel
Returns:
the length of the text document in the JTextPanel

getText

public MConstText getText()
Return the text document in the JTextPanel.
Specified by:
getText in interface MTextPanel
Returns:
the text document in the JTextPanel.

getSelectionStart

public int getSelectionStart()
Return the offset of the start of the selection.
Specified by:
getSelectionStart in interface MTextPanel

getSelectionEnd

public int getSelectionEnd()
Return the offset of the end of the selection.
Specified by:
getSelectionEnd in interface MTextPanel

setSelectionStart

public void setSelectionStart(int selectionStart)
Set the beginning of the selection range. This is equivalent to select(selectionStart, getSelectionEnd()).
Specified by:
setSelectionStart in interface MTextPanel
Parameters:
selectionStart - the start of the new selection range

setSelectionEnd

public void setSelectionEnd(int selectionEnd)
Set the end of the selection range. This is equivalent to select(getSelectionStart(), selectionEnd).
Specified by:
setSelectionEnd in interface MTextPanel
Parameters:
selectionStart - the start of the new selection range

setCaretPosition

public void setCaretPosition(int position)
Set the selection range to an insertion point at the given offset. This is equivalent to select(position, position).
Specified by:
setCaretPosition in interface MTextPanel
Parameters:
position - the offset of the new insertion point

select

public void select(int selectionStart,
                   int selectionEnd)
Set the selection range to the given range. The range start is pinned between 0 and the text length; the range end is pinned between the range start and the end of the text. These semantics are identical to those of java.awt.TextComponent. This method has no effect if the text is not selectable.
Specified by:
select in interface MTextPanel
Parameters:
selectionStart - the beginning of the selection range
selectionEnd - the end of the selection range

selectAll

public void selectAll()
Select all of the text in the document. This method has no effect if the text is not selectable.
Specified by:
selectAll in interface MTextPanel

getFormatWidth

public int getFormatWidth()
Return the total format width, in pixels. The format width is the width to which text is wrapped.
Specified by:
getFormatWidth in interface MTextPanel
Returns:
the format width

paragraphIsLeftToRight

public boolean paragraphIsLeftToRight(int offset)
Return true if the paragraph at the given offset is left-to-right.
Specified by:
paragraphIsLeftToRight in interface MTextPanel
Parameters:
offset - an offset in the text
Returns:
true if the paragraph at the given offset is left-to-right

canUndo

public boolean canUndo()
Return true if there is a change which can be undone.
Specified by:
canUndo in interface MTextPanel
Returns:
true if there is a change which can be undone.

canRedo

public boolean canRedo()
Return true if there is a change which can be redone.
Specified by:
canRedo in interface MTextPanel
Returns:
true if there is a change which can be redone.

clipboardNotEmpty

public boolean clipboardNotEmpty()
Return true if the clipboard contains contents which could be transfered into the text.
Specified by:
clipboardNotEmpty in interface MTextPanel
Returns:
true if the clipboard has text content.

getDefaultValues

public AttributeMap getDefaultValues()
Return an AttributeMap of keys with default values. The default values are used when displaying text for values which are not specified in the text.
Specified by:
getDefaultValues in interface MTextPanel
Returns:
an AttributeMap of default key-value pairs

getCharacterStyleOverSelection

public java.lang.Object getCharacterStyleOverSelection(java.lang.Object key)
This method inspects the character style runs in the selection range (or the typing style at the insertion point). It returns: If a style run does not contain key, its value is considered to be the default style for key, as defined by the default values AttributeMap. Note that if key does not have a default value this method may return null. This method is useful for configuring style menus.
Specified by:
getCharacterStyleOverSelection in interface MTextPanel
Parameters:
key - the key used to retrieve values for comparison
See Also:
MTextPanel.MULTIPLE_VALUES

getParagraphStyleOverSelection

public java.lang.Object getParagraphStyleOverSelection(java.lang.Object key)
This method inspects the paragraph style runs in the selection range (or the typing style at the insertion point). It returns: If a style run does not contain key, its value is considered to be the default style for key, as defined by the default values AttributeMap. Note that if key does not have a default value this method may return null. This method is useful for configuring style menus.
Specified by:
getParagraphStyleOverSelection in interface MTextPanel
Parameters:
key - the key used to retrieve values for comparison
See Also:
MTextPanel.MULTIPLE_VALUES

cut

public void cut()
Remove the selected text from the document and place it on the clipboard. This method has no effect if the text is not editable, or if no text is selected.
Specified by:
cut in interface MTextPanel

copy

public void copy()
Place the selected text on the clipboard. This method has no effect if no text is selected.
Specified by:
copy in interface MTextPanel

paste

public void paste()
Replace the currently selected text with the text on the clipboard. This method has no effect if the text is not editable, or if no text is on the clipboard.
Specified by:
paste in interface MTextPanel

clear

public void clear()
Remove selected text from the document, without altering the clipboard. This method has no effect if the text is not editable.
Specified by:
clear in interface MTextPanel

undo

public void undo()
Undo the most recent text change. This method has no effect if there is no change to undo.
Specified by:
undo in interface MTextPanel

redo

public void redo()
Redo the most recent text change. This method has no effect if there is no change to redo.
Specified by:
redo in interface MTextPanel

getCommandLogSize

public int getCommandLogSize()
Return the number of commands the command log can hold.
Specified by:
getCommandLogSize in interface MTextPanel
Returns:
the number of commands the command log can hold

setCommandLogSize

public void setCommandLogSize(int size)
Set the number of commands the command log can hold. All redoable commands are removed when this method is called.
Specified by:
setCommandLogSize in interface MTextPanel
Parameters:
size - the number of commands kept in the command log

clearCommandLog

public void clearCommandLog()
Remove all commands from the command log.
Specified by:
clearCommandLog in interface MTextPanel

modifyCharacterStyleOnSelection

public void modifyCharacterStyleOnSelection(StyleModifier modifier)
Modify the character styles on the selected characters. If no characters are selected, modify the typing style.
Specified by:
modifyCharacterStyleOnSelection in interface MTextPanel
Parameters:
modifier - the StyleModifier with which to modify the styles

modifyParagraphStyleOnSelection

public void modifyParagraphStyleOnSelection(StyleModifier modifier)
Modify the paragraph styles in paragraphs containing selected characters, or the paragraph containing the insertion point.
Specified by:
modifyParagraphStyleOnSelection in interface MTextPanel
Parameters:
modifier - the StyleModifier with which to modify the styles

getKeyRemap

public KeyRemap getKeyRemap()
Return the KeyRemap used to process key events.
Specified by:
getKeyRemap in interface MTextPanel
Returns:
the key remap used to process key events
See Also:
setKeyRemap(com.ibm.richtext.textpanel.KeyRemap)

setKeyRemap

public void setKeyRemap(KeyRemap remap)
Use the given KeyRemap to map key events to characters. Only key events are affected by the remap; other text entering the control (via the clipboard, for example) is not affected by the KeyRemap.

Do not pass null to this method to leave key events unmapped. Instead, use KeyRemap.getIdentityRemap()

Specified by:
setKeyRemap in interface MTextPanel
Parameters:
remap - the KeyRemap to use for mapping key events to characters
Throws:
java.lang.NullPointerException - if parameter is null
See Also:
KeyRemap

isModified

public boolean isModified()
Return the modification flag of the current text change.
Specified by:
isModified in interface MTextPanel
See Also:
setModified(boolean)

setModified

public void setModified(boolean modified)
Set the modification flag of the current text change.
Specified by:
setModified in interface MTextPanel

setBackground

public void setBackground(java.awt.Color color)
Overrides:
setBackground in class javax.swing.JComponent


Copyright (c) 2001 IBM Corporation and others.