Search in sources :

Example 21 with AutoCompletion

use of org.fife.ui.autocomplete.AutoCompletion in project lara-framework by specs-feup.

the class EditorConfigurer method setLaraTextArea.

public static void setLaraTextArea(SourceTextArea sourceTextArea) {
    TextEditorPane textArea = sourceTextArea.getTextArea();
    textArea.setSyntaxEditingStyle(TextEditorDemo.LARA_STYLE_KEY);
    CompletionProvider provider = EditorConfigurer.createCompletionProvider();
    AutoCompletion ac = new AutoCompletion(provider);
    ac.install(textArea);
    textArea.clearParsers();
    EditorParser parser = new EditorParser();
    textArea.addParser(parser);
    // adds a list of aspects to the aspect list pane whenever a parsing is performed
    parser.addListener(sourceTextArea::outlineAstListener);
}
Also used : DefaultCompletionProvider(org.fife.ui.autocomplete.DefaultCompletionProvider) CompletionProvider(org.fife.ui.autocomplete.CompletionProvider) AutoCompletion(org.fife.ui.autocomplete.AutoCompletion) TextEditorPane(org.fife.ui.rsyntaxtextarea.TextEditorPane)

Example 22 with AutoCompletion

use of org.fife.ui.autocomplete.AutoCompletion in project ultimate-cube by G3G4X5X6.

the class EditorPanel method autoSetSyntaxStyle.

