/** * Overridden to display a short name for the completion, since it's * used in the tool tips for the "back" and "forward" buttons. * * @return A string representation of this history entry. */ @Override public String toString() { return completion.getInputText(); }
protected void checkProviderAndAdd(Completion c) { if (c.getProvider()!=this) { throw new IllegalArgumentException("Invalid CompletionProvider"); } completions.add(c); }
/** * Sets the icon to display based off of a completion, falling back to a * default icon if the completion has no icon. * * @param completion The completion to check. * @param defaultIcon The icon to use if <code>completion</code> does not * specify an icon. * @see #setIconWithDefault(Completion) */ protected void setIconWithDefault(Completion completion, Icon defaultIcon) { Icon icon = completion.getIcon(); setIcon(icon!=null ? icon : (defaultIcon!=null ? defaultIcon : emptyIcon)); }
@Override public int compare(Completion c1, Completion c2) { int rel1 = c1.getRelevance(); int rel2 = c2.getRelevance(); int diff = rel2 - rel1;//rel1 - rel2; return diff==0 ? c1.compareTo(c2) : diff; }
/** * Returns the text to replace with in the document. This is a "last-chance" * hook for subclasses to make special modifications to the completion text * inserted. The default implementation simply returns * <tt>c.getReplacementText()</tt>. You usually will not need to modify this * method. * * @param c The completion being inserted. * @param doc The document being modified. * @param start The start of the text being replaced. * @param len The length of the text being replaced. * @return The text to replace with. */ protected String getReplacementText(Completion c, Document doc, int start, int len) { return c.getReplacementText(); }
/** * Returns the tool tip to display for a mouse event.<p> * * For this method to be called, the <tt>RSyntaxTextArea</tt> must be * registered with the <tt>javax.swing.ToolTipManager</tt> like so: * * <pre> * ToolTipManager.sharedInstance().registerComponent(textArea); * </pre> * * @param textArea The text area. * @param e The mouse event. * @return The tool tip text, or <code>null</code> if none. */ @Override public String getToolTipText(RTextArea textArea, MouseEvent e) { String tip = null; List<Completion> completions = getCompletionsAt(textArea, e.getPoint()); if (completions!=null && completions.size()>0) { // Only ever 1 match for us in C... Completion c = completions.get(0); tip = c.getToolTipText(); } return tip; }
private void setDisplayedDesc(Completion completion, final String anchor, boolean addToHistory) { String desc = completion==null ? null : completion.getSummary(); if (desc==null) { desc = "<html><em>" + getString("NoDescAvailable") + "</em>"; } descArea.setText(desc); if (anchor!=null) { SwingUtilities.invokeLater(() -> descArea.scrollToReference(anchor)); } else { descArea.setCaretPosition(0); // In case of scrolling } if (!addToHistory) { // Remove everything first if this is going to be the only // thing in history. clearHistory(); } addToHistory(new HistoryEntry(completion, desc, null)); }
/** * Inserts a completion. Any time a code completion event occurs, the actual * text insertion happens through this method. * * @param c A completion to insert. This cannot be <code>null</code>. * @param typedParamListStartChar Whether the parameterized completion start * character was typed (typically <code>'('</code>). */ protected void insertCompletion(Completion c, boolean typedParamListStartChar) { JTextComponent textComp = getTextComponent(); String alreadyEntered = c.getAlreadyEntered(textComp); hidePopupWindow(); Caret caret = textComp.getCaret(); int dot = caret.getDot(); int len = alreadyEntered.length(); int start = dot - len; String replacement = getReplacementText(c, textComp.getDocument(), start, len); caret.setDot(start); caret.moveDot(dot); textComp.replaceSelection(replacement); if (isParameterAssistanceEnabled() && (c instanceof ParameterizedCompletion)) { ParameterizedCompletion pc = (ParameterizedCompletion) c; startParameterizedCompletionAssistance(pc, typedParamListStartChar); } }
@Override public int compare(Completion o1, Completion o2) { String name1 = o1.getReplacementText(); String name2 = o2.getReplacementText();
/** * Returns the tool tip to display for a mouse event. * <p> * For this method to be called, the <tt>RSyntaxTextArea</tt> must be * registered with the <tt>javax.swing.ToolTipManager</tt> like so: * </p> * * <pre> * ToolTipManager.sharedInstance().registerComponent(textArea); * </pre> * * @param textArea The text area. * @param e The mouse event. * @return The tool tip text, or <code>null</code> if none. */ @Override public String getToolTipText(final RTextArea textArea, final MouseEvent e) { String tip = null; final List<Completion> completions = // getCompletionsAt(textArea, e.getPoint()); if (completions != null && completions.size() > 0) { // Only ever 1 match for us in C... final Completion c = completions.get(0); tip = c.getToolTipText(); } return tip; }
@Override public int compare(Completion c1, Completion c2) { String s1 = c1.getInputText(); String s2 = c2.getInputText(); return String.CASE_INSENSITIVE_ORDER.compare(s1, s2); }
@Override protected String getReplacementText(Completion c, Document doc, int start, int len) { String texto = super.getReplacementText(c, doc, start, len); if (c.getProvider() instanceof ProvedorConclusaoCodigoBibliotecas) { try { texto = doc.getText(start, len); texto = texto.substring(0, texto.lastIndexOf(".")); texto = texto.concat(".").concat(super.getReplacementText(c, doc, start, len)); return texto; } catch (BadLocationException ex) { } } return texto; } }
String replacement = c.getReplacementText();
jsc = null; nonJavaCompletion = (Completion)value; setIcon(nonJavaCompletion.getIcon());
@Override public int compare(Object o1, Object o2) { String s1 = o1 instanceof String ? (String)o1 : ((Completion)o1).getInputText(); String s2 = o2 instanceof String ? (String)o2 : ((Completion)o2).getInputText(); return String.CASE_INSENSITIVE_ORDER.compare(s1, s2); }
@Override public Component getListCellRendererComponent(JList<?> list, Object value, int index, boolean selected, boolean hasFocus) { Completion c = (Completion)value; CompletionProvider p = c.getProvider(); ListCellRenderer<Object> r = p.getListCellRenderer(); if (r!=null) { return r.getListCellRendererComponent(list, value, index, selected, hasFocus); } if (fallback==null) { return super.getListCellRendererComponent(list, value, index, selected, hasFocus); } return fallback.getListCellRendererComponent(list, value, index, selected, hasFocus); }
if (choices!=null) { for (Completion c : choices) { String choice = c.getReplacementText(); if (prefix==null || Util.startsWithIgnoreCase(choice, prefix)) { temp.add(c);
setIcon(c.getIcon());
/** * Prepares this renderer to display a completion not specifically handled * elsewhere. * * @param list The list of choices being rendered. * @param c The completion to render. * @param index The index into <code>list</code> being rendered. * @param selected Whether the item is selected. * @param hasFocus Whether the item has focus. */ protected void prepareForOtherCompletion(JList list, Completion c, int index, boolean selected, boolean hasFocus) { StringBuilder sb = new StringBuilder(PREFIX); sb.append(c.getInputText()); if (c instanceof BasicCompletion) { String definition = ((BasicCompletion)c).getShortDescription(); if (definition!=null) { sb.append(" - "); if (!selected) { sb.append("<font color='").append(typeColor).append("'>"); } sb.append(definition); if (!selected) { sb.append("</font>"); } } } setText(sb.toString()); }
ClassFile cf = jls.getJarManager().getClassEntry(clazz); if (cf!=null) { ClassCompletion cc = new ClassCompletion(c.getProvider(), cf); callback.showSummaryFor(cc, anchor); ClassCompletion cc = new ClassCompletion(c.getProvider(), cf); callback.showSummaryFor(cc, null); FieldInfo fi = cf.getFieldInfoByName(member); if (fi!=null) { // Try fields first, it's most likely memberCompletion = new FieldCompletion(c.getProvider(), fi); if (miList!=null && miList.size()>0) { MethodInfo mi = miList.get(0);// Just show the first if multiple memberCompletion = new MethodCompletion(c.getProvider(), mi); memberCompletion = new MethodCompletion(c.getProvider(), mi);