Class LineNumberList

All Implemented Interfaces:
MouseListener, MouseMotionListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible, MouseInputListener

public class LineNumberList extends JPanel implements MouseInputListener
Renders line numbers in the gutter.
Version:
1.0
Author:
Robert Futrell
See Also:
  • Field Details

    • DEFAULT_LINE_NUMBER_COLOR

      public static final Color DEFAULT_LINE_NUMBER_COLOR
    • DEFAULT_LINE_NUMBER_FORMATTER

      public static final LineNumberFormatter DEFAULT_LINE_NUMBER_FORMATTER
    • textArea

      protected RTextArea textArea
      The text area whose lines we are marking with icons.
    • currentLineCount

      protected int currentLineCount
      The number of lines in the text area.
  • Constructor Details

    • LineNumberList

      public LineNumberList(RTextArea textArea)
      Constructs a new LineNumberList using default values for line number color (gray) and highlighting the current line.
      Parameters:
      textArea - The text component for which line numbers will be displayed.
    • LineNumberList

      public LineNumberList(RTextArea textArea, Color numberColor)
      Constructs a new LineNumberList.
      Parameters:
      textArea - The text component for which line numbers will be displayed.
      numberColor - The color to use for the line numbers. If this is null, gray will be used.
    • LineNumberList

      public LineNumberList(RTextArea textArea, Color numberColor, Color currentLineNumberColor)
      Constructs a new LineNumberList.
      Parameters:
      textArea - The text component for which line numbers will be displayed.
      numberColor - The color to use for the line numbers. If this is null, gray will be used.
      currentLineNumberColor - The color to use for the current line number. If this is null, the current line's number will not have a special color.
  • Method Details

    • addNotify

      public void addNotify()
      Overridden to set width of this component correctly when we are first displayed (as keying off of the RTextArea gives us (0,0) when it isn't yet displayed.
    • getCurrentLineNumberColor

      public Color getCurrentLineNumberColor()
      Returns the color to use when painting the current line's line number.
      Returns:
      The color to use when painting the current line's line number. If this is null, the regular line number color will be used.
      See Also:
    • getLineNumberingStartIndex

      public int getLineNumberingStartIndex()
      Returns the starting line's line number. The default value is 1.
      Returns:
      The index
      See Also:
    • getLineNumberFormatter

      public LineNumberFormatter getLineNumberFormatter()
      Returns the line number formatter. The default value is DEFAULT_LINE_NUMBER_FORMATTER
      Returns:
      The formatter
      See Also:
    • getPreferredSize

      public Dimension getPreferredSize()
      Overrides:
      getPreferredSize in class JComponent
    • init

      protected void init()
      Called by the constructor before the text area is set. This is a hook to allow subclasses to do any needed initialization. The default implementation does nothing.
    • mouseClicked

      public void mouseClicked(MouseEvent e)
      Specified by:
      mouseClicked in interface MouseListener
    • mouseDragged

      public void mouseDragged(MouseEvent e)
      Specified by:
      mouseDragged in interface MouseMotionListener
    • mouseEntered

      public void mouseEntered(MouseEvent e)
      Specified by:
      mouseEntered in interface MouseListener
    • mouseExited

      public void mouseExited(MouseEvent e)
      Specified by:
      mouseExited in interface MouseListener
    • mouseMoved

      public void mouseMoved(MouseEvent e)
      Specified by:
      mouseMoved in interface MouseMotionListener
    • mousePressed

      public void mousePressed(MouseEvent e)
      Specified by:
      mousePressed in interface MouseListener
    • mouseReleased

      public void mouseReleased(MouseEvent e)
      Specified by:
      mouseReleased in interface MouseListener
    • paintComponent

      protected void paintComponent(Graphics g)
      Paints this component.
      Overrides:
      paintComponent in class JComponent
      Parameters:
      g - The graphics context.
    • removeNotify

      public void removeNotify()
      Called when this component is removed from the view hierarchy.
    • setCurrentLineNumberColor

      public void setCurrentLineNumberColor(Color color)
      Sets the color to use when painting the current line's line number.
      Parameters:
      color - The color to use. If this is null, the current line's line number will be painted just like any other.
      See Also:
    • setFont

      public void setFont(Font font)
      Overridden to ensure line number cell sizes are updated with the font size change.
      Overrides:
      setFont in class JComponent
      Parameters:
      font - The new font to use for line numbers.
    • setLineNumberingStartIndex

      public void setLineNumberingStartIndex(int index)
      Sets the starting line's line number. The default value is 1. Applications can call this method to change this value if they are displaying a subset of lines in a file, for example.
      Parameters:
      index - The new index.
      See Also:
    • setLineNumberFormatter

      public void setLineNumberFormatter(LineNumberFormatter formatter)
      Sets a custom line number formatter. Can be called when other number formats are needed like hindu-arabic numerals.
      Parameters:
      formatter - The new line number formatter
      See Also:
    • setTextArea

      public void setTextArea(RTextArea textArea)
      Sets the text area being displayed.
      Parameters:
      textArea - The text area.
    • getChildViewBounds

      protected static Rectangle getChildViewBounds(View parent, int line, Rectangle editorRect)
      Returns the bounds of a child view as a rectangle, since Views tend to use Shape.
      Parameters:
      parent - The parent view of the child whose bounds we're getting.
      line - The index of the child view.
      editorRect - Returned from the text area's getVisibleEditorRect method.
      Returns:
      The child view's bounds.
    • getGutter

      protected Gutter getGutter()
      Returns the parent Gutter component.
      Returns:
      The parent Gutter.