Search in sources :

Example 6 with TextEditorPane

use of org.fife.ui.rsyntaxtextarea.TextEditorPane in project lara-framework by specs-feup.

the class EditorConfigurer method buildTextArea.

/**
 * Build a text area according to the type of the input file
 *
 * @param inputFile
 * @param sourceTextArea
 * @return
 */
public TextEditorPane buildTextArea(File inputFile, boolean isNew, SourceTextArea sourceTextArea) {
    TextEditorPane textArea = new TextEditorPane();
    sourceTextArea.setTextArea(textArea);
    // textArea.setFont(textArea.getFont().deriveFont(12f));
    if (theme != null) {
        theme.apply(textArea);
    }
    textArea.setMarkAllHighlightColor(MARK_ALL_COLOR);
    addPopupOptions(textArea);
    // Add folding
    textArea.setCodeFoldingEnabled(true);
    textArea.setAntiAliasingEnabled(true);
    loadFile(sourceTextArea, inputFile);
    return textArea;
}
Also used : TextEditorPane(org.fife.ui.rsyntaxtextarea.TextEditorPane)

Example 7 with TextEditorPane

use of org.fife.ui.rsyntaxtextarea.TextEditorPane in project MeteoInfo by meteoinfo.

the class EditorDockable method runPythonScript.

/**
 * Run Jython script
 *
 * @param jTextArea_Output
 */
