Search in sources :

Example 6 with BooleanProperty

use of javafx.beans.property.BooleanProperty in project VocabHunter by VocabHunter.

the class FilterGridController method buildAndBindCheckBox.

private CheckBox buildAndBindCheckBox(final FilterGridModel filterModel, final int columnNo) {
    String name = ColumnNameTool.columnName(columnNo);
    CheckBox box = new CheckBox(name);
    BooleanProperty property = getColumnSelection(filterModel, columnNo);
    box.selectedProperty().bindBidirectional(property);
    box.setId("checkBoxColumn" + columnNo);
    box.selectedProperty().addListener((a, b, c) -> tableWords.refresh());
    return box;
}
Also used : CheckBox(javafx.scene.control.CheckBox) BooleanProperty(javafx.beans.property.BooleanProperty)

Example 7 with BooleanProperty

use of javafx.beans.property.BooleanProperty 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 8 with BooleanProperty

use of javafx.beans.property.BooleanProperty in project bitsquare by bitsquare.

the class TorNetworkNode method torNetworkNodeShutDown.

private BooleanProperty torNetworkNodeShutDown() {
    final BooleanProperty done = new SimpleBooleanProperty();
    executorService.submit(() -> {
        Utilities.setThreadName("torNetworkNodeShutDown");
        long ts = System.currentTimeMillis();
        log.debug("Shutdown torNetworkNode");
        try {
            if (torNetworkNode != null)
                torNetworkNode.shutdown();
            log.debug("Shutdown torNetworkNode done after " + (System.currentTimeMillis() - ts) + " ms.");
        } catch (Throwable e) {
            log.error("Shutdown torNetworkNode failed with exception: " + e.getMessage());
            e.printStackTrace();
        } finally {
            UserThread.execute(() -> done.set(true));
        }
    });
    return done;
}
Also used : SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) BooleanProperty(javafx.beans.property.BooleanProperty) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty)

Example 9 with BooleanProperty

use of javafx.beans.property.BooleanProperty in project bitsquare by bitsquare.

the class TorNetworkNode method shutDown.

public void shutDown(@Nullable Runnable shutDownCompleteHandler) {
    Log.traceCall();
    BooleanProperty torNetworkNodeShutDown = torNetworkNodeShutDown();
    BooleanProperty networkNodeShutDown = networkNodeShutDown();
    BooleanProperty shutDownTimerTriggered = shutDownTimerTriggered();
    // Need to store allShutDown to not get garbage collected
    allShutDown = EasyBind.combine(torNetworkNodeShutDown, networkNodeShutDown, shutDownTimerTriggered, (a, b, c) -> (a && b) || c);
    allShutDown.subscribe((observable, oldValue, newValue) -> {
        if (newValue) {
            shutDownTimeoutTimer.stop();
            long ts = System.currentTimeMillis();
            log.debug("Shutdown executorService");
            try {
                MoreExecutors.shutdownAndAwaitTermination(executorService, 500, TimeUnit.MILLISECONDS);
                log.debug("Shutdown executorService done after " + (System.currentTimeMillis() - ts) + " ms.");
                log.debug("Shutdown completed");
            } catch (Throwable t) {
                log.error("Shutdown executorService failed with exception: " + t.getMessage());
                t.printStackTrace();
            } finally {
                if (shutDownCompleteHandler != null)
                    shutDownCompleteHandler.run();
            }
        }
    });
}
Also used : HiddenServiceDescriptor(io.nucleo.net.HiddenServiceDescriptor) MoreExecutors(com.google.common.util.concurrent.MoreExecutors) Socket(java.net.Socket) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) LoggerFactory(org.slf4j.LoggerFactory) Timer(io.bitsquare.common.Timer) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) JavaOnionProxyContext(com.msopentech.thali.java.toronionproxy.JavaOnionProxyContext) TorNode(io.nucleo.net.TorNode) Socks5Proxy(com.runjva.sourceforge.jsocks.protocol.Socks5Proxy) MonadicBinding(org.fxmisc.easybind.monadic.MonadicBinding) JavaTorNode(io.nucleo.net.JavaTorNode) Log(io.bitsquare.app.Log) Utilities(io.bitsquare.common.util.Utilities) Logger(org.slf4j.Logger) JavaOnionProxyManager(com.msopentech.thali.java.toronionproxy.JavaOnionProxyManager) UserThread(io.bitsquare.common.UserThread) NodeAddress(io.bitsquare.p2p.NodeAddress) IOException(java.io.IOException) FutureCallback(com.google.common.util.concurrent.FutureCallback) File(java.io.File) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) Nullable(org.jetbrains.annotations.Nullable) Futures(com.google.common.util.concurrent.Futures) BooleanProperty(javafx.beans.property.BooleanProperty) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) EasyBind(org.fxmisc.easybind.EasyBind) Utils(io.bitsquare.p2p.Utils) NotNull(org.jetbrains.annotations.NotNull) BooleanProperty(javafx.beans.property.BooleanProperty) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty)

Example 10 with BooleanProperty

use of javafx.beans.property.BooleanProperty in project bitsquare by bitsquare.

the class TorNetworkNode method networkNodeShutDown.

private BooleanProperty networkNodeShutDown() {
    final BooleanProperty done = new SimpleBooleanProperty();
    super.shutDown(() -> done.set(true));
    return done;
}
Also used : SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty) BooleanProperty(javafx.beans.property.BooleanProperty) SimpleBooleanProperty(javafx.beans.property.SimpleBooleanProperty)

Aggregations

BooleanProperty (javafx.beans.property.BooleanProperty)14 SimpleBooleanProperty (javafx.beans.property.SimpleBooleanProperty)9 CountDownLatch (java.util.concurrent.CountDownLatch)3 IManager (EmployeeContracts.IManager)2 ConnectionFailure (EmployeeDefs.AEmployeeException.ConnectionFailure)2 EmployeeNotConnected (EmployeeDefs.AEmployeeException.EmployeeNotConnected)2 InvalidParameter (EmployeeDefs.AEmployeeException.InvalidParameter)2 Manager (EmployeeImplementations.Manager)2 CriticalError (SMExceptions.CommonExceptions.CriticalError)2 InjectionFactory (UtilsImplementations.InjectionFactory)2 StackTraceUtil (UtilsImplementations.StackTraceUtil)2 JFXButton (com.jfoenix.controls.JFXButton)2 JFXListView (com.jfoenix.controls.JFXListView)2 JFXTextField (com.jfoenix.controls.JFXTextField)2 UserThread (io.bitsquare.common.UserThread)2 IOException (java.io.IOException)2 URL (java.net.URL)2 HashSet (java.util.HashSet)2 ResourceBundle (java.util.ResourceBundle)2 ObservableValue (javafx.beans.value.ObservableValue)2