use of org.myrobotlab.swing.widget.EditorPanel 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.myrobotlab.swing.widget.EditorPanel in project myrobotlab by MyRobotLab.
the class PythonGui method actionPerformed.
@Override
public void actionPerformed(ActionEvent arg0) {
Object o = arg0.getSource();
if (o == stop) {
stop.activate();
send("stop");
send("attachPythonConsole");
return;
} else if (o == execute) {
execute.activate();
stop.deactivate();
// Hmm... noticed this is only local JVM
javaConsole.startLogging();
// :) the Python console can be pushed
// over the network
String currentScriptName = getSelected();
if (scripts.containsKey(currentScriptName)) {
EditorPanel p = scripts.get(currentScriptName);
send("exec", p.getText());
} else {
log.error(String.format("cant exec %s", currentScriptName));
}
return;
} else if (o == save) {
save();
return;
} else if (o == open) {
openFile();
return;
}
if (!(o instanceof JMenuItem)) {
return;
}
JMenuItem m = (JMenuItem) o;
if (m.getText().equals("new")) {
++untitledCount;
Script s = new Script(String.format("%s%suntitled.%d.py", Service.getCfgDir(), File.separator, untitledCount), "");
addNewEditorPanel(s);
} else if (m.getText().equals("save")) {
save();
} else if (m.getText().equals("open")) {
openFile();
} else if (m.getText().equals("save as")) {
saveAs();
} else if (m.getText().equals("close")) {
closeFile();
} else if (m.getActionCommand().equals("examples")) {
// } else if (m.getActionCommand().equals("examples")) {
// BareBonesBrowserLaunch.openURL("https://github.com/MyRobotLab/pyrobotlab");
/*
* String filename = String.format("Python/examples/%1$s",
* m.getText()); Script script = new Script(filename,
* FileIO.resourceToString(filename)); addNewEditorPanel(script);
*/
}
}
use of org.myrobotlab.swing.widget.EditorPanel in project myrobotlab by MyRobotLab.
the class PythonGui method saveAs.
public void saveAs() {
String currentScriptName = getSelected();
if (scripts.containsKey(currentScriptName)) {
EditorPanel p = scripts.get(currentScriptName);
// FIXME - don't create if not necessary
if (FileUtil.saveAs(jframe, p.getText(), currentScriptName)) {
currentScriptName = FileUtil.getLastFileSaved();
scripts.remove(p);
editorTabs.removeTab(currentScriptName);
EditorPanel np = addNewEditorPanel(new Script(currentScriptName, p.getText()));
editorTabs.setSelectedComponent(np.getDisplay());
}
} else {
log.error(String.format("cant saveAsFile %s", currentScriptName));
}
// TODO do we need to handle errors with permissions?
}
use of org.myrobotlab.swing.widget.EditorPanel in project myrobotlab by MyRobotLab.
the class PythonGui method closeFile.
public void closeFile() {
String currentScriptName = getSelected();
if (scripts.containsKey(currentScriptName)) {
EditorPanel p = scripts.get(currentScriptName);
if (p.isDirty()) {
saveAs();
}
p = scripts.get(currentScriptName);
scripts.remove(p);
editorTabs.removeTab(currentScriptName);
} else {
log.error(String.format("can't closeFile %s", currentScriptName));
}
}
use of org.myrobotlab.swing.widget.EditorPanel in project myrobotlab by MyRobotLab.
the class PythonGui method onAppendScript.
public void onAppendScript(String data) {
String currentScriptName = getSelected();
if (currentScriptName == null) {
error("no script selected to append");
return;
}
EditorPanel p = scripts.get(currentScriptName);
if (p != null) {
p.setText(String.format("%s\n%s", p.getText(), data));
} else {
info("can't append Script to current");
}
}
Aggregations