javafx.collections.ObservableMap Java Examples

The following examples show how to use javafx.collections.ObservableMap. 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: MeshGeneratorJobManager.java    From paintera with GNU General Public License v2.0 6 votes vote down vote up
public MeshGeneratorJobManager(
		final int numScaleLevels,
		final T identifier,
		final ObservableMap<ShapeKey<T>, Pair<MeshView, Node>> meshesAndBlocks,
		final Pair<Group, Group> meshesAndBlocksGroups,
		final MeshViewUpdateQueue<T> meshViewUpdateQueue,
		final GetBlockListFor<T> getBlockLists,
		final GetMeshFor<T> getMeshes,
		final IntFunction<AffineTransform3D> unshiftedWorldTransforms,
		final ExecutorService managers,
		final HashPriorityQueueBasedTaskExecutor<MeshWorkerPriority> workers,
		final IndividualMeshProgress meshProgress)
{
	this.identifier = identifier;
	this.meshesAndBlocks = meshesAndBlocks;
	this.meshesAndBlocksGroups = meshesAndBlocksGroups;
	this.meshViewUpdateQueue = meshViewUpdateQueue;
	this.getBlockLists = getBlockLists;
	this.getMeshes = getMeshes;
	this.unshiftedWorldTransforms = unshiftedWorldTransforms;
	this.managers = managers;
	this.workers = workers;
	this.numScaleLevels = numScaleLevels;
	this.meshesAndBlocks.addListener(this::handleMeshListChange);
	this.meshProgress = meshProgress;
}
 
Example #2
Source File: ReactfxUtil.java    From pmd-designer with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static <K, V> Val<Map<K, V>> observableMapVal(ObservableMap<K, V> map) {
    return new ValBase<Map<K, V>>() {

        @Override
        protected Subscription connect() {
            MapChangeListener<K, V> listener = ch -> notifyObservers(new HashMap<>(map));
            map.addListener(listener);
            return () -> map.removeListener(listener);
        }

        @Override
        protected Map<K, V> computeValue() {
            return new HashMap<>(map);
        }
    };
}
 
Example #3
Source File: ContainersController.java    From phoenicis with GNU Lesser General Public License v3.0 6 votes vote down vote up
private void updateEngineSettings(RepositoryDTO repositoryDTO) {
    this.engineSettingsManager.fetchAvailableEngineSettings(repositoryDTO,
            engineSettings -> Platform.runLater(() -> {
                final ObservableMap<String, List<EngineSetting>> engineSettingsMap = this.containersView
                        .getEngineSettings();

                engineSettingsMap.clear();
                engineSettingsMap.putAll(engineSettings);
            }),
            e -> Platform.runLater(() -> {
                final ErrorDialog errorDialog = ErrorDialog.builder()
                        .withMessage(tr("Loading engine settings failed."))
                        .withException(e)
                        .withOwner(this.containersView.getScene().getWindow())
                        .build();

                errorDialog.showAndWait();
            }));
}
 
Example #4
Source File: ModularDataModel.java    From mzmine3 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Set the value that is wrapped inside a property
 * 
 * @param <T>
 * @param tclass
 * @param value
 */
default <T extends Property<?>> void set(Class<? extends DataType<T>> tclass, Object value) {
  // type in defined columns?
  if (!getTypes().containsKey(tclass))
    throw new TypeColumnUndefinedException(this, tclass);

  DataType realType = getTypeColumn(tclass);
  Property property = get(realType);
  // lists need to be ObservableList
  if (value instanceof List && !(value instanceof ObservableList))
    property.setValue(FXCollections.observableList((List) value));
  else if (value instanceof Map && !(value instanceof ObservableMap))
    property.setValue(FXCollections.observableMap((Map) value));
  else
    property.setValue(value);
}
 
