contentPane.add(new RTextScrollPane(textArea)); CompletionProvider provider = createCompletionProvider(); AutoCompletion ac = new AutoCompletion(provider); ac.setAutoActivationEnabled(true); ac.install(textArea);
/** * Creates an auto-completion instance pre-configured and usable by * most <code>LanguageSupport</code>s. * * @param p The completion provider. * @return The auto-completion instance. */ protected AutoCompletion createAutoCompletion(CompletionProvider p) { AutoCompletion ac = new AutoCompletion(p); ac.setListCellRenderer(getDefaultCompletionCellRenderer()); ac.setAutoCompleteEnabled(isAutoCompleteEnabled()); ac.setAutoActivationEnabled(isAutoActivationEnabled()); ac.setAutoActivationDelay(getAutoActivationDelay()); ac.setParameterAssistanceEnabled(isParameterAssistanceEnabled()); ac.setShowDescWindow(getShowDescWindow()); return ac; }
/** * Overridden to allow for prepending to the replacement text. This * allows us to insert fully qualified class names. instead of * unqualified ones, if necessary (i.e. if the user tries to * auto-complete <code>javax.swing.text.Document</code>, but they've * explicitly imported <code>org.w3c.dom.Document</code> - we need to * insert the fully qualified name in that case). */ @Override protected String getReplacementText(Completion c, Document doc, int start, int len) { String text = super.getReplacementText(c, doc, start, len); if (replacementTextPrefix!=null) { text = replacementTextPrefix + text; replacementTextPrefix = null; } return text; }
private void installAutoComplete() { AutoCompletion ac = new AutoCompletion(provider); ac.install(this); }
@Override public void actionPerformed(ActionEvent e) { if (isAutoCompleteEnabled()) { refreshPopupWindow(); } else if (oldTriggerAction != null) { oldTriggerAction.actionPerformed(e); } }
@Override public void install(RSyntaxTextArea textArea) { // We use a custom auto-completion. // AutoCompletion ac = createAutoCompletion(p); AutoCompletion ac = new JavaScriptAutoCompletion(provider, textArea); ac.setListCellRenderer(getDefaultCompletionCellRenderer()); ac.setAutoCompleteEnabled(isAutoCompleteEnabled()); ac.setAutoActivationEnabled(isAutoActivationEnabled()); ac.setAutoActivationDelay(getAutoActivationDelay()); ac.setParameterAssistanceEnabled(isParameterAssistanceEnabled()); ac.setExternalURLHandler(new JavaScriptDocUrlhandler(this)); ac.setShowDescWindow(getShowDescWindow()); ac.install(textArea); installImpl(textArea, ac); Listener listener = new Listener(textArea); textArea.putClientProperty(PROPERTY_LISTENER, listener); parser = new JavaScriptParser(this, textArea); textArea.putClientProperty(PROPERTY_LANGUAGE_PARSER, parser); textArea.addParser(parser); //textArea.setToolTipSupplier(provider); Info info = new Info(provider, parser); parserToInfoMap.put(parser, info); installKeyboardShortcuts(textArea); // Set XML on JavascriptTokenMaker JavaScriptTokenMaker.setE4xSupported(isXmlAvailable()); textArea.setLinkGenerator(new JavaScriptLinkGenerator(this)); }
@Override public void install(RSyntaxTextArea textArea) { // We use a custom auto-completion. AutoCompletion ac = createAutoCompletion(); ac.install(textArea); installImpl(textArea, ac); // Listener listener = new Listener(textArea); // textArea.putClientProperty(PROPERTY_LISTENER, listener); // // parser = new JavaScriptParser(this, textArea); // textArea.putClientProperty(PROPERTY_LANGUAGE_PARSER, parser); // textArea.addParser(parser); // //textArea.setToolTipSupplier(provider); // // Info info = new Info(provider, parser); // parserToInfoMap.put(parser, info); // installKeyboardShortcuts(textArea); // textArea.setLinkGenerator(new JavaScriptLinkGenerator(this)); }
@Override public void install(final RSyntaxTextArea rSyntaxTextArea) { final AutoCompletion ac = createAutoCompletion(getCompletionProvider()); ac.setAutoActivationDelay(100); ac.setAutoActivationEnabled(true); ac.setShowDescWindow(true); ac.install(rSyntaxTextArea); installImpl(rSyntaxTextArea, ac); rSyntaxTextArea.addKeyListener(new MacroAutoCompletionKeyListener(ac, rSyntaxTextArea)); rSyntaxTextArea.setToolTipSupplier(getMacroAutoCompletionProvider()); }
/** * Constructor. * * @param provider The completion provider. This cannot be <code>null</code> */ public AutoCompletion(CompletionProvider provider) { setChoicesWindowSize(350, 200); setDescriptionWindowSize(350, 250); setCompletionProvider(provider); setTriggerKey(getDefaultTriggerKey()); setAutoCompleteEnabled(true); setAutoCompleteSingleChoices(true); setAutoActivationEnabled(false); setShowDescWindow(false); setHideOnCompletionProviderChange(true); setHideOnNoText(true); parentWindowListener = new ParentWindowListener(); textComponentListener = new TextComponentListener(); autoActivationListener = new AutoActivationListener(); lafListener = new LookAndFeelChangeListener(); popupWindowListener = new PopupWindowListener(); listeners = new EventListenerList(); }
if (text == null && !isPopupVisible()) { return getLineOfCaret(); if (textLen == 0 && isHideOnNoText()) { if (isPopupVisible()) { hidePopupWindow(); return getLineOfCaret(); int count = completions==null ? 0 : completions.size(); if (count > 1 || (count == 1 && (isPopupVisible() || textLen == 0)) || (count == 1 && !getAutoCompleteSingleChoices())) { .applyComponentOrientation(getTextComponentOrientation()); if (renderer != null) { popupWindow.setListCellRenderer(renderer); r.y = p.y; popupWindow.setLocationRelativeTo(r); setPopupVisible(true); SwingUtilities.invokeLater(() -> insertCompletion(completions.get(0))); hidePopupWindow(); return getLineOfCaret();
/** * 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 void setAutoActivationEnabled(boolean enabled) { if (enabled!=autoActivationEnabled) { autoActivationEnabled = enabled; for (AutoCompletion ac : textAreaToAutoCompletion.values()) { ac.setAutoActivationEnabled(enabled); } } }
/** * Displays the popup window. Hosting applications can call this method to * programmatically begin an auto-completion operation. */ public void doCompletion() { refreshPopupWindow(); }
/** * 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>. */ protected final void insertCompletion(Completion c) { insertCompletion(c, false); }
@Override public void actionPerformed(ActionEvent e) { // Prevents keystrokes from messing up boolean wasVisible = hidePopupWindow(); // Only proceed if they were selecting a completion if (!wasVisible || !isParameterAssistanceEnabled()) { textComponent.replaceSelection(start); return; } Completion c = popupWindow.getSelection(); if (c instanceof ParameterizedCompletion) { // Should always be true // Fixes capitalization of the entered text. insertCompletion(c, true); } }
@Override public void setAutoActivationDelay(int ms) { ms = Math.max(0, ms); if (ms!=autoActivationDelay) { autoActivationDelay = ms; for (AutoCompletion ac : textAreaToAutoCompletion.values()) { ac.setAutoActivationDelay(autoActivationDelay); } } }
@Override public boolean isAutoActivateOkay(JTextComponent tc) { CompletionProvider provider = getProviderFor(tc); if (provider != null) { if (provider == provedorConclusaoCodigoBibliotecas) { delayAnterior = conclusaoCodigo.getAutoActivationDelay(); conclusaoCodigo.setAutoActivationDelay(50); } else { conclusaoCodigo.setAutoActivationDelay(delayAnterior); } return provider.isAutoActivateOkay(tc); } return false; } }
private AutoCompletion createAutoCompletion() { AutoCompletion ac = new AutoCompletion(provider); return ac; }
@Override public void setShowDescWindow(boolean show) { if (show!=showDescWindow) { showDescWindow = show; for (AutoCompletion ac : textAreaToAutoCompletion.values()) { ac.setShowDescWindow(show); } } }
/** * {@inheritDoc} */ @Override public void install(RSyntaxTextArea textArea) { JavaCompletionProvider p = new JavaCompletionProvider(jarManager); // Can't use createAutoCompletion(), as Java's is "special." AutoCompletion ac = new JavaAutoCompletion(p, textArea); ac.setListCellRenderer(new JavaCellRenderer()); ac.setAutoCompleteEnabled(isAutoCompleteEnabled()); ac.setAutoActivationEnabled(isAutoActivationEnabled()); ac.setAutoActivationDelay(getAutoActivationDelay()); ac.setExternalURLHandler(new JavadocUrlHandler()); ac.setParameterAssistanceEnabled(isParameterAssistanceEnabled()); ac.setParamChoicesRenderer(new JavaParamListCellRenderer()); ac.setShowDescWindow(getShowDescWindow()); ac.install(textArea); installImpl(textArea, ac); textArea.setToolTipSupplier(p); Listener listener = new Listener(textArea); textArea.putClientProperty(PROPERTY_LISTENER, listener); JavaParser parser = new JavaParser(textArea); textArea.putClientProperty(PROPERTY_LANGUAGE_PARSER, parser); textArea.addParser(parser); textArea.setToolTipSupplier(p); Info info = new Info(textArea, p, parser); parserToInfoMap.put(parser, info); installKeyboardShortcuts(textArea); textArea.setLinkGenerator(new JavaLinkGenerator(this)); }