cleaned up more mote type visualizer code

This commit is contained in:
Fredrik Osterlind 2012-05-25 15:54:59 +02:00
parent 9e67306eee
commit 86787df272
2 changed files with 40 additions and 86 deletions

View file

@ -31,9 +31,7 @@
package se.sics.cooja.contikimote; package se.sics.cooja.contikimote;
import java.awt.BorderLayout;
import java.awt.Container; import java.awt.Container;
import java.awt.Dimension;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.File; import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -50,12 +48,13 @@ import java.util.Random;
import java.util.Vector; import java.util.Vector;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import javax.swing.Box;
import javax.swing.BoxLayout; import javax.swing.JComponent;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.jdom.Element; import org.jdom.Element;
import se.sics.cooja.AbstractionLevelDescription; import se.sics.cooja.AbstractionLevelDescription;
import se.sics.cooja.ClassDescription; import se.sics.cooja.ClassDescription;
import se.sics.cooja.CoreComm; import se.sics.cooja.CoreComm;
@ -1194,98 +1193,52 @@ public class ContikiMoteType implements MoteType {
* *
* @return Mote type visualizer * @return Mote type visualizer
*/ */
public JPanel getTypeVisualizer() { public JComponent getTypeVisualizer() {
JPanel panel = new JPanel(); StringBuilder sb = new StringBuilder();
JLabel label = new JLabel(); // Identifier
JPanel smallPane; sb.append("<html><table><tr><td>Identifier</td><td>")
.append(getIdentifier()).append("</td></tr>");
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS)); // Description
sb.append("<tr><td>Description</td><td>")
/* Identifier */ .append(getDescription()).append("</td></tr>");
smallPane = new JPanel(new BorderLayout());
label = new JLabel("Identifier");
smallPane.add(BorderLayout.WEST, label);
label = new JLabel(identifier);
smallPane.add(BorderLayout.EAST, label);
panel.add(smallPane);
/* Description */
smallPane = new JPanel(new BorderLayout());
label = new JLabel("Description");
smallPane.add(BorderLayout.WEST, label);
label = new JLabel(description);
smallPane.add(BorderLayout.EAST, label);
panel.add(smallPane);
/* Contiki application */ /* Contiki application */
smallPane = new JPanel(new BorderLayout()); sb.append("<tr><td>Contiki application</td><td>")
label = new JLabel("Contiki application"); .append(getContikiSourceFile().getAbsolutePath()).append("</td></tr>");
smallPane.add(BorderLayout.WEST, label);
label = new JLabel(getContikiSourceFile().getName());
label.setToolTipText(getContikiSourceFile().getAbsolutePath());
smallPane.add(BorderLayout.EAST, label);
panel.add(smallPane);
panel.add(Box.createVerticalStrut(15));
/* Contiki firmware */ /* Contiki firmware */
smallPane = new JPanel(new BorderLayout()); sb.append("<tr><td>Contiki firmware</td><td>")
label = new JLabel("Contiki firmware"); .append(getContikiFirmwareFile().getAbsolutePath()).append("</td></tr>");
smallPane.add(BorderLayout.WEST, label);
label = new JLabel(getContikiFirmwareFile().getName());
label.setToolTipText(getContikiFirmwareFile().getAbsolutePath());
smallPane.add(BorderLayout.EAST, label);
panel.add(smallPane);
/* JNI Class */ /* JNI class */
smallPane = new JPanel(new BorderLayout()); sb.append("<tr><td>JNI library</td><td>")
label = new JLabel("Java class (JNI)"); .append(this.javaClassName).append("</td></tr>");
smallPane.add(BorderLayout.WEST, label);
label = new JLabel(this.javaClassName);
smallPane.add(BorderLayout.EAST, label);
panel.add(smallPane);
/* Sensors */ /* Contiki sensors */
smallPane = new JPanel(new BorderLayout()); sb.append("<tr><td valign=\"top\">Contiki sensors</td><td>");
label = new JLabel("Sensors"); for (String sensor: sensors) {
smallPane.add(BorderLayout.WEST, label); sb.append(sensor).append("<br>");
panel.add(smallPane);
for (String sensor : sensors) {
smallPane = new JPanel(new BorderLayout());
label = new JLabel(sensor);
smallPane.add(BorderLayout.EAST, label);
panel.add(smallPane);
} }
sb.append("</td></tr>");
/* Mote Interfaces */ /* Mote interfaces */
smallPane = new JPanel(new BorderLayout()); sb.append("<tr><td valign=\"top\">Mote interface</td><td>");
label = new JLabel("Mote interfaces"); for (Class<? extends MoteInterface> moteInterface: moteInterfacesClasses) {
smallPane.add(BorderLayout.WEST, label); sb.append(moteInterface.getSimpleName()).append("<br>");
panel.add(smallPane);
for (Class<? extends MoteInterface> intf : moteInterfacesClasses) {
smallPane = new JPanel(new BorderLayout());
label = new JLabel(intf.getSimpleName());
smallPane.add(BorderLayout.EAST, label);
panel.add(smallPane);
} }
sb.append("</td></tr>");
/* Core Interfaces */ /* Contiki core mote interfaces */
smallPane = new JPanel(new BorderLayout()); sb.append("<tr><td valign=\"top\">Contiki's mote interface</td><td>");
label = new JLabel("Core interfaces"); for (String coreInterface: getCoreInterfaces()) {
smallPane.add(BorderLayout.WEST, label); sb.append(coreInterface).append("<br>");
panel.add(smallPane);
for (String intf : getCoreInterfaces()) {
smallPane = new JPanel(new BorderLayout());
label = new JLabel(intf);
smallPane.add(BorderLayout.EAST, label);
panel.add(smallPane);
} }
sb.append("</td></tr>");
panel.add(Box.createRigidArea(new Dimension(0, 5))); JLabel label = new JLabel(sb.append("</table></html>").toString());
return panel; label.setVerticalTextPosition(JLabel.TOP);
return label;
} }
public Collection<Element> getConfigXML(Simulation simulation) { public Collection<Element> getConfigXML(Simulation simulation) {

View file

@ -145,10 +145,11 @@ public abstract class AbstractApplicationMoteType implements MoteType {
sb.append("<tr><td>Description</td><td>") sb.append("<tr><td>Description</td><td>")
.append(getDescription()).append("</td></tr>"); .append(getDescription()).append("</td></tr>");
sb.append("<tr><td valign=\"top\">Mote interface</td><td>");
for (Class<? extends MoteInterface> moteInterface : moteInterfaceClasses) { for (Class<? extends MoteInterface> moteInterface : moteInterfaceClasses) {
sb.append("<tr><td>Mote interface</td><td>") sb.append(moteInterface.getSimpleName()).append("<br>");
.append(moteInterface.getSimpleName()).append("</td></tr>");
} }
sb.append("</td></tr>");
JLabel label = new JLabel(sb.append("</table></html>").toString()); JLabel label = new JLabel(sb.append("</table></html>").toString());
label.setVerticalTextPosition(JLabel.TOP); label.setVerticalTextPosition(JLabel.TOP);