javafx.beans.InvalidationListener Java Examples

The following examples show how to use javafx.beans.InvalidationListener. 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: SessionManager.java    From mokka7 with Eclipse Public License 1.0 6 votes vote down vote up
public void bind(final ToggleGroup toggleGroup, final String propertyName) {
    try {
        String value = props.getProperty(propertyName);
        if (value != null) {
            int selectedToggleIndex = Integer.parseInt(value);
            toggleGroup.selectToggle(toggleGroup.getToggles().get(selectedToggleIndex));
        }
    } catch (Exception ignored) {
    }
    toggleGroup.selectedToggleProperty().addListener(new InvalidationListener() {

        @Override
        public void invalidated(Observable o) {
            if (toggleGroup.getSelectedToggle() == null) {
                props.remove(propertyName);
            } else {
                props.setProperty(propertyName, Integer.toString(toggleGroup.getToggles().indexOf(toggleGroup.getSelectedToggle())));
            }
        }
    });
}
 
Example #2
Source File: HighlightOptions.java    From LogFX with GNU General Public License v3.0 6 votes vote down vote up
Row( String pattern, Paint backgroundColor, Paint fillColor, boolean isFiltered ) {
    setSpacing( 5 );

    expressionField = new TextField( pattern );
    expressionField.setMinWidth( 300 );
    expressionField.setTooltip( new Tooltip( "Enter a regular expression." ) );

    bkgColorPicker = new ColorChooser( backgroundColor.toString(), "Enter the background color." );
    fillColorPicker = new ColorChooser( fillColor.toString(), "Enter the text color." );

    isFilteredBox = new CheckBox();
    isFilteredBox.setSelected( isFiltered );
    isFilteredBox.setTooltip( new Tooltip( "Include in filter" ) );

    InvalidationListener updater = ( ignore ) ->
            update( bkgColorPicker.getColor(), fillColorPicker.getColor(), isFilteredBox.selectedProperty().get() );

    bkgColorPicker.addListener( updater );
    fillColorPicker.addListener( updater );
    isFilteredBox.selectedProperty().addListener( updater );
    expressionField.textProperty().addListener( updater );

    setMinWidth( 500 );
}
 
Example #3
Source File: ActionsDialog.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
/** @return Sub-pane for OpenWeb action */
private GridPane createOpenWebDetails()
{
    final InvalidationListener update = whatever ->
    {
        if (updating  ||  selected_action_index < 0)
            return;
        actions.set(selected_action_index, getOpenWebAction());
    };

    final GridPane open_web_details = new GridPane();
    open_web_details.setHgap(10);
    open_web_details.setVgap(10);

    open_web_details.add(new Label(Messages.ActionsDialog_Description), 0, 0);
    open_web_description.textProperty().addListener(update);
    open_web_details.add(open_web_description, 1, 0);
    GridPane.setHgrow(open_web_description, Priority.ALWAYS);

    open_web_details.add(new Label(Messages.ActionsDialog_URL), 0, 1);
    open_web_url.textProperty().addListener(update);
    open_web_details.add(open_web_url, 1, 1);

    return open_web_details;
}
 
Example #4
Source File: SpriteView.java    From quantumjava with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public Lamb(SpriteView following) {
    super(LAMB, following);
    direction.addListener(directionListener);
    directionListener.changed(direction, direction.getValue(), direction.getValue());
    startValueAnimation();
    valueProperty.addListener(new InvalidationListener() {
        @Override
        public void invalidated(Observable observable) {
            double value = valueProperty.get();
            if (value > .5){
                imageView.setEffect(new InnerShadow(150, Color.BLACK));
            } else {
                imageView.setEffect(null);
            }
        }
    });
}
 
Example #5
Source File: SetListenerHelperEx.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Notifies all registered {@link InvalidationListener}s.
 */
protected void notifyInvalidationListeners() {
	if (invalidationListeners != null) {
		try {
			lockInvalidationListeners = true;
			for (InvalidationListener l : invalidationListeners) {
				try {
					l.invalidated(source);
				} catch (Exception e) {
					Thread.currentThread().getUncaughtExceptionHandler()
							.uncaughtException(Thread.currentThread(), e);
				}
			}
		} finally {
			lockInvalidationListeners = false;
		}
	}
}
 
