made a text-based version of the MessageList for headless execution
This commit is contained in:
parent
5b5f07ba52
commit
19120788c0
|
@ -63,7 +63,9 @@ import org.contikios.cooja.avrmote.interfaces.MicaZLED;
|
|||
import org.contikios.cooja.avrmote.interfaces.MicaZRadio;
|
||||
import org.contikios.cooja.dialogs.CompileContiki;
|
||||
import org.contikios.cooja.dialogs.MessageList;
|
||||
import org.contikios.cooja.dialogs.MessageList.MessageContainer;
|
||||
import org.contikios.cooja.dialogs.MessageListText;
|
||||
import org.contikios.cooja.dialogs.MessageListUI;
|
||||
import org.contikios.cooja.dialogs.MessageContainer;
|
||||
import org.contikios.cooja.interfaces.Mote2MoteRelations;
|
||||
import org.contikios.cooja.interfaces.MoteAttributes;
|
||||
import org.contikios.cooja.interfaces.Position;
|
||||
|
@ -364,7 +366,7 @@ public class MicaZMoteType implements MoteType {
|
|||
throw new MoteTypeCreationException("No identifier");
|
||||
}
|
||||
|
||||
final MessageList compilationOutput = new MessageList();
|
||||
final MessageList compilationOutput = visAvailable ? new MessageListUI() : new MessageListText();
|
||||
|
||||
if (getCompileCommands() != null) {
|
||||
/* Handle multiple compilation commands one by one */
|
||||
|
|
|
@ -45,7 +45,6 @@ import org.apache.log4j.Logger;
|
|||
|
||||
import org.contikios.cooja.*;
|
||||
import org.contikios.cooja.dialogs.*;
|
||||
import org.contikios.cooja.dialogs.MessageList.MessageContainer;
|
||||
|
||||
/**
|
||||
*
|
||||
|
@ -119,7 +118,7 @@ public abstract class AbstractMspMoteType extends MspMoteType {
|
|||
throw new MoteTypeCreationException("No identifier");
|
||||
}
|
||||
|
||||
final MessageList compilationOutput = new MessageList();
|
||||
final MessageList compilationOutput = visAvailable ? new MessageListUI() : new MessageListText();
|
||||
|
||||
if (getCompileCommands() != null) {
|
||||
/* Handle multiple compilation commands one by one */
|
||||
|
|
|
@ -50,8 +50,10 @@ import org.contikios.cooja.MoteInterface;
|
|||
import org.contikios.cooja.MoteType;
|
||||
import org.contikios.cooja.Simulation;
|
||||
import org.contikios.cooja.dialogs.CompileContiki;
|
||||
import org.contikios.cooja.dialogs.MessageContainer;
|
||||
import org.contikios.cooja.dialogs.MessageList;
|
||||
import org.contikios.cooja.dialogs.MessageList.MessageContainer;
|
||||
import org.contikios.cooja.dialogs.MessageListText;
|
||||
import org.contikios.cooja.dialogs.MessageListUI;
|
||||
import org.contikios.cooja.interfaces.IPAddress;
|
||||
import org.contikios.cooja.interfaces.Mote2MoteRelations;
|
||||
import org.contikios.cooja.interfaces.MoteAttributes;
|
||||
|
@ -113,7 +115,7 @@ public class CC430MoteType extends MspMoteType {
|
|||
throw new MoteTypeCreationException("No identifier");
|
||||
}
|
||||
|
||||
final MessageList compilationOutput = new MessageList();
|
||||
final MessageList compilationOutput = visAvailable ? new MessageListUI() : new MessageListText();
|
||||
|
||||
if (getCompileCommands() != null) {
|
||||
/* Handle multiple compilation commands one by one */
|
||||
|
|
|
@ -51,7 +51,9 @@ import org.contikios.cooja.MoteType;
|
|||
import org.contikios.cooja.Simulation;
|
||||
import org.contikios.cooja.dialogs.CompileContiki;
|
||||
import org.contikios.cooja.dialogs.MessageList;
|
||||
import org.contikios.cooja.dialogs.MessageList.MessageContainer;
|
||||
import org.contikios.cooja.dialogs.MessageListText;
|
||||
import org.contikios.cooja.dialogs.MessageListUI;
|
||||
import org.contikios.cooja.dialogs.MessageContainer;
|
||||
import org.contikios.cooja.interfaces.IPAddress;
|
||||
import org.contikios.cooja.interfaces.Mote2MoteRelations;
|
||||
import org.contikios.cooja.interfaces.MoteAttributes;
|
||||
|
@ -149,7 +151,7 @@ public class ESBMoteType extends MspMoteType {
|
|||
throw new MoteTypeCreationException("No identifier");
|
||||
}
|
||||
|
||||
final MessageList compilationOutput = new MessageList();
|
||||
final MessageList compilationOutput = visAvailable ? new MessageListUI() : new MessageListText();
|
||||
|
||||
if (getCompileCommands() != null) {
|
||||
/* Handle multiple compilation commands one by one */
|
||||
|
|
|
@ -11,7 +11,9 @@ import org.contikios.cooja.MoteType;
|
|||
import org.contikios.cooja.Simulation;
|
||||
import org.contikios.cooja.dialogs.CompileContiki;
|
||||
import org.contikios.cooja.dialogs.MessageList;
|
||||
import org.contikios.cooja.dialogs.MessageList.MessageContainer;
|
||||
import org.contikios.cooja.dialogs.MessageListText;
|
||||
import org.contikios.cooja.dialogs.MessageListUI;
|
||||
import org.contikios.cooja.dialogs.MessageContainer;
|
||||
import org.contikios.cooja.interfaces.IPAddress;
|
||||
import org.contikios.cooja.interfaces.Mote2MoteRelations;
|
||||
import org.contikios.cooja.interfaces.MoteAttributes;
|
||||
|
@ -71,7 +73,7 @@ public class Eth1120MoteType extends Exp5438MoteType {
|
|||
throw new MoteTypeCreationException("No identifier");
|
||||
}
|
||||
|
||||
final MessageList compilationOutput = new MessageList();
|
||||
final MessageList compilationOutput = visAvailable ? new MessageListUI() : new MessageListText();
|
||||
|
||||
if (getCompileCommands() != null) {
|
||||
/* Handle multiple compilation commands one by one */
|
||||
|
|
|
@ -11,7 +11,9 @@ import org.contikios.cooja.MoteType;
|
|||
import org.contikios.cooja.Simulation;
|
||||
import org.contikios.cooja.dialogs.CompileContiki;
|
||||
import org.contikios.cooja.dialogs.MessageList;
|
||||
import org.contikios.cooja.dialogs.MessageList.MessageContainer;
|
||||
import org.contikios.cooja.dialogs.MessageListText;
|
||||
import org.contikios.cooja.dialogs.MessageListUI;
|
||||
import org.contikios.cooja.dialogs.MessageContainer;
|
||||
import org.contikios.cooja.interfaces.IPAddress;
|
||||
import org.contikios.cooja.interfaces.Mote2MoteRelations;
|
||||
import org.contikios.cooja.interfaces.MoteAttributes;
|
||||
|
@ -71,7 +73,7 @@ public class Exp1101MoteType extends Exp5438MoteType {
|
|||
throw new MoteTypeCreationException("No identifier");
|
||||
}
|
||||
|
||||
final MessageList compilationOutput = new MessageList();
|
||||
final MessageList compilationOutput = visAvailable ? new MessageListUI() : new MessageListText();
|
||||
|
||||
if (getCompileCommands() != null) {
|
||||
/* Handle multiple compilation commands one by one */
|
||||
|
|
|
@ -11,7 +11,9 @@ import org.contikios.cooja.MoteType;
|
|||
import org.contikios.cooja.Simulation;
|
||||
import org.contikios.cooja.dialogs.CompileContiki;
|
||||
import org.contikios.cooja.dialogs.MessageList;
|
||||
import org.contikios.cooja.dialogs.MessageList.MessageContainer;
|
||||
import org.contikios.cooja.dialogs.MessageListText;
|
||||
import org.contikios.cooja.dialogs.MessageListUI;
|
||||
import org.contikios.cooja.dialogs.MessageContainer;
|
||||
import org.contikios.cooja.interfaces.IPAddress;
|
||||
import org.contikios.cooja.interfaces.Mote2MoteRelations;
|
||||
import org.contikios.cooja.interfaces.MoteAttributes;
|
||||
|
@ -72,7 +74,7 @@ public class Exp1120MoteType extends Exp5438MoteType {
|
|||
throw new MoteTypeCreationException("No identifier");
|
||||
}
|
||||
|
||||
final MessageList compilationOutput = new MessageList();
|
||||
final MessageList compilationOutput = visAvailable ? new MessageListUI() : new MessageListText();
|
||||
|
||||
if (getCompileCommands() != null) {
|
||||
/* Handle multiple compilation commands one by one */
|
||||
|
|
|
@ -11,7 +11,9 @@ import org.contikios.cooja.MoteType;
|
|||
import org.contikios.cooja.Simulation;
|
||||
import org.contikios.cooja.dialogs.CompileContiki;
|
||||
import org.contikios.cooja.dialogs.MessageList;
|
||||
import org.contikios.cooja.dialogs.MessageList.MessageContainer;
|
||||
import org.contikios.cooja.dialogs.MessageListText;
|
||||
import org.contikios.cooja.dialogs.MessageListUI;
|
||||
import org.contikios.cooja.dialogs.MessageContainer;
|
||||
import org.contikios.cooja.interfaces.IPAddress;
|
||||
import org.contikios.cooja.interfaces.Mote2MoteRelations;
|
||||
import org.contikios.cooja.interfaces.MoteAttributes;
|
||||
|
@ -72,7 +74,7 @@ public class Exp2420MoteType extends Exp5438MoteType {
|
|||
throw new MoteTypeCreationException("No identifier");
|
||||
}
|
||||
|
||||
final MessageList compilationOutput = new MessageList();
|
||||
final MessageList compilationOutput = visAvailable ? new MessageListUI() : new MessageListText();
|
||||
|
||||
if (getCompileCommands() != null) {
|
||||
/* Handle multiple compilation commands one by one */
|
||||
|
|
|
@ -48,7 +48,9 @@ import org.contikios.cooja.MoteType;
|
|||
import org.contikios.cooja.Simulation;
|
||||
import org.contikios.cooja.dialogs.CompileContiki;
|
||||
import org.contikios.cooja.dialogs.MessageList;
|
||||
import org.contikios.cooja.dialogs.MessageList.MessageContainer;
|
||||
import org.contikios.cooja.dialogs.MessageListText;
|
||||
import org.contikios.cooja.dialogs.MessageListUI;
|
||||
import org.contikios.cooja.dialogs.MessageContainer;
|
||||
import org.contikios.cooja.interfaces.IPAddress;
|
||||
import org.contikios.cooja.interfaces.Mote2MoteRelations;
|
||||
import org.contikios.cooja.interfaces.MoteAttributes;
|
||||
|
@ -113,7 +115,7 @@ public class Exp5438MoteType extends MspMoteType {
|
|||
throw new MoteTypeCreationException("No identifier");
|
||||
}
|
||||
|
||||
final MessageList compilationOutput = new MessageList();
|
||||
final MessageList compilationOutput = visAvailable ? new MessageListUI() : new MessageListText();
|
||||
|
||||
if (getCompileCommands() != null) {
|
||||
/* Handle multiple compilation commands one by one */
|
||||
|
|
|
@ -51,7 +51,9 @@ import org.contikios.cooja.MoteType;
|
|||
import org.contikios.cooja.Simulation;
|
||||
import org.contikios.cooja.dialogs.CompileContiki;
|
||||
import org.contikios.cooja.dialogs.MessageList;
|
||||
import org.contikios.cooja.dialogs.MessageList.MessageContainer;
|
||||
import org.contikios.cooja.dialogs.MessageListText;
|
||||
import org.contikios.cooja.dialogs.MessageListUI;
|
||||
import org.contikios.cooja.dialogs.MessageContainer;
|
||||
import org.contikios.cooja.interfaces.IPAddress;
|
||||
import org.contikios.cooja.interfaces.Mote2MoteRelations;
|
||||
import org.contikios.cooja.interfaces.MoteAttributes;
|
||||
|
@ -135,7 +137,7 @@ public class SkyMoteType extends MspMoteType {
|
|||
throw new MoteTypeCreationException("No identifier");
|
||||
}
|
||||
|
||||
final MessageList compilationOutput = new MessageList();
|
||||
final MessageList compilationOutput = visAvailable ? new MessageListUI() : new MessageListText();
|
||||
|
||||
if (getCompileCommands() != null) {
|
||||
/* Handle multiple compilation commands one by one */
|
||||
|
|
|
@ -11,7 +11,9 @@ import org.contikios.cooja.MoteType;
|
|||
import org.contikios.cooja.Simulation;
|
||||
import org.contikios.cooja.dialogs.CompileContiki;
|
||||
import org.contikios.cooja.dialogs.MessageList;
|
||||
import org.contikios.cooja.dialogs.MessageList.MessageContainer;
|
||||
import org.contikios.cooja.dialogs.MessageListText;
|
||||
import org.contikios.cooja.dialogs.MessageListUI;
|
||||
import org.contikios.cooja.dialogs.MessageContainer;
|
||||
import org.contikios.cooja.interfaces.IPAddress;
|
||||
import org.contikios.cooja.interfaces.Mote2MoteRelations;
|
||||
import org.contikios.cooja.interfaces.MoteAttributes;
|
||||
|
@ -71,7 +73,7 @@ public class Trxeb1120MoteType extends Exp5438MoteType {
|
|||
throw new MoteTypeCreationException("No identifier");
|
||||
}
|
||||
|
||||
final MessageList compilationOutput = new MessageList();
|
||||
final MessageList compilationOutput = visAvailable ? new MessageListUI() : new MessageListText();
|
||||
|
||||
if (getCompileCommands() != null) {
|
||||
/* Handle multiple compilation commands one by one */
|
||||
|
|
|
@ -11,7 +11,9 @@ import org.contikios.cooja.MoteType;
|
|||
import org.contikios.cooja.Simulation;
|
||||
import org.contikios.cooja.dialogs.CompileContiki;
|
||||
import org.contikios.cooja.dialogs.MessageList;
|
||||
import org.contikios.cooja.dialogs.MessageList.MessageContainer;
|
||||
import org.contikios.cooja.dialogs.MessageListText;
|
||||
import org.contikios.cooja.dialogs.MessageListUI;
|
||||
import org.contikios.cooja.dialogs.MessageContainer;
|
||||
import org.contikios.cooja.interfaces.IPAddress;
|
||||
import org.contikios.cooja.interfaces.Mote2MoteRelations;
|
||||
import org.contikios.cooja.interfaces.MoteAttributes;
|
||||
|
@ -71,7 +73,7 @@ public class Trxeb2520MoteType extends Exp5438MoteType {
|
|||
throw new MoteTypeCreationException("No identifier");
|
||||
}
|
||||
|
||||
final MessageList compilationOutput = new MessageList();
|
||||
final MessageList compilationOutput = visAvailable ? new MessageListUI() : new MessageListText();
|
||||
|
||||
if (getCompileCommands() != null) {
|
||||
/* Handle multiple compilation commands one by one */
|
||||
|
|
|
@ -49,7 +49,9 @@ import org.contikios.cooja.MoteType;
|
|||
import org.contikios.cooja.Simulation;
|
||||
import org.contikios.cooja.dialogs.CompileContiki;
|
||||
import org.contikios.cooja.dialogs.MessageList;
|
||||
import org.contikios.cooja.dialogs.MessageList.MessageContainer;
|
||||
import org.contikios.cooja.dialogs.MessageListText;
|
||||
import org.contikios.cooja.dialogs.MessageListUI;
|
||||
import org.contikios.cooja.dialogs.MessageContainer;
|
||||
import org.contikios.cooja.interfaces.IPAddress;
|
||||
import org.contikios.cooja.interfaces.Mote2MoteRelations;
|
||||
import org.contikios.cooja.interfaces.MoteAttributes;
|
||||
|
@ -112,7 +114,7 @@ public class TyndallMoteType extends MspMoteType {
|
|||
throw new MoteTypeCreationException("No identifier");
|
||||
}
|
||||
|
||||
final MessageList compilationOutput = new MessageList();
|
||||
final MessageList compilationOutput = visAvailable ? new MessageListUI() : new MessageListText();
|
||||
|
||||
if (getCompileCommands() != null) {
|
||||
/* Handle multiple compilation commands one by one */
|
||||
|
|
|
@ -77,6 +77,7 @@ import org.contikios.cooja.Watchpoint;
|
|||
import org.contikios.cooja.WatchpointMote;
|
||||
import org.contikios.cooja.WatchpointMote.WatchpointListener;
|
||||
import org.contikios.cooja.dialogs.MessageList;
|
||||
import org.contikios.cooja.dialogs.MessageListUI;
|
||||
import org.contikios.cooja.mspmote.MspMote;
|
||||
import org.contikios.cooja.mspmote.MspMoteType;
|
||||
import se.sics.mspsim.core.EmulationException;
|
||||
|
@ -468,7 +469,7 @@ public class MspCodeWatcher extends VisPlugin implements MotePlugin {
|
|||
}
|
||||
}
|
||||
|
||||
private MessageList rulesDebuggingOutput = new MessageList();
|
||||
private MessageListUI rulesDebuggingOutput = new MessageListUI();
|
||||
private boolean rulesWithDebuggingOutput = false;
|
||||
private int[] rulesMatched = null;
|
||||
private int[] rulesOK = null;
|
||||
|
|
|
@ -133,6 +133,7 @@ import org.contikios.cooja.dialogs.ConfigurationWizard;
|
|||
import org.contikios.cooja.dialogs.CreateSimDialog;
|
||||
import org.contikios.cooja.dialogs.ExternalToolsDialog;
|
||||
import org.contikios.cooja.dialogs.MessageList;
|
||||
import org.contikios.cooja.dialogs.MessageListUI;
|
||||
import org.contikios.cooja.dialogs.ProjectDirectoriesDialog;
|
||||
import org.contikios.cooja.plugins.MoteTypeInformation;
|
||||
import org.contikios.cooja.plugins.ScriptRunner;
|
||||
|
@ -3834,7 +3835,7 @@ public class Cooja extends Observable {
|
|||
/* Contiki error */
|
||||
if (exception instanceof ContikiError) {
|
||||
String contikiError = ((ContikiError) exception).getContikiError();
|
||||
MessageList list = new MessageList();
|
||||
MessageListUI list = new MessageListUI();
|
||||
for (String l: contikiError.split("\n")) {
|
||||
list.addMessage(l);
|
||||
}
|
||||
|
@ -3843,14 +3844,14 @@ public class Cooja extends Observable {
|
|||
}
|
||||
|
||||
/* Compilation output */
|
||||
MessageList compilationOutput = null;
|
||||
MessageListUI compilationOutput = null;
|
||||
if (exception instanceof MoteTypeCreationException
|
||||
&& ((MoteTypeCreationException) exception).hasCompilationOutput()) {
|
||||
compilationOutput = ((MoteTypeCreationException) exception).getCompilationOutput();
|
||||
compilationOutput = (MessageListUI) ((MoteTypeCreationException) exception).getCompilationOutput();
|
||||
} else if (exception.getCause() != null
|
||||
&& exception.getCause() instanceof MoteTypeCreationException
|
||||
&& ((MoteTypeCreationException) exception.getCause()).hasCompilationOutput()) {
|
||||
compilationOutput = ((MoteTypeCreationException) exception.getCause()).getCompilationOutput();
|
||||
compilationOutput = (MessageListUI) ((MoteTypeCreationException) exception.getCause()).getCompilationOutput();
|
||||
}
|
||||
if (compilationOutput != null) {
|
||||
compilationOutput.addPopupMenuItem(null, true);
|
||||
|
@ -3858,8 +3859,8 @@ public class Cooja extends Observable {
|
|||
}
|
||||
|
||||
/* Stack trace */
|
||||
MessageList stackTrace = new MessageList();
|
||||
PrintStream printStream = stackTrace.getInputStream(MessageList.NORMAL);
|
||||
MessageListUI stackTrace = new MessageListUI();
|
||||
PrintStream printStream = stackTrace.getInputStream(MessageListUI.NORMAL);
|
||||
exception.printStackTrace(printStream);
|
||||
stackTrace.addPopupMenuItem(null, true);
|
||||
tabbedPane.addTab("Java stack trace", new JScrollPane(stackTrace));
|
||||
|
@ -3931,7 +3932,7 @@ public class Cooja extends Observable {
|
|||
Box buttonBox = Box.createHorizontalBox();
|
||||
|
||||
/* Warnings message list */
|
||||
MessageList compilationOutput = new MessageList();
|
||||
MessageListUI compilationOutput = new MessageListUI();
|
||||
for (String w: warnings) {
|
||||
compilationOutput.addMessage(w, MessageList.ERROR);
|
||||
}
|
||||
|
@ -4354,14 +4355,14 @@ public class Cooja extends Observable {
|
|||
private static JProgressBar PROGRESS_BAR = null;
|
||||
private static ArrayList<String> PROGRESS_WARNINGS = new ArrayList<String>();
|
||||
public static void setProgressMessage(String msg) {
|
||||
setProgressMessage(msg, MessageList.NORMAL);
|
||||
setProgressMessage(msg, MessageListUI.NORMAL);
|
||||
}
|
||||
public static void setProgressMessage(String msg, int type) {
|
||||
if (PROGRESS_BAR != null && PROGRESS_BAR.isShowing()) {
|
||||
PROGRESS_BAR.setString(msg);
|
||||
PROGRESS_BAR.setStringPainted(true);
|
||||
}
|
||||
if (type != MessageList.NORMAL) {
|
||||
if (type != MessageListUI.NORMAL) {
|
||||
PROGRESS_WARNINGS.add(msg);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ import java.util.Vector;
|
|||
import org.contikios.cooja.MoteType.MoteTypeCreationException;
|
||||
import org.contikios.cooja.contikimote.ContikiMoteType;
|
||||
import org.contikios.cooja.dialogs.MessageList;
|
||||
import org.contikios.cooja.dialogs.MessageListUI;
|
||||
|
||||
/**
|
||||
* The purpose of corecomm's is communicating with a compiled Contiki system
|
||||
|
@ -203,9 +204,9 @@ public abstract class CoreComm {
|
|||
*/
|
||||
public static void compileSourceFile(String className)
|
||||
throws MoteTypeCreationException {
|
||||
MessageList compilationOutput = new MessageList();
|
||||
MessageListUI compilationOutput = new MessageListUI();
|
||||
OutputStream compilationStandardStream = compilationOutput
|
||||
.getInputStream(MessageList.NORMAL);
|
||||
.getInputStream(MessageListUI.NORMAL);
|
||||
OutputStream compilationErrorStream = compilationOutput
|
||||
.getInputStream(MessageList.ERROR);
|
||||
|
||||
|
|
|
@ -37,6 +37,7 @@ import org.jdom.Element;
|
|||
|
||||
import org.contikios.cooja.contikimote.ContikiMoteType;
|
||||
import org.contikios.cooja.dialogs.MessageList;
|
||||
import org.contikios.cooja.dialogs.MessageListUI;
|
||||
|
||||
/**
|
||||
* The mote type defines properties common for several motes. These properties
|
||||
|
|
|
@ -45,13 +45,11 @@ import java.util.Collection;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Vector;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
import javax.swing.JLabel;
|
||||
import org.apache.log4j.Level;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.jdom.Element;
|
||||
|
@ -68,8 +66,8 @@ import org.contikios.cooja.mote.memory.SectionMoteMemory;
|
|||
import org.contikios.cooja.Simulation;
|
||||
import org.contikios.cooja.dialogs.CompileContiki;
|
||||
import org.contikios.cooja.dialogs.ContikiMoteCompileDialog;
|
||||
import org.contikios.cooja.dialogs.MessageList;
|
||||
import org.contikios.cooja.dialogs.MessageList.MessageContainer;
|
||||
import org.contikios.cooja.dialogs.MessageListUI;
|
||||
import org.contikios.cooja.dialogs.MessageContainer;
|
||||
import org.contikios.cooja.mote.memory.ArrayMemory;
|
||||
import org.contikios.cooja.mote.memory.MemoryInterface;
|
||||
import org.contikios.cooja.mote.memory.MemoryInterface.Symbol;
|
||||
|
@ -319,7 +317,7 @@ public class ContikiMoteType implements MoteType {
|
|||
if (getCompileCommands() == null) {
|
||||
throw new MoteTypeCreationException("No compile commands specified");
|
||||
}
|
||||
final MessageList compilationOutput = new MessageList();
|
||||
final MessageListUI compilationOutput = new MessageListUI();
|
||||
String[] arr = getCompileCommands().split("\n");
|
||||
for (String cmd : arr) {
|
||||
if (cmd.trim().isEmpty()) {
|
||||
|
|
|
@ -468,7 +468,7 @@ public abstract class AbstractCompileDialog extends JDialog {
|
|||
|
||||
protected String[] compilationEnvironment = null; /* Default environment: inherit from current process */
|
||||
public void compileContiki() throws Exception {
|
||||
final MessageList taskOutput = new MessageList();
|
||||
final MessageListUI taskOutput = new MessageListUI();
|
||||
|
||||
if (contikiFirmware.exists()) {
|
||||
contikiFirmware.delete();
|
||||
|
@ -861,7 +861,7 @@ public abstract class AbstractCompileDialog extends JDialog {
|
|||
currentCompilationProcess = null;
|
||||
}
|
||||
|
||||
private boolean createNewCompilationTab(MessageList output) {
|
||||
private boolean createNewCompilationTab(MessageListUI output) {
|
||||
abortAnyCompilation();
|
||||
tabbedPane.remove(currentCompilationOutput);
|
||||
|
||||
|
|
|
@ -127,7 +127,7 @@ public class CompileContiki {
|
|||
/* TODO Fix me */
|
||||
final MessageList messageDialog;
|
||||
if (compilationOutput == null) {
|
||||
messageDialog = new MessageList();
|
||||
messageDialog = new MessageListUI();
|
||||
} else {
|
||||
messageDialog = compilationOutput;
|
||||
}
|
||||
|
@ -138,8 +138,8 @@ public class CompileContiki {
|
|||
cmd += c + " ";
|
||||
}
|
||||
logger.info("> " + cmd);
|
||||
messageDialog.addMessage("", MessageList.NORMAL);
|
||||
messageDialog.addMessage("> " + cmd, MessageList.NORMAL);
|
||||
messageDialog.addMessage("", MessageListUI.NORMAL);
|
||||
messageDialog.addMessage("> " + cmd, MessageListUI.NORMAL);
|
||||
}
|
||||
|
||||
final Process compileProcess;
|
||||
|
@ -170,7 +170,7 @@ public class CompileContiki {
|
|||
String readLine;
|
||||
while ((readLine = processNormal.readLine()) != null) {
|
||||
if (messageDialog != null) {
|
||||
messageDialog.addMessage(readLine, MessageList.NORMAL);
|
||||
messageDialog.addMessage(readLine, MessageListUI.NORMAL);
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
|
@ -203,7 +203,7 @@ public class CompileContiki {
|
|||
compileProcess.waitFor();
|
||||
} catch (Exception e) {
|
||||
messageDialog.addMessage(e.getMessage(), MessageList.ERROR);
|
||||
syncException.setCompilationOutput(new MessageList());
|
||||
syncException.setCompilationOutput(new MessageListUI());
|
||||
syncException.fillInStackTrace();
|
||||
return;
|
||||
}
|
||||
|
@ -214,7 +214,7 @@ public class CompileContiki {
|
|||
if (onFailure != null) {
|
||||
onFailure.actionPerformed(null);
|
||||
}
|
||||
syncException.setCompilationOutput(new MessageList());
|
||||
syncException.setCompilationOutput(new MessageListUI());
|
||||
syncException.fillInStackTrace();
|
||||
return;
|
||||
}
|
||||
|
@ -232,13 +232,13 @@ public class CompileContiki {
|
|||
if (onFailure != null) {
|
||||
onFailure.actionPerformed(null);
|
||||
}
|
||||
syncException.setCompilationOutput(new MessageList());
|
||||
syncException.setCompilationOutput(new MessageListUI());
|
||||
syncException.fillInStackTrace();
|
||||
return;
|
||||
}
|
||||
|
||||
messageDialog.addMessage("", MessageList.NORMAL);
|
||||
messageDialog.addMessage("Compilation succeded", MessageList.NORMAL);
|
||||
messageDialog.addMessage("", MessageListUI.NORMAL);
|
||||
messageDialog.addMessage("Compilation succeded", MessageListUI.NORMAL);
|
||||
if (onSuccess != null) {
|
||||
onSuccess.actionPerformed(null);
|
||||
}
|
||||
|
|
|
@ -150,7 +150,7 @@ public class ConfigurationWizard extends JDialog {
|
|||
private static int relBssSectionAddr;
|
||||
private static int bssSectionSize;
|
||||
|
||||
private static MessageList output;
|
||||
private static MessageListUI output;
|
||||
private static JDialog progressDialog;
|
||||
private static JButton button;
|
||||
private static JProgressBar progressBar;
|
||||
|
@ -430,7 +430,7 @@ public class ConfigurationWizard extends JDialog {
|
|||
}
|
||||
|
||||
private static void prepareShowTestProgress(JFrame parent, String desc) {
|
||||
output = new MessageList();
|
||||
output = new MessageListUI();
|
||||
output.addPopupMenuItem(null, true);
|
||||
progressDialog = new JDialog(parent, desc);
|
||||
button = new JButton("Close");
|
||||
|
@ -542,7 +542,7 @@ public class ConfigurationWizard extends JDialog {
|
|||
return (String) optionPane.getValue();
|
||||
}
|
||||
|
||||
public static boolean performCompileCTest(MessageList testOutput, PrintStream normalStream, PrintStream errorStream) {
|
||||
public static boolean performCompileCTest(MessageListUI testOutput, PrintStream normalStream, PrintStream errorStream) {
|
||||
javaLibraryName = "LibTest" + testCounter;
|
||||
cLibraryName = "libtest" + testCounter;
|
||||
cLibrarySourceFile = new File(ContikiMoteType.tempOutputDirectory, cLibraryName + ".c");
|
||||
|
@ -642,8 +642,8 @@ public class ConfigurationWizard extends JDialog {
|
|||
return true;
|
||||
}
|
||||
|
||||
public static boolean performLoadTest(MessageList testOutput, PrintStream normalStream, PrintStream errorStream) {
|
||||
MessageList dummy = new MessageList();
|
||||
public static boolean performLoadTest(MessageListUI testOutput, PrintStream normalStream, PrintStream errorStream) {
|
||||
MessageListUI dummy = new MessageListUI();
|
||||
PrintStream dummyStream = dummy.getInputStream(MessageList.NORMAL);
|
||||
if (!performCompileCTest(dummy, dummyStream, errorStream)) {
|
||||
return false;
|
||||
|
@ -696,8 +696,8 @@ public class ConfigurationWizard extends JDialog {
|
|||
return true;
|
||||
}
|
||||
|
||||
public static boolean performAddressTest(MessageList testOutput, PrintStream normalStream, PrintStream errorStream) {
|
||||
MessageList dummy = new MessageList();
|
||||
public static boolean performAddressTest(MessageListUI testOutput, PrintStream normalStream, PrintStream errorStream) {
|
||||
MessageListUI dummy = new MessageListUI();
|
||||
PrintStream dummyStream = dummy.getInputStream(MessageList.NORMAL);
|
||||
if (!performCompileCTest(dummy, dummyStream, errorStream)) {
|
||||
return false;
|
||||
|
@ -743,7 +743,7 @@ public class ConfigurationWizard extends JDialog {
|
|||
return false;
|
||||
}
|
||||
|
||||
private static boolean performMapAddressTest(MessageList testOutput, PrintStream normalStream, PrintStream errorStream) {
|
||||
private static boolean performMapAddressTest(MessageListUI testOutput, PrintStream normalStream, PrintStream errorStream) {
|
||||
testOutput.addMessage("### Testing map file based address parsing");
|
||||
|
||||
File mapFile = new File(ContikiMoteType.tempOutputDirectory, cLibraryName + ContikiMoteType.mapSuffix);
|
||||
|
@ -839,7 +839,7 @@ public class ConfigurationWizard extends JDialog {
|
|||
return true;
|
||||
}
|
||||
|
||||
private static boolean performCommandAddressTest(MessageList testOutput, PrintStream normalStream, PrintStream errorStream) {
|
||||
private static boolean performCommandAddressTest(MessageListUI testOutput, PrintStream normalStream, PrintStream errorStream) {
|
||||
testOutput.addMessage("### Testing command based address parsing");
|
||||
|
||||
testOutput.addMessage("### Executing command");
|
||||
|
@ -933,8 +933,8 @@ public class ConfigurationWizard extends JDialog {
|
|||
}
|
||||
|
||||
|
||||
public static boolean performMemoryReplacementTest(MessageList testOutput, PrintStream normalStream, PrintStream errorStream) {
|
||||
MessageList dummy = new MessageList();
|
||||
public static boolean performMemoryReplacementTest(MessageListUI testOutput, PrintStream normalStream, PrintStream errorStream) {
|
||||
MessageListUI dummy = new MessageListUI();
|
||||
PrintStream dummyStream = dummy.getInputStream(MessageList.NORMAL);
|
||||
if (!performCompileCTest(dummy, dummyStream, errorStream)) {
|
||||
return false;
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
package org.contikios.cooja.dialogs;
|
||||
|
||||
public class MessageContainer {
|
||||
|
||||
public final int type;
|
||||
public final String message;
|
||||
|
||||
public MessageContainer(String message, int type) {
|
||||
this.message = message;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return message;
|
||||
}
|
||||
}
|
|
@ -1,359 +1,17 @@
|
|||
/*
|
||||
* Copyright (c) 2006, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* 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
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.contikios.cooja.dialogs;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.datatransfer.Clipboard;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PipedInputStream;
|
||||
import java.io.PipedOutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.util.ArrayList;
|
||||
public interface MessageList {
|
||||
|
||||
import javax.swing.DefaultListCellRenderer;
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.JSeparator;
|
||||
import javax.swing.ListModel;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import org.apache.log4j.Logger;
|
||||
public static final int NORMAL = 0;
|
||||
public static final int WARNING = 1;
|
||||
public static final int ERROR = 2;
|
||||
|
||||
public void addMessage(String string, int normal);
|
||||
|
||||
import org.contikios.cooja.Cooja;
|
||||
public MessageContainer[] getMessages();
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adam Dunkels
|
||||
* @author Joakim Eriksson
|
||||
* @author Niclas Finne
|
||||
* @author Fredrik Osterlind
|
||||
*/
|
||||
public class MessageList extends JList {
|
||||
public void clearMessages();
|
||||
|
||||
private static final Logger logger = Logger.getLogger(MessageList.class);
|
||||
public void addMessage(String string);
|
||||
|
||||
public static final int NORMAL = 0;
|
||||
public static final int WARNING = 1;
|
||||
public static final int ERROR = 2;
|
||||
|
||||
private Color[] foregrounds = new Color[] { null, Color.red };
|
||||
private Color[] backgrounds = new Color[] { null, null };
|
||||
|
||||
private JPopupMenu popup = null;
|
||||
private boolean hideNormal = false;
|
||||
|
||||
private int max = -1;
|
||||
|
||||
public MessageList() {
|
||||
super.setModel(new MessageModel());
|
||||
setCellRenderer(new MessageRenderer());
|
||||
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param max Maximum number of messages
|
||||
*/
|
||||
public MessageList(int max) {
|
||||
this();
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
public Color getForeground(int type) {
|
||||
Color c = type > 0 && type <= foregrounds.length
|
||||
? foregrounds[type - 1] : null;
|
||||
return c == null ? getForeground() : c;
|
||||
}
|
||||
|
||||
public void setForeground(int type, Color color) {
|
||||
if (type > 0 && type <= foregrounds.length) {
|
||||
foregrounds[type - 1] = color;
|
||||
} else if (type == NORMAL) {
|
||||
setForeground(color);
|
||||
}
|
||||
}
|
||||
|
||||
public Color getBackground(int type) {
|
||||
Color c = type > 0 && type <= backgrounds.length
|
||||
? backgrounds[type - 1] : null;
|
||||
return c == null ? getBackground() : c;
|
||||
}
|
||||
|
||||
public void setBackground(int type, Color color) {
|
||||
if (type > 0 && type <= backgrounds.length) {
|
||||
backgrounds[type - 1] = color;
|
||||
} else if (type == NORMAL) {
|
||||
setBackground(color);
|
||||
}
|
||||
}
|
||||
|
||||
public PrintStream getInputStream(final int type) {
|
||||
try {
|
||||
PipedInputStream input = new PipedInputStream();
|
||||
PipedOutputStream output = new PipedOutputStream(input);
|
||||
final BufferedReader stringInput = new BufferedReader(new InputStreamReader(input));
|
||||
|
||||
Thread readThread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String readLine;
|
||||
try {
|
||||
while ((readLine = stringInput.readLine()) != null) {
|
||||
addMessage(readLine, type);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// Occurs when write end closes pipe - die quietly
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
readThread.start();
|
||||
|
||||
return new PrintStream(output);
|
||||
} catch (IOException e) {
|
||||
logger.error(messages);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void addMessage(String message) {
|
||||
addMessage(message, NORMAL);
|
||||
}
|
||||
|
||||
private ArrayList<MessageContainer> messages = new ArrayList<MessageContainer>();
|
||||
|
||||
public MessageContainer[] getMessages() {
|
||||
return messages.toArray(new MessageContainer[0]);
|
||||
}
|
||||
|
||||
private void updateModel() {
|
||||
boolean scroll = getLastVisibleIndex() >= getModel().getSize() - 2;
|
||||
|
||||
while (messages.size() > getModel().getSize()) {
|
||||
((DefaultListModel) getModel()).addElement(messages.get(getModel().getSize()));
|
||||
}
|
||||
while (max > 0 && getModel().getSize() > max) {
|
||||
((DefaultListModel) getModel()).removeElementAt(0);
|
||||
messages.remove(0);
|
||||
}
|
||||
|
||||
if (scroll) {
|
||||
ensureIndexIsVisible(getModel().getSize() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void addMessage(final String message, final int type) {
|
||||
Cooja.setProgressMessage(message, type);
|
||||
|
||||
MessageContainer msg = new MessageContainer(message, type);
|
||||
messages.add(msg);
|
||||
|
||||
java.awt.EventQueue.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateModel();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void clearMessages() {
|
||||
messages.clear();
|
||||
((DefaultListModel) getModel()).clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setModel(ListModel model) {
|
||||
throw new IllegalArgumentException("changing model not permitted");
|
||||
}
|
||||
|
||||
public void addPopupMenuItem(JMenuItem item, boolean withDefaults) {
|
||||
if (popup == null) {
|
||||
popup = new JPopupMenu();
|
||||
addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
popup.show(MessageList.this, e.getX(), e.getY());
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
popup.show(MessageList.this, e.getX(), e.getY());
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
popup.show(MessageList.this, e.getX(), e.getY());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
JMenuItem headerMenuItem = new JMenuItem("Output:");
|
||||
headerMenuItem.setEnabled(false);
|
||||
popup.add(headerMenuItem);
|
||||
popup.add(new JSeparator());
|
||||
|
||||
if (withDefaults) {
|
||||
/* Create default menu items */
|
||||
final JMenuItem hideNormalMenuItem = new JCheckBoxMenuItem("Hide normal output");
|
||||
hideNormalMenuItem.setEnabled(true);
|
||||
hideNormalMenuItem.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
MessageList.this.hideNormal = hideNormalMenuItem.isSelected();
|
||||
((MessageModel)getModel()).updateList();
|
||||
}
|
||||
});
|
||||
popup.add(hideNormalMenuItem);
|
||||
|
||||
JMenuItem consoleOutputMenuItem = new JMenuItem("Output to console");
|
||||
consoleOutputMenuItem.setEnabled(true);
|
||||
consoleOutputMenuItem.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
MessageContainer[] messages = getMessages();
|
||||
logger.info("\nCOMPILATION OUTPUT:\n");
|
||||
for (MessageContainer msg: messages) {
|
||||
if (hideNormal && msg.type == NORMAL) {
|
||||
continue;
|
||||
}
|
||||
logger.info(msg);
|
||||
}
|
||||
logger.info("\n");
|
||||
}
|
||||
});
|
||||
popup.add(consoleOutputMenuItem);
|
||||
|
||||
JMenuItem clipboardMenuItem = new JMenuItem("Copy to clipboard");
|
||||
clipboardMenuItem.setEnabled(true);
|
||||
clipboardMenuItem.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
MessageContainer[] messages = getMessages();
|
||||
for (MessageContainer msg: messages) {
|
||||
if (hideNormal && msg.type == NORMAL) {
|
||||
continue;
|
||||
}
|
||||
sb.append(msg + "\n");
|
||||
}
|
||||
|
||||
StringSelection stringSelection = new StringSelection(sb.toString());
|
||||
clipboard.setContents(stringSelection, null);
|
||||
}
|
||||
});
|
||||
popup.add(clipboardMenuItem);
|
||||
|
||||
popup.add(new JSeparator());
|
||||
}
|
||||
}
|
||||
|
||||
if (item == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
popup.add(item);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// MessageContainer
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
public static class MessageContainer {
|
||||
public final int type;
|
||||
public final String message;
|
||||
|
||||
public MessageContainer(String message, int type) {
|
||||
this.message = message;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return message;
|
||||
}
|
||||
|
||||
} // end of inner class MessageContainer
|
||||
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Renderer for messages
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
private class MessageModel extends DefaultListModel {
|
||||
public void updateList() {
|
||||
fireContentsChanged(this, 0, getSize());
|
||||
}
|
||||
}
|
||||
|
||||
private class MessageRenderer extends DefaultListCellRenderer {
|
||||
private Dimension nullDimension = new Dimension(0,0);
|
||||
@Override
|
||||
public Component getListCellRendererComponent(
|
||||
JList list,
|
||||
Object value,
|
||||
int index,
|
||||
boolean isSelected,
|
||||
boolean cellHasFocus)
|
||||
{
|
||||
super.getListCellRendererComponent(list, value, index, isSelected,
|
||||
cellHasFocus);
|
||||
MessageContainer msg = (MessageContainer) value;
|
||||
|
||||
if (hideNormal && msg.type == NORMAL && index != MessageList.this.getModel().getSize()-1) {
|
||||
setPreferredSize(nullDimension);
|
||||
return this;
|
||||
}
|
||||
|
||||
setPreferredSize(null);
|
||||
setForeground(((MessageList) list).getForeground(msg.type));
|
||||
setBackground(((MessageList) list).getBackground(msg.type));
|
||||
return this;
|
||||
}
|
||||
|
||||
} // end of inner class MessageRenderer
|
||||
|
||||
} // end of MessagList
|
||||
}
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
package org.contikios.cooja.dialogs;
|
||||
|
||||
public class MessageListText implements MessageList {
|
||||
|
||||
@Override
|
||||
public void addMessage(String string, int type) {
|
||||
System.out.println("Message:" + string);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MessageContainer[] getMessages() {
|
||||
// TODO Auto-generated method stub
|
||||
return new MessageContainer[0];
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clearMessages() {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addMessage(String string) {
|
||||
// TODO Auto-generated method stub
|
||||
addMessage(string, MessageList.NORMAL);
|
||||
}
|
||||
|
||||
}
|
334
tools/cooja/java/org/contikios/cooja/dialogs/MessageListUI.java
Normal file
334
tools/cooja/java/org/contikios/cooja/dialogs/MessageListUI.java
Normal file
|
@ -0,0 +1,334 @@
|
|||
/*
|
||||
* Copyright (c) 2006, Swedish Institute of Computer Science.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of the Institute nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* 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
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.contikios.cooja.dialogs;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.datatransfer.Clipboard;
|
||||
import java.awt.datatransfer.StringSelection;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.PipedInputStream;
|
||||
import java.io.PipedOutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import javax.swing.DefaultListCellRenderer;
|
||||
import javax.swing.DefaultListModel;
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.JSeparator;
|
||||
import javax.swing.ListModel;
|
||||
import javax.swing.ListSelectionModel;
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import org.contikios.cooja.Cooja;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Adam Dunkels
|
||||
* @author Joakim Eriksson
|
||||
* @author Niclas Finne
|
||||
* @author Fredrik Osterlind
|
||||
*/
|
||||
public class MessageListUI extends JList implements MessageList {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(MessageListUI.class);
|
||||
|
||||
private Color[] foregrounds = new Color[] { null, Color.red };
|
||||
private Color[] backgrounds = new Color[] { null, null };
|
||||
|
||||
private JPopupMenu popup = null;
|
||||
private boolean hideNormal = false;
|
||||
|
||||
private int max = -1;
|
||||
|
||||
public MessageListUI() {
|
||||
super.setModel(new MessageModel());
|
||||
setCellRenderer(new MessageRenderer());
|
||||
setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param max Maximum number of messages
|
||||
*/
|
||||
public MessageListUI(int max) {
|
||||
this();
|
||||
this.max = max;
|
||||
}
|
||||
|
||||
public Color getForeground(int type) {
|
||||
Color c = type > 0 && type <= foregrounds.length
|
||||
? foregrounds[type - 1] : null;
|
||||
return c == null ? getForeground() : c;
|
||||
}
|
||||
|
||||
public void setForeground(int type, Color color) {
|
||||
if (type > 0 && type <= foregrounds.length) {
|
||||
foregrounds[type - 1] = color;
|
||||
} else if (type == NORMAL) {
|
||||
setForeground(color);
|
||||
}
|
||||
}
|
||||
|
||||
public Color getBackground(int type) {
|
||||
Color c = type > 0 && type <= backgrounds.length
|
||||
? backgrounds[type - 1] : null;
|
||||
return c == null ? getBackground() : c;
|
||||
}
|
||||
|
||||
public void setBackground(int type, Color color) {
|
||||
if (type > 0 && type <= backgrounds.length) {
|
||||
backgrounds[type - 1] = color;
|
||||
} else if (type == NORMAL) {
|
||||
setBackground(color);
|
||||
}
|
||||
}
|
||||
|
||||
public PrintStream getInputStream(final int type) {
|
||||
try {
|
||||
PipedInputStream input = new PipedInputStream();
|
||||
PipedOutputStream output = new PipedOutputStream(input);
|
||||
final BufferedReader stringInput = new BufferedReader(new InputStreamReader(input));
|
||||
|
||||
Thread readThread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
String readLine;
|
||||
try {
|
||||
while ((readLine = stringInput.readLine()) != null) {
|
||||
addMessage(readLine, type);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
// Occurs when write end closes pipe - die quietly
|
||||
}
|
||||
}
|
||||
|
||||
});
|
||||
readThread.start();
|
||||
|
||||
return new PrintStream(output);
|
||||
} catch (IOException e) {
|
||||
logger.error(messages);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void addMessage(String message) {
|
||||
addMessage(message, NORMAL);
|
||||
}
|
||||
|
||||
private ArrayList<MessageContainer> messages = new ArrayList<MessageContainer>();
|
||||
|
||||
public MessageContainer[] getMessages() {
|
||||
return messages.toArray(new MessageContainer[0]);
|
||||
}
|
||||
|
||||
private void updateModel() {
|
||||
boolean scroll = getLastVisibleIndex() >= getModel().getSize() - 2;
|
||||
|
||||
while (messages.size() > getModel().getSize()) {
|
||||
((DefaultListModel<MessageContainer>) getModel()).addElement(messages.get(getModel().getSize()));
|
||||
}
|
||||
while (max > 0 && getModel().getSize() > max) {
|
||||
((DefaultListModel) getModel()).removeElementAt(0);
|
||||
messages.remove(0);
|
||||
}
|
||||
|
||||
if (scroll) {
|
||||
ensureIndexIsVisible(getModel().getSize() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
public void addMessage(final String message, final int type) {
|
||||
Cooja.setProgressMessage(message, type);
|
||||
|
||||
MessageContainer msg = new MessageContainer(message, type);
|
||||
messages.add(msg);
|
||||
|
||||
java.awt.EventQueue.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
updateModel();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void clearMessages() {
|
||||
messages.clear();
|
||||
((DefaultListModel) getModel()).clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setModel(ListModel model) {
|
||||
throw new IllegalArgumentException("changing model not permitted");
|
||||
}
|
||||
|
||||
public void addPopupMenuItem(JMenuItem item, boolean withDefaults) {
|
||||
if (popup == null) {
|
||||
popup = new JPopupMenu();
|
||||
addMouseListener(new MouseAdapter() {
|
||||
@Override
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
popup.show(MessageListUI.this, e.getX(), e.getY());
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void mousePressed(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
popup.show(MessageListUI.this, e.getX(), e.getY());
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void mouseReleased(MouseEvent e) {
|
||||
if (e.isPopupTrigger()) {
|
||||
popup.show(MessageListUI.this, e.getX(), e.getY());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
JMenuItem headerMenuItem = new JMenuItem("Output:");
|
||||
headerMenuItem.setEnabled(false);
|
||||
popup.add(headerMenuItem);
|
||||
popup.add(new JSeparator());
|
||||
|
||||
if (withDefaults) {
|
||||
/* Create default menu items */
|
||||
final JMenuItem hideNormalMenuItem = new JCheckBoxMenuItem("Hide normal output");
|
||||
hideNormalMenuItem.setEnabled(true);
|
||||
hideNormalMenuItem.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
MessageListUI.this.hideNormal = hideNormalMenuItem.isSelected();
|
||||
((MessageModel)getModel()).updateList();
|
||||
}
|
||||
});
|
||||
popup.add(hideNormalMenuItem);
|
||||
|
||||
JMenuItem consoleOutputMenuItem = new JMenuItem("Output to console");
|
||||
consoleOutputMenuItem.setEnabled(true);
|
||||
consoleOutputMenuItem.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
MessageContainer[] messages = getMessages();
|
||||
logger.info("\nCOMPILATION OUTPUT:\n");
|
||||
for (MessageContainer msg: messages) {
|
||||
if (hideNormal && msg.type == NORMAL) {
|
||||
continue;
|
||||
}
|
||||
logger.info(msg);
|
||||
}
|
||||
logger.info("\n");
|
||||
}
|
||||
});
|
||||
popup.add(consoleOutputMenuItem);
|
||||
|
||||
JMenuItem clipboardMenuItem = new JMenuItem("Copy to clipboard");
|
||||
clipboardMenuItem.setEnabled(true);
|
||||
clipboardMenuItem.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
MessageContainer[] messages = getMessages();
|
||||
for (MessageContainer msg: messages) {
|
||||
if (hideNormal && msg.type == NORMAL) {
|
||||
continue;
|
||||
}
|
||||
sb.append(msg + "\n");
|
||||
}
|
||||
|
||||
StringSelection stringSelection = new StringSelection(sb.toString());
|
||||
clipboard.setContents(stringSelection, null);
|
||||
}
|
||||
});
|
||||
popup.add(clipboardMenuItem);
|
||||
|
||||
popup.add(new JSeparator());
|
||||
}
|
||||
}
|
||||
|
||||
if (item == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
popup.add(item);
|
||||
}
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
// Renderer for messages
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
private class MessageModel extends DefaultListModel {
|
||||
public void updateList() {
|
||||
fireContentsChanged(this, 0, getSize());
|
||||
}
|
||||
}
|
||||
|
||||
private class MessageRenderer extends DefaultListCellRenderer {
|
||||
private Dimension nullDimension = new Dimension(0,0);
|
||||
@Override
|
||||
public Component getListCellRendererComponent(
|
||||
JList list,
|
||||
Object value,
|
||||
int index,
|
||||
boolean isSelected,
|
||||
boolean cellHasFocus)
|
||||
{
|
||||
super.getListCellRendererComponent(list, value, index, isSelected,
|
||||
cellHasFocus);
|
||||
MessageContainer msg = (MessageContainer) value;
|
||||
|
||||
if (hideNormal && msg.type == NORMAL && index != MessageListUI.this.getModel().getSize()-1) {
|
||||
setPreferredSize(nullDimension);
|
||||
return this;
|
||||
}
|
||||
|
||||
setPreferredSize(null);
|
||||
setForeground(((MessageListUI) list).getForeground(msg.type));
|
||||
setBackground(((MessageListUI) list).getBackground(msg.type));
|
||||
return this;
|
||||
}
|
||||
|
||||
} // end of inner class MessageRenderer
|
||||
|
||||
} // end of MessagList
|
|
@ -85,6 +85,7 @@ import org.contikios.cooja.PluginType;
|
|||
import org.contikios.cooja.Simulation;
|
||||
import org.contikios.cooja.VisPlugin;
|
||||
import org.contikios.cooja.dialogs.MessageList;
|
||||
import org.contikios.cooja.dialogs.MessageListUI;
|
||||
import org.contikios.cooja.util.StringUtils;
|
||||
|
||||
@ClassDescription("Simulation script editor")
|
||||
|
@ -503,7 +504,7 @@ public class ScriptRunner extends VisPlugin {
|
|||
final BufferedReader err = new BufferedReader(new InputStreamReader(process.getErrorStream()));
|
||||
|
||||
/* GUI components */
|
||||
final MessageList testOutput = new MessageList();
|
||||
final MessageListUI testOutput = new MessageListUI();
|
||||
final AbstractAction abort = new AbstractAction() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
process.destroy();
|
||||
|
@ -538,14 +539,14 @@ public class ScriptRunner extends VisPlugin {
|
|||
String line;
|
||||
try {
|
||||
while ((line = input.readLine()) != null) {
|
||||
testOutput.addMessage(line, MessageList.NORMAL);
|
||||
testOutput.addMessage(line, MessageListUI.NORMAL);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
}
|
||||
|
||||
testOutput.addMessage("", MessageList.NORMAL);
|
||||
testOutput.addMessage("", MessageList.NORMAL);
|
||||
testOutput.addMessage("", MessageList.NORMAL);
|
||||
testOutput.addMessage("", MessageListUI.NORMAL);
|
||||
testOutput.addMessage("", MessageListUI.NORMAL);
|
||||
testOutput.addMessage("", MessageListUI.NORMAL);
|
||||
|
||||
/* Parse log file, check if test succeeded */
|
||||
try {
|
||||
|
@ -559,7 +560,7 @@ public class ScriptRunner extends VisPlugin {
|
|||
if (l == null) {
|
||||
line = "";
|
||||
}
|
||||
testOutput.addMessage(l, MessageList.NORMAL);
|
||||
testOutput.addMessage(l, MessageListUI.NORMAL);
|
||||
if (l.contains("TEST OK")) {
|
||||
testSucceeded = true;
|
||||
break;
|
||||
|
|
|
@ -46,7 +46,6 @@ import org.contikios.cooja.ClassDescription;
|
|||
import org.contikios.cooja.Mote;
|
||||
import org.contikios.cooja.Simulation;
|
||||
import org.contikios.cooja.SimEventCentral.MoteCountListener;
|
||||
import org.contikios.cooja.dialogs.MessageList.MessageContainer;
|
||||
import org.contikios.cooja.interfaces.IPAddress;
|
||||
import org.contikios.cooja.interfaces.Position;
|
||||
import org.contikios.cooja.interfaces.RimeAddress;
|
||||
|
|
|
@ -54,8 +54,8 @@ import org.contikios.cooja.Plugin;
|
|||
import org.contikios.cooja.ProjectConfig;
|
||||
import org.contikios.cooja.Simulation;
|
||||
import org.contikios.cooja.dialogs.CompileContiki;
|
||||
import org.contikios.cooja.dialogs.MessageList;
|
||||
import org.contikios.cooja.dialogs.MessageList.MessageContainer;
|
||||
import org.contikios.cooja.dialogs.MessageContainer;
|
||||
import org.contikios.cooja.dialogs.MessageListUI;
|
||||
import org.contikios.cooja.plugins.ScriptRunner;
|
||||
import org.contikios.cooja.PluginType;
|
||||
|
||||
|
@ -415,7 +415,7 @@ public class ExecuteJAR {
|
|||
}
|
||||
|
||||
logger.info("Building executable JAR: " + outputFile);
|
||||
MessageList errors = new MessageList();
|
||||
MessageListUI errors = new MessageListUI();
|
||||
try {
|
||||
CompileContiki.compile(
|
||||
"jar cfm " + outputFile.getAbsolutePath() + " manifest.tmp .",
|
||||
|
|
Loading…
Reference in a new issue