javafx.beans.value.ObservableObjectValue Java Examples

The following examples show how to use javafx.beans.value.ObservableObjectValue. 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: TabService.java    From AsciidocFX with Apache License 2.0 6 votes vote down vote up
public void initializeTabChangeListener(TabPane tabPane) {

        ReadOnlyObjectProperty<Tab> itemProperty = tabPane.getSelectionModel().selectedItemProperty();

        tabPane.setOnMouseReleased(event -> {
            Optional.ofNullable(itemProperty)
                    .map(ObservableObjectValue::get)
                    .filter(e -> e instanceof MyTab)
                    .map(e -> (MyTab) e)
                    .map(MyTab::getEditorPane)
                    .ifPresent(EditorPane::focus);
        });

        itemProperty.addListener((observable, oldValue, selectedTab) -> {
            Optional.ofNullable(selectedTab)
                    .filter(e -> e instanceof MyTab)
                    .map(e -> (MyTab) e)
                    .map(MyTab::getEditorPane)
                    .filter(EditorPane::getReady)
                    .ifPresent(EditorPane::updatePreviewUrl);
        });
    }
 
Example #2
Source File: ObjectBinding.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 <T> ObjectBinding<T> wrap(ObservableObjectValue<T> source) {
    return new ObjectBinding<T>() {
        { bind(source); }

        @Override
        protected T computeValue() { return source.get(); }
    };
}
 
Example #3
Source File: CurrentSourceVisibilityToggle.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
public CurrentSourceVisibilityToggle(final ObservableObjectValue<SourceState<?, ?>> currentState)
{
	super();
	this.currentState = currentState;
}
 
Example #4
Source File: SourceInfo.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
public ObservableObjectValue<SourceState<?, ?>> currentState()
{
	return this.currentState;
}
 
Example #5
Source File: MetaPanel.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
public void listenOnDimensions(final ObservableObjectValue<long[]> dimensions)
{
	this.dimensionsProperty.bind(dimensions);
}
 
Example #6
Source File: GenericBackendDialogN5.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
public ObservableObjectValue<DatasetAttributes> datsetAttributesProperty()
{
	return this.datasetAttributes;
}
 
Example #7
Source File: GenericBackendDialogN5.java    From paintera with GNU General Public License v2.0 4 votes vote down vote up
public ObservableObjectValue<long[]> dimensionsProperty()
{
	return this.dimensions;
}
 
Example #8
Source File: BaseIndicatorBox.java    From TAcharting with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public ObservableObjectValue<TaBarSeries> getObservableBarSeries(){
    return series;
}
 
Example #9
Source File: SizeTracker.java    From Flowless with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Constructs a SizeTracker
 *
 * @param orientation if vertical, breadth = width and length = height;
 *                    if horizontal, breadth = height and length = width
 */
public SizeTracker(
        OrientationHelper orientation,
        ObservableObjectValue<Bounds> viewportBounds,
        MemoizationList<? extends Cell<?, ?>> lazyCells) {
    this.orientation = orientation;
    this.viewportBounds = viewportBounds;
    this.cells = lazyCells;
    this.breadths = lazyCells.map(orientation::minBreadth).memoize();
    this.maxKnownMinBreadth = breadths.memoizedItems()
            .reduce(Math::max)
            .orElseConst(0.0);
    this.breadthForCells = Val.combine(
            maxKnownMinBreadth,
            viewportBounds,
            (a, b) -> Math.max(a, orientation.breadth(b)));

    Val<Function<Cell<?, ?>, Double>> lengthFn = avoidFalseInvalidations(breadthForCells).map(
            breadth -> cell -> orientation.prefLength(cell, breadth));

    this.lengths = cells.mapDynamic(lengthFn).memoize();

    LiveList<Double> knownLengths = this.lengths.memoizedItems();
    Val<Double> sumOfKnownLengths = knownLengths.reduce((a, b) -> a + b).orElseConst(0.0);
    Val<Integer> knownLengthCount = knownLengths.sizeProperty();

    this.averageLengthEstimate = Val.create(
            () -> {
                // make sure to use pref lengths of all present cells
                for(int i = 0; i < cells.getMemoizedCount(); ++i) {
                    int j = cells.indexOfMemoizedItem(i);
                    lengths.force(j, j + 1);
                }

                int count = knownLengthCount.getValue();
                return count == 0
                        ? null
                        : sumOfKnownLengths.getValue() / count;
            },
            sumOfKnownLengths, knownLengthCount);

    this.totalLengthEstimate = Val.combine(
            averageLengthEstimate, cells.sizeProperty(),
            (avg, n) -> n * avg);

    Val<Integer> firstVisibleIndex = Val.create(
            () -> cells.getMemoizedCount() == 0 ? null : cells.indexOfMemoizedItem(0),
            cells, cells.memoizedItems()); // need to observe cells.memoizedItems()
            // as well, because they may change without a change in cells.

    Val<? extends Cell<?, ?>> firstVisibleCell = cells.memoizedItems()
            .collapse(visCells -> visCells.isEmpty() ? null : visCells.get(0));

    Val<Integer> knownLengthCountBeforeFirstVisibleCell = Val.create(() -> {
        return firstVisibleIndex.getOpt()
                .map(i -> lengths.getMemoizedCountBefore(Math.min(i, lengths.size())))
                .orElse(0);
    }, lengths, firstVisibleIndex);

    Val<Double> totalKnownLengthBeforeFirstVisibleCell = knownLengths.reduceRange(
            knownLengthCountBeforeFirstVisibleCell.map(n -> new IndexRange(0, n)),
            (a, b) -> a + b).orElseConst(0.0);

    Val<Double> unknownLengthEstimateBeforeFirstVisibleCell = Val.combine(
            firstVisibleIndex,
            knownLengthCountBeforeFirstVisibleCell,
            averageLengthEstimate,
            (firstIdx, knownCnt, avgLen) -> (firstIdx - knownCnt) * avgLen);

    Val<Double> firstCellMinY = firstVisibleCell.flatMap(orientation::minYProperty);

    lengthOffsetEstimate = Val.combine(
            totalKnownLengthBeforeFirstVisibleCell,
            unknownLengthEstimateBeforeFirstVisibleCell,
            firstCellMinY,
            (a, b, minY) -> a + b - minY).orElseConst(0.0);

    // pinning totalLengthEstimate and lengthOffsetEstimate
    // binds it all together and enables memoization
    this.subscription = Subscription.multi(
            totalLengthEstimate.pin(),
            lengthOffsetEstimate.pin());
}
 
Example #10
Source File: IndicatorBox.java    From TAcharting with GNU Lesser General Public License v2.1 votes vote down vote up
ObservableObjectValue<TaBarSeries> getObservableBarSeries();