javafx.beans.value.ObservableBooleanValue Java Examples

The following examples show how to use javafx.beans.value.ObservableBooleanValue. 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: Bindings.java    From SmartModInserter with GNU Lesser General Public License v3.0 7 votes vote down vote up
/**
 * Returns a new observable string which contains either the contents of ifTrue, or ifFalse, depending on the condition
 * @param condition
 * @param ifTrue
 * @param ifFalse
 * @return
 */
public static ObservableStringValue decision(ObservableBooleanValue condition,
                                             ObservableStringValue ifTrue,
                                             ObservableStringValue ifFalse) {
    StringProperty ret = new SimpleStringProperty();
    condition.addListener((obs, ov, nv) -> {
        ret.set(nv ? ifTrue.get() : ifFalse.get());
    });
    ifTrue.addListener((obs, ov, nv) -> {
        if (condition.get()) {
            ret.set(nv);
        }
    });
    ifFalse.addListener((obs, ov, nv) -> {
        if (!condition.get()) {
            ret.set(nv);
        }
    });
    ret.set(condition.get() ? ifTrue.get() : ifFalse.get());

    return ret;
}
 
Example #2
Source File: VirtualAssetEditorDialog.java    From jmonkeybuilder with Apache License 2.0 6 votes vote down vote up
@Override
@FxThread
protected @NotNull ObservableBooleanValue buildAdditionalDisableCondition() {

    final VirtualResourceTree<C> resourceTree = getResourceTree();
    final MultipleSelectionModel<TreeItem<VirtualResourceElement<?>>> selectionModel = resourceTree.getSelectionModel();
    final ReadOnlyObjectProperty<TreeItem<VirtualResourceElement<?>>> selectedItemProperty = selectionModel.selectedItemProperty();

    final Class<C> type = getObjectsType();
    final BooleanBinding typeCondition = new BooleanBinding() {

        @Override
        protected boolean computeValue() {
            final TreeItem<VirtualResourceElement<?>> treeItem = selectedItemProperty.get();
            return treeItem == null || !type.isInstance(treeItem.getValue().getObject());
        }

        @Override
        public Boolean getValue() {
            return computeValue();
        }
    };

    return Bindings.or(selectedItemProperty.isNull(), typeCondition);
}
 
Example #3
Source File: NeuralImageCell.java    From neural-style-gui with GNU General Public License v3.0 6 votes vote down vote up
public NeuralImageCell(ObservableBooleanValue editable) {
    FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/neuralImageCell.fxml"));
    fxmlLoader.setController(this);
    fxmlLoader.setRoot(this);

    try {
        fxmlLoader.load();
    } catch (IOException exception) {
        throw new RuntimeException(exception);
    }

    setEditable(false);
    if (editable != null) {
        EventStreams.changesOf(editable).subscribe(editableChange -> {
            setEditable(editableChange.getNewValue());
        });
    }
}
 
