Package: groovy.console.ui.text

## [Java] Class TextEditor

- groovy.console.ui.text.TextEditor

- All Implemented Interfaces and Traits:
    Pageable, Printable

      public class TextEditor
      extends JTextPane
      implements Pageable, Printable

  A simple text pane that is printable and wrapping is optional.

- - ### Field Summary

    Fields
    Modifiers | Name | Description
    --- | --- | ---
    `static String` | `AUTO_INDENT` | Action name for automatic indentation.
    `static String` | `DELETE` | Action name for backspace deletion.
    `static String` | `FIND` | Action name for opening the find dialog.
    `static String` | `FIND_NEXT` | Action name for repeating the next find.
    `static String` | `FIND_PREVIOUS` | Action name for repeating the previous find.
    `static String` | `REPLACE` | Action name for opening the replace dialog.

  - Inherited fields
    Fields inherited from class | Fields
    --- | ---
    `class JTextPane` | `W3C_LENGTH_UNITS, HONOR_DISPLAY_PROPERTIES, FOCUS_ACCELERATOR_KEY, DEFAULT_KEYMAP, WHEN_FOCUSED, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_IN_FOCUSED_WINDOW, UNDEFINED_CONDITION, TOOL_TIP_TEXT_KEY, TOP_ALIGNMENT, CENTER_ALIGNMENT, BOTTOM_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, WIDTH, HEIGHT, PROPERTIES, SOMEBITS, FRAMEBITS, ALLBITS, ERROR, ABORT`

  - ### Constructor Summary

    Constructors
    Constructor and description
    `TextEditor()` Creates a new instance of TextEditor
    `TextEditor(boolean tabsAsSpaces)` Creates a new instance of TextEditor
    `TextEditor(boolean tabsAsSpaces, boolean multiLineTab)` Creates a new instance of TextEditor
    `TextEditor(boolean tabsAsSpaces, boolean multiLineTab, boolean unwrapped)` Creates a new instance of TextEditor

  - ### Methods Summary

    Methods
    Type Params | Return Type | Name and description
    --- | --- | ---
    `` | `public void` | `addNotify()` Notifies this component that it now has a parent component. When this method is invoked, the chain of parent components is set up with `KeyboardAction` event listeners. This method is called by the toolkit internally and should not be called directly by programs. See Also: registerKeyboardAction
    `` | `public int` | `getNumberOfPages()` Returns the number of pages in the set. To enable advanced printing features, it is recommended that `Pageable` implementations return the true number of pages rather than the UNKNOWN_NUMBER_OF_PAGES constant. Returns: the number of pages in this `Pageable`.
    `` | `public PageFormat` | `getPageFormat(int pageIndex)` Returns the `PageFormat` of the page specified by `pageIndex`. throws: IndexOutOfBoundsException if the `Pageable` does not contain the requested page. Parameters: `pageIndex` - the zero based index of the page whose `PageFormat` is being requested Returns: the `PageFormat` describing the size and orientation.
    `` | `public Printable` | `getPrintable(int param)` Returns the `Printable` instance responsible for rendering the page specified by `pageIndex`. throws: IndexOutOfBoundsException if the `Pageable` does not contain the requested page. Parameters: `pageIndex` - the zero based index of the page whose `Printable` is being requested Returns: the `Printable` that renders the page.
    `` | `public boolean` | `getScrollableTracksViewportWidth()` Returns true if a viewport should always force the width of this `Scrollable` to match the width of the viewport. Returns: true if a viewport should force the Scrollables width to match its own, false otherwise
    `` | `public boolean` | `isMultiLineTabbed()` Whether using the tab key indents the selected lines of code
    `` | `public void` | `isMultiLineTabbed(boolean multiLineTab)` Enables or disables indenting all selected lines when tabbing.
    `` | `public static boolean` | `isOvertypeMode()` Returns: true if overtype mode is active, false for insert mode
    `` | `public boolean` | `isTabsAsSpaces()` Returns: true if tabs are converted to spaces upon typing
    `` | `public void` | `isTabsAsSpaces(boolean tabsAsSpaces)` Enables or disables replacing typed tab characters with spaces.
    `` | `public boolean` | `isUnwrapped()` Returns: true if text wrapping is disabled
    `` | `public int` | `print(Graphics graphics, PageFormat pageFormat, int page)` Prints the page at the specified index into the specified Graphics context in the specified format. A `PrinterJob` calls the `Printable` interface to request that a page be rendered into the context specified by `graphics`. The format of the page to be drawn is specified by `pageFormat`. The zero based index of the requested page is specified by `pageIndex`. If the requested page does not exist then this method returns NO_SUCH_PAGE; otherwise PAGE_EXISTS is returned. The `Graphics` class or subclass implements the PrinterGraphics interface to provide additional information. If the `Printable` object aborts the print job then it throws a PrinterException. Parameters: `graphics` - 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 Returns: PAGE_EXISTS if the page is rendered successfully or NO_SUCH_PAGE if `pageIndex` specifies a non-existent page. Throws: java.awt.print.PrinterException thrown when the print job is terminated.
    `` | `protected void` | `processKeyEvent(KeyEvent e)` Overrides `processKeyEvent` to process events. *
    `` | `public void` | `removeNotify()`
    `` | `public void` | `replaceSelection(String text)` Replaces the currently selected content with new content represented by the given string. If there is no selection this amounts to an insert of the given text. If there is no replacement text this amounts to a removal of the current selection. The replacement text will have the attributes currently defined for input at the point of insertion. If the document is not editable, beep and return. Parameters: `content` - the content to replace the selection with
    `` | `public void` | `setBounds(int x, int y, int width, int height)` Moves and resizes this component. The new location of the top-left corner is specified by `x` and `y`, and the new size is specified by `width` and `height`. This method changes layout-related information, and therefore, invalidates the component hierarchy. Parameters: `x` - the new x-coordinate of this component `y` - the new y-coordinate of this component `width` - the new `width` of this component `height` - the new `height` of this component See Also: getBounds setLocation(int, int) setLocation(Point) setSize(int, int) setSize(Dimension) invalidate Since: 1.1
    `` | `public void` | `setOvertypeMode(boolean isOvertypeMode)` Set the caret to use depending on overtype/insert mode
    `` | `public void` | `setUnwrapped(boolean unwrapped)` Parameters: `unwrapped` - the new unwrapped value

  - ### Inherited Methods Summary

    Inherited Methods
    Methods inherited from class | Name
    --- | ---
    `class JTextPane` | `action, add, add, add, add, add, add, addAncestorListener, addCaretListener, addComponentListener, addContainerListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addHyperlinkListener, addInputMethodListener, addKeyListener, addKeymap, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addStyle, addVetoableChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, computeVisibleRect, contains, contains, copy, countComponents, createEditorKitForContentType, createImage, createImage, createToolTip, createVolatileImage, createVolatileImage, cut, deliverEvent, disable, dispatchEvent, doLayout, enable, enable, enableInputMethods, equals, findComponentAt, findComponentAt, fireHyperlinkUpdate, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getActions, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBackground, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getBounds, getCaret, getCaretColor, getCaretListeners, getCaretPosition, getCharacterAttributes, getClass, getClientProperty, getColorModel, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponentListeners, getComponentOrientation, getComponentPopupMenu, getComponentZOrder, getComponents, getConditionForKeyStroke, getContainerListeners, getContentType, getCursor, getDebugGraphicsOptions, getDefaultLocale, getDisabledTextColor, getDocument, getDragEnabled, getDropLocation, getDropMode, getDropTarget, getEditorKit, getEditorKitClassNameForContentType, getEditorKitForContentType, getFocusAccelerator, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFocusTraversalPolicy, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getHighlighter, getHyperlinkListeners, getIgnoreRepaint, getInheritsPopupMenu, getInputAttributes, getInputContext, getInputMap, getInputMap, getInputMethodListeners, getInputMethodRequests, getInputVerifier, getInsets, getInsets, getKeyListeners, getKeymap, getKeymap, getLayout, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getLogicalStyle, getMargin, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMousePosition, getMouseWheelListeners, getName, getNavigationFilter, getNextFocusableComponent, getPage, getParagraphAttributes, getParent, getPopupLocation, getPreferredScrollableViewportSize, getPreferredSize, getPrintable, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getScrollableBlockIncrement, getScrollableTracksViewportHeight, getScrollableTracksViewportWidth, getScrollableUnitIncrement, getSelectedText, getSelectedTextColor, getSelectionColor, getSelectionEnd, getSelectionStart, getSize, getSize, getStyle, getStyledDocument, getText, getText, getToolTipLocation, getToolTipText, getToolTipText, getToolkit, getTopLevelAncestor, getTransferHandler, getTreeLock, getUI, getUI, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, gotFocus, grabFocus, handleEvent, hasFocus, hashCode, hide, imageUpdate, insertComponent, insertIcon, insets, inside, invalidate, isAncestorOf, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEditable, isEnabled, isFocusCycleRoot, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, isFocusable, isFontSet, isForegroundSet, isLightweight, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isShowing, isValid, isValidateRoot, isVisible, keyDown, keyUp, layout, list, list, list, list, list, loadKeymap, locate, location, lostFocus, minimumSize, modelToView, modelToView2D, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, moveCaretPosition, nextFocus, notify, notifyAll, paint, paintAll, paintComponents, paintImmediately, paintImmediately, paste, postEvent, preferredSize, prepareImage, prepareImage, print, print, print, print, printAll, printComponents, putClientProperty, read, read, registerEditorKitForContentType, registerEditorKitForContentType, registerKeyboardAction, registerKeyboardAction, remove, remove, remove, removeAll, removeAncestorListener, removeCaretListener, removeComponentListener, removeContainerListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeHyperlinkListener, removeInputMethodListener, removeKeyListener, removeKeymap, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeStyle, removeVetoableChangeListener, repaint, repaint, repaint, repaint, repaint, replaceSelection, requestDefaultFocus, requestFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, resize, resize, revalidate, scrollRectToVisible, scrollToReference, select, selectAll, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setBounds, setBounds, setCaret, setCaretColor, setCaretPosition, setCharacterAttributes, setComponentOrientation, setComponentPopupMenu, setComponentZOrder, setContentType, setCursor, setDebugGraphicsOptions, setDefaultLocale, setDisabledTextColor, setDocument, setDoubleBuffered, setDragEnabled, setDropMode, setDropTarget, setEditable, setEditorKit, setEditorKitForContentType, setEnabled, setFocusAccelerator, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFocusable, setFont, setForeground, setHighlighter, setIgnoreRepaint, setInheritsPopupMenu, setInputMap, setInputVerifier, setKeymap, setLayout, setLocale, setLocation, setLocation, setLogicalStyle, setMargin, setMaximumSize, setMinimumSize, setMixingCutoutShape, setName, setNavigationFilter, setNextFocusableComponent, setOpaque, setPage, setPage, setParagraphAttributes, setPreferredSize, setRequestFocusEnabled, setSelectedTextColor, setSelectionColor, setSelectionEnd, setSelectionStart, setSize, setSize, setStyledDocument, setText, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusDownCycle, transferFocusUpCycle, unregisterKeyboardAction, update, updateUI, validate, viewToModel, viewToModel2D, wait, wait, wait, write`

