/**
   * Create a GUI that shows a graph for the specified user's payoff history
   *
   * @param user The user to show the Payoff history for
   */
  public GraphGUI(User user) {
    super(
        user.getUserName()
            + "'s Payoff History (Over "
            + user.getPayoffHistory().size()
            + " Steps)");

    this.userInfo = user;
    this.pack();

    // Set size
    this.setMinimumSize(new Dimension(500, 500));

    // Center the graph
    this.setLocationRelativeTo(null);

    // Create a series collection
    xySeriesCollection = new XYSeriesCollection();

    // Create (refresh) chart data
    refreshChartData();

    // Create an XY Line Chart
    chart =
        ChartFactory.createXYLineChart(
            "User Payoff Over Time",
            "Steps (Simulation Iterations)",
            "User Payoff",
            xySeriesCollection);
    chart.getPlot().setBackgroundPaint(Color.WHITE);
    chart.getPlot().setOutlinePaint(Color.BLACK);

    // Draw the Initial Chart
    chart.draw(
        (Graphics2D) this.getGraphics(),
        (Rectangle2D) new Rectangle2D.Double(0, 0, this.getWidth(), this.getHeight()));

    // Set the content pane to a graphics panel for drawing the graph
    this.setContentPane(new GraphPanel(this));

    // Show the frame
    this.setVisible(true);

    // Subscribe to the user's UserPayoff events
    user.addPayoffListener(this);
  }
예제 #2
0
 /** Creates fundamental diagram chart. */
 private JFreeChart makeFDChart() {
   updateFDSeries();
   XYSeriesCollection dataset = new XYSeriesCollection();
   dataset.addSeries(ffFD);
   dataset.addSeries(cFD);
   dataset.addSeries(cdFD);
   JFreeChart chart =
       ChartFactory.createXYLineChart(
           null, // chart title
           "Density (vpm)", // x axis label
           "Flow (vph)", // y axis label
           dataset, // data
           PlotOrientation.VERTICAL,
           false, // include legend
           false, // tooltips
           false // urls
           );
   XYPlot plot = (XYPlot) chart.getPlot();
   plot.getRenderer().setSeriesPaint(0, Color.GREEN);
   plot.getRenderer().setSeriesPaint(1, Color.RED);
   plot.getRenderer().setSeriesPaint(2, Color.BLUE);
   plot.getRenderer().setStroke(new BasicStroke(2));
   return chart;
 }