Java Code Examples for javafx.scene.layout.GridPane#setMargin()

The following examples show how to use javafx.scene.layout.GridPane#setMargin() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FormBuilder.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
public static Tuple3<Label, Label, VBox> addLabelWithSubText(GridPane gridPane,
                                                             int rowIndex,
                                                             String title,
                                                             String description,
                                                             double top) {
    Label label = new AutoTooltipLabel(title);
    Label subText = new AutoTooltipLabel(description);

    VBox vBox = new VBox();
    vBox.getChildren().setAll(label, subText);

    GridPane.setRowIndex(vBox, rowIndex);
    GridPane.setMargin(vBox, new Insets(top, 0, 0, 0));
    gridPane.getChildren().add(vBox);

    return new Tuple3<>(label, subText, vBox);
}
 
Example 2
Source File: FormBuilder.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
public static Tuple2<Label, TextArea> addConfirmationLabelTextArea(GridPane gridPane,
                                                                   int rowIndex,
                                                                   String title1,
                                                                   String title2,
                                                                   double top) {
    Label label = addLabel(gridPane, rowIndex, title1);
    label.getStyleClass().add("confirmation-label");

    TextArea textArea = addTextArea(gridPane, rowIndex, title2);
    ((JFXTextArea) textArea).setLabelFloat(false);

    GridPane.setColumnIndex(textArea, 1);
    GridPane.setMargin(label, new Insets(top, 0, 0, 0));
    GridPane.setHalignment(label, HPos.LEFT);
    GridPane.setMargin(textArea, new Insets(top, 0, 0, 0));

    return new Tuple2<>(label, textArea);
}
 
Example 3
Source File: FormBuilder.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
@NotNull
public static Tuple2<Label, VBox> addTopLabelWithVBox(GridPane gridPane,
                                                      int rowIndex,
                                                      int columnIndex,
                                                      String title,
                                                      Node node,
                                                      double top) {
    final Tuple2<Label, VBox> topLabelWithVBox = getTopLabelWithVBox(title, node);
    VBox vBox = topLabelWithVBox.second;

    GridPane.setRowIndex(vBox, rowIndex);
    GridPane.setColumnIndex(vBox, columnIndex);
    GridPane.setMargin(vBox, new Insets(top + Layout.FLOATING_LABEL_DISTANCE, 0, 0, 0));
    gridPane.getChildren().add(vBox);

    return new Tuple2<>(topLabelWithVBox.first, vBox);
}
 
Example 4
Source File: FormBuilder.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
public static Tuple2<Label, TextFieldWithCopyIcon> addConfirmationLabelTextFieldWithCopyIcon(GridPane gridPane,
                                                                                             int rowIndex,
                                                                                             String title,
                                                                                             String value,
                                                                                             double top) {
    Label label = addLabel(gridPane, rowIndex, title, top);
    label.getStyleClass().add("confirmation-label");
    GridPane.setHalignment(label, HPos.LEFT);

    TextFieldWithCopyIcon textFieldWithCopyIcon = new TextFieldWithCopyIcon("confirmation-text-field-as-label");
    textFieldWithCopyIcon.setText(value);
    GridPane.setRowIndex(textFieldWithCopyIcon, rowIndex);
    GridPane.setColumnIndex(textFieldWithCopyIcon, 1);
    GridPane.setMargin(textFieldWithCopyIcon, new Insets(top, 0, 0, 0));
    gridPane.getChildren().add(textFieldWithCopyIcon);

    return new Tuple2<>(label, textFieldWithCopyIcon);
}
 
