Made the mote type information for MSPSim based platforms more compact

This commit is contained in:
Niclas Finne 2012-05-23 17:03:45 +02:00
parent 73cb02fb49
commit e18cc3b6b9
2 changed files with 24 additions and 67 deletions

View file

@ -1,5 +1,5 @@
/* /*
* Copyright (c) 2007, Swedish Institute of Computer Science. * Copyright (c) 2007-2012, Swedish Institute of Computer Science.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -25,27 +25,19 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* 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: MspMoteType.java,v 1.38 2010/10/25 14:13:38 nifi Exp $
*/ */
package se.sics.cooja.mspmote; package se.sics.cooja.mspmote;
import java.awt.BorderLayout; import java.awt.BorderLayout;
import java.awt.Dimension;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.Hashtable; import java.util.Hashtable;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.Icon; import javax.swing.Icon;
import javax.swing.JLabel; import javax.swing.JLabel;
import javax.swing.JPanel; import javax.swing.JPanel;
import javax.swing.JTextArea;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.jdom.Element; import org.jdom.Element;
import se.sics.cooja.ClassDescription; import se.sics.cooja.ClassDescription;
@ -57,7 +49,6 @@ import se.sics.cooja.ProjectConfig;
import se.sics.cooja.Simulation; import se.sics.cooja.Simulation;
import se.sics.cooja.interfaces.IPAddress; import se.sics.cooja.interfaces.IPAddress;
import se.sics.cooja.mspmote.interfaces.MspSerial; import se.sics.cooja.mspmote.interfaces.MspSerial;
import se.sics.cooja.util.ArrayUtils;
import se.sics.mspsim.util.DebugInfo; import se.sics.mspsim.util.DebugInfo;
import se.sics.mspsim.util.ELF; import se.sics.mspsim.util.ELF;
@ -139,74 +130,50 @@ public abstract class MspMoteType implements MoteType {
protected abstract MspMote createMote(Simulation simulation); protected abstract MspMote createMote(Simulation simulation);
@Override
public JPanel getTypeVisualizer() { public JPanel getTypeVisualizer() {
/* TODO Move to emulated layer */ StringBuilder sb = new StringBuilder();
JPanel panel = new JPanel();
JLabel label = new JLabel();
JPanel smallPane;
panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
// Identifier // Identifier
smallPane = new JPanel(new BorderLayout()); sb.append("<html><table><tr><td>Identifier</td><td>")
label = new JLabel("Identifier"); .append(getIdentifier()).append("</td></tr>");
smallPane.add(BorderLayout.WEST, label);
label = new JLabel(getIdentifier());
smallPane.add(BorderLayout.EAST, label);
panel.add(smallPane);
// Description // Description
smallPane = new JPanel(new BorderLayout()); sb.append("<tr><td>Description</td><td>")
label = new JLabel("Description"); .append(getDescription()).append("</td></tr>");
smallPane.add(BorderLayout.WEST, label);
label = new JLabel(getDescription());
smallPane.add(BorderLayout.EAST, label);
panel.add(smallPane);
/* Contiki source */ /* Contiki source */
smallPane = new JPanel(new BorderLayout()); sb.append("<tr><td>Contiki source</td><td>");
label = new JLabel("Contiki source");
smallPane.add(BorderLayout.WEST, label);
if (getContikiSourceFile() != null) { if (getContikiSourceFile() != null) {
label = new JLabel(getContikiSourceFile().getName()); sb.append(getContikiSourceFile().getAbsolutePath());
label.setToolTipText(getContikiSourceFile().getPath());
} else { } else {
label = new JLabel("[not specified]"); sb.append("[not specified]");
} }
smallPane.add(BorderLayout.EAST, label); sb.append("</td></tr>");
panel.add(smallPane);
/* 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().getPath());
smallPane.add(BorderLayout.EAST, label);
panel.add(smallPane);
/* Compile commands */ /* Compile commands */
smallPane = new JPanel(new BorderLayout()); String compileCommands = getCompileCommands();
label = new JLabel("Compile commands"); if (compileCommands == null) {
smallPane.add(BorderLayout.WEST, label); compileCommands = "";
JTextArea textArea = new JTextArea(getCompileCommands()); }
textArea.setEditable(false); sb.append("<tr><td valign=top>Compile commands</td><td>")
textArea.setBorder(BorderFactory.createEmptyBorder()); .append(compileCommands.replace("<", "&lt;").replace(">", "&gt;").replace("\n", "<br>")).append("</td></tr>");
smallPane.add(BorderLayout.EAST, textArea);
panel.add(smallPane);
JLabel label = new JLabel(sb.append("</table></html>").toString());
label.setVerticalTextPosition(JLabel.TOP);
/* Icon (if available) */ /* Icon (if available) */
if (!GUI.isVisualizedInApplet()) { if (!GUI.isVisualizedInApplet()) {
Icon moteTypeIcon = getMoteTypeIcon(); Icon moteTypeIcon = getMoteTypeIcon();
if (moteTypeIcon != null) { if (moteTypeIcon != null) {
smallPane = new JPanel(new BorderLayout()); label.setIcon(moteTypeIcon);
label = new JLabel(moteTypeIcon);
smallPane.add(BorderLayout.CENTER, label);
panel.add(smallPane);
} }
} }
panel.add(Box.createRigidArea(new Dimension(0, 5))); JPanel panel = new JPanel(new BorderLayout());
panel.add(BorderLayout.CENTER, label);
return panel; return panel;
} }
@ -351,13 +318,6 @@ public abstract class MspMoteType implements MoteType {
public abstract Class<? extends MoteInterface>[] getAllMoteInterfaceClasses(); public abstract Class<? extends MoteInterface>[] getAllMoteInterfaceClasses();
public abstract File getExpectedFirmwareFile(File source); public abstract File getExpectedFirmwareFile(File source);
private static ELF loadELF(URL url) throws Exception {
byte[] data = ArrayUtils.readFromStream(url.openStream());
ELF elf = new ELF(data);
elf.readAll();
return elf;
}
private static ELF loadELF(String filepath) throws IOException { private static ELF loadELF(String filepath) throws IOException {
return ELF.readELF(filepath); return ELF.readELF(filepath);
} }

View file

@ -69,8 +69,6 @@ public class MoteTypeInformation extends VisPlugin {
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED)); JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
pack(); pack();
setPreferredSize(new Dimension(350,500));
setSize(new Dimension(350,500));
mySimulation.addObserver(simObserver = new Observer() { mySimulation.addObserver(simObserver = new Observer() {
public void update(Observable obs, Object obj) { public void update(Observable obs, Object obj) {
@ -79,7 +77,6 @@ public class MoteTypeInformation extends VisPlugin {
new JScrollPane(createPanel(), new JScrollPane(createPanel(),
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED)); JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED));
setPreferredSize(MoteTypeInformation.this.getSize());
pack(); pack();
} }
}); });