Java Code Examples for javafx.beans.property.BooleanProperty#addListener()

The following examples show how to use javafx.beans.property.BooleanProperty#addListener() . 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: WebViewHyperlinkListenerDemo.java    From mars-sim with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Attaches/detaches the specified listener to/from the specified web view according to the specified property's
 * value.
 *
 * @param webView
 *            the {@link WebView} to which the listener will be added
 * @param listener
 *            the added listener
 * @param attachedProperty
 *            defines whether the listener is attached or not
 */
private static void manageListener(WebView webView, WebViewHyperlinkListener listener,
		BooleanProperty attachedProperty) {
	attachedProperty.set(true);
	ListenerHandle listenerHandle = WebViews.addHyperlinkListener(webView, listener);

	attachedProperty.addListener((obs, wasAttached, isAttached) -> {
		if (isAttached) {
			listenerHandle.attach();
			System.out.println("LISTENER: attached.");
		} else {
			listenerHandle.detach();
			System.out.println("LISTENER: detached.");
		}
	});
}
 
Example 2
Source File: SessionManager.java    From mokka7 with Eclipse Public License 1.0 5 votes vote down vote up
public void bind(final BooleanProperty property, final String propertyName) {
    String value = props.getProperty(propertyName);
    if (value != null) {
        property.set(Boolean.valueOf(value));
    }
    property.addListener(new InvalidationListener() {

        @Override
        public void invalidated(Observable o) {
            props.setProperty(propertyName, property.getValue().toString());
        }
    });
}
 
Example 3
Source File: SessionContext.java    From jfxvnc with Apache License 2.0 5 votes vote down vote up
public void bind(final BooleanProperty property, final String propertyName) {
  String value = props.getProperty(propertyName);
  if (value != null) {
    property.set(Boolean.valueOf(value));
  }
  property.addListener(o -> {
    props.setProperty(propertyName, property.getValue().toString());
  });
}
 
Example 4
Source File: PrefBind.java    From erlyberly with GNU General Public License v3.0 5 votes vote down vote up
public static void bindBoolean(final String propName, BooleanProperty boolProp){
    if(props == null) {
        return;
    }
    Boolean storedValue = (Boolean) props.get(propName);
    if(storedValue != null) {
        boolProp.set(storedValue);
    }
    boolProp.addListener((ObservableValue<? extends Boolean> observable, Boolean oldValue, Boolean newValue) -> {
        set(propName, newValue);
    });
}
 
Example 5
Source File: DataViewerSample.java    From chart-fx with Apache License 2.0 4 votes vote down vote up
private static void logPropertyChange(final BooleanProperty property, final String name) {
    property.addListener((ch, o, n) -> LOGGER.atInfo().log("Property '{}' changed to '{}'", name, n));
}
 
Example 6
Source File: SortManager.java    From PDF4Teachers with Apache License 2.0 4 votes vote down vote up
public void setup(GridPane parent, String selectedButtonName, String... buttonsName){

        int row = 0;
        for(String buttonName : buttonsName){

            if(buttonName.equals("\n")){
                row++; continue;
            }

            Button button = new Button(buttonName);
            button.setGraphic(Builders.buildImage(getClass().getResource("/img/Sort/up.png")+"", 0, 0));
            button.setAlignment(Pos.CENTER_LEFT);
            button.setMaxWidth(Double.MAX_VALUE);
            GridPane.setHgrow(button, Priority.ALWAYS);
            BooleanProperty order = new SimpleBooleanProperty(true);
            buttons.put(button, order);
            parent.addRow(row, button);

            if(selectedButtonName.equals(buttonName)){
                selectedButton.set(button);
                button.setStyle("-fx-background-color: " + selectedColor + ";");
            }else button.setStyle("-fx-background-color: " + StyleManager.getHexAccentColor() + ";");

            // Image de l'ordre
            order.addListener(new ChangeListener<>() {
                @Override public void changed(ObservableValue<? extends Boolean> observableValue, Boolean lastOrder, Boolean newOrder) {
                    button.setGraphic(Builders.buildImage(getClass().getResource(newOrder ? "/img/Sort/up.png" : "/img/Sort/down.png") + "", 0, 0));
                }
            });

            // Change selectedButton lors du clic ET update l'ordre
            button.setOnAction(actionEvent -> {
                if(selectedButton.get() == button){
                    order.set(!order.get());
                    updateSort.call(button.getText(), order.get());
                }else selectedButton.set(button);
            });
        }
        if(selectedButton.get() == null){
            selectedButton.set(buttons.keySet().iterator().next());
            buttons.keySet().iterator().next().setStyle("-fx-background-color: " + selectedColor);
        }

        // Couleurs des boutons
        selectedButton.addListener((observableValue, lastSelected, newSelected) -> {
            lastSelected.setStyle("-fx-background-color: " + StyleManager.getHexAccentColor() + ";");
            newSelected.setStyle("-fx-background-color: " + selectedColor + ";");
            updateSort.call(newSelected.getText(), buttons.get(newSelected).get());
        });
    }
 
Example 7
Source File: LogPropertiesDemo.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void start(Stage primaryStage) throws IOException {

    Map<String, String> tracAttributes = new HashMap<>();
    tracAttributes.put("id", "1234");
    tracAttributes.put("URL", "https://trac.epics.org/tickets/1234");
    Property track = PropertyImpl.of("Track",tracAttributes);

    Map<String, String> experimentAttributes = new HashMap<>();
    experimentAttributes.put("id", "1234");
    experimentAttributes.put("type", "XPD xray diffraction");
    experimentAttributes.put("scan-id", "6789");
    Property experimentProperty = PropertyImpl.of("Experiment", experimentAttributes);

    FXMLLoader loader = new FXMLLoader();

    loader.setLocation(this.getClass().getResource("LogProperties.fxml"));
    loader.load();
    final LogPropertiesController controller = loader.getController();
    Node tree = loader.getRoot();

    CheckBox checkBox = new CheckBox();
    BooleanProperty editable = new SimpleBooleanProperty();
    checkBox.selectedProperty().bindBidirectional(editable);

    controller.setProperties(Arrays.asList(track, experimentProperty));
    editable.addListener((observable, oldValue, newValue) -> {
        controller.setEditable(newValue);
    });

    VBox vbox = new VBox();
    vbox.getChildren().add(checkBox);
    vbox.getChildren().add(tree);
    primaryStage.setScene(new Scene(vbox, 400, 400));
    primaryStage.show();

    primaryStage.setOnCloseRequest(v -> {
        controller.getProperties().stream().forEach(p -> {
            System.out.println(p.getName());
            p.getAttributes().entrySet().stream().forEach(e -> {
                System.out.println("     " + e.getKey() + " : " + e.getValue());
            });
        });
    });
}
 
Example 8
Source File: MainView.java    From bisq with GNU Affero General Public License v3.0 4 votes vote down vote up
private void setupBadge(JFXBadge buttonWithBadge, StringProperty badgeNumber, BooleanProperty badgeEnabled) {
    buttonWithBadge.textProperty().bind(badgeNumber);
    buttonWithBadge.setEnabled(badgeEnabled.get());
    badgeEnabled.addListener((observable, oldValue, newValue) -> {
        buttonWithBadge.setEnabled(newValue);
        buttonWithBadge.refreshBadge();
    });

    buttonWithBadge.setPosition(Pos.TOP_RIGHT);
    buttonWithBadge.setMinHeight(34);
    buttonWithBadge.setMaxHeight(34);
}