Java Code Examples for javafx.beans.binding.Bindings#createBooleanBinding()

The following examples show how to use javafx.beans.binding.Bindings#createBooleanBinding() . 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: MeshExporterDialog.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
public MeshExporterDialog(final MeshInfo<T> meshInfo)
{
	super();
	this.meshInfo = meshInfo;
	this.dirPath = new TextField();
	this.setTitle("Export mesh");
	this.isError = (Bindings.createBooleanBinding(() -> dirPath.getText().isEmpty(), dirPath.textProperty()));
	final MeshSettings settings = meshInfo.getMeshSettings();
	this.scale = new TextField(Integer.toString(settings.getFinestScaleLevel()));
	UIUtils.setNumericTextField(scale, settings.getNumScaleLevels() - 1);

	setResultConverter(button -> {
		if (button.getButtonData().isCancelButton()) { return null; }
		return new MeshExportResult(
				meshExporter,
				filePath,
				Integer.parseInt(scale.getText())
		);
	});

	createDialog();
}
 
Example 2
Source File: PasswordDialogController.java    From chvote-1-0 with GNU Affero General Public License v3.0 6 votes vote down vote up
private BooleanBinding bindForValidity(boolean withConfirmation, TextField electionOfficer1Password, TextField electionOfficer2Password, Label errorMessage, Node confirmButton) {
    BooleanBinding passwordsValid = Bindings.createBooleanBinding(
            () -> withConfirmation ? arePasswordsEqualAndValid(electionOfficer1Password.textProperty(), electionOfficer2Password.textProperty()) : isPasswordValid(electionOfficer1Password.getText()),
            electionOfficer1Password.textProperty(),
            electionOfficer2Password.textProperty());
    passwordsValid.addListener((observable, werePasswordsValid, arePasswordsValid) -> {
        confirmButton.setDisable(!arePasswordsValid);
        errorMessage.setVisible(!arePasswordsValid && withConfirmation);
    });
    return passwordsValid;
}
 
Example 3
Source File: MainView.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void updateHost() {

        Dialog<String> dialog = new Dialog<String>("Host", null);

        TextField hostField = new TextField(TicTacToe.getHost());
        dialog.setContent(hostField);

        Button okButton = new Button("OK");
        okButton.setOnAction(e -> {
            dialog.setResult(hostField.getText());
            dialog.hide();
        });

        BooleanBinding urlBinding = Bindings.createBooleanBinding(
                () -> isUrlValid(hostField.getText()),
                hostField.textProperty());
        okButton.disableProperty().bind(urlBinding.not());

        Button cancelButton = new Button("CANCEL");
        cancelButton.setOnAction(e -> dialog.hide());
        dialog.getButtons().addAll(okButton,cancelButton);
        dialog.showAndWait().ifPresent( url -> TicTacToe.setHost(url));

    }
 
Example 4
Source File: IncorrectMatchPresenter.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public void initialize() {

        incorrectView.setShowTransitionFactory(FlipInYTransition::new);

        toggleGroup.selectToggle(null);

        BooleanBinding toggleNotSelected = Bindings.createBooleanBinding(
                () -> toggleGroup.getSelectedToggle() == null,
                toggleGroup.selectedToggleProperty()
        );
        submitButton.disableProperty().bind(toggleNotSelected);
     //   imageView.imageProperty().bind(model.filteredImageProperty());
        incorrectView.showingProperty().addListener((obs, oldValue, newValue) -> {
            if (newValue) {
                AppBar appBar = getApp().getAppBar();
                appBar.setTitleText("Incorrect Match");
                appBar.setNavIcon(MaterialDesignIcon.ERROR.button());
            }
        });
    }
 
Example 5
Source File: SourceInfo.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
public ObservableBooleanValue isCurrentSource(final Source<?> source)
{
	return Bindings.createBooleanBinding(
			() -> Optional.ofNullable(currentSource.get()).map(source::equals).orElse(false),
			currentSource
	                                    );
}
 
