added support for multiple log interfaces
This commit is contained in:
parent
c0e12ffa54
commit
f1db103777
|
@ -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: LogVisualizerSkin.java,v 1.4 2009/10/28 15:42:03 fros4943 Exp $
|
* $Id: LogVisualizerSkin.java,v 1.5 2010/02/12 09:25:46 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.plugins.skins;
|
package se.sics.cooja.plugins.skins;
|
||||||
|
@ -42,10 +42,14 @@ import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import se.sics.cooja.ClassDescription;
|
import se.sics.cooja.ClassDescription;
|
||||||
import se.sics.cooja.Mote;
|
import se.sics.cooja.Mote;
|
||||||
|
import se.sics.cooja.MoteInterface;
|
||||||
import se.sics.cooja.Simulation;
|
import se.sics.cooja.Simulation;
|
||||||
|
import se.sics.cooja.SimEventCentral.LogOutputEvent;
|
||||||
|
import se.sics.cooja.SimEventCentral.LogOutputListener;
|
||||||
import se.sics.cooja.SimEventCentral.MoteCountListener;
|
import se.sics.cooja.SimEventCentral.MoteCountListener;
|
||||||
import se.sics.cooja.interfaces.Log;
|
import se.sics.cooja.interfaces.Log;
|
||||||
import se.sics.cooja.interfaces.Position;
|
import se.sics.cooja.interfaces.Position;
|
||||||
|
import se.sics.cooja.interfaces.SerialPort;
|
||||||
import se.sics.cooja.plugins.Visualizer;
|
import se.sics.cooja.plugins.Visualizer;
|
||||||
import se.sics.cooja.plugins.VisualizerSkin;
|
import se.sics.cooja.plugins.VisualizerSkin;
|
||||||
|
|
||||||
|
@ -63,23 +67,17 @@ public class LogVisualizerSkin implements VisualizerSkin {
|
||||||
private Simulation simulation = null;
|
private Simulation simulation = null;
|
||||||
private Visualizer visualizer = null;
|
private Visualizer visualizer = null;
|
||||||
|
|
||||||
private Observer logObserver = new Observer() {
|
private LogOutputListener logOutputListener = new LogOutputListener() {
|
||||||
public void update(Observable obs, Object obj) {
|
public void moteWasAdded(Mote mote) {
|
||||||
visualizer.repaint();
|
visualizer.repaint();
|
||||||
}
|
}
|
||||||
};
|
|
||||||
private MoteCountListener newMotesListener = new MoteCountListener() {
|
|
||||||
public void moteWasAdded(Mote mote) {
|
|
||||||
Log log = mote.getInterfaces().getLog();
|
|
||||||
if (log != null) {
|
|
||||||
log.addObserver(logObserver);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
public void moteWasRemoved(Mote mote) {
|
public void moteWasRemoved(Mote mote) {
|
||||||
Log log = mote.getInterfaces().getLog();
|
visualizer.repaint();
|
||||||
if (log != null) {
|
|
||||||
log.deleteObserver(logObserver);
|
|
||||||
}
|
}
|
||||||
|
public void newLogOutput(LogOutputEvent ev) {
|
||||||
|
visualizer.repaint();
|
||||||
|
}
|
||||||
|
public void removedLogOutput(LogOutputEvent ev) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -87,17 +85,11 @@ public class LogVisualizerSkin implements VisualizerSkin {
|
||||||
this.simulation = simulation;
|
this.simulation = simulation;
|
||||||
this.visualizer = vis;
|
this.visualizer = vis;
|
||||||
|
|
||||||
simulation.getEventCentral().addMoteCountListener(newMotesListener);
|
simulation.getEventCentral().addLogOutputListener(logOutputListener);
|
||||||
for (Mote m: simulation.getMotes()) {
|
|
||||||
newMotesListener.moteWasAdded(m);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setInactive() {
|
public void setInactive() {
|
||||||
simulation.getEventCentral().removeMoteCountListener(newMotesListener);
|
simulation.getEventCentral().removeLogOutputListener(logOutputListener);
|
||||||
for (Mote m: simulation.getMotes()) {
|
|
||||||
newMotesListener.moteWasRemoved(m);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Color[] getColorOf(Mote mote) {
|
public Color[] getColorOf(Mote mote) {
|
||||||
|
@ -114,11 +106,17 @@ public class LogVisualizerSkin implements VisualizerSkin {
|
||||||
/* Paint last output below motes */
|
/* Paint last output below motes */
|
||||||
Mote[] allMotes = simulation.getMotes();
|
Mote[] allMotes = simulation.getMotes();
|
||||||
for (Mote mote: allMotes) {
|
for (Mote mote: allMotes) {
|
||||||
Log log = mote.getInterfaces().getLog();
|
String msg = null;
|
||||||
if (log == null) {
|
for (MoteInterface mi: mote.getInterfaces().getInterfaces()) {
|
||||||
|
if (!(mi instanceof Log)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
String msg = log.getLastLogMessage();
|
Log log = (Log) mi;
|
||||||
|
if (log.getLastLogMessage() == null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
msg = log.getLastLogMessage();
|
||||||
|
}
|
||||||
if (msg == null) {
|
if (msg == null) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue