Package ca.cgjennings.ui.textedit
Class NavigationPoint
- java.lang.Object
-
- ca.cgjennings.ui.textedit.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
-
-
Field Summary
Fields Modifier and Type Field Description static javax.swing.Icon
ICON_ALIAS
static javax.swing.Icon
ICON_CALL
static javax.swing.Icon
ICON_CLASS
static javax.swing.Icon
ICON_CONST
static javax.swing.Icon
ICON_DIRECTORY
static javax.swing.Icon
ICON_DIV
static javax.swing.Icon
ICON_ENUM
static javax.swing.Icon
ICON_ENUM_MEMBER
static javax.swing.Icon
ICON_ERROR
An error symbol icon sometimes used by navigation points.static javax.swing.Icon
ICON_FUNCTION
static javax.swing.Icon
ICON_GETTER
static javax.swing.Icon
ICON_GLOBAL
static javax.swing.Icon
ICON_H1
static javax.swing.Icon
ICON_H2
static javax.swing.Icon
ICON_H3
static javax.swing.Icon
ICON_H4
static javax.swing.Icon
ICON_H5
static javax.swing.Icon
ICON_H6
static javax.swing.Icon
ICON_INDEX
static javax.swing.Icon
ICON_INTERFACE
static javax.swing.Icon
ICON_KEYWORD
static javax.swing.Icon
ICON_LABEL
static javax.swing.Icon
ICON_LET
static javax.swing.Icon
ICON_METHOD
static javax.swing.Icon
ICON_MODULE
static javax.swing.Icon
ICON_NONE
An empty icon the same size as the standard navigation point icons.static javax.swing.Icon
ICON_PACKAGE
static javax.swing.Icon
ICON_PARAMETER
static javax.swing.Icon
ICON_PRIMITIVE
static javax.swing.Icon
ICON_PROPERTY
static javax.swing.Icon
ICON_SETTER
static javax.swing.Icon
ICON_SETTING
static javax.swing.Icon
ICON_TABLE
static javax.swing.Icon
ICON_TITLE
static javax.swing.Icon
ICON_TYPE
static javax.swing.Icon
ICON_TYPE_PARAMETER
static javax.swing.Icon
ICON_VAR
static javax.swing.Icon
ICON_WARNING
A warning symbol icon sometimes used by navigation points.
-
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)
Returnstrue
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, ornull
.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.
-
-
-
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 locationoffset
- 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 locationoffset
- the location of the point in the text, as a character offset from the start of the filescope
- 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 locationlongDescription
- a longer, more detailed description (may benull
)offset
- the location of the point in the text, as a character offset from the start of the filescope
- a value that indicates a nesting depth relative to other navigation points in a collection of navigation points; default is 0icon
- an icon for the navigation point type (may benull
)
-
-
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, ornull
.- 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 classjava.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)
Returnstrue
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 classjava.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 classjava.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 aNavigator
.- 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 interfacejava.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
-
-