Example 5
Source File: FormBuilder.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
public static <T> Tuple3<Label, ComboBox<T>, Button> addLabelComboBoxButton(GridPane gridPane,
                                                                            int rowIndex,
                                                                            String title,
                                                                            String buttonTitle,
                                                                            double top) {
    Label label = addLabel(gridPane, rowIndex, title, top);

    HBox hBox = new HBox();
    hBox.setSpacing(10);

    Button button = new AutoTooltipButton(buttonTitle);
    button.setDefaultButton(true);

    ComboBox<T> comboBox = new JFXComboBox<>();

    hBox.getChildren().addAll(comboBox, button);

    GridPane.setRowIndex(hBox, rowIndex);
    GridPane.setColumnIndex(hBox, 1);
    GridPane.setMargin(hBox, new Insets(top, 0, 0, 0));
    gridPane.getChildren().add(hBox);

    return new Tuple3<>(label, comboBox, button);
}
 
Example 6
Source File: TakeOfferView.java    From bisq with GNU Affero General Public License v3.0 6 votes vote down vote up
private void addOptionsGroup() {
    advancedOptionsGroup = addTitledGroupBg(gridPane, ++gridRow, 1, Res.get("shared.advancedOptions"), Layout.COMPACT_GROUP_DISTANCE);

    advancedOptionsBox = new HBox();
    advancedOptionsBox.setSpacing(40);

    GridPane.setRowIndex(advancedOptionsBox, gridRow);
    GridPane.setColumnIndex(advancedOptionsBox, 0);
    GridPane.setHalignment(advancedOptionsBox, HPos.LEFT);
    GridPane.setMargin(advancedOptionsBox, new Insets(Layout.COMPACT_FIRST_ROW_AND_GROUP_DISTANCE, 0, 0, 0));
    gridPane.getChildren().add(advancedOptionsBox);

    advancedOptionsBox.getChildren().addAll(getTradeFeeFieldsBox());
}
 
Example 7
Source File: FormBuilder.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
public static PasswordTextField addPasswordTextField(GridPane gridPane, int rowIndex, String title, double top) {
    PasswordTextField passwordField = new PasswordTextField();
    passwordField.setPromptText(title);
    GridPane.setRowIndex(passwordField, rowIndex);
    GridPane.setColumnIndex(passwordField, 0);
    GridPane.setColumnSpan(passwordField, 2);
    GridPane.setMargin(passwordField, new Insets(top + 10, 0, 20, 0));
    gridPane.getChildren().add(passwordField);

    return passwordField;
}
 
Example 8
Source File: NewsView.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
private GridPane createBisqDAOOnTestnetContent() {
    GridPane gridPane = new GridPane();
    gridPane.setMaxWidth(370);

    int rowIndex = 0;

    TitledGroupBg titledGroupBg = addTitledGroupBg(gridPane, rowIndex, 14, Res.get("dao.news.DAOOnTestnet.title"));
    titledGroupBg.getStyleClass().addAll("last", "dao-news-titled-group");
    Label daoTestnetDescription = addMultilineLabel(gridPane, ++rowIndex, Res.get("dao.news.DAOOnTestnet.description"), 0, 370);
    GridPane.setMargin(daoTestnetDescription, new Insets(Layout.FLOATING_LABEL_DISTANCE, 0, 8, 0));
    daoTestnetDescription.getStyleClass().add("dao-news-content");

    rowIndex = addInfoSection(gridPane, rowIndex, Res.get("dao.news.DAOOnTestnet.firstSection.title"),
            Res.get("dao.news.DAOOnTestnet.firstSection.content"),
            "https://docs.bisq.network/getting-started-dao.html#switch-to-testnet-mode");
    rowIndex = addInfoSection(gridPane, rowIndex, Res.get("dao.news.DAOOnTestnet.secondSection.title"),
            Res.get("dao.news.DAOOnTestnet.secondSection.content"),
            "https://docs.bisq.network/getting-started-dao.html#acquire-some-bsq");
    rowIndex = addInfoSection(gridPane, rowIndex, Res.get("dao.news.DAOOnTestnet.thirdSection.title"),
            Res.get("dao.news.DAOOnTestnet.thirdSection.content"),
            "https://docs.bisq.network/getting-started-dao.html#participate-in-a-voting-cycle");
    rowIndex = addInfoSection(gridPane, rowIndex, Res.get("dao.news.DAOOnTestnet.fourthSection.title"),
            Res.get("dao.news.DAOOnTestnet.fourthSection.content"),
            "https://docs.bisq.network/getting-started-dao.html#explore-a-bsq-block-explorer");

    Hyperlink hyperlink = addHyperlinkWithIcon(gridPane, ++rowIndex, Res.get("dao.news.DAOOnTestnet.readMoreLink"),
            "https://bisq.network/docs/dao");
    hyperlink.getStyleClass().add("dao-news-link");

    return gridPane;
}
 
