Example usage for javafx.scene.control MenuItem setGraphic

List of usage examples for javafx.scene.control MenuItem setGraphic

Introduction

In this page you can find the example usage for javafx.scene.control MenuItem setGraphic.

Prototype

public final void setGraphic(Node value) 

Source Link

Usage

From source file:de.pixida.logtest.designer.automaton.Graph.java

Graph(final IAutomatonEditor aAutomatonEditor) {
    Validate.notNull(aAutomatonEditor);/*  w w w.  ja  v  a2 s  . co  m*/
    this.automatonEditor = aAutomatonEditor;

    this.pane.setBackground(new Background(new BackgroundFill(Color.WHITE, CornerRadii.EMPTY, Insets.EMPTY)));
    final double minSizeX = 800.0;
    final double minSizeY = 600.0;
    this.pane.setMinSize(minSizeX, minSizeY);
    final double paddingRightBottom = 8.0;
    this.pane.setPadding(new Insets(0.0, paddingRightBottom, paddingRightBottom, 0.0));
    this.pane.setOnMouseMoved(event -> this.mouseMovedOnPane(event));
    this.pane.setOnMouseClicked(event -> this.mouseClickedOnPane(event));
    final MenuItem mi = new MenuItem("Create new state");
    mi.setGraphic(Icons.getIconGraphics("pencil_add"));
    mi.setOnAction(event -> {
        // The following code does not really belong here as the class is designed only to handle business belongings... it should be
        // moved somewhere else!?
        final AutomatonNode newNode = new AutomatonNode(Graph.this);
        newNode.setPosition(new Point2D(this.lastMousePositionOnPaneX, this.lastMousePositionOnPaneY));
        newNode.setName("New state");
        Graph.this.addObject(newNode);
        Graph.this.handleChange();
        Graph.this.showConfigFrameOfObject(newNode);
    });
    this.contextMenu.getItems().add(mi);
}

From source file:de.pixida.logtest.designer.automaton.AutomatonNode.java

@Override
ContextMenu createContextMenu() {//from w ww  . ja  v a  2  s. c  o  m
    final ContextMenu cm = new ContextMenu();

    MenuItem mi = new MenuItem("Create edge from here");
    mi.setGraphic(Icons.getIconGraphics("bullet_go"));
    mi.setOnAction(event -> {
        final AutomatonEdgeBuilder newEdge = new AutomatonEdgeBuilder(this.getGraph());
        this.getGraph().startDrawingConnector(this, newEdge);
    });
    cm.getItems().add(mi);

    mi = new MenuItem("Delete state");
    mi.setGraphic(Icons.getIconGraphics("delete"));
    mi.setStyle("-fx-text-fill:#FF3030");
    mi.setOnAction(event -> {
        final Alert alert = new Alert(AlertType.CONFIRMATION);
        alert.setTitle("Confirm");
        alert.setHeaderText("You are about to delete the state.");
        alert.setContentText("Do you want to continue?");
        alert.showAndWait().filter(response -> response == ButtonType.OK)
                .ifPresent(response -> this.removeNodeAndEdges());
    });
    cm.getItems().add(mi);

    return cm;
}

From source file:de.pixida.logtest.designer.MainWindow.java

private void createAndAppendHelpMenuItems(final Menu help) {
    final MenuItem visitDocumentation = new MenuItem("Visit Online Documentation");
    visitDocumentation.setGraphic(Icons.getIconGraphics("help"));
    visitDocumentation.setOnAction(event -> {
        Exception ex = null;/*ww  w  .j  a  v a 2  s . c o  m*/
        final String url = "https://github.com/Pixida/logtest/wiki";
        final Desktop desktop = java.awt.Desktop.getDesktop();
        if (desktop.isSupported(java.awt.Desktop.Action.BROWSE)) {
            try {
                desktop.browse(new URI(url));
            } catch (final Exception e) {
                ex = e;
            }
        } else {
            ex = new Exception("Browsing not supported.");
        }
        if (ex != null) {
            ExceptionDialog.showFatalException("Failed to open browser", "Visit us at " + url, ex);
        }
    });

    final MenuItem about = new MenuItem("About " + APP_TITLE);
    about.setGraphic(Icons.getIconGraphics(APP_ICON));
    about.setOnAction(event -> {
        final Alert alert = new Alert(Alert.AlertType.INFORMATION);
        alert.initStyle(StageStyle.UTILITY);
        alert.setTitle(about.getText());
        alert.setHeaderText(APP_TITLE);
        alert.setContentText("Copyright (C) " + Calendar.getInstance().get(Calendar.YEAR) + " Pixida GmbH\n"
                + "\n" + "This application includes FAMFAMFAM icons (http://www.famfamfam.com).");
        alert.showAndWait();
    });

    help.getItems().addAll(visitDocumentation, about);
}

From source file:gov.va.isaac.gui.ConceptNode.java

/**
 * descriptionReader is optional//from   w w w  .j  a  va  2s . c  om
 */
public ConceptNode(ConceptVersionBI initialConcept, boolean flagAsInvalidWhenBlank,
        ObservableList<SimpleDisplayConcept> dropDownOptions,
        Function<ConceptVersionBI, String> descriptionReader) {
    c_ = initialConcept;
    //We can't simply use the ObservableList from the CommonlyUsedConcepts, because it infinite loops - there doesn't seem to be a way 
    //to change the items in the drop down without changing the selection.  So, we have this hack instead.
    listChangeListener_ = new ListChangeListener<SimpleDisplayConcept>() {
        @Override
        public void onChanged(Change<? extends SimpleDisplayConcept> c) {
            //TODO I still have an infinite loop here.  Find and fix.
            logger.debug("updating concept dropdown");
            disableChangeListener_ = true;
            SimpleDisplayConcept temp = cb_.getValue();
            cb_.setItems(FXCollections.observableArrayList(dropDownOptions_));
            cb_.setValue(temp);
            cb_.getSelectionModel().select(temp);
            disableChangeListener_ = false;
        }
    };
    descriptionReader_ = (descriptionReader == null ? (conceptVersion) -> {
        return conceptVersion == null ? "" : OTFUtility.getDescription(conceptVersion);
    } : descriptionReader);
    dropDownOptions_ = dropDownOptions == null
            ? AppContext.getService(CommonlyUsedConcepts.class).getObservableConcepts()
            : dropDownOptions;
    dropDownOptions_.addListener(new WeakListChangeListener<SimpleDisplayConcept>(listChangeListener_));
    conceptBinding_ = new ObjectBinding<ConceptVersionBI>() {
        @Override
        protected ConceptVersionBI computeValue() {
            return c_;
        }
    };

    flagAsInvalidWhenBlank_ = flagAsInvalidWhenBlank;
    cb_ = new ComboBox<>();
    cb_.setConverter(new StringConverter<SimpleDisplayConcept>() {
        @Override
        public String toString(SimpleDisplayConcept object) {
            return object == null ? "" : object.getDescription();
        }

        @Override
        public SimpleDisplayConcept fromString(String string) {
            return new SimpleDisplayConcept(string, 0);
        }
    });
    cb_.setValue(new SimpleDisplayConcept("", 0));
    cb_.setEditable(true);
    cb_.setMaxWidth(Double.MAX_VALUE);
    cb_.setPrefWidth(ComboBox.USE_COMPUTED_SIZE);
    cb_.setMinWidth(200.0);
    cb_.setPromptText("Type, drop or select a concept");

    cb_.setItems(FXCollections.observableArrayList(dropDownOptions_));
    cb_.setVisibleRowCount(11);

    cm_ = new ContextMenu();

    MenuItem copyText = new MenuItem("Copy Description");
    copyText.setGraphic(Images.COPY.createImageView());
    copyText.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            CustomClipboard.set(cb_.getEditor().getText());
        }
    });
    cm_.getItems().add(copyText);

    CommonMenusNIdProvider nidProvider = new CommonMenusNIdProvider() {
        @Override
        public Set<Integer> getNIds() {
            Set<Integer> nids = new HashSet<>();
            if (c_ != null) {
                nids.add(c_.getNid());
            }
            return nids;
        }
    };
    CommonMenuBuilderI menuBuilder = CommonMenus.CommonMenuBuilder.newInstance();
    menuBuilder.setInvisibleWhenFalse(isValid);
    CommonMenus.addCommonMenus(cm_, menuBuilder, nidProvider);

    cb_.getEditor().setContextMenu(cm_);

    updateGUI();

    new LookAheadConceptPopup(cb_);

    if (cb_.getValue().getNid() == 0) {
        if (flagAsInvalidWhenBlank_) {
            isValid.setInvalid("Concept Required");
        }
    } else {
        isValid.setValid();
    }

    cb_.valueProperty().addListener(new ChangeListener<SimpleDisplayConcept>() {
        @Override
        public void changed(ObservableValue<? extends SimpleDisplayConcept> observable,
                SimpleDisplayConcept oldValue, SimpleDisplayConcept newValue) {
            if (newValue == null) {
                logger.debug("Combo Value Changed - null entry");
            } else {
                logger.debug("Combo Value Changed: {} {}", newValue.getDescription(), newValue.getNid());
            }

            if (disableChangeListener_) {
                logger.debug("change listener disabled");
                return;
            }

            if (newValue == null) {
                //This can happen if someone calls clearSelection() - it passes in a null.
                cb_.setValue(new SimpleDisplayConcept("", 0));
                return;
            } else {
                if (newValue.shouldIgnoreChange()) {
                    logger.debug("One time change ignore");
                    return;
                }
                //Whenever the focus leaves the combo box editor, a new combo box is generated.  But, the new box will have 0 for an id.  detect and ignore
                if (oldValue != null && oldValue.getDescription().equals(newValue.getDescription())
                        && newValue.getNid() == 0) {
                    logger.debug("Not a real change, ignore");
                    newValue.setNid(oldValue.getNid());
                    return;
                }
                lookup();
            }
        }
    });

    AppContext.getService(DragRegistry.class).setupDragAndDrop(cb_, new SingleConceptIdProvider() {
        @Override
        public String getConceptId() {
            return cb_.getValue().getNid() + "";
        }
    }, true);

    pi_ = new ProgressIndicator(ProgressIndicator.INDETERMINATE_PROGRESS);
    pi_.visibleProperty().bind(isLookupInProgress_);
    pi_.setPrefHeight(16.0);
    pi_.setPrefWidth(16.0);
    pi_.setMaxWidth(16.0);
    pi_.setMaxHeight(16.0);

    lookupFailImage_ = Images.EXCLAMATION.createImageView();
    lookupFailImage_.visibleProperty().bind(isValid.not().and(isLookupInProgress_.not()));
    Tooltip t = new Tooltip();
    t.textProperty().bind(isValid.getReasonWhyInvalid());
    Tooltip.install(lookupFailImage_, t);

    StackPane sp = new StackPane();
    sp.setMaxWidth(Double.MAX_VALUE);
    sp.getChildren().add(cb_);
    sp.getChildren().add(lookupFailImage_);
    sp.getChildren().add(pi_);
    StackPane.setAlignment(cb_, Pos.CENTER_LEFT);
    StackPane.setAlignment(lookupFailImage_, Pos.CENTER_RIGHT);
    StackPane.setMargin(lookupFailImage_, new Insets(0.0, 30.0, 0.0, 0.0));
    StackPane.setAlignment(pi_, Pos.CENTER_RIGHT);
    StackPane.setMargin(pi_, new Insets(0.0, 30.0, 0.0, 0.0));

    hbox_ = new HBox();
    hbox_.setSpacing(5.0);
    hbox_.setAlignment(Pos.CENTER_LEFT);

    hbox_.getChildren().add(sp);
    HBox.setHgrow(sp, Priority.SOMETIMES);
}

