Package org.fife.rsta.ac.html
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.DefaultCompletionProviderCompletion provider for HTML documents.- Version:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description private booleanisTagNameWhether the text last grabbed viagetAlreadyEnteredText(JTextComponent)was an HTML tag name.private java.lang.StringlastTagNameReturns the last tag name grabbed viagetAlreadyEnteredText(JTextComponent).private java.util.Map<java.lang.String,java.util.List<AttributeCompletion>>tagToAttrsA mapping of tag names to their legal attributes.
-
Constructor Summary
Constructors Constructor Description HtmlCompletionProvider()Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected java.lang.StringdefaultGetAlreadyEnteredText(javax.swing.text.JTextComponent comp)This nasty hack is just a hook for subclasses (e.g.private booleanfindLastTagNameBefore(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.StringgetAlreadyEnteredText(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.TokengetTokenBeforeOffset(org.fife.ui.rsyntaxtextarea.Token tokenList, int offs)Returns the token before the specified offset.protected voidinitCompletions()CallsDefaultCompletionProvider.loadFromXML(String)to load all standard HTML completions.private static booleaninsideMarkupTag(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).booleanisAutoActivateOkay(javax.swing.text.JTextComponent tc)Overridden to ensure auto-activation only occurs in a markup tag.protected booleanisAutoActivateOkayOutsideOfMarkup(javax.swing.text.JTextComponent tc)Returns the base implementation - basically checking that the caret comes immediately after letters.private static booleanisTagOpeningToken(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
-
-
-
-
Field Detail
-
tagToAttrs
private java.util.Map<java.lang.String,java.util.List<AttributeCompletion>> tagToAttrs
A mapping of tag names to their legal attributes.
-
isTagName
private boolean isTagName
Whether the text last grabbed viagetAlreadyEnteredText(JTextComponent)was an HTML tag name.- See Also:
lastTagName
-
lastTagName
private java.lang.String lastTagName
Returns the last tag name grabbed viagetAlreadyEnteredText(JTextComponent). This value is only valid ifisTagNameisfalse.
-
-
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 theDefaultCompletionProviderimplementation.- Parameters:
comp- The text component.- Returns:
- The text, or
nullif 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 thatoffsis 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:
getAlreadyEnteredTextin interfaceorg.fife.ui.autocomplete.CompletionProvider- Overrides:
getAlreadyEnteredTextin classorg.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
nullif the tag is not recognized.
-
getCompletionsImpl
protected java.util.List<org.fife.ui.autocomplete.Completion> getCompletionsImpl(javax.swing.text.JTextComponent comp)
- Overrides:
getCompletionsImplin classorg.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
nullif 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()
CallsDefaultCompletionProvider.loadFromXML(String)to load all standard HTML completions. Subclasses can override to also load additional standard tags (i.e. JSP'sjsp:*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 containingoffs).line- The index of the line containingoffs.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:
isAutoActivateOkayin interfaceorg.fife.ui.autocomplete.CompletionProvider- Overrides:
isAutoActivateOkayin classorg.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.
-
-