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

The following examples show how to use javafx.beans.property.BooleanProperty#bind() . 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: TowerDefenseApp.java    From FXGLGames with MIT License 6 votes vote down vote up
@Override
protected void initGame() {
    getGameWorld().addEntityFactory(new TowerDefenseFactory());

    // TODO: read this from external level data
    waypoints.addAll(Arrays.asList(
            new Point2D(700, 0),
            new Point2D(700, 300),
            new Point2D(50, 300),
            new Point2D(50, 450),
            new Point2D(700, 500)
    ));

    BooleanProperty enemiesLeft = new SimpleBooleanProperty();
    enemiesLeft.bind(getGameState().intProperty("numEnemies").greaterThan(0));

    getGameTimer().runAtIntervalWhile(this::spawnEnemy, Duration.seconds(1), enemiesLeft);

    getEventBus().addEventHandler(EnemyKilledEvent.ANY, this::onEnemyKilled);
    getEventBus().addEventHandler(EnemyReachedGoalEvent.ANY, e -> gameOver());
}
 
Example 2
Source File: TowerDefenseApp.java    From FXGLGames with MIT License 6 votes vote down vote up
@Override
protected void initGame() {
    getGameWorld().addEntityFactory(new TowerDefenseFactory());

    // TODO: read this from external level data
    waypoints.addAll(Arrays.asList(
            new Point2D(700, 0),
            new Point2D(700, 300),
            new Point2D(50, 300),
            new Point2D(50, 450),
            new Point2D(700, 500)
    ));

    BooleanProperty enemiesLeft = new SimpleBooleanProperty();
    enemiesLeft.bind(getGameState().intProperty("numEnemies").greaterThan(0));

    getGameTimer().runAtIntervalWhile(this::spawnEnemy, Duration.seconds(1), enemiesLeft);

    getEventBus().addEventHandler(EnemyKilledEvent.ANY, this::onEnemyKilled);
    getEventBus().addEventHandler(EnemyReachedGoalEvent.ANY, e -> gameOver());
}
 
Example 3
Source File: DemoUtil.java    From RadialFx with GNU Lesser General Public License v3.0 6 votes vote down vote up
public void addBooleanControl(final String title,
    final BooleanProperty boolProp) {
final CheckBox check = new CheckBox();
check.setSelected(boolProp.get());
boolProp.bind(check.selectedProperty());

final VBox box = new VBox();
final Text titleText = new Text(title);

titleText.textProperty().bind(new StringBinding() {
    {
	super.bind(check.selectedProperty());
    }

    @Override
    protected String computeValue() {
	return title + " : "
		+ String.valueOf(check.selectedProperty().get());
    }

});
box.getChildren().addAll(titleText, check);
getChildren().add(box);

   }
 
Example 4
Source File: BezierOffsetSnippet.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
public HBox ToggleButtonColor(String text,
		ObjectProperty<Color> colorProperty,
		BooleanProperty toggledProperty, boolean isToggled) {
	HBox hbox = new HBox();
	ToggleButton toggleButton = new ToggleButton(text);
	toggleButton.setOnAction((ae) -> {
		refreshAll();
	});
	ColorPicker colorPicker = new ColorPicker(colorProperty.get());
	colorProperty.bind(colorPicker.valueProperty());
	hbox.getChildren().addAll(toggleButton, colorPicker);
	toggledProperty.bind(toggleButton.selectedProperty());
	toggleButton.setSelected(isToggled);
	return hbox;
}
 
Example 5
Source File: MainWindow.java    From markdown-writer-fx with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Creates a boolean property that is bound to another boolean value
 * of the active editor.
 */
private BooleanProperty createActiveBooleanProperty(Function<FileEditor, ObservableBooleanValue> func) {
	BooleanProperty b = new SimpleBooleanProperty();
	FileEditor fileEditor = fileEditorTabPane.getActiveFileEditor();
	if (fileEditor != null)
		b.bind(func.apply(fileEditor));
	fileEditorTabPane.activeFileEditorProperty().addListener((observable, oldFileEditor, newFileEditor) -> {
		b.unbind();
		if (newFileEditor != null)
			b.bind(func.apply(newFileEditor));
		else
			b.set(false);
	});
	return b;
}
 
Example 6
Source File: MainWindow.java    From markdown-writer-fx with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Creates a boolean property that is bound to another boolean value
 * of the active editor's SmartEdit.
 */
private BooleanProperty createActiveEditBooleanProperty(Function<SmartEdit, ObservableBooleanValue> func) {
	BooleanProperty b = new SimpleBooleanProperty() {
		@Override
		public void set(boolean newValue) {
			// invoked when the user invokes an action
			// do not try to change SmartEdit properties because this
			// would throw a "bound value cannot be set" exception
		}
	};

	ChangeListener<? super FileEditor> listener = (observable, oldFileEditor, newFileEditor) -> {
		b.unbind();
		if (newFileEditor != null) {
			if (newFileEditor.getEditor() != null)
				b.bind(func.apply(newFileEditor.getEditor().getSmartEdit()));
			else {
				newFileEditor.editorProperty().addListener((ob, o, n) -> {
					b.bind(func.apply(n.getSmartEdit()));
				});
			}
		} else
			b.set(false);
	};
	FileEditor fileEditor = fileEditorTabPane.getActiveFileEditor();
	listener.changed(null, null, fileEditor);
	fileEditorTabPane.activeFileEditorProperty().addListener(listener);
	return b;
}
 
Example 7
Source File: CompletableService.java    From mokka7 with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * {@link #runningProperty()}
 */
public CompletableService<T> bindRunning(BooleanProperty running) {
    running.bind(runningProperty());
    return this;
}