コード例 #1
0
  private Tuple2<TableView<Offer>, VBox> getOfferTable(Offer.Direction direction) {
    TableView<Offer> tableView = new TableView();

    // price
    TableColumn<Offer, Offer> priceColumn = new TableColumn<>();
    priceColumn.textProperty().bind(priceColumnLabel);
    priceColumn.setMinWidth(120);
    priceColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
    priceColumn.setCellFactory(
        new Callback<TableColumn<Offer, Offer>, TableCell<Offer, Offer>>() {
          @Override
          public TableCell<Offer, Offer> call(TableColumn<Offer, Offer> column) {
            return new TableCell<Offer, Offer>() {
              @Override
              public void updateItem(final Offer item, boolean empty) {
                super.updateItem(item, empty);
                if (item != null && !empty) setText(formatter.formatFiat(item.getPrice()));
                else setText("");
              }
            };
          }
        });
    tableView.getColumns().add(priceColumn);

    // amount
    TableColumn<Offer, Offer> amountColumn = new TableColumn<>("Amount (BTC)");
    amountColumn.setText("Amount (BTC)");
    amountColumn.setMinWidth(120);
    amountColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
    amountColumn.setCellFactory(
        new Callback<TableColumn<Offer, Offer>, TableCell<Offer, Offer>>() {
          @Override
          public TableCell<Offer, Offer> call(TableColumn<Offer, Offer> column) {
            return new TableCell<Offer, Offer>() {
              @Override
              public void updateItem(final Offer item, boolean empty) {
                super.updateItem(item, empty);
                if (item != null && !empty) setText(formatter.formatCoin(item.getAmount()));
                else setText("");
              }
            };
          }
        });
    tableView.getColumns().add(amountColumn);

    // volume
    TableColumn<Offer, Offer> volumeColumn = new TableColumn<>("Amount (BTC)");
    volumeColumn.setMinWidth(120);
    volumeColumn.textProperty().bind(volumeColumnLabel);
    volumeColumn.setCellValueFactory((offer) -> new ReadOnlyObjectWrapper<>(offer.getValue()));
    volumeColumn.setCellFactory(
        new Callback<TableColumn<Offer, Offer>, TableCell<Offer, Offer>>() {
          @Override
          public TableCell<Offer, Offer> call(TableColumn<Offer, Offer> column) {
            return new TableCell<Offer, Offer>() {
              @Override
              public void updateItem(final Offer item, boolean empty) {
                super.updateItem(item, empty);
                if (item != null && !empty) setText(formatter.formatFiat(item.getOfferVolume()));
                else setText("");
              }
            };
          }
        });
    tableView.getColumns().add(volumeColumn);

    tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
    Label placeholder = new Label("Currently there are no offers available");
    placeholder.setWrapText(true);
    tableView.setPlaceholder(placeholder);

    Label titleLabel =
        new Label(
            direction.equals(Offer.Direction.BUY)
                ? "Offers for buy bitcoin (bid)"
                : "Offers for sell bitcoin (ask)");
    titleLabel.setStyle("-fx-font-weight: bold; -fx-font-size: 16; -fx-alignment: center");
    UserThread.execute(() -> titleLabel.prefWidthProperty().bind(tableView.widthProperty()));

    VBox vBox = new VBox();
    vBox.setSpacing(10);
    vBox.setFillWidth(true);
    vBox.setMinHeight(150);
    vBox.getChildren().addAll(titleLabel, tableView);
    return new Tuple2<>(tableView, vBox);
  }
コード例 #2
0
  private Button createCommandLinksButton(ButtonType buttonType) {
    // look up the CommandLinkButtonType for the given ButtonType
    CommandLinksButtonType commandLink =
        typeMap.getOrDefault(buttonType, new CommandLinksButtonType(buttonType));

    // put the content inside a button
    final Button button = new Button();
    button.getStyleClass().addAll("command-link-button"); // $NON-NLS-1$
    button.setMaxHeight(Double.MAX_VALUE);
    button.setMaxWidth(Double.MAX_VALUE);
    button.setAlignment(Pos.CENTER_LEFT);

    final ButtonData buttonData = buttonType.getButtonData();
    button.setDefaultButton(buttonData != null && buttonData.isDefaultButton());
    button.setOnAction(ae -> setResult(buttonType));

    final Label titleLabel = new Label(commandLink.getButtonType().getText());
    titleLabel
        .minWidthProperty()
        .bind(
            new DoubleBinding() {
              {
                bind(titleLabel.prefWidthProperty());
              }

              @Override
              protected double computeValue() {
                return titleLabel.getPrefWidth() + 400;
              }
            });
    titleLabel.getStyleClass().addAll("line-1"); // $NON-NLS-1$
    titleLabel.setWrapText(true);
    titleLabel.setAlignment(Pos.TOP_LEFT);
    GridPane.setVgrow(titleLabel, Priority.NEVER);

    Label messageLabel = new Label(commandLink.getLongText());
    messageLabel.getStyleClass().addAll("line-2"); // $NON-NLS-1$
    messageLabel.setWrapText(true);
    messageLabel.setAlignment(Pos.TOP_LEFT);
    messageLabel.setMaxHeight(Double.MAX_VALUE);
    GridPane.setVgrow(messageLabel, Priority.SOMETIMES);

    Node commandLinkImage = commandLink.getGraphic();
    Node view =
        commandLinkImage == null
            ? new ImageView(
                CommandLinksDialog.class.getResource("arrow-green-right.png").toExternalForm())
            : //$NON-NLS-1$
            commandLinkImage;
    Pane graphicContainer = new Pane(view);
    graphicContainer.getStyleClass().add("graphic-container"); // $NON-NLS-1$
    GridPane.setValignment(graphicContainer, VPos.TOP);
    GridPane.setMargin(graphicContainer, new Insets(0, 10, 0, 0));

    GridPane grid = new GridPane();
    grid.minWidthProperty().bind(titleLabel.prefWidthProperty());
    grid.setMaxHeight(Double.MAX_VALUE);
    grid.setMaxWidth(Double.MAX_VALUE);
    grid.getStyleClass().add("container"); // $NON-NLS-1$
    grid.add(graphicContainer, 0, 0, 1, 2);
    grid.add(titleLabel, 1, 0);
    grid.add(messageLabel, 1, 1);

    button.setGraphic(grid);
    button.minWidthProperty().bind(titleLabel.prefWidthProperty());

    if (commandLink.isHidden) {
      button.setVisible(false);
      button.setPrefHeight(1);
    }
    return button;
  }