Example 6
Source File: SegmentMeshExporterDialog.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
public SegmentMeshExporterDialog(final SegmentMeshInfo meshInfo)
{
	super();
	this.segmentIds = new long[] { meshInfo.segmentId() };
	this.fragmentIds = new long[][] { meshInfo.containedFragments() };
	this.filePath = new TextField();
	this.filePaths = new String[] {""};
	this.setTitle("Export mesh " + this.segmentIds);
	this.isError = (Bindings.createBooleanBinding(() -> filePath.getText().isEmpty(), filePath.textProperty()));
	final MeshSettings settings = meshInfo.getMeshSettings();
	this.scale = new TextField(Integer.toString(settings.getFinestScaleLevel()));
	UIUtils.setNumericTextField(scale, settings.getNumScaleLevels() - 1);

	setResultConverter(button -> {
		if (button.getButtonData().isCancelButton()) { return null; }
		return new SegmentMeshExportResult(
				meshExporter,
				fragmentIds,
				segmentIds,
				Integer.parseInt(scale.getText()),
				filePaths
		);
	});

	createDialog();

}
 
Example 7
Source File: KeyTestingController.java    From chvote-1-0 with GNU Affero General Public License v3.0 5 votes vote down vote up
private void initializeBindings() {
    encryptButton.setDisable(true);
    BooleanBinding plainTextsEmpty = Bindings.createBooleanBinding(plainTexts::isEmpty, plainTexts);
    plainTextsEmpty.addListener(
            (observable, oldValue, isPlainTextListEmpty) ->
                    encryptButton.setDisable(isPlainTextListEmpty)
    );

    decryptButton.setDisable(true);
    cipherTexts.addListener((ListChangeListener<AuthenticatedBallot>) c -> decryptButton.setDisable(c.getList().isEmpty()));
}
 
Example 8
Source File: IntersectingSourceState.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
public <D extends IntegerType<D>, T extends Type<T>, B extends BooleanType<B>> IntersectingSourceState(
		final ThresholdingSourceState<?, ?> thresholded,
		final ConnectomicsLabelState<D, T> labels,
		final Composite<ARGBType, ARGBType> composite,
		final String name,
		final SharedQueue queue,
		final int priority,
		final Group meshesGroup,
		final ObjectProperty<ViewFrustum> viewFrustumProperty,
		final ObjectProperty<AffineTransform3D> eyeToWorldTransformProperty,
		final ObservableBooleanValue viewerEnabled,
		final ExecutorService manager,
		final HashPriorityQueueBasedTaskExecutor<MeshWorkerPriority> workers) {
	// TODO use better converter
	super(
			makeIntersect(thresholded, labels, queue, priority, name),
			new ARGBColorConverter.Imp0<>(0, 1),
			composite,
			name,
			// dependsOn:
			thresholded,
			labels);
	final DataSource<UnsignedByteType, VolatileUnsignedByteType> source = getDataSource();

	final MeshManagerWithAssignmentForSegments segmentMeshManager = labels.getMeshManager();

	this.labelsMeshesEnabledAndMeshesEnabled = Bindings.createBooleanBinding(
			() -> meshesEnabled.get() && segmentMeshManager.getManagedSettings().meshesEnabledProperty().get(),
			meshesEnabled,
			segmentMeshManager.getManagedSettings().meshesEnabledProperty());

	final BiFunction<TLongHashSet, Double, Converter<UnsignedByteType, BoolType>> getMaskGenerator = (l, minLabelRatio) -> (s, t) -> t.set(s.get() > 0);
	final SegmentMeshCacheLoader<UnsignedByteType>[] loaders = new SegmentMeshCacheLoader[getDataSource().getNumMipmapLevels()];
	Arrays.setAll(loaders, d -> new SegmentMeshCacheLoader<>(
			() -> getDataSource().getDataSource(0, d),
			getMaskGenerator,
			getDataSource().getSourceTransformCopy(0, d)));
	final GetMeshFor.FromCache<TLongHashSet> getMeshFor = GetMeshFor.FromCache.fromPairLoaders(loaders);

	this.fragmentsInSelectedSegments = new FragmentsInSelectedSegments(labels.getSelectedSegments());

	this.meshManager = new MeshManagerWithSingleMesh<>(
			source,
			getGetBlockListFor(segmentMeshManager.getLabelBlockLookup()),
			new WrappedGetMeshFromCache(getMeshFor),
			viewFrustumProperty,
			eyeToWorldTransformProperty,
			manager,
			workers,
			new MeshViewUpdateQueue<>());
	this.meshManager.viewerEnabledProperty().bind(viewerEnabled);
	final ObjectBinding<Color> colorProperty = Bindings.createObjectBinding(
			() -> Colors.toColor(this.converter().getColor()),
			this.converter().colorProperty());
	this.meshManager.colorProperty().bind(colorProperty);
	meshesGroup.getChildren().add(this.meshManager.getMeshesGroup());
	this.meshManager.getSettings().bindBidirectionalTo(segmentMeshManager.getSettings());
	this.meshManager.getRendererSettings().meshesEnabledProperty().bind(labelsMeshesEnabledAndMeshesEnabled);
	this.meshManager.getRendererSettings().blockSizeProperty().bind(segmentMeshManager.getRendererSettings().blockSizeProperty());
	this.meshManager.getRendererSettings().setShowBlockBounadries(false);
	this.meshManager.getRendererSettings().frameDelayMsecProperty().bind(segmentMeshManager.getRendererSettings().frameDelayMsecProperty());
	this.meshManager.getRendererSettings().numElementsPerFrameProperty().bind(segmentMeshManager.getRendererSettings().numElementsPerFrameProperty());
	this.meshManager.getRendererSettings().sceneUpdateDelayMsecProperty().bind(segmentMeshManager.getRendererSettings().sceneUpdateDelayMsecProperty());

	thresholded.getThreshold().minValue().addListener((obs, oldv, newv) -> {
		getMeshFor.invalidateAll();
		refreshMeshes(); });
	thresholded.getThreshold().maxValue().addListener((obs, oldv, newv) -> {
		getMeshFor.invalidateAll();
		refreshMeshes(); });

	fragmentsInSelectedSegments.addListener(obs -> refreshMeshes());
}
 
