Пример #1
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;
  }