Class NavigationPoint

  • All Implemented Interfaces:
    java.lang.Comparable<NavigationPoint>

    public class NavigationPoint
    extends java.lang.Object
    implements java.lang.Comparable<NavigationPoint>
    A navigation point describes a semantically significant location within a text file.
    Since:
    3.0
    Author:
    Chris Jennings
    See Also:
    CodeEditor, NavigationPoint
    • Constructor Summary

      Constructors 
      Constructor Description
      NavigationPoint​(java.lang.String description, int offset)
      Creates a new navigation point.
      NavigationPoint​(java.lang.String description, int offset, int scope)
      Creates a new navigation point.
      NavigationPoint​(java.lang.String description, java.lang.String longDescription, int offset, int scope, javax.swing.Icon icon)
      Creates a new navigation point.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int compareTo​(NavigationPoint rhs)
      Compares two navigation points by their description.
      boolean equals​(java.lang.Object rhs)
      Returns true if two navigation points are considered equal, based on their string description.
      NavigationPoint getClosestPoint​(java.util.List<NavigationPoint> newPoints)
      Returns the navigation point in a list of points that is the best match for this point.
      javax.swing.Icon getIcon()
      Returns the icon for this point, or null.
      java.lang.String getLongDescription()
      Returns the long description of this navigation point.
      int getOffset()
      Returns the character offset into the file that the navigation point represents.
      int getScope()
      Returns the scope depth of this navigation point.
      int hashCode()
      Returns a hash code for this navigation point.
      static void sortByName​(java.util.List<NavigationPoint> points)
      Sort a list of navigation points by their description.
      static void sortByOffset​(java.util.List<NavigationPoint> points)
      Sort a list of navigation points by their offset.
      java.lang.String toString()
      Returns the description of the navigation point.
      void visit​(CodeEditor editor)
      Visits the point in a code editor.
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Field Detail

      • ICON_KEYWORD

        public static final javax.swing.Icon ICON_KEYWORD
      • ICON_MODULE

        public static final javax.swing.Icon ICON_MODULE
      • ICON_PACKAGE

        public static final javax.swing.Icon ICON_PACKAGE
      • ICON_CLASS

        public static final javax.swing.Icon ICON_CLASS
      • ICON_INTERFACE

        public static final javax.swing.Icon ICON_INTERFACE
      • ICON_ENUM

        public static final javax.swing.Icon ICON_ENUM
      • ICON_ENUM_MEMBER

        public static final javax.swing.Icon ICON_ENUM_MEMBER
      • ICON_VAR

        public static final javax.swing.Icon ICON_VAR
      • ICON_LET

        public static final javax.swing.Icon ICON_LET
      • ICON_CONST

        public static final javax.swing.Icon ICON_CONST
      • ICON_PROPERTY

        public static final javax.swing.Icon ICON_PROPERTY
      • ICON_FUNCTION

        public static final javax.swing.Icon ICON_FUNCTION
      • ICON_METHOD

        public static final javax.swing.Icon ICON_METHOD
      • ICON_GETTER

        public static final javax.swing.Icon ICON_GETTER
      • ICON_SETTER

        public static final javax.swing.Icon ICON_SETTER
      • ICON_TYPE

        public static final javax.swing.Icon ICON_TYPE
      • ICON_ALIAS

        public static final javax.swing.Icon ICON_ALIAS
      • ICON_PRIMITIVE

        public static final javax.swing.Icon ICON_PRIMITIVE
      • ICON_CALL

        public static final javax.swing.Icon ICON_CALL
      • ICON_INDEX

        public static final javax.swing.Icon ICON_INDEX
      • ICON_PARAMETER

        public static final javax.swing.Icon ICON_PARAMETER
      • ICON_TYPE_PARAMETER

        public static final javax.swing.Icon ICON_TYPE_PARAMETER
      • ICON_LABEL

        public static final javax.swing.Icon ICON_LABEL
      • ICON_DIRECTORY

        public static final javax.swing.Icon ICON_DIRECTORY
      • ICON_GLOBAL

        public static final javax.swing.Icon ICON_GLOBAL
      • ICON_H1

        public static final javax.swing.Icon ICON_H1
      • ICON_H2

        public static final javax.swing.Icon ICON_H2
      • ICON_H3

        public static final javax.swing.Icon ICON_H3
      • ICON_H4

        public static final javax.swing.Icon ICON_H4
      • ICON_H5

        public static final javax.swing.Icon ICON_H5
      • ICON_H6

        public static final javax.swing.Icon ICON_H6
      • ICON_TITLE

        public static final javax.swing.Icon ICON_TITLE
      • ICON_DIV

        public static final javax.swing.Icon ICON_DIV
      • ICON_TABLE

        public static final javax.swing.Icon ICON_TABLE
      • ICON_SETTING

        public static final javax.swing.Icon ICON_SETTING
      • ICON_ERROR

        public static final javax.swing.Icon ICON_ERROR
        An error symbol icon sometimes used by navigation points. Typical use is to represent compiler errors.
      • ICON_WARNING

        public static final javax.swing.Icon ICON_WARNING
        A warning symbol icon sometimes used by navigation points. Typical use is to represent compiler warnings or other style hints.
      • ICON_NONE

        public static final javax.swing.Icon ICON_NONE
        An empty icon the same size as the standard navigation point icons.
    • Constructor Detail

      • NavigationPoint

        public NavigationPoint​(java.lang.String description,
                               int offset)
        Creates a new navigation point.
        Parameters:
        description - a brief description or summary of the content of the location
        offset - the location of the point in the text, as a character offset from the start of the file
      • NavigationPoint

        public NavigationPoint​(java.lang.String description,
                               int offset,
                               int scope)
        Creates a new navigation point.
        Parameters:
        description - a brief description or summary of the content of the location
        offset - the location of the point in the text, as a character offset from the start of the file
        scope - a value that indicates a nesting depth relative to other navigation points in a collection of navigation points; default is 0
      • NavigationPoint

        public NavigationPoint​(java.lang.String description,
                               java.lang.String longDescription,
                               int offset,
                               int scope,
                               javax.swing.Icon icon)
        Creates a new navigation point.
        Parameters:
        description - a brief description or summary of the content of the location
        longDescription - a longer, more detailed description (may be null)
        offset - the location of the point in the text, as a character offset from the start of the file
        scope - a value that indicates a nesting depth relative to other navigation points in a collection of navigation points; default is 0
        icon - an icon for the navigation point type (may be null)
    • Method Detail

      • getOffset

        public int getOffset()
        Returns the character offset into the file that the navigation point represents.
        Returns:
        the offset that this point jumps to
      • getIcon

        public javax.swing.Icon getIcon()
        Returns the icon for this point, or null.
        Returns:
        this point's icon, if any
      • getLongDescription

        public java.lang.String getLongDescription()
        Returns the long description of this navigation point. If the point has no long description, returns the short description.
        Returns:
        the long description of the point
      • getScope

        public int getScope()
        Returns the scope depth of this navigation point.
        Returns:
        the non-negative scope depth
      • toString

        public java.lang.String toString()
        Returns the description of the navigation point.
        Overrides:
        toString in class java.lang.Object
        Returns:
        the short description of the point
      • visit

        public void visit​(CodeEditor editor)
        Visits the point in a code editor. The editor's caret will be moved to the offset specified by this navigation point.
        Parameters:
        editor - the editor to display the navigation point within
      • equals

        public boolean equals​(java.lang.Object rhs)
        Returns true if two navigation points are considered equal, based on their string description. Line numbers are NOT be considered when determining equality. This is intentional.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        rhs - the object to compare to
        Returns:
        true if the specified object is a navigation point with the same description
      • hashCode

        public int hashCode()
        Returns a hash code for this navigation point.
        Overrides:
        hashCode in class java.lang.Object
        Returns:
        a hash code consistent with equals
      • getClosestPoint

        public NavigationPoint getClosestPoint​(java.util.List<NavigationPoint> newPoints)
        Returns the navigation point in a list of points that is the best match for this point. This method attempts to detect the point that best reflects this point even if the points in the list were generated from a version of the same text file that has been edited since the original point was generated by a Navigator.
        Parameters:
        newPoints - the points to consider
        Returns:
        the best matching point in the list for this point, or null if the list is empty
      • compareTo

        public int compareTo​(NavigationPoint rhs)
        Compares two navigation points by their description.
        Specified by:
        compareTo in interface java.lang.Comparable<NavigationPoint>
        Parameters:
        rhs - the navigation point to compare this point to
        Returns:
        a negative, zero, or positive integer as this point is less than, equal to, or greater than the target of the comparison
      • sortByName

        public static void sortByName​(java.util.List<NavigationPoint> points)
        Sort a list of navigation points by their description.
        Parameters:
        points - the points to sort
      • sortByOffset

        public static void sortByOffset​(java.util.List<NavigationPoint> points)
        Sort a list of navigation points by their offset.
        Parameters:
        points - the points to sort