Java Code Examples for javafx.collections.FXCollections#observableHashMap()

The following examples show how to use javafx.collections.FXCollections#observableHashMap() . 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: ReadOnlyMapWrapperExTests.java    From gef with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void readOnlyWrapperChangeNotifications() {
	ReadOnlyMapWrapperEx<String, Integer> mapWrapper = new ReadOnlyMapWrapperEx<>(
			FXCollections.observableHashMap());
	ReadOnlyMapProperty<String, Integer> roProperty = mapWrapper
			.getReadOnlyProperty();
	MapChangeExpector<String, Integer> mapChangeListener = new MapChangeExpector<>(
			roProperty);
	roProperty.addListener(mapChangeListener);
	mapChangeListener.addExpectation("key1", null, 1);
	roProperty.put("key1", 1);
	mapChangeListener.check();
	mapChangeListener.addExpectation("key2", null, 2);
	roProperty.put("key2", 2);
	mapChangeListener.check();
	mapChangeListener.addExpectation("key1", 1, null);
	roProperty.remove("key1");
	mapChangeListener.check();
	mapChangeListener.addExpectation("key2", 2, null);
	roProperty.remove("key2");
	mapChangeListener.check();
}
 
Example 2
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 3
Source File: ContainersFeaturePanel.java    From phoenicis with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Constructor
 */
public ContainersFeaturePanel() {
    super();

    this.filter = new SimpleObjectProperty<>();
    this.javaFxSettingsManager = new SimpleObjectProperty<>();
    this.categories = FXCollections.observableArrayList();
    this.containersManager = new SimpleObjectProperty<>();
    this.enginesManager = new SimpleObjectProperty<>();
    this.verbsManager = new SimpleObjectProperty<>();
    this.engineToolsManager = new SimpleObjectProperty<>();
    this.engineSettings = FXCollections.observableHashMap();
    this.verbs = FXCollections.observableHashMap();
    this.engineTools = FXCollections.observableHashMap();
    this.selectedContainer = new SimpleObjectProperty<>();
    this.openedDetailsPanel = new SimpleObjectProperty<>(new None());
}
 
Example 4
Source File: ShortcutInformationPanelSkin.java    From phoenicis with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Constructor
 *
 * @param control The control belonging to the skin
 */
public ShortcutInformationPanelSkin(ShortcutInformationPanel control) {
    super(control);

    this.description = StringBindings.map(getControl().shortcutProperty(),
            shortcut -> shortcut.getInfo().getDescription());

    this.shortcutProperties = CollectionBindings.mapToMap(getControl().shortcutProperty(), shortcut -> {
        try {
            return getControl().getObjectMapper()
                    .readValue(shortcut.getScript(), new TypeReference<Map<String, Object>>() {
                        // nothing
                    });
        } catch (IOException e) {
            LOGGER.error("An error occurred during a shortcut update", e);

            return Map.of();
        }
    });

    this.environmentAttributes = FXCollections.observableHashMap();
}
 
Example 5
Source File: ShortcutEditingPanelSkin.java    From phoenicis with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Constructor
 *
 * @param control The control belonging to the skin
 */
public ShortcutEditingPanelSkin(ShortcutEditingPanel control) {
    super(control);

    this.description = StringBindings.map(getControl().shortcutProperty(),
            shortcut -> shortcut.getInfo().getDescription());

    this.shortcutProperties = CollectionBindings.mapToMap(getControl().shortcutProperty(), shortcut -> {
        try {
            return getControl().getObjectMapper()
                    .readValue(shortcut.getScript(), new TypeReference<Map<String, Object>>() {
                        // nothing
                    });
        } catch (IOException e) {
            LOGGER.error("An error occurred during a shortcut update", e);

            return Map.of();
        }
    });

    this.environmentAttributes = FXCollections.observableHashMap();
}
 
