Search in sources :

Example 1 with CurlyFoldParser

use of org.fife.ui.rsyntaxtextarea.folding.CurlyFoldParser 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

GridView (com.jeta.forms.gui.form.GridView)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 DocumentEvent (javax.swing.event.DocumentEvent)1 DocumentListener (javax.swing.event.DocumentListener)1 MapToolScriptAutoComplete (net.rptools.maptool.client.ui.syntax.MapToolScriptAutoComplete)1 CollapsibleSectionPanel (org.fife.rsta.ui.CollapsibleSectionPanel)1 AutoCompletion (org.fife.ui.autocomplete.AutoCompletion)1 CompletionProvider (org.fife.ui.autocomplete.CompletionProvider)1 AbstractTokenMakerFactory (org.fife.ui.rsyntaxtextarea.AbstractTokenMakerFactory)1 ErrorStrip (org.fife.ui.rsyntaxtextarea.ErrorStrip)1 Theme (org.fife.ui.rsyntaxtextarea.Theme)1 CurlyFoldParser (org.fife.ui.rsyntaxtextarea.folding.CurlyFoldParser)1 RTextScrollPane (org.fife.ui.rtextarea.RTextScrollPane)1