From source file:de.pixida.logtest.designer.automaton.AutomatonEdge.java

@Override
ContextMenu createContextMenu() {// www.ja v  a2s  .com
    final ContextMenu cm = new ContextMenu();

    final MenuItem mi = new MenuItem("Delete edge");
    mi.setGraphic(Icons.getIconGraphics("delete"));
    mi.setStyle("-fx-text-fill:red");
    mi.setOnAction(event -> {
        final Alert alert = new Alert(AlertType.CONFIRMATION);
        alert.setTitle("Confirm");
        alert.setHeaderText("You are about to delete the edge.");
        alert.setContentText("Do you want to continue?");
        alert.showAndWait().filter(response -> response == ButtonType.OK)
                .ifPresent(response -> this.removeNodeAndEdges());
    });
    cm.getItems().add(mi);

    return cm;
}

From source file:View.Visualize.java

public void getPieChartData(Integer nameColumn, Integer valueColumn, Table table, PieChart pieChart, Label lbl,
        Boolean newSeries, Boolean rowCounter) {
    data.clear();//from ww w  . j av  a  2 s  .c  om

    if (!newSeries) {
        pieChart.getData().clear();
    }

    addDataFromTable(table, nameColumn, valueColumn, rowCounter);

    data.entrySet().stream().map(entry -> new PieChart.Data(entry.getKey(), entry.getValue()))
            .forEach(pieChart.getData()::add);

    for (PieChart.Data d : pieChart.getData()) {
        //deretter legger vi animasjon p piecharten.. 
        d.getNode().setOnMouseClicked(new mouseHooverAnimationPieChart.MouseHoverAnimation(d, pieChart));
        final Node n = d.getNode();
        Tooltip tooltip = new Tooltip();
        String toolTipText = "Value : " + d.getPieValue();
        tooltip.setText(toolTipText);
        Tooltip.install(n, tooltip);
        n.setOnMouseEntered(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent e) {
                n.setEffect(glow);
            }
        });
        n.setOnMouseExited(new EventHandler<MouseEvent>() {
            @Override
            public void handle(MouseEvent e) {
                n.setEffect(null);
            }
        });
        final ContextMenu contextMenu = new ContextMenu();
        MenuItem changeColor = new MenuItem("Change Color");
        MenuItem delete = new MenuItem("Standard color");
        ColorPicker cp = new ColorPicker();
        changeColor.setGraphic(cp);
        contextMenu.getItems().addAll(changeColor, delete);

        d.getNode().setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override
            public void handle(MouseEvent t) {
                if (t.getButton() == MouseButton.SECONDARY) {
                    delete.setOnAction(new EventHandler() {
                        public void handle(Event t) {
                            d.getNode().setStyle("");
                        }

                    });

                    cp.setValue(null);
                    cp.setOnAction(new EventHandler() {
                        public void handle(Event t) {
                            String hex1 = "#" + Integer.toHexString(cp.getValue().hashCode());

                            d.getNode().setStyle("-fx-background-color: " + hex1 + ";");
                        }
                    });

                    contextMenu.show(d.getNode(), t.getScreenX(), t.getScreenY());
                }
            }

        });

    }

}