Example #6
Source File: StartPresenter.java    From gluon-samples with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void showResult (StringProperty answer) {
      MATCH_VIEW.switchView();
        Optional<Object> presenter = MATCH_VIEW.getPresenter();
        MatchPresenter p = (MatchPresenter) presenter.get();
        p.setResult(-1);
        answer.addListener(new InvalidationListener() {
            @Override
            public void invalidated(Observable o) {
                String astring = answer.get();
                System.out.println("got answer: "+astring);
                if (astring != null) {
                    p.setResult(Integer.valueOf(astring));
                }
            }
        });
        if (answer.get() != null) {
            p.setResult(Integer.valueOf(answer.get()));
        }
}
 
Example #7
Source File: ListListenerHelperEx.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Notifies all registered {@link InvalidationListener}s.
 */
protected void notifyInvalidationListeners() {
	if (invalidationListeners != null) {
		try {
			lockInvalidationListeners = true;
			for (InvalidationListener l : invalidationListeners) {
				try {
					l.invalidated(source);
				} catch (Exception e) {
					Thread.currentThread().getUncaughtExceptionHandler()
							.uncaughtException(Thread.currentThread(), e);
				}
			}
		} finally {
			lockInvalidationListeners = false;
		}
	}
}
 
Example #8
Source File: MultisetListenerHelper.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Adds a new {@link InvalidationListener} to this
 * {@link MultisetListenerHelper}. If the same listener is added more than
 * once, it will be registered more than once and will receive multiple
 * change events.
 *
 * @param listener
 *            The listener to add.
 */
public void addListener(InvalidationListener listener) {
	if (invalidationListeners == null) {
		invalidationListeners = new ArrayList<>();
	}
	// XXX: Prevent ConcurrentModificationExceptions (in case listeners are
	// added during notifications); as we only create a new multi-set in the
	// locked case, memory should not be waisted.
	if (lockInvalidationListeners) {
		invalidationListeners = new ArrayList<>(invalidationListeners);
	}
	invalidationListeners.add(listener);
}
 
Example #9
Source File: ListListenerHelperEx.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Adds a new {@link InvalidationListener} to this
 * {@link ListListenerHelperEx}. If the same listener is added more than
 * once, it will be registered more than once and will receive multiple
 * change events.
 *
 * @param listener
 *            The listener to add.
 */
public void addListener(InvalidationListener listener) {
	if (invalidationListeners == null) {
		invalidationListeners = new ArrayList<>();
	}
	// XXX: Prevent ConcurrentModificationExceptions (in case listeners are
	// added during notifications); as we only create a new multi-set in the
	// locked case, memory should not be waisted.
	if (lockInvalidationListeners) {
		invalidationListeners = new ArrayList<>(invalidationListeners);
	}
	invalidationListeners.add(listener);
}
 
Example #10
Source File: SetListenerHelperEx.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Removes the given {@link InvalidationListener} from this
 * {@link SetListenerHelperEx}. If its was registered more than once,
 * removes one occurrence.
 *
 * @param listener
 *            The listener to remove.
 */
public void removeListener(InvalidationListener listener) {
	if (invalidationListeners == null) {
		return;
	}

	// XXX: Prevent ConcurrentModificationExceptions (in case listeners are
	// added during notifications); as we only create a new multi-set in the
	// locked case, memory should not be waisted.
	if (lockInvalidationListeners) {
		invalidationListeners = new ArrayList<>(invalidationListeners);
	}

	// XXX: We have to ignore the hash code when removing listeners, as
	// otherwise unbinding will be broken (JavaFX bindings violate the
	// contract between equals() and hashCode(): JI-9028554); remove() may
	// thus not be used.
	for (Iterator<InvalidationListener> iterator = invalidationListeners
			.iterator(); iterator.hasNext();) {
		if (iterator.next().equals(listener)) {
			iterator.remove();
			break;
		}
	}
	if (invalidationListeners.isEmpty()) {
		invalidationListeners = null;
	}
}
 
Example #11
Source File: PropertyTracker.java    From scenic-view with GNU General Public License v3.0 5 votes vote down vote up
public PropertyTracker() {
    propListener = new InvalidationListener() {
        @Override public void invalidated(final Observable property) {
            updateDetail(properties.get(property), (ObservableValue) property);
        }
    };
}
 
Example #12
Source File: PeriodicScreenCapture.java    From chart-fx with Apache License 2.0 5 votes vote down vote up
@Override
public void addListener(final InvalidationListener listener) {
    Objects.requireNonNull(listener, "InvalidationListener must not be null");
    // N.B. suppress duplicates
    if (!listeners.contains(listener)) {
        listeners.add(listener);
    }
}
 
Example #13
Source File: MapTile.java    From maps with GNU General Public License v3.0 5 votes vote down vote up
MapTile(BaseMap baseMap, int nearestZoom, long i, long j) {
        this.baseMap = baseMap;
        this.myZoom = nearestZoom;
        this.i = i;
        this.j = j;
        scale.setPivotX(0);
        scale.setPivotY(0);
        getTransforms().add(scale);
        debug("[JVDBG] load image [" + myZoom + "], i = " + i + ", j = " + j);

        ImageView imageView = new ImageView();
        imageView.setMouseTransparent(true);
        Image tile = TILE_RETRIEVER.loadTile(myZoom, i, j);
        imageView.setImage(tile);
        this.progress = tile.progressProperty();

//        Label l = new Label("Tile [" + myZoom + "], i = " + i + ", j = " + j);
        getChildren().addAll(imageView);//,l);
        this.progress.addListener(new InvalidationListener() {
            @Override
            public void invalidated(Observable observable) {
                if (progress.get() >= 1.0d) {
                    debug("[JVDBG] got image [" + myZoom + "], i = " + i + ", j = " + j);
                    setNeedsLayout(true);
                    progress.removeListener(this);
                }
            }
        });
        baseMap.zoom().addListener(new WeakInvalidationListener(zl));
        baseMap.translateXProperty().addListener(new WeakInvalidationListener(zl));
        baseMap.translateYProperty().addListener(new WeakInvalidationListener(zl));
        calculatePosition();
        this.setMouseTransparent(true);
    }
 
Example #14
Source File: JFXNodeUtils.java    From JFoenix with Apache License 2.0 5 votes vote down vote up
public static <T> InvalidationListener addDelayedPropertyInvalidationListener(ObservableValue<T> property,
                                                                              Duration delayTime,
                                                                              Consumer<T> justInTimeConsumer,
                                                                              Consumer<T> delayedConsumer) {
    Wrapper<T> eventWrapper = new Wrapper<>();
    PauseTransition holdTimer = new PauseTransition(delayTime);
    holdTimer.setOnFinished(event -> delayedConsumer.accept(eventWrapper.content));
    final InvalidationListener invalidationListener = observable -> {
        eventWrapper.content = property.getValue();
        justInTimeConsumer.accept(eventWrapper.content);
        holdTimer.playFromStart();
    };
    property.addListener(invalidationListener);
    return invalidationListener;
}
 
Example #15
Source File: ListListenerHelperEx.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Removes the given {@link InvalidationListener} from this
 * {@link ListListenerHelperEx}. If its was registered more than once,
 * removes one occurrence.
 *
 * @param listener
 *            The listener to remove.
 */
public void removeListener(InvalidationListener listener) {
	if (invalidationListeners == null) {
		return;
	}

	// XXX: Prevent ConcurrentModificationExceptions (in case listeners are
	// added during notifications); as we only create a new multi-set in the
	// locked case, memory should not be waisted.
	if (lockInvalidationListeners) {
		invalidationListeners = new ArrayList<>(invalidationListeners);
	}

	// XXX: We have to ignore the hash code when removing listeners, as
	// otherwise unbinding will be broken (JavaFX bindings violate the
	// contract between equals() and hashCode(): JI-9028554); remove() may
	// thus not be used.
	for (Iterator<InvalidationListener> iterator = invalidationListeners
			.iterator(); iterator.hasNext();) {
		if (iterator.next().equals(listener)) {
			iterator.remove();
			break;
		}
	}
	if (invalidationListeners.isEmpty()) {
		invalidationListeners = null;
	}
}
 
Example #16
Source File: WorldRendererCanvas.java    From BlockMap with MIT License 5 votes vote down vote up
public WorldRendererCanvas() {
	{// Executor
		executor = (ThreadPoolExecutor) Executors.newFixedThreadPool(THREAD_COUNT);
		executor.setKeepAliveTime(20, TimeUnit.SECONDS);
		executor.allowCoreThreadTimeOut(true);
	}

	progress.addListener(e -> repaint());

	this.regionFolder.addListener((obs, prev, val) -> {
		if (val == null || val.listRegions().isEmpty()) {
			map = null;
			status.set("No regions loaded");
			chunkMetadata.unbind();
			chunkMetadata.clear();
		} else {
			map = new RenderedMap(val, executor, viewport.mouseWorldProperty);
			map.getCurrentlyRendering().addListener((InvalidationListener) e -> repaint());
			progress.bind(map.getProgress());
			chunkMetadata.bind(map.getChunkMetadata());
			status.set("Rendering");
			executor.execute(() -> Platform.runLater(() -> status.set("Done")));
		}
		repaint();
	});
	this.regionFolder.set(null);

	viewport.widthProperty.bind(widthProperty());
	viewport.heightProperty.bind(heightProperty());
	viewport.frustumProperty.addListener(e -> repaint());

	repaint();
}
 