Example #5
Source File: CollectionBindings.java    From phoenicis with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Maps an {@link ObservableValue<I>} object to an {@link ObservableMap} by applying the given converter function
 * and adding the result to the {@link ObservableMap}.
 * In case the input value is empty, i.e. contains <code>null</code>, the returned {@link ObservableMap} is also
 * empty
 *
 * @param property The input value
 * @param converter The converter function
 * @param <I> The type of the input value
 * @param <O1> The input type of the result map
 * @param <O2> The output type of the result map
 * @return A {@link ObservableMap} containing the converted map
 */
public static <I, O1, O2> ObservableMap<O1, O2> mapToMap(ObservableValue<I> property,
        Function<I, Map<O1, O2>> converter) {
    final ObservableMap<O1, O2> result = FXCollections.observableHashMap();

    final InvalidationListener listener = (Observable invalidation) -> {
        final I input = property.getValue();

        result.clear();

        if (input != null) {
            result.putAll(converter.apply(input));
        }
    };

    // add the listener to the property
    property.addListener(listener);

    // ensure that the result map is initialised correctly
    listener.invalidated(property);

    return result;
}
 
Example #6
Source File: Listeners.java    From SynchronizeFX with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void onChanged(final MapChangeListener.Change<? extends Object, ? extends Object> change) {
    final ObservableMap<?, ?> map = change.getMap();
    if (disabledFor.containsKey(map)) {
        return;
    }
    try {
        final UUID mapId = objectRegistry.getIdOrFail(map);
        final Object key = change.getKey();
        if (change.wasAdded()) {
            final Object value = change.getValueAdded();
            final List<Command> commands = creator.putToMap(mapId, key, value);
            registerListenersOnEverything(key);
            if (value != null) {
                registerListenersOnEverything(value);
            }
            distributeCommands(commands);
        } else {
            distributeCommands(creator.removeFromMap(mapId, key));
        }
    } catch (final SynchronizeFXException e) {
        topology.onError(e);
    }
}
 
Example #7
Source File: MapExpressionHelperEx.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Removes the given {@link ChangeListener} from this
 * {@link MapChangeListener}. If it was registered more than once, removes
 * only one occurrence.
 *
 * @param listener
 *            The {@link ChangeListener} to remove.
 */
public void removeListener(
		ChangeListener<? super ObservableMap<K, V>> listener) {
	// 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 (lockChangeListeners) {
		changeListeners = new ArrayList<>(changeListeners);
	}
	// 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()); remove() may thus not be
	// used.
	for (Iterator<ChangeListener<? super ObservableMap<K, V>>> iterator = changeListeners
			.iterator(); iterator.hasNext();) {
		if (iterator.next().equals(listener)) {
			iterator.remove();
			break;
		}
	}
	if (changeListeners.isEmpty()) {
		changeListeners = null;
	}
}
 
Example #8
Source File: Participant.java    From pikatimer with GNU General Public License v3.0 6 votes vote down vote up
public static ObservableMap<String,String> getAvailableAttributes() {
    ObservableMap<String,String> attribMap = FXCollections.observableMap(new LinkedHashMap() );
    
    attribMap.put("bib", "Bib");
    attribMap.put("first", "First Name");
    attribMap.put("middle", "Middle Name");
    attribMap.put("last", "Last Name");
    attribMap.put("age", "Age");
    attribMap.put("birth","Birthday");
    attribMap.put("sex-gender", "Sex");
    attribMap.put("city", "City");
    attribMap.put("state", "State");
    attribMap.put("zip","Zip Code");
    attribMap.put("country", "Country");
    attribMap.put("status","Status");
    attribMap.put("note","Note");
    attribMap.put("email", "EMail");
    // TODO: routine to add custom attributes based on db lookup
    return attribMap; 
}
 
Example #9
Source File: SessionContext.java    From jfxvnc with Apache License 2.0 5 votes vote down vote up
/**
 * session scope bindings
 * 
 * @return
 */
public ObservableMap<String, Property<?>> getBindings() {
  if (bindings == null) {
    bindings = FXCollections.observableHashMap();
  }
  return bindings;
}
 
Example #10
Source File: DynamicIconSupport.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Adds support changing icons by pressed.
 *
 * @param button the button.
 */
@FxThread
public static void addSupport(@NotNull final ButtonBase button) {

    final EditorConfig editorConfig = EditorConfig.getInstance();
    final CssColorTheme theme = editorConfig.getEnum(PREF_UI_THEME, PREF_DEFAULT_THEME);

    if (!theme.needRepaintIcons()) {
        return;
    }

    final ImageView graphic = (ImageView) button.getGraphic();
    final Image image = graphic.getImage();
    final Image original = FILE_ICON_MANAGER.getOriginal(image);

    final ObservableMap<Object, Object> properties = button.getProperties();
    properties.put(NOT_PRESSED_IMAGE, image);
    properties.put(PRESSED_IMAGE, original);

    button.pressedProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue) {
            graphic.setImage((Image) properties.get(PRESSED_IMAGE));
        } else {
            graphic.setImage((Image) properties.get(NOT_PRESSED_IMAGE));
        }
    });

    if (button.isPressed()) {
        graphic.setImage(original);
    } else {
        graphic.setImage(image);
    }
}
 
Example #11
Source File: SimpleMapPropertyEx.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void addListener(
		ChangeListener<? super ObservableMap<K, V>> listener) {
	if (helper == null) {
		helper = new MapExpressionHelperEx<>(this);
	}
	helper.addListener(listener);
}
 
Example #12
Source File: SimpleMapPropertyEx.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void removeListener(
		ChangeListener<? super ObservableMap<K, V>> listener) {
	if (helper != null) {
		helper.removeListener(listener);
	}
}
 
Example #13
Source File: MapExpressionHelperEx.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Adds a new {@link ChangeListener} to this {@link MapExpressionHelperEx}.
 * 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 {@link ChangeListener} to add.
 */
