quickfix to allow running in headless mode
This commit is contained in:
parent
d716ee55e7
commit
a9e36b0365
|
@ -34,6 +34,7 @@ package se.sics.cooja.plugins;
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Component;
|
import java.awt.Component;
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
|
import java.awt.GraphicsEnvironment;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
import java.awt.Window;
|
import java.awt.Window;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionEvent;
|
||||||
|
@ -89,8 +90,13 @@ public class ScriptRunner extends VisPlugin {
|
||||||
private static final long serialVersionUID = 7614358340336799109L;
|
private static final long serialVersionUID = 7614358340336799109L;
|
||||||
private static Logger logger = Logger.getLogger(ScriptRunner.class);
|
private static Logger logger = Logger.getLogger(ScriptRunner.class);
|
||||||
|
|
||||||
|
static boolean headless;
|
||||||
{
|
{
|
||||||
DefaultSyntaxKit.initKit();
|
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||||
|
headless = ge.isHeadless();
|
||||||
|
if (!headless) {
|
||||||
|
DefaultSyntaxKit.initKit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
final String[] EXAMPLE_SCRIPTS = new String[] {
|
final String[] EXAMPLE_SCRIPTS = new String[] {
|
||||||
|
@ -158,9 +164,11 @@ public class ScriptRunner extends VisPlugin {
|
||||||
JEditorPane e = new JEditorPane();
|
JEditorPane e = new JEditorPane();
|
||||||
new JScrollPane(e);
|
new JScrollPane(e);
|
||||||
e.setContentType("text/javascript");
|
e.setContentType("text/javascript");
|
||||||
DefaultSyntaxKit kit = (DefaultSyntaxKit) e.getEditorKit();
|
if (e.getEditorKit() instanceof DefaultSyntaxKit) {
|
||||||
kit.setProperty("PopupMenu", "copy-to-clipboard,-,find,find-next,goto-line,-,linkfile");
|
DefaultSyntaxKit kit = (DefaultSyntaxKit) e.getEditorKit();
|
||||||
kit.setProperty("Action.linkfile", JSyntaxLinkFile.class.getName());
|
kit.setProperty("PopupMenu", "copy-to-clipboard,-,find,find-next,goto-line,-,linkfile");
|
||||||
|
kit.setProperty("Action.linkfile", JSyntaxLinkFile.class.getName());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Script area */
|
/* Script area */
|
||||||
|
@ -198,18 +206,22 @@ public class ScriptRunner extends VisPlugin {
|
||||||
);
|
);
|
||||||
|
|
||||||
codeEditor.setContentType("text/javascript");
|
codeEditor.setContentType("text/javascript");
|
||||||
DefaultSyntaxKit kit = (DefaultSyntaxKit) codeEditor.getEditorKit();
|
if (codeEditor.getEditorKit() instanceof DefaultSyntaxKit) {
|
||||||
kit.setProperty("PopupMenu", "copy-to-clipboard,-,find,find-next,goto-line,-,linkfile");
|
DefaultSyntaxKit kit = (DefaultSyntaxKit) codeEditor.getEditorKit();
|
||||||
kit.setProperty("Action.linkfile", JSyntaxLinkFile.class.getName());
|
kit.setProperty("PopupMenu", "copy-to-clipboard,-,find,find-next,goto-line,-,linkfile");
|
||||||
|
kit.setProperty("Action.linkfile", JSyntaxLinkFile.class.getName());
|
||||||
|
}
|
||||||
|
|
||||||
JPopupMenu p = codeEditor.getComponentPopupMenu();
|
JPopupMenu p = codeEditor.getComponentPopupMenu();
|
||||||
for (Component c: p.getComponents()) {
|
if (p != null) {
|
||||||
if (c instanceof JMenuItem) {
|
for (Component c: p.getComponents()) {
|
||||||
if (((JMenuItem) c).getAction() != null &&
|
if (c instanceof JMenuItem) {
|
||||||
((JMenuItem) c).getAction() instanceof JSyntaxLinkFile) {
|
if (((JMenuItem) c).getAction() != null &&
|
||||||
actionLinkFile = (JSyntaxLinkFile)(((JMenuItem) c).getAction());
|
((JMenuItem) c).getAction() instanceof JSyntaxLinkFile) {
|
||||||
actionLinkFile.setMenuText("Link script to disk file");
|
actionLinkFile = (JSyntaxLinkFile)(((JMenuItem) c).getAction());
|
||||||
actionLinkFile.putValue("ScriptRunner", this);
|
actionLinkFile.setMenuText("Link script to disk file");
|
||||||
|
actionLinkFile.putValue("ScriptRunner", this);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -328,12 +340,14 @@ public class ScriptRunner extends VisPlugin {
|
||||||
try {
|
try {
|
||||||
engine.activateScript(codeEditor.getText());
|
engine.activateScript(codeEditor.getText());
|
||||||
|
|
||||||
actionLinkFile.setEnabled(false);
|
if (!headless) {
|
||||||
toggleButton.setText("Deactivate");
|
actionLinkFile.setEnabled(false);
|
||||||
examplesButton.setEnabled(false);
|
toggleButton.setText("Deactivate");
|
||||||
logTextArea.setText("");
|
examplesButton.setEnabled(false);
|
||||||
codeEditor.setEnabled(false);
|
logTextArea.setText("");
|
||||||
updateTitle();
|
codeEditor.setEnabled(false);
|
||||||
|
updateTitle();
|
||||||
|
}
|
||||||
|
|
||||||
logger.info("Test script activated");
|
logger.info("Test script activated");
|
||||||
|
|
||||||
|
@ -371,12 +385,14 @@ public class ScriptRunner extends VisPlugin {
|
||||||
logWriter = null;
|
logWriter = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
actionLinkFile.setEnabled(true);
|
if (!headless) {
|
||||||
toggleButton.setText("Activate");
|
actionLinkFile.setEnabled(true);
|
||||||
examplesButton.setEnabled(linkedFile==null?true:false);
|
toggleButton.setText("Activate");
|
||||||
codeEditor.setEnabled(true);
|
examplesButton.setEnabled(linkedFile==null?true:false);
|
||||||
|
codeEditor.setEnabled(true);
|
||||||
|
updateTitle();
|
||||||
|
}
|
||||||
logger.info("Test script deactivated");
|
logger.info("Test script deactivated");
|
||||||
updateTitle();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -429,6 +445,7 @@ public class ScriptRunner extends VisPlugin {
|
||||||
|
|
||||||
String command[] = {
|
String command[] = {
|
||||||
"java",
|
"java",
|
||||||
|
"-Djava.awt.headless=true",
|
||||||
"-jar",
|
"-jar",
|
||||||
"../dist/cooja.jar",
|
"../dist/cooja.jar",
|
||||||
"-nogui=" + configFile.getAbsolutePath()
|
"-nogui=" + configFile.getAbsolutePath()
|
||||||
|
|
Loading…
Reference in a new issue