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

The following examples show how to use javafx.collections.FXCollections#singletonObservableList() . 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: BindingUtils.java    From gef with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Creates a new {@link ObjectBinding} that contains the values mapped to
 * the specified key.
 *
 * @param setMultimap
 *            The {@link ObservableSetMultimap} from which the values are to
 *            be retrieved.
 * @param <K>
 *            The key type of the {@link ObservableSetMultimap}.
 * @param <V>
 *            The value type of the {@link ObservableSetMultimap}.
 *
 *
 * @param key
 *            the key of the mapping
 * @return A new {@code ObjectBinding}.
 */
public static <K, V> SetBinding<V> valuesAt(
		final ObservableSetMultimap<K, V> setMultimap, final K key) {
	if (setMultimap == null) {
		throw new UnsupportedOperationException(
				"setMultimap may not be null.");
	}

	return new SetBinding<V>() {
		{
			super.bind(setMultimap);
		}

		@Override
		protected ObservableSet<V> computeValue() {
			return FXCollections.observableSet(setMultimap.get(key));
		}

		@Override
		public void dispose() {
			super.unbind(setMultimap);
		}

		@Override
		public ObservableList<?> getDependencies() {
			return FXCollections.singletonObservableList(setMultimap);
		}
	};
}
 
Example 2
Source File: ContainerInformationPanelSkin.java    From phoenicis with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Constructor
 *
 * @param control The control belonging to the skin
 */
public ContainerInformationPanelSkin(ContainerInformationPanel control) {
    super(control);

    // initialise the "Overview" tab
    final ObservableList<Tab> overviewTab = FXCollections.singletonObservableList(createContainerOverviewTab());

    // initialise the "Engine settings" tab
    final ObjectBinding<Tab> engineSettingsBinding = Bindings
            .when(Bindings.isNotEmpty(getControl().getEngineSettings()))
            .then(createContainerEngineSettingsTab()).otherwise(new SimpleObjectProperty<>());
    final ObservableList<Tab> engineSettingsTab = CollectionBindings.mapToList(engineSettingsBinding,
            engineSettings -> Optional.ofNullable(engineSettings).map(List::of).orElse(List.of()));

    // initialise the "Verbs" tab
    final Tab verbsTabInstance = createContainerVerbsTab();
    final ObservableList<Tab> verbsTab = CollectionBindings.mapToList(getControl().verbsProperty(),
            verbs -> verbs != null ? List.of(verbsTabInstance) : List.of());

    // initialise the "Engine tools" tab
    final Tab engineToolsTabInstance = createContainerEngineToolsTab();
    final ObservableList<Tab> engineToolsTab = CollectionBindings.mapToList(getControl().engineToolsProperty(),
            engineTools -> engineTools != null ? List.of(engineToolsTabInstance) : List.of());

    // initialise the "Tools" tab
    final ObservableList<Tab> toolsTab = FXCollections.singletonObservableList(createContainerToolsTab());

    this.concatenatedTabs = ConcatenatedList.create(overviewTab, engineSettingsTab, verbsTab, engineToolsTab,
            toolsTab);
}
 
Example 3
Source File: VirtualFlowTest.java    From Flowless with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void idempotentShowTest() {
    // create VirtualFlow with 1 big cell
    Rectangle rect = new Rectangle(500, 500);
    ObservableList<Rectangle> items = FXCollections.singletonObservableList(rect);
    VirtualFlow<Rectangle, Cell<Rectangle, Rectangle>> vf = VirtualFlow.createVertical(items, Cell::wrapNode);
    vf.resize(100, 100); // size of VirtualFlow less than that of the cell
    vf.layout();

    vf.show(110.0);
    vf.show(110.0);
    vf.layout();
    assertEquals(-10.0, rect.getBoundsInParent().getMinY(), 0.01);
}
 
Example 4
Source File: VirtualFlowTest.java    From Flowless with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Test
public void idempotentSetLengthOffsetTest() {
    // create VirtualFlow with 1 big cell
    Rectangle rect = new Rectangle(500, 500);
    ObservableList<Rectangle> items = FXCollections.singletonObservableList(rect);
    VirtualFlow<Rectangle, Cell<Rectangle, Rectangle>> vf = VirtualFlow.createVertical(items, Cell::wrapNode);
    vf.resize(100, 100); // size of VirtualFlow less than that of the cell
    vf.layout();

    vf.setLengthOffset(10.0);
    vf.setLengthOffset(10.0);
    vf.layout();
    assertEquals(-10.0, rect.getBoundsInParent().getMinY(), 0.01);
}
 
Example 5
Source File: SwitchBinding.java    From phoenicis with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public ObservableList<?> getDependencies() {
    return FXCollections.singletonObservableList(value);
}
 
Example 6
Source File: CSSFX.java    From cssfx with Apache License 2.0 4 votes vote down vote up
/**
 * Start monitoring CSS resources with the config parameters collected until now. 
 * @return a Runnable object to stop CSSFX monitoring
 */
public Runnable start() {
    if (!CSSFXLogger.isInitialized()) {
        if (Boolean.getBoolean("cssfx.log")) {
            LogLevel toActivate = LogLevel.INFO;
            String levelStr = System.getProperty("cssfx.log.level", "INFO");
            try {
                toActivate = LogLevel.valueOf(levelStr);
            } catch (Exception ignore) {
                System.err.println("[CSSFX] invalid value for cssfx.log.level, '" + levelStr + "' is not allowed. Select one in: " + Arrays.asList(LogLevel.values()));
            }
            CSSFXLogger.setLogLevel(toActivate);
            
            String logType = System.getProperty("cssfx.log.type", "console");
            switch (logType) {
            case "noop":
                CSSFXLogger.noop();
                break;
            case "console":
                CSSFXLogger.console();
                break;
            case "jul":
                CSSFXLogger.jul();
                break;
            default:
                System.err.println("[CSSFX] invalid value for cssfx.log.type, '" + logType + "' is not allowed. Select one in: " + Arrays.asList("noop", "console", "jul"));
                break;
            }
        } else {
            CSSFXLogger.noop();
        }
    }
    
    CSSFXMonitor m = new CSSFXMonitor();
    
    if (restrictedToWindow != null) {
        m.setWindows(FXCollections.singletonObservableList(restrictedToWindow));
    } else if (restrictedToScene != null) {
        m.setScenes(FXCollections.singletonObservableList(restrictedToScene));
    } else if (restrictedToNode != null) {
        m.setNodes(FXCollections.singletonObservableList(restrictedToNode));
    } else {
        // we monitor all the stages
        // THIS CANNOT WORK!
        ObservableList<Window> monitoredStages = (restrictedToWindow == null)?Window.getWindows():FXCollections.singletonObservableList(restrictedToWindow);
        m.setWindows(monitoredStages);
    }
    
    return start(() -> m);
}