Search in sources :

Example 1 with TextEditorPane

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

the class FrmTextEditor method runPythonScript.

// GEN-LAST:event_formWindowClosing
private void runPythonScript() {
    SwingWorker worker = new SwingWorker<String, String>() {

        PrintStream oout = System.out;

        PrintStream oerr = System.err;

        @Override
        protected String doInBackground() throws Exception {
            interp.console.println("run script...");
            interp.console.setFocusable(true);
            interp.console.requestFocusInWindow();
            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) ByteArrayInputStream(java.io.ByteArrayInputStream) MITextEditorPane(org.meteoinfo.console.editor.MITextEditorPane) TextEditorPane(org.fife.ui.rsyntaxtextarea.TextEditorPane)

Example 2 with TextEditorPane

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

the class PythonGui method makeReadyForRelease.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.myrobotlab.swing.widget.ServiceGUI#makeReadyForRelease() Shutting
	 * down - check for dirty script and offer to save
	 */
@Override
public void makeReadyForRelease() {
    log.info("makeReadyForRelease");
    // Iterator<String> it = scripts.keySet().iterator();
    Iterator<Entry<String, EditorPanel>> it = scripts.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry pairs = it.next();
        TextEditorPane e = ((EditorPanel) pairs.getValue()).getEditor();
        log.info(String.format("checking script %s", e.getFileFullPath()));
        if (e.isDirty()) {
            try {
                log.info(String.format("saving script / file %s", e.getFileFullPath()));
                e.save();
            } catch (Exception ex) {
                Logging.logError(ex);
            }
        /*
				 * FileLocation fl = FileLocation.create(e.getFileFullPath());
				 * String filename =
				 * JOptionPane.showInputDialog(myService.getFrame(),
				 * "Save File?", name); if (filename != null) { fl =
				 * FileLocation.create(filename); try { e.saveAs(fl); } catch
				 * (IOException e1) { Logging.logException(e1); // TODO
				 * Auto-generated catch block } }
				 */
        }
    }
}
Also used : Entry(java.util.Map.Entry) Entry(java.util.Map.Entry) EditorPanel(org.myrobotlab.swing.widget.EditorPanel) TextEditorPane(org.fife.ui.rsyntaxtextarea.TextEditorPane) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with TextEditorPane

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

the class EditorConfigurer method addPopupOptions.

private static void addPopupOptions(TextEditorPane textArea) {
    JPopupMenu popupMenu = textArea.getPopupMenu();
    popupMenu.addSeparator();
    JMenuItem copySyntax = new JMenuItem("Copy with Syntax Higlighting");
    copySyntax.addActionListener(new GenericActionListener(e -> textArea.copyAsRtf()));
    popupMenu.add(copySyntax);
}
Also used : Color(java.awt.Color) TextEditorDemo(org.lara.interpreter.joptions.panels.editor.TextEditorDemo) UnicodeWriter(org.fife.io.UnicodeWriter) Completion(org.fife.ui.autocomplete.Completion) FileLocation(org.fife.ui.rsyntaxtextarea.FileLocation) SyntaxConstants(org.fife.ui.rsyntaxtextarea.SyntaxConstants) BasicCompletion(org.fife.ui.autocomplete.BasicCompletion) FoldParserManager(org.fife.ui.rsyntaxtextarea.folding.FoldParserManager) ArrayList(java.util.ArrayList) DefaultCompletionProvider(org.fife.ui.autocomplete.DefaultCompletionProvider) AutoCompletion(org.fife.ui.autocomplete.AutoCompletion) JMenuItem(javax.swing.JMenuItem) AbstractTokenMakerFactory(org.fife.ui.rsyntaxtextarea.AbstractTokenMakerFactory) FunctionCompletion(org.fife.ui.autocomplete.FunctionCompletion) CurlyFoldParser(org.fife.ui.rsyntaxtextarea.folding.CurlyFoldParser) SpecsIo(pt.up.fe.specs.util.SpecsIo) TokenMakerFactory(org.fife.ui.rsyntaxtextarea.TokenMakerFactory) JPopupMenu(javax.swing.JPopupMenu) DefaultEditorKit(javax.swing.text.DefaultEditorKit) IOException(java.io.IOException) CompletionProvider(org.fife.ui.autocomplete.CompletionProvider) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) Theme(org.fife.ui.rsyntaxtextarea.Theme) List(java.util.List) Parameter(org.fife.ui.autocomplete.ParameterizedCompletion.Parameter) SpecsLogs(pt.up.fe.specs.util.SpecsLogs) TextEditorPane(org.fife.ui.rsyntaxtextarea.TextEditorPane) SourceTextArea(org.lara.interpreter.joptions.panels.editor.tabbed.SourceTextArea) GenericActionListener(pt.up.fe.specs.util.swing.GenericActionListener) GenericActionListener(pt.up.fe.specs.util.swing.GenericActionListener) JMenuItem(javax.swing.JMenuItem) JPopupMenu(javax.swing.JPopupMenu)

Example 4 with TextEditorPane

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

the class EditorConfigurer method setSyntaxEditingStyle.

public static void setSyntaxEditingStyle(SourceTextArea sourceTextArea, File inputFile) {
    TextEditorPane textArea = sourceTextArea.getTextArea();
    // System.out.println(textArea.getDocument());
    String extension = SpecsIo.getExtension(inputFile);
    if (extension.isEmpty()) {
        textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_NONE);
    } else if (extension.equals("lara")) {
        setLaraTextArea(sourceTextArea);
    } else if (extension.equals("js")) {
        textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_JAVASCRIPT);
    } else if ((extension.equals("h"))) {
        textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_C);
    } else if ((extension.equals("hpp"))) {
        textArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_CPLUSPLUS);
    } else {
        textArea.setSyntaxEditingStyle("text/" + extension);
    }
}
Also used : TextEditorPane(org.fife.ui.rsyntaxtextarea.TextEditorPane)

Example 5 with TextEditorPane

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

the class EditorConfigurer method loadFile.

public static boolean loadFile(SourceTextArea sourceTextArea, File inputFile) {
    TextEditorPane textArea = sourceTextArea.getTextArea();
    if (inputFile.isDirectory()) {
        SpecsLogs.warn("Input file cannot be a directory: '" + SpecsIo.getCanonicalPath(inputFile) + "'\n");
        return false;
    }
    FileLocation location = FileLocation.create(inputFile);
    try {
        textArea.load(location, null);
        textArea.setEncoding(StandardCharsets.UTF_8.name());
        textArea.getDocument().putProperty(DefaultEditorKit.EndOfLineStringProperty, System.lineSeparator());
        setSyntaxEditingStyle(sourceTextArea, inputFile);
        return true;
    } catch (IOException e) {
        SpecsLogs.warn("Error message:\n", e);
    }
    return false;
}
Also used : FileLocation(org.fife.ui.rsyntaxtextarea.FileLocation) TextEditorPane(org.fife.ui.rsyntaxtextarea.TextEditorPane) IOException(java.io.IOException)

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