Class ErrorStrip

All Implemented Interfaces:
ImageObserver, MenuContainer, Serializable, Accessible

public class ErrorStrip extends JPanel
A component to sit alongside an RSyntaxTextArea that displays colored markers for locations of interest (parser errors, marked occurrences, etc.).

ErrorStrips display ParserNotices from Parsers. Currently, the only way to get lines flagged in this component is to register a Parser on an RSyntaxTextArea and return ParserNotices for each line to display an icon for. The severity of each notice must be at least the threshold set by setLevelThreshold(org.fife.ui.rsyntaxtextarea.parser.ParserNotice.Level) to be displayed in this error strip. The default threshold is ParserNotice.Level.WARNING.

An ErrorStrip can be added to a UI like so:

 textArea = createTextArea();
 textArea.addParser(new MyParser(textArea)); // Identifies lines to display
 scrollPane = new RTextScrollPane(textArea, true);
 ErrorStrip es = new ErrorStrip(textArea);
 JPanel temp = new JPanel(new BorderLayout());
 temp.add(scrollPane);
 temp.add(es, BorderLayout.LINE_END);
 
Version:
0.5
See Also:
  • Field Details

    • textArea

      private RSyntaxTextArea textArea
      The text area.
    • listener

      private transient ErrorStrip.Listener listener
      Listens for events in this component.
    • showMarkedOccurrences

      private boolean showMarkedOccurrences
      Whether "marked occurrences" in the text area should be shown in this error strip.
    • showMarkAll

      private boolean showMarkAll
      Whether markers for "mark all" highlights should be shown in this error strip.
    • brighterColors

      private Map<Color,Color> brighterColors
      Mapping of colors to brighter colors. This is kept to prevent unnecessary creation of the same Colors over and over.
    • levelThreshold

      private ParserNotice.Level levelThreshold
      Only notices of this severity (or worse) will be displayed in this error strip.
    • followCaret

      private boolean followCaret
      Whether the caret marker's location should be rendered.
    • caretMarkerColor

      private Color caretMarkerColor
      The color to use for the caret marker.
    • caretLineY

      private int caretLineY
      Where we paint the caret marker.
    • lastLineY

      private int lastLineY
      The last location of the caret marker.
    • markerToolTipProvider

      private transient ErrorStrip.ErrorStripMarkerToolTipProvider markerToolTipProvider
      Generates the tool tips for markers in this error strip.
    • PREFERRED_WIDTH

      private static final int PREFERRED_WIDTH
      The preferred width of this component.
      See Also:
    • MSG

      private static final ResourceBundle MSG
  • Constructor Details

    • ErrorStrip

      public ErrorStrip(RSyntaxTextArea textArea)
      Constructor.
      Parameters:
      textArea - The text area we are examining.
  • Method Details

    • addNotify

      public void addNotify()
      Overridden so we only start listening for parser notices when this component (and presumably the text area) are visible.
      Overrides:
      addNotify in class JComponent
    • doLayout

      public void doLayout()
      Manually manages layout since this component uses no layout manager.
      Overrides:
      doLayout in class Container
    • getBrighterColor

      private Color getBrighterColor(Color c)
      Returns a "brighter" color.
      Parameters:
      c - The color.
      Returns:
      A brighter color.
    • getCaretMarkerColor

      public Color getCaretMarkerColor()
      returns the color to use when painting the caret marker.
      Returns:
      The caret marker color.
      See Also:
    • getDefaultCaretMarkerColor

      private ColorUIResource getDefaultCaretMarkerColor()
      Returns the default color for the caret marker. This is a UI resource so that it is updated if the LookAndFeel is updated, but not if the user overrides it.
      Returns:
      The default color.
    • getFollowCaret

      public boolean getFollowCaret()
      Returns whether the caret's position should be drawn.
      Returns:
      Whether the caret's position should be drawn.
      See Also:
    • getPreferredSize

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

      public ParserNotice.Level getLevelThreshold()
      Returns the minimum severity a parser notice must be for it to be displayed in this error strip. This will be one of the constants defined in the ParserNotice class.
      Returns:
      The minimum severity.
      See Also:
    • getShowMarkAll

      public boolean getShowMarkAll()
      Returns whether "mark all" highlights are shown in this error strip.
      Returns:
      Whether markers are shown for "mark all" highlights.
      See Also:
    • getShowMarkedOccurrences

      public boolean getShowMarkedOccurrences()
      Returns whether marked occurrences are shown in this error strip.
      Returns:
      Whether marked occurrences are shown.
      See Also:
    • getToolTipText

      public String getToolTipText(MouseEvent e)
      Overrides:
      getToolTipText in class JComponent
    • lineToY

      private int lineToY(int line, Rectangle r)
      Returns the y-offset in this component corresponding to a line in the text component.
      Parameters:
      line - The line.
      Returns:
      The y-offset.
      See Also:
    • paintComponent

      protected void paintComponent(Graphics g)
      Overridden to (possibly) draw the caret's position.
      Overrides:
      paintComponent in class JComponent
      Parameters:
      g - The graphics context.
    • possiblyBrighter

      private static int possiblyBrighter(int i)
      Returns a possibly brighter component for a color.
      Parameters:
      i - An RGB component for a color (0-255).
      Returns:
      A possibly brighter value for the component.
    • refreshMarkers

      private void refreshMarkers()
      Refreshes the markers displayed in this error strip.
    • addMarkersForRanges

      private void addMarkersForRanges(List<DocumentRange> ranges, Map<Integer,ErrorStrip.Marker> markerMap, Color color)
      Adds markers for a list of ranges in the document.
      Parameters:
      ranges - The list of ranges in the document.
      markerMap - A mapping from line number to Marker.
      color - The color to use for the markers.
    • removeNotify

      public void removeNotify()
      Overrides:
      removeNotify in class JComponent
    • setCaretMarkerColor

      public void setCaretMarkerColor(Color color)
      Sets the color to use when painting the caret marker.
      Parameters:
      color - The new caret marker color.
      See Also:
    • setFollowCaret

      public void setFollowCaret(boolean follow)
      Toggles whether the caret's current location should be drawn.
      Parameters:
      follow - Whether the caret's current location should be followed.
      See Also:
    • setLevelThreshold

      public void setLevelThreshold(ParserNotice.Level level)
      Sets the minimum severity a parser notice must be for it to be displayed in this error strip. This should be one of the constants defined in the ParserNotice class. The default value is ParserNotice.Level.WARNING.
      Parameters:
      level - The new severity threshold.
      See Also:
    • setMarkerToolTipProvider

      public void setMarkerToolTipProvider(ErrorStrip.ErrorStripMarkerToolTipProvider provider)
      Sets the provider of tool tips for markers in this error strip. Applications can use this method to control the content and format of the tool tip descriptions of line markers.
      Parameters:
      provider - The provider. If this is null, a default implementation will be used.
    • setShowMarkAll

      public void setShowMarkAll(boolean show)
      Sets whether "mark all" highlights are shown in this error strip.
      Parameters:
      show - Whether to show markers for "mark all" highlights.
      See Also:
    • setShowMarkedOccurrences

      public void setShowMarkedOccurrences(boolean show)
      Sets whether marked occurrences are shown in this error strip.
      Parameters:
      show - Whether to show marked occurrences.
      See Also:
    • updateUI

      public void updateUI()
      Overrides:
      updateUI in class JPanel
    • yToLine

      private int yToLine(int y)
      Returns the line in the text area corresponding to a y-offset in this component.
      Parameters:
      y - The y-offset.
      Returns:
      The line.
      See Also: