示例#1
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());
            }
          }
        });
  }
示例#2
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());
            }
          }
        });
  }