register as observer at end of constructor
This commit is contained in:
parent
65a2f11887
commit
9b433cc06a
1 changed files with 38 additions and 31 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: 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;
|
package se.sics.cooja.plugins;
|
||||||
|
@ -69,28 +69,6 @@ public class SimInformation extends VisPlugin {
|
||||||
|
|
||||||
simulation = simulationToView;
|
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;
|
JLabel label;
|
||||||
JPanel mainPane = new JPanel();
|
JPanel mainPane = new JPanel();
|
||||||
mainPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
|
mainPane.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
|
||||||
|
@ -109,10 +87,11 @@ public class SimInformation extends VisPlugin {
|
||||||
smallPane.add(Box.createHorizontalGlue());
|
smallPane.add(Box.createHorizontalGlue());
|
||||||
|
|
||||||
label = new JLabel();
|
label = new JLabel();
|
||||||
if (simulation.isRunning())
|
if (simulation.isRunning()) {
|
||||||
label.setText("RUNNING");
|
label.setText("RUNNING");
|
||||||
else
|
} else {
|
||||||
label.setText("STOPPED");
|
label.setText("STOPPED");
|
||||||
|
}
|
||||||
|
|
||||||
labelStatus = label;
|
labelStatus = label;
|
||||||
smallPane.add(label);
|
smallPane.add(label);
|
||||||
|
@ -212,6 +191,32 @@ public class SimInformation extends VisPlugin {
|
||||||
this.setContentPane(mainPane);
|
this.setContentPane(mainPane);
|
||||||
pack();
|
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 {
|
try {
|
||||||
setSelected(true);
|
setSelected(true);
|
||||||
} catch (java.beans.PropertyVetoException e) {
|
} catch (java.beans.PropertyVetoException e) {
|
||||||
|
@ -222,11 +227,13 @@ public class SimInformation extends VisPlugin {
|
||||||
|
|
||||||
public void closePlugin() {
|
public void closePlugin() {
|
||||||
// Remove log observer from all log interfaces
|
// Remove log observer from all log interfaces
|
||||||
if (simObserver != null)
|
if (simObserver != null) {
|
||||||
simulation.deleteObserver(simObserver);
|
simulation.deleteObserver(simObserver);
|
||||||
|
}
|
||||||
|
|
||||||
if (tickObserver != null)
|
if (tickObserver != null) {
|
||||||
simulation.deleteTickObserver(tickObserver);
|
simulation.deleteTickObserver(tickObserver);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue