public void init(Controller c) {
    super.init(c);

    // Make the Display2D.  We'll have it display stuff later.
    display = new Display2D(500, 500, this, 1); // at 400x400, we've got 4x4 per array position
    displayFrame = display.createFrame();
    c.registerFrame(displayFrame); // register the frame so it appears in the "Display" list
    displayFrame.setVisible(true);

    // attach the portrayals from bottom to top
    display.attach(foodPortrayal, "Food");
    display.attach(agentPortrayal, "Agents");
    displayFrame.setTitle("Agents");
    // specify the backdrop color  -- what gets painted behind the displays
    display.setBackdrop(Color.yellow);
    // Make the Display2D.  We'll have it display stuff later.
    display2 = new Display2D(400, 400, this, 1); // at 400x400, we've got 4x4 per array position
    displayFrame2 = display2.createFrame();
    displayFrame2.setTitle("Statistic");
    c.registerFrame(displayFrame2); // register the frame so it appears in the "Display" list
    displayFrame2.setVisible(false);
    // specify the backdrop color  -- what gets painted behind the displays
    display2.setBackdrop(Color.GRAY);
    // attach the portrayals from bottom to top
    display2.attach(summaryPortrayal, "Summary");
  }
  ChartGenerator createNewChart(final GUIState simulation) {
    generator = createNewGenerator();
    globalAttributes = new GlobalAttributes();
    generator.addGlobalAttribute(globalAttributes); // it'll be added last

    // set up the simulation -- need a new name other than guiObjects: and it should be
    // a HashMap rather than a Bag.
    if (simulation.guiObjects == null) simulation.guiObjects = new Bag();
    simulation.guiObjects.add(generator);
    final JFrame f = generator.createFrame(simulation);
    WindowListener wl =
        new WindowListener() {
          public void windowActivated(WindowEvent e) {}

          public void windowClosed(WindowEvent e) {}

          public void windowClosing(WindowEvent e) {
            generator.quit();
          }

          public void windowDeactivated(WindowEvent e) {}

          public void windowDeiconified(WindowEvent e) {}

          public void windowIconified(WindowEvent e) {}

          public void windowOpened(WindowEvent e) {}
        };
    f.addWindowListener(wl);
    f.setVisible(true);

    return generator;
  }
Exemplo n.º 3
0
  /**
   * Schedules a series with the MASON simulation. You specify a value provider to give series data
   * each timestep. This value provider can be null, in which case no data will ever be updated --
   * you'd have to update it on your own as you saw fit.
   */
  public static Stoppable scheduleSeries(
      final GUIState state,
      final BarChartSeriesAttributes attributes,
      final ProvidesCollection valueProvider) {
    return state.scheduleRepeatingImmediatelyAfter(
        new Steppable() {
          double last = state.state.schedule.BEFORE_SIMULATION;

          public void step(SimState state) {
            double x = state.schedule.getTime();
            if (x > last && x >= state.schedule.EPOCH && x < state.schedule.AFTER_SIMULATION) {
              last = x;
              if (valueProvider != null) {
                final Collection vals = valueProvider.provide();

                // JFreeChart isn't synchronized.  So we have to update it from the Swing Event
                // Thread
                if (vals != null)
                  SwingUtilities.invokeLater(
                      new Runnable() {
                        public void run() {
                          attributes.setElements(new ArrayList(vals));
                        }
                      });
              }
              // this will get pushed on the swing queue late
              attributes.getGenerator().updateChartLater(state.schedule.getSteps());
            }
          }
        });
  }
Exemplo n.º 4
0
  /**
   * Schedules a series with the MASON simulation. You specify a value provider to give series data
   * each timestep. This value provider can be null, in which case no data will ever be updated --
   * you'd have to update it on your own as you saw fit.
   */
  public static Stoppable scheduleSeries(
      final GUIState state, final TimeSeriesAttributes attributes, final Valuable valueProvider) {
    return state.scheduleRepeatingImmediatelyAfter(
        new Steppable() {
          final XYSeries series = attributes.getSeries();
          double last = state.state.schedule.BEFORE_SIMULATION;

          public void step(SimState state) {
            final double x = state.schedule.getTime();
            if (x > last && x >= state.schedule.EPOCH && x < state.schedule.AFTER_SIMULATION) {
              last = x;
              final double value =
                  (valueProvider == null) ? Double.NaN : valueProvider.doubleValue();

              // JFreeChart isn't synchronized.  So we have to update it from the Swing Event Thread
              SwingUtilities.invokeLater(
                  new Runnable() {
                    public void run() {
                      attributes.possiblyCull();
                      series.add(x, value, true);
                    }
                  });
              // this will get pushed on the swing queue late
              attributes.getGenerator().updateChartLater(state.schedule.getSteps());
            }
          }
        });
  }
Exemplo n.º 5
0
  public void quit() {
    super.quit();
    display = null;

    if (displayFrame != null) {
      JFrame f = displayFrame;
      displayFrame = null;
      f.dispose();
    }
  }
  // this method is called when the user close the java window
  public void quit() {
    super.quit();

    // disposing the displayFrame automatically calls quit() on the display,
    // so we don't need to do so ourselves here.
    if (displayFrame != null) {
      displayFrame.dispose();
      displayFrame2.dispose();
    }
    // displayFrame = null;  // let gc
    // displayFrame2=null;
    // display = null;       // let gc
    // display2=null;
  }
Exemplo n.º 7
0
  public void init(final Controller c) {
    super.init(c);

    // make the displayer
    display =
        new Display2D(448, 560, this) {
          public void createConsoleMenu() {}

          public void quit() {
            super.quit();
            ((SimpleController) c).doClose();
          }
        };

    display.setBackdrop(Color.black);

    displayFrame = display.createFrame();
    displayFrame.setTitle("MASON Pac Man");
    c.registerFrame(displayFrame); // register the frame so it appears in the "Display" list
    displayFrame.setVisible(true);

    // Notice the order: first the background, then the dots, then the agents, then the overlay
    display.attach(mazePortrayal, "Maze");
    // display.attach( background, "Background");
    display.attach(dotPortrayal, "Dots", 8, 8, true);
    display.attach(agentPortrayal, "Agents", 8, 8, true);
    display.attach(new Overlay(this), "Overlay");

    // Some stuff to make this feel less like MASON
    // delete the header
    display.remove(display.header);
    // delete all listeners
    display.removeListeners();
    // delete the scroll bars
    display.display.setVerticalScrollBarPolicy(display.display.VERTICAL_SCROLLBAR_NEVER);
    display.display.setHorizontalScrollBarPolicy(display.display.HORIZONTAL_SCROLLBAR_NEVER);
    // when we close the window, the application quits
    displayFrame.setDefaultCloseOperation(javax.swing.JFrame.DISPOSE_ON_CLOSE);
    // can't resize
    displayFrame.setResizable(false);
    // add antialiasing and interpolation
    display.insideDisplay.setupHints(true, false, false);

    // the window won't be the right size now -- modify it.
    displayFrame.pack();

    // Now we add in the listeners we want
    addListeners(display);
  }
Exemplo n.º 8
0
 public void load(SimState state) {
   super.load(state);
   setupPortrayals();
 }
Exemplo n.º 9
0
 public void start() {
   super.start();
   setupPortrayals();
 }
 public void start() {
   super.start(); // set up everything but replacing the display
   // set up our portrayals
   setupPortrayals();
 }
 public void load(SimState state) {
   super.load(state);
   // we now have new grids.  Set up the portrayals to reflect that
   setupPortrayals();
 }