public void addListener(
		ChangeListener<? super ObservableMap<K, V>> listener) {
	if (changeListeners == null) {
		changeListeners = 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 (lockChangeListeners) {
		changeListeners = new ArrayList<>(changeListeners);
	}
	changeListeners.add(listener);
}
 
Example #14
Source File: AlarmLogSearchJob.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
private AlarmLogSearchJob(RestHighLevelClient client, String pattern, Boolean isNodeTable, ObservableMap<Keys, String> searchParameters,
        Consumer<List<AlarmLogTableType>> alarmMessageHandler, BiConsumer<String, Exception> errorHandler) {
    super();
    this.client = client;
    this.pattern = pattern;
    this.isNodeTable = isNodeTable;
    this.searchParameters = searchParameters;
    this.alarmMessageHandler = alarmMessageHandler;
    this.errorHandler = errorHandler;
    this.objectMapper = new ObjectMapper();
    this.objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
}
 
Example #15
Source File: AlarmLogSearchJob.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
public static Job submit(RestHighLevelClient client, final String pattern, Boolean isNodeTable, ObservableMap<Keys, String> searchParameters,
        final Consumer<List<AlarmLogTableType>> alarmMessageHandler,
        final BiConsumer<String, Exception> errorHandler) {

    return JobManager.schedule("searching alarm log messages for : " + pattern,
            new AlarmLogSearchJob(client, pattern, isNodeTable, searchParameters, alarmMessageHandler, errorHandler));
}
 
Example #16
Source File: PropertyMapModel.java    From pmd-designer with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private static RebindSubscription<PropertyDescriptorSpec> makeDefault(PropertyDescriptorSpec p, ObservableMap<PropertyDescriptorSpec, Var<String>> mapping) {
    return RebindSubscription.make(
        () -> mapping.remove(p),
        addedP -> {
            if (addedP == p) {
                return makeDefault(p, mapping);
            } else {
                mapping.remove(p);
                mapping.put(addedP, defaultedVar(addedP.valueProperty()));
                return makeDefault(addedP, mapping);
            }
        }
    );
}
 
Example #17
Source File: GenericStyledArea.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public ObservableMap<Object, Object> getProperties() {
    try {
        return (ObservableMap<Object, Object>) genericStyledAreaKlass.getMethod("getProperties").invoke(genericStyledArea);
    } catch (NoSuchMethodException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
    }
    return null;
}
 
Example #18
Source File: MapPropertyExTests.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
public void addExpectation(ObservableMap<K, V> oldValue,
		ObservableMap<K, V> newValue) {
	// We check that the reference to the observable value is correct,
	// thus do not copy the passed in values.
	oldValueQueue.addFirst(oldValue);
	newValueQueue.addFirst(newValue);
}
 
Example #19
Source File: ContainersController.java    From phoenicis with GNU Lesser General Public License v3.0 5 votes vote down vote up
private void updateVerbs(RepositoryDTO repositoryDTO) {
    this.verbsManager.fetchAvailableVerbs(repositoryDTO, verbs -> Platform.runLater(() -> {
        final ObservableMap<String, ApplicationDTO> verbsMap = this.containersView.getVerbs();

        verbsMap.clear();
        verbsMap.putAll(verbs);
    }));
}
 
Example #20
Source File: ReadOnlyMapPropertyBaseEx.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void removeListener(
		ChangeListener<? super ObservableMap<K, V>> listener) {
	if (helper != null) {
		helper.removeListener(listener);
	}
}
 
Example #21
Source File: DynamicIconSupport.java    From jmonkeybuilder with Apache License 2.0 5 votes vote down vote up
/**
 * Adds support changing icons by selection.
 *
 * @param button the button.
 */
@FxThread
public static void addSupport(@NotNull final ToggleButton button) {

    final EditorConfig editorConfig = EditorConfig.getInstance();
    final CssColorTheme theme = editorConfig.getEnum(PREF_UI_THEME, PREF_DEFAULT_THEME);

    if (!theme.needRepaintIcons()) {
        return;
    }

    final ImageView graphic = (ImageView) button.getGraphic();
    final Image image = graphic.getImage();
    final Image original = FILE_ICON_MANAGER.getOriginal(image);

    final ObservableMap<Object, Object> properties = button.getProperties();
    properties.put(NOT_SELECTED_IMAGE, image);
    properties.put(SELECTED_IMAGE, original);

    button.selectedProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue) {
            graphic.setImage((Image) properties.get(SELECTED_IMAGE));
        } else {
            graphic.setImage((Image) properties.get(NOT_SELECTED_IMAGE));
        }
    });

    if (button.isSelected()) {
        graphic.setImage(original);
    } else {
        graphic.setImage(image);
    }
}
 
Example #22
Source File: LoadDialog.java    From Animu-Downloaderu with MIT License 5 votes vote down vote up
public static void showDialog(Window owner, String title, Message message) {
	alert = new Alert(AlertType.NONE);
	alert.initOwner(owner);
	alert.setTitle(title);
	ObservableMap<String, String> messages = message.getMessages();
	StringBuilder msg = new StringBuilder();
	messages.forEach((key, value) -> msg.append(String.format("%s\t: %s%n", key, value)));
	alert.getDialogPane().setMinHeight(messages.size() * 30d);
	alert.setContentText(msg.toString());

	// Run with small delay on each change
	messages.addListener((Change<? extends String, ? extends String> change) -> Platform.runLater(() -> {
		StringBuilder msgChange = new StringBuilder();
		messages.forEach((key, value) -> msgChange.append(String.format("%s\t: %s%n", key, value)));
		alert.setContentText(msgChange.toString());
		if (messages.values().stream().allMatch(val -> val.startsWith(Message.processed))) {
			stopDialog();
			message.clearMessages();
		}
	}));

	alert.initModality(Modality.APPLICATION_MODAL);
	alert.getDialogPane().getStylesheets()
			.add(LoadDialog.class.getResource("/css/application.css").toExternalForm());
	// Calculate the center position of the parent Stage
	double centerXPosition = owner.getX() + owner.getWidth() / 2d;
	double centerYPosition = owner.getY() + owner.getHeight() / 2d;

	alert.setOnShowing(e -> {
		alert.setX(centerXPosition - alert.getDialogPane().getWidth() / 2d);
		alert.setY(centerYPosition - alert.getDialogPane().getHeight() / 2d);
	});
	alert.show();
}
 
