bugfix: previously did not listen to all log interfaces
This commit is contained in:
parent
fe8417bd8a
commit
6d987651c6
1 changed files with 67 additions and 84 deletions
|
@ -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: Mote2MoteRelations.java,v 1.4 2010/02/05 09:07:58 fros4943 Exp $
|
* $Id: Mote2MoteRelations.java,v 1.5 2010/02/09 22:14:23 fros4943 Exp $
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package se.sics.cooja.interfaces;
|
package se.sics.cooja.interfaces;
|
||||||
|
@ -39,7 +39,6 @@ import java.util.Observer;
|
||||||
import javax.swing.BoxLayout;
|
import javax.swing.BoxLayout;
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.SwingUtilities;
|
|
||||||
|
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.jdom.Element;
|
import org.jdom.Element;
|
||||||
|
@ -48,7 +47,8 @@ import se.sics.cooja.ClassDescription;
|
||||||
import se.sics.cooja.GUI;
|
import se.sics.cooja.GUI;
|
||||||
import se.sics.cooja.Mote;
|
import se.sics.cooja.Mote;
|
||||||
import se.sics.cooja.MoteInterface;
|
import se.sics.cooja.MoteInterface;
|
||||||
import se.sics.cooja.SimEventCentral.MoteCountListener;
|
import se.sics.cooja.SimEventCentral.LogOutputEvent;
|
||||||
|
import se.sics.cooja.SimEventCentral.LogOutputListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mote2Mote Relations is used to show mote relations in simulated
|
* Mote2Mote Relations is used to show mote relations in simulated
|
||||||
|
@ -79,38 +79,18 @@ public class Mote2MoteRelations extends MoteInterface {
|
||||||
private static Logger logger = Logger.getLogger(Mote2MoteRelations.class);
|
private static Logger logger = Logger.getLogger(Mote2MoteRelations.class);
|
||||||
private Mote mote = null;
|
private Mote mote = null;
|
||||||
|
|
||||||
private Log log;
|
|
||||||
private ArrayList<Mote> relations = new ArrayList<Mote>();
|
private ArrayList<Mote> relations = new ArrayList<Mote>();
|
||||||
private GUI gui;
|
private GUI gui;
|
||||||
|
|
||||||
private MoteCountListener moteCountListener;
|
private LogOutputListener logListener;
|
||||||
|
|
||||||
public Mote2MoteRelations(Mote mote) {
|
public Mote2MoteRelations(Mote mote) {
|
||||||
this.mote = mote;
|
this.mote = mote;
|
||||||
this.gui = mote.getSimulation().getGUI();
|
this.gui = mote.getSimulation().getGUI();
|
||||||
|
|
||||||
/* XXX Bug: Infinitely repeating runnable if no log interface exists! */
|
mote.getSimulation().getEventCentral().addLogOutputListener(logListener = new LogOutputListener() {
|
||||||
Runnable init = new Runnable() {
|
|
||||||
public void run() {
|
|
||||||
if (Mote2MoteRelations.this.mote.getInterfaces() == null
|
|
||||||
|| Mote2MoteRelations.this.mote.getInterfaces().getLog() == null) {
|
|
||||||
SwingUtilities.invokeLater(this);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
log = Mote2MoteRelations.this.mote.getInterfaces().getLog();
|
|
||||||
if (log == null) {
|
|
||||||
SwingUtilities.invokeLater(this);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
log.addObserver(logObserver);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
init.run();
|
|
||||||
|
|
||||||
mote.getSimulation().getEventCentral().addMoteCountListener(moteCountListener = new MoteCountListener() {
|
|
||||||
public void moteWasAdded(Mote mote) {
|
public void moteWasAdded(Mote mote) {
|
||||||
|
/* Ignored */
|
||||||
}
|
}
|
||||||
public void moteWasRemoved(Mote mote) {
|
public void moteWasRemoved(Mote mote) {
|
||||||
/* This mote was removed - cleanup by removed() */
|
/* This mote was removed - cleanup by removed() */
|
||||||
|
@ -125,24 +105,28 @@ public class Mote2MoteRelations extends MoteInterface {
|
||||||
relations.remove(mote);
|
relations.remove(mote);
|
||||||
gui.removeMoteRelation(Mote2MoteRelations.this.mote, mote);
|
gui.removeMoteRelation(Mote2MoteRelations.this.mote, mote);
|
||||||
}
|
}
|
||||||
|
public void newLogOutput(LogOutputEvent ev) {
|
||||||
|
handleNewLog(ev.msg);
|
||||||
|
}
|
||||||
|
public void removedLogOutput(LogOutputEvent ev) {
|
||||||
|
/* Ignored */
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removed() {
|
public void removed() {
|
||||||
super.removed();
|
super.removed();
|
||||||
|
|
||||||
for (Mote m: relations) {
|
Mote[] relationsArr = relations.toArray(new Mote[0]);
|
||||||
|
for (Mote m: relationsArr) {
|
||||||
gui.removeMoteRelation(Mote2MoteRelations.this.mote, m);
|
gui.removeMoteRelation(Mote2MoteRelations.this.mote, m);
|
||||||
}
|
}
|
||||||
relations.clear();
|
relations.clear();
|
||||||
|
|
||||||
mote.getSimulation().getEventCentral().removeMoteCountListener(moteCountListener);
|
mote.getSimulation().getEventCentral().removeLogOutputListener(logListener);
|
||||||
mote.getInterfaces().getLog().deleteObserver(logObserver);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Observer logObserver = new Observer() {
|
private void handleNewLog(String msg) {
|
||||||
public void update(Observable o, Object arg) {
|
|
||||||
String msg = log.getLastLogMessage();
|
|
||||||
if (msg == null) {
|
if (msg == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -193,7 +177,6 @@ public class Mote2MoteRelations extends MoteInterface {
|
||||||
setChanged();
|
setChanged();
|
||||||
notifyObservers();
|
notifyObservers();
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
public JPanel getInterfaceVisualizer() {
|
public JPanel getInterfaceVisualizer() {
|
||||||
JPanel panel = new JPanel();
|
JPanel panel = new JPanel();
|
||||||
|
|
Loading…
Reference in a new issue