Java Code Examples for javafx.beans.binding.Bindings#bindContent()

The following examples show how to use javafx.beans.binding.Bindings#bindContent() . 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: Navigator.java    From Flowless with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public Navigator(
        CellListManager<T, C> cellListManager,
        CellPositioner<T, C> positioner,
        OrientationHelper orientation,
        ObjectProperty<Gravity> gravity,
        SizeTracker sizeTracker) {
    this.cellListManager = cellListManager;
    this.cells = cellListManager.getLazyCellList();
    this.positioner = positioner;
    this.orientation = orientation;
    this.gravity = gravity;
    this.sizeTracker = sizeTracker;

    this.itemsSubscription = LiveList.observeQuasiChanges(cellListManager.getLazyCellList(), this::itemsChanged);
    Bindings.bindContent(getChildren(), cellListManager.getNodes());
    // When gravity changes, we must redo our layout:
    gravity.addListener((prop, oldVal, newVal) -> requestLayout());
}
 
Example 2
Source File: SidebarGroupSkin.java    From phoenicis with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void initialise() {
    final Label title = createTitleLabel();

    // ensure that the title label is only shown when it contains a nonempty string
    title.textProperty().addListener((Observable invalidation) -> updateTitleLabelVisibility(title));
    // ensure that the title label is correctly shown during initialisation
    updateTitleLabelVisibility(title);

    VBox container = new VBox();
    container.getStyleClass().add("sidebarInside");

    Bindings.bindContent(container.getChildren(), components);

    getChildren().addAll(container);
}
 
Example 3
Source File: SidebarToggleGroupBaseSkin.java    From phoenicis with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void initialise() {
    final ObservableList<ToggleButton> mappedToggleButtons = new MappedList<>(getControl().getElements(),
            this::convertToToggleButton);

    final ObservableList<ToggleButton> allToggleButton = createAllButton()
            .map(FXCollections::singletonObservableList)
            .orElse(FXCollections.emptyObservableList());

    final ConcatenatedList<ToggleButton> adhocToggleButtons = ConcatenatedList.create(allToggleButton,
            mappedToggleButtons);

    Bindings.bindContent(toggleGroup.getToggles(), adhocToggleButtons);

    SidebarGroup<ToggleButton> sidebarGroup = new SidebarGroup<>(getControl().titleProperty(), adhocToggleButtons);

    getChildren().addAll(sidebarGroup);
}
 
Example 4
Source File: IconsListWidgetSkin.java    From phoenicis with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Creates the {@link FlowPane} which contains the icons of the icons list
 *
 * @param container The scroll pane container which will contain the {@link FlowPane}
 * @return The new {@link FlowPane}
 */
private FlowPane createContent(final ScrollPane container) {
    final FlowPane content = new FlowPane();

    content.prefWidthProperty().bind(container.widthProperty());
    content.setPrefHeight(0);

    Bindings.bindContent(content.getChildren(), mappedElements);

    // ensure that updates to the selected element property are automatically reflected in the view
    getControl().selectedElementProperty().addListener((observable, oldValue, newValue) -> {
        // deselect the old element
        updateOldSelection(oldValue);

        // select the new element
        updateNewSelection(newValue);
    });

    // initialise selection at startup
    updateNewSelection(getControl().getSelectedElement());

    return content;
}
 
Example 5
Source File: UserInterfacePanelSkin.java    From phoenicis with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * Create the {@link ComboBox} containing the known themes
 *
 * @return A {@link ComboBox} containing the known themes
 */
private ComboBox<Theme> createThemeSelection() {
    final ComboBox<Theme> themeSelection = new ComboBox<>();

    Bindings.bindContent(themeSelection.getItems(), getControl().getThemes());

    themeSelection.valueProperty().bindBidirectional(getControl().selectedThemeProperty());
    themeSelection.setConverter(new StringConverter<>() {
        @Override
        public String toString(Theme theme) {
            return theme.getName();
        }

        @Override
        public Theme fromString(String themeName) {
            final Optional<Theme> foundTheme = getControl().getThemes().stream()
                    .filter(theme -> themeName.equals(theme.getName()))
                    .findFirst();

            return foundTheme.orElseThrow(
                    () -> new IllegalArgumentException("Couldn't find theme with name \"" + themeName + "\""));
        }
    });

    return themeSelection;
}
 