private void autoSetSyntaxStyle(String title) {
    int index = title.lastIndexOf(".");
    if (index == -1) {
        if (title.equalsIgnoreCase("dockerfile")) {
            setSyntax("text/dockerfile");
        // String SYNTAX_STYLE_DOCKERFILE = "text/dockerfile";
        } else if (title.equalsIgnoreCase("hosts")) {
            // String SYNTAX_STYLE_HOSTS = "text/hosts";
            setSyntax("text/hosts");
        } else if (title.equalsIgnoreCase("makefile")) {
            // String SYNTAX_STYLE_MAKEFILE = "text/makefile";
            setSyntax("text/makefile");
        } else {
            // String SYNTAX_STYLE_UNIX_SHELL = "text/unix";
            // 默认:text/unix -> bash
            setSyntax("text/unix");
            icon = new FlatSVGIcon("icons/OpenTerminal_13x13.svg");
            ac = new AutoCompletion(new BashCompletionProvider());
            ac.install(textArea);
        }
    } else {
        // 造孽呀
        String ext = title.substring(title.lastIndexOf(".") + 1);
        switch(ext.toLowerCase()) {
            // String SYNTAX_STYLE_NONE = "text/plain";
            case "txt":
                setSyntax("text/plain");
                icon = new FlatSVGIcon("icons/file-text.svg");
                break;
            // String SYNTAX_STYLE_ACTIONSCRIPT = "text/actionscript";
            case "as":
                setSyntax("text/actionscript");
                icon = new FlatSVGIcon("icons/file-as.svg");
                break;
            // String SYNTAX_STYLE_ASSEMBLER_X86 = "text/asm";
            case "asm":
                setSyntax("text/asm");
                icon = new FlatSVGIcon("icons/asm.svg");
                break;
            // String SYNTAX_STYLE_ASSEMBLER_6502 = "text/asm6502";
            case "asm6502":
                setSyntax("text/asm6502");
                break;
            // String SYNTAX_STYLE_BBCODE = "text/bbcode";
            case "bbcode":
                setSyntax("text/bbcode");
                break;
            // String SYNTAX_STYLE_C = "text/c";
            case "c":
            case "h":
                setSyntax("text/c");
                break;
            // String SYNTAX_STYLE_CLOJURE = "text/clojure";
            case "clj":
                setSyntax("text/clojure");
                break;
            // String SYNTAX_STYLE_CPLUSPLUS = "text/cpp";
            case "cpp":
            case "hpp":
            case "cc":
                setSyntax("text/cpp");
                break;
            // String SYNTAX_STYLE_CSHARP = "text/cs";
            case "cs":
                setSyntax("text/cs");
                break;
            // String SYNTAX_STYLE_CSS = "text/css";
            case "css":
                setSyntax("text/css");
                icon = new FlatSVGIcon("icons/file-css.svg");
                break;
            // String SYNTAX_STYLE_CSV = "text/csv";
            case "csv":
                setSyntax("text/csv");
                break;
            // String SYNTAX_STYLE_D = "text/d";
            case "d":
                setSyntax("text/d");
                break;
            // String SYNTAX_STYLE_DART = "text/dart";
            case "dart":
                setSyntax("text/dart");
                break;
            // String SYNTAX_STYLE_DELPHI = "text/delphi";
            case "dpr":
            case "dfm":
            case "cfg":
            case "ddp ":
            case "pas":
                setSyntax("text/delphi");
                break;
            // String SYNTAX_STYLE_DTD = "text/dtd";
            case "dtd":
                setSyntax("text/dtd");
                icon = new FlatSVGIcon("icons/file-dtd.svg");
                break;
            // String SYNTAX_STYLE_FORTRAN = "text/fortran";
            case "f":
            case "f90":
            case "f95":
            case "for":
                setSyntax("text/fortran");
                break;
            // String SYNTAX_STYLE_GO = "text/golang";
            case "go":
                setSyntax("text/golang");
                icon = new FlatSVGIcon("icons/file-go.svg");
                break;
            // String SYNTAX_STYLE_GROOVY = "text/groovy";
            case "groovy":
                setSyntax("text/groovy");
                break;
            case "htaccess":
                setSyntax("text/htaccess");
                icon = new FlatSVGIcon("icons/file-htaccess.svg");
                break;
            // String SYNTAX_STYLE_HTML = "text/html";
            case "html":
            case // 模板文件
            "ftl":
                setSyntax("text/html");
                icon = new FlatSVGIcon("icons/file-html.svg");
                break;
            // String SYNTAX_STYLE_INI = "text/ini";
            case "ini":
                setSyntax("text/ini");
                break;
            // String SYNTAX_STYLE_JAVA = "text/java";
            case "java":
                setSyntax("text/java");
                icon = new FlatSVGIcon("icons/file-java.svg");
                ac = new AutoCompletion(new JavaCompletionProvider());
                ac.install(textArea);
                break;
            // String SYNTAX_STYLE_JAVASCRIPT = "text/javascript";
            case "js":
                setSyntax("text/javascript");
                icon = new FlatSVGIcon("icons/file-js.svg");
                break;
            // String SYNTAX_STYLE_JSON = "text/json";
            case "json":
                setSyntax("text/json");
                icon = new FlatSVGIcon("icons/file-json.svg");
                break;
            // String SYNTAX_STYLE_JSON_WITH_COMMENTS = "text/jshintrc";
            case "jshintrc":
                setSyntax("text/jshintrc");
                break;
            // String SYNTAX_STYLE_JSP = "text/jsp";
            case "jsp":
                setSyntax("text/jsp");
                icon = new FlatSVGIcon("icons/file-jsp.svg");
                break;
            // String SYNTAX_STYLE_KOTLIN = "text/kotlin";
            case "kt":
                setSyntax("text/kotlin");
                icon = new FlatSVGIcon("icons/file-kotlin.svg");
                break;
            // String SYNTAX_STYLE_LATEX = "text/latex";
            case "latex":
            case "tex":
            case "sty":
            case "cls":
            case "bib":
            case "bst":
                setSyntax("text/latex");
                break;
            // String SYNTAX_STYLE_LESS = "text/less";
            case "less":
                setSyntax("text/less");
                break;
            // String SYNTAX_STYLE_LISP = "text/lisp";
            case "lisp":
                setSyntax("text/lisp");
                break;
            // String SYNTAX_STYLE_LUA = "text/lua";
            case "lua":
                setSyntax("text/lua");
                break;
            // String SYNTAX_STYLE_MARKDOWN = "text/markdown";
            case "md":
                setSyntax("text/markdown");
                icon = new FlatSVGIcon("icons/MarkdownPlugin.svg");
                break;
            // String SYNTAX_STYLE_MXML = "text/mxml";
            case "mxml":
                setSyntax("text/mxml");
                break;
            // String SYNTAX_STYLE_NSIS = "text/nsis";
            case "nsis":
                setSyntax("text/nsis");
                break;
            // String SYNTAX_STYLE_PERL = "text/perl";
            case "pl":
                setSyntax("text/perl");
                break;
            // String SYNTAX_STYLE_PHP = "text/php";
            case "php":
                setSyntax("text/php");
                break;
            // String SYNTAX_STYLE_PROPERTIES_FILE = "text/properties";
            case "properties":
                setSyntax("text/properties");
                break;
            // String SYNTAX_STYLE_PYTHON = "text/python";
            case "py":
                setSyntax("text/python");
                icon = new FlatSVGIcon("icons/file-python.svg");
                break;
            // String SYNTAX_STYLE_RUBY = "text/ruby";
            case "rb":
                setSyntax("text/ruby");
                break;
            // String SYNTAX_STYLE_SAS = "text/sas";
            case "sas":
                setSyntax("text/sas");
                break;
            // String SYNTAX_STYLE_SCALA = "text/scala";
            case "scala":
                setSyntax("text/scala");
                break;
            // String SYNTAX_STYLE_SQL = "text/sql";
            case "sql":
                setSyntax("text/sql");
                break;
            // String SYNTAX_STYLE_TCL = "text/tcl";
            case "tcl":
                setSyntax("text/tcl");
                break;
            // String SYNTAX_STYLE_TYPESCRIPT = "text/typescript";
            case "ts":
                setSyntax("text/typescript");
                icon = new FlatSVGIcon("icons/file-ts.svg");
                break;
            // String SYNTAX_STYLE_UNIX_SHELL = "text/unix";
            case "sh":
            case "rc":
            case "bashrc":
            case "profile":
            case "viminfo":
            case "bash_logout":
            case "bash_history":
            case "bash_profile":
                setSyntax("text/unix");
                icon = new FlatSVGIcon("icons/OpenTerminal_13x13.svg");
                ac = new AutoCompletion(new BashCompletionProvider());
                ac.install(textArea);
                break;
            // String SYNTAX_STYLE_VISUAL_BASIC = "text/vb";
            case "vb":
                setSyntax("text/vb");
                break;
            // String SYNTAX_STYLE_WINDOWS_BATCH = "text/bat";
            case "bat":
                setSyntax("text/bat");
                break;
            // String SYNTAX_STYLE_XML = "text/xml";
            case "xml":
                setSyntax("text/xml");
                icon = new FlatSVGIcon("icons/file-xml.svg");
                break;
            // String SYNTAX_STYLE_YAML = "text/yaml";
            case "yaml":
            case "yml":
                setSyntax("text/yaml");
                icon = new FlatSVGIcon("icons/file-yaml.svg");
                break;
        }
    }
    if (ac != null) {
        // TODO 快捷键与自动激活作为一个用户设置,二选一
        // ac.setAutoActivationEnabled(true);  // 找到唯一符合的关键字,将直接自动完成
        ac.setTriggerKey(KeyStroke.getKeyStroke(KeyEvent.VK_I, InputEvent.CTRL_DOWN_MASK));
        log.debug("setAutoActivationEnabled");
    }
}
Also used : AutoCompletion(org.fife.ui.autocomplete.AutoCompletion) BashCompletionProvider(com.g3g4x5x6.editor.provider.BashCompletionProvider) FlatSVGIcon(com.formdev.flatlaf.extras.FlatSVGIcon) JavaCompletionProvider(com.g3g4x5x6.editor.provider.JavaCompletionProvider)

