Class HtmlCompletionProvider

java.lang.Object
org.fife.ui.autocomplete.CompletionProviderBase
org.fife.ui.autocomplete.AbstractCompletionProvider
org.fife.ui.autocomplete.DefaultCompletionProvider
org.fife.rsta.ac.html.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
    Whether the text last grabbed via getAlreadyEnteredText(JTextComponent) was an HTML tag name.
    private String
    Returns the last tag name grabbed via getAlreadyEnteredText(JTextComponent).
    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
  • Constructor Summary

    Constructors
    Constructor
    Description
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected String
    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.
    Returns the attributes that can be code-completed for the specified tag.
    protected List<org.fife.ui.autocomplete.Completion>
    protected List<org.fife.ui.autocomplete.Completion>
    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
    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
    Overridden to ensure auto-activation only occurs in a markup tag.
    protected boolean
    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
  • Field Details

  • Constructor Details

    • HtmlCompletionProvider

      public HtmlCompletionProvider()
      Constructor.
  • Method Details

    • defaultGetAlreadyEnteredText

      protected String defaultGetAlreadyEnteredText(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 String getAlreadyEnteredText(JTextComponent comp)
      Specified by:
      getAlreadyEnteredText in interface org.fife.ui.autocomplete.CompletionProvider
      Overrides:
      getAlreadyEnteredText in class org.fife.ui.autocomplete.DefaultCompletionProvider
    • getAttributeCompletionsForTag

      protected List<AttributeCompletion> getAttributeCompletionsForTag(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 List<org.fife.ui.autocomplete.Completion> getCompletionsImpl(JTextComponent comp)
      Overrides:
      getCompletionsImpl in class org.fife.ui.autocomplete.AbstractCompletionProvider
    • getTagCompletions

      protected 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(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

      public boolean isAutoActivateOkay(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:
    • 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.