Search in sources :

Example 11 with Observable

use of javafx.beans.Observable in project POL-POM-5 by PlayOnLinux.

the class LibraryFeaturePanelSkin method createCombinedListWidget.

private CombinedListWidget<ShortcutDTO> createCombinedListWidget() {
    final FilteredList<ShortcutDTO> filteredShortcuts = ConcatenatedList.create(new MappedList<>(getControl().getCategories().sorted(Comparator.comparing(ShortcutCategoryDTO::getName)), ShortcutCategoryDTO::getShortcuts)).filtered(getControl().getFilter()::filter);
    filteredShortcuts.predicateProperty().bind(Bindings.createObjectBinding(() -> getControl().getFilter()::filter, getControl().getFilter().searchTermProperty(), getControl().getFilter().selectedShortcutCategoryProperty()));
    final SortedList<ShortcutDTO> sortedShortcuts = filteredShortcuts.sorted(Comparator.comparing(shortcut -> shortcut.getInfo().getName()));
    final ObservableList<ListWidgetElement<ShortcutDTO>> listWidgetEntries = new MappedList<>(sortedShortcuts, ListWidgetElement::create);
    final CombinedListWidget<ShortcutDTO> combinedListWidget = new CombinedListWidget<>(listWidgetEntries, this.selectedListWidget);
    // bind direction: controller property -> skin property
    getControl().selectedShortcutProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue != null) {
            combinedListWidget.select(newValue);
        } else {
            combinedListWidget.deselect();
        }
    });
    // bind direction: skin property -> controller properties
    combinedListWidget.selectedElementProperty().addListener((observable, oldValue, newValue) -> {
        if (newValue != null) {
            final ShortcutDTO selectedItem = newValue.getItem();
            final MouseEvent event = newValue.getEvent();
            getControl().setSelectedShortcut(selectedItem);
            getControl().setOpenedDetailsPanel(new ShortcutInformation(selectedItem));
            if (event.getClickCount() == 2) {
                getControl().runShortcut(selectedItem);
            }
        } else {
            getControl().setSelectedShortcut(null);
            getControl().setOpenedDetailsPanel(new None());
        }
    });
    return combinedListWidget;
}
Also used : CombinedListWidget(org.phoenicis.javafx.components.common.widgets.control.CombinedListWidget) ShortcutCategoryDTO(org.phoenicis.library.dto.ShortcutCategoryDTO) StringBindings(org.phoenicis.javafx.utils.StringBindings) ObjectExpression(javafx.beans.binding.ObjectExpression) MappedList(org.phoenicis.javafx.collections.MappedList) MouseEvent(javafx.scene.input.MouseEvent) ShortcutEditing(org.phoenicis.javafx.components.library.panelstates.ShortcutEditing) Bindings(javafx.beans.binding.Bindings) SidebarBase(org.phoenicis.javafx.components.common.control.SidebarBase) org.phoenicis.javafx.components.library.control(org.phoenicis.javafx.components.library.control) ListWidgetElement(org.phoenicis.javafx.components.common.widgets.utils.ListWidgetElement) ShortcutInformation(org.phoenicis.javafx.components.library.panelstates.ShortcutInformation) ShortcutCreation(org.phoenicis.javafx.components.library.panelstates.ShortcutCreation) TabPane(javafx.scene.control.TabPane) None(org.phoenicis.javafx.components.common.panelstates.None) FeaturePanelSkin(org.phoenicis.javafx.components.common.skin.FeaturePanelSkin) ShortcutDTO(org.phoenicis.library.dto.ShortcutDTO) SwitchBinding(org.phoenicis.javafx.utils.SwitchBinding) SortedList(javafx.collections.transformation.SortedList) ListWidgetType(org.phoenicis.javafx.components.common.widgets.utils.ListWidgetType) ObjectProperty(javafx.beans.property.ObjectProperty) Node(javafx.scene.Node) FilteredList(javafx.collections.transformation.FilteredList) Localisation.tr(org.phoenicis.configuration.localisation.Localisation.tr) Observable(javafx.beans.Observable) JavaFxSettingsManager(org.phoenicis.javafx.settings.JavaFxSettingsManager) SimpleObjectProperty(javafx.beans.property.SimpleObjectProperty) Tab(javafx.scene.control.Tab) OpenDetailsPanel(org.phoenicis.javafx.components.common.panelstates.OpenDetailsPanel) DetailsPanel(org.phoenicis.javafx.components.common.control.DetailsPanel) Optional(java.util.Optional) ObjectBindings(org.phoenicis.javafx.utils.ObjectBindings) ObservableList(javafx.collections.ObservableList) ConcatenatedList(org.phoenicis.javafx.collections.ConcatenatedList) Comparator(java.util.Comparator) CombinedListWidget(org.phoenicis.javafx.components.common.widgets.control.CombinedListWidget) MouseEvent(javafx.scene.input.MouseEvent) ListWidgetElement(org.phoenicis.javafx.components.common.widgets.utils.ListWidgetElement) ShortcutInformation(org.phoenicis.javafx.components.library.panelstates.ShortcutInformation) ShortcutDTO(org.phoenicis.library.dto.ShortcutDTO) MappedList(org.phoenicis.javafx.collections.MappedList) ShortcutCategoryDTO(org.phoenicis.library.dto.ShortcutCategoryDTO) None(org.phoenicis.javafx.components.common.panelstates.None)