Example 9
Source File: FormBuilder.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
public static ToggleButton addSlideToggleButton(GridPane gridPane, int rowIndex, String title, double top) {
    ToggleButton toggleButton = new AutoTooltipSlideToggleButton();
    toggleButton.setText(title);
    GridPane.setRowIndex(toggleButton, rowIndex);
    GridPane.setColumnIndex(toggleButton, 0);
    GridPane.setMargin(toggleButton, new Insets(top, 0, 0, 0));
    gridPane.getChildren().add(toggleButton);

    return toggleButton;
}
 
Example 10
Source File: ManageMarketAlertsWindow.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
private void addContent() {
    TableView<MarketAlertFilter> tableView = new TableView<>();
    GridPane.setRowIndex(tableView, ++rowIndex);
    GridPane.setColumnSpan(tableView, 2);
    GridPane.setMargin(tableView, new Insets(10, 0, 0, 0));
    gridPane.getChildren().add(tableView);
    Label placeholder = new AutoTooltipLabel(Res.get("table.placeholder.noData"));
    placeholder.setWrapText(true);
    tableView.setPlaceholder(placeholder);
    tableView.setPrefHeight(300);
    tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);

    setColumns(tableView);
    tableView.setItems(FXCollections.observableArrayList(marketAlerts.getMarketAlertFilters()));
}
 
Example 11
Source File: FormBuilder.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
public static Tuple3<Button, Button, HBox> add2ButtonsWithBox(GridPane gridPane, int rowIndex, String title1,
                                                              String title2, double top, boolean hasPrimaryButton) {
    HBox hBox = new HBox();
    hBox.setSpacing(10);

    Button button1 = new AutoTooltipButton(title1);

    if (hasPrimaryButton) {
        button1.getStyleClass().add("action-button");
        button1.setDefaultButton(true);
    }

    button1.setMaxWidth(Double.MAX_VALUE);
    HBox.setHgrow(button1, Priority.ALWAYS);

    Button button2 = new AutoTooltipButton(title2);
    button2.setMaxWidth(Double.MAX_VALUE);
    HBox.setHgrow(button2, Priority.ALWAYS);

    hBox.getChildren().addAll(button1, button2);

    GridPane.setRowIndex(hBox, rowIndex);
    GridPane.setColumnIndex(hBox, 0);
    GridPane.setMargin(hBox, new Insets(top, 10, 0, 0));
    gridPane.getChildren().add(hBox);
    return new Tuple3<>(button1, button2, hBox);
}
 
Example 12
Source File: Overlay.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
private void addReportErrorButtons() {
    messageLabel.setText(Res.get("popup.reportError", truncatedMessage));

    Button logButton = new AutoTooltipButton(Res.get("popup.reportError.log"));
    GridPane.setMargin(logButton, new Insets(20, 0, 0, 0));
    GridPane.setHalignment(logButton, HPos.LEFT);
    GridPane.setRowIndex(logButton, ++rowIndex);
    gridPane.getChildren().add(logButton);
    logButton.setOnAction(event -> {
        try {
            File dataDir = Config.appDataDir();
            File logFile = new File(dataDir, "bisq.log");
            Utilities.openFile(logFile);
        } catch (IOException e) {
            e.printStackTrace();
            log.error(e.getMessage());
        }
    });

    Button gitHubButton = new AutoTooltipButton(Res.get("popup.reportError.gitHub"));
    GridPane.setHalignment(gitHubButton, HPos.RIGHT);
    GridPane.setRowIndex(gitHubButton, ++rowIndex);
    gridPane.getChildren().add(gitHubButton);
    gitHubButton.setOnAction(event -> {
        if (message != null)
            Utilities.copyToClipboard(message);
        GUIUtil.openWebPage("https://bisq.network/source/bisq/issues");
        hide();
    });
}
 
Example 13
Source File: SupplyView.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
private void addToTopMargin(Node child) {
    var margin = GridPane.getMargin(child);

    var new_insets = new Insets(
            margin.getTop() + Layout.COMPACT_FIRST_ROW_DISTANCE,
            margin.getRight(),
            margin.getBottom(),
            margin.getLeft()
    );

    GridPane.setMargin(child, new_insets);
}
 
Example 14
Source File: FormBuilder.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
public static Label addLabel(GridPane gridPane, int rowIndex, String title, double top) {
    Label label = new AutoTooltipLabel(title);
    GridPane.setRowIndex(label, rowIndex);
    GridPane.setMargin(label, new Insets(top, 0, 0, 0));
    gridPane.getChildren().add(label);
    return label;
}
 
Example 15
Source File: TorNetworkSettingsWindow.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
protected void addButtons() {
    closeButton = new AutoTooltipButton(closeButtonText == null ? Res.get("shared.close") : closeButtonText);
    closeButton.setOnAction(event -> doClose());

    if (actionHandlerOptional.isPresent()) {
        actionButton = new AutoTooltipButton(Res.get("shared.shutDown"));
        actionButton.setDefaultButton(true);
        //TODO app wide focus
        //actionButton.requestFocus();
        actionButton.setOnAction(event -> saveAndShutDown());

        Button urlButton = new AutoTooltipButton(Res.get("torNetworkSettingWindow.openTorWebPage"));
        urlButton.setOnAction(event -> {
            try {
                Utilities.openURI(URI.create("https://bridges.torproject.org/bridges"));
            } catch (IOException e) {
                e.printStackTrace();
            }
        });

        Pane spacer = new Pane();
        HBox hBox = new HBox();
        hBox.setSpacing(10);
        hBox.getChildren().addAll(spacer, urlButton, closeButton, actionButton);
        HBox.setHgrow(spacer, Priority.ALWAYS);

        GridPane.setHalignment(hBox, HPos.RIGHT);
        GridPane.setRowIndex(hBox, ++rowIndex);
        GridPane.setColumnSpan(hBox, 2);
        GridPane.setMargin(hBox, new Insets(buttonDistance, 0, 0, 0));
        gridPane.getChildren().add(hBox);
    } else if (!hideCloseButton) {
        closeButton.setDefaultButton(true);
        GridPane.setHalignment(closeButton, HPos.RIGHT);
        GridPane.setMargin(closeButton, new Insets(buttonDistance, 0, 0, 0));
        GridPane.setRowIndex(closeButton, rowIndex);
        GridPane.setColumnIndex(closeButton, 1);
        gridPane.getChildren().add(closeButton);
    }
}
 
Example 16
Source File: FormBuilder.java    From bisq with GNU Affero General Public License v3.0 5 votes vote down vote up
public static Label addMultilineLabel(GridPane gridPane, int rowIndex, String text, double top, double maxWidth) {
    Label label = new AutoTooltipLabel(text);
    label.setWrapText(true);
    label.setMaxWidth(maxWidth);
    GridPane.setHalignment(label, HPos.LEFT);
    GridPane.setHgrow(label, Priority.ALWAYS);
    GridPane.setRowIndex(label, rowIndex);
    GridPane.setMargin(label, new Insets(top + Layout.FLOATING_LABEL_DISTANCE, 0, 0, 0));
    gridPane.getChildren().add(label);
    return label;
}
 
