Class TextAreaPainter

java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
mars.venus.editor.jeditsyntax.TextAreaPainter
All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, TabExpander

public class TextAreaPainter extends JComponent implements TabExpander
The text area repaint manager. It performs double buffering and paints lines of text.
Version:
$Id: TextAreaPainter.java,v 1.24 1999/12/13 03:40:30 sp Exp $
Author:
Slava Pestov
See Also:
  • Field Details

    • textArea

      protected JEditTextArea textArea
    • styles

      protected SyntaxStyle[] styles
    • caretForeground

      protected Color caretForeground
    • selectionBackground

      protected Color selectionBackground
    • lineHighlightColor

      protected Color lineHighlightColor
    • bracketHighlightColor

      protected Color bracketHighlightColor
    • eolMarkerColor

      protected Color eolMarkerColor
    • blockCaret

      protected boolean blockCaret
    • lineHighlight

      protected boolean lineHighlight
    • bracketHighlight

      protected boolean bracketHighlight
    • paintInvalid

      protected boolean paintInvalid
    • eolMarkers

      protected boolean eolMarkers
    • cols

      protected int cols
    • rows

      protected int rows
    • tabSize

      protected int tabSize
    • tabSizeChars

      protected int tabSizeChars
    • fontMetrics

      protected FontMetrics fontMetrics
    • highlights

      protected TextAreaPainter.Highlight highlights
  • Constructor Details

    • TextAreaPainter

      public TextAreaPainter(JEditTextArea textArea, TextAreaDefaults defaults)
      Creates a new repaint manager. This should be not be called directly.
  • Method Details

    • getTabSize

      public int getTabSize()
      Fetch the tab size in characters. DPS 12-May-2010.
      Returns:
      int tab size in characters
    • setTabSize

      public void setTabSize(int size)
      Set the tab size in characters. DPS 12-May-2010. Originally it was fixed at PlainDocument property value (8).
      Parameters:
      size - tab size in characters
    • getStyles

      public final SyntaxStyle[] getStyles()
      Returns the syntax styles used to paint colorized text. Entry n will be used to paint tokens with id = n.
      See Also:
    • setStyles

      public final void setStyles(SyntaxStyle[] styles)
      Sets the syntax styles used to paint colorized text. Entry n will be used to paint tokens with id = n.
      Parameters:
      styles - The syntax styles
      See Also:
    • getCaretForeground

      public final Color getCaretForeground()
      Returns the caret color.
    • setCaretForeground

      public final void setCaretForeground(Color caretForeground)
      Sets the caret color.
      Parameters:
      caretForeground - The caret color
    • getSelectionBackground

      public final Color getSelectionBackground()
      Returns the selection color.
    • setSelectionBackground

      public final void setSelectionBackground(Color selectionBackground)
      Sets the selection color.
      Parameters:
      selectionBackground - The selection color
    • getLineHighlightColor

      public final Color getLineHighlightColor()
      Returns the line highlight color.
    • setLineHighlightColor

      public final void setLineHighlightColor(Color lineHighlightColor)
      Sets the line highlight color.
      Parameters:
      lineHighlightColor - The line highlight color
    • isLineHighlightEnabled

      public final boolean isLineHighlightEnabled()
      Returns true if line highlight is enabled, false otherwise.
    • setLineHighlightEnabled

      public final void setLineHighlightEnabled(boolean lineHighlight)
      Enables or disables current line highlighting.
      Parameters:
      lineHighlight - True if current line highlight should be enabled, false otherwise
    • getBracketHighlightColor

      public final Color getBracketHighlightColor()
      Returns the bracket highlight color.
    • setBracketHighlightColor

      public final void setBracketHighlightColor(Color bracketHighlightColor)
      Sets the bracket highlight color.
      Parameters:
      bracketHighlightColor - The bracket highlight color
    • isBracketHighlightEnabled

      public final boolean isBracketHighlightEnabled()
      Returns true if bracket highlighting is enabled, false otherwise. When bracket highlighting is enabled, the bracket matching the one before the caret (if any) is highlighted.
    • setBracketHighlightEnabled

      public final void setBracketHighlightEnabled(boolean bracketHighlight)
      Enables or disables bracket highlighting. When bracket highlighting is enabled, the bracket matching the one before the caret (if any) is highlighted.
      Parameters:
      bracketHighlight - True if bracket highlighting should be enabled, false otherwise
    • isBlockCaretEnabled

      public final boolean isBlockCaretEnabled()
      Returns true if the caret should be drawn as a block, false otherwise.
    • setBlockCaretEnabled

      public final void setBlockCaretEnabled(boolean blockCaret)
      Sets if the caret should be drawn as a block, false otherwise.
      Parameters:
      blockCaret - True if the caret should be drawn as a block, false otherwise.
    • getEOLMarkerColor

      public final Color getEOLMarkerColor()
      Returns the EOL marker color.
    • setEOLMarkerColor

      public final void setEOLMarkerColor(Color eolMarkerColor)
      Sets the EOL marker color.
      Parameters:
      eolMarkerColor - The EOL marker color
    • getEOLMarkersPainted

      public final boolean getEOLMarkersPainted()
      Returns true if EOL markers are drawn, false otherwise.
    • setEOLMarkersPainted

      public final void setEOLMarkersPainted(boolean eolMarkers)
      Sets if EOL markers are to be drawn.
      Parameters:
      eolMarkers - True if EOL markers should be drawn, false otherwise
    • getInvalidLinesPainted

      public boolean getInvalidLinesPainted()
      Returns true if invalid lines are painted as red tildes (~), false otherwise.
    • setInvalidLinesPainted

      public void setInvalidLinesPainted(boolean paintInvalid)
      Sets if invalid lines are to be painted as red tildes.
      Parameters:
      paintInvalid - True if invalid lines should be drawn, false otherwise
    • addCustomHighlight

      public void addCustomHighlight(TextAreaPainter.Highlight highlight)
      Adds a custom highlight painter.
      Parameters:
      highlight - The highlight
    • getToolTipText

      public String getToolTipText(MouseEvent event)
      Returns the tool tip to display at the specified location.
      Overrides:
      getToolTipText in class JComponent
      Parameters:
      event - The mouse event
    • getFontMetrics

      public FontMetrics getFontMetrics()
      Returns the font metrics used by this component.
    • setFont

      public void setFont(Font font)
      Sets the font for this component. This is overridden to update the cached font metrics and to recalculate which lines are visible.
      Overrides:
      setFont in class JComponent
      Parameters:
      font - The font
    • paint

      public void paint(Graphics graphics)
      Repaints the text.
      Overrides:
      paint in class JComponent
      Parameters:
      graphics - The graphics context
    • invalidateLine

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

      public final 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 final void invalidateSelectedLines()
      Repaints the lines containing the selection.
    • nextTabStop

      public float nextTabStop(float x, int tabOffset)
      Implementation of TabExpander interface. Returns next tab stop after a specified point.
      Specified by:
      nextTabStop in interface TabExpander
      Parameters:
      x - The x coordinate.
      tabOffset - Ignored.
      Returns:
      The next tab stop after x.
    • getPreferredSize

      public Dimension getPreferredSize()
      Returns the painter's preferred size.
      Overrides:
      getPreferredSize in class JComponent
    • getMinimumSize

      public Dimension getMinimumSize()
      Returns the painter's minimum size.
      Overrides:
      getMinimumSize in class JComponent
    • paintLine

      protected void paintLine(Graphics graphics, TokenMarker tokenMarker, int line, float x)
    • paintPlainLine

      protected void paintPlainLine(Graphics graphics, int line, Font defaultFont, Color defaultColor, float x, float y)
    • paintSyntaxLine

      protected void paintSyntaxLine(Graphics graphics, TokenMarker tokenMarker, int line, Font defaultFont, Color defaultColor, float x, float y)
    • paintHighlight

      protected void paintHighlight(Graphics graphics, int line, float y)
    • paintLineHighlight

      protected void paintLineHighlight(Graphics graphics, int line, float y)
    • paintBracketHighlight

      protected void paintBracketHighlight(Graphics graphics, int line, float y)
    • paintCaret

      protected void paintCaret(Graphics graphics, int line, float y)
    • updateUI

      public void updateUI()
      Overrides:
      updateUI in class JComponent