Example 12 with Observable

use of javafx.beans.Observable in project POL-POM-5 by PlayOnLinux.

the class CollectionBindings method mapToMap.

/**
 * 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;
}
Also used : InvalidationListener(javafx.beans.InvalidationListener) Observable(javafx.beans.Observable)

Example 13 with Observable

use of javafx.beans.Observable in project POL-POM-5 by PlayOnLinux.

the class CollectionBindings method mapToList.

/**
 * Maps an {@link ObservableValue<I>} object to an {@link ObservableList} by applying the given converter function
 * and adding the result to the {@link ObservableList}.
 * In case the input value is empty, i.e. contains <code>null</code>, the returned {@link ObservableList} is also
 * empty
 *
 * @param property The input value
 * @param converter The converter function
 * @param <I> The type of the input value
 * @param <O> The type of the output value
 * @return A {@link ObservableList} containing the converted list
 */
public static <I, O> ObservableList<O> mapToList(ObservableValue<I> property, Function<I, ? extends Collection<O>> converter) {
    final ObservableList<O> result = FXCollections.observableArrayList();
    final InvalidationListener listener = (Observable invalidation) -> {
        final I input = property.getValue();
        if (input != null) {
            result.setAll(converter.apply(input));
        } else {
            result.clear();
        }
    };
    // add the listener to the property
    property.addListener(listener);
    // ensure that the result list is initialised correctly
    listener.invalidated(property);
    return result;
}
Also used : InvalidationListener(javafx.beans.InvalidationListener) Observable(javafx.beans.Observable)

Example 14 with Observable

use of javafx.beans.Observable in project POL-POM-5 by PlayOnLinux.

the class ShortcutInformationPanelSkin method createKeyAttributeList.

private KeyAttributeList createKeyAttributeList() {
    final KeyAttributeList keyAttributeList = new KeyAttributeList();
    this.environmentAttributes.addListener((Observable invalidated) -> keyAttributeList.setAttributeMap(this.environmentAttributes));
    keyAttributeList.setAttributeMap(this.environmentAttributes);
    return keyAttributeList;
}
Also used : KeyAttributeList(org.phoenicis.javafx.components.common.control.KeyAttributeList) Observable(javafx.beans.Observable)

Example 15 with Observable

use of javafx.beans.Observable in project POL-POM-5 by PlayOnLinux.

the class ShortcutInformationPanelSkin method createPropertiesGrid.

/**
 * Creates a new {@link GridPane} containing the properties of the selected shortcut
 *
 * @return a new {@link GridPane} containing the properties of the selected shortcut
 */
private GridPane createPropertiesGrid() {
    final GridPane propertiesGrid = new GridPane();
    propertiesGrid.getStyleClass().add("grid");
    ColumnConstraints titleColumn = new ColumnConstraintsWithPercentage(30);
    ColumnConstraints valueColumn = new ColumnConstraintsWithPercentage(70);
    propertiesGrid.getColumnConstraints().addAll(titleColumn, valueColumn);
    // ensure that changes to the shortcutProperties map result in updates to the GridPane
    shortcutProperties.addListener((Observable invalidation) -> updateProperties(propertiesGrid));
    // initialize the properties grid correctly
    updateProperties(propertiesGrid);
    return propertiesGrid;
}
Also used : ColumnConstraintsWithPercentage(org.phoenicis.javafx.views.common.ColumnConstraintsWithPercentage) GridPane(javafx.scene.layout.GridPane) ColumnConstraints(javafx.scene.layout.ColumnConstraints) Observable(javafx.beans.Observable)

Aggregations

Observable (javafx.beans.Observable)23 InvalidationListener (javafx.beans.InvalidationListener)7 VBox (javafx.scene.layout.VBox)7 Image (javafx.scene.image.Image)4 HBox (javafx.scene.layout.HBox)4 Text (javafx.scene.text.Text)4 Bindings (javafx.beans.binding.Bindings)3 SimpleObjectProperty (javafx.beans.property.SimpleObjectProperty)3 ObservableList (javafx.collections.ObservableList)3 ActionEvent (javafx.event.ActionEvent)3 Button (javafx.scene.control.Button)3 Label (javafx.scene.control.Label)3 ImageView (javafx.scene.image.ImageView)3 GridPane (javafx.scene.layout.GridPane)3 MediaFile (com.negativevr.media_library.files.MediaFile)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Optional (java.util.Optional)2 KeyFrame (javafx.animation.KeyFrame)2 KeyValue (javafx.animation.KeyValue)2