public void runPythonScript(final JTextArea jTextArea_Output) {
    SwingWorker worker = new SwingWorker<String, String>() {

        PrintStream oout = System.out;

        PrintStream oerr = System.err;

        @Override
        protected String doInBackground() throws Exception {
            JTextAreaWriter writer = new JTextAreaWriter(jTextArea_Output);
            JTextAreaPrintStream printStream = new JTextAreaPrintStream(System.out, jTextArea_Output);
            jTextArea_Output.setText("");
            // Create an instance of the PythonInterpreter
            // Py.getSystemState().setdefaultencoding("utf-8");
            // UPythonInterpreter interp = new UPythonInterpreter();
            PythonInterpreter interp = new PythonInterpreter();
            interp.setOut(writer);
            interp.setErr(writer);
            System.setOut(printStream);
            System.setErr(printStream);
            // }
            try {
                interp.exec("import sys");
                interp.set("milapp", EditorDockable.this.parent);
            // interp.exec("sys.path.append('" + path + "')");
            // interp.exec("import mipylib");
            // interp.exec("from mipylib.miscript import *");
            // interp.exec("from meteoinfo.numeric.JNumeric import *");
            // interp.exec("mis = MeteoInfoScript()");
            // interp.set("miapp", _parent);
            // for (String jarfn : jarfns) {
            // interp.exec("sys.path.append('" + jarfn + "')");
            // }
            } catch (Exception e) {
                e.printStackTrace();
            }
            TextEditorPane textArea = getActiveTextArea();
            // textArea.setEncoding(fn);
            String code = textArea.getText();
            // if (code.contains("coding=utf-8")){
            // code = code.replace("coding=utf-8", "coding = utf-8");
            // }
            String encoding = EncodingUtil.findEncoding(code);
            if (encoding != null) {
                try {
                    interp.execfile(new ByteArrayInputStream(code.getBytes(encoding)));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            } else {
                try {
                    interp.execfile(new ByteArrayInputStream(code.getBytes()));
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            return "";
        }

        @Override
        protected void done() {
            System.setOut(oout);
            System.setErr(oerr);
        }
    };
    worker.execute();
}
Also used : PrintStream(java.io.PrintStream) JTextAreaPrintStream(org.meteoinfo.console.editor.JTextAreaPrintStream) PythonInterpreter(org.python.util.PythonInterpreter) JTextAreaPrintStream(org.meteoinfo.console.editor.JTextAreaPrintStream) ByteArrayInputStream(java.io.ByteArrayInputStream) SwingWorker(javax.swing.SwingWorker) MITextEditorPane(org.meteoinfo.console.editor.MITextEditorPane) TextEditorPane(org.fife.ui.rsyntaxtextarea.TextEditorPane) JTextAreaWriter(org.meteoinfo.console.editor.JTextAreaWriter) IOException(java.io.IOException) BadLocationException(javax.swing.text.BadLocationException) AWTException(java.awt.AWTException)

Example 8 with TextEditorPane

use of org.fife.ui.rsyntaxtextarea.TextEditorPane in project lara-framework by specs-feup.

the class OutlinePanel method selectionHandler.

private void selectionHandler(ListSelectionEvent e) {
    // if (listModel.isEmpty()) {
    // return;
    // }
    OutlineElement element = list.getSelectedValue();
    if (element == null) {
        return;
    }
    int line = element.getLine();
    try {
        TextEditorPane laraTextArea = editor.getTabsContainer().getCurrentTab().getTextArea();
        laraTextArea.setCaretPosition(laraTextArea.getLineStartOffset(line - 1));
    } catch (BadLocationException e1) {
    }
}
Also used : TextEditorPane(org.fife.ui.rsyntaxtextarea.TextEditorPane) BadLocationException(javax.swing.text.BadLocationException)

Example 9 with TextEditorPane

use of org.fife.ui.rsyntaxtextarea.TextEditorPane 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 10 with TextEditorPane

use of org.fife.ui.rsyntaxtextarea.TextEditorPane in project myrobotlab by MyRobotLab.

the class ArduinoGui method addMrlCommPanel.

public void addMrlCommPanel() {
    JPanel uploadPanel = new JPanel(new BorderLayout());
    String pathToMrlComm = null;
    String mrlIno = null;
    try {
        pathToMrlComm = "resource/Arduino/MrlComm/MrlComm.ino";
        mrlIno = FileIO.toString(pathToMrlComm);
    } catch (Exception e) {
    }
    try {
        if (mrlIno == null) {
            pathToMrlComm = "src/resource/Arduino/MrlComm/MrlComm.ino";
            mrlIno = FileIO.toString(pathToMrlComm);
        }
    } catch (Exception e) {
    }
    GridBagConstraints gc = new GridBagConstraints();
    gc.gridx = 0;
    gc.gridy = 0;
    JPanel top = new JPanel(new GridBagLayout());
    top.add(new JLabel("Arduino IDE Path "), gc);
    gc.gridx++;
    top.add(arduinoPath, gc);
    gc.gridx++;
    if (chooser == null) {
        chooser = new FileChooser("browse", arduinoPath);
        chooser.filterDirsOnly();
    }
    top.add(chooser, gc);
    gc.gridx++;
    top.add(openMrlComm, gc);
    gc.gridx++;
    top.add(uploadMrlComm, gc);
    gc.gridx++;
    gc.gridx = 0;
    gc.gridy = 1;
    gc.gridwidth = 2;
    top.add(new JLabel("MrlComm.ino location "), gc);
    gc.gridx += 2;
    top.add(new JLabel(pathToMrlComm), gc);
    uploadPanel.add(top, BorderLayout.NORTH);
    editor = new TextEditorPane();
    // editor.setPreferredSize(new Dimension(500, 400));
    editor.setText(mrlIno);
    editor.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_CPLUSPLUS);
    editor.setCodeFoldingEnabled(true);
    editor.setAntiAliasingEnabled(true);
    editor.setEnabled(false);
    editor.setReadOnly(true);
    RTextScrollPane pane = new RTextScrollPane(editor);
    pane.setPreferredSize(new Dimension(500, 400));
    uploadPanel.add(pane, BorderLayout.CENTER);
    JScrollPane pane2 = new JScrollPane(uploadResults);
    uploadPanel.add(pane2, BorderLayout.SOUTH);
    localTabs.addTab("upload", uploadPanel);
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) BorderLayout(java.awt.BorderLayout) GridBagLayout(java.awt.GridBagLayout) FileChooser(org.myrobotlab.swing.widget.FileChooser) JLabel(javax.swing.JLabel) TextEditorPane(org.fife.ui.rsyntaxtextarea.TextEditorPane) Dimension(java.awt.Dimension) RTextScrollPane(org.fife.ui.rtextarea.RTextScrollPane)

Aggregations

TextEditorPane (org.fife.ui.rsyntaxtextarea.TextEditorPane)10 IOException (java.io.IOException)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 PrintStream (java.io.PrintStream)2 BadLocationException (javax.swing.text.BadLocationException)2 AutoCompletion (org.fife.ui.autocomplete.AutoCompletion)2 CompletionProvider (org.fife.ui.autocomplete.CompletionProvider)2 DefaultCompletionProvider (org.fife.ui.autocomplete.DefaultCompletionProvider)2 FileLocation (org.fife.ui.rsyntaxtextarea.FileLocation)2 MITextEditorPane (org.meteoinfo.console.editor.MITextEditorPane)2 AWTException (java.awt.AWTException)1 BorderLayout (java.awt.BorderLayout)1 Color (java.awt.Color)1 Dimension (java.awt.Dimension)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 File (java.io.File)1 StandardCharsets (java.nio.charset.StandardCharsets)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1