Add ScnObservable class with setChangedAndNotify() function
The ScnObservable extends the normal Observable with the combined setChangedAndNotify() function
This commit is contained in:
parent
ddf970d3db
commit
42077adbb1
|
@ -53,6 +53,8 @@ import org.contikios.cooja.Simulation;
|
|||
import org.contikios.cooja.interfaces.DirectionalAntennaRadio;
|
||||
import org.contikios.cooja.interfaces.Radio;
|
||||
import org.contikios.cooja.radiomediums.AbstractRadioMedium;
|
||||
import org.contikios.cooja.util.ScnObservable;
|
||||
|
||||
import statistics.GaussianWrapper;
|
||||
|
||||
/**
|
||||
|
@ -103,13 +105,7 @@ public class ChannelModel {
|
|||
/**
|
||||
* Notifies observers when this channel model has changed settings.
|
||||
*/
|
||||
private class SettingsObservable extends Observable {
|
||||
private void notifySettingsChanged() {
|
||||
setChanged();
|
||||
notifyObservers();
|
||||
}
|
||||
}
|
||||
private SettingsObservable settingsObservable = new SettingsObservable();
|
||||
private ScnObservable settingsObservable = new ScnObservable();
|
||||
public enum Parameter {
|
||||
apply_random,
|
||||
snr_threshold,
|
||||
|
@ -330,7 +326,7 @@ public class ChannelModel {
|
|||
*/
|
||||
public void removeAllObstacles() {
|
||||
myObstacleWorld.removeAll();
|
||||
settingsObservable.notifySettingsChanged();
|
||||
settingsObservable.setChangedAndNotify();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -360,7 +356,7 @@ public class ChannelModel {
|
|||
myObstacleWorld.addObstacle(startX, startY, width, height);
|
||||
|
||||
if (notify) {
|
||||
settingsObservable.notifySettingsChanged();
|
||||
settingsObservable.setChangedAndNotify();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -442,7 +438,7 @@ public class ChannelModel {
|
|||
needToPrecalculateFSPL = true;
|
||||
needToPrecalculateOutputPower = true;
|
||||
|
||||
settingsObservable.notifySettingsChanged();
|
||||
settingsObservable.setChangedAndNotify();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -450,7 +446,7 @@ public class ChannelModel {
|
|||
* will be notified.
|
||||
*/
|
||||
public void notifySettingsChanged() {
|
||||
settingsObservable.notifySettingsChanged();
|
||||
settingsObservable.setChangedAndNotify();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1884,7 +1880,7 @@ public class ChannelModel {
|
|||
}
|
||||
needToPrecalculateFSPL = true;
|
||||
needToPrecalculateOutputPower = true;
|
||||
settingsObservable.notifySettingsChanged();
|
||||
settingsObservable.setChangedAndNotify();
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ import org.contikios.cooja.interfaces.Position;
|
|||
import org.contikios.cooja.interfaces.Radio;
|
||||
import org.contikios.cooja.plugins.Visualizer;
|
||||
import org.contikios.cooja.radiomediums.AbstractRadioMedium;
|
||||
import org.contikios.cooja.util.ScnObservable;
|
||||
import org.contikios.mrm.ChannelModel.Parameter;
|
||||
import org.contikios.mrm.ChannelModel.RadioPair;
|
||||
import org.contikios.mrm.ChannelModel.TxPair;
|
||||
|
@ -93,7 +94,7 @@ public class MRM extends AbstractRadioMedium {
|
|||
/**
|
||||
* Notifies observers when this radio medium has changed settings.
|
||||
*/
|
||||
private SettingsObservable settingsObservable = new SettingsObservable();
|
||||
private ScnObservable settingsObservable = new ScnObservable();
|
||||
|
||||
/**
|
||||
* Creates a new Multi-path Ray-tracing Medium (MRM).
|
||||
|
@ -449,13 +450,6 @@ public class MRM extends AbstractRadioMedium {
|
|||
return currentChannelModel;
|
||||
}
|
||||
|
||||
class SettingsObservable extends Observable {
|
||||
private void notifySettingsChanged() {
|
||||
setChanged();
|
||||
notifyObservers();
|
||||
}
|
||||
}
|
||||
|
||||
class MRMRadioConnection extends RadioConnection {
|
||||
private Hashtable<Radio, Double> signalStrengths = new Hashtable<Radio, Double>();
|
||||
|
||||
|
|
|
@ -139,6 +139,7 @@ import org.contikios.cooja.plugins.ScriptRunner;
|
|||
import org.contikios.cooja.plugins.SimControl;
|
||||
import org.contikios.cooja.plugins.SimInformation;
|
||||
import org.contikios.cooja.util.ExecuteJAR;
|
||||
import org.contikios.cooja.util.ScnObservable;
|
||||
|
||||
/**
|
||||
* Main file of COOJA Simulator. Typically contains a visualizer for the
|
||||
|
@ -325,21 +326,10 @@ public class Cooja extends Observable {
|
|||
|
||||
private Vector<Class<? extends Positioner>> positionerClasses = new Vector<Class<? extends Positioner>>();
|
||||
|
||||
private class HighlightObservable extends Observable {
|
||||
private void setChangedAndNotify(Mote mote) {
|
||||
setChanged();
|
||||
notifyObservers(mote);
|
||||
}
|
||||
}
|
||||
private HighlightObservable moteHighlightObservable = new HighlightObservable();
|
||||
|
||||
private class MoteRelationsObservable extends Observable {
|
||||
private void setChangedAndNotify() {
|
||||
setChanged();
|
||||
notifyObservers();
|
||||
}
|
||||
}
|
||||
private MoteRelationsObservable moteRelationObservable = new MoteRelationsObservable();
|
||||
private ScnObservable moteHighlightObservable = new ScnObservable();
|
||||
|
||||
private ScnObservable moteRelationObservable = new ScnObservable();
|
||||
|
||||
private JTextPane quickHelpTextPane;
|
||||
private JScrollPane quickHelpScroll;
|
||||
|
|
|
@ -49,8 +49,10 @@ import org.contikios.cooja.Simulation;
|
|||
import org.contikios.cooja.TimeEvent;
|
||||
import org.contikios.cooja.interfaces.CustomDataRadio;
|
||||
import org.contikios.cooja.interfaces.Radio;
|
||||
import org.contikios.cooja.util.ScnObservable;
|
||||
import org.jdom.Element;
|
||||
|
||||
|
||||
/**
|
||||
* Abstract radio medium provides basic functionality for implementing radio
|
||||
* mediums.
|
||||
|
@ -90,17 +92,7 @@ public abstract class AbstractRadioMedium extends RadioMedium {
|
|||
public int COUNTER_RX = 0;
|
||||
public int COUNTER_INTERFERED = 0;
|
||||
|
||||
public class RadioMediumObservable extends Observable {
|
||||
public void setRadioMediumChanged() {
|
||||
setChanged();
|
||||
}
|
||||
public void setRadioMediumChangedAndNotify() {
|
||||
setChanged();
|
||||
notifyObservers();
|
||||
}
|
||||
}
|
||||
|
||||
private RadioMediumObservable radioMediumObservable = new RadioMediumObservable();
|
||||
protected ScnObservable radioMediumObservable = new ScnObservable();
|
||||
|
||||
/**
|
||||
* This constructor should always be called from implemented radio mediums.
|
||||
|
@ -288,7 +280,7 @@ public abstract class AbstractRadioMedium extends RadioMedium {
|
|||
|
||||
/* Notify observers */
|
||||
lastConnection = null;
|
||||
radioMediumObservable.setRadioMediumChangedAndNotify();
|
||||
radioMediumObservable.setChangedAndNotify();
|
||||
}
|
||||
break;
|
||||
case TRANSMISSION_FINISHED: {
|
||||
|
@ -333,7 +325,7 @@ public abstract class AbstractRadioMedium extends RadioMedium {
|
|||
updateSignalStrengths();
|
||||
|
||||
/* Notify observers */
|
||||
radioMediumObservable.setRadioMediumChangedAndNotify();
|
||||
radioMediumObservable.setChangedAndNotify();
|
||||
}
|
||||
break;
|
||||
case CUSTOM_DATA_TRANSMITTED: {
|
||||
|
|
|
@ -93,8 +93,7 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
|
|||
edges.add(e);
|
||||
requestEdgeAnalysis();
|
||||
|
||||
((AbstractRadioMedium.RadioMediumObservable)
|
||||
this.getRadioMediumObservable()).setRadioMediumChangedAndNotify();
|
||||
radioMediumObservable.setChangedAndNotify();
|
||||
}
|
||||
|
||||
public void removeEdge(Edge edge) {
|
||||
|
@ -105,16 +104,14 @@ public class DirectedGraphMedium extends AbstractRadioMedium {
|
|||
edges.remove(edge);
|
||||
requestEdgeAnalysis();
|
||||
|
||||
((AbstractRadioMedium.RadioMediumObservable)
|
||||
this.getRadioMediumObservable()).setRadioMediumChangedAndNotify();
|
||||
radioMediumObservable.setChangedAndNotify();
|
||||
}
|
||||
|
||||
public void clearEdges() {
|
||||
edges.clear();
|
||||
requestEdgeAnalysis();
|
||||
|
||||
((AbstractRadioMedium.RadioMediumObservable)
|
||||
this.getRadioMediumObservable()).setRadioMediumChangedAndNotify();
|
||||
radioMediumObservable.setChangedAndNotify();
|
||||
}
|
||||
|
||||
public Edge[] getEdges() {
|
||||
|
|
16
tools/cooja/java/org/contikios/cooja/util/ScnObservable.java
Normal file
16
tools/cooja/java/org/contikios/cooja/util/ScnObservable.java
Normal file
|
@ -0,0 +1,16 @@
|
|||
package org.contikios.cooja.util;
|
||||
|
||||
import java.util.Observable;
|
||||
|
||||
public class ScnObservable extends Observable {
|
||||
public void setChangedAndNotify() {
|
||||
setChanged();
|
||||
notifyObservers();
|
||||
}
|
||||
|
||||
public void setChangedAndNotify(Object obj) {
|
||||
setChanged();
|
||||
notifyObservers(obj);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue