Search in sources :

Example 26 with Callback

use of javafx.util.Callback in project bitsquare by bitsquare.

the class ArbitratorSelectionView method addArbitratorsGroup.

private void addArbitratorsGroup() {
    TableGroupHeadline tableGroupHeadline = new TableGroupHeadline("Which arbitrators do you accept");
    GridPane.setRowIndex(tableGroupHeadline, ++gridRow);
    GridPane.setColumnSpan(tableGroupHeadline, 2);
    GridPane.setMargin(tableGroupHeadline, new Insets(40, -10, -10, -10));
    root.getChildren().add(tableGroupHeadline);
    tableView = new TableView<>();
    GridPane.setRowIndex(tableView, gridRow);
    GridPane.setColumnSpan(tableView, 2);
    GridPane.setMargin(tableView, new Insets(60, -10, 5, -10));
    root.getChildren().add(tableView);
    autoSelectAllMatchingCheckBox = addCheckBox(root, ++gridRow, "Auto select all arbitrators with matching language");
    GridPane.setColumnSpan(autoSelectAllMatchingCheckBox, 2);
    GridPane.setHalignment(autoSelectAllMatchingCheckBox, HPos.LEFT);
    GridPane.setColumnIndex(autoSelectAllMatchingCheckBox, 0);
    GridPane.setMargin(autoSelectAllMatchingCheckBox, new Insets(0, -10, 0, -10));
    autoSelectAllMatchingCheckBox.setOnAction(event -> model.setAutoSelectArbitrators(autoSelectAllMatchingCheckBox.isSelected()));
    TableColumn<ArbitratorListItem, String> dateColumn = new TableColumn("Registration date");
    dateColumn.setSortable(false);
    dateColumn.setCellValueFactory(param -> new ReadOnlyObjectWrapper(param.getValue().getRegistrationDate()));
    dateColumn.setMinWidth(140);
    dateColumn.setMaxWidth(140);
    TableColumn<ArbitratorListItem, String> nameColumn = new TableColumn("Onion address");
    nameColumn.setSortable(false);
    nameColumn.setCellValueFactory(param -> new ReadOnlyObjectWrapper(param.getValue().getAddressString()));
    nameColumn.setMinWidth(90);
    TableColumn<ArbitratorListItem, String> languagesColumn = new TableColumn("Languages");
    languagesColumn.setSortable(false);
    languagesColumn.setCellValueFactory(param -> new ReadOnlyObjectWrapper(param.getValue().getLanguageCodes()));
    languagesColumn.setMinWidth(130);
    TableColumn<ArbitratorListItem, ArbitratorListItem> selectionColumn = new TableColumn<ArbitratorListItem, ArbitratorListItem>("Accept") {

        {
            setMinWidth(60);
            setMaxWidth(60);
            setSortable(false);
        }
    };
    selectionColumn.setCellValueFactory((arbitrator) -> new ReadOnlyObjectWrapper<>(arbitrator.getValue()));
    selectionColumn.setCellFactory(new Callback<TableColumn<ArbitratorListItem, ArbitratorListItem>, TableCell<ArbitratorListItem, ArbitratorListItem>>() {

        @Override
        public TableCell<ArbitratorListItem, ArbitratorListItem> call(TableColumn<ArbitratorListItem, ArbitratorListItem> column) {
            return new TableCell<ArbitratorListItem, ArbitratorListItem>() {

                private final CheckBox checkBox = new CheckBox();

                private TableRow tableRow;

                private BooleanProperty selectedProperty;

                private void updateDisableState(final ArbitratorListItem item) {
                    boolean selected = model.isAcceptedArbitrator(item.arbitrator);
                    item.setIsSelected(selected);
                    boolean hasMatchingLanguage = model.hasMatchingLanguage(item.arbitrator);
                    if (!hasMatchingLanguage) {
                        model.onRemoveArbitrator(item.arbitrator);
                        if (selected)
                            item.setIsSelected(false);
                    }
                    boolean isMyOwnRegisteredArbitrator = model.isMyOwnRegisteredArbitrator(item.arbitrator);
                    checkBox.setDisable(!hasMatchingLanguage || isMyOwnRegisteredArbitrator);
                    tableRow = getTableRow();
                    if (tableRow != null) {
                        tableRow.setOpacity(hasMatchingLanguage && !isMyOwnRegisteredArbitrator ? 1 : 0.4);
                        if (isMyOwnRegisteredArbitrator) {
                            tableRow.setTooltip(new Tooltip("An arbitrator cannot select himself for trading."));
                            tableRow.setOnMouseClicked(e -> new Popup().warning("An arbitrator cannot select himself for trading.").show());
                        } else if (!hasMatchingLanguage) {
                            tableRow.setTooltip(new Tooltip("No matching language."));
                            tableRow.setOnMouseClicked(e -> new Popup().warning("You can only select arbitrators who are speaking at least 1 common language.").show());
                        } else {
                            tableRow.setOnMouseClicked(null);
                            tableRow.setTooltip(null);
                        }
                    }
                }

                @Override
                public void updateItem(final ArbitratorListItem item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null && !empty) {
                        selectedProperty = item.isSelectedProperty();
                        languageCodesListChangeListener = c -> updateDisableState(item);
                        model.languageCodes.addListener(languageCodesListChangeListener);
                        isSelectedChangeListener = (observable, oldValue, newValue) -> checkBox.setSelected(newValue);
                        selectedProperty.addListener(isSelectedChangeListener);
                        checkBox.setSelected(model.isAcceptedArbitrator(item.arbitrator));
                        checkBox.setOnAction(e -> {
                            if (checkBox.isSelected()) {
                                onAddArbitrator(item);
                            } else if (model.isDeselectAllowed(item)) {
                                onRemoveArbitrator(item);
                            } else {
                                new Popup().warning("You need to have at least one arbitrator selected.").show();
                                checkBox.setSelected(true);
                            }
                            item.setIsSelected(checkBox.isSelected());
                        });
                        updateDisableState(item);
                        setGraphic(checkBox);
                    } else {
                        model.languageCodes.removeListener(languageCodesListChangeListener);
                        if (selectedProperty != null)
                            selectedProperty.removeListener(isSelectedChangeListener);
                        setGraphic(null);
                        if (checkBox != null)
                            checkBox.setOnAction(null);
                        if (tableRow != null)
                            tableRow.setOnMouseClicked(null);
                    }
                }
            };
        }
    });
    tableView.getColumns().addAll(dateColumn, nameColumn, languagesColumn, selectionColumn);
    tableView.setColumnResizePolicy(TableView.CONSTRAINED_RESIZE_POLICY);
}
Also used : HPos(javafx.geometry.HPos) Popup(io.bitsquare.gui.main.overlays.popups.Popup) javafx.scene.control(javafx.scene.control) TableGroupHeadline(io.bitsquare.gui.components.TableGroupHeadline) UserThread(io.bitsquare.common.UserThread) ImageUtil(io.bitsquare.gui.util.ImageUtil) Tuple2(io.bitsquare.common.util.Tuple2) StringConverter(javafx.util.StringConverter) ActivatableViewAndModel(io.bitsquare.gui.common.view.ActivatableViewAndModel) LanguageUtil(io.bitsquare.locale.LanguageUtil) Inject(javax.inject.Inject) BooleanProperty(javafx.beans.property.BooleanProperty) FormBuilder(io.bitsquare.gui.util.FormBuilder) Insets(javafx.geometry.Insets) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) ListChangeListener(javafx.collections.ListChangeListener) Layout(io.bitsquare.gui.util.Layout) VPos(javafx.geometry.VPos) AnchorPane(javafx.scene.layout.AnchorPane) ImageView(javafx.scene.image.ImageView) FxmlView(io.bitsquare.gui.common.view.FxmlView) ChangeListener(javafx.beans.value.ChangeListener) Callback(javafx.util.Callback) GridPane(javafx.scene.layout.GridPane) TableGroupHeadline(io.bitsquare.gui.components.TableGroupHeadline) Insets(javafx.geometry.Insets) BooleanProperty(javafx.beans.property.BooleanProperty) Popup(io.bitsquare.gui.main.overlays.popups.Popup) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper)

Example 27 with Callback

use of javafx.util.Callback in project bitsquare by bitsquare.

the class TraderDisputeView method onSelectDispute.

private void onSelectDispute(Dispute dispute) {
    removeListenersOnSelectDispute();
    if (dispute == null) {
        if (root.getChildren().size() > 2)
            root.getChildren().remove(2);
        selectedDispute = null;
    } else if (selectedDispute != dispute) {
        this.selectedDispute = dispute;
        boolean isTrader = disputeManager.isTrader(selectedDispute);
        tableGroupHeadline = new TableGroupHeadline();
        tableGroupHeadline.setText("Messages");
        AnchorPane.setTopAnchor(tableGroupHeadline, 10d);
        AnchorPane.setRightAnchor(tableGroupHeadline, 0d);
        AnchorPane.setBottomAnchor(tableGroupHeadline, 0d);
        AnchorPane.setLeftAnchor(tableGroupHeadline, 0d);
        disputeCommunicationMessages = selectedDispute.getDisputeCommunicationMessagesAsObservableList();
        SortedList<DisputeCommunicationMessage> sortedList = new SortedList<>(disputeCommunicationMessages);
        sortedList.setComparator((o1, o2) -> o1.getDate().compareTo(o2.getDate()));
        messageListView = new ListView<>(sortedList);
        messageListView.setId("message-list-view");
        messageListView.setMinHeight(150);
        AnchorPane.setTopAnchor(messageListView, 30d);
        AnchorPane.setRightAnchor(messageListView, 0d);
        AnchorPane.setLeftAnchor(messageListView, 0d);
        messagesAnchorPane = new AnchorPane();
        VBox.setVgrow(messagesAnchorPane, Priority.ALWAYS);
        inputTextArea = new TextArea();
        inputTextArea.setPrefHeight(70);
        inputTextArea.setWrapText(true);
        sendButton = new Button("Send");
        sendButton.setDefaultButton(true);
        sendButton.setOnAction(e -> {
            if (p2PService.isBootstrapped()) {
                String text = inputTextArea.getText();
                if (!text.isEmpty())
                    onSendMessage(text, selectedDispute);
            } else {
                new Popup().information("You need to wait until you are fully connected to the network.\n" + "That might take up to about 2 minutes at startup.").show();
            }
        });
        inputTextAreaTextSubscription = EasyBind.subscribe(inputTextArea.textProperty(), t -> sendButton.setDisable(t.isEmpty()));
        Button uploadButton = new Button("Add attachments");
        uploadButton.setOnAction(e -> onRequestUpload());
        sendMsgInfoLabel = new Label();
        sendMsgInfoLabel.setVisible(false);
        sendMsgInfoLabel.setManaged(false);
        sendMsgInfoLabel.setPadding(new Insets(5, 0, 0, 0));
        sendMsgBusyAnimation = new BusyAnimation(false);
        if (!selectedDispute.isClosed()) {
            HBox buttonBox = new HBox();
            buttonBox.setSpacing(10);
            buttonBox.getChildren().addAll(sendButton, uploadButton, sendMsgBusyAnimation, sendMsgInfoLabel);
            if (!isTrader) {
                Button closeDisputeButton = new Button("Close ticket");
                closeDisputeButton.setOnAction(e -> onCloseDispute(selectedDispute));
                closeDisputeButton.setDefaultButton(true);
                Pane spacer = new Pane();
                HBox.setHgrow(spacer, Priority.ALWAYS);
                buttonBox.getChildren().addAll(spacer, closeDisputeButton);
            }
            messagesInputBox = new VBox();
            messagesInputBox.setSpacing(10);
            messagesInputBox.getChildren().addAll(inputTextArea, buttonBox);
            VBox.setVgrow(buttonBox, Priority.ALWAYS);
            AnchorPane.setRightAnchor(messagesInputBox, 0d);
            AnchorPane.setBottomAnchor(messagesInputBox, 5d);
            AnchorPane.setLeftAnchor(messagesInputBox, 0d);
            AnchorPane.setBottomAnchor(messageListView, 120d);
            messagesAnchorPane.getChildren().addAll(tableGroupHeadline, messageListView, messagesInputBox);
        } else {
            AnchorPane.setBottomAnchor(messageListView, 0d);
            messagesAnchorPane.getChildren().addAll(tableGroupHeadline, messageListView);
        }
        messageListView.setCellFactory(new Callback<ListView<DisputeCommunicationMessage>, ListCell<DisputeCommunicationMessage>>() {

            @Override
            public ListCell<DisputeCommunicationMessage> call(ListView<DisputeCommunicationMessage> list) {
                return new ListCell<DisputeCommunicationMessage>() {

                    public ChangeListener<Boolean> sendMsgBusyAnimationListener;

                    final Pane bg = new Pane();

                    final ImageView arrow = new ImageView();

                    final Label headerLabel = new Label();

                    final Label messageLabel = new Label();

                    final Label copyIcon = new Label();

                    final HBox attachmentsBox = new HBox();

                    final AnchorPane messageAnchorPane = new AnchorPane();

                    final Label statusIcon = new Label();

                    final double arrowWidth = 15d;

                    final double attachmentsBoxHeight = 20d;

                    final double border = 10d;

                    final double bottomBorder = 25d;

                    final double padding = border + 10d;

                    final double msgLabelPaddingRight = padding + 20d;

                    {
                        bg.setMinHeight(30);
                        messageLabel.setWrapText(true);
                        headerLabel.setTextAlignment(TextAlignment.CENTER);
                        attachmentsBox.setSpacing(5);
                        statusIcon.setStyle("-fx-font-size: 10;");
                        Tooltip.install(copyIcon, new Tooltip("Copy to clipboard"));
                        messageAnchorPane.getChildren().addAll(bg, arrow, headerLabel, messageLabel, copyIcon, attachmentsBox, statusIcon);
                    }

                    @Override
                    public void updateItem(final DisputeCommunicationMessage item, boolean empty) {
                        super.updateItem(item, empty);
                        if (item != null && !empty) {
                            copyIcon.setOnMouseClicked(e -> Utilities.copyToClipboard(messageLabel.getText()));
                            /* messageAnchorPane.prefWidthProperty().bind(EasyBind.map(messageListView.widthProperty(),
                                        w -> (double) w - padding - GUIUtil.getScrollbarWidth(messageListView)));*/
                            if (!messageAnchorPane.prefWidthProperty().isBound())
                                messageAnchorPane.prefWidthProperty().bind(messageListView.widthProperty().subtract(padding + GUIUtil.getScrollbarWidth(messageListView)));
                            AnchorPane.setTopAnchor(bg, 15d);
                            AnchorPane.setBottomAnchor(bg, bottomBorder);
                            AnchorPane.setTopAnchor(headerLabel, 0d);
                            AnchorPane.setBottomAnchor(arrow, bottomBorder + 5d);
                            AnchorPane.setTopAnchor(messageLabel, 25d);
                            AnchorPane.setTopAnchor(copyIcon, 25d);
                            AnchorPane.setBottomAnchor(attachmentsBox, bottomBorder + 10);
                            boolean senderIsTrader = item.isSenderIsTrader();
                            boolean isMyMsg = isTrader ? senderIsTrader : !senderIsTrader;
                            arrow.setVisible(!item.isSystemMessage());
                            arrow.setManaged(!item.isSystemMessage());
                            statusIcon.setVisible(false);
                            if (item.isSystemMessage()) {
                                headerLabel.setStyle("-fx-text-fill: -bs-green; -fx-font-size: 11;");
                                bg.setId("message-bubble-green");
                                messageLabel.setStyle("-fx-text-fill: white;");
                                copyIcon.setStyle("-fx-text-fill: white;");
                            } else if (isMyMsg) {
                                headerLabel.setStyle("-fx-text-fill: -fx-accent; -fx-font-size: 11;");
                                bg.setId("message-bubble-blue");
                                messageLabel.setStyle("-fx-text-fill: white;");
                                copyIcon.setStyle("-fx-text-fill: white;");
                                if (isTrader)
                                    arrow.setId("bubble_arrow_blue_left");
                                else
                                    arrow.setId("bubble_arrow_blue_right");
                                if (sendMsgBusyAnimationListener != null)
                                    sendMsgBusyAnimation.isRunningProperty().removeListener(sendMsgBusyAnimationListener);
                                sendMsgBusyAnimationListener = (observable, oldValue, newValue) -> {
                                    if (!newValue) {
                                        if (item.arrivedProperty().get())
                                            showArrivedIcon();
                                        else if (item.storedInMailboxProperty().get())
                                            showMailboxIcon();
                                    }
                                };
                                sendMsgBusyAnimation.isRunningProperty().addListener(sendMsgBusyAnimationListener);
                                if (item.arrivedProperty().get())
                                    showArrivedIcon();
                                else if (item.storedInMailboxProperty().get())
                                    showMailboxIcon();
                            //TODO show that icon on error
                            /*else if (sendMsgProgressIndicator.getProgress() == 0)
                                        showNotArrivedIcon();*/
                            } else {
                                headerLabel.setStyle("-fx-text-fill: -bs-light-grey; -fx-font-size: 11;");
                                bg.setId("message-bubble-grey");
                                messageLabel.setStyle("-fx-text-fill: black;");
                                copyIcon.setStyle("-fx-text-fill: black;");
                                if (isTrader)
                                    arrow.setId("bubble_arrow_grey_right");
                                else
                                    arrow.setId("bubble_arrow_grey_left");
                            }
                            if (item.isSystemMessage()) {
                                AnchorPane.setLeftAnchor(headerLabel, padding);
                                AnchorPane.setRightAnchor(headerLabel, padding);
                                AnchorPane.setLeftAnchor(bg, border);
                                AnchorPane.setRightAnchor(bg, border);
                                AnchorPane.setLeftAnchor(messageLabel, padding);
                                AnchorPane.setRightAnchor(messageLabel, msgLabelPaddingRight);
                                AnchorPane.setRightAnchor(copyIcon, padding);
                                AnchorPane.setLeftAnchor(attachmentsBox, padding);
                                AnchorPane.setRightAnchor(attachmentsBox, padding);
                            } else if (senderIsTrader) {
                                AnchorPane.setLeftAnchor(headerLabel, padding + arrowWidth);
                                AnchorPane.setLeftAnchor(bg, border + arrowWidth);
                                AnchorPane.setRightAnchor(bg, border);
                                AnchorPane.setLeftAnchor(arrow, border);
                                AnchorPane.setLeftAnchor(messageLabel, padding + arrowWidth);
                                AnchorPane.setRightAnchor(messageLabel, msgLabelPaddingRight);
                                AnchorPane.setRightAnchor(copyIcon, padding);
                                AnchorPane.setLeftAnchor(attachmentsBox, padding + arrowWidth);
                                AnchorPane.setRightAnchor(attachmentsBox, padding);
                                AnchorPane.setRightAnchor(statusIcon, padding);
                            } else {
                                AnchorPane.setRightAnchor(headerLabel, padding + arrowWidth);
                                AnchorPane.setLeftAnchor(bg, border);
                                AnchorPane.setRightAnchor(bg, border + arrowWidth);
                                AnchorPane.setRightAnchor(arrow, border);
                                AnchorPane.setLeftAnchor(messageLabel, padding);
                                AnchorPane.setRightAnchor(messageLabel, msgLabelPaddingRight + arrowWidth);
                                AnchorPane.setRightAnchor(copyIcon, padding + arrowWidth);
                                AnchorPane.setLeftAnchor(attachmentsBox, padding);
                                AnchorPane.setRightAnchor(attachmentsBox, padding + arrowWidth);
                                AnchorPane.setLeftAnchor(statusIcon, padding);
                            }
                            AnchorPane.setBottomAnchor(statusIcon, 7d);
                            headerLabel.setText(formatter.formatDateTime(item.getDate()));
                            messageLabel.setText(item.getMessage());
                            attachmentsBox.getChildren().clear();
                            if (item.getAttachments().size() > 0) {
                                AnchorPane.setBottomAnchor(messageLabel, bottomBorder + attachmentsBoxHeight + 10);
                                attachmentsBox.getChildren().add(new Label("Attachments: ") {

                                    {
                                        setPadding(new Insets(0, 0, 3, 0));
                                        if (isMyMsg)
                                            setStyle("-fx-text-fill: white;");
                                        else
                                            setStyle("-fx-text-fill: black;");
                                    }
                                });
                                item.getAttachments().stream().forEach(attachment -> {
                                    final Label icon = new Label();
                                    setPadding(new Insets(0, 0, 3, 0));
                                    if (isMyMsg)
                                        icon.getStyleClass().add("attachment-icon");
                                    else
                                        icon.getStyleClass().add("attachment-icon-black");
                                    AwesomeDude.setIcon(icon, AwesomeIcon.FILE_TEXT);
                                    icon.setPadding(new Insets(-2, 0, 0, 0));
                                    icon.setTooltip(new Tooltip(attachment.getFileName()));
                                    icon.setOnMouseClicked(event -> onOpenAttachment(attachment));
                                    attachmentsBox.getChildren().add(icon);
                                });
                            } else {
                                AnchorPane.setBottomAnchor(messageLabel, bottomBorder + 10);
                            }
                            // Need to set it here otherwise style is not correct
                            AwesomeDude.setIcon(copyIcon, AwesomeIcon.COPY, "16.0");
                            copyIcon.getStyleClass().add("copy-icon-disputes");
                            // TODO There are still some cell rendering issues on updates
                            setGraphic(messageAnchorPane);
                        } else {
                            if (sendMsgBusyAnimation != null && sendMsgBusyAnimationListener != null)
                                sendMsgBusyAnimation.isRunningProperty().removeListener(sendMsgBusyAnimationListener);
                            messageAnchorPane.prefWidthProperty().unbind();
                            AnchorPane.clearConstraints(bg);
                            AnchorPane.clearConstraints(headerLabel);
                            AnchorPane.clearConstraints(arrow);
                            AnchorPane.clearConstraints(messageLabel);
                            AnchorPane.clearConstraints(copyIcon);
                            AnchorPane.clearConstraints(statusIcon);
                            AnchorPane.clearConstraints(attachmentsBox);
                            copyIcon.setOnMouseClicked(null);
                            setGraphic(null);
                        }
                    }

                    /*  private void showNotArrivedIcon() {
                            statusIcon.setVisible(true);
                            AwesomeDude.setIcon(statusIcon, AwesomeIcon.WARNING_SIGN, "14");
                            Tooltip.install(statusIcon, new Tooltip("Message did not arrive. Please try to send again."));
                            statusIcon.setTextFill(Paint.valueOf("#dd0000"));
                        }*/
                    private void showMailboxIcon() {
                        statusIcon.setVisible(true);
                        AwesomeDude.setIcon(statusIcon, AwesomeIcon.ENVELOPE_ALT, "14");
                        Tooltip.install(statusIcon, new Tooltip("Message saved in receiver's mailbox"));
                        statusIcon.setTextFill(Paint.valueOf("#0f87c3"));
                    }

                    private void showArrivedIcon() {
                        statusIcon.setVisible(true);
                        AwesomeDude.setIcon(statusIcon, AwesomeIcon.OK, "14");
                        Tooltip.install(statusIcon, new Tooltip("Message arrived at receiver"));
                        statusIcon.setTextFill(Paint.valueOf("#0f87c3"));
                    }
                };
            }
        });
        if (root.getChildren().size() > 2)
            root.getChildren().remove(2);
        root.getChildren().add(2, messagesAnchorPane);
        scrollToBottom();
    }
    addListenersOnSelectDispute();
}
Also used : EventHandler(javafx.event.EventHandler) PubKeyRing(io.bitsquare.common.crypto.PubKeyRing) Popup(io.bitsquare.gui.main.overlays.popups.Popup) javafx.scene.layout(javafx.scene.layout) javafx.scene.control(javafx.scene.control) URL(java.net.URL) ReadOnlyBooleanProperty(javafx.beans.property.ReadOnlyBooleanProperty) DisputeManager(io.bitsquare.arbitration.DisputeManager) Trade(io.bitsquare.trade.Trade) ActivatableView(io.bitsquare.gui.common.view.ActivatableView) DisputeCommunicationMessage(io.bitsquare.arbitration.messages.DisputeCommunicationMessage) GUIUtil(io.bitsquare.gui.util.GUIUtil) KeyCombination(javafx.scene.input.KeyCombination) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) ListChangeListener(javafx.collections.ListChangeListener) KeyRing(io.bitsquare.common.crypto.KeyRing) DisputeSummaryWindow(io.bitsquare.gui.main.overlays.windows.DisputeSummaryWindow) ParseException(java.text.ParseException) DateFormat(java.text.DateFormat) SortedList(javafx.collections.transformation.SortedList) TableGroupHeadline(io.bitsquare.gui.components.TableGroupHeadline) Contract(io.bitsquare.trade.Contract) FilteredList(javafx.collections.transformation.FilteredList) KeyEvent(javafx.scene.input.KeyEvent) Subscription(org.fxmisc.easybind.Subscription) PrivateNotificationManager(io.bitsquare.alert.PrivateNotificationManager) Attachment(io.bitsquare.arbitration.payload.Attachment) Paint(javafx.scene.paint.Paint) ByteStreams(com.google.common.io.ByteStreams) Dispute(io.bitsquare.arbitration.Dispute) ObservableList(javafx.collections.ObservableList) AwesomeIcon(de.jensd.fx.fontawesome.AwesomeIcon) Version(io.bitsquare.app.Version) Scene(javafx.scene.Scene) java.util(java.util) P2PService(io.bitsquare.p2p.P2PService) SimpleDateFormat(java.text.SimpleDateFormat) Connection(io.bitsquare.p2p.network.Connection) Timer(io.bitsquare.common.Timer) Inject(javax.inject.Inject) TradeManager(io.bitsquare.trade.TradeManager) Lists(com.google.common.collect.Lists) Insets(javafx.geometry.Insets) TradeDetailsWindow(io.bitsquare.gui.main.overlays.windows.TradeDetailsWindow) TextAlignment(javafx.scene.text.TextAlignment) Callback(javafx.util.Callback) Nullable(javax.annotation.Nullable) BSFormatter(io.bitsquare.gui.util.BSFormatter) KeyCode(javafx.scene.input.KeyCode) InputTextField(io.bitsquare.gui.components.InputTextField) Utilities(io.bitsquare.common.util.Utilities) ContractWindow(io.bitsquare.gui.main.overlays.windows.ContractWindow) MalformedURLException(java.net.MalformedURLException) UserThread(io.bitsquare.common.UserThread) AwesomeDude(de.jensd.fx.fontawesome.AwesomeDude) NodeAddress(io.bitsquare.p2p.NodeAddress) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) KeyCodeCombination(javafx.scene.input.KeyCodeCombination) TimeUnit(java.util.concurrent.TimeUnit) FileChooser(javafx.stage.FileChooser) HyperlinkWithIcon(io.bitsquare.gui.components.HyperlinkWithIcon) Stage(javafx.stage.Stage) EasyBind(org.fxmisc.easybind.EasyBind) ImageView(javafx.scene.image.ImageView) BusyAnimation(io.bitsquare.gui.components.BusyAnimation) SendPrivateNotificationWindow(io.bitsquare.gui.main.overlays.windows.SendPrivateNotificationWindow) FxmlView(io.bitsquare.gui.common.view.FxmlView) ChangeListener(javafx.beans.value.ChangeListener) InputStream(java.io.InputStream) TableGroupHeadline(io.bitsquare.gui.components.TableGroupHeadline) Insets(javafx.geometry.Insets) BusyAnimation(io.bitsquare.gui.components.BusyAnimation) SortedList(javafx.collections.transformation.SortedList) Callback(javafx.util.Callback) Popup(io.bitsquare.gui.main.overlays.popups.Popup) ListChangeListener(javafx.collections.ListChangeListener) ChangeListener(javafx.beans.value.ChangeListener) ImageView(javafx.scene.image.ImageView) DisputeCommunicationMessage(io.bitsquare.arbitration.messages.DisputeCommunicationMessage)

Example 28 with Callback

use of javafx.util.Callback in project bitsquare by bitsquare.

the class TraderDisputeView method getStateColumn.

private TableColumn<Dispute, Dispute> getStateColumn() {
    TableColumn<Dispute, Dispute> column = new TableColumn<Dispute, Dispute>("State") {

        {
            setMinWidth(50);
        }
    };
    column.setCellValueFactory((dispute) -> new ReadOnlyObjectWrapper<>(dispute.getValue()));
    column.setCellFactory(new Callback<TableColumn<Dispute, Dispute>, TableCell<Dispute, Dispute>>() {

        @Override
        public TableCell<Dispute, Dispute> call(TableColumn<Dispute, Dispute> column) {
            return new TableCell<Dispute, Dispute>() {

                public ReadOnlyBooleanProperty closedProperty;

                public ChangeListener<Boolean> listener;

                @Override
                public void updateItem(final Dispute item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null && !empty) {
                        listener = (observable, oldValue, newValue) -> {
                            setText(newValue ? "Closed" : "Open");
                            getTableRow().setOpacity(newValue ? 0.4 : 1);
                        };
                        closedProperty = item.isClosedProperty();
                        closedProperty.addListener(listener);
                        boolean isClosed = item.isClosed();
                        setText(isClosed ? "Closed" : "Open");
                        getTableRow().setOpacity(isClosed ? 0.4 : 1);
                    } else {
                        if (closedProperty != null) {
                            closedProperty.removeListener(listener);
                            closedProperty = null;
                        }
                        setText("");
                    }
                }
            };
        }
    });
    return column;
}
Also used : EventHandler(javafx.event.EventHandler) PubKeyRing(io.bitsquare.common.crypto.PubKeyRing) Popup(io.bitsquare.gui.main.overlays.popups.Popup) javafx.scene.layout(javafx.scene.layout) javafx.scene.control(javafx.scene.control) URL(java.net.URL) ReadOnlyBooleanProperty(javafx.beans.property.ReadOnlyBooleanProperty) DisputeManager(io.bitsquare.arbitration.DisputeManager) Trade(io.bitsquare.trade.Trade) ActivatableView(io.bitsquare.gui.common.view.ActivatableView) DisputeCommunicationMessage(io.bitsquare.arbitration.messages.DisputeCommunicationMessage) GUIUtil(io.bitsquare.gui.util.GUIUtil) KeyCombination(javafx.scene.input.KeyCombination) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) ListChangeListener(javafx.collections.ListChangeListener) KeyRing(io.bitsquare.common.crypto.KeyRing) DisputeSummaryWindow(io.bitsquare.gui.main.overlays.windows.DisputeSummaryWindow) ParseException(java.text.ParseException) DateFormat(java.text.DateFormat) SortedList(javafx.collections.transformation.SortedList) TableGroupHeadline(io.bitsquare.gui.components.TableGroupHeadline) Contract(io.bitsquare.trade.Contract) FilteredList(javafx.collections.transformation.FilteredList) KeyEvent(javafx.scene.input.KeyEvent) Subscription(org.fxmisc.easybind.Subscription) PrivateNotificationManager(io.bitsquare.alert.PrivateNotificationManager) Attachment(io.bitsquare.arbitration.payload.Attachment) Paint(javafx.scene.paint.Paint) ByteStreams(com.google.common.io.ByteStreams) Dispute(io.bitsquare.arbitration.Dispute) ObservableList(javafx.collections.ObservableList) AwesomeIcon(de.jensd.fx.fontawesome.AwesomeIcon) Version(io.bitsquare.app.Version) Scene(javafx.scene.Scene) java.util(java.util) P2PService(io.bitsquare.p2p.P2PService) SimpleDateFormat(java.text.SimpleDateFormat) Connection(io.bitsquare.p2p.network.Connection) Timer(io.bitsquare.common.Timer) Inject(javax.inject.Inject) TradeManager(io.bitsquare.trade.TradeManager) Lists(com.google.common.collect.Lists) Insets(javafx.geometry.Insets) TradeDetailsWindow(io.bitsquare.gui.main.overlays.windows.TradeDetailsWindow) TextAlignment(javafx.scene.text.TextAlignment) Callback(javafx.util.Callback) Nullable(javax.annotation.Nullable) BSFormatter(io.bitsquare.gui.util.BSFormatter) KeyCode(javafx.scene.input.KeyCode) InputTextField(io.bitsquare.gui.components.InputTextField) Utilities(io.bitsquare.common.util.Utilities) ContractWindow(io.bitsquare.gui.main.overlays.windows.ContractWindow) MalformedURLException(java.net.MalformedURLException) UserThread(io.bitsquare.common.UserThread) AwesomeDude(de.jensd.fx.fontawesome.AwesomeDude) NodeAddress(io.bitsquare.p2p.NodeAddress) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) KeyCodeCombination(javafx.scene.input.KeyCodeCombination) TimeUnit(java.util.concurrent.TimeUnit) FileChooser(javafx.stage.FileChooser) HyperlinkWithIcon(io.bitsquare.gui.components.HyperlinkWithIcon) Stage(javafx.stage.Stage) EasyBind(org.fxmisc.easybind.EasyBind) ImageView(javafx.scene.image.ImageView) BusyAnimation(io.bitsquare.gui.components.BusyAnimation) SendPrivateNotificationWindow(io.bitsquare.gui.main.overlays.windows.SendPrivateNotificationWindow) FxmlView(io.bitsquare.gui.common.view.FxmlView) ChangeListener(javafx.beans.value.ChangeListener) InputStream(java.io.InputStream) ReadOnlyBooleanProperty(javafx.beans.property.ReadOnlyBooleanProperty) Dispute(io.bitsquare.arbitration.Dispute)

Example 29 with Callback

use of javafx.util.Callback in project bitsquare by bitsquare.

the class DepositView method setAddressColumnCellFactory.

private void setAddressColumnCellFactory() {
    addressColumn.setCellValueFactory((addressListItem) -> new ReadOnlyObjectWrapper<>(addressListItem.getValue()));
    addressColumn.setCellFactory(new Callback<TableColumn<DepositListItem, DepositListItem>, TableCell<DepositListItem, DepositListItem>>() {

        @Override
        public TableCell<DepositListItem, DepositListItem> call(TableColumn<DepositListItem, DepositListItem> column) {
            return new TableCell<DepositListItem, DepositListItem>() {

                private HyperlinkWithIcon field;

                @Override
                public void updateItem(final DepositListItem item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null && !empty) {
                        String addressString = item.getAddressString();
                        field = new HyperlinkWithIcon(addressString, AwesomeIcon.EXTERNAL_LINK);
                        field.setOnAction(event -> {
                            openBlockExplorer(item);
                            tableView.getSelectionModel().select(item);
                        });
                        field.setTooltip(new Tooltip("Open external blockchain explorer for " + "address: " + addressString));
                        setGraphic(field);
                    } else {
                        setGraphic(null);
                        if (field != null)
                            field.setOnAction(null);
                    }
                }
            };
        }
    });
}
Also used : QRCodeWindow(io.bitsquare.gui.main.overlays.windows.QRCodeWindow) HPos(javafx.geometry.HPos) Popup(io.bitsquare.gui.main.overlays.popups.Popup) Transaction(org.bitcoinj.core.Transaction) javafx.scene.control(javafx.scene.control) Coin(org.bitcoinj.core.Coin) Restrictions(io.bitsquare.btc.Restrictions) FXCollections(javafx.collections.FXCollections) Tuple2(io.bitsquare.common.util.Tuple2) ActivatableView(io.bitsquare.gui.common.view.ActivatableView) VBox(javafx.scene.layout.VBox) BalanceListener(io.bitsquare.btc.listeners.BalanceListener) GUIUtil(io.bitsquare.gui.util.GUIUtil) Inject(javax.inject.Inject) DevFlags(io.bitsquare.app.DevFlags) Insets(javafx.geometry.Insets) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) QRCode(net.glxn.qrgen.QRCode) ByteArrayInputStream(java.io.ByteArrayInputStream) WalletService(io.bitsquare.btc.WalletService) Layout(io.bitsquare.gui.util.Layout) ImageType(net.glxn.qrgen.image.ImageType) Callback(javafx.util.Callback) AddressEntry(io.bitsquare.btc.AddressEntry) GridPane(javafx.scene.layout.GridPane) BSFormatter(io.bitsquare.gui.util.BSFormatter) SortedList(javafx.collections.transformation.SortedList) InputTextField(io.bitsquare.gui.components.InputTextField) UserThread(io.bitsquare.common.UserThread) Subscription(org.fxmisc.easybind.Subscription) BitcoinURI(org.bitcoinj.uri.BitcoinURI) FXML(javafx.fxml.FXML) TimeUnit(java.util.concurrent.TimeUnit) Preferences(io.bitsquare.user.Preferences) HyperlinkWithIcon(io.bitsquare.gui.components.HyperlinkWithIcon) FormBuilder(io.bitsquare.gui.util.FormBuilder) EasyBind(org.fxmisc.easybind.EasyBind) ImageView(javafx.scene.image.ImageView) AddressTextField(io.bitsquare.gui.components.AddressTextField) ObservableList(javafx.collections.ObservableList) AwesomeIcon(de.jensd.fx.fontawesome.AwesomeIcon) FxmlView(io.bitsquare.gui.common.view.FxmlView) ChangeListener(javafx.beans.value.ChangeListener) NotNull(org.jetbrains.annotations.NotNull) Image(javafx.scene.image.Image) TitledGroupBg(io.bitsquare.gui.components.TitledGroupBg) HyperlinkWithIcon(io.bitsquare.gui.components.HyperlinkWithIcon)

Example 30 with Callback

use of javafx.util.Callback in project bitsquare by bitsquare.

the class TransactionsView method setDetailsColumnCellFactory.

private void setDetailsColumnCellFactory() {
    detailsColumn.setCellValueFactory((addressListItem) -> new ReadOnlyObjectWrapper<>(addressListItem.getValue()));
    detailsColumn.setCellFactory(new Callback<TableColumn<TransactionsListItem, TransactionsListItem>, TableCell<TransactionsListItem, TransactionsListItem>>() {

        @Override
        public TableCell<TransactionsListItem, TransactionsListItem> call(TableColumn<TransactionsListItem, TransactionsListItem> column) {
            return new TableCell<TransactionsListItem, TransactionsListItem>() {

                private HyperlinkWithIcon field;

                @Override
                public void updateItem(final TransactionsListItem item, boolean empty) {
                    super.updateItem(item, empty);
                    if (item != null && !empty) {
                        if (item.getDetailsAvailable()) {
                            field = new HyperlinkWithIcon(item.getDetails(), AwesomeIcon.INFO_SIGN);
                            field.setOnAction(event -> openDetailPopup(item));
                            field.setTooltip(new Tooltip("Open popup for details"));
                            setGraphic(field);
                        } else {
                            setGraphic(new Label(item.getDetails()));
                        }
                    } else {
                        setGraphic(null);
                        if (field != null)
                            field.setOnAction(null);
                    }
                }
            };
        }
    });
}
Also used : EventHandler(javafx.event.EventHandler) OpenOffer(io.bitsquare.trade.offer.OpenOffer) Scene(javafx.scene.Scene) Popup(io.bitsquare.gui.main.overlays.popups.Popup) java.util(java.util) javafx.scene.control(javafx.scene.control) AddressWithIconAndDirection(io.bitsquare.gui.components.AddressWithIconAndDirection) FXCollections(javafx.collections.FXCollections) DisputeManager(io.bitsquare.arbitration.DisputeManager) Trade(io.bitsquare.trade.Trade) CSVEntryConverter(com.googlecode.jcsv.writer.CSVEntryConverter) Tuple2(io.bitsquare.common.util.Tuple2) ActivatableView(io.bitsquare.gui.common.view.ActivatableView) VBox(javafx.scene.layout.VBox) Tradable(io.bitsquare.trade.Tradable) GUIUtil(io.bitsquare.gui.util.GUIUtil) KeyCombination(javafx.scene.input.KeyCombination) Inject(javax.inject.Inject) TradeManager(io.bitsquare.trade.TradeManager) FailedTradesManager(io.bitsquare.trade.failed.FailedTradesManager) ReadOnlyObjectWrapper(javafx.beans.property.ReadOnlyObjectWrapper) WalletService(io.bitsquare.btc.WalletService) TradeDetailsWindow(io.bitsquare.gui.main.overlays.windows.TradeDetailsWindow) FeePolicy(io.bitsquare.btc.FeePolicy) Callback(javafx.util.Callback) Nullable(javax.annotation.Nullable) DateFormat(java.text.DateFormat) BSFormatter(io.bitsquare.gui.util.BSFormatter) SortedList(javafx.collections.transformation.SortedList) KeyCode(javafx.scene.input.KeyCode) Utilities(io.bitsquare.common.util.Utilities) OfferDetailsWindow(io.bitsquare.gui.main.overlays.windows.OfferDetailsWindow) ClosedTradableManager(io.bitsquare.trade.closed.ClosedTradableManager) KeyEvent(javafx.scene.input.KeyEvent) Collectors(java.util.stream.Collectors) org.bitcoinj.core(org.bitcoinj.core) FXML(javafx.fxml.FXML) KeyCodeCombination(javafx.scene.input.KeyCodeCombination) Preferences(io.bitsquare.user.Preferences) HyperlinkWithIcon(io.bitsquare.gui.components.HyperlinkWithIcon) Script(org.bitcoinj.script.Script) Stream(java.util.stream.Stream) Stage(javafx.stage.Stage) Tuple4(io.bitsquare.common.util.Tuple4) OpenOfferManager(io.bitsquare.trade.offer.OpenOfferManager) ObservableList(javafx.collections.ObservableList) AwesomeIcon(de.jensd.fx.fontawesome.AwesomeIcon) FxmlView(io.bitsquare.gui.common.view.FxmlView) HyperlinkWithIcon(io.bitsquare.gui.components.HyperlinkWithIcon)

Aggregations

Callback (javafx.util.Callback)43 Inject (javax.inject.Inject)27 FxmlView (io.bitsquare.gui.common.view.FxmlView)26 javafx.scene.control (javafx.scene.control)25 Popup (io.bitsquare.gui.main.overlays.popups.Popup)24 ReadOnlyObjectWrapper (javafx.beans.property.ReadOnlyObjectWrapper)23 ObservableList (javafx.collections.ObservableList)22 FXML (javafx.fxml.FXML)22 VBox (javafx.scene.layout.VBox)21 HyperlinkWithIcon (io.bitsquare.gui.components.HyperlinkWithIcon)20 BSFormatter (io.bitsquare.gui.util.BSFormatter)20 SortedList (javafx.collections.transformation.SortedList)19 ImageView (javafx.scene.image.ImageView)18 ChangeListener (javafx.beans.value.ChangeListener)17 GUIUtil (io.bitsquare.gui.util.GUIUtil)16 FXCollections (javafx.collections.FXCollections)16 Insets (javafx.geometry.Insets)15 AwesomeIcon (de.jensd.fx.fontawesome.AwesomeIcon)13 UserThread (io.bitsquare.common.UserThread)13 ActivatableView (io.bitsquare.gui.common.view.ActivatableView)13