public class DefaultCompletionItem extends java.lang.Object implements CompletionItem
Constructor and Description |
---|
DefaultCompletionItem(java.lang.String text,
int offset,
java.lang.String complete,
java.lang.String label,
java.lang.String link) |
DefaultCompletionItem(java.lang.String text,
int offset,
java.lang.String complete,
java.lang.String label,
java.lang.String link,
int sortPriority,
javax.swing.ImageIcon icon) |
Modifier and Type | Method and Description |
---|---|
CompletionTask |
createDocumentationTask()
Returns a task used to obtain a documentation associated with the item if there
is any.
|
CompletionTask |
createToolTipTask()
Returns a task used to obtain a tooltip hint associated with the item if there
is any.
|
void |
defaultAction(javax.swing.text.JTextComponent jTextComponent)
Gets invoked when user presses
VK_ENTER key
or when she double-clicks on this item with the mouse cursor. |
static DefaultCompletionItem |
error(java.lang.String message) |
java.lang.String |
getComplete() |
java.lang.CharSequence |
getInsertPrefix()
Returns a text used for finding of a longest common prefix
after the TAB gets pressed or when the completion is opened explicitly.
|
int |
getPreferredWidth(java.awt.Graphics graphics,
java.awt.Font font)
Get the preferred visual width of this item.
|
int |
getSortPriority()
Returns the item's priority.
|
java.lang.CharSequence |
getSortText()
Returns a text used to sort items alphabetically.
|
boolean |
instantSubstitution(javax.swing.text.JTextComponent jTextComponent)
When enabled for the item the instant substitution should process the item
in the same way like when the item is displayed and Enter key gets pressed
by the user.
|
void |
processKeyEvent(java.awt.event.KeyEvent keyEvent)
Process the key pressed when this completion item was selected
in the completion popup window.
|
void |
render(java.awt.Graphics graphics,
java.awt.Font font,
java.awt.Color color,
java.awt.Color color0,
int i,
int i0,
boolean b)
Render this item into the given graphics.
|
void |
setReferenceOnly(boolean ref) |
protected void |
substituteText(javax.swing.text.JTextComponent c,
int offset,
int len,
java.lang.String toAdd) |
public DefaultCompletionItem(java.lang.String text, int offset, java.lang.String complete, java.lang.String label, java.lang.String link, int sortPriority, javax.swing.ImageIcon icon)
text
- used for sort and insert prefix. Typically same as complete.offset
- number of chars already typed.complete
- complete.substring(offset) is inserted.label
- the human readable presentation of this, maybe with html. Note an arrow "->" will split the label to the left and right.link
- handed over to DefaultDocumentationItem, if non null. May be "inline:<html>..."sortPriority
- 1 is default.icon
- the icon to show next to this completion.public DefaultCompletionItem(java.lang.String text, int offset, java.lang.String complete, java.lang.String label, java.lang.String link)
text
- used for sort and insert prefix. Typically same as complete.offset
- number of chars already typed.complete
- complete.substring(offset) is inserted.label
- the human readable presentation of this, maybe with html.link
- handed over to DefaultDocumentationItem, if non null. May be "inline:<html>..."public void setReferenceOnly(boolean ref)
public static DefaultCompletionItem error(java.lang.String message)
public void defaultAction(javax.swing.text.JTextComponent jTextComponent)
CompletionItem
VK_ENTER
key
or when she double-clicks on this item with the mouse cursor.
defaultAction
in interface CompletionItem
jTextComponent
- non-null text component for which the completion was invoked.public java.lang.String getComplete()
protected void substituteText(javax.swing.text.JTextComponent c, int offset, int len, java.lang.String toAdd)
public void processKeyEvent(java.awt.event.KeyEvent keyEvent)
CompletionItem
processKeyEvent
in interface CompletionItem
keyEvent
- non-null key event of the pressed key. It should be consumed
in case the item is sensitive to the given key. The source of this
event is the text component to which the corresponding action should
be performed.public int getPreferredWidth(java.awt.Graphics graphics, java.awt.Font font)
CompletionItem
getPreferredWidth
in interface CompletionItem
graphics
- graphics that can be used for determining the preferred width
e.g. getting of the font metrics.font
- default font used for rendering.public void render(java.awt.Graphics graphics, java.awt.Font font, java.awt.Color color, java.awt.Color color0, int i, int i0, boolean b)
CompletionItem
render
in interface CompletionItem
graphics
- graphics to render the item into.font
- default font used for rendering.color
- default color used for rendering.color0
- color used for background.i
- width of the area to render into.i0
- height of the are to render into.b
- whether this item is visually selected in the list
into which the items are being rendered.public CompletionTask createDocumentationTask()
CompletionItem
createDocumentationTask
in interface CompletionItem
public CompletionTask createToolTipTask()
CompletionItem
createToolTipTask
in interface CompletionItem
public boolean instantSubstitution(javax.swing.text.JTextComponent jTextComponent)
CompletionItem
CompletionItem.defaultAction(JTextComponent)
if necessary.
instantSubstitution
in interface CompletionItem
jTextComponent
- non-null text component for which the completion was invoked.true
if the instant substitution was successfully done.
false
means that the instant substitution should not be done
for this item and the completion item should normally be displayed.public int getSortPriority()
CompletionItem
getSortPriority
in interface CompletionItem
public java.lang.CharSequence getSortText()
CompletionItem
getSortText
in interface CompletionItem
public java.lang.CharSequence getInsertPrefix()
CompletionItem
Generally the returned text does not need to contain all the information
that gets inserted when the item is selected.
For example in java completion the field name should be returned for fields
or a method name for methods (but not parameters)
or a non-FQN name for classes.
getInsertPrefix
in interface CompletionItem