mirror of
https://github.com/oliverschmidt/contiki.git
synced 2024-09-01 02:29:03 +00:00
minor fixes: remember last used test, respect maximum window size etc
This commit is contained in:
parent
3a6e561ea8
commit
2768a96b9b
@ -26,16 +26,18 @@
|
|||||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*
|
*
|
||||||
* $Id: ScriptRunner.java,v 1.16 2009/03/22 14:05:19 fros4943 Exp $
|
* $Id: ScriptRunner.java,v 1.17 2009/04/23 08:54:10 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.plugins;
|
package se.sics.cooja.plugins;
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Dimension;
|
||||||
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;
|
||||||
import java.awt.event.ActionListener;
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@ -49,6 +51,7 @@ import java.io.InputStreamReader;
|
|||||||
import java.io.OutputStreamWriter;
|
import java.io.OutputStreamWriter;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import javax.script.ScriptException;
|
import javax.script.ScriptException;
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import javax.swing.event.DocumentEvent;
|
import javax.swing.event.DocumentEvent;
|
||||||
@ -95,6 +98,9 @@ public class ScriptRunner implements Plugin {
|
|||||||
"log.log(\"waiting for hello world output from mote 1\\n\");\n" +
|
"log.log(\"waiting for hello world output from mote 1\\n\");\n" +
|
||||||
"WAIT_UNTIL(id == 1 && msg.equals(\"Hello, world\"));\n" +
|
"WAIT_UNTIL(id == 1 && msg.equals(\"Hello, world\"));\n" +
|
||||||
"\n" +
|
"\n" +
|
||||||
|
"GENERATE_MSG(15000, \"continue\");\n" +
|
||||||
|
"WAIT_UNTIL(msg.equals(\"continue\"));\n" +
|
||||||
|
"\n" +
|
||||||
"log.log(\"ok, reporting success now\\n\");\n" +
|
"log.log(\"ok, reporting success now\\n\");\n" +
|
||||||
"log.testOK(); /* Report test success and quit */\n" +
|
"log.testOK(); /* Report test success and quit */\n" +
|
||||||
"//log.testFailed(); /* Report test failure and quit */\n";
|
"//log.testFailed(); /* Report test failure and quit */\n";
|
||||||
@ -223,9 +229,8 @@ public class ScriptRunner implements Plugin {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
JButton importButton = new JButton("Import Contiki test");
|
Action importAction = new AbstractAction() {
|
||||||
importButton.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
||||||
public void actionPerformed(ActionEvent ev) {
|
|
||||||
Runnable doImport = new Runnable() {
|
Runnable doImport = new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
setScriptActive(false);
|
setScriptActive(false);
|
||||||
@ -234,14 +239,23 @@ public class ScriptRunner implements Plugin {
|
|||||||
};
|
};
|
||||||
new Thread(doImport).start();
|
new Thread(doImport).start();
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
JButton importButton = new JButton(importAction);
|
||||||
|
importButton.setText("Import Contiki test Ctrl+I");
|
||||||
|
InputMap inputMap = importButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
|
||||||
|
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_I, KeyEvent.CTRL_DOWN_MASK, false), "import");
|
||||||
|
importButton.getActionMap().put("import", importAction);
|
||||||
|
|
||||||
JButton exportButton = new JButton("Export as Contiki test");
|
Action exportAction = new AbstractAction() {
|
||||||
exportButton.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
||||||
public void actionPerformed(ActionEvent ev) {
|
|
||||||
exportAsContikiTest();
|
exportAsContikiTest();
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
JButton exportButton = new JButton(exportAction);
|
||||||
|
exportButton.setText("Export as Contiki test Ctrl+O");
|
||||||
|
inputMap = exportButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
|
||||||
|
inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_DOWN_MASK, false), "export");
|
||||||
|
exportButton.getActionMap().put("export", exportAction);
|
||||||
|
|
||||||
|
|
||||||
JPanel scriptArea = new JPanel(new BorderLayout());
|
JPanel scriptArea = new JPanel(new BorderLayout());
|
||||||
@ -269,6 +283,13 @@ public class ScriptRunner implements Plugin {
|
|||||||
pluginGUI.getContentPane().add(BorderLayout.SOUTH, southPanel);
|
pluginGUI.getContentPane().add(BorderLayout.SOUTH, southPanel);
|
||||||
|
|
||||||
pluginGUI.pack();
|
pluginGUI.pack();
|
||||||
|
Dimension maxSize = gui.getDesktopPane().getSize();
|
||||||
|
if (pluginGUI.getWidth() > maxSize.getWidth()) {
|
||||||
|
pluginGUI.setSize((int)maxSize.getWidth(), pluginGUI.getHeight());
|
||||||
|
}
|
||||||
|
if (pluginGUI.getHeight() > maxSize.getHeight()) {
|
||||||
|
pluginGUI.setSize(pluginGUI.getWidth(), (int)maxSize.getHeight());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setScriptActive(boolean active) {
|
private void setScriptActive(boolean active) {
|
||||||
@ -284,15 +305,20 @@ public class ScriptRunner implements Plugin {
|
|||||||
});
|
});
|
||||||
try {
|
try {
|
||||||
engine.activateScript(scriptTextArea.getText());
|
engine.activateScript(scriptTextArea.getText());
|
||||||
|
|
||||||
|
toggleButton.setText("Deactivate");
|
||||||
|
logTextArea.setText("");
|
||||||
|
scriptTextArea.setEnabled(false);
|
||||||
|
|
||||||
|
logger.info("Test script activated");
|
||||||
|
|
||||||
} catch (ScriptException e) {
|
} catch (ScriptException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
setScriptActive(false);
|
setScriptActive(false);
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
setScriptActive(false);
|
||||||
}
|
}
|
||||||
toggleButton.setText("Deactivate");
|
|
||||||
logTextArea.setText("");
|
|
||||||
scriptTextArea.setEnabled(false);
|
|
||||||
|
|
||||||
logger.info("Test script activated");
|
|
||||||
} else {
|
} else {
|
||||||
if (engine != null) {
|
if (engine != null) {
|
||||||
engine.deactivateScript();
|
engine.deactivateScript();
|
||||||
@ -313,20 +339,47 @@ public class ScriptRunner implements Plugin {
|
|||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
/* Load config from test directory */
|
/* Load config from test directory */
|
||||||
final File proposedDir = new File(GUI.getExternalToolsSetting("PATH_CONTIKI") + "/tools/cooja/contiki_tests");
|
File proposedDir = new File(GUI.getExternalToolsSetting("PATH_CONTIKI") + "/tools/cooja/contiki_tests");
|
||||||
if (!proposedDir.exists()) {
|
if (!proposedDir.exists()) {
|
||||||
logger.fatal("Test directory does not exist: " + proposedDir.getPath());
|
logger.fatal("Test directory does not exist: " + proposedDir.getPath());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JFileChooser fc = new JFileChooser();
|
||||||
|
fc.setFileFilter(GUI.SAVED_SIMULATIONS_FILES);
|
||||||
|
fc.setCurrentDirectory(proposedDir);
|
||||||
|
|
||||||
|
/* Pre-select last used test */
|
||||||
|
String name = GUI.getExternalToolsSetting("LAST_TEST_CONFIG", null);
|
||||||
|
if (name != null) {
|
||||||
|
if (new File(proposedDir, name).exists()) {
|
||||||
|
fc.setSelectedFile(new File(proposedDir, name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int returnVal = fc.showOpenDialog(GUI.getTopParentContainer());
|
||||||
|
if (returnVal != JFileChooser.APPROVE_OPTION) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
File file = fc.getSelectedFile();
|
||||||
|
if (!file.exists() || !file.canRead()) {
|
||||||
|
logger.fatal("No read access to file");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
scriptTextArea.setText("");
|
scriptTextArea.setText("");
|
||||||
logTextArea.setText("");
|
logTextArea.setText("");
|
||||||
|
|
||||||
gui.doLoadConfig(false, true, proposedDir);
|
gui.doLoadConfig(false, true, file);
|
||||||
|
|
||||||
if (gui.getSimulation() == null) {
|
if (gui.getSimulation() == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
File cscFile = gui.currentConfigFile;
|
File cscFile = gui.currentConfigFile;
|
||||||
|
if (cscFile == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
String testName = cscFile.getName().substring(0, cscFile.getName().length()-4);
|
String testName = cscFile.getName().substring(0, cscFile.getName().length()-4);
|
||||||
File testDir = cscFile.getParentFile();
|
File testDir = cscFile.getParentFile();
|
||||||
File jsFile = new File(testDir, testName + ".js");
|
File jsFile = new File(testDir, testName + ".js");
|
||||||
@ -434,6 +487,8 @@ public class ScriptRunner implements Plugin {
|
|||||||
File infoFile = new File(testDir, testName + ".info");
|
File infoFile = new File(testDir, testName + ".info");
|
||||||
final File logFile = new File(testDir, testName + ".log");
|
final File logFile = new File(testDir, testName + ".log");
|
||||||
|
|
||||||
|
GUI.setExternalToolsSetting("LAST_TEST_CONFIG", cscFile.getName());
|
||||||
|
|
||||||
/* Overwrite existing test */
|
/* Overwrite existing test */
|
||||||
if (cscFile.exists() || jsFile.exists() || infoFile.exists()) {
|
if (cscFile.exists() || jsFile.exists() || infoFile.exists()) {
|
||||||
s1 = "Overwrite";
|
s1 = "Overwrite";
|
||||||
@ -539,7 +594,7 @@ public class ScriptRunner implements Plugin {
|
|||||||
"\n" +
|
"\n" +
|
||||||
"Run exported test in forked Cooja now?",
|
"Run exported test in forked Cooja now?",
|
||||||
"Run test?", JOptionPane.YES_NO_OPTION,
|
"Run test?", JOptionPane.YES_NO_OPTION,
|
||||||
JOptionPane.QUESTION_MESSAGE, null, options, s1);
|
JOptionPane.QUESTION_MESSAGE, null, options, s2);
|
||||||
if (n != JOptionPane.YES_OPTION) {
|
if (n != JOptionPane.YES_OPTION) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user