Example 6
Source File: ContainerInformationPanelSkin.java    From phoenicis with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void initialise() {
    final TabPane container = new TabPane();
    container.getStyleClass().add("container-information-panel");

    Bindings.bindContent(container.getTabs(), this.concatenatedTabs);

    getChildren().addAll(container);
}
 
Example 7
Source File: ContainerEngineToolsPanelSkin.java    From phoenicis with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Creates a container for all the tool buttons
 *
 * @return A container containing all the tool buttons
 */
private FlowPane createToolButtonContainer() {
    final FlowPane toolsContentPane = new FlowPane();
    toolsContentPane.getStyleClass().add("grid");

    Bindings.bindContent(toolsContentPane.getChildren(), toolButtons);

    return toolsContentPane;
}
 
Example 8
Source File: WindowMenuUpdateListener.java    From NSMenuFX with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public WindowMenuUpdateListener(Menu windowMenu) {
	this.windowMenu = new WeakReference<>(windowMenu);
	createdMenuItems = new HashMap<>();

	addItemsToMenu(StageUtils.getStages());

	stages = FXCollections.observableArrayList(stage -> new Observable[] {stage.focusedProperty()});
	Bindings.bindContent(stages, StageUtils.getStages());

	stages.addListener((Change <? extends Stage> c) -> checkFocusedStage());
}
 
Example 9
Source File: NavigationDrawerSkin.java    From WorkbenchFX with Apache License 2.0 5 votes vote down vote up
private MenuButton buildSubmenu(MenuItem item) {
  Menu menu = (Menu) item;
  MenuButton menuButton = new MenuButton();
  menuButton.setPopupSide(Side.RIGHT);
  menuButton.graphicProperty().bind(menu.graphicProperty());
  menuButton.textProperty().bind(menu.textProperty());
  menuButton.disableProperty().bind(menu.disableProperty());
  menuButton.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
  menuButton.getStyleClass().addAll(item.getStyleClass());
  Bindings.bindContent(menuButton.getItems(), menu.getItems());

  // To determine if a TOUCH_RELEASED event happens.
  // The MOUSE_ENTERED results in an unexpected behaviour on touch events.
  // Event filter triggers before the handler.
  menuButton.addEventFilter(TouchEvent.TOUCH_RELEASED, e -> isTouchUsed = true);

  // Only when ALWAYS or SOMETIMES
  if (!Priority.NEVER.equals(getSkinnable().getMenuHoverBehavior())) {
    menuButton.addEventHandler(MouseEvent.MOUSE_ENTERED, e -> { // Triggers on hovering over Menu
      if (isTouchUsed) {
        isTouchUsed = false;
        return;
      }
      // When ALWAYS, then trigger immediately. Else check if clicked before (case: SOMETIMES)
      if (Priority.ALWAYS.equals(getSkinnable().getMenuHoverBehavior())
          || (hoveredBtn != null && hoveredBtn.isShowing())) {
        menuButton.show(); // Shows the context-menu
        if (hoveredBtn != null && hoveredBtn != menuButton) {
          hoveredBtn.hide(); // Hides the previously hovered Button if not null and not self
        }
      }
      hoveredBtn = menuButton; // Add the button as previously hovered
    });
  }
  return menuButton;
}
 
Example 10
Source File: DialogSkin.java    From WorkbenchFX with Apache License 2.0 5 votes vote down vote up
private void setupBindings() {
  dialogButtonBar.managedProperty().bind(dialogButtonBar.visibleProperty());
  // FIXME: these two select bindings result in these warnings:
  /* com.sun.javafx.binding.SelectBinding$SelectBindingHelper getObservableValue
     WARNING: Exception while evaluating select-binding */
  dialogButtonBar.visibleProperty().bind(Bindings.select(dialog, "buttonsBarShown"));
  dialogTitle.textProperty().bind(Bindings.select(dialog, "title"));
  Bindings.bindContent(dialogButtonBar.getButtons(), buttons);
}
 