Example 9
Source File: IntersectingSourceState.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
@Deprecated
public <D extends IntegerType<D>, T extends Type<T>, B extends BooleanType<B>> IntersectingSourceState(
		final ThresholdingSourceState<?, ?> thresholded,
		final LabelSourceState<D, T> labels,
		final Composite<ARGBType, ARGBType> composite,
		final String name,
		final SharedQueue queue,
		final int priority,
		final Group meshesGroup,
		final ObjectProperty<ViewFrustum> viewFrustumProperty,
		final ObjectProperty<AffineTransform3D> eyeToWorldTransformProperty,
		final ObservableBooleanValue viewerEnabled,
		final ExecutorService manager,
		final HashPriorityQueueBasedTaskExecutor<MeshWorkerPriority> workers) {
	// TODO use better converter
	super(
			makeIntersect(thresholded, labels, queue, priority, name),
			new ARGBColorConverter.Imp0<>(0, 1),
			composite,
			name,
			// dependsOn:
			thresholded,
			labels);
	final DataSource<UnsignedByteType, VolatileUnsignedByteType> source = getDataSource();

	final MeshManagerWithAssignmentForSegments segmentMeshManager = labels.meshManager();
	final SelectedIds selectedIds = labels.selectedIds();

	this.labelsMeshesEnabledAndMeshesEnabled = Bindings.createBooleanBinding(
			() -> meshesEnabled.get() && segmentMeshManager.getManagedSettings().meshesEnabledProperty().get(),
			meshesEnabled,
			segmentMeshManager.getManagedSettings().meshesEnabledProperty());


	final BiFunction<TLongHashSet, Double, Converter<UnsignedByteType, BoolType>> getMaskGenerator = (l, minLabelRatio) -> (s, t) -> t.set(s.get() > 0);
	final SegmentMeshCacheLoader<UnsignedByteType>[] loaders = new SegmentMeshCacheLoader[getDataSource().getNumMipmapLevels()];
	Arrays.setAll(loaders, d -> new SegmentMeshCacheLoader<>(
			() -> getDataSource().getDataSource(0, d),
			getMaskGenerator,
			getDataSource().getSourceTransformCopy(0, d)));
	final GetMeshFor.FromCache<TLongHashSet> getMeshFor = GetMeshFor.FromCache.fromPairLoaders(loaders);

	final FragmentSegmentAssignmentState assignment                  = labels.assignment();
	final SelectedSegments               selectedSegments            = new SelectedSegments(selectedIds, assignment);
	this.fragmentsInSelectedSegments = new FragmentsInSelectedSegments(selectedSegments);

	this.meshManager = new MeshManagerWithSingleMesh<>(
			source,
			getGetBlockListFor(segmentMeshManager.getLabelBlockLookup()),
			new WrappedGetMeshFromCache(getMeshFor),
			viewFrustumProperty,
			eyeToWorldTransformProperty,
			manager,
			workers,
			new MeshViewUpdateQueue<>());
	this.meshManager.viewerEnabledProperty().bind(viewerEnabled);
	meshesGroup.getChildren().add(this.meshManager.getMeshesGroup());
	final ObjectBinding<Color> colorProperty = Bindings.createObjectBinding(
			() -> Colors.toColor(this.converter().getColor()),
			this.converter().colorProperty());
	this.meshManager.colorProperty().bind(colorProperty);
	this.meshManager.getSettings().bindBidirectionalTo(segmentMeshManager.getSettings());
	this.meshManager.getRendererSettings().meshesEnabledProperty().bind(labelsMeshesEnabledAndMeshesEnabled);
	this.meshManager.getRendererSettings().blockSizeProperty().bind(segmentMeshManager.getRendererSettings().blockSizeProperty());
	this.meshManager.getRendererSettings().setShowBlockBounadries(false);
	this.meshManager.getRendererSettings().frameDelayMsecProperty().bind(segmentMeshManager.getRendererSettings().frameDelayMsecProperty());
	this.meshManager.getRendererSettings().numElementsPerFrameProperty().bind(segmentMeshManager.getRendererSettings().numElementsPerFrameProperty());
	this.meshManager.getRendererSettings().sceneUpdateDelayMsecProperty().bind(segmentMeshManager.getRendererSettings().sceneUpdateDelayMsecProperty());

	thresholded.getThreshold().minValue().addListener((obs, oldv, newv) -> {
		getMeshFor.invalidateAll();
		refreshMeshes();
	});
	thresholded.getThreshold().maxValue().addListener((obs, oldv, newv) -> {
		getMeshFor.invalidateAll();
		refreshMeshes();
	});

	fragmentsInSelectedSegments.addListener(obs -> refreshMeshes());
}
 
