removed passive/active interfaces notion.

This commit is contained in:
fros4943 2008-10-28 14:09:25 +00:00
parent 4829ffea50
commit a0bf017e2f

View File

@ -26,7 +26,7 @@
* 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: MoteInterfaceViewer.java,v 1.3 2007/01/09 09:49:24 fros4943 Exp $ * $Id: MoteInterfaceViewer.java,v 1.4 2008/10/28 14:09:25 fros4943 Exp $
*/ */
package se.sics.cooja.plugins; package se.sics.cooja.plugins;
@ -41,9 +41,9 @@ import org.jdom.Element;
import se.sics.cooja.*; import se.sics.cooja.*;
/** /**
* MoteInterfaceViewer allows a user to select and view information about a node's interfaces. * Mote Interface Viewer views information about a specific mote interface.
* *
* @author Fredrik Osterlind * @author Fredrik Österlind
*/ */
@ClassDescription("Mote Interface Viewer") @ClassDescription("Mote Interface Viewer")
@PluginType(PluginType.MOTE_PLUGIN) @PluginType(PluginType.MOTE_PLUGIN)
@ -53,7 +53,7 @@ public class MoteInterfaceViewer extends VisPlugin {
private Mote mote; private Mote mote;
private MoteInterface selectedMoteInterface = null; private MoteInterface selectedMoteInterface = null;
private JPanel currentInterfaceVisualizer = null; private JPanel currentInterfaceVisualizer = null;
private JComboBox selectInterfaceComboBox = null; private JComboBox selectInterfaceComboBox = null;
/** /**
* Create a new mote interface viewer. * Create a new mote interface viewer.
@ -78,31 +78,28 @@ public class MoteInterfaceViewer extends VisPlugin {
selectInterfaceComboBox = new JComboBox(); selectInterfaceComboBox = new JComboBox();
final JPanel interfacePanel = new JPanel(); final JPanel interfacePanel = new JPanel();
for (int i=0; i < mote.getInterfaces().getAllActiveInterfaces().size(); i++) { Vector<MoteInterface> intfs = mote.getInterfaces().getInterfaces();
selectInterfaceComboBox.addItem(GUI.getDescriptionOf(mote.getInterfaces().getAllActiveInterfaces().get(i))); for (MoteInterface intf : intfs) {
selectInterfaceComboBox.addItem(GUI.getDescriptionOf(intf));
} }
for (int i=0; i < mote.getInterfaces().getAllPassiveInterfaces().size(); i++) {
selectInterfaceComboBox.addItem(GUI.getDescriptionOf(mote.getInterfaces().getAllPassiveInterfaces().get(i)));
}
selectInterfaceComboBox.addActionListener(new ActionListener() { selectInterfaceComboBox.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) { public void actionPerformed(ActionEvent e) {
// Release old interface visualizer if any // Release old interface visualizer if any
if (selectedMoteInterface != null && currentInterfaceVisualizer != null) if (selectedMoteInterface != null && currentInterfaceVisualizer != null) {
selectedMoteInterface.releaseInterfaceVisualizer(currentInterfaceVisualizer); selectedMoteInterface.releaseInterfaceVisualizer(currentInterfaceVisualizer);
}
// View selected interface if any // View selected interface if any
interfacePanel.removeAll(); interfacePanel.removeAll();
String interfaceDescription = (String) selectInterfaceComboBox.getSelectedItem(); String interfaceDescription = (String) selectInterfaceComboBox.getSelectedItem();
selectedMoteInterface = null; selectedMoteInterface = null;
for (int i=0; i < mote.getInterfaces().getAllActiveInterfaces().size(); i++) { Vector<MoteInterface> intfs = mote.getInterfaces().getInterfaces();
if (GUI.getDescriptionOf(mote.getInterfaces().getAllActiveInterfaces().get(i)).equals(interfaceDescription)) for (MoteInterface intf : intfs) {
selectedMoteInterface = mote.getInterfaces().getAllActiveInterfaces().get(i); if (GUI.getDescriptionOf(intf).equals(interfaceDescription)) {
} selectedMoteInterface = intf;
for (int i=0; i < mote.getInterfaces().getAllPassiveInterfaces().size(); i++) { }
if (GUI.getDescriptionOf(mote.getInterfaces().getAllPassiveInterfaces().get(i)).equals(interfaceDescription))
selectedMoteInterface = mote.getInterfaces().getAllPassiveInterfaces().get(i);
} }
currentInterfaceVisualizer = selectedMoteInterface.getInterfaceVisualizer(); currentInterfaceVisualizer = selectedMoteInterface.getInterfaceVisualizer();
if (currentInterfaceVisualizer != null) { if (currentInterfaceVisualizer != null) {
@ -110,10 +107,10 @@ public class MoteInterfaceViewer extends VisPlugin {
interfacePanel.add(BorderLayout.CENTER, currentInterfaceVisualizer); interfacePanel.add(BorderLayout.CENTER, currentInterfaceVisualizer);
currentInterfaceVisualizer.setVisible(true); currentInterfaceVisualizer.setVisible(true);
} else { } else {
interfacePanel.add(new JLabel("No interface visualizer exists!")); interfacePanel.add(new JLabel("No interface visualizer"));
currentInterfaceVisualizer = null; currentInterfaceVisualizer = null;
} }
setSize(getSize()); setSize(getSize());
} }
}); });
selectInterfaceComboBox.setSelectedIndex(0); selectInterfaceComboBox.setSelectedIndex(0);
@ -161,16 +158,17 @@ public class MoteInterfaceViewer extends VisPlugin {
} }
return false; return false;
} }
public void closePlugin() { public void closePlugin() {
// Release old interface visualizer if any // Release old interface visualizer if any
if (selectedMoteInterface != null && currentInterfaceVisualizer != null) if (selectedMoteInterface != null && currentInterfaceVisualizer != null) {
selectedMoteInterface.releaseInterfaceVisualizer(currentInterfaceVisualizer); selectedMoteInterface.releaseInterfaceVisualizer(currentInterfaceVisualizer);
}
} }
public Collection<Element> getConfigXML() { public Collection<Element> getConfigXML() {
Vector<Element> config = new Vector<Element>(); Vector<Element> config = new Vector<Element>();
Element element; Element element;
// Selected variable name // Selected variable name
@ -180,14 +178,14 @@ public class MoteInterfaceViewer extends VisPlugin {
return config; return config;
} }
public boolean setConfigXML(Collection<Element> configXML, boolean visAvailable) { public boolean setConfigXML(Collection<Element> configXML, boolean visAvailable) {
for (Element element : configXML) { for (Element element : configXML) {
if (element.getName().equals("interface")) { if (element.getName().equals("interface")) {
setSelectedInterface(element.getText()); setSelectedInterface(element.getText());
} }
} }
return true; return true;
} }
} }