mirror of
https://github.com/oliverschmidt/contiki.git
synced 2025-01-23 20:30:07 +00:00
register as observer at end of constructor
This commit is contained in:
parent
65a2f11887
commit
9b433cc06a
@ -26,7 +26,7 @@
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* $Id: SimInformation.java,v 1.3 2007/01/09 09:49:24 fros4943 Exp $
|
||||
* $Id: SimInformation.java,v 1.4 2007/11/23 06:21:24 fros4943 Exp $
|
||||
*/
|
||||
|
||||
package se.sics.cooja.plugins;
|
||||
@ -69,28 +69,6 @@ public class SimInformation extends VisPlugin {
|
||||
|
||||
simulation = simulationToView;
|
||||
|
||||
// Register as simulation observer
|
||||
simulation.addObserver(simObserver = new Observer() {
|
||||
public void update(Observable obs, Object obj) {
|
||||
if (simulation.isRunning()) {
|
||||
labelStatus.setText("RUNNING");
|
||||
} else {
|
||||
labelStatus.setText("STOPPED");
|
||||
}
|
||||
labelNrMotes.setText("" + simulation.getMotesCount());
|
||||
labelNrMoteTypes.setText("" + simulation.getMoteTypes().size());
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
// Register as tick observer
|
||||
simulation.addTickObserver(tickObserver = new Observer() {
|
||||
public void update(Observable obs, Object obj) {
|
||||
if (labelSimTime != null)
|
||||
labelSimTime.setText("" + simulation.getSimulationTime());
|
||||
}
|
||||
});
|
||||
|
||||
JLabel label;
|
||||
JPanel mainPane = new JPanel();
|
||||
mainPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
|
||||
@ -109,10 +87,11 @@ public class SimInformation extends VisPlugin {
|
||||
smallPane.add(Box.createHorizontalGlue());
|
||||
|
||||
label = new JLabel();
|
||||
if (simulation.isRunning())
|
||||
if (simulation.isRunning()) {
|
||||
label.setText("RUNNING");
|
||||
else
|
||||
} else {
|
||||
label.setText("STOPPED");
|
||||
}
|
||||
|
||||
labelStatus = label;
|
||||
smallPane.add(label);
|
||||
@ -212,6 +191,32 @@ public class SimInformation extends VisPlugin {
|
||||
this.setContentPane(mainPane);
|
||||
pack();
|
||||
|
||||
// Register as simulation observer
|
||||
simulation.addObserver(simObserver = new Observer() {
|
||||
public void update(Observable obs, Object obj) {
|
||||
if (simulation == null) {
|
||||
return;
|
||||
}
|
||||
if (simulation.isRunning()) {
|
||||
labelStatus.setText("RUNNING");
|
||||
} else {
|
||||
labelStatus.setText("STOPPED");
|
||||
}
|
||||
labelNrMotes.setText("" + simulation.getMotesCount());
|
||||
labelNrMoteTypes.setText("" + simulation.getMoteTypes().size());
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
// Register as tick observer
|
||||
simulation.addTickObserver(tickObserver = new Observer() {
|
||||
public void update(Observable obs, Object obj) {
|
||||
if (labelSimTime != null) {
|
||||
labelSimTime.setText("" + simulation.getSimulationTime());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
setSelected(true);
|
||||
} catch (java.beans.PropertyVetoException e) {
|
||||
@ -222,11 +227,13 @@ public class SimInformation extends VisPlugin {
|
||||
|
||||
public void closePlugin() {
|
||||
// Remove log observer from all log interfaces
|
||||
if (simObserver != null)
|
||||
if (simObserver != null) {
|
||||
simulation.deleteObserver(simObserver);
|
||||
}
|
||||
|
||||
if (tickObserver != null)
|
||||
if (tickObserver != null) {
|
||||
simulation.deleteTickObserver(tickObserver);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user