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