Example 17
Source File: BuyerStep4View.java    From bisq with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected void addContent() {
    gridPane.getColumnConstraints().get(1).setHgrow(Priority.SOMETIMES);

    addTitledGroupBg(gridPane, gridRow, 5, Res.get("portfolio.pending.step5_buyer.groupTitle"), 0);
    addCompactTopLabelTextField(gridPane, gridRow, getBtcTradeAmountLabel(), model.getTradeVolume(), Layout.TWICE_FIRST_ROW_DISTANCE);

    addCompactTopLabelTextField(gridPane, ++gridRow, getFiatTradeAmountLabel(), model.getFiatVolume());
    addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("portfolio.pending.step5_buyer.refunded"), model.getSecurityDeposit());
    addCompactTopLabelTextField(gridPane, ++gridRow, Res.get("portfolio.pending.step5_buyer.tradeFee"), model.getTradeFee());
    final String miningFee = model.dataModel.isMaker() ?
            Res.get("portfolio.pending.step5_buyer.makersMiningFee") :
            Res.get("portfolio.pending.step5_buyer.takersMiningFee");
    addCompactTopLabelTextField(gridPane, ++gridRow, miningFee, model.getTxFee());
    withdrawTitledGroupBg = addTitledGroupBg(gridPane, ++gridRow, 1, Res.get("portfolio.pending.step5_buyer.withdrawBTC"), Layout.COMPACT_GROUP_DISTANCE);
    withdrawTitledGroupBg.getStyleClass().add("last");
    addCompactTopLabelTextField(gridPane, gridRow, Res.get("portfolio.pending.step5_buyer.amount"), model.getPayoutAmount(), Layout.FIRST_ROW_AND_GROUP_DISTANCE);
    withdrawAddressTextField = addInputTextField(gridPane, ++gridRow, Res.get("portfolio.pending.step5_buyer.withdrawToAddress"));
    withdrawAddressTextField.setManaged(false);
    withdrawAddressTextField.setVisible(false);

    HBox hBox = new HBox();
    hBox.setSpacing(10);
    useSavingsWalletButton = new AutoTooltipButton(Res.get("portfolio.pending.step5_buyer.moveToBisqWallet"));
    useSavingsWalletButton.setDefaultButton(true);
    useSavingsWalletButton.getStyleClass().add("action-button");
    Label label = new AutoTooltipLabel(Res.get("shared.OR"));
    label.setPadding(new Insets(5, 0, 0, 0));
    withdrawToExternalWalletButton = new AutoTooltipButton(Res.get("portfolio.pending.step5_buyer.withdrawExternal"));
    withdrawToExternalWalletButton.setDefaultButton(false);
    hBox.getChildren().addAll(useSavingsWalletButton, label, withdrawToExternalWalletButton);
    GridPane.setRowIndex(hBox, ++gridRow);
    GridPane.setMargin(hBox, new Insets(5, 10, 0, 0));
    gridPane.getChildren().add(hBox);

    useSavingsWalletButton.setOnAction(e -> {
        handleTradeCompleted();
        model.dataModel.tradeManager.addTradeToClosedTrades(trade);
    });
    withdrawToExternalWalletButton.setOnAction(e -> {
        onWithdrawal();
    });

    String key = "tradeCompleted" + trade.getId();
    if (!DevEnv.isDevMode() && DontShowAgainLookup.showAgain(key)) {
        DontShowAgainLookup.dontShowAgain(key, true);
        new Notification().headLine(Res.get("notification.tradeCompleted.headline"))
                .notification(Res.get("notification.tradeCompleted.msg"))
                .autoClose()
                .show();
    }
}
 
Example 18
Source File: PreferencesFxGroupRenderer.java    From PreferencesFX with Apache License 2.0 4 votes vote down vote up
/**
 * Defines the layout of the rendered group.
 */
