javafx.collections.WeakListChangeListener Java Examples

The following examples show how to use javafx.collections.WeakListChangeListener. 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: CycleStepTileSkin.java    From tilesfx with Apache License 2.0 6 votes vote down vote up
@Override protected void registerListeners() {
    super.registerListeners();
    tile.getChartData().addListener(new WeakListChangeListener<>(change -> {
        while (change.next()) {
            if (change.wasAdded()) {
                double sum = tile.getChartData().stream().mapToDouble(chartData -> chartData.getValue()).sum();
                change.getAddedSubList().forEach(chartData -> chartBox.getChildren().add(new ChartItem(chartData, sum)));
                updateChart();
            } else if (change.wasRemoved()) {
                change.getRemoved().forEach(removedItem -> {
                    Node itemToRemove = chartBox.getChildren().stream().filter(item -> item.equals(removedItem)).findFirst().get();
                    if (null != itemToRemove) {
                        chartBox.getChildren().remove(itemToRemove);
                    }
                });
                updateChart();
            }
        }
    }));
}
 
Example #2
Source File: ClusterMonitorTileSkin.java    From tilesfx with Apache License 2.0 6 votes vote down vote up
@Override protected void registerListeners() {
    super.registerListeners();
    tile.getChartData().addListener(new WeakListChangeListener<>(change -> {
        while (change.next()) {
            if (change.wasAdded()) {
                change.getAddedSubList().forEach(addedData -> {
                    addedData.addChartDataEventListener(updateHandler);
                    dataItemMap.put(addedData, new ChartItem(addedData, contentBounds));
                });
            } else if (change.wasRemoved()) {
                change.getRemoved().forEach(removedData -> {
                    removedData.removeChartDataEventListener(updateHandler);
                    dataItemMap.remove(removedData);
                });
            }
        }
        chartPane.getChildren().clear();
        dataItemMap.entrySet().forEach(entry -> chartPane.getChildren().add(entry.getValue()));
        updateChart();
    }));
    if (null != tile.getSVGPath()) { graphicRegion.addEventHandler(MouseEvent.MOUSE_PRESSED, svgPathPressedHandler); }

    pane.widthProperty().addListener(paneSizeListener);
    pane.heightProperty().addListener(paneSizeListener);
}
 
Example #3
Source File: BarChartTileSkin.java    From OEE-Designer with MIT License 5 votes vote down vote up
@Override protected void registerListeners() {
    super.registerListeners();
    tile.getBarChartItems().addListener(new WeakListChangeListener<>(change -> {
        while (change.next()) {
            if (change.wasAdded()) {
                change.getAddedSubList().forEach(addedItem -> {
                    barChartPane.getChildren().add(addedItem);
                    addedItem.addChartDataEventListener(updateHandler);
                    EventHandler<MouseEvent> clickHandler = e -> tile.fireTileEvent(new TileEvent(EventType.SELECTED_CHART_DATA, addedItem.getChartData()));
                    handlerMap.put(addedItem, clickHandler);
                    addedItem.setOnMousePressed(clickHandler);
                });
                updateChart();
            } else if (change.wasRemoved()) {
                change.getRemoved().forEach(removedItem -> {
                    removedItem.removeChartDataEventListener(updateHandler);
                    removedItem.removeEventHandler(MouseEvent.MOUSE_PRESSED, handlerMap.get(removedItem));
                    barChartPane.getChildren().remove(removedItem);
                });
                updateChart();
            }
        }
    }));

    pane.widthProperty().addListener(paneSizeListener);
    pane.heightProperty().addListener(paneSizeListener);
}
 
Example #4
Source File: BarChartTileSkin.java    From tilesfx with Apache License 2.0 5 votes vote down vote up
@Override protected void registerListeners() {
    super.registerListeners();
    tile.getBarChartItems().addListener(new WeakListChangeListener<>(change -> {
        while (change.next()) {
            if (change.wasAdded()) {
                change.getAddedSubList().forEach(addedItem -> {
                    barChartPane.getChildren().add(addedItem);
                    addedItem.addChartDataEventListener(updateHandler);
                    EventHandler<MouseEvent> clickHandler = e -> tile.fireTileEvent(new TileEvent(EventType.SELECTED_CHART_DATA, addedItem.getChartData()));
                    handlerMap.put(addedItem, clickHandler);
                    addedItem.setOnMousePressed(clickHandler);
                });
                updateChart();
            } else if (change.wasRemoved()) {
                change.getRemoved().forEach(removedItem -> {
                    removedItem.removeChartDataEventListener(updateHandler);
                    removedItem.removeEventHandler(MouseEvent.MOUSE_PRESSED, handlerMap.get(removedItem));
                    barChartPane.getChildren().remove(removedItem);
                });
                updateChart();
            }
        }
    }));

    pane.widthProperty().addListener(paneSizeListener);
    pane.heightProperty().addListener(paneSizeListener);
}
 
Example #5
Source File: JFXChipViewSkin.java    From JFoenix with Apache License 2.0 4 votes vote down vote up
public JFXChipViewSkin(JFXChipView<T> control) {
    super(control, new ChipViewBehaviorBase<T>(control, null));
    this.control = control;

    root = new CustomFlowPane();
    root.getStyleClass().add("chips-pane");
    setupEditor();

    scrollPane = new ScrollPane(root) {
        @Override
        public void requestFocus() {
            if (getSkinnable() != null) {
                getSkinnable().requestFocus();
            }
        }
    };
    scrollPane.setFitToWidth(true);

    getChildren().add(scrollPane);

    // init auto complete
    autoCompletePopup = (ChipsAutoComplete<T>) getSkinnable().getAutoCompletePopup();
    autoCompletePopup.setSelectionHandler(event -> {
        T selectedItem = event.getObject();
        if (getSkinnable().getSelectionHandler() != null) {
            selectedItem = getSkinnable().getSelectionHandler().apply(selectedItem);
        }
        getSkinnable().getChips().add(selectedItem);
        editor.clear();
    });
    // add position listener to auto complete
    autoCompletePopup.setShift(root.getVgap() * 2);
    root.vgapProperty().addListener((observable -> autoCompletePopup.setShift(root.getVgap() * 2)));

    // create initial chips
    for (T item : control.getChips()) {
        createChip(item);
    }
    control.getChips().addListener(new WeakListChangeListener<>(chipsChangeListeners));
    
}
 
Example #6
Source File: JFXMasonryPane.java    From JFoenix with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs a new JFXMasonryPane
 */
public JFXMasonryPane() {
    getChildren().addListener(new WeakListChangeListener<>(childrenListener));
}