Example #4
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 #5
Source File: BooleanBinding.java    From ReactFX with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * @deprecated Use {@link Val#suspendable(javafx.beans.value.ObservableValue)}.
 */
@Deprecated
public static BooleanBinding wrap(ObservableBooleanValue source) {
    return new BooleanBinding() {
        { bind(source); }

        @Override
        protected boolean computeValue() { return source.get(); }
    };
}
 
Example #6
Source File: UndoUtils.java    From RichTextFX with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Constructs an UndoManager with no history
 */
public static UndoManager noOpUndoManager() {
    return new UndoManager() {

        private final Val<Boolean> alwaysFalse = Val.constant(false);

        @Override public boolean undo() { return false; }
        @Override public boolean redo() { return false; }
        @Override public Val<Boolean> undoAvailableProperty() { return alwaysFalse; }
        @Override public boolean isUndoAvailable() { return false; }
        @Override public Val<Boolean> redoAvailableProperty() { return alwaysFalse; }
        @Override public boolean isRedoAvailable() { return false; }
        @Override public boolean isPerformingAction() { return false; }
        @Override public boolean isAtMarkedPosition() { return false; }

        // not sure whether these may throw NPEs at some point
        @Override public Val nextUndoProperty() { return null; }
        @Override public Val nextRedoProperty() { return null; }
        @Override public ObservableBooleanValue performingActionProperty() { return null; }
        @Override public UndoPosition getCurrentPosition() { return null; }
        @Override public ObservableBooleanValue atMarkedPositionProperty() { return null; }

        // ignore these
        @Override public void preventMerge() { }
        @Override public void forgetHistory() { }
        @Override public void close() { }
    };
}
 
Example #7
Source File: AssetEditorDialog.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
@Override
@FxThread
protected @NotNull ObservableBooleanValue buildAdditionalDisableCondition() {
    final ResourceTree resourceTree = getResourceTree();
    final MultipleSelectionModel<TreeItem<ResourceElement>> selectionModel = resourceTree.getSelectionModel();
    final ReadOnlyObjectProperty<TreeItem<ResourceElement>> selectedItemProperty = selectionModel.selectedItemProperty();
    return selectedItemProperty.isNull();
}
 
Example #8
Source File: Action.java    From markdown-writer-fx with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public Action(String text, String accelerator, GlyphIcons icon,
	EventHandler<ActionEvent> action, ObservableBooleanValue disable,
	BooleanProperty selected)
{
	this.text = text;
	this.accelerator = (accelerator != null) ? KeyCombination.valueOf(accelerator) : null;
	this.icon = icon;
	this.action = action;
	this.disable = disable;
	this.selected = selected;
}
 
Example #9
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 #10
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 #11
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 #12
Source File: Await.java    From ReactFX with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public final ObservableBooleanValue pendingProperty() {
    return pending;
}
 
Example #13
Source File: UndoManagerImpl.java    From UndoFX with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public ObservableBooleanValue atMarkedPositionProperty() {
    return atMarkedPosition;
}
 
Example #14
Source File: UndoManagerImpl.java    From UndoFX with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public ObservableBooleanValue performingActionProperty() {
    return performingAction;
}
 
Example #15
Source File: Action.java    From markdown-writer-fx with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Action(String text, String accelerator, GlyphIcons icon,
	EventHandler<ActionEvent> action, ObservableBooleanValue disable)
{
	this(text, accelerator, icon, action, disable, null);
}
 
Example #16
Source File: FilterSessionWordTableCell.java    From VocabHunter with Apache License 2.0 4 votes vote down vote up
public FilterSessionWordTableCell(final ObservableBooleanValue includeUnknown) {
    this.includeUnknown = includeUnknown;
}
 
Example #17
Source File: ConfigNode.java    From trex-stateless-gui with Apache License 2.0 4 votes vote down vote up
public ObservableBooleanValue mandatoryProperty() {
    return mandatoryProperty;
}
 
Example #18
Source File: SourceInfo.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
public ObservableBooleanValue isDirtyProperty()
{
	return this.isDirty;
}
 
Example #19
Source File: SourceInfo.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
public ObservableBooleanValue hasVisibleSources()
{
	return this.hasVisibleSources;
}
 
Example #20
Source File: SourceInfo.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
public ObservableBooleanValue hasSources()
{
	return this.hasSources;
}
 
Example #21
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 #22
Source File: BaseAssetEditorDialog.java    From jmonkeybuilder with Apache License 2.0 2 votes vote down vote up
/**
 * Build additional disable condition.
 *
 * @return the additional condition.
 */
@FxThread
protected @NotNull ObservableBooleanValue buildAdditionalDisableCondition() {
    throw new RuntimeException("unsupported");
}
 
Example #23
Source File: UndoManager.java    From UndoFX with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * Indicates whether this undo manager is currently performing undo or redo
 * action.
 */
ObservableBooleanValue performingActionProperty();
 
Example #24
Source File: UndoManager.java    From UndoFX with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * Indicates whether this UndoManager's current position within
 * its history is the same as the last marked position.
 */
ObservableBooleanValue atMarkedPositionProperty();
 
Example #25
Source File: AwaitingEventStream.java    From ReactFX with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * Indicates whether there is a pending event that will be emitted by this
 * stream in the (near) future. This may mean that an event has occurred
 * that causes this stream to emit an event with some delay, e.g. waiting
 * for a timer or completion of an asynchronous task.
 */
ObservableBooleanValue pendingProperty();
 
Example #26
Source File: AndGateDemo.java    From ReactFX with BSD 2-Clause "Simplified" License votes vote down vote up
@Override public ObservableBooleanValue a() { return a; } 
Example #27
Source File: AndGateDemo.java    From ReactFX with BSD 2-Clause "Simplified" License votes vote down vote up
@Override public ObservableBooleanValue b() { return b; }