Example 6
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 7
Source File: RadialBargraph.java    From Enzo with Apache License 2.0 5 votes vote down vote up
public RadialBargraph() {
    getStyleClass().add("radial-bargraph");
    _value                   = 0;
    _oldValue                = 0;
    _minValue                = 0;
    _maxValue                = 100;
    _threshold               = 50;
    _thresholdVisible        = false;
    _minMeasuredValue        = 100;
    _minMeasuredValueVisible = false;
    _maxMeasuredValue        = 0;
    _maxMeasuredValueVisible = false;
    _decimals                = 1;
    _title                   = "";
    _unit                    = "";
    _animated                = true;
    _startAngle              = 320;
    _angleRange              = 280;
    _clockwise               = true;
    _autoScale               = false;
    _barColor                = Color.rgb(248, 202, 0);
    _barGradient             = FXCollections.observableArrayList();
    _barGradientEnabled      = false;
    _numberFormat            = NumberFormat.STANDARD;
    sections                 = FXCollections.observableArrayList();
    _sectionsVisible         = true;
    markers                  = FXCollections.observableHashMap();
    _markersVisible          = true;
    _majorTickSpace          = 10;
    _minorTickSpace          = 1;
    animationDuration        = 800;
    _plainValue              = false;
}
 
Example 8
Source File: RadialMenu.java    From Enzo with Apache License 2.0 5 votes vote down vote up
public RadialMenu(final Options OPTIONS, final List<MenuItem> ITEMS) {
    options               = OPTIONS;
    items                 = FXCollections.observableHashMap();
    getStylesheets().add(getClass().getResource("radialmenu.css").toExternalForm());
    getStyleClass().addAll("radial-menu");
    state                 = new SimpleObjectProperty<>(this, "state", State.CLOSED);
    degrees               = Math.max(Math.min(360, options.getDegrees()), 0);
    cross                 = new Group();
    firstTime             = true;
    initHandler();
    initMainButton();
    initMenuItems(ITEMS);
    initGraphics();
    registerListeners();
}
 
Example 9
Source File: PreferencesViewModelTest.java    From bisq with GNU Affero General Public License v3.0 3 votes vote down vote up
@Test
public void getArbitrationLanguages() {

    RefundAgentManager refundAgentManager = mock(RefundAgentManager.class);

    final ObservableMap<NodeAddress, RefundAgent> refundAgents = FXCollections.observableHashMap();

    ArrayList<String> languagesOne = new ArrayList<>() {{
        add("en");
        add("de");
    }};

    ArrayList<String> languagesTwo = new ArrayList<>() {{
        add("en");
        add("es");
    }};

    RefundAgent one = new RefundAgent(new NodeAddress("refundAgent:1"), null, languagesOne, 0L,
            null, null, null, null, null);

    RefundAgent two = new RefundAgent(new NodeAddress("refundAgent:2"), null, languagesTwo, 0L,
            null, null, null, null, null);

    refundAgents.put(one.getNodeAddress(), one);
    refundAgents.put(two.getNodeAddress(), two);

    Preferences preferences = PreferenceMakers.empty;

    when(refundAgentManager.getObservableMap()).thenReturn(refundAgents);

    PreferencesViewModel model = new PreferencesViewModel(preferences, refundAgentManager, null);

    assertEquals("English, Deutsch, español", model.getArbitrationLanguages());
}
 
Example 10
Source File: PreferencesViewModelTest.java    From bisq with GNU Affero General Public License v3.0 3 votes vote down vote up
@Test
public void getMediationLanguages() {

    MediatorManager mediationManager = mock(MediatorManager.class);

    final ObservableMap<NodeAddress, Mediator> mnediators = FXCollections.observableHashMap();

    ArrayList<String> languagesOne = new ArrayList<>() {{
        add("en");
        add("de");
    }};

    ArrayList<String> languagesTwo = new ArrayList<>() {{
        add("en");
        add("es");
    }};

    Mediator one = new Mediator(new NodeAddress("refundAgent:1"), null, languagesOne, 0L,
            null, null, null, null, null);

    Mediator two = new Mediator(new NodeAddress("refundAgent:2"), null, languagesTwo, 0L,
            null, null, null, null, null);

    mnediators.put(one.getNodeAddress(), one);
    mnediators.put(two.getNodeAddress(), two);

    Preferences preferences = PreferenceMakers.empty;

    when(mediationManager.getObservableMap()).thenReturn(mnediators);

    PreferencesViewModel model = new PreferencesViewModel(preferences, null, mediationManager);

    assertEquals("English, Deutsch, español", model.getMediationLanguages());
}