Class HtmlCompletionProvider

  • All Implemented Interfaces:
    org.fife.ui.autocomplete.CompletionProvider
    Direct Known Subclasses:
    JspCompletionProvider, PhpCompletionProvider

    public class HtmlCompletionProvider
    extends org.fife.ui.autocomplete.DefaultCompletionProvider
    Completion provider for HTML documents.
    Version:
    1.0
    • Nested Class Summary

      • Nested classes/interfaces inherited from class org.fife.ui.autocomplete.AbstractCompletionProvider

        org.fife.ui.autocomplete.AbstractCompletionProvider.CaseInsensitiveComparator
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private boolean isTagName
      Whether the text last grabbed via getAlreadyEnteredText(JTextComponent) was an HTML tag name.
      private java.lang.String lastTagName
      Returns the last tag name grabbed via getAlreadyEnteredText(JTextComponent).
      private java.util.Map<java.lang.String,​java.util.List<AttributeCompletion>> tagToAttrs
      A mapping of tag names to their legal attributes.
      • Fields inherited from class org.fife.ui.autocomplete.DefaultCompletionProvider

        seg
      • Fields inherited from class org.fife.ui.autocomplete.AbstractCompletionProvider

        comparator, completions
      • Fields inherited from class org.fife.ui.autocomplete.CompletionProviderBase

        EMPTY_STRING
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected java.lang.String defaultGetAlreadyEnteredText​(javax.swing.text.JTextComponent comp)
      This nasty hack is just a hook for subclasses (e.g.
      private boolean findLastTagNameBefore​(org.fife.ui.rsyntaxtextarea.RSyntaxDocument doc, org.fife.ui.rsyntaxtextarea.Token tokenList, int offs)
      Locates the name of the tag a given offset is in.
      java.lang.String getAlreadyEnteredText​(javax.swing.text.JTextComponent comp)
      protected java.util.List<AttributeCompletion> getAttributeCompletionsForTag​(java.lang.String tagName)
      Returns the attributes that can be code-completed for the specified tag.
      protected java.util.List<org.fife.ui.autocomplete.Completion> getCompletionsImpl​(javax.swing.text.JTextComponent comp)
      protected java.util.List<org.fife.ui.autocomplete.Completion> getTagCompletions()
      Returns the completions for the basic tag set.
      private static org.fife.ui.rsyntaxtextarea.Token getTokenBeforeOffset​(org.fife.ui.rsyntaxtextarea.Token tokenList, int offs)
      Returns the token before the specified offset.
      protected void initCompletions()
      Calls DefaultCompletionProvider.loadFromXML(String) to load all standard HTML completions.
      private static boolean insideMarkupTag​(org.fife.ui.rsyntaxtextarea.RSyntaxTextArea textArea, org.fife.ui.rsyntaxtextarea.Token list, int line, int offs)
      Returns whether the given offset is inside a markup tag (and not in string content, such as an attribute value).
      boolean isAutoActivateOkay​(javax.swing.text.JTextComponent tc)
      Overridden to ensure auto-activation only occurs in a markup tag.
      protected boolean isAutoActivateOkayOutsideOfMarkup​(javax.swing.text.JTextComponent tc)
      Returns the base implementation - basically checking that the caret comes immediately after letters.
      private static boolean isTagOpeningToken​(org.fife.ui.rsyntaxtextarea.Token t)
      Returns whether this token's text is "<" or "</".
      • Methods inherited from class org.fife.ui.autocomplete.DefaultCompletionProvider

        getCompletionsAt, getParameterizedCompletions, init, isValidChar, loadFromXML, loadFromXML, loadFromXML, loadFromXML
      • Methods inherited from class org.fife.ui.autocomplete.AbstractCompletionProvider

        addCompletion, addCompletions, addWordCompletions, checkProviderAndAdd, clear, getCompletionByInputText, removeCompletion
      • Methods inherited from class org.fife.ui.autocomplete.CompletionProviderBase

        clearParameterizedCompletionParams, getCompletions, getListCellRenderer, getParameterChoicesProvider, getParameterListEnd, getParameterListSeparator, getParameterListStart, getParent, setAutoActivationRules, setListCellRenderer, setParameterChoicesProvider, setParameterizedCompletionParams, setParent
      • Methods inherited from class java.lang.Object

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

      • HtmlCompletionProvider

        public HtmlCompletionProvider()
        Constructor.
    • Method Detail

      • defaultGetAlreadyEnteredText

        protected java.lang.String defaultGetAlreadyEnteredText​(javax.swing.text.JTextComponent comp)
        This nasty hack is just a hook for subclasses (e.g. PhpCompletionProvider) to be able to get at the DefaultCompletionProvider implementation.
        Parameters:
        comp - The text component.
        Returns:
        The text, or null if none.
      • findLastTagNameBefore

        private boolean findLastTagNameBefore​(org.fife.ui.rsyntaxtextarea.RSyntaxDocument doc,
                                              org.fife.ui.rsyntaxtextarea.Token tokenList,
                                              int offs)
        Locates the name of the tag a given offset is in. This method assumes that the caller has already concluded that offs is in fact inside a tag, and that there is a little "text" just before it.
        Parameters:
        doc - The document being parsed.
        tokenList - The token list for the current line.
        offs - The offset into the document to check.
        Returns:
        Whether a tag name was found.
      • getAlreadyEnteredText

        public java.lang.String getAlreadyEnteredText​(javax.swing.text.JTextComponent comp)
        Specified by:
        getAlreadyEnteredText in interface org.fife.ui.autocomplete.CompletionProvider
        Overrides:
        getAlreadyEnteredText in class org.fife.ui.autocomplete.DefaultCompletionProvider
      • getAttributeCompletionsForTag

        protected java.util.List<AttributeCompletion> getAttributeCompletionsForTag​(java.lang.String tagName)
        Returns the attributes that can be code-completed for the specified tag. Subclasses can override this method to handle more than the standard set of HTML 5 tags and their attributes.
        Parameters:
        tagName - The tag whose attributes are being code-completed.
        Returns:
        A list of attributes, or null if the tag is not recognized.
      • getCompletionsImpl

        protected java.util.List<org.fife.ui.autocomplete.Completion> getCompletionsImpl​(javax.swing.text.JTextComponent comp)
        Overrides:
        getCompletionsImpl in class org.fife.ui.autocomplete.AbstractCompletionProvider
      • getTagCompletions

        protected java.util.List<org.fife.ui.autocomplete.Completion> getTagCompletions()
        Returns the completions for the basic tag set. This method is here so subclasses can add to it if they provide additional tags (i.e. JSP).
        Returns:
        The completions for the standard tag set.
      • getTokenBeforeOffset

        private static org.fife.ui.rsyntaxtextarea.Token getTokenBeforeOffset​(org.fife.ui.rsyntaxtextarea.Token tokenList,
                                                                              int offs)
        Returns the token before the specified offset.
        Parameters:
        tokenList - A list of tokens containing the offset.
        offs - The offset.
        Returns:
        The token before the offset, or null if the offset was the first offset in the token list (or not in the token list at all, which would be an error).
      • initCompletions

        protected void initCompletions()
        Calls DefaultCompletionProvider.loadFromXML(String) to load all standard HTML completions. Subclasses can override to also load additional standard tags (i.e. JSP's jsp:* tags).
      • insideMarkupTag

        private static boolean insideMarkupTag​(org.fife.ui.rsyntaxtextarea.RSyntaxTextArea textArea,
                                               org.fife.ui.rsyntaxtextarea.Token list,
                                               int line,
                                               int offs)
        Returns whether the given offset is inside a markup tag (and not in string content, such as an attribute value).
        Parameters:
        textArea - The text area being parsed.
        list - The list of tokens for the current line (the line containing offs).
        line - The index of the line containing offs.
        offs - The offset into the text area's content to check.
        Returns:
        Whether the offset is inside a markup tag.
      • isAutoActivateOkayOutsideOfMarkup

        protected boolean isAutoActivateOkayOutsideOfMarkup​(javax.swing.text.JTextComponent tc)
        Returns the base implementation - basically checking that the caret comes immediately after letters. This is here for subclasses that sometimes auto-activate in markup, other times auto-activate in some other language, such as PHP.
        Parameters:
        tc - The text component.
        Returns:
        Whether auto-activation is okay outside of markup.
        See Also:
        isAutoActivateOkay(JTextComponent)
      • isAutoActivateOkay

        public boolean isAutoActivateOkay​(javax.swing.text.JTextComponent tc)
        Overridden to ensure auto-activation only occurs in a markup tag.
        Specified by:
        isAutoActivateOkay in interface org.fife.ui.autocomplete.CompletionProvider
        Overrides:
        isAutoActivateOkay in class org.fife.ui.autocomplete.CompletionProviderBase
        See Also:
        isAutoActivateOkayOutsideOfMarkup(JTextComponent)
      • isTagOpeningToken

        private static boolean isTagOpeningToken​(org.fife.ui.rsyntaxtextarea.Token t)
        Returns whether this token's text is "<" or "</". It is assumed that whether this is a markup delimiter token is checked elsewhere.
        Parameters:
        t - The token to check.
        Returns:
        Whether it is a tag opening token.