Example #23
Source File: ReadOnlyMapPropertyBaseEx.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void addListener(
		ChangeListener<? super ObservableMap<K, V>> listener) {
	if (helper == null) {
		helper = new MapExpressionHelperEx<>(this);
	}
	helper.addListener(listener);
}
 
Example #24
Source File: EventStreams.java    From ReactFX with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public static <K, V> EventStream<MapChangeListener.Change<? extends K, ? extends V>> changesOf(ObservableMap<K, V> map) {
    return new EventStreamBase<MapChangeListener.Change<? extends K, ? extends V>>() {
        @Override
        protected Subscription observeInputs() {
            MapChangeListener<K, V> listener = c -> emit(c);
            map.addListener(listener);
            return () -> map.removeListener(listener);
        }
    };
}
 
Example #25
Source File: AbstractAnchor.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public ObservableMap<AnchorKey, Point> getPositionsUnmodifiable() {
	if (positionsUnmodifiable == null) {
		positionsUnmodifiable = FXCollections
				.unmodifiableObservableMap(positions);
	}
	return positionsUnmodifiable;
}
 
Example #26
Source File: ReadOnlyMapWrapperEx.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void removeListener(
		ChangeListener<? super ObservableMap<K, V>> listener) {
	// don't delegate to read-only property (fix for
	// https://bugs.openjdk.java.net/browse/JDK-8089557)
	if (helper != null) {
		helper.removeListener(listener);
	}
}
 
Example #27
Source File: AdaptableSupport.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Retrieves all registered adapters, mapped to the respective
 * {@link AdapterKey}s they are registered.
 *
 * @return An unmodifiable observable map containing the registered adapters
 *         under their {@link AdapterKey}s as a copy.
 */
public ObservableMap<AdapterKey<?>, Object> getAdapters() {
	if (adaptersUnmodifiable == null) {
		adaptersUnmodifiable = FXCollections
				.unmodifiableObservableMap(adapters);
	}
	return adaptersUnmodifiable;
}
 
Example #28
Source File: ContainersFeaturePanelSkin.java    From phoenicis with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Applies the engine settings belonging to the currently selected container to the given
 * {@link ContainerInformationPanel}
 *
 * @param containerInformationPanel The information panel showing the details for the currently selected container
 */
private void updateEngineSettings(final ContainerInformationPanel containerInformationPanel) {
    final ObservableMap<String, List<EngineSetting>> engineSettings = getControl().getEngineSettings();
    final ContainerDTO container = containerInformationPanel.getContainer();

    if (container != null && engineSettings.containsKey(container.getEngine().toLowerCase())) {
        containerInformationPanel.getEngineSettings()
                .setAll(engineSettings.get(container.getEngine().toLowerCase()));
    } else {
        containerInformationPanel.getEngineSettings().clear();
    }
}
 
Example #29
Source File: ReadOnlyMapWrapperEx.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void addListener(
		ChangeListener<? super ObservableMap<K, V>> listener) {
	if (helper == null) {
		helper = new MapExpressionHelperEx<>(this);
	}
	helper.addListener(listener);
}
 
Example #30
Source File: ObservableMapValues.java    From SmartModInserter with GNU Lesser General Public License v3.0 5 votes vote down vote up
public ObservableMapValues(ObservableList<T> internalStore, ObservableMap<?, T> referencedMap) {
    this.internalStore = internalStore;
    this.referencedMap = referencedMap;

    referencedMap.addListener((MapChangeListener<Object, T>) change -> {
        if (change.wasAdded()) {
            internalStore.add(change.getValueAdded());
        }
        if (change.wasRemoved()) {
            internalStore.remove(change.getValueRemoved());
        }
    });
}