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();
}
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 } }
*/
}
}
}
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);
}
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);
}
}
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;
}
Aggregations