Class ErrorStrip

  • All Implemented Interfaces:
    java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

    public class ErrorStrip
    extends javax.swing.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:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  ErrorStrip.DefaultErrorStripMarkerToolTipProvider
      The default implementation of the provider of tool tips for markers in an error strip.
      static interface  ErrorStrip.ErrorStripMarkerToolTipProvider
      Returns tool tip text for the markers in an ErrorStrip that denote one or more parser notices.
      private class  ErrorStrip.Listener
      Listens for events in the error strip and its markers.
      private class  ErrorStrip.MarkedOccurrenceNotice
      A notice that wraps a "marked occurrence" instance.
      private class  ErrorStrip.Marker
      A "marker" in this error strip, representing one or more notices.
      • Nested classes/interfaces inherited from class javax.swing.JPanel

        javax.swing.JPanel.AccessibleJPanel
      • 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 
      Modifier and Type Field Description
      private java.util.Map<java.awt.Color,​java.awt.Color> brighterColors
      Mapping of colors to brighter colors.
      private int caretLineY
      Where we paint the caret marker.
      private java.awt.Color caretMarkerColor
      The color to use for the caret marker.
      private boolean followCaret
      Whether the caret marker's location should be rendered.
      private int lastLineY
      The last location of the caret marker.
      private ParserNotice.Level levelThreshold
      Only notices of this severity (or worse) will be displayed in this error strip.
      private ErrorStrip.Listener listener
      Listens for events in this component.
      private ErrorStrip.ErrorStripMarkerToolTipProvider markerToolTipProvider
      Generates the tool tips for markers in this error strip.
      private static java.util.ResourceBundle MSG  
      private static int PREFERRED_WIDTH
      The preferred width of this component.
      private boolean showMarkAll
      Whether markers for "mark all" highlights should be shown in this error strip.
      private boolean showMarkedOccurrences
      Whether "marked occurrences" in the text area should be shown in this error strip.
      private RSyntaxTextArea textArea
      The text area.
      • 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 Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void addMarkersForRanges​(java.util.List<DocumentRange> ranges, java.util.Map<java.lang.Integer,​ErrorStrip.Marker> markerMap, java.awt.Color color)
      Adds markers for a list of ranges in the document.
      void addNotify()
      Overridden so we only start listening for parser notices when this component (and presumably the text area) are visible.
      void doLayout()
      Manually manages layout since this component uses no layout manager.
      private java.awt.Color getBrighterColor​(java.awt.Color c)
      Returns a "brighter" color.
      java.awt.Color getCaretMarkerColor()
      returns the color to use when painting the caret marker.
      private javax.swing.plaf.ColorUIResource getDefaultCaretMarkerColor()
      Returns the default color for the caret marker.
      boolean getFollowCaret()
      Returns whether the caret's position should be drawn.
      ParserNotice.Level getLevelThreshold()
      Returns the minimum severity a parser notice must be for it to be displayed in this error strip.
      java.awt.Dimension getPreferredSize()  
      boolean getShowMarkAll()
      Returns whether "mark all" highlights are shown in this error strip.
      boolean getShowMarkedOccurrences()
      Returns whether marked occurrences are shown in this error strip.
      java.lang.String getToolTipText​(java.awt.event.MouseEvent e)  
      private int lineToY​(int line, java.awt.Rectangle r)
      Returns the y-offset in this component corresponding to a line in the text component.
      protected void paintComponent​(java.awt.Graphics g)
      Overridden to (possibly) draw the caret's position.
      private static int possiblyBrighter​(int i)
      Returns a possibly brighter component for a color.
      private void refreshMarkers()
      Refreshes the markers displayed in this error strip.
      void removeNotify()  
      void setCaretMarkerColor​(java.awt.Color color)
      Sets the color to use when painting the caret marker.
      void setFollowCaret​(boolean follow)
      Toggles whether the caret's current location should be drawn.
      void setLevelThreshold​(ParserNotice.Level level)
      Sets the minimum severity a parser notice must be for it to be displayed in this error strip.
      void setMarkerToolTipProvider​(ErrorStrip.ErrorStripMarkerToolTipProvider provider)
      Sets the provider of tool tips for markers in this error strip.
      void setShowMarkAll​(boolean show)
      Sets whether "mark all" highlights are shown in this error strip.
      void setShowMarkedOccurrences​(boolean show)
      Sets whether marked occurrences are shown in this error strip.
      void updateUI()  
      private int yToLine​(int y)
      Returns the line in the text area corresponding to a y-offset in this component.
      • Methods inherited from class javax.swing.JPanel

        getAccessibleContext, getUI, getUIClassID, paramString, setUI
      • Methods inherited from class javax.swing.JComponent

        addAncestorListener, 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, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
      • Methods inherited from class java.awt.Container

        add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, 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, 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
    • Field Detail

      • 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 java.util.Map<java.awt.Color,​java.awt.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 java.awt.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.
      • PREFERRED_WIDTH

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

        private static final java.util.ResourceBundle MSG
    • Constructor Detail

      • ErrorStrip

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

      • 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 javax.swing.JComponent
      • doLayout

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

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

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

        private javax.swing.plaf.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:
        setFollowCaret(boolean)
      • getPreferredSize

        public java.awt.Dimension getPreferredSize()
        Overrides:
        getPreferredSize in class javax.swing.JComponent
      • 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:
        setShowMarkAll(boolean)
      • getShowMarkedOccurrences

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

        public java.lang.String getToolTipText​(java.awt.event.MouseEvent e)
        Overrides:
        getToolTipText in class javax.swing.JComponent
      • lineToY

        private int lineToY​(int line,
                            java.awt.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:
        yToLine(int)
      • paintComponent

        protected void paintComponent​(java.awt.Graphics g)
        Overridden to (possibly) draw the caret's position.
        Overrides:
        paintComponent in class javax.swing.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​(java.util.List<DocumentRange> ranges,
                                         java.util.Map<java.lang.Integer,​ErrorStrip.Marker> markerMap,
                                         java.awt.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 javax.swing.JComponent
      • setCaretMarkerColor

        public void setCaretMarkerColor​(java.awt.Color color)
        Sets the color to use when painting the caret marker.
        Parameters:
        color - The new caret marker color.
        See Also:
        getCaretMarkerColor()
      • 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:
        getFollowCaret()
      • 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:
        getLevelThreshold(), ParserNotice
      • 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:
        getShowMarkAll()
      • 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:
        getShowMarkedOccurrences()
      • updateUI

        public void updateUI()
        Overrides:
        updateUI in class javax.swing.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:
        lineToY(int, Rectangle)