Example 23 with AutoCompletion

use of org.fife.ui.autocomplete.AutoCompletion in project maptool by RPTools.

the class MacroButtonDialog method initCommandTextArea.

private void initCommandTextArea() {
    AbstractTokenMakerFactory atmf = (AbstractTokenMakerFactory) TokenMakerFactory.getDefaultInstance();
    atmf.putMapping("text/MapToolScript", "net.rptools.maptool.client.ui.syntax.MapToolScriptSyntax");
    // Expanding use of tooltip - already accepts HTML so lets show it
    getToolTipTextField().setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_HTML);
    getToolTipTextField().setLineWrap(true);
    getToolTipTextField().setWrapStyleWord(true);
    getToolTipTextField().setTabSize(2);
    // Macro Editor setup
    macroEditorRSyntaxTextArea.setSyntaxEditingStyle("text/MapToolScript");
    macroEditorRSyntaxTextArea.setEditable(true);
    macroEditorRSyntaxTextArea.setCodeFoldingEnabled(true);
    macroEditorRSyntaxTextArea.setLineWrap(true);
    macroEditorRSyntaxTextArea.setWrapStyleWord(true);
    macroEditorRSyntaxTextArea.setTabSize(4);
    FoldParserManager.get().addFoldParserMapping("text/MapToolScript", new CurlyFoldParser());
    // https://stackoverflow.com/questions/39613186/how-to-add-keywords-for-rsyntaxtextarea-for-syntax-highlighting
    CompletionProvider provider = new MapToolScriptAutoComplete().get();
    AutoCompletion ac = new AutoCompletion(provider);
    ac.setAutoCompleteEnabled(true);
    ac.setAutoActivationEnabled(true);
    ac.setAutoActivationDelay(500);
    ac.setShowDescWindow(true);
    ac.setAutoCompleteSingleChoices(false);
    ac.install(macroEditorRSyntaxTextArea);
    // Set the color style via Theme
    try {
        File themeFile = new File(AppConstants.THEMES_DIR, AppPreferences.getDefaultMacroEditorTheme() + ".xml");
        Theme theme = Theme.load(new FileInputStream(themeFile));
        theme.apply(macroEditorRSyntaxTextArea);
        theme.apply(getToolTipTextField());
        macroEditorRSyntaxTextArea.revalidate();
    } catch (IOException e) {
        e.printStackTrace();
    }
    // Listen for changes in the text
    macroEditorRSyntaxTextArea.getDocument().addDocumentListener(new DocumentListener() {

        @Override
        public void changedUpdate(DocumentEvent e) {
            status.setText(READY);
        }

        @Override
        public void removeUpdate(DocumentEvent e) {
            status.setText(READY);
        }

        @Override
        public void insertUpdate(DocumentEvent e) {
            status.setText(READY);
        }
    });
    csp = new CollapsibleSectionPanel();
    ((GridView) panel.getComponentByName("macroEditorPanel")).add(csp);
    csp.add(new ErrorStrip(macroEditorRSyntaxTextArea), BorderLayout.LINE_END);
    RTextScrollPane macroEditorRTextScrollPane = new RTextScrollPane(macroEditorRSyntaxTextArea);
    macroEditorRTextScrollPane.setLineNumbersEnabled(true);
    // replaceComponent("macroEditorPanel", "macroEditorRTextScrollPane",
    // macroEditorRTextScrollPane);
    csp.add(new ErrorStrip(getToolTipTextField()), BorderLayout.LINE_END);
    // RTextScrollPane macroEditorRTextScrollPane = new
    // RTextScrollPane(macroEditorRSyntaxTextArea);
    // macroEditorRTextScrollPane.setLineNumbersEnabled(true);
    csp.add(macroEditorRTextScrollPane);
}
Also used : CurlyFoldParser(org.fife.ui.rsyntaxtextarea.folding.CurlyFoldParser) AutoCompletion(org.fife.ui.autocomplete.AutoCompletion) DocumentListener(javax.swing.event.DocumentListener) AbstractTokenMakerFactory(org.fife.ui.rsyntaxtextarea.AbstractTokenMakerFactory) CollapsibleSectionPanel(org.fife.rsta.ui.CollapsibleSectionPanel) IOException(java.io.IOException) DocumentEvent(javax.swing.event.DocumentEvent) FileInputStream(java.io.FileInputStream) CompletionProvider(org.fife.ui.autocomplete.CompletionProvider) Theme(org.fife.ui.rsyntaxtextarea.Theme) MapToolScriptAutoComplete(net.rptools.maptool.client.ui.syntax.MapToolScriptAutoComplete) GridView(com.jeta.forms.gui.form.GridView) File(java.io.File) RTextScrollPane(org.fife.ui.rtextarea.RTextScrollPane) ErrorStrip(org.fife.ui.rsyntaxtextarea.ErrorStrip)

