Example usage for javafx.scene.image ImageView setPickOnBounds

List of usage examples for javafx.scene.image ImageView setPickOnBounds

Introduction

In this page you can find the example usage for javafx.scene.image ImageView setPickOnBounds.

Prototype

public final void setPickOnBounds(boolean value) 

Source Link

Usage

From source file:ubicrypt.ui.ctrl.providers.ProvidersController.java

@Override
public void initialize(URL url, ResourceBundle resourceBundle) {
    String fxml = substringBefore(substringAfterLast(url.getFile(), "/"), ".fxml");
    navigator = new StackNavigator(root, fxml, controllerFactory);
    providers.setCellFactory(listView -> new ListCell<ProviderItem>() {
        @Override/*from w ww  .  j  a  v a 2  s  .co  m*/
        protected void updateItem(ProviderItem pi, boolean empty) {
            super.updateItem(pi, empty);
            if (empty) {
                setText(null);
                setGraphic(null);
                return;
            }
            setContextMenu(pi.getContextMenu());
            Platform.runLater(() -> setGraphic(pi.getGraphics()));
        }
    });
    providerDescriptors.stream().forEach(pd -> {
        Button button = new Button();
        Image img = pd.getLogo().getImage();
        ImageView view = new ImageView(img);
        view.setFitWidth(30.0);
        view.setPickOnBounds(true);
        view.setPreserveRatio(true);
        button.setGraphic(view);
        button.setOnMouseClicked(mouseEvent -> {
            log.debug("adding provider :{}", pd.getCode());
            navigator.browse(format("provider/%s", pd.getCode()));
        });
        button.setTooltip(new Tooltip("Add " + pd.getDescription()));
        availableProviders.getItems().add(button);
    });

    //provider status events
    providerEvent.subscribe(pevent -> {
        UbiProvider provider = pevent.getHook().getProvider();
        if (!providers.getItems().stream().filter(pi -> pi.getProvider().equals(provider)).findFirst()
                .isPresent()) {
            log.info("add new provider:{}", pevent.getHook().getProvider());
            String code = providerDescriptors.stream().filter(pd -> pd.getType() == provider.getClass())
                    .map(ProviderDescriptor::getCode).findFirst().get();
            final ProviderItem providerItem = new ProviderItem(provider, providerDescriptors.stream()
                    .filter(pd -> pd.getType() == provider.getClass()).findFirst().get(), providerRemover,
                    navigator);
            providers.getItems().add(providerItem);
            pevent.getHook().getStatusEvents().subscribe(providerItem::changeStatus);
        }
        switch (pevent.getEvent()) {
        case removed:
            //TODO: remove provider
            break;
        default:
            log.warn("unmanaged event:{}", pevent.getEvent());
        }
        providers.getItems().stream().filter(pi -> pi.getProvider().equals(provider)).findFirst()
                .ifPresent(pi -> pi.changeStatus(pevent.getEvent()));
    });
}