From source file:View.Visualize.java

private void addColorChangeOnIndividual(ObservableList<XYChart.Data> data) {

    final ContextMenu contextMenu = new ContextMenu();
    MenuItem changeColor = new MenuItem("Change Color");
    MenuItem delete = new MenuItem("Standard color");

    ColorPicker cp = new ColorPicker();
    changeColor.setGraphic(cp);
    contextMenu.getItems().addAll(changeColor, delete);

    for (XYChart.Data d : data) {

        d.getNode().setOnMouseClicked(new EventHandler<MouseEvent>() {

            @Override//w  ww . j a  v a2s. c  o  m
            public void handle(MouseEvent t) {
                if (t.getButton() == MouseButton.SECONDARY) {
                    delete.setOnAction(new EventHandler() {
                        public void handle(Event t) {
                            d.getNode().setStyle("");
                        }

                    });

                    cp.setValue(null);
                    cp.setOnAction(new EventHandler() {
                        public void handle(Event t) {
                            String hex1 = "#" + Integer.toHexString(cp.getValue().hashCode());

                            d.getNode().setStyle("-fx-background-color: " + hex1 + ";");
                        }
                    });

                    contextMenu.show(d.getNode(), t.getScreenX(), t.getScreenY());
                }
            }

        });
    }

}

From source file:View.Visualize.java

private void addColorChangeOnSeries(XYChart.Series series) {

    final ContextMenu contextMenu = new ContextMenu();
    MenuItem changeColor = new MenuItem("Change color");
    MenuItem delete = new MenuItem("Standard color");
    ColorPicker cp = new ColorPicker();
    changeColor.setGraphic(cp);
    contextMenu.getItems().addAll(changeColor, delete);

    Node d = series.getNode();//from w  ww .jav a2 s  .  co  m

    d.setOnMouseClicked(new EventHandler<MouseEvent>() {

        @Override
        public void handle(MouseEvent t) {
            if (t.getButton() == MouseButton.SECONDARY) {
                delete.setOnAction(new EventHandler() {
                    public void handle(Event t) {
                        if (series.getChart() instanceof StackedAreaChart) {
                            series.getChart().lookup(".default-color" + series.getNode().getUserData()
                                    + ".chart-series-area-fill").setStyle("");
                        }
                        if (series.getChart() instanceof LineChart) {
                            series.getChart().lookup(
                                    ".default-color" + series.getNode().getUserData() + ".chart-series-line")
                                    .setStyle("");
                        }
                    }

                });
                cp.setValue(null);
                cp.setOnAction(new EventHandler() {
                    public void handle(Event t) {
                        String hex1 = "#" + Integer.toHexString(cp.getValue().hashCode());

                        if (series.getChart() instanceof StackedAreaChart) {
                            series.getChart().lookup(".default-color" + series.getNode().getUserData()
                                    + ".chart-series-area-fill").setStyle("-fx-fill:" + hex1 + ";");
                        }
                        if (series.getChart() instanceof LineChart) {
                            series.getChart().lookup(
                                    ".default-color" + series.getNode().getUserData() + ".chart-series-line")
                                    .setStyle("-fx-stroke:" + hex1 + ";");
                        }

                    }
                });

                contextMenu.show(d, t.getScreenX(), t.getScreenY());
            }
        }

    });
}