Aggregations

AutoCompletion (org.fife.ui.autocomplete.AutoCompletion)23 CompletionProvider (org.fife.ui.autocomplete.CompletionProvider)9 DefaultCompletionProvider (org.fife.ui.autocomplete.DefaultCompletionProvider)9 IOException (java.io.IOException)6 KeyStroke (javax.swing.KeyStroke)6 BadLocationException (javax.swing.text.BadLocationException)5 Method (java.lang.reflect.Method)4 Semaphore (java.util.concurrent.Semaphore)4 RSyntaxTextArea (org.fife.ui.rsyntaxtextarea.RSyntaxTextArea)4 RTextScrollPane (org.fife.ui.rtextarea.RTextScrollPane)3 JTextComponent (javax.swing.text.JTextComponent)2 CollapsibleSectionPanel (org.fife.rsta.ui.CollapsibleSectionPanel)2 FlatSVGIcon (com.formdev.flatlaf.extras.FlatSVGIcon)1 BashCompletionProvider (com.g3g4x5x6.editor.provider.BashCompletionProvider)1 JavaCompletionProvider (com.g3g4x5x6.editor.provider.JavaCompletionProvider)1 NucleiYamlCompletionProvider (com.g3g4x5x6.nuclei.NucleiYamlCompletionProvider)1 GridView (com.jeta.forms.gui.form.GridView)1 Font (java.awt.Font)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1