public void layoutParts() {
  StringBuilder styleClass = new StringBuilder("group");

  // if there are no rows yet, getRowCount returns -1, in this case the next row is 0
  int nextRow = PreferencesFxUtils.getRowCount(grid) + 1;

  // Only when the preferencesGroup has a title
  if (preferencesGroup.getTitle() != null) {
    grid.add(titleLabel, 0, nextRow++, 2, 1);
    styleClass.append("-title");
    titleLabel.getStyleClass().add("group-title");
  }

  List<Element> elements = preferencesGroup.getElements().stream()
      .map(Element.class::cast)
      .collect(Collectors.toList());
  styleClass.append("-setting");

  int rowAmount = nextRow;
  for (int i = 0; i < elements.size(); i++) {
    // add to GridPane
    Element element = elements.get(i);
    if (element instanceof Field) {
      SimpleControl c = (SimpleControl) ((Field)element).getRenderer();
      c.setField((Field)element);
      grid.add(c.getFieldLabel(), 0, i + rowAmount, 1, 1);
      grid.add(c.getNode(), 1, i + rowAmount, 1, 1);

      // Styling
      GridPane.setHgrow(c.getNode(), Priority.SOMETIMES);
      GridPane.setValignment(c.getNode(), VPos.CENTER);
      GridPane.setValignment(c.getFieldLabel(), VPos.CENTER);

      // additional styling for the last setting
      if (i == elements.size() - 1) {
        styleClass.append("-last");
        GridPane.setMargin(
            c.getNode(),
            new Insets(0, 0, PreferencesFxFormRenderer.SPACING * 4, 0)
        );
        GridPane.setMargin(
            c.getFieldLabel(),
            new Insets(0, 0, PreferencesFxFormRenderer.SPACING * 4, 0)
        );
      }

      c.getFieldLabel().getStyleClass().add(styleClass.toString() + "-label");
      c.getNode().getStyleClass().add(styleClass.toString() + "-node");
    }
    if (element instanceof NodeElement) {
      NodeElement nodeElement = (NodeElement) element;
      grid.add(nodeElement.getNode(), 0, i + rowAmount, GridPane.REMAINING, 1);
    }
  }
}
 
Example 19
Source File: InfoDisplay.java    From bisq with GNU Affero General Public License v3.0 4 votes vote down vote up
public InfoDisplay() {
    icon.setId("non-clickable-icon");
    icon.visibleProperty().bind(visibleProperty());

    GridPane.setValignment(icon, VPos.TOP);
    GridPane.setMargin(icon, new Insets(-2, 0, 0, 0));
    GridPane.setRowSpan(icon, 2);

    label = new AutoTooltipLabel();
    label.textProperty().bind(text);
    label.setTextOverrun(OverrunStyle.WORD_ELLIPSIS);
    // width is set a frame later so we hide it first
    label.setVisible(false);

    link = new Hyperlink(Res.get("shared.readMore"));
    link.setPadding(new Insets(0, 0, 0, -2));

    // We need that to know if we have a wrapping or not.
    // Did not find a way to get that from the API.
    Label testLabel = new AutoTooltipLabel();
    testLabel.textProperty().bind(text);

    textFlow = new TextFlow();
    textFlow.visibleProperty().bind(visibleProperty());
    textFlow.getChildren().addAll(testLabel);

    testLabel.widthProperty().addListener((ov, o, n) -> {
        useReadMore = (double) n > textFlow.getWidth();
        link.setText(Res.get(useReadMore ? "shared.readMore" : "shared.openHelp"));
        UserThread.execute(() -> textFlow.getChildren().setAll(label, link));
    });

    // update the width when the window gets resized
    ChangeListener<Number> listener = (ov2, oldValue2, windowWidth) -> {
        if (label.prefWidthProperty().isBound())
            label.prefWidthProperty().unbind();
        label.setPrefWidth((double) windowWidth - localToScene(0, 0).getX() - 35);
    };


    // when clicking "Read more..." we expand and change the link to the Help
    link.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent actionEvent) {
            if (useReadMore) {

                label.setWrapText(true);
                link.setText(Res.get("shared.openHelp"));
                getScene().getWindow().widthProperty().removeListener(listener);
                if (label.prefWidthProperty().isBound())
                    label.prefWidthProperty().unbind();
                label.prefWidthProperty().bind(textFlow.widthProperty());
                link.setVisited(false);
                // focus border is a bit confusing here so we remove it
                link.getStyleClass().add("hide-focus");
                link.setOnAction(onAction.get());
                getParent().layout();
            } else {
                onAction.get().handle(actionEvent);
            }
        }
    });

    sceneProperty().addListener((ov, oldValue, newValue) -> {
        if (oldValue == null && newValue != null && newValue.getWindow() != null) {
            newValue.getWindow().widthProperty().addListener(listener);
            // localToScene does deliver 0 instead of the correct x position when scene property gets set,
            // so we delay for 1 render cycle
            UserThread.execute(() -> {
                label.setVisible(true);
                label.prefWidthProperty().unbind();
                label.setPrefWidth(newValue.getWindow().getWidth() - localToScene(0, 0).getX() - 35);
            });
        }
    });
}
 