Example 10
Source File: SegmentMeshExporterDialog.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
public SegmentMeshExporterDialog(final SegmentMeshInfos meshInfos)
{
	super();
	final ObservableList<SegmentMeshInfo> meshInfoList = meshInfos.readOnlyInfos();
	this.filePath = new TextField();
	this.setTitle("Export mesh ");
	this.segmentIds = new long[meshInfoList.size()];
	this.fragmentIds = new long[meshInfoList.size()][];
	this.filePaths = new String[meshInfoList.size()];
	this.checkListView = new CheckListView<>();
	this.isError = (Bindings.createBooleanBinding(() -> filePath.getText().isEmpty() || checkListView.getItems()
					.isEmpty(),
			filePath.textProperty(),
			checkListView.itemsProperty()
	                                             ));

	int                        minCommonScaleLevels = Integer.MAX_VALUE;
	int                        minCommonScale       = Integer.MAX_VALUE;
	final ObservableList<Long> ids                  = FXCollections.observableArrayList();
	for (int i = 0; i < meshInfoList.size(); i++)
	{
		final SegmentMeshInfo info = meshInfoList.get(i);
		this.segmentIds[i] = info.segmentId();
		this.fragmentIds[i] = info.containedFragments();
		final MeshSettings settings = info.getMeshSettings();
		ids.add(info.segmentId());

		if (minCommonScaleLevels > settings.getNumScaleLevels())
		{
			minCommonScaleLevels = settings.getNumScaleLevels();
		}

		if (minCommonScale > settings.getFinestScaleLevel())
		{
			minCommonScale = settings.getFinestScaleLevel();
		}
	}

	scale = new TextField(Integer.toString(minCommonScale));
	UIUtils.setNumericTextField(scale, minCommonScaleLevels - 1);

	setResultConverter(button -> {
		if (button.getButtonData().isCancelButton()) { return null; }
		return new SegmentMeshExportResult<>(
				meshExporter,
				fragmentIds,
				segmentIds,
				Integer.parseInt(scale.getText()),
				filePaths
		);
	});

	createMultiIdsDialog(ids);
}
 
Example 11
Source File: UIUtils.java    From cute-proxy with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public static ObservableValue<Boolean> observeNull(ObservableValue<?> observable) {
    return Bindings.createBooleanBinding(() -> observable.getValue() == null, observable);
}
 
