Class JXEditorPane.DocumentSearchable

  • All Implemented Interfaces:
    Searchable
    Enclosing class:
    JXEditorPane

    public class JXEditorPane.DocumentSearchable
    extends java.lang.Object
    implements Searchable
    A Searchable implementation for Documents.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      (package private) int lastFoundIndex  
      (package private) java.util.regex.MatchResult lastMatchResult  
      (package private) java.lang.String lastRegEx  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private boolean foundExtendedMatch​(java.util.regex.Pattern pattern, int start)
      Search from same startIndex as the previous search.
      private java.util.regex.MatchResult getMatchResult​(java.util.regex.Matcher matcher, boolean useFirst)  
      protected boolean isEmpty​(java.lang.String searchString)
      checks if the searchString should be interpreted as empty.
      private boolean maybeExtendedMatch​(int startIndex)
      Checks if the startIndex is a candidate for trying a re-match.
      int search​(java.lang.String searchString)
      Search searchString from the beginning of a document.
      int search​(java.lang.String searchString, int columnIndex)
      Search searchString from the given position in a document.
      int search​(java.lang.String searchString, int columnIndex, boolean backward)
      Search searchString in the given direction from the some position in a document.
      int search​(java.util.regex.Pattern pattern)
      Search for the pattern from the beginning of the document.
      int search​(java.util.regex.Pattern pattern, int startIndex)
      Search for the pattern from the start index.
      int search​(java.util.regex.Pattern pattern, int startIndex, boolean backwards)
      Search for the pattern from the start index.
      private int updateStateAfterFound​(java.util.regex.MatchResult currentResult, int offset)  
      private void updateStateAfterNotFound()  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • lastFoundIndex

        int lastFoundIndex
      • lastMatchResult

        java.util.regex.MatchResult lastMatchResult
      • lastRegEx

        java.lang.String lastRegEx
    • Constructor Detail

      • DocumentSearchable

        public DocumentSearchable()
    • Method Detail

      • search

        public int search​(java.lang.String searchString)
        Description copied from interface: Searchable
        Search searchString from the beginning of a document.
        Specified by:
        search in interface Searchable
        Parameters:
        searchString - String we should find in a document.
        Returns:
        index of matched String or -1 if a match cannot be found.
      • search

        public int search​(java.lang.String searchString,
                          int columnIndex)
        Description copied from interface: Searchable
        Search searchString from the given position in a document.
        Specified by:
        search in interface Searchable
        Parameters:
        searchString - String we should find in a document.
        columnIndex - Start position in a document or -1 if we want to search from the beginning.
        Returns:
        index of matched String or -1 if a match cannot be found.
      • search

        public int search​(java.lang.String searchString,
                          int columnIndex,
                          boolean backward)
        Description copied from interface: Searchable
        Search searchString in the given direction from the some position in a document.
        Specified by:
        search in interface Searchable
        Parameters:
        searchString - String we should find in a document.
        columnIndex - Start position in a document or -1 if we want to search from the beginning.
        backward - Indicates search direction, will search from the given position towards the beginning of a document if this parameter is true.
        Returns:
        index of matched String or -1 if a match cannot be found.
      • isEmpty

        protected boolean isEmpty​(java.lang.String searchString)
        checks if the searchString should be interpreted as empty. here: returns true if string is null or has zero length. TODO: This should be in a utility class.
        Parameters:
        searchString -
        Returns:
        true if string is null or has zero length
      • search

        public int search​(java.util.regex.Pattern pattern)
        Description copied from interface: Searchable
        Search for the pattern from the beginning of the document.
        Specified by:
        search in interface Searchable
        Parameters:
        pattern - Pattern for search
        Returns:
        index of matched Pattern or -1 if a match cannot be found.
      • search

        public int search​(java.util.regex.Pattern pattern,
                          int startIndex)
        Description copied from interface: Searchable
        Search for the pattern from the start index.
        Specified by:
        search in interface Searchable
        Parameters:
        pattern - Pattern for search
        startIndex - starting index of search. If -1 then start from the beginning
        Returns:
        index of matched pattern or -1 if a match cannot be found.
      • search

        public int search​(java.util.regex.Pattern pattern,
                          int startIndex,
                          boolean backwards)
        Description copied from interface: Searchable
        Search for the pattern from the start index.
        Specified by:
        search in interface Searchable
        Parameters:
        pattern - Pattern for search
        startIndex - starting index of search. If -1 then start from the beginning
        backwards - indicates the direction if true then search is backwards
        Returns:
        start position of matching string or -1
      • foundExtendedMatch

        private boolean foundExtendedMatch​(java.util.regex.Pattern pattern,
                                           int start)
        Search from same startIndex as the previous search. Checks if the match is different from the last (either extended/reduced) at the same position. Returns true if the current match result represents a different match than the last, false if no match or the same.
        Parameters:
        pattern -
        start -
        Returns:
        true if the current match result represents a different match than the last, false if no match or the same.
      • maybeExtendedMatch

        private boolean maybeExtendedMatch​(int startIndex)
        Checks if the startIndex is a candidate for trying a re-match.
        Parameters:
        startIndex -
        Returns:
        true if the startIndex should be re-matched, false if not.
      • updateStateAfterFound

        private int updateStateAfterFound​(java.util.regex.MatchResult currentResult,
                                          int offset)
        Parameters:
        currentResult -
        offset -
        Returns:
        the start position of the selected text
      • getMatchResult

        private java.util.regex.MatchResult getMatchResult​(java.util.regex.Matcher matcher,
                                                           boolean useFirst)
        Parameters:
        matcher -
        useFirst - whether or not to return after the first match is found.
        Returns:
        MatchResult or null
      • updateStateAfterNotFound

        private void updateStateAfterNotFound()