Class TextAreaPainter

  • All Implemented Interfaces:
    java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.swing.text.TabExpander

    public class TextAreaPainter
    extends javax.swing.JComponent
    implements javax.swing.text.TabExpander
    The text area repaint manager. It performs double buffering and paints lines of text.
    See Also:
    Serialized Form
    • Nested Class Summary

      • 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
    • Field Summary

      • Fields inherited from class javax.swing.JComponent

        listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
      • Fields inherited from class java.awt.Component

        accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
      • Fields inherited from interface java.awt.image.ImageObserver

        ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getCurrentLineIndex()
      Returns the currently painted line.
      int getDefaultCharWidth()
      This works only for fonts with fixed line height.
      int getFirstLine()
      Returns the line displayed at the text area's origin.
      @Nullable java.awt.FontMetrics getFontMetrics()
      Returns the font metrics used by this component.
      int getHorizontalOffset()
      Returns the horizontal offset of drawn lines.
      @NotNull java.awt.Dimension getMinimumSize()  
      @NotNull java.awt.Dimension getPreferredSize()  
      @NotNull SyntaxStyles getStyles()
      Returns the syntax styles used to paint colorized text.
      int getVisibleLines()  
      void invalidateLine​(int line)
      Marks a line as needing a repaint.
      void invalidateLineRange​(int firstLine, int lastLine)
      Marks a range of lines as needing a repaint.
      void invalidateSelectedLines()
      Repaints the lines containing the selection.
      boolean isBlockCaretEnabled()
      Returns whether the caret should be drawn as a block.
      boolean isBracketHighlightEnabled()
      Returns whether bracket highlighting is enabled.
      int lineToY​(int line)
      Converts a line index to a y co-ordinate.
      float nextTabStop​(float x, int tabOffset)  
      int offsetToX​(int line, int offset)
      Converts an offset in a line into an x co-ordinate.
      int offsetToX2​(int line, int offset)
      Converts an offset in a line into an x co-ordinate.
      void paint​(@NotNull java.awt.Graphics g)
      Repaints the text.
      void recalculateVisibleLines()
      Recalculates the number of visible lines.
      void setCurrentLineIndex​(int lineIndex)
      Sets the currently painted line.
      boolean setFirstLine​(int firstLine)  
      void setFont​(@NotNull java.awt.Font font)  
      boolean setHorizontalOffset​(int horizontalOffset)  
      void setStyles​(@NotNull SyntaxStyles styles)
      Sets the syntax styles used to paint colorized text.
      int xToOffset​(int line, int x)
      Converts a x co-ordinate to an offset within a line.
      int xyToOffset​(int x, int y)
      Converts a point to an offset, from the start of the text.
      int yToLine​(int y)
      Converts a y co-ordinate to a line index.
      • Methods inherited from class javax.swing.JComponent

        addAncestorListener, addNotify, 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, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUI, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
      • 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, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, 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, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, 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
    • Constructor Detail

      • TextAreaPainter

        public TextAreaPainter​(@NotNull
                               @NotNull JEditTextArea textArea,
                               @NotNull
                               @NotNull TextAreaSelection selection,
                               @NotNull
                               @NotNull TextAreaCaret caret,
                               @NotNull
                               @NotNull TextAreaDefaults defaults,
                               @NotNull
                               @NotNull TextAreaBrackets brackets,
                               @NotNull
                               @NotNull TextAreaConfig config,
                               boolean paintInvalid)
        Creates a new repaint manager. This should be not be called directly.
        Parameters:
        textArea - the associated text area that is painted
        defaults - the text attributes to use
        brackets - the brackets to paint
        config - the text area configuration options to use
        paintInvalid - whether invalid lines should be painted as red tildes
    • Method Detail

      • getDefaultCharWidth

        public int getDefaultCharWidth()
        This works only for fonts with fixed line height. It's sort of hack to avoid the use of deprecated methods.
        Returns:
        default line height in pixels
      • getStyles

        @NotNull
        public @NotNull SyntaxStyles getStyles()
        Returns the syntax styles used to paint colorized text.
        Returns:
        the styles
        See Also:
        Token
      • setStyles

        public void setStyles​(@NotNull
                              @NotNull SyntaxStyles styles)
        Sets the syntax styles used to paint colorized text.
        Parameters:
        styles - the syntax styles
        See Also:
        Token
      • isBracketHighlightEnabled

        public boolean isBracketHighlightEnabled()
        Returns whether bracket highlighting is enabled. When bracket highlighting is enabled, the bracket matching the one before the caret (if any) is highlighted.
        Returns:
        whether bracket highlighting is enabled
      • isBlockCaretEnabled

        public boolean isBlockCaretEnabled()
        Returns whether the caret should be drawn as a block.
        Returns:
        whether the caret should be drawn as a block
      • getFontMetrics

        @Nullable
        public @Nullable java.awt.FontMetrics getFontMetrics()
        Returns the font metrics used by this component.
        Returns:
        the font metrics
      • setFont

        public final void setFont​(@NotNull
                                  @NotNull java.awt.Font font)
        Overrides:
        setFont in class javax.swing.JComponent
      • paint

        public void paint​(@NotNull
                          @NotNull java.awt.Graphics g)
        Repaints the text.
        Overrides:
        paint in class javax.swing.JComponent
        Parameters:
        g - the graphics context
      • invalidateLine

        public void invalidateLine​(int line)
        Marks a line as needing a repaint.
        Parameters:
        line - the line to invalidate
      • invalidateLineRange

        public void invalidateLineRange​(int firstLine,
                                        int lastLine)
        Marks a range of lines as needing a repaint.
        Parameters:
        firstLine - the first line to invalidate
        lastLine - the last line to invalidate
      • invalidateSelectedLines

        public void invalidateSelectedLines()
        Repaints the lines containing the selection.
      • nextTabStop

        public float nextTabStop​(float x,
                                 int tabOffset)
        Specified by:
        nextTabStop in interface javax.swing.text.TabExpander
      • getPreferredSize

        @NotNull
        public @NotNull java.awt.Dimension getPreferredSize()
        Overrides:
        getPreferredSize in class javax.swing.JComponent
      • getMinimumSize

        @NotNull
        public @NotNull java.awt.Dimension getMinimumSize()
        Overrides:
        getMinimumSize in class javax.swing.JComponent
      • getCurrentLineIndex

        public int getCurrentLineIndex()
        Returns the currently painted line.
        Returns:
        the line index
      • setCurrentLineIndex

        public void setCurrentLineIndex​(int lineIndex)
        Sets the currently painted line.
        Parameters:
        lineIndex - the line index
      • recalculateVisibleLines

        public void recalculateVisibleLines()
        Recalculates the number of visible lines. This should not be called directly.
      • getVisibleLines

        public int getVisibleLines()
      • getFirstLine

        public int getFirstLine()
        Returns the line displayed at the text area's origin.
      • setFirstLine

        public boolean setFirstLine​(int firstLine)
      • lineToY

        public int lineToY​(int line)
        Converts a line index to a y co-ordinate.
        Parameters:
        line - the line
      • getHorizontalOffset

        public int getHorizontalOffset()
        Returns the horizontal offset of drawn lines.
      • setHorizontalOffset

        public boolean setHorizontalOffset​(int horizontalOffset)
      • offsetToX2

        public int offsetToX2​(int line,
                              int offset)
        Converts an offset in a line into an x co-ordinate. This is a fast version that should only be used if no changes were made to the text since the last repaint.
        Parameters:
        line - the line
        offset - the offset, from the start of the line
      • offsetToX

        public int offsetToX​(int line,
                             int offset)
        Converts an offset in a line into an x co-ordinate. This is a slow version that can be used any time.
        Parameters:
        line - the line
        offset - the offset, from the start of the line
      • yToLine

        public int yToLine​(int y)
        Converts a y co-ordinate to a line index.
        Parameters:
        y - the y co-ordinate
      • xToOffset

        public int xToOffset​(int line,
                             int x)
        Converts a x co-ordinate to an offset within a line.
        Parameters:
        line - the line
        x - the x co-ordinate
      • xyToOffset

        public int xyToOffset​(int x,
                              int y)
        Converts a point to an offset, from the start of the text.
        Parameters:
        x - the x co-ordinate of the point
        y - the y co-ordinate of the point