Example 12
Source File: MainPresenter.java    From clarity-analyzer with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void initialize(java.net.URL location, java.util.ResourceBundle resources) {
    preferences = Preferences.userNodeForPackage(this.getClass());
    replayController = new ReplayController(slider);

    BooleanBinding runnerIsNull = Bindings.createBooleanBinding(() -> replayController.getRunner() == null, replayController.runnerProperty());
    buttonPlay.disableProperty().bind(runnerIsNull.or(replayController.playingProperty()));
    buttonPause.disableProperty().bind(runnerIsNull.or(replayController.playingProperty().not()));
    slider.disableProperty().bind(runnerIsNull);

    labelTick.textProperty().bind(replayController.tickProperty().asString());
    labelLastTick.textProperty().bind(replayController.lastTickProperty().asString());

    TableColumn<ObservableEntity, String> entityTableIdColumn = (TableColumn<ObservableEntity, String>) entityTable.getColumns().get(0);
    entityTableIdColumn.setCellValueFactory(param -> param.getValue() != null ? param.getValue().indexProperty() : new ReadOnlyStringWrapper(""));
    TableColumn<ObservableEntity, String> entityTableNameColumn = (TableColumn<ObservableEntity, String>) entityTable.getColumns().get(1);
    entityTableNameColumn.setCellValueFactory(param -> param.getValue() != null ? param.getValue().nameProperty() : new ReadOnlyStringWrapper(""));
    entityTable.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
        log.info("entity table selection from {} to {}", oldValue, newValue);
        detailTable.setItems(newValue);
    });

    TableColumn<ObservableEntityProperty, String> idColumn =
        (TableColumn<ObservableEntityProperty, String>) detailTable.getColumns().get(0);
    idColumn.setCellValueFactory(param -> param.getValue().indexProperty());
    TableColumn<ObservableEntityProperty, String> nameColumn =
        (TableColumn<ObservableEntityProperty, String>) detailTable.getColumns().get(1);
    nameColumn.setCellValueFactory(param -> param.getValue().nameProperty());
    TableColumn<ObservableEntityProperty, String> valueColumn =
        (TableColumn<ObservableEntityProperty, String>) detailTable.getColumns().get(2);
    valueColumn.setCellValueFactory(param -> param.getValue().valueProperty());

    valueColumn.setCellFactory(v -> new TableCell<ObservableEntityProperty, String>() {
        final Animation animation = new Transition() {
            {
                setCycleDuration(Duration.millis(500));
                setInterpolator(Interpolator.EASE_OUT);
            }
            @Override
            protected void interpolate(double frac) {
                Color col = Color.YELLOW.interpolate(Color.WHITE, frac);
                getTableRow().setStyle(String.format(
                        "-fx-control-inner-background: #%02X%02X%02X;",
                        (int)(col.getRed() * 255),
                        (int)(col.getGreen() * 255),
                        (int)(col.getBlue() * 255)
                ));
            }
        };
        @Override
        protected void updateItem(String item, boolean empty) {
            super.updateItem(item, empty);
            setText(item);
            ObservableEntityProperty oep = (ObservableEntityProperty) getTableRow().getItem();
            if (oep != null) {
                animation.stop();
                animation.playFrom(Duration.millis(System.currentTimeMillis() - oep.getLastChangedAt()));
            }
        }
    });

    detailTable.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    detailTable.setOnKeyPressed(e -> {
        KeyCombination ctrlC = new KeyCodeCombination(KeyCode.C, KeyCodeCombination.CONTROL_DOWN);
        if (ctrlC.match(e)) {
            ClipboardContent cbc = new ClipboardContent();
            cbc.putString(detailTable.getSelectionModel().getSelectedIndices().stream()
                    .map(i -> detailTable.getItems().get(i))
                    .map(p -> String.format("%s %s %s", p.indexProperty().get(), p.nameProperty().get(), p.valueProperty().get()))
                    .collect(Collectors.joining("\n"))
            );
            Clipboard.getSystemClipboard().setContent(cbc);
        }
    });


    entityNameFilter.textProperty().addListener(observable -> {
        if (filteredEntityList != null) {
            filteredEntityList.setPredicate(allFilterFunc);
            filteredEntityList.setPredicate(filterFunc);
        }
    });

    mapControl = new MapControl();
    mapCanvasPane.getChildren().add(mapControl);

    mapCanvasPane.setTopAnchor(mapControl, 0.0);
    mapCanvasPane.setBottomAnchor(mapControl, 0.0);
    mapCanvasPane.setLeftAnchor(mapControl, 0.0);
    mapCanvasPane.setRightAnchor(mapControl, 0.0);
    mapCanvasPane.widthProperty().addListener(evt -> resizeMapControl());
    mapCanvasPane.heightProperty().addListener(evt -> resizeMapControl());

}