Example 20
Source File: SendPrivateNotificationWindow.java    From bisq with GNU Affero General Public License v3.0 4 votes vote down vote up
private void addContent() {
    InputTextField keyInputTextField = addInputTextField(gridPane, ++rowIndex, Res.get("shared.unlock"), 10);
    if (useDevPrivilegeKeys)
        keyInputTextField.setText(DevEnv.DEV_PRIVILEGE_PRIV_KEY);

    Tuple2<Label, TextArea> labelTextAreaTuple2 = addTopLabelTextArea(gridPane, ++rowIndex,
            Res.get("sendPrivateNotificationWindow.privateNotification"),
            Res.get("sendPrivateNotificationWindow.enterNotification"));
    TextArea alertMessageTextArea = labelTextAreaTuple2.second;
    Label first = labelTextAreaTuple2.first;
    first.setMinWidth(200);

    Button sendButton = new AutoTooltipButton(Res.get("sendPrivateNotificationWindow.send"));
    sendButton.setOnAction(e -> {
        if (alertMessageTextArea.getText().length() > 0 && keyInputTextField.getText().length() > 0) {
            PrivateNotificationPayload privateNotification = new PrivateNotificationPayload(alertMessageTextArea.getText());
            if (!privateNotificationManager.sendPrivateNotificationMessageIfKeyIsValid(
                    privateNotification,
                    pubKeyRing,
                    nodeAddress,
                    keyInputTextField.getText(),
                    new SendMailboxMessageListener() {
                        @Override
                        public void onArrived() {
                            log.info("PrivateNotificationPayload arrived at peer {}.", nodeAddress);
                            new Popup().feedback(Res.get("shared.messageArrived"))
                                    .onClose(SendPrivateNotificationWindow.this::hide).show();
                        }

                        @Override
                        public void onStoredInMailbox() {
                            log.info("PrivateNotificationPayload stored in mailbox for peer {}.", nodeAddress);
                            new Popup().feedback(Res.get("shared.messageStoredInMailbox"))
                                    .onClose(SendPrivateNotificationWindow.this::hide).show();
                        }

                        @Override
                        public void onFault(String errorMessage) {
                            log.error("PrivateNotificationPayload failed: Peer {}, errorMessage={}", nodeAddress,
                                    errorMessage);
                            new Popup().feedback(Res.get("shared.messageSendingFailed", errorMessage))
                                    .onClose(SendPrivateNotificationWindow.this::hide).show();
                        }
                    }))
                new Popup().warning(Res.get("shared.invalidKey")).width(300).onClose(this::blurAgain).show();
        }
    });

    closeButton = new AutoTooltipButton(Res.get("shared.close"));
    closeButton.setOnAction(e -> {
        hide();
        closeHandlerOptional.ifPresent(Runnable::run);
    });

    HBox hBox = new HBox();
    hBox.setSpacing(10);
    hBox.setAlignment(Pos.CENTER_RIGHT);
    GridPane.setRowIndex(hBox, ++rowIndex);
    GridPane.setColumnSpan(hBox, 2);
    GridPane.setColumnIndex(hBox, 0);
    hBox.getChildren().addAll(sendButton, closeButton);
    gridPane.getChildren().add(hBox);
    GridPane.setMargin(hBox, new Insets(10, 0, 0, 0));
}