MASON-INTEREST-L Archives

October 2006

MASON-INTEREST-L@LISTSERV.GMU.EDU

Options: Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Sean Luke <[log in to unmask]>
Reply To:
MASON Multiagent Simulation Toolkit <[log in to unmask]>
Date:
Tue, 10 Oct 2006 12:41:02 -0400
Content-Type:
text/plain
Parts/Attachments:
text/plain (76 lines)
On Oct 10, 2006, at 11:40 AM, Maciej M. Latek wrote:

> Everything depends on the layout you are using. In most cases, a
> straightforward application of any of them to repaint a dynamic  
> network each
> MASON time step will result in display of many intermittent JUNG  
> steps,
> which makes things slower and certainly a lot uglier.

If the issue is that JUNG is taking too long to repaint, here's  
another approach.  Let's say that you've inserted into your  
GUIState's "mini-schedule" a repeating Steppable that looks like this:

public class MySteppable extends Steppable
	{
	public void step(SimState state) { if (myJungComponent!=null)  
myJungComponent.repaint(); }
	}



You could set this up to only update within N milliseconds like this:


public class MySteppable extends Steppable
	{
	    Thread timer = null;
	    public void startTimer(final long milliseconds)
	       {
	       if (timer == null)
	           timer= sim.util.Utilities.doLater(milliseconds, new  
Runnable()
	              {
	              public void run()
	                  {
	                  if (myJungComponent!=null) myJungComponent.repaint();
	                  timer = null;  // reset the timer
	                  }
	              });
	       }

	   public void step(SimState state) { startTimer(100); }

	}

This guarantees that only one repaint will be forced every 100ms.  Of  
course, it also delays your repaint by as much as 100ms -- if you'd  
like an immediate repaint followed by a 100ms wait, an easy way to do  
it is to just do a repaint now and a repaint at 100ms later like this:

public class MySteppable extends Steppable
	{
	    long lastRepaint = 0;
	    public void startTimer(final long milliseconds)
	       {
	       if (timer == null)
		   {
	           if (myJungComponent!=null) myJungComponent.repaint();  //  
repaint now
	           timer= sim.util.Utilities.doLater(milliseconds, new  
Runnable()
	              {
	              public void run()
	                  {
	                  if (myJungComponent!=null) myJungComponent.repaint 
();  // repaint later
	                  timer = null;  // reset the timer
	                  }
	              });
	       }

	   public void step(SimState state) { startTimer(100); }
	}

Sean

ATOM RSS1 RSS2