Example #17
Source File: SegmentMeshInfos.java    From paintera with GNU General Public License v2.0 5 votes vote down vote up
public SegmentMeshInfos(
		final SelectedSegments selectedSegments,
		final MeshManagerWithAssignmentForSegments meshManager,
		final ManagedMeshSettings meshSettings,
		final int numScaleLevels)
{
	super();

	this.meshSettings = meshSettings;
	this.numScaleLevels = numScaleLevels;

	final InvalidationListener updateMeshInfosHandler = obs -> {
		final long[] segments = selectedSegments.getSelectedSegmentsCopyAsArray();
		final List<SegmentMeshInfo> infos = Arrays
				.stream(segments)
				.mapToObj(id -> {
					final MeshSettings settings = meshSettings.getOrAddMesh(id, true);
					return new SegmentMeshInfo(
							id,
							settings,
							meshSettings.isManagedProperty(id),
							selectedSegments.getAssignment(),
							meshManager);
				})
				.collect(Collectors.toList());
		this.infos.setAll(infos);
	};

	meshManager.getMeshUpdateObservable().addListener(updateMeshInfosHandler);
	meshSettings.isMeshListEnabledProperty().addListener(updateMeshInfosHandler);
}
 
Example #18
Source File: ObservableAtomicReferenceTest.java    From pdfsam with GNU Affero General Public License v3.0 5 votes vote down vote up
@Test
public void listeners() {
    ObservableAtomicReference<String> victim = new ObservableAtomicReference<>("Initial");
    ChangeListener<String> listener = mock(ChangeListener.class);
    InvalidationListener invalidationListener = mock(InvalidationListener.class);
    victim.addListener(listener);
    victim.addListener(invalidationListener);
    victim.set("newVal");
    assertEquals("newVal", victim.getValue());
    verify(listener).changed(any(), eq("Initial"), eq("newVal"));
    verify(invalidationListener).invalidated(victim);
}
 
Example #19
Source File: ReadOnlySetMultimapWrapper.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void addListener(InvalidationListener listener) {
	if (helper == null) {
		helper = new SetMultimapExpressionHelper<>(this);
	}
	helper.addListener(listener);
}
 
Example #20
Source File: ReadOnlyListWrapperEx.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void addListener(InvalidationListener listener) {
	if (helper == null) {
		helper = new ListExpressionHelperEx<>(this);
	}
	helper.addListener(listener);
}
 
Example #21
Source File: ActionsDialog.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
/** @return Sub-pane for WritePV action */
private GridPane createWritePVDetails()
{
    final InvalidationListener update = whatever ->
    {
        if (updating  ||  selected_action_index < 0)
            return;
        actions.set(selected_action_index, getWritePVAction());
    };

    final GridPane write_pv_details = new GridPane();
    write_pv_details.setHgap(10);
    write_pv_details.setVgap(10);

    write_pv_details.add(new Label(Messages.ActionsDialog_Description), 0, 0);
    write_pv_description.textProperty().addListener(update);
    write_pv_details.add(write_pv_description, 1, 0);
    GridPane.setHgrow(write_pv_description, Priority.ALWAYS);

    write_pv_details.add(new Label(Messages.ActionsDialog_PVName), 0, 1);
    PVAutocompleteMenu.INSTANCE.attachField(write_pv_name);
    write_pv_name.textProperty().addListener(update);
    write_pv_details.add(write_pv_name, 1, 1);

    write_pv_details.add(new Label(Messages.ActionsDialog_Value), 0, 2);
    write_pv_value.textProperty().addListener(update);
    write_pv_details.add(write_pv_value, 1, 2);

    return write_pv_details;
}
 
Example #22
Source File: ReadOnlyListPropertyBaseEx.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void addListener(InvalidationListener listener) {
	if (helper == null) {
		helper = new ListExpressionHelperEx<>(this);
	}
	helper.addListener(listener);
}
 