- - ### Field Detail

    - #### public static final String AUTO_INDENT

      Action name for automatic indentation.

    - #### public static final String DELETE

      Action name for backspace deletion.

    - #### public static final String FIND

      Action name for opening the find dialog.

    - #### public static final String FIND_NEXT

      Action name for repeating the next find.

    - #### public static final String FIND_PREVIOUS

      Action name for repeating the previous find.

    - #### public static final String REPLACE

      Action name for opening the replace dialog.

  - ### Constructor Detail

    - #### public TextEditor()

      Creates a new instance of TextEditor

    - #### public TextEditor(boolean tabsAsSpaces)

      Creates a new instance of TextEditor

      Parameters:
        `tabsAsSpaces` - whether typed tabs should be converted to spaces

    - #### public TextEditor(boolean tabsAsSpaces, boolean multiLineTab)

      Creates a new instance of TextEditor

      Parameters:
        `tabsAsSpaces` - whether typed tabs should be converted to spaces
        `multiLineTab` - whether tab actions should affect all selected lines

    - #### public TextEditor(boolean tabsAsSpaces, boolean multiLineTab, boolean unwrapped)

      Creates a new instance of TextEditor

      Parameters:
        `tabsAsSpaces` - whether typed tabs should be converted to spaces
        `multiLineTab` - whether tab actions should affect all selected lines
        `unwrapped` - whether long lines should avoid viewport wrapping

  - ### Method Detail

    - #### public void addNotify()

      Notifies this component that it now has a parent component. When this method is invoked, the chain of parent components is set up with `KeyboardAction` event listeners. This method is called by the toolkit internally and should not be called directly by programs.

      See Also:
        registerKeyboardAction

    - #### public int getNumberOfPages()

      Returns the number of pages in the set. To enable advanced printing features, it is recommended that `Pageable` implementations return the true number of pages rather than the UNKNOWN_NUMBER_OF_PAGES constant.

      Returns:
        the number of pages in this `Pageable`.

    - #### public PageFormat getPageFormat(int pageIndex)

      Returns the `PageFormat` of the page specified by `pageIndex`.

      throws:
        IndexOutOfBoundsException if the `Pageable` does not contain the requested page.
      Parameters:
        `pageIndex` - the zero based index of the page whose `PageFormat` is being requested
      Returns:
        the `PageFormat` describing the size and orientation.

    - #### public Printable getPrintable(int param)

      Returns the `Printable` instance responsible for rendering the page specified by `pageIndex`.

      throws:
        IndexOutOfBoundsException if the `Pageable` does not contain the requested page.
      Parameters:
        `pageIndex` - the zero based index of the page whose `Printable` is being requested
      Returns:
        the `Printable` that renders the page.

    - #### public boolean getScrollableTracksViewportWidth()

      Returns true if a viewport should always force the width of this `Scrollable` to match the width of the viewport.

      Returns:
        true if a viewport should force the Scrollables width to match its own, false otherwise

    - #### public boolean isMultiLineTabbed()

      Whether using the tab key indents the selected lines of code

      Returns:
        true if multiline tabbing is active

    - #### public void isMultiLineTabbed(boolean multiLineTab)

      Enables or disables indenting all selected lines when tabbing.

      Parameters:
        `multiLineTab` - the new multiLine tab value

    - #### public static boolean isOvertypeMode()

      Returns:
        true if overtype mode is active, false for insert mode

    - #### public boolean isTabsAsSpaces()

      Returns:
        true if tabs are converted to spaces upon typing

    - #### public void isTabsAsSpaces(boolean tabsAsSpaces)

      Enables or disables replacing typed tab characters with spaces.

      Parameters:
        `tabsAsSpaces` - whether tabs are converted to spaces

    - #### public boolean isUnwrapped()

      Returns:
        true if text wrapping is disabled

    - #### public int print(Graphics graphics, PageFormat pageFormat, int page)

      Prints the page at the specified index into the specified Graphics context in the specified format. A `PrinterJob` calls the `Printable` interface to request that a page be rendered into the context specified by `graphics`. The format of the page to be drawn is specified by `pageFormat`. The zero based index of the requested page is specified by `pageIndex`. If the requested page does not exist then this method returns NO_SUCH_PAGE; otherwise PAGE_EXISTS is returned. The `Graphics` class or subclass implements the PrinterGraphics interface to provide additional information. If the `Printable` object aborts the print job then it throws a PrinterException.

      Parameters:
        `graphics` - 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
      Returns:
        PAGE_EXISTS if the page is rendered successfully or NO_SUCH_PAGE if `pageIndex` specifies a non-existent page.
      Throws:
        java.awt.print.PrinterException thrown when the print job is terminated.

    - #### protected void processKeyEvent(KeyEvent e)

      Overrides `processKeyEvent` to process events. *

    - #### public void removeNotify()

    - #### public void replaceSelection(String text)

      Replaces the currently selected content with new content represented by the given string. If there is no selection this amounts to an insert of the given text. If there is no replacement text this amounts to a removal of the current selection. The replacement text will have the attributes currently defined for input at the point of insertion. If the document is not editable, beep and return.

      Parameters:
        `content` - the content to replace the selection with

    - #### public void setBounds(int x, int y, int width, int height)

      Moves and resizes this component. The new location of the top-left corner is specified by `x` and `y`, and the new size is specified by `width` and `height`.

      This method changes layout-related information, and therefore, invalidates the component hierarchy.

      Parameters:
        `x` - the new x-coordinate of this component
        `y` - the new y-coordinate of this component
        `width` - the new `width` of this component
        `height` - the new `height` of this component
      See Also:
        getBounds
        setLocation(int, int)
        setLocation(Point)
        setSize(int, int)
        setSize(Dimension)
        invalidate
      Since:
        1.1

    - #### public void setOvertypeMode(boolean isOvertypeMode)

      Set the caret to use depending on overtype/insert mode

      Parameters:
        `isOvertypeMode` - the new mode; true = overtype

    - #### public void setUnwrapped(boolean unwrapped)

      Parameters:
        `unwrapped` - the new unwrapped value