Class RTextArea

  • All Implemented Interfaces:
    java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.print.Printable, java.io.Serializable, javax.accessibility.Accessible, javax.swing.Scrollable
    Direct Known Subclasses:
    RSyntaxTextArea

    public class RTextArea
    extends RTextAreaBase
    implements java.awt.print.Printable
    An extension of 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
    NOTE: If the background for an 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
    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      protected class  RTextArea.RTextAreaMutableCaretEvent
      Modified from MutableCaretEvent in JTextComponent so that mouse events get fired when the user is selecting text with the mouse as well.
      • Nested classes/interfaces inherited from class javax.swing.JTextArea

        javax.swing.JTextArea.AccessibleJTextArea
      • Nested classes/interfaces inherited from class javax.swing.text.JTextComponent

        javax.swing.text.JTextComponent.AccessibleJTextComponent, javax.swing.text.JTextComponent.DropLocation, javax.swing.text.JTextComponent.KeyBinding
      • Nested classes/interfaces inherited from class javax.swing.JComponent

        javax.swing.JComponent.AccessibleJComponent
      • Nested classes/interfaces inherited from class java.awt.Container

        java.awt.Container.AccessibleAWTContainer
      • Nested classes/interfaces inherited from class java.awt.Component

        java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
    • Constructor Summary

      Constructors 
      Constructor Description
      RTextArea()
      Constructor.
      RTextArea​(int textMode)
      Creates a new RTextArea.
      RTextArea​(int rows, int cols)
      Constructor.
      RTextArea​(java.lang.String text)
      Constructor.
      RTextArea​(java.lang.String text, int rows, int cols)
      Constructor.
      RTextArea​(javax.swing.text.AbstractDocument doc)
      Constructor.
      RTextArea​(javax.swing.text.AbstractDocument doc, java.lang.String text, int rows, int cols)
      Constructor.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object addLineHighlight​(int line, java.awt.Color color)
      Adds a line highlight.
      (package private) static void addToCurrentMacro​(java.lang.String id, java.lang.String actionCommand)
      Adds an action event to the current macro.
      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.
      static void beginRecordingMacro()
      Begins recording a macro.
      boolean canRedo()
      Returns whether a redo is possible.
      boolean canUndo()
      Returns whether an undo is possible.
      void clearMarkAllHighlights()
      Clears any "mark all" highlights, if any.
      protected void configurePopupMenu​(javax.swing.JPopupMenu popupMenu)
      Configures the popup menu for this text area.
      protected javax.swing.text.Document createDefaultModel()
      Creates the default implementation of the model to be used at construction if one isn't explicitly given.
      protected RTextAreaBase.RTAMouseListener createMouseListener()
      Returns the caret event/mouse listener for RTextAreas.
      protected javax.swing.JPopupMenu createPopupMenu()
      Creates the right-click popup menu.
      private static void createPopupMenuActions()
      Creates the actions used in the popup menu and retrievable by getAction(int).
      protected javax.swing.JMenuItem createPopupMenuItem​(javax.swing.Action a)
      Creates and configures a menu item for used in the popup menu.
      protected RTextAreaUI createRTextAreaUI()
      Returns a real UI to install on this text area.
      private java.lang.String createSpacer​(int size)
      Creates a string of space characters of the specified size.
      protected RUndoManager createUndoManager()
      Creates an undo manager for use in this text area.
      void discardAllEdits()
      Removes all undoable edits from this document's undo manager.
      void endAtomicEdit()
      Completes an "atomic" edit.
      static void endRecordingMacro()
      Ends recording a macro.
      protected void fireCaretUpdate​(javax.swing.event.CaretEvent e)
      Notifies all listeners that a caret change has occurred.
      private void fixCtrlH()
      Removes the "Ctrl+H <=> Backspace" behavior that Java shows, for some odd reason...
      static RecordableTextAction getAction​(int action)
      Provides a way to gain access to the editor actions on the right-click popup menu.
      static Macro getCurrentMacro()
      Returns the macro currently stored in this RTextArea.
      static java.awt.Color getDefaultMarkAllHighlightColor()
      Returns the default color used for "mark all" highlights.
      static int getDefaultModifier()
      Returns the default modifier key for a system.
      static IconGroup getIconGroup()
      Returns the icon group being used for the actions of this text area.
      (package private) LineHighlightManager getLineHighlightManager()
      Returns the line highlight manager.
      java.awt.Color getMarkAllHighlightColor()
      Returns the color used in "mark all" highlights.
      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).
      int getMaxAscent()
      Returns the maximum ascent of all fonts used in this text area.
      javax.swing.JPopupMenu getPopupMenu()
      Returns the popup menu for this component, lazily creating it if necessary.
      static java.lang.String getSelectedOccurrenceText()
      Returns the text last selected and used in a Ctrl+K operation.
      int getTextMode()
      Returns the text mode this editor pane is currently in.
      ToolTipSupplier getToolTipSupplier()
      Returns the tool tip supplier.
      java.lang.String getToolTipText​(java.awt.event.MouseEvent e)
      Returns the tooltip to display for a mouse event at the given location.
      protected void handleReplaceSelection​(java.lang.String content)
      Does the actual dirty-work of replacing the selected text in this text area (i.e., in its document).
      protected void init()
      Initializes this text area.
      static boolean isRecordingMacro()
      Returns whether a macro is being recorded.
      static void loadMacro​(Macro macro)
      Loads a macro to be used by all RTextAreas in the current application.
      void markAll​(java.util.List<DocumentRange> ranges)
      Marks all ranges specified with the "mark all" highlighter.
      void paste()  
      void playbackLastMacro()
      "Plays back" the last recorded macro in this text area.
      int print​(java.awt.Graphics g, java.awt.print.PageFormat pageFormat, int pageIndex)
      Method called when it's time to print this badboy (the old-school, AWT way).
      protected void processMouseEvent​(java.awt.event.MouseEvent e)
      Overridden to disable drag-and-drop if the user triple-clicks.
      void read​(java.io.Reader in, java.lang.Object desc)
      We override this method because the super version gives us an entirely new Document, thus requiring us to re-attach our Undo manager.
      private void readObject​(java.io.ObjectInputStream s)
      De-serializes a text area.
      void redoLastAction()
      Attempt to redo the last action.
      void removeAllLineHighlights()
      Removes all line highlights.
      void removeLineHighlight​(java.lang.Object tag)
      Removes a line highlight.
      void replaceRange​(java.lang.String str, int start, int end)
      Replaces text from the indicated start to end position with the new text specified.
      void replaceSelection​(java.lang.String text)
      This method overrides JTextComponent's replaceSelection, so that if textMode is OVERWRITE_MODE, it actually overwrites.
      private java.lang.String replaceTabsWithSpaces​(java.lang.String text, int docOffs, int firstTab)
      Replaces all instances of the tab character in text with the number of spaces equivalent to a tab in this text area.
      static void setActionProperties​(int action, java.lang.String name, char mnemonic, javax.swing.KeyStroke accelerator)
      Sets the properties of one of the actions this text area owns.
      static void setActionProperties​(int action, java.lang.String name, java.lang.Integer mnemonic, javax.swing.KeyStroke accelerator)
      Sets the properties of one of the actions this text area owns.
      void setCaret​(javax.swing.text.Caret caret)
      Sets the caret to use in this text area.
      void setCaretStyle​(int mode, CaretStyle style)
      Sets the style of caret used when in insert or overwrite mode.
      void setDocument​(javax.swing.text.Document document)
      Sets the document used by this text area.
      static void setIconGroup​(IconGroup group)
      Sets the path in which to find images to associate with the editor's actions.
      void setMarkAllHighlightColor​(java.awt.Color color)
      Sets the color used for "mark all." This fires a property change of type MARK_ALL_COLOR_PROPERTY.
      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).
      void setPopupMenu​(javax.swing.JPopupMenu popupMenu)
      Sets the popup menu used by this text area.
      void setRoundedSelectionEdges​(boolean rounded)
      Sets whether the edges of selections are rounded in this text area.
      static void setSelectedOccurrenceText​(java.lang.String text)
      Sets the text last selected/Ctrl+K'd in an RTextArea.
      void setTextMode​(int mode)
      Sets the text mode for this editor pane.
      void setToolTipSupplier​(ToolTipSupplier supplier)
      Sets the tool tip supplier.
      void setUI​(javax.swing.plaf.TextUI ui)
      Sets the UI used by this text area.
      void undoLastAction()
      Attempt to undo an "action" done in this text area.
      private void writeObject​(java.io.ObjectOutputStream s)
      Serializes this text area.
      • Methods inherited from class javax.swing.JTextArea

        append, getAccessibleContext, getColumns, getColumnWidth, getLineCount, getLineEndOffset, getLineOfOffset, getLineStartOffset, getLineWrap, getPreferredScrollableViewportSize, getPreferredSize, getRowHeight, getRows, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getTabSize, getUIClassID, getWrapStyleWord, insert, paramString, setColumns, setRows, setWrapStyleWord
      • Methods inherited from class javax.swing.text.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, write
      • Methods inherited from class javax.swing.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, update
      • Methods inherited from class java.awt.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, validateTree
      • Methods inherited from class java.awt.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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • MARK_ALL_COLOR_PROPERTY

        public static final java.lang.String MARK_ALL_COLOR_PROPERTY
        The property fired when the "mark all" color changes.
        See Also:
        Constant Field Values
      • MARK_ALL_ON_OCCURRENCE_SEARCHES_PROPERTY

        public static final java.lang.String MARK_ALL_ON_OCCURRENCE_SEARCHES_PROPERTY
        The property fired when the "mark all on occurrence" property changes.
        See Also:
        Constant Field Values
      • MARK_ALL_OCCURRENCES_CHANGED_PROPERTY

        public static final java.lang.String MARK_ALL_OCCURRENCES_CHANGED_PROPERTY
        The property fired when what ranges are labeled "mark all" changes.
        See Also:
        Constant Field Values
      • DEFAULT_MARK_ALL_COLOR

        private static final java.awt.Color DEFAULT_MARK_ALL_COLOR
      • recordingMacro

        private static boolean recordingMacro
      • currentMacro

        private static Macro currentMacro
      • popupMenu

        private javax.swing.JPopupMenu popupMenu
        This text area's popup menu.
      • undoMenuItem

        private javax.swing.JMenuItem undoMenuItem
      • redoMenuItem

        private javax.swing.JMenuItem redoMenuItem
      • cutMenuItem

        private javax.swing.JMenuItem cutMenuItem
      • pasteMenuItem

        private javax.swing.JMenuItem pasteMenuItem
      • deleteMenuItem

        private javax.swing.JMenuItem deleteMenuItem
      • popupMenuCreated

        private boolean popupMenuCreated
        Whether the popup menu has been created.
      • selectedOccurrenceText

        private static java.lang.String selectedOccurrenceText
        The text last searched for via Ctrl+K or Ctrl+Shift+K.
      • toolTipSupplier

        private ToolTipSupplier toolTipSupplier
        Can return tool tips for this text area. Subclasses can install a supplier as a means of adding custom tool tips without subclassing RTextArea. JComponent.getToolTipText() checks this supplier before calling the super class's version.
      • iconGroup

        private static IconGroup iconGroup
      • markAllOnOccurrenceSearches

        private boolean markAllOnOccurrenceSearches
      • repTabsSB

        private static java.lang.StringBuilder repTabsSB
      • repTabsSeg

        private static javax.swing.text.Segment repTabsSeg
    • Constructor Detail

      • RTextArea

        public RTextArea()
        Constructor.
      • RTextArea

        public RTextArea​(javax.swing.text.AbstractDocument doc)
        Constructor.
        Parameters:
        doc - The document for the editor.
      • RTextArea

        public RTextArea​(java.lang.String text)
        Constructor.
        Parameters:
        text - The initial text to display.
      • RTextArea

        public RTextArea​(int rows,
                         int cols)
        Constructor.
        Parameters:
        rows - The number of rows to display.
        cols - The number of columns to display.
        Throws:
        java.lang.IllegalArgumentException - If either rows or cols is negative.
      • RTextArea

        public RTextArea​(java.lang.String text,
                         int rows,
                         int cols)
        Constructor.
        Parameters:
        text - The initial text to display.
        rows - The number of rows to display.
        cols - The number of columns to display.
        Throws:
        java.lang.IllegalArgumentException - If either rows or cols is negative.
      • RTextArea

        public RTextArea​(javax.swing.text.AbstractDocument doc,
                         java.lang.String text,
                         int rows,
                         int cols)
        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:
        java.lang.IllegalArgumentException - If either rows or cols is negative.
      • RTextArea

        public RTextArea​(int textMode)
        Creates a new RTextArea.
        Parameters:
        textMode - Either INSERT_MODE or OVERWRITE_MODE.
    • Method Detail

      • addToCurrentMacro

        static void addToCurrentMacro​(java.lang.String id,
                                      java.lang.String actionCommand)
        Adds an action event to the current macro. This shouldn't be called directly, as it is called by the actions themselves.
        Parameters:
        id - The ID of the recordable text action.
        actionCommand - The "command" of the action event passed to it.
      • addLineHighlight

        public java.lang.Object addLineHighlight​(int line,
                                                 java.awt.Color color)
                                          throws javax.swing.text.BadLocationException
        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:
        javax.swing.text.BadLocationException - If line is an invalid line number.
        See Also:
        removeLineHighlight(Object), removeAllLineHighlights()
      • 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:
        endAtomicEdit()
      • beginRecordingMacro

        public static void beginRecordingMacro()
        Begins recording a macro. After this method is called, all input/caret events, etc. are recorded until endMacroRecording is called. If this method is called but the text component is already recording a macro, nothing happens (but the macro keeps recording).
        See Also:
        isRecordingMacro(), endRecordingMacro()
      • canUndo

        public boolean canUndo()
        Returns whether an undo is possible.
        Returns:
        Whether the operation was successful.
        See Also:
        canRedo(), undoLastAction()
      • canRedo

        public boolean canRedo()
        Returns whether a redo is possible.
        Returns:
        Whether the operation was successful.
        See Also:
        canUndo(), redoLastAction()
      • configurePopupMenu

        protected void configurePopupMenu​(javax.swing.JPopupMenu popupMenu)
        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 be null.
        See Also:
        createPopupMenu(), setPopupMenu(JPopupMenu)
      • createDefaultModel

        protected javax.swing.text.Document 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:
        createDefaultModel in class javax.swing.JTextArea
        Returns:
        The default document.
      • createPopupMenuActions

        private static void createPopupMenuActions()
        Creates the actions used in the popup menu and retrievable by getAction(int). TODO: Remove these horrible hacks and move localizing of actions into the editor kits, where it should be! The context menu should contain actions from the editor kits.
      • createPopupMenuItem

        protected javax.swing.JMenuItem createPopupMenuItem​(javax.swing.Action a)
        Creates and configures a menu item for used in the popup menu.
        Parameters:
        a - The action for the menu item.
        Returns:
        The menu item.
        See Also:
        createPopupMenu()
      • createSpacer

        private java.lang.String createSpacer​(int size)
        Creates a string of space characters of the specified size.
        Parameters:
        size - The number of spaces.
        Returns:
        The string of spaces.
      • createUndoManager

        protected RUndoManager 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:
        beginAtomicEdit()
      • 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:
        isRecordingMacro(), beginRecordingMacro()
      • fireCaretUpdate

        protected void fireCaretUpdate​(javax.swing.event.CaretEvent e)
        Notifies all listeners that a caret change has occurred.
        Overrides:
        fireCaretUpdate in class javax.swing.text.JTextComponent
        Parameters:
        e - The caret event.
      • fixCtrlH

        private void fixCtrlH()
        Removes the "Ctrl+H <=> Backspace" behavior that Java shows, for some odd reason...
      • getAction

        public static RecordableTextAction getAction​(int action)
        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 all RTextAreas, 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 all RTextArea editors in your application.

        Parameters:
        action - The action to retrieve, such as CUT_ACTION. If the action name is invalid, null is returned.
        Returns:
        The action, or null if an invalid action is requested.
      • getCurrentMacro

        public static Macro getCurrentMacro()
        Returns the macro currently stored in this RTextArea. Since macros are shared, all RTextAreas in the currently running application are using this macro.
        Returns:
        The current macro, or null if no macro has been recorded/loaded.
        See Also:
        loadMacro(Macro)
      • 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

        public static IconGroup getIconGroup()
        Returns the icon group being used for the actions of this text area.
        Returns:
        The icon group.
        See Also:
        setIconGroup(IconGroup)
      • 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 is true.
        Returns:
        Whether "mark all" should be enabled.
        See Also:
        setMarkAllOnOccurrenceSearches(boolean)
      • getLineHighlightManager

        LineHighlightManager getLineHighlightManager()
        Returns the line highlight manager.
        Returns:
        The line highlight manager. This may be null.
      • getMarkAllHighlightColor

        public java.awt.Color getMarkAllHighlightColor()
        Returns the color used in "mark all" highlights.
        Returns:
        The color.
        See Also:
        setMarkAllHighlightColor(Color)
      • getMaxAscent

        public int getMaxAscent()
        Returns the maximum ascent of all fonts used in this text area. In the case of a standard RTextArea, 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

        public javax.swing.JPopupMenu getPopupMenu()
        Returns the popup menu for this component, lazily creating it if necessary.
        Returns:
        The popup menu.
        See Also:
        createPopupMenu(), setPopupMenu(JPopupMenu)
      • getSelectedOccurrenceText

        public static java.lang.String getSelectedOccurrenceText()
        Returns the text last selected and used in a Ctrl+K operation.
        Returns:
        The text, or null if none.
        See Also:
        setSelectedOccurrenceText(String)
      • getToolTipText

        public java.lang.String getToolTipText​(java.awt.event.MouseEvent e)
        Returns the tooltip to display for a mouse event at the given location. This method is overridden to check for a ToolTipSupplier; if there is one installed, it is queried for tool tip text before using the super class's implementation of this method.
        Overrides:
        getToolTipText in class javax.swing.text.JTextComponent
        Parameters:
        e - The mouse event.
        Returns:
        The tool tip text, or null if none.
        See Also:
        getToolTipSupplier(), setToolTipSupplier(ToolTipSupplier)
      • handleReplaceSelection

        protected void handleReplaceSelection​(java.lang.String content)
        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.
      • isRecordingMacro

        public static boolean isRecordingMacro()
        Returns whether a macro is being recorded.
        Returns:
        Whether a macro is being recorded.
        See Also:
        beginRecordingMacro(), endRecordingMacro()
      • loadMacro

        public static void loadMacro​(Macro macro)
        Loads a macro to be used by all RTextAreas in the current application.
        Parameters:
        macro - The macro to load.
        See Also:
        getCurrentMacro()
      • paste

        public void paste()
        Overrides:
        paste in class javax.swing.text.JTextComponent
      • playbackLastMacro

        public void playbackLastMacro()
        "Plays back" the last recorded macro in this text area.
      • print

        public int print​(java.awt.Graphics g,
                         java.awt.print.PageFormat pageFormat,
                         int pageIndex)
        Method called when it's time to print this badboy (the old-school, AWT way).
        Specified by:
        print in interface java.awt.print.Printable
        Parameters:
        g - The context into which the page is drawn.
        pageFormat - The size and orientation of the page being drawn.
        pageIndex - The zero based index of the page to be drawn.
      • processMouseEvent

        protected void processMouseEvent​(java.awt.event.MouseEvent e)
        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:
        processMouseEvent in class javax.swing.JComponent
        Parameters:
        e - The mouse event being dispatched.
      • read

        public void read​(java.io.Reader in,
                         java.lang.Object desc)
                  throws java.io.IOException
        We override this method because the super version gives us an entirely new Document, thus requiring us to re-attach our Undo manager. With this version we just replace the text.
        Overrides:
        read in class javax.swing.text.JTextComponent
        Throws:
        java.io.IOException
      • readObject

        private void readObject​(java.io.ObjectInputStream s)
                         throws java.lang.ClassNotFoundException,
                                java.io.IOException
        De-serializes a text area.
        Parameters:
        s - The stream to read from.
        Throws:
        java.lang.ClassNotFoundException - If something bad happens.
        java.io.IOException - If an IO error occurs.
      • redoLastAction

        public void redoLastAction()
        Attempt to redo the last action.
        See Also:
        undoLastAction()
      • replaceRange

        public void replaceRange​(java.lang.String str,
                                 int start,
                                 int end)
        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 RSyntaxTextArea and the "auto-indent" feature).

        Overrides:
        replaceRange in class javax.swing.JTextArea
        Parameters:
        str - the text to use as the replacement
        start - the start position >= 0
        end - the end position >= start
        Throws:
        java.lang.IllegalArgumentException - if part of the range is an invalid position in the model.
        See Also:
        JTextArea.insert(String, int), replaceRange(String, int, int)
      • replaceSelection

        public void replaceSelection​(java.lang.String text)
        This method overrides JTextComponent's replaceSelection, so that if textMode is OVERWRITE_MODE, it actually overwrites.
        Overrides:
        replaceSelection in class javax.swing.text.JTextComponent
        Parameters:
        text - The content to replace the selection with.
      • replaceTabsWithSpaces

        private java.lang.String replaceTabsWithSpaces​(java.lang.String text,
                                                       int docOffs,
                                                       int firstTab)
                                                throws javax.swing.text.BadLocationException
        Replaces all instances of the tab character in text with the number of spaces equivalent to a tab in this text area.

        This method should only be called from thread-safe methods, such as replaceSelection(String).

        Parameters:
        text - The java.lang.String in which to replace tabs with spaces. This has already been verified to have at least one tab character in it.
        docOffs - The offset in the document at which the text is being inserted.
        firstTab - The offset into text of the first tab. Assumed to be >= 0.
        Returns:
        A String just like text, but with spaces instead of tabs.
        Throws:
        javax.swing.text.BadLocationException
      • setActionProperties

        public static void setActionProperties​(int action,
                                               java.lang.String name,
                                               char mnemonic,
                                               javax.swing.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,
                                               java.lang.String name,
                                               java.lang.Integer mnemonic,
                                               javax.swing.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

        public void setCaret​(javax.swing.text.Caret caret)
        Sets the caret to use in this text area. It is strongly encouraged to use ConfigurableCarets (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:
        setCaret in class javax.swing.text.JTextComponent
        Parameters:
        caret - The caret to use.
        See Also:
        setCaretStyle(int, CaretStyle)
      • setDocument

        public void setDocument​(javax.swing.text.Document document)
        Sets the document used by this text area.
        Overrides:
        setDocument in class javax.swing.text.JTextComponent
        Parameters:
        document - The new document to use.
        Throws:
        java.lang.IllegalArgumentException - If the document is not an instance of RDocument.
      • setIconGroup

        public static void setIconGroup​(IconGroup group)
        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
        If any of the above images don't exist, the corresponding action will not have an icon.
        Parameters:
        group - The icon group to load.
        See Also:
        getIconGroup()
      • setMarkAllHighlightColor

        public void setMarkAllHighlightColor​(java.awt.Color color)
        Sets the color used for "mark all." This fires a property change of type MARK_ALL_COLOR_PROPERTY.
        Parameters:
        color - The color to use for "mark all."
        See Also:
        getMarkAllHighlightColor()
      • 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 is true.

        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:
        getMarkAllOnOccurrenceSearches()
      • setPopupMenu

        public void setPopupMenu​(javax.swing.JPopupMenu popupMenu)
        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 is null, no popup menu will be displayed.
        See Also:
        getPopupMenu(), configurePopupMenu(JPopupMenu)
      • setSelectedOccurrenceText

        public static void setSelectedOccurrenceText​(java.lang.String text)
        Sets the text last selected/Ctrl+K'd in an RTextArea. 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:
        getSelectedOccurrenceText()
      • setTextMode

        public void setTextMode​(int mode)
        Sets the text mode for this editor pane. If the currently installed caret is an instance of ConfigurableCaret, it will be automatically updated to render itself appropriately for the new text mode.
        Parameters:
        mode - Either INSERT_MODE or OVERWRITE_MODE.
        See Also:
        getTextMode()
      • setToolTipSupplier

        public void setToolTipSupplier​(ToolTipSupplier supplier)
        Sets the tool tip supplier.
        Parameters:
        supplier - The new tool tip supplier, or null if there is to be no supplier.
        See Also:
        getToolTipSupplier()
      • setUI

        public final void setUI​(javax.swing.plaf.TextUI ui)
        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 an RTextArea is independent of the Java Look and Feel, and so this method does not change the text area itself. Subclasses (such as RSyntaxTextArea) can call setRTextAreaUI if they wish to install a new UI.
        Overrides:
        setUI in class javax.swing.text.JTextComponent
        Parameters:
        ui - This parameter is ignored.
      • undoLastAction

        public void undoLastAction()
        Attempt to undo an "action" done in this text area.
        See Also:
        redoLastAction()
      • writeObject

        private void writeObject​(java.io.ObjectOutputStream s)
                          throws java.io.IOException
        Serializes this text area.
        Parameters:
        s - The stream to write to.
        Throws:
        java.io.IOException - If an IO error occurs.