quickfix to allow running in headless mode

This commit is contained in:
Fredrik Osterlind 2012-03-23 09:55:36 +01:00
parent d716ee55e7
commit a9e36b0365

View file

@ -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,9 +90,14 @@ 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;
{ {
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
headless = ge.isHeadless();
if (!headless) {
DefaultSyntaxKit.initKit(); DefaultSyntaxKit.initKit();
} }
}
final String[] EXAMPLE_SCRIPTS = new String[] { final String[] EXAMPLE_SCRIPTS = new String[] {
"basic.js", "Various commands", "basic.js", "Various commands",
@ -158,10 +164,12 @@ 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");
if (e.getEditorKit() instanceof DefaultSyntaxKit) {
DefaultSyntaxKit kit = (DefaultSyntaxKit) e.getEditorKit(); DefaultSyntaxKit kit = (DefaultSyntaxKit) e.getEditorKit();
kit.setProperty("PopupMenu", "copy-to-clipboard,-,find,find-next,goto-line,-,linkfile"); kit.setProperty("PopupMenu", "copy-to-clipboard,-,find,find-next,goto-line,-,linkfile");
kit.setProperty("Action.linkfile", JSyntaxLinkFile.class.getName()); kit.setProperty("Action.linkfile", JSyntaxLinkFile.class.getName());
} }
}
/* Script area */ /* Script area */
setLayout(new BorderLayout()); setLayout(new BorderLayout());
@ -198,11 +206,14 @@ public class ScriptRunner extends VisPlugin {
); );
codeEditor.setContentType("text/javascript"); codeEditor.setContentType("text/javascript");
if (codeEditor.getEditorKit() instanceof DefaultSyntaxKit) {
DefaultSyntaxKit kit = (DefaultSyntaxKit) codeEditor.getEditorKit(); DefaultSyntaxKit kit = (DefaultSyntaxKit) codeEditor.getEditorKit();
kit.setProperty("PopupMenu", "copy-to-clipboard,-,find,find-next,goto-line,-,linkfile"); kit.setProperty("PopupMenu", "copy-to-clipboard,-,find,find-next,goto-line,-,linkfile");
kit.setProperty("Action.linkfile", JSyntaxLinkFile.class.getName()); kit.setProperty("Action.linkfile", JSyntaxLinkFile.class.getName());
}
JPopupMenu p = codeEditor.getComponentPopupMenu(); JPopupMenu p = codeEditor.getComponentPopupMenu();
if (p != null) {
for (Component c: p.getComponents()) { for (Component c: p.getComponents()) {
if (c instanceof JMenuItem) { if (c instanceof JMenuItem) {
if (((JMenuItem) c).getAction() != null && if (((JMenuItem) c).getAction() != null &&
@ -213,6 +224,7 @@ public class ScriptRunner extends VisPlugin {
} }
} }
} }
}
centerPanel.setOneTouchExpandable(true); centerPanel.setOneTouchExpandable(true);
centerPanel.setResizeWeight(0.5); centerPanel.setResizeWeight(0.5);
@ -328,12 +340,14 @@ public class ScriptRunner extends VisPlugin {
try { try {
engine.activateScript(codeEditor.getText()); engine.activateScript(codeEditor.getText());
if (!headless) {
actionLinkFile.setEnabled(false); actionLinkFile.setEnabled(false);
toggleButton.setText("Deactivate"); toggleButton.setText("Deactivate");
examplesButton.setEnabled(false); examplesButton.setEnabled(false);
logTextArea.setText(""); logTextArea.setText("");
codeEditor.setEnabled(false); codeEditor.setEnabled(false);
updateTitle(); updateTitle();
}
logger.info("Test script activated"); logger.info("Test script activated");
@ -371,13 +385,15 @@ public class ScriptRunner extends VisPlugin {
logWriter = null; logWriter = null;
} }
if (!headless) {
actionLinkFile.setEnabled(true); actionLinkFile.setEnabled(true);
toggleButton.setText("Activate"); toggleButton.setText("Activate");
examplesButton.setEnabled(linkedFile==null?true:false); examplesButton.setEnabled(linkedFile==null?true:false);
codeEditor.setEnabled(true); codeEditor.setEnabled(true);
logger.info("Test script deactivated");
updateTitle(); updateTitle();
} }
logger.info("Test script deactivated");
}
} }
private void updateTitle() { private void 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()