From 54e8dd9547113eb31aebb2db30a9c73adca04bdf Mon Sep 17 00:00:00 2001 From: fros4943 Date: Thu, 30 Nov 2006 14:25:44 +0000 Subject: [PATCH] added saved config plugin specifics support --- .../cooja/java/se/sics/cooja/Simulation.java | 25 ++++--- .../cooja/plugins/MoteInterfaceViewer.java | 36 +++++++++- .../sics/cooja/plugins/VariableWatcher.java | 67 ++++++++++++++++++- 3 files changed, 113 insertions(+), 15 deletions(-) diff --git a/tools/cooja/java/se/sics/cooja/Simulation.java b/tools/cooja/java/se/sics/cooja/Simulation.java index 241830db1..201beb807 100644 --- a/tools/cooja/java/se/sics/cooja/Simulation.java +++ b/tools/cooja/java/se/sics/cooja/Simulation.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: Simulation.java,v 1.3 2006/11/08 21:28:51 fros4943 Exp $ + * $Id: Simulation.java,v 1.4 2006/11/30 14:25:44 fros4943 Exp $ */ package se.sics.cooja; @@ -300,6 +300,11 @@ public class Simulation extends Observable implements Runnable { int moteNr = Integer.parseInt(moteNrString); Mote mote = newSim.getMote(moteNr); openedPlugin = visPluginClass.getConstructor(new Class[]{Mote.class}).newInstance(mote); + + // Tag plugin with mote + openedPlugin.putClientProperty("mote", mote); + + // Show plugin GUI.currentGUI.showPlugin(openedPlugin); } @@ -318,7 +323,7 @@ public class Simulation extends Observable implements Runnable { } else if (pluginSubElement.getName().equals("minimized")) { openedPlugin.setIcon(Boolean.parseBoolean(pluginSubElement.getText())); } else if (pluginSubElement.getName().equals("visplugin_config")) { - logger.fatal("NOT IMPLEMENTED: Not passing plugin specific data yet: " + pluginSubElement.getText()); + openedPlugin.setConfigXML(pluginSubElement.getChildren()); } } } catch (Exception e) { @@ -375,16 +380,16 @@ public class Simulation extends Observable implements Runnable { pluginType == VisPluginType.SIM_STANDARD_PLUGIN) { pluginSubElement.setText("sim"); pluginElement.addContent(pluginSubElement); - } else if (pluginType == VisPluginType.MOTE_PLUGIN) { - if (openedPlugin.getClientProperty("mote") != null) { - Mote taggedMote = (Mote) openedPlugin.getClientProperty("mote"); - for (int moteNr = 0; moteNr < getMotesCount(); moteNr++) { - if (getMote(moteNr) == taggedMote) { - pluginSubElement.setText("mote: " + moteNr); - pluginElement.addContent(pluginSubElement); - } + } else if (pluginType == VisPluginType.MOTE_PLUGIN && openedPlugin.getClientProperty("mote") != null) { + Mote taggedMote = (Mote) openedPlugin.getClientProperty("mote"); + for (int moteNr = 0; moteNr < getMotesCount(); moteNr++) { + if (getMote(moteNr) == taggedMote) { + pluginSubElement.setText("mote: " + moteNr); + pluginElement.addContent(pluginSubElement); } } + } else { + logger.fatal("Warning! Could not write visplugin constructor information: " + pluginType + "@" + openedPlugin); } pluginSubElement = new Element("width"); diff --git a/tools/cooja/java/se/sics/cooja/plugins/MoteInterfaceViewer.java b/tools/cooja/java/se/sics/cooja/plugins/MoteInterfaceViewer.java index 68d10bb06..e51c94d9e 100644 --- a/tools/cooja/java/se/sics/cooja/plugins/MoteInterfaceViewer.java +++ b/tools/cooja/java/se/sics/cooja/plugins/MoteInterfaceViewer.java @@ -26,14 +26,17 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: MoteInterfaceViewer.java,v 1.1 2006/08/21 12:13:09 fros4943 Exp $ + * $Id: MoteInterfaceViewer.java,v 1.2 2006/11/30 14:25:59 fros4943 Exp $ */ package se.sics.cooja.plugins; import java.awt.*; import java.awt.event.*; +import java.util.Collection; +import java.util.Vector; import javax.swing.*; +import org.jdom.Element; import se.sics.cooja.*; @@ -50,7 +53,8 @@ public class MoteInterfaceViewer extends VisPlugin { private Mote mote; private MoteInterface selectedMoteInterface = null; private JPanel currentInterfaceVisualizer = null; - + private JComboBox selectInterfaceComboBox = null; + /** * Create a new mote interface viewer. * @@ -71,7 +75,7 @@ public class MoteInterfaceViewer extends VisPlugin { label = new JLabel("Select interface:"); - final JComboBox selectInterfaceComboBox = new JComboBox(); + selectInterfaceComboBox = new JComboBox(); final JPanel interfacePanel = new JPanel(); for (int i=0; i < mote.getInterfaces().getAllActiveInterfaces().size(); i++) { @@ -149,4 +153,30 @@ public class MoteInterfaceViewer extends VisPlugin { selectedMoteInterface.releaseInterfaceVisualizer(currentInterfaceVisualizer); } + public Collection getConfigXML() { + Vector config = new Vector(); + + Element element; + + // Selected variable name + element = new Element("interface"); + element.setText((String) selectInterfaceComboBox.getSelectedItem()); + config.add(element); + + return config; + } + + public boolean setConfigXML(Collection configXML) { + for (Element element : configXML) { + if (element.getName().equals("interface")) { + for (int i=0; i < selectInterfaceComboBox.getItemCount(); i++) { + if (selectInterfaceComboBox.getItemAt(i).equals(element.getText())) { + selectInterfaceComboBox.setSelectedIndex(i); + } + } + } + } + return true; + } + } diff --git a/tools/cooja/java/se/sics/cooja/plugins/VariableWatcher.java b/tools/cooja/java/se/sics/cooja/plugins/VariableWatcher.java index 5d1c78f2b..01f654a53 100644 --- a/tools/cooja/java/se/sics/cooja/plugins/VariableWatcher.java +++ b/tools/cooja/java/se/sics/cooja/plugins/VariableWatcher.java @@ -26,7 +26,7 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * $Id: VariableWatcher.java,v 1.1 2006/08/21 12:13:07 fros4943 Exp $ + * $Id: VariableWatcher.java,v 1.2 2006/11/30 14:25:59 fros4943 Exp $ */ package se.sics.cooja.plugins; @@ -35,7 +35,10 @@ import java.awt.*; import java.awt.event.*; import java.beans.*; import java.text.NumberFormat; +import java.util.Collection; +import java.util.Vector; import javax.swing.*; +import org.jdom.Element; import se.sics.cooja.*; @@ -64,6 +67,7 @@ public class VariableWatcher extends VisPlugin { private JPanel lengthPane; private JPanel valuePane; private JComboBox varName; + private JComboBox varType; private JFormattedTextField[] varValues; private JFormattedTextField varLength; private JButton writeButton; @@ -122,7 +126,7 @@ public class VariableWatcher extends VisPlugin { label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT)); smallPane.add(BorderLayout.WEST, label); - final JComboBox varType = new JComboBox(); + varType = new JComboBox(); varType.addItem("Byte (1 byte)"); // BYTE_INDEX = 0 varType.addItem("Integer (4 bytes)"); // INT_INDEX = 1 varType.addItem("Byte array (x bytes)"); // ARRAY_INDEX = 2 @@ -307,4 +311,63 @@ public class VariableWatcher extends VisPlugin { public void closePlugin() { } + public Collection getConfigXML() { + // Return currently watched variable and type + Vector config = new Vector(); + + Element element; + + // Selected variable name + element = new Element("varname"); + element.setText((String) varName.getSelectedItem()); + config.add(element); + + // Selected variable type + if (varType.getSelectedIndex() == BYTE_INDEX) { + element = new Element("vartype"); + element.setText("byte"); + config.add(element); + } else if (varType.getSelectedIndex() == INT_INDEX) { + element = new Element("vartype"); + element.setText("int"); + config.add(element); + } else if (varType.getSelectedIndex() == ARRAY_INDEX) { + element = new Element("vartype"); + element.setText("array"); + config.add(element); + element = new Element("array_length"); + element.setText(varLength.getValue().toString()); + config.add(element); + } + + return config; + } + + public boolean setConfigXML(Collection configXML) { + lengthPane.setVisible(false); + setNumberOfValues(1); + varLength.setValue(1); + + for (Element element : configXML) { + if (element.getName().equals("varname")) { + varName.setSelectedItem(element.getText()); + } else if (element.getName().equals("vartype")) { + if (element.getText().equals("byte")) { + varType.setSelectedIndex(BYTE_INDEX); + } else if (element.getText().equals("int")) { + varType.setSelectedIndex(INT_INDEX); + } else if (element.getText().equals("array")) { + varType.setSelectedIndex(ARRAY_INDEX); + lengthPane.setVisible(true); + } + } else if (element.getName().equals("array_length")) { + int nrValues = Integer.parseInt(element.getText()); + setNumberOfValues(nrValues); + varLength.setValue(nrValues); + } + } + + return true; + } + }