Example 11
Source File: CustomNavigationDrawerSkin.java    From WorkbenchFX with Apache License 2.0 5 votes vote down vote up
private MenuButton buildSubmenu(MenuItem item) {
  Menu menu = (Menu) item;
  MenuButton menuButton = new MenuButton();
  menuButton.setPopupSide(Side.RIGHT);
  menuButton.graphicProperty().bind(menu.graphicProperty());
  menuButton.textProperty().bind(menu.textProperty());
  menuButton.disableProperty().bind(menu.disableProperty());
  menuButton.setMaxSize(Double.MAX_VALUE, Double.MAX_VALUE);
  menuButton.getStyleClass().addAll(item.getStyleClass());
  Bindings.bindContent(menuButton.getItems(), menu.getItems());

  // To determine if a TOUCH_RELEASED event happens.
  // The MOUSE_ENTERED results in an unexpected behaviour on touch events.
  // Event filter triggers before the handler.
  menuButton.addEventFilter(TouchEvent.TOUCH_RELEASED, e -> isTouchUsed = true);

  // Only when ALWAYS or SOMETIMES
  if (!Priority.NEVER.equals(getSkinnable().getMenuHoverBehavior())) {
    menuButton.addEventHandler(MouseEvent.MOUSE_ENTERED, e -> { // Triggers on hovering over Menu
      if (isTouchUsed) {
        isTouchUsed = false;
        return;
      }
      // When ALWAYS, then trigger immediately. Else check if clicked before (case: SOMETIMES)
      if (Priority.ALWAYS.equals(getSkinnable().getMenuHoverBehavior())
          || (hoveredBtn != null && hoveredBtn.isShowing())) {
        menuButton.show(); // Shows the context-menu
        if (hoveredBtn != null && hoveredBtn != menuButton) {
          hoveredBtn.hide(); // Hides the previously hovered Button if not null and not self
        }
      }
      hoveredBtn = menuButton; // Add the button as previously hovered
    });
  }
  return menuButton;
}
 
Example 12
Source File: TableViewer.java    From chart-fx with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a new instance of DataSetTableViewer class and setup the required listeners.
 */
public TableViewer() {
    super();
    table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);
    table.getSelectionModel().setCellSelectionEnabled(true);
    table.setEditable(true); // Generally the TableView is editable, actual editability is configured column-wise
    table.setItems(dsModel);
    Bindings.bindContent(table.getColumns(), dsModel.getColumns());

    chartProperty().addListener((change, oldChart, newChart) -> {
        if (oldChart != null) {
            // plugin has already been initialised for old chart
            oldChart.getToolBar().getChildren().remove(interactorButtons);
            oldChart.getPlotForeground().getChildren().remove(table);
            oldChart.getPlotArea().setBottom(null);
            table.prefWidthProperty().unbind();
            table.prefHeightProperty().unbind();
        }
        if (newChart != null) {
            if (isAddButtonsToToolBar()) {
                newChart.getToolBar().getChildren().add(interactorButtons);
            }
            newChart.getPlotForeground().getChildren().add(table);
            table.toFront();
            table.setVisible(false); // table is initially invisible above the chart
            table.prefWidthProperty().bind(newChart.getPlotForeground().widthProperty());
            table.prefHeightProperty().bind(newChart.getPlotForeground().heightProperty());
        }
        dsModel.chartChanged(oldChart, newChart);
    });

    addButtonsToToolBarProperty().addListener((ch, o, n) -> {
        final Chart chartLocal = getChart();
        if (chartLocal == null || o.equals(n)) {
            return;
        }
        if (Boolean.TRUE.equals(n)) {
            chartLocal.getToolBar().getChildren().add(interactorButtons);
        } else {
            chartLocal.getToolBar().getChildren().remove(interactorButtons);
        }
    });
}
 
