Great! I was trying to do this in recent few days.
Actually the output window is very useful (snap shot, video, zoom,...)
. In addition to using Mason itself for Multi-Agent simulation, I use
the window for my analyzer tool.
The fact that Mason is light weight (in comparison to other
libraries/tool boxes I have used before) and the design (separate
sections) make it very useful for big simulations. I have had up to
100,000 pedestrians (with
On Thu, Feb 21, 2008 at 5:53 AM, Sean Luke <[log in to unmask]> wrote:
> Siamak asked how one might go about displaying only a Display2D.
> I've been fooling around a little bit to put together a bit of code
> explaining this.
>
> Before I go on, here are some very slightly revised files for
> Display2D and Display3D which I'll commit to CVS when I am able (I'm
> typing this on the plane :-) ...
>
>
>
>
> The first step is to start the Console by yourself, rather than
> having the user do it. This is easy: you just call Console.pressPlay
> (). For example, in the main() method of HeatBugsWithUI, you could
> do this:
>
> public static void main(String[] args)
> {
> HeatBugsWithSimpleUI heatbugs = new HeatBugsWithSimpleUI();
> Console c = new Console(heatbugs);
> c.pressPlay();
> }
>
> The second step is to hide the Console. There are two parts to
> this. First, you keep it from showing up in the first place, and
> second, you remove the menu option on the Display2D or Display3D
> which pops it up later. To keep it from showing in the first place,
> just don't call Console.setVisible() in your main method. In the
> main method above, notice that it's not called. To eliminate the
> menu, I have a simple hack: you'll need to prevent Display2D and
> Display3D's createConsoleMenu() from doing anything when called. For
> example, in HeatBugsWithUI's init() method, you change
>
> display = new Display2D(400,400,this,1)
>
> to...
>
> display = new Display2D(400,400,this,1)
> {
> public void createConsoleMenu() { }
> };
>
> Basically we're making an anonymous subclass of Display2D which does
> our bidding.
>
> Third, you need to prevent the close box from merely HIDING the
> Display2D rather than doing something smarter, like exiting the
> program. To do this, add this to the very end of your init() method
> in HeatBugsWithUI:
>
> // change the behavior of the display so when we close it, the
> program quits.
> // other options are:
> // HIDE_ON_CLOSE hide the window
> // DISPOSE_ON_CLOSE close and delete the window but don't quit the
> program
> // DO_NOTHINg_ON_CLOSE Ignore the close button
> displayFrame.setDefaultCloseOperation
> (javax.swing.JFrame.EXIT_ON_CLOSE);
>
> This isn't the greatest approach because the quit() method is never
> called on your GUIState. This has various undesirable results: for
> example, if the user is making a movie, it won't get flushed out
> properly when he closes the window.
>
> Instead you could set the default close operation to be dispose:
>
> displayFrame.setDefaultCloseOperation
> (javax.swing.JFrame.EXIT_ON_CLOSE);
>
> This disposes the window but it doesn't quit the program. How do we
> quit the program? When the Display2D's default JFrame is disposed,
> the first thing it does is call Display2D.quit(). We can tap into
> this in our Display2D subclass to call the doClose() method on our
> console, which clicks the *Console's* close box and quits the program
> cleanly:
>
> // Make the Display2D. We'll have it display stuff later.
> display = new Display2D(400,400,this,1)
> {
> public void createConsoleMenu() { }
> public void quit()
> {
> super.quit();
> ((Console)c).doClose();
> }
> };
>
> Not that to do this, you need to make the Controller c final in
> init's argument list.
>
> Last, you may wish to eliminate the entire header of the Display2D so
> the user can't scale, skip frames, make movies, etc. This is
> straightforward: in the init method, you just call:
>
> display.remove(display.header); // get rid of the header bar
>
> I've put together an example which does all of this for your viewing
> pleasure:
>
>
>
>
>
> Sean
>
>
>
>
>
|