removed passive/active interfaces notion.

+ fixed scrollbar
This commit is contained in:
fros4943 2008-10-28 13:59:35 +00:00
parent bbf88f3723
commit e7c064801e

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: MoteInformation.java,v 1.5 2008/02/07 13:15:22 fros4943 Exp $ * $Id: MoteInformation.java,v 1.6 2008/10/28 13:59:35 fros4943 Exp $
*/ */
package se.sics.cooja.plugins; package se.sics.cooja.plugins;
@ -35,14 +35,13 @@ import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.util.*; import java.util.*;
import javax.swing.*; import javax.swing.*;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import se.sics.cooja.*; import se.sics.cooja.*;
import se.sics.cooja.Mote.State; import se.sics.cooja.Mote.State;
/** /**
* MoteInformation is a simple information window for motes. * Mote information displays information about a given mote.
* *
* @author Fredrik Osterlind * @author Fredrik Osterlind
*/ */
@ -82,7 +81,7 @@ public class MoteInformation extends VisPlugin {
mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS)); mainPane.setLayout(new BoxLayout(mainPane, BoxLayout.Y_AXIS));
JPanel smallPane; JPanel smallPane;
// Remove mote button /* Remove button */
smallPane = new JPanel(new BorderLayout()); smallPane = new JPanel(new BorderLayout());
label = new JLabel("Remove mote"); label = new JLabel("Remove mote");
label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT)); label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT));
@ -101,7 +100,7 @@ public class MoteInformation extends VisPlugin {
mainPane.add(smallPane); mainPane.add(smallPane);
mainPane.add(Box.createRigidArea(new Dimension(0,25))); mainPane.add(Box.createRigidArea(new Dimension(0,25)));
// Visualize state /* State */
smallPane = new JPanel(new BorderLayout()); smallPane = new JPanel(new BorderLayout());
label = new JLabel("-- STATE --"); label = new JLabel("-- STATE --");
label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT)); label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT));
@ -122,8 +121,7 @@ public class MoteInformation extends VisPlugin {
mainPane.add(smallPane); mainPane.add(smallPane);
mainPane.add(Box.createRigidArea(new Dimension(0,25))); mainPane.add(Box.createRigidArea(new Dimension(0,25)));
/* Mote type */
// Visualize mote type
smallPane = new JPanel(new BorderLayout()); smallPane = new JPanel(new BorderLayout());
label = new JLabel("-- MOTE TYPE --"); label = new JLabel("-- MOTE TYPE --");
label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT)); label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT));
@ -135,22 +133,21 @@ public class MoteInformation extends VisPlugin {
mainPane.add(smallPane); mainPane.add(smallPane);
mainPane.add(Box.createRigidArea(new Dimension(0,25))); mainPane.add(Box.createRigidArea(new Dimension(0,25)));
// All interfaces /* Mote interfaces */
smallPane = new JPanel(new BorderLayout()); smallPane = new JPanel(new BorderLayout());
label = new JLabel("-- INTERFACES --"); label = new JLabel("-- MOTE INTERFACES --");
label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT)); label.setPreferredSize(new Dimension(LABEL_WIDTH,LABEL_HEIGHT));
smallPane.add(BorderLayout.NORTH, label); smallPane.add(BorderLayout.NORTH, label);
mainPane.add(smallPane); mainPane.add(smallPane);
mainPane.add(Box.createRigidArea(new Dimension(0,10))); mainPane.add(Box.createRigidArea(new Dimension(0,10)));
for (int i=0; i < mote.getInterfaces().getAllActiveInterfaces().size(); i++) { for (MoteInterface intf : mote.getInterfaces().getInterfaces()) {
smallPane = new JPanel(); smallPane = new JPanel();
smallPane.setLayout(new BorderLayout()); smallPane.setLayout(new BorderLayout());
MoteInterface moteInterface = mote.getInterfaces().getAllActiveInterfaces().get(i); String interfaceDescription = GUI.getDescriptionOf(intf);
String interfaceDescription = GUI.getDescriptionOf(moteInterface); JPanel interfaceVisualizer = intf.getInterfaceVisualizer();
JPanel interfaceVisualizer = moteInterface.getInterfaceVisualizer();
label = new JLabel(interfaceDescription); label = new JLabel(interfaceDescription);
label.setAlignmentX(JLabel.CENTER_ALIGNMENT); label.setAlignmentX(JLabel.CENTER_ALIGNMENT);
smallPane.add(BorderLayout.NORTH, label); smallPane.add(BorderLayout.NORTH, label);
@ -159,32 +156,8 @@ public class MoteInformation extends VisPlugin {
interfaceVisualizer.setBorder(BorderFactory.createEtchedBorder()); interfaceVisualizer.setBorder(BorderFactory.createEtchedBorder());
smallPane.add(BorderLayout.CENTER, interfaceVisualizer); smallPane.add(BorderLayout.CENTER, interfaceVisualizer);
// Tag each visualized interface to easier release them later // Tag each visualized interface
interfaceVisualizer.putClientProperty("my_interface", moteInterface); interfaceVisualizer.putClientProperty("my_interface", intf);
visibleMoteInterfaces.add(interfaceVisualizer);
}
mainPane.add(smallPane);
mainPane.add(Box.createRigidArea(new Dimension(0,5)));
}
for (int i=0; i < mote.getInterfaces().getAllPassiveInterfaces().size(); i++) {
smallPane = new JPanel();
smallPane.setLayout(new BorderLayout());
MoteInterface moteInterface = mote.getInterfaces().getAllPassiveInterfaces().get(i);
String interfaceDescription = GUI.getDescriptionOf(moteInterface);
JPanel interfaceVisualizer = moteInterface.getInterfaceVisualizer();
label = new JLabel(interfaceDescription);
label.setAlignmentX(JLabel.CENTER_ALIGNMENT);
smallPane.add(BorderLayout.NORTH, label);
if (interfaceVisualizer != null) {
interfaceVisualizer.setBorder(BorderFactory.createEtchedBorder());
smallPane.add(BorderLayout.CENTER, interfaceVisualizer);
// Tag each visualized interface to easier release them later
interfaceVisualizer.putClientProperty("my_interface", moteInterface);
visibleMoteInterfaces.add(interfaceVisualizer); visibleMoteInterfaces.add(interfaceVisualizer);
} }
@ -192,13 +165,14 @@ public class MoteInformation extends VisPlugin {
mainPane.add(Box.createRigidArea(new Dimension(0,5))); mainPane.add(Box.createRigidArea(new Dimension(0,5)));
} }
this.getContentPane().add(BorderLayout.CENTER,
new JScrollPane(mainPane,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
this.getContentPane().add(BorderLayout.NORTH, new JScrollPane(mainPane,
JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
pack(); pack();
setPreferredSize(new Dimension(350,500)); setPreferredSize(new Dimension(getWidth()+15, 250));
setSize(new Dimension(350,500)); setSize(new Dimension(getWidth()+15, 250));
try { try {
setSelected(true); setSelected(true);
@ -206,7 +180,7 @@ public class MoteInformation extends VisPlugin {
// Could not select // Could not select
} }
// Register as state observer to detect if mote changes state /* Listen to mote state changes */
mote.addStateObserver(stateObserver = new Observer() { mote.addStateObserver(stateObserver = new Observer() {
public void update(Observable obs, Object obj) { public void update(Observable obs, Object obj) {
if (mote.getState() == State.ACTIVE) { if (mote.getState() == State.ACTIVE) {
@ -227,7 +201,7 @@ public class MoteInformation extends VisPlugin {
// Release all interface visualizations // Release all interface visualizations
for (JPanel interfaceVisualization: visibleMoteInterfaces) { for (JPanel interfaceVisualization: visibleMoteInterfaces) {
MoteInterface moteInterface = (MoteInterface) interfaceVisualization.getClientProperty("my_interface"); MoteInterface moteInterface = (MoteInterface) interfaceVisualization.getClientProperty("my_interface");
if (moteInterface != null && interfaceVisualization != null) { if (moteInterface != null) {
moteInterface.releaseInterfaceVisualizer(interfaceVisualization); moteInterface.releaseInterfaceVisualizer(interfaceVisualization);
} else { } else {
logger.warn("Could not release panel"); logger.warn("Could not release panel");