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.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.GraphicsEnvironment;
|
||||
import java.awt.Insets;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
@ -89,9 +90,14 @@ public class ScriptRunner extends VisPlugin {
|
|||
private static final long serialVersionUID = 7614358340336799109L;
|
||||
private static Logger logger = Logger.getLogger(ScriptRunner.class);
|
||||
|
||||
static boolean headless;
|
||||
{
|
||||
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
||||
headless = ge.isHeadless();
|
||||
if (!headless) {
|
||||
DefaultSyntaxKit.initKit();
|
||||
}
|
||||
}
|
||||
|
||||
final String[] EXAMPLE_SCRIPTS = new String[] {
|
||||
"basic.js", "Various commands",
|
||||
|
@ -158,10 +164,12 @@ public class ScriptRunner extends VisPlugin {
|
|||
JEditorPane e = new JEditorPane();
|
||||
new JScrollPane(e);
|
||||
e.setContentType("text/javascript");
|
||||
if (e.getEditorKit() instanceof DefaultSyntaxKit) {
|
||||
DefaultSyntaxKit kit = (DefaultSyntaxKit) e.getEditorKit();
|
||||
kit.setProperty("PopupMenu", "copy-to-clipboard,-,find,find-next,goto-line,-,linkfile");
|
||||
kit.setProperty("Action.linkfile", JSyntaxLinkFile.class.getName());
|
||||
}
|
||||
}
|
||||
|
||||
/* Script area */
|
||||
setLayout(new BorderLayout());
|
||||
|
@ -198,11 +206,14 @@ public class ScriptRunner extends VisPlugin {
|
|||
);
|
||||
|
||||
codeEditor.setContentType("text/javascript");
|
||||
if (codeEditor.getEditorKit() instanceof DefaultSyntaxKit) {
|
||||
DefaultSyntaxKit kit = (DefaultSyntaxKit) codeEditor.getEditorKit();
|
||||
kit.setProperty("PopupMenu", "copy-to-clipboard,-,find,find-next,goto-line,-,linkfile");
|
||||
kit.setProperty("Action.linkfile", JSyntaxLinkFile.class.getName());
|
||||
}
|
||||
|
||||
JPopupMenu p = codeEditor.getComponentPopupMenu();
|
||||
if (p != null) {
|
||||
for (Component c: p.getComponents()) {
|
||||
if (c instanceof JMenuItem) {
|
||||
if (((JMenuItem) c).getAction() != null &&
|
||||
|
@ -213,6 +224,7 @@ public class ScriptRunner extends VisPlugin {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
centerPanel.setOneTouchExpandable(true);
|
||||
centerPanel.setResizeWeight(0.5);
|
||||
|
@ -328,12 +340,14 @@ public class ScriptRunner extends VisPlugin {
|
|||
try {
|
||||
engine.activateScript(codeEditor.getText());
|
||||
|
||||
if (!headless) {
|
||||
actionLinkFile.setEnabled(false);
|
||||
toggleButton.setText("Deactivate");
|
||||
examplesButton.setEnabled(false);
|
||||
logTextArea.setText("");
|
||||
codeEditor.setEnabled(false);
|
||||
updateTitle();
|
||||
}
|
||||
|
||||
logger.info("Test script activated");
|
||||
|
||||
|
@ -371,13 +385,15 @@ public class ScriptRunner extends VisPlugin {
|
|||
logWriter = null;
|
||||
}
|
||||
|
||||
if (!headless) {
|
||||
actionLinkFile.setEnabled(true);
|
||||
toggleButton.setText("Activate");
|
||||
examplesButton.setEnabled(linkedFile==null?true:false);
|
||||
codeEditor.setEnabled(true);
|
||||
logger.info("Test script deactivated");
|
||||
updateTitle();
|
||||
}
|
||||
logger.info("Test script deactivated");
|
||||
}
|
||||
}
|
||||
|
||||
private void updateTitle() {
|
||||
|
@ -429,6 +445,7 @@ public class ScriptRunner extends VisPlugin {
|
|||
|
||||
String command[] = {
|
||||
"java",
|
||||
"-Djava.awt.headless=true",
|
||||
"-jar",
|
||||
"../dist/cooja.jar",
|
||||
"-nogui=" + configFile.getAbsolutePath()
|
||||
|
|
Loading…
Reference in a new issue