Example 13
Source File: CompactListWidgetSkin.java    From phoenicis with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void initialise() {
    final ListView<CompactListElement<E>> container = new ListView<>();
    container.getStyleClass().addAll("listWidget", "compactListWidget");

    container.setPrefWidth(0);
    container.setPrefHeight(0);

    // ensure that empty rows have the same height as non-empty ones
    container.setCellFactory(param -> {
        final ListCell<CompactListElement<E>> listCell = new ListCell<CompactListElement<E>>() {
            @Override
            public void updateItem(CompactListElement<E> item, boolean empty) {
                super.updateItem(item, empty);
                if (!empty && item != null) {
                    setGraphic(item);
                } else {
                    setGraphic(null);
                }
            }
        };

        listCell.getStyleClass().addAll("compactListElement");

        return listCell;
    });

    Bindings.bindContent(container.getItems(), mappedElements);

    // ensure that updates to the selected element property are automatically reflected in the view
    getControl().selectedElementProperty().addListener((observable, oldValue, newValue) -> {
        // deselect the old element
        updateOldSelection(container, oldValue);

        // select the new element
        updateNewSelection(container, newValue);
    });

    // initialise selection at startup
    updateNewSelection(container, getControl().getSelectedElement());

    getChildren().addAll(container);
}
 
Example 14
Source File: DetailsListWidgetSkin.java    From phoenicis with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void initialise() {
    final ListView<DetailsListElement<E>> container = new ListView<>();
    container.getStyleClass().addAll("listWidget", "detailsListWidget");

    container.setPrefWidth(0);
    container.setPrefHeight(0);

    // ensure that empty rows have the same height as non-empty ones
    container.setCellFactory(param -> {
        final ListCell<DetailsListElement<E>> listCell = new ListCell<DetailsListElement<E>>() {
            @Override
            public void updateItem(DetailsListElement<E> item, boolean empty) {
                super.updateItem(item, empty);
                if (!empty && item != null) {
                    setGraphic(item);
                } else {
                    setGraphic(null);
                }
            }
        };

        listCell.getStyleClass().addAll("detailsListElement");

        return listCell;
    });

    Bindings.bindContent(container.getItems(), mappedElements);

    // ensure that updates to the selected element property are automatically reflected in the view
    getControl().selectedElementProperty().addListener((observable, oldValue, newValue) -> {
        // deselect the old element
        updateOldSelection(container, oldValue);

        // select the new element
        updateNewSelection(container, newValue);
    });

    // initialise selection at startup
    updateNewSelection(container, getControl().getSelectedElement());

    getChildren().addAll(container);
}
 
Example 15
Source File: Chart.java    From chart-fx with Apache License 2.0 4 votes vote down vote up
protected void pluginAdded(final ChartPlugin plugin) {
    plugin.setChart(Chart.this);
    final Group group = Chart.createChildGroup();
    Bindings.bindContent(group.getChildren(), plugin.getChartChildren());
    pluginGroups.put(plugin, group);
}
 
Example 16
Source File: PhoenicisScene.java    From phoenicis with GNU Lesser General Public License v3.0 3 votes vote down vote up
public PhoenicisScene(Parent parent, ThemeManager themeManager, JavaFxSettingsManager javaFxSettingsManager) {
    super(parent);

    Bindings.bindContent(getStylesheets(), themeManager.getStylesheets());

    this.getRoot().setStyle(String.format("-fx-font-size: %.2fpt;", javaFxSettingsManager.getScale()));
}
 
Example 17
Source File: EnginesView.java    From phoenicis with GNU Lesser General Public License v3.0 3 votes vote down vote up
private TabPane createEngineVersion() {
    final TabPane availableEngines = new TabPane();

    availableEngines.getStyleClass().add("rightPane");
    availableEngines.setTabClosingPolicy(TabPane.TabClosingPolicy.UNAVAILABLE);

    Bindings.bindContent(availableEngines.getTabs(), this.engineSubCategoryTabs);

    return availableEngines;
}
 
Example 18
Source File: ContainerInformationPanelSkin.java    From phoenicis with GNU Lesser General Public License v3.0 3 votes vote down vote up
private Tab createContainerEngineSettingsTab() {
    final ContainerEngineSettingsPanel containerEngineSettingsPanel = new ContainerEngineSettingsPanel();

    containerEngineSettingsPanel.containerProperty().bind(getControl().containerProperty());
    Bindings.bindContent(containerEngineSettingsPanel.getEngineSettings(), getControl().getEngineSettings());

    final Tab engineSettingsTab = new Tab(tr(tr("Engine Settings")), containerEngineSettingsPanel);

    engineSettingsTab.setClosable(false);

    return engineSettingsTab;
}