Class RTextArea
- All Implemented Interfaces:
ImageObserver, MenuContainer, Printable, Serializable, Accessible, Scrollable
- Direct Known Subclasses:
RSyntaxTextArea
JTextArea that adds the following features:
- Insert/Overwrite modes (can be toggled via the Insert key)
- A right-click popup menu with standard editing options
- Macro support
- "Mark all" functionality.
- A way to change the background to an image (gif/png/jpg)
- Highlight the current line (can be toggled)
- An easy way to print its text (implements Printable)
- Hard/soft (emulated with spaces) tabs
- Fixes a bug with setTabSize
- Other handy new methods
RTextArea is set to a color,
its opaque property is set to true for performance reasons. If
the background is set to an image, then the opaque property is set to
false. This slows things down a little, but if it didn't happen
then we would see garbage on-screen when the user scrolled through a document
using the arrow keys (not the page-up/down keys though). You should never
have to set the opaque property yourself; it is always done for you.- Version:
- 1.0
- Author:
- Robert Futrell
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classModified fromMutableCaretEventinJTextComponentso that mouse events get fired when the user is selecting text with the mouse as well.Nested classes/interfaces inherited from class RTextAreaBase
RTextAreaBase.RTAMouseListenerNested classes/interfaces inherited from class JTextArea
JTextArea.AccessibleJTextAreaNested classes/interfaces inherited from class JTextComponent
JTextComponent.AccessibleJTextComponent, JTextComponent.DropLocation, JTextComponent.KeyBindingNested classes/interfaces inherited from class JComponent
JComponent.AccessibleJComponentNested classes/interfaces inherited from class Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intprotected static RecordableTextActionstatic final intprotected static RecordableTextActionstatic final intstatic final intConstant representing insert mode.static final StringThe property fired when the "mark all" color changes.static final StringThe property fired when what ranges are labeled "mark all" changes.static final StringThe property fired when the "mark all on occurrence" property changes.static final intConstant representing overwrite mode.static final intstatic final intstatic final intstatic final intFields inherited from class RTextAreaBase
BACKGROUND_IMAGE_PROPERTY, CURRENT_LINE_HIGHLIGHT_COLOR_PROPERTY, CURRENT_LINE_HIGHLIGHT_FADE_PROPERTY, HIGHLIGHT_CURRENT_LINE_PROPERTY, ROUNDED_SELECTION_PROPERTYFields inherited from class JTextComponent
DEFAULT_KEYMAP, FOCUS_ACCELERATOR_KEYFields inherited from class JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields inherited from interface ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTHFields inherited from interface Printable
NO_SUCH_PAGE, PAGE_EXISTS -
Constructor Summary
ConstructorsConstructorDescriptionConstructor.RTextArea(int textMode) Creates a newRTextArea.RTextArea(int rows, int cols) Constructor.Constructor.Constructor.Constructor.RTextArea(AbstractDocument doc, String text, int rows, int cols) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionaddLineHighlight(int line, Color color) Adds a line highlight.voidBegins an "atomic edit."static voidBegins recording a macro.booleancanRedo()Returns whether a redo is possible.booleancanUndo()Returns whether an undo is possible.voidClears any "mark all" highlights, if any.protected voidconfigurePopupMenu(JPopupMenu popupMenu) Configures the popup menu for this text area.protected DocumentCreates the default implementation of the model to be used at construction if one isn't explicitly given.protected RTextAreaBase.RTAMouseListenerReturns the caret event/mouse listener forRTextAreas.protected JPopupMenuCreates the right-click popup menu.protected JMenuItemCreates and configures a menu item for used in the popup menu.protected RTextAreaUIReturns a real UI to install on this text area.protected RUndoManagerCreates an undo manager for use in this text area.voidRemoves all undoable edits from this document's undo manager.voidCompletes an "atomic" edit.static voidEnds recording a macro.protected voidNotifies all listeners that a caret change has occurred.static RecordableTextActiongetAction(int action) Provides a way to gain access to the editor actions on the right-click popup menu.static MacroReturns the macro currently stored in thisRTextArea.static ColorReturns the default color used for "mark all" highlights.static intReturns the default modifier key for a system.static IconGroupReturns the icon group being used for the actions of this text area.Returns the color used in "mark all" highlights.booleanReturns whether "mark all" should be enabled when a user does a "find next/find previous" action via Ctrl+K or Ctrl+Shift+K (the default shortcut keys for this action).intReturns the maximum ascent of all fonts used in this text area.Returns the popup menu for this component, lazily creating it if necessary.static StringReturns the text last selected and used in a Ctrl+K operation.final intReturns the text mode this editor pane is currently in.Returns the tool tip supplier.Returns the tooltip to display for a mouse event at the given location.protected voidhandleReplaceSelection(String content) Does the actual dirty-work of replacing the selected text in this text area (i.e., in its document).protected voidinit()Initializes this text area.static booleanReturns whether a macro is being recorded.static voidLoads a macro to be used by allRTextAreas in the current application.voidmarkAll(List<DocumentRange> ranges) Marks all ranges specified with the "mark all" highlighter.voidpaste()void"Plays back" the last recorded macro in this text area.intprint(Graphics g, PageFormat pageFormat, int pageIndex) Method called when it's time to print this badboy (the old-school, AWT way).protected voidOverridden to disable drag-and-drop if the user triple-clicks.voidWe override this method because the super version gives us an entirely newDocument, thus requiring us to re-attach our Undo manager.voidAttempt to redo the last action.voidRemoves all line highlights.voidRemoves a line highlight.voidreplaceRange(String str, int start, int end) Replaces text from the indicated start to end position with the new text specified.voidreplaceSelection(String text) This method overridesJTextComponent'sreplaceSelection, so that iftextModeisOVERWRITE_MODE, it actually overwrites.static voidsetActionProperties(int action, String name, char mnemonic, KeyStroke accelerator) Sets the properties of one of the actions this text area owns.static voidsetActionProperties(int action, String name, Integer mnemonic, KeyStroke accelerator) Sets the properties of one of the actions this text area owns.voidSets the caret to use in this text area.voidsetCaretStyle(int mode, CaretStyle style) Sets the style of caret used when in insert or overwrite mode.voidsetDocument(Document document) Sets the document used by this text area.static voidsetIconGroup(IconGroup group) Sets the path in which to find images to associate with the editor's actions.voidsetMarkAllHighlightColor(Color color) Sets the color used for "mark all."voidsetMarkAllOnOccurrenceSearches(boolean markAll) Sets whether "mark all" should be enabled when a user does a "find next/find previous" action via Ctrl+K or Ctrl+Shift+K (the default shortcut keys for this action).voidsetPopupMenu(JPopupMenu popupMenu) Sets the popup menu used by this text area.voidsetRoundedSelectionEdges(boolean rounded) Sets whether the edges of selections are rounded in this text area.static voidSets the text last selected/Ctrl+K'd in anRTextArea.voidsetTextMode(int mode) Sets the text mode for this editor pane.voidsetToolTipSupplier(ToolTipSupplier supplier) Sets the tool tip supplier.final voidSets the UI used by this text area.voidAttempt to undo an "action" done in this text area.Methods inherited from class RTextAreaBase
addNotify, convertSpacesToTabs, convertTabsToSpaces, forceCurrentLineHighlightRepaint, getBackground, getBackgroundImage, getBackgroundObject, getCaretLineNumber, getCaretOffsetFromLineStart, getCurrentCaretY, getCurrentLineHighlightColor, getDefaultCaretColor, getDefaultCurrentLineHighlightColor, getDefaultFont, getDefaultForeground, getDefaultMarginLineColor, getDefaultMarginLinePosition, getDefaultTabSize, getFadeCurrentLineHighlight, getHighlightCurrentLine, getLineEndOffsetOfCurrentLine, getLineHeight, getLineStartOffsetOfCurrentLine, getMarginLineColor, getMarginLinePixelLocation, getMarginLinePosition, getRoundedSelectionEdges, getTabsEmulated, isMarginLineEnabled, isOSX, paintComponent, possiblyUpdateCurrentLineHighlightLocation, processComponentEvent, setBackground, setBackgroundImage, setBackgroundObject, setCurrentLineHighlightColor, setFadeCurrentLineHighlight, setFont, setHighlightCurrentLine, setLineWrap, setMargin, setMarginLineColor, setMarginLineEnabled, setMarginLinePosition, setRTextAreaUI, setTabsEmulated, setTabSize, updateMarginLineX, yForLine, yForLineContainingMethods inherited from class JTextArea
append, getAccessibleContext, getColumns, getColumnWidth, getLineCount, getLineEndOffset, getLineOfOffset, getLineStartOffset, getLineWrap, getPreferredScrollableViewportSize, getPreferredSize, getRowHeight, getRows, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getTabSize, getUIClassID, getWrapStyleWord, insert, paramString, setColumns, setRows, setWrapStyleWordMethods inherited from class JTextComponent
addCaretListener, addInputMethodListener, addKeymap, copy, cut, getActions, getCaret, getCaretColor, getCaretListeners, getCaretPosition, getDisabledTextColor, getDocument, getDragEnabled, getDropLocation, getDropMode, getFocusAccelerator, getHighlighter, getInputMethodRequests, getKeymap, getKeymap, getMargin, getNavigationFilter, getPrintable, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getText, getText, getUI, isEditable, loadKeymap, modelToView, modelToView2D, moveCaretPosition, print, print, print, processInputMethodEvent, removeCaretListener, removeKeymap, removeNotify, restoreComposedText, saveComposedText, select, selectAll, setCaretColor, setCaretPosition, setComponentOrientation, setDisabledTextColor, setDragEnabled, setDropMode, setEditable, setFocusAccelerator, setHighlighter, setKeymap, setNavigationFilter, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setText, updateUI, viewToModel, viewToModel2D, writeMethods inherited from class JComponent
addAncestorListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, updateMethods inherited from class Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTreeMethods inherited from class Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
INSERT_MODE
public static final int INSERT_MODEConstant representing insert mode.- See Also:
-
OVERWRITE_MODE
public static final int OVERWRITE_MODEConstant representing overwrite mode.- See Also:
-
MARK_ALL_COLOR_PROPERTY
The property fired when the "mark all" color changes.- See Also:
-
MARK_ALL_ON_OCCURRENCE_SEARCHES_PROPERTY
The property fired when the "mark all on occurrence" property changes.- See Also:
-
MARK_ALL_OCCURRENCES_CHANGED_PROPERTY
The property fired when what ranges are labeled "mark all" changes.- See Also:
-
COPY_ACTION
public static final int COPY_ACTION- See Also:
-
CUT_ACTION
public static final int CUT_ACTION- See Also:
-
DELETE_ACTION
public static final int DELETE_ACTION- See Also:
-
PASTE_ACTION
public static final int PASTE_ACTION- See Also:
-
REDO_ACTION
public static final int REDO_ACTION- See Also:
-
SELECT_ALL_ACTION
public static final int SELECT_ALL_ACTION- See Also:
-
UNDO_ACTION
public static final int UNDO_ACTION- See Also:
-
cutAction
-
copyAction
-
-
Constructor Details
-
RTextArea
public RTextArea()Constructor. -
RTextArea
-
RTextArea
-
RTextArea
public RTextArea(int rows, int cols) Constructor.- Parameters:
rows- The number of rows to display.cols- The number of columns to display.- Throws:
IllegalArgumentException- If eitherrowsorcolsis negative.
-
RTextArea
Constructor.- Parameters:
text- The initial text to display.rows- The number of rows to display.cols- The number of columns to display.- Throws:
IllegalArgumentException- If eitherrowsorcolsis negative.
-
RTextArea
Constructor.- Parameters:
doc- The document for the editor.text- The initial text to display.rows- The number of rows to display.cols- The number of columns to display.- Throws:
IllegalArgumentException- If eitherrowsorcolsis negative.
-
RTextArea
public RTextArea(int textMode) Creates a newRTextArea.- Parameters:
textMode- EitherINSERT_MODEorOVERWRITE_MODE.
-
-
Method Details
-
addLineHighlight
Adds a line highlight.- Parameters:
line- The line to highlight. This is zero-based.color- The color to highlight the line with.- Returns:
- An opaque tag that can be used to remove the highlight later.
- Throws:
BadLocationException- Iflineis an invalid line number.- See Also:
-
beginAtomicEdit
public void beginAtomicEdit()Begins an "atomic edit." All text editing operations between this call and the next call to endAtomicEdit() will be treated as a single operation by the undo manager.Using this method should be done with great care. You should probably wrap the call to endAtomicEdit() in a finally block:
textArea.beginAtomicEdit(); try { // Do editing } finally { textArea.endAtomicEdit(); }- See Also:
-
beginRecordingMacro
public static void beginRecordingMacro()Begins recording a macro. After this method is called, all input/caret events, etc. are recorded untilendMacroRecordingis called. If this method is called but the text component is already recording a macro, nothing happens (but the macro keeps recording).- See Also:
-
canUndo
public boolean canUndo()Returns whether an undo is possible.- Returns:
- Whether the operation was successful.
- See Also:
-
canRedo
public boolean canRedo()Returns whether a redo is possible.- Returns:
- Whether the operation was successful.
- See Also:
-
clearMarkAllHighlights
public void clearMarkAllHighlights()Clears any "mark all" highlights, if any. AsSearchEnginehandles "mark all" highlights itself, the programmer doesn't usually need to call this directly. One use case to do so might be doing custom highlighting of specific text in the text area.- See Also:
-
configurePopupMenu
Configures the popup menu for this text area. This method is called right before it is displayed, so a hosting application can do any custom configuration (configuring actions, adding/removing items, etc.).The default implementation does nothing.
If you set the popup menu via
setPopupMenu(JPopupMenu), you will want to override this method, especially if you removed any of the menu items in the default popup menu.- Parameters:
popupMenu- The popup menu. This will never benull.- See Also:
-
createDefaultModel
Creates the default implementation of the model to be used at construction if one isn't explicitly given. A new instance of RDocument is returned.- Overrides:
createDefaultModelin classJTextArea- Returns:
- The default document.
-
createMouseListener
Returns the caret event/mouse listener forRTextAreas.- Specified by:
createMouseListenerin classRTextAreaBase- Returns:
- The caret event/mouse listener.
-
createPopupMenu
Creates the right-click popup menu. Subclasses can override this method to replace or augment the popup menu returned.- Returns:
- The popup menu.
- See Also:
-
createPopupMenuItem
-
createRTextAreaUI
Returns a real UI to install on this text area.- Specified by:
createRTextAreaUIin classRTextAreaBase- Returns:
- The UI.
-
createUndoManager
Creates an undo manager for use in this text area.- Returns:
- The undo manager.
-
discardAllEdits
public void discardAllEdits()Removes all undoable edits from this document's undo manager. This method also makes the undo/redo actions disabled. -
endAtomicEdit
public void endAtomicEdit()Completes an "atomic" edit.- See Also:
-
endRecordingMacro
public static void endRecordingMacro()Ends recording a macro. If this method is called but the text component is not recording a macro, nothing happens.- See Also:
-
fireCaretUpdate
Notifies all listeners that a caret change has occurred.- Overrides:
fireCaretUpdatein classJTextComponent- Parameters:
e- The caret event.
-
getAction
Provides a way to gain access to the editor actions on the right-click popup menu. This way you can make toolbar/menu bar items use the actual actions used by allRTextAreas, so that icons stay synchronized and you don't have to worry about enabling/disabling them yourself.Keep in mind that these actions are shared across all instances of
RTextArea, so a change to any action returned by this method is global across allRTextAreaeditors in your application.- Parameters:
action- The action to retrieve, such asCUT_ACTION. If the action name is invalid,nullis returned.- Returns:
- The action, or
nullif an invalid action is requested.
-
getCurrentMacro
Returns the macro currently stored in thisRTextArea. Since macros are shared, allRTextAreas in the currently running application are using this macro.- Returns:
- The current macro, or
nullif no macro has been recorded/loaded. - See Also:
-
getDefaultMarkAllHighlightColor
Returns the default color used for "mark all" highlights.- Returns:
- The color.
- See Also:
-
getDefaultModifier
public static int getDefaultModifier()Returns the default modifier key for a system. For example, on Windows this would be the CTRL key (InputEvent.CTRL_MASK).- Returns:
- The default modifier key.
-
getIconGroup
Returns the icon group being used for the actions of this text area.- Returns:
- The icon group.
- See Also:
-
getMarkAllOnOccurrenceSearches
public boolean getMarkAllOnOccurrenceSearches()Returns whether "mark all" should be enabled when a user does a "find next/find previous" action via Ctrl+K or Ctrl+Shift+K (the default shortcut keys for this action). The default value istrue.- Returns:
- Whether "mark all" should be enabled.
- See Also:
-
getMarkAllHighlightColor
Returns the color used in "mark all" highlights.- Returns:
- The color.
- See Also:
-
getMaxAscent
public int getMaxAscent()Returns the maximum ascent of all fonts used in this text area. In the case of a standardRTextArea, this is simply the ascent of the current font.This value could be useful, for example, to implement a line-numbering scheme.
- Returns:
- The ascent of the current font.
-
getPopupMenu
Returns the popup menu for this component, lazily creating it if necessary.- Returns:
- The popup menu.
- See Also:
-
getSelectedOccurrenceText
Returns the text last selected and used in a Ctrl+K operation.- Returns:
- The text, or
nullif none. - See Also:
-
getTextMode
public final int getTextMode()Returns the text mode this editor pane is currently in.- Returns:
- Either
INSERT_MODEorOVERWRITE_MODE. - See Also:
-
getToolTipSupplier
Returns the tool tip supplier.- Returns:
- The tool tip supplier, or
nullif one isn't installed. - See Also:
-
getToolTipText
Returns the tooltip to display for a mouse event at the given location. This method is overridden to check for aToolTipSupplier; if there is one installed, it is queried for tool tip text before using the super class's implementation of this method.- Overrides:
getToolTipTextin classJTextComponent- Parameters:
e- The mouse event.- Returns:
- The tool tip text, or
nullif none. - See Also:
-
handleReplaceSelection
Does the actual dirty-work of replacing the selected text in this text area (i.e., in its document). This method provides a hook for subclasses to handle this in a different way.- Parameters:
content- The content to add.
-
init
protected void init()Description copied from class:RTextAreaBaseInitializes this text area.- Overrides:
initin classRTextAreaBase
-
isRecordingMacro
public static boolean isRecordingMacro()Returns whether a macro is being recorded.- Returns:
- Whether a macro is being recorded.
- See Also:
-
loadMacro
Loads a macro to be used by allRTextAreas in the current application.- Parameters:
macro- The macro to load.- See Also:
-
markAll
Marks all ranges specified with the "mark all" highlighter. AsSearchEnginehandles "mark all" highlights itself, the programmer doesn't usually need to call this directly. One use case to do so might be doing custom highlighting of specific text in the text area.This method fires a property change event of type
MARK_ALL_OCCURRENCES_CHANGED_PROPERTY.- Parameters:
ranges- The ranges to mark. This should not benull.- See Also:
-
paste
public void paste()- Overrides:
pastein classJTextComponent
-
playbackLastMacro
public void playbackLastMacro()"Plays back" the last recorded macro in this text area. -
print
Method called when it's time to print this badboy (the old-school, AWT way). -
processMouseEvent
Overridden to disable drag-and-drop if the user triple-clicks. Typically, the user will select text, or double-click a word, then drag it to its destination. Triple-clicking before dragging text to a new location is rare. For that reason, we disable it in that case since it causes issues with triple-click-to-select-by-line. See https://github.com/bobbylight/RSyntaxTextArea/issues/59 for more information.- Overrides:
processMouseEventin classJComponent- Parameters:
e- The mouse event being dispatched.
-
read
We override this method because the super version gives us an entirely newDocument, thus requiring us to re-attach our Undo manager. With this version we just replace the text.- Overrides:
readin classJTextComponent- Throws:
IOException
-
redoLastAction
public void redoLastAction()Attempt to redo the last action.- See Also:
-
removeAllLineHighlights
public void removeAllLineHighlights()Removes all line highlights.- See Also:
-
removeLineHighlight
Removes a line highlight.- Parameters:
tag- The tag of the line highlight to remove.- See Also:
-
replaceRange
Replaces text from the indicated start to end position with the new text specified. Does nothing if the model is null. Simply does a delete if the new string is null or empty.This method is thread safe, although most Swing methods are not.
This method is overridden so that our Undo manager remembers it as a single operation (it has trouble with this, especially for
RSyntaxTextAreaand the "auto-indent" feature).- Overrides:
replaceRangein classJTextArea- Parameters:
str- the text to use as the replacementstart- the start position >= 0end- the end position >= start- Throws:
IllegalArgumentException- if part of the range is an invalid position in the model.- See Also:
-
replaceSelection
This method overridesJTextComponent'sreplaceSelection, so that iftextModeisOVERWRITE_MODE, it actually overwrites.- Overrides:
replaceSelectionin classJTextComponent- Parameters:
text- The content to replace the selection with.
-
setActionProperties
public static void setActionProperties(int action, String name, char mnemonic, KeyStroke accelerator) Sets the properties of one of the actions this text area owns.- Parameters:
action- The action to modify; for example,CUT_ACTION.name- The new name for the action.mnemonic- The new mnemonic for the action.accelerator- The new accelerator key for the action.
-
setActionProperties
public static void setActionProperties(int action, String name, Integer mnemonic, KeyStroke accelerator) Sets the properties of one of the actions this text area owns.- Parameters:
action- The action to modify; for example,CUT_ACTION.name- The new name for the action.mnemonic- The new mnemonic for the action.accelerator- The new accelerator key for the action.
-
setCaret
Sets the caret to use in this text area. It is strongly encouraged to useConfigurableCarets (which is used by default), or a subclass, since they know how to render themselves differently when the user toggles between insert and overwrite modes.- Overrides:
setCaretin classJTextComponent- Parameters:
caret- The caret to use.- See Also:
-
setCaretStyle
Sets the style of caret used when in insert or overwrite mode.- Parameters:
mode- EitherINSERT_MODEorOVERWRITE_MODE.style- The style for the caret.- See Also:
-
setDocument
Sets the document used by this text area.- Overrides:
setDocumentin classJTextComponent- Parameters:
document- The new document to use.- Throws:
IllegalArgumentException- If the document is not an instance ofRDocument.
-
setIconGroup
Sets the path in which to find images to associate with the editor's actions. The path MUST contain the following images (with the appropriate extension as defined by the icon group):
- cut
- copy
- paste
- delete
- undo
- redo
- selectall
- Parameters:
group- The icon group to load.- See Also:
-
setMarkAllHighlightColor
Sets the color used for "mark all." This fires a property change of typeMARK_ALL_COLOR_PROPERTY.- Parameters:
color- The color to use for "mark all."- See Also:
-
setMarkAllOnOccurrenceSearches
public void setMarkAllOnOccurrenceSearches(boolean markAll) Sets whether "mark all" should be enabled when a user does a "find next/find previous" action via Ctrl+K or Ctrl+Shift+K (the default shortcut keys for this action). The default value istrue.This method fires a property change event of type
MARK_ALL_ON_OCCURRENCE_SEARCHES_PROPERTY.- Parameters:
markAll- Whether "mark all" should be enabled.- See Also:
-
setPopupMenu
Sets the popup menu used by this text area.If you set the popup menu with this method, you'll want to consider also overriding
configurePopupMenu(JPopupMenu), especially if you removed any of the default menu items.- Parameters:
popupMenu- The popup menu. If this isnull, no popup menu will be displayed.- See Also:
-
setRoundedSelectionEdges
public void setRoundedSelectionEdges(boolean rounded) Description copied from class:RTextAreaBaseSets whether the edges of selections are rounded in this text area. This method fires a property change of typeRTextAreaBase.ROUNDED_SELECTION_PROPERTY.- Overrides:
setRoundedSelectionEdgesin classRTextAreaBase- Parameters:
rounded- Whether selection edges should be rounded.- See Also:
-
setSelectedOccurrenceText
Sets the text last selected/Ctrl+K'd in anRTextArea. This text will be searched for in subsequent Ctrl+K/Ctrl+Shift+K actions (Cmd+K on OS X).Since the selected occurrence actions are built into RTextArea, applications usually do not have to call this method directly, but can choose to do so if they wish (for example, if they wish to set this value when the user does a search via a Find dialog).
- Parameters:
text- The selected text.- See Also:
-
setTextMode
public void setTextMode(int mode) Sets the text mode for this editor pane. If the currently installed caret is an instance ofConfigurableCaret, it will be automatically updated to render itself appropriately for the new text mode.- Parameters:
mode- EitherINSERT_MODEorOVERWRITE_MODE.- See Also:
-
setToolTipSupplier
Sets the tool tip supplier.- Parameters:
supplier- The new tool tip supplier, ornullif there is to be no supplier.- See Also:
-
setUI
Sets the UI used by this text area. This is overridden so only the right-click popup menu's UI is updated. The look and feel of anRTextAreais independent of the Java Look and Feel, and so this method does not change the text area itself. Subclasses (such asRSyntaxTextArea) can callsetRTextAreaUIif they wish to install a new UI.- Overrides:
setUIin classJTextComponent- Parameters:
ui- This parameter is ignored.
-
undoLastAction
public void undoLastAction()Attempt to undo an "action" done in this text area.- See Also:
-