Start button listener

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Start button listener

RALITERA Tahina Vololona Eulalie
Hi all,

How can I add a listener to the start/Pause/stop button on Repast Simphony?
I found that source code but it doesn't work:

Controller c = (Controller)this.getController();
  c.addStartListener(new ActionListener() {
    public void actionPerformed(ActionEvent evt) {
      System.out.println("start");
    }
  });
 
Thanks and regards,

Tahina

------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|

Re: Start button listener

Tatara, Eric R.
You can add a RunListener to the Repast Controller:

 RSApplication.getRSApplicationInstance().getController().getScheduleRunner().addRunListener(new MyListener());;
   
An example MyListener class would be for example:

class MyListener implements RunListener {

        @Override
        public void stopped() {
            System.out.println("Stopped");
           
        }

        @Override
        public void paused() {
            System.out.println("Paused");
           
        }

        @Override
        public void started() {
            System.out.println("Started");
           
        }

        @Override
        public void restarted() {
            System.out.println("Restarted");
           
        }
       
    }

Eric Tatara, PhD, PE
Software Engineer
Global Security Sciences Division
Argonne National Laboratory

From: RALITERA Tahina Vololona Eulalie [[hidden email]]
Sent: Monday, May 02, 2016 7:07 AM
To: Repast List
Subject: [Repast-interest] Start button listener

Hi all,

How can I add a listener to the start/Pause/stop button on Repast Simphony?
I found that source code but it doesn't work:

Controller c = (Controller)this.getController();
  c.addStartListener(new ActionListener() {
    public void actionPerformed(ActionEvent evt) {
      System.out.println("start");
    }
  });
 
Thanks and regards,

Tahina

------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest
Reply | Threaded
Open this post in threaded view
|

Re: Start button listener

Jonas Andersen
In reply to this post by RALITERA Tahina Vololona Eulalie
Hi Tahina,

You can get notified of the start, pause, stop and restart events by implementing the RunListener interface. This isn't directly listening for events on the buttons but integrates with the Repast framework.

You will probably also need to create a custom model initializer (the only approach I've tested), to register the RunListener.

Below is an outline of the code

------
package my.example;

import repast.simphony.engine.environment.RunEnvironmentBuilder;
import repast.simphony.engine.environment.RunListener;
import repast.simphony.scenario.ModelInitializer;
import repast.simphony.scenario.Scenario;

public class MyInitializer implements ModelInitializer {

    @Override
    public void initialize(Scenario scenario, RunEnvironmentBuilder builder) {
        System.err.println("INITIALIZING!");
        builder.getScheduleRunner().addRunListener(new RunListener() {
           
            @Override
            public void stopped() {
                System.err.println("STOPPED!");
            }
           
            @Override
            public void started() {
                System.err.println("STARTED!");
            }
           
            @Override
            public void restarted() {
                System.err.println("RESTARTED!");
            }
           
            @Override
            public void paused() {
                System.err.println("PAUSED!");
            }
        });
    }
}
------

and in order to get your custom initializer called, you'll need to modify the scenario.xml file found in the <model>.rs folder. The following should be added at the end of the Scenario element (just before the </Scenario>):

<model.initializer class="my.example.MyInitializer" />

Best regards,

Jonas Andersen


On 2 May 2016 at 14:07, RALITERA Tahina Vololona Eulalie <[hidden email]> wrote:
Hi all,

How can I add a listener to the start/Pause/stop button on Repast Simphony?
I found that source code but it doesn't work:

Controller c = (Controller)this.getController();
  c.addStartListener(new ActionListener() {
    public void actionPerformed(ActionEvent evt) {
      System.out.println("start");
    }
  });
 
Thanks and regards,

Tahina

------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest



------------------------------------------------------------------------------
Find and fix application performance issues faster with Applications Manager
Applications Manager provides deep performance insights into multiple tiers of
your business applications. It resolves application problems quickly and
reduces your MTTR. Get your free trial!
https://ad.doubleclick.net/ddm/clk/302982198;130105516;z
_______________________________________________
Repast-interest mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/repast-interest