Example #23
Source File: ProcView.java    From erlyberly with GNU General Public License v3.0 5 votes vote down vote up
private void initialiseProcessSorting() {
    InvalidationListener invalidationListener = new ProcSortUpdater();

    for (TableColumn<ProcInfo, ?> col : processView.getColumns()) {
        col.sortTypeProperty().addListener(invalidationListener);
    }

    processView.getSortOrder().addListener(invalidationListener);
}
 
Example #24
Source File: EventStreams.java    From ReactFX with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Creates an event stream that emits an impulse on every invalidation
 * of the given observable.
 */
public static EventStream<Void> invalidationsOf(Observable observable) {
    return new EventStreamBase<Void>() {
        @Override
        protected Subscription observeInputs() {
            InvalidationListener listener = obs -> emit(null);
            observable.addListener(listener);
            return () -> observable.removeListener(listener);
        }
    };
}
 
Example #25
Source File: MapTile.java    From maps with GNU General Public License v3.0 5 votes vote down vote up
/**
     * This tile is covering for the child tile that is still being loaded.
     *
     * @param child
     */
    void addCovering(MapTile child) {
        coveredTiles.add(child);
        InvalidationListener il = createProgressListener(child);
//        System.out.println("We have to cover, add "+il);
        child.progress.addListener(il);
        calculatePosition();
    }
 
Example #26
Source File: Controller.java    From xdat_editor with MIT License 5 votes vote down vote up
private TreeView<Object> createTreeView(Field listField, ObservableValue<String> filter) {
    TreeView<Object> elements = new TreeView<>();
    elements.setCellFactory(param -> new TreeCell<Object>() {
        @Override
        protected void updateItem(Object item, boolean empty) {
            super.updateItem(item, empty);

            if (item == null || empty) {
                setText(null);
                setGraphic(null);
            } else {
                setText(item.toString());
                if (UIEntity.class.isAssignableFrom(item.getClass())) {
                    try (InputStream is = getClass().getResourceAsStream("/acmi/l2/clientmod/xdat/nodeicons/" + UI_NODE_ICONS.getOrDefault(item.getClass().getSimpleName(), UI_NODE_ICON_DEFAULT))) {
                        setGraphic(new ImageView(new Image(is)));
                    } catch (IOException ignore) {}
                }
            }
        }
    });
    elements.setShowRoot(false);
    elements.setContextMenu(createContextMenu(elements));

    InvalidationListener treeInvalidation = (observable) -> buildTree(editor.xdatObjectProperty().get(), listField, elements, filter.getValue());
    editor.xdatObjectProperty().addListener(treeInvalidation);
    xdatListeners.add(treeInvalidation);

    filter.addListener(treeInvalidation);

    return elements;
}
 
Example #27
Source File: BoardPresenter.java    From Game2048FX with GNU General Public License v3.0 5 votes vote down vote up
private void updateList() {
    AppBar appBar = getApp().getAppBar();
    appBar.setProgress(-1);
    appBar.setProgressBarVisible(true);
    scores = cloud.updateLeaderboard();
    scores.addListener((ListChangeListener.Change<? extends Score> c) -> {
        while (c.next()) {
            if (c.wasAdded() && ! c.getAddedSubList().isEmpty()) {
                Platform.runLater(() -> scoreBoardDay.getSelectionModel().select(c.getAddedSubList().get(0)));
            }
        }
    });
    if (scores.isInitialized()) {
        scoreBoardDay.setItems(new SortedList<>(scores, COMPARATOR));
        appBar.setProgress(1);
        appBar.setProgressBarVisible(false);
    } else {
        scores.initializedProperty().addListener(new InvalidationListener() {
            @Override
            public void invalidated(Observable observable) {
                if (scores.isInitialized()) {
                    scoreBoardDay.setItems(new SortedList<>(scores, COMPARATOR));
                    appBar.setProgress(1);
                    appBar.setProgressBarVisible(false);
                    scores.initializedProperty().removeListener(this);
                }
            }
        });
    }
}
 
Example #28
Source File: ObservableListWrapperEx.java    From gef with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public void addListener(InvalidationListener listener) {
	helper.addListener(listener);
}
 
Example #29
Source File: StringTable.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void removeListener(final InvalidationListener listener)
{
    invalid_listeners.remove(listener);
}
 
Example #30
Source File: Book.java    From AudioBookConverter with GNU General Public License v2.0 4 votes vote down vote up
public void addListener(InvalidationListener listener) {
    this.listener = listener;
}