Пример #1
0
  /**
   * This is called onyl if the GUI is on, and only to show the trade on the network
   *
   * @param sender the agent giving up the goods
   * @param receiver the agent receiving the goods
   * @param g what kind of good?
   * @param quantity how much is exchanged?
   */
  private void registerTradeOnNetwork(
      EconomicAgent sender, EconomicAgent receiver, GoodType g, int quantity) {
    // if graphing is not active, don't bother
    assert MacroII.hasGUI();

    assert network.containsAgent(sender);
    assert network.containsAgent(receiver);

    // if both are registered
    network.registerInventoryDelivery(sender, receiver, g, quantity);
  }
Пример #2
0
  /**
   * This is called when somebody is fired/quit/removed from the plant. So far it's purely
   * decorative (tells the network if the GUI is on)
   *
   * @param employer the employer
   * @param employee the employee
   */
  public void registerFiring(EconomicAgent employer, EconomicAgent employee) {
    // with no GUI, forget about it
    if (!MacroII.hasGUI()) return;

    boolean removedSuccessfully = network.removeEdges(employer, employee);
    assert removedSuccessfully;
  }
Пример #3
0
  /**
   * Remove a buyer from the registry as they exit the market
   *
   * @param buyer buyer exiting the market
   */
  public void deregisterBuyer(EconomicAgent buyer) {
    boolean isNew = buyers.remove(buyer);
    assert isNew; // make sure it wasn't there before!

    if (MacroII.hasGUI()) {
      // todo logtodo

      network.removeAgent(buyer);
    }
  }
Пример #4
0
  /**
   * Remove a seller from the registry as they exit the market
   *
   * @param seller seller exiting the market
   */
  public void deregisterSeller(EconomicAgent seller) {
    boolean isNew = sellers.remove(seller);
    assert isNew; // make sure it wasn't there before!

    if (MacroII.hasGUI()) {
      // todo logtodo

      // remove agent to the network
      network.removeAgent(seller);
    }
  }
Пример #5
0
  /**
   * Add a buyer to the registry as they enter the market
   *
   * @param buyer buyer entering the market
   */
  public void registerBuyer(EconomicAgent buyer) {
    boolean isNew = buyers.add(buyer); // addSalesDepartmentListener it to the set
    assert isNew; // make sure it wasn't there before!

    // record it, if necessary
    if (MacroII.hasGUI()) {
      // todo logtodo

      network.addAgent(buyer);
    }
  }
Пример #6
0
 /**
  * During weekends the market stores the volume
  *
  * @param model the simstate
  */
 public void weekEnd(MacroII model) {
   lastWeekVolume = weeklyVolume;
   //       if(!getGoodType().isLabor())
   //  volume.add(new Week(model.getWeeksPassed(), (int) (model.getWeeksPassed() /
   // model.getWeekLength())),weeklyVolume); //addSalesDepartmentListener it to the weeks
   weeklyVolume = 0;
   // if there is GUI, clear the network
   if (MacroII.hasGUI()) {
     network.weekEnd();
     // todo logtodo
   }
 }
Пример #7
0
  protected TabbedInspector buildInspector() {

    // create the network
    network = new ExchangeNetwork(getGoodType());

    // if there is no GUI, forget about it
    Preconditions.checkState(MacroII.hasGUI()); // can't be called otherwise!

    TabbedInspector toReturn = new TabbedInspector(true);
    toReturn.setName(toString() + " inspector");

    /**
     * ******************************************* Prices ******************************************
     */

    // switching to JavaFX for fun and profit
    // set up the chart
    panel = new JFXPanel();

    NumberAxis xAxis = new NumberAxis();
    NumberAxis yAxis = new NumberAxis();
    xAxis.setLabel("Day");
    yAxis.setLabel("Price");
    final LineChart<Number, Number> priceChart = new LineChart<>(xAxis, yAxis);
    priceChart.setAnimated(true);

    // set up the series
    priceSeries = new XYChart.Series<>();
    priceSeries.setName("LastClosingPrice");
    // now make the price update whenever data updates!
    // use steppable to update

    priceChart.getData().add(priceSeries);

    Platform.runLater(
        new Runnable() {
          @Override
          public void run() {
            panel.setScene(new Scene(priceChart));
          }
        });
    // we are going to add the new JPanel IN the new inspector
    closingPriceInspector =
        new Inspector() {
          @Override
          public void updateInspector() {
            SwingUtilities.invokeLater(
                new Runnable() {
                  public void run() {
                    repaint();
                  }
                });
          }
        };
    closingPriceInspector.setVolatile(true);
    closingPriceInspector.setLayout(new BorderLayout()); // this centers it
    closingPriceInspector.add(panel);

    toReturn.addInspector(closingPriceInspector, "Closing price");

    /**
     * ******************************************* VOLUME ******************************************
     */

    // switching to JavaFX for fun and profit
    // set up the chart
    final JFXPanel panel2 = new JFXPanel();

    xAxis = new NumberAxis();
    yAxis = new NumberAxis();
    xAxis.setLabel("Day");
    yAxis.setLabel("Volume");
    final LineChart<Number, Number> volumeChart = new LineChart<>(xAxis, yAxis);
    volumeChart.setAnimated(true);
    volumeChart.setCreateSymbols(false);
    // set up the series
    volumeSeries = new XYChart.Series<Number, Number>();
    volumeSeries.setName("Daily Volume Traded");

    volumeChart.getData().add(volumeSeries);
    Platform.runLater(
        new Runnable() {
          @Override
          public void run() {
            panel2.setScene(new Scene(volumeChart));
          }
        });
    // we are going to add the new JPanel IN the new inspector
    Inspector closingVolumeInspector =
        new Inspector() {
          @Override
          public void updateInspector() {
            SwingUtilities.invokeLater(
                new Runnable() {
                  public void run() {
                    repaint();
                  }
                });
          }
        };
    closingVolumeInspector.setVolatile(true);
    closingVolumeInspector.setLayout(new BorderLayout()); // this centers it
    closingVolumeInspector.add(panel2);

    toReturn.addInspector(closingVolumeInspector, "Volume");

    /**
     * ******************************************* TIMELINE
     * ******************************************
     */
    // todo logtodo

    /**
     * ************************************************* Network
     * *************************************************
     */
    Inspector networkInspector =
        new Inspector() {
          @Override
          public void updateInspector() {
            SwingUtilities.invokeLater(
                new Runnable() {
                  public void run() {
                    repaint();
                  }
                });
          }
        };
    networkInspector.setLayout(new BorderLayout());
    // add the visualization
    networkInspector.add(network.getVisualization());
    toReturn.addInspector(networkInspector, "Network");

    return toReturn;
  }