made table contents more compact and changed tooltip for radio packets to show hex dump

This commit is contained in:
nifi 2009-04-20 17:24:03 +00:00
parent ecf288c89d
commit a66724e272

View File

@ -26,11 +26,11 @@
* 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: RadioLogger.java,v 1.16 2009/04/01 23:40:00 fros4943 Exp $ * $Id: RadioLogger.java,v 1.17 2009/04/20 17:24:03 nifi Exp $
*/ */
package se.sics.cooja.plugins; package se.sics.cooja.plugins;
import java.awt.Font;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import java.util.*; import java.util.*;
import javax.swing.*; import javax.swing.*;
@ -41,7 +41,9 @@ import org.apache.log4j.Logger;
import org.jdom.Element; import org.jdom.Element;
import se.sics.cooja.*; import se.sics.cooja.*;
import se.sics.cooja.interfaces.MoteID;
import se.sics.cooja.interfaces.Radio; import se.sics.cooja.interfaces.Radio;
import se.sics.cooja.util.StringUtils;
/** /**
* Radio logger listens to the simulation radio medium and lists all transmitted * Radio logger listens to the simulation radio medium and lists all transmitted
@ -67,7 +69,6 @@ public class RadioLogger extends VisPlugin {
}; };
private Simulation simulation; private Simulation simulation;
//private ArrayList<Object[]> rowData = new ArrayList<Object[]>();
private ArrayList<RadioConnectionLog> connections = new ArrayList<RadioConnectionLog>(); private ArrayList<RadioConnectionLog> connections = new ArrayList<RadioConnectionLog>();
private JTable dataTable = null; private JTable dataTable = null;
private RadioMedium radioMedium; private RadioMedium radioMedium;
@ -96,11 +97,11 @@ public class RadioLogger extends VisPlugin {
if (col == COLUMN_TIME) { if (col == COLUMN_TIME) {
return conn.startTime; return conn.startTime;
} else if (col == COLUMN_FROM) { } else if (col == COLUMN_FROM) {
return conn.connection.getSource().getMote(); return getMoteID(conn.connection.getSource().getMote());
} else if (col == COLUMN_TO) { } else if (col == COLUMN_TO) {
Radio[] dests = conn.connection.getDestinations(); Radio[] dests = conn.connection.getDestinations();
if (dests.length == 1) { if (dests.length == 1) {
return dests[0].getMote(); return getMoteID(dests[0].getMote());
} }
return "[" + dests.length + " motes]"; return "[" + dests.length + " motes]";
} else if (col == COLUMN_DATA) { } else if (col == COLUMN_DATA) {
@ -125,7 +126,7 @@ public class RadioLogger extends VisPlugin {
for (Radio dest: dests) { for (Radio dest: dests) {
gui.signalMoteHighlight(dest.getMote()); gui.signalMoteHighlight(dest.getMote());
} }
return true; return false;
} }
return false; return false;
} }
@ -135,31 +136,7 @@ public class RadioLogger extends VisPlugin {
} }
}; };
final JComboBox destinationComboBox = new JComboBox();
dataTable = new JTable(model) { dataTable = new JTable(model) {
public TableCellEditor getCellEditor(int row, int column) {
/* Reset destination box */
destinationComboBox.removeAllItems();
if (row < 0 || row >= connections.size()) {
return super.getCellEditor(row, column);
}
RadioConnection conn = connections.get(row).connection;
if (conn == null) {
return super.getCellEditor(row, column);
}
for (Radio destRadio: conn.getDestinations()) {
if (destRadio.getMote() != null) {
destinationComboBox.addItem(destRadio.getMote());
} else {
destinationComboBox.addItem("[standalone radio]");
}
}
return super.getCellEditor(row, column);
}
public String getToolTipText(MouseEvent e) { public String getToolTipText(MouseEvent e) {
java.awt.Point p = e.getPoint(); java.awt.Point p = e.getPoint();
@ -175,18 +152,19 @@ public class RadioLogger extends VisPlugin {
"<br>" + "<br>" +
"End time: " + conn.endTime + "End time: " + conn.endTime +
"<br><br>" + "<br><br>" +
"Duration: " + (conn.endTime - conn.startTime)+ "Duration: " + (conn.endTime - conn.startTime) +
"</html>"; "</html>";
} else if (realColumnIndex == COLUMN_FROM) { } else if (realColumnIndex == COLUMN_FROM) {
return conn.connection.getSource().getMote().toString(); return conn.connection.getSource().getMote().toString();
} else if (realColumnIndex == COLUMN_TO) { } else if (realColumnIndex == COLUMN_TO) {
String tip = "<html>"; StringBuilder tip = new StringBuilder();
tip.append("<html>");
Radio[] dests = conn.connection.getDestinations(); Radio[] dests = conn.connection.getDestinations();
for (Radio radio: dests) { for (Radio radio: dests) {
tip += radio.getMote() + "<br>"; tip.append(radio.getMote()).append("<br>");
} }
tip += "</html>"; tip.append("</html>");
return tip; return tip.toString();
} else if (realColumnIndex == COLUMN_DATA) { } else if (realColumnIndex == COLUMN_DATA) {
if (conn.tooltip == null) { if (conn.tooltip == null) {
prepareTooltipString(conn); prepareTooltipString(conn);
@ -199,16 +177,15 @@ public class RadioLogger extends VisPlugin {
// Set data column width greedy // Set data column width greedy
dataTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); dataTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
dataTable.getColumnModel().getColumn(COLUMN_TIME).setPreferredWidth(150); dataTable.getColumnModel().getColumn(COLUMN_TIME).setPreferredWidth(130);
dataTable.getColumnModel().getColumn(COLUMN_TIME).setResizable(false); // dataTable.getColumnModel().getColumn(COLUMN_TIME).setResizable(false);
dataTable.getColumnModel().getColumn(COLUMN_FROM).setPreferredWidth(250); dataTable.getColumnModel().getColumn(COLUMN_FROM).setPreferredWidth(90);
dataTable.getColumnModel().getColumn(COLUMN_TO).setPreferredWidth(250); dataTable.getColumnModel().getColumn(COLUMN_TO).setPreferredWidth(150);
dataTable.getColumnModel().getColumn(COLUMN_DATA).setPreferredWidth(1500); dataTable.getColumnModel().getColumn(COLUMN_DATA).setPreferredWidth(1500);
dataTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION); dataTable.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
TableColumn destColumn = dataTable.getColumnModel().getColumn(COLUMN_TO); dataTable.setFont(new Font("Monospaced", Font.PLAIN, 12));
destColumn.setCellEditor(new DefaultCellEditor(destinationComboBox));
simulation.getRadioMedium().addRadioMediumObserver(radioMediumObserver = new Observer() { simulation.getRadioMedium().addRadioMediumObserver(radioMediumObserver = new Observer() {
public void update(Observable obs, Object obj) { public void update(Observable obs, Object obj) {
@ -240,6 +217,14 @@ public class RadioLogger extends VisPlugin {
} }
} }
private String getMoteID(Mote mote) {
MoteID moteID = mote.getInterfaces().getMoteID();
if (moteID != null) {
return Integer.toString(moteID.getMoteID());
}
return mote.toString();
}
private void prepareDataString(RadioConnectionLog conn) { private void prepareDataString(RadioConnectionLog conn) {
byte[] data; byte[] data;
if (conn.packet instanceof ConvertedRadioPacket) { if (conn.packet instanceof ConvertedRadioPacket) {
@ -251,13 +236,7 @@ public class RadioLogger extends VisPlugin {
conn.data = "[unknown data]"; conn.data = "[unknown data]";
return; return;
} }
conn.data = data.length + ": 0x" + StringUtils.toHex(data, 4);
conn.data = "";
for (byte b: data) {
String hexB = "0" + Integer.toHexString(b);
hexB = hexB.substring(hexB.length() - 2);
conn.data += "0x" + hexB + " ";
}
} }
private void prepareTooltipString(RadioConnectionLog conn) { private void prepareTooltipString(RadioConnectionLog conn) {
@ -274,22 +253,11 @@ public class RadioLogger extends VisPlugin {
data = packet.getPacketData(); data = packet.getPacketData();
} }
conn.tooltip = "<html><b>Packet data</b><br>"; conn.tooltip = "<html><font face=\"Monospaced\"><b>Packet data (" +
int byteCounter = 0; data.length +
for (byte b: data) { " bytes)</b><br><pre>" +
String hexB = "0" + Integer.toHexString(b); StringUtils.hexDump(data) +
hexB = hexB.substring(hexB.length() - 2); "</pre></font></html>";
conn.tooltip += "0x" + hexB + " ";
if (byteCounter++ > 2) {
conn.tooltip += "<br>";
byteCounter = 0;
}
}
conn.tooltip += "<br><br>";
for (byte b: data) {
conn.tooltip += (char) b;
}
conn.tooltip += "</html>";
} }
public void closePlugin() { public void closePlugin() {
@ -307,7 +275,7 @@ public class RadioLogger extends VisPlugin {
return true; return true;
} }
private class RadioConnectionLog { private static class RadioConnectionLog {
long startTime; long startTime;
long endTime; long endTime;
RadioConnection connection; RadioConnection connection;