Java 类javafx.scene.control.CustomMenuItem 实例源码

项目:main    文件:AutoCompleteTextField.java   
private void populatePopup(LinkedList<String> results) {
    List<CustomMenuItem> menuItems = results.stream()
        .map(Label::new)
        .map(label -> {
            CustomMenuItem menuItem = new CustomMenuItem(label, true);
            menuItem.setOnAction(action -> {
                select(label.getText());
                popup.hide();
            });
            return menuItem;
        })
        .collect(Collectors.toCollection(LinkedList::new));

    popup.getItems().setAll(menuItems);

    if (!popup.isShowing()) {
        popup.show(this, Side.BOTTOM, 0, 0);
    }
}
项目:arma-dialog-creator    文件:DefaultComponentContextMenu.java   
public DefaultComponentContextMenu(ArmaControl c) {
    MenuItem configure = new MenuItem(Lang.ApplicationBundle().getString("ContextMenu.DefaultComponent.configure"));

    Counter counter = new Counter(0, 0, Integer.MAX_VALUE, 1.0, true);
    counter.addUpdateButton(-10, "-10", 0);
    counter.addUpdateButton(10, "+10", 100); //put on end
    CustomMenuItem renderQueueItem = new CustomMenuItem(counter, false);

    Menu renderQueueMenu = new Menu(Lang.ApplicationBundle().getString("ContextMenu.DefaultComponent.render_queue"), null, renderQueueItem);

    getItems().addAll(/*renderQueueMenu, */configure);
    configure.setOnAction(new EventHandler<ActionEvent>() {
        @Override
        public void handle(ActionEvent event) {
            showControlPropertiesPopup(c);
        }
    });
}
项目:gitember    文件:ChangeListenerHistoryHint.java   
/**
 * Populate the entry set with the given search results.  Display is limited to 10 entries, for performance.
 *
 * @param searchResult The set of matching strings.
 */
private void populatePopup(List<String> searchResult) {
    List<CustomMenuItem> menuItems = new LinkedList<>();
    // If you'd like more entries, modify this line.
    int maxEntries = 10;
    int count = Math.min(searchResult.size(), maxEntries);
    for (int i = 0; i < count; i++) {
        final String result = searchResult.get(i);
        Label entryLabel = new Label(result);
        CustomMenuItem item = new CustomMenuItem(entryLabel, true);
        item.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent actionEvent) {
                textInputControl.setText(result); //todo add word
                entriesPopup.hide();
            }
        });
        menuItems.add(item);
    }
    entriesPopup.getItems().clear();
    entriesPopup.getItems().addAll(menuItems);

}
项目:openjfx-8u-dev-tests    文件:MenuItemApp.java   
public InvisibleItemsMenu() {
    super(INVISIBLE_ID);
    setId(INVISIBLE_ID);

    getItems().addAll(
            new MenuItem("Menu Item", new Rectangle(10, 10)),
            new MenuItem("Invisible Menu Item", new Rectangle(10, 10)),
            new CheckMenuItem("Check Item", new Rectangle(10, 10)),
            new CheckMenuItem("Invisible Check Item", new Rectangle(10, 10)),
            new RadioMenuItem("Radio Item", new Rectangle(10, 10)),
            new RadioMenuItem("Invisible Radio Item", new Rectangle(10, 10)),
            new CustomMenuItem(new Label("Custom Item")),
            new CustomMenuItem(new Label("Invisible Custom Item")));

    setEventHandlers();
}
项目:blackmarket    文件:AutoCompleteComboBox.java   
/**
 * Populate the entry set with the given search results.  Display is limited to 10 entries, for performance.
 * @param searchResult The set of matching strings.
 */
private void populatePopup(List<String> searchResult) {
  List<CustomMenuItem> menuItems = new LinkedList<>();
  // If you'd like more entries, modify this line.
  int maxEntries = 10;
  int count = Math.min(searchResult.size(), maxEntries);
  for (int i = 0; i < count; i++)
  {
    final String result = searchResult.get(i);
    Label entryLabel = new Label(result);
    CustomMenuItem item = new CustomMenuItem(entryLabel, true);
    item.setOnAction(new EventHandler<ActionEvent>()
    {
      @Override
      public void handle(ActionEvent actionEvent) {
        getEditor().setText(result);
        entriesPopup.hide();
      }
    });
    menuItems.add(item);
  }
  entriesPopup.getItems().clear();
  entriesPopup.getItems().addAll(menuItems);

}
项目:bgfinancas    文件:AutoCompletarTextField.java   
private void popularPopup(ObservableList<T> lista_itens) {
    int maximoItens = 18;
    int contador = Math.min(lista_itens.size(), maximoItens);
    List<CustomMenuItem> popupItens = new LinkedList<>();
    for (int i = 0; i < contador; i++) {
        final T item = lista_itens.get(i);
        Label itemLabel = new Label(item.toString());
        CustomMenuItem menuItem = new CustomMenuItem(itemLabel, true);
        menuItem.setOnAction(actionEvent -> {
            setText(item.toString());
            popup.hide();
            if (controlador != null) {
                controladorF.adicionar(null);
            }
        });
        popupItens.add(menuItem);
    }
    popup.getItems().clear();
    popup.getItems().addAll(popupItens);
}
项目:BetonQuest-Editor    文件:AutoCompleteTextField.java   
/**
 * Populate the entry set with the given search results. Display is limited
 * to 10 entries, for performance.
 * 
 * @param searchResult
 *            The set of matching strings.
 */
private void populatePopup(List<String> searchResult) {
    List<CustomMenuItem> menuItems = new LinkedList<>();
    // If you'd like more entries, modify this line.
    int maxEntries = 10;
    int count = Math.min(searchResult.size(), maxEntries);
    for (int i = 0; i < count; i++) {
        final String result = searchResult.get(i);
        Label entryLabel = new Label(result);
        CustomMenuItem item = new CustomMenuItem(entryLabel, true);
        item.setOnAction(new EventHandler<ActionEvent>() {
            @Override
            public void handle(ActionEvent actionEvent) {
                setText(result);
                entriesPopup.hide();
            }
        });
        menuItems.add(item);
    }
    entriesPopup.getItems().clear();
    entriesPopup.getItems().addAll(menuItems);
}
项目:StreamSis    文件:ActorContextMenuBuilder.java   
public static ContextMenu createCMForStructureViewList(ListView<Actor> listView) {
    ContextMenu cm = new ContextMenu();
    CustomMenuItem addActorMenuItem = GUIUtil.createTooltipedMenuItem("Add new",
            "Create new global Actor and add it to currently selected SisScene.\n\n"
                    + aboutActor);
    Menu addExistingActorMenuItem = generateAddExistingActorMenu(false);
    addActorMenuItem.setOnAction((ActionEvent event) -> {
        addNewActor();
    });
    cm.getItems().addAll(addActorMenuItem);
    if (addExistingActorMenuItem.getItems().size() != 0) {
        cm.getItems().add(addExistingActorMenuItem);
    }
    cm.autoHideProperty().set(true);
    return cm;
}
项目:FastisFX    文件:WeekViewRenderer.java   
public Node createHeaderPane(WeekView calView) {
    final GridPane container = new GridPane();
    container.setAlignment(Pos.BOTTOM_LEFT);
    container.getStyleClass().add("headerpane");

    final Label lblWeekday = new Label(calView.getDate().get().format(DateTimeFormatter.ofPattern("EEE")));
    lblWeekday.getStyleClass().add("label-weekday");

    final Label lblDate = new Label(calView.getDate().get().toString());
    lblDate.getStyleClass().add("label-date");
    final ContextMenu dayChooserMenu = new ContextMenu();
    final CustomMenuItem item = new CustomMenuItem(new DayChooser(calView.getDate()));
    dayChooserMenu.getStyleClass().add("day-chooser");
    item.setHideOnClick(false);
    dayChooserMenu.getItems().add(item);
    lblDate.setOnMouseClicked(event ->
            dayChooserMenu.show(lblDate,
                    lblDate.localToScreen(0, 0).getX(),
                    lblDate.localToScreen(0, 0).getY())
    );

    final Button left = new Button("<");
    left.getStyleClass().add("header-button");
    left.setOnAction(event -> calView.getDate().set(calView.getDate().get().minusDays(1)));
    final Button right = new Button(">");
    right.getStyleClass().add("header-button");
    right.setOnAction(event -> calView.getDate().set(calView.getDate().get().plusDays(1)));

    final ColumnConstraints columnWeekday = new ColumnConstraints(70);
    final ColumnConstraints columnCenter = new ColumnConstraints(20,50,Double.POSITIVE_INFINITY, Priority.ALWAYS, HPos.LEFT,true);
    final ColumnConstraints columnSwitcher = new ColumnConstraints(60);
    container.getColumnConstraints().addAll(columnWeekday, columnCenter, columnSwitcher);
    container.add(lblWeekday,0,0);
    container.add(lblDate, 1,0);
    container.add(new HBox(left, right), 2,0);
    return container;
}
项目:strongbox    文件:GetUpdatePolicies.java   
CustomMenuItem getSuggestion(String suggestion) {
    Label entryLabel = new Label(suggestion);
    CustomMenuItem item = new CustomMenuItem(entryLabel, true);
    item.setOnAction(f -> {
        addPrincipal.setText(suggestion);
    });
    return item;
}
项目:myWMS    文件:MyWMS.java   
public MenuItem createZoomMenus() {
    Integer zoomValue = getDefaultZoom();
    R.mainStyle.fontSizeProperty().bind(DoubleExpression.doubleExpression(zoomSpinner.valueProperty()).multiply(0.13d));
    zoomSpinner.getValueFactory().setValue(zoomValue.doubleValue());
    Label l = new Label("Zoom", zoomSpinner);
    l.setContentDisplay(ContentDisplay.RIGHT);
    return new CustomMenuItem(l, false);
}
项目:openjfx-8u-dev-tests    文件:MenuItemApp.java   
public MixedItemsMenu() {
    super(MIXED_ID);
    setId(MIXED_ID);

    MenuItem graphics_menu_item = new MenuItem(MENU_ITEM_GRAPHICS_ID, new Rectangle(10, 10));
    graphics_menu_item.setId(MENU_ITEM_GRAPHICS_ID);
    graphics_menu_item.setAccelerator(MENU_ITEM_ACCELERATOR);

    CheckMenuItem graphics_check_menu_item = new CheckMenuItem(CHECK_MENU_ITEM_GRAPHICS_ID, new Rectangle(10, 10));
    graphics_check_menu_item.setId(CHECK_MENU_ITEM_GRAPHICS_ID);
    graphics_check_menu_item.setAccelerator(CHECK_MENU_ITEM_ACCELERATOR);

    RadioMenuItem graphics_radio_menu_item = new RadioMenuItem(RADIO_MENU_ITEM_GRAPHICS_ID, new Rectangle(10, 10));
    graphics_radio_menu_item.setId(RADIO_MENU_ITEM_GRAPHICS_ID);
    graphics_radio_menu_item.setAccelerator(RADIO_MENU_ITEM_ACCELERATOR);

    HBox node_box_bool = new HBox();
    node_box_bool.getChildren().addAll(new Rectangle(10, 10), new Label(NODE_MENU_ITEM_BOOL_ID));
    CustomMenuItem graphics_node_menu_item = new CustomMenuItem(node_box_bool, true);
    graphics_node_menu_item.setId(NODE_MENU_ITEM_BOOL_ID);
    graphics_node_menu_item.setAccelerator(NODE_MENU_ITEM_ACCELERATOR);

    SeparatorMenuItem separator_menu_item = new SeparatorMenuItem();
    separator_menu_item.setId(SEPARATOR_MENU_ITEM_VOID_ID);

    getItems().addAll(graphics_menu_item,
            graphics_check_menu_item,
            graphics_radio_menu_item,
            graphics_node_menu_item,
            separator_menu_item);

    setEventHandlers();
}
项目:openjfx-8u-dev-tests    文件:MenuItemApp.java   
public NodeItemsMenu() {
    super(NODE_ID);
    setId(NODE_ID);

    for (int i = 0; i < 3; i++) {
        CustomMenuItem item = new CustomMenuItem(new Label("Item " + i));
        item.setId("Item " + i);
        getItems().add(item);
    }

    setEventHandlers();
}
项目:openjfx-8u-dev-tests    文件:MenuItemApp.java   
public AllInvisibleItemsMenu() {
    super(ALL_INVISIBLE_ID);
    setId(ALL_INVISIBLE_ID);

    getItems().addAll(
            new MenuItem("Invisible Menu Item", new Rectangle(10, 10)),
            new CheckMenuItem("Invisible Check Item", new Rectangle(10, 10)),
            new RadioMenuItem("Invisible Radio Item", new Rectangle(10, 10)),
            new CustomMenuItem(new Label("Invisible Custom Item")));

    setEventHandlers();
}
项目:qupath    文件:ScriptInterpreterCommand.java   
private MenuItem getCompletionMenuItem(final String name, final String oldText, final int startInd, final String completion, final Node graphic) {
    Label label = new Label(name);
    label.setMaxWidth(Double.POSITIVE_INFINITY);
    CustomMenuItem item = new CustomMenuItem(label);
    item.setOnAction(e -> {
        currentText.set(oldText.substring(0, startInd) + completion);
        textAreaInput.appendText("");
        updateLastHistoryListEntry();
    });
    if (graphic != null) {
        label.setContentDisplay(ContentDisplay.RIGHT);
        label.setGraphic(graphic);
    }
    return item;
}
项目:org.csstudio.display.builder    文件:AutocompleteMenu.java   
private final CustomMenuItem createHeaderItem(final String header)
{
    final CustomMenuItem item = new CustomMenuItem(new Text(header), false);
    item.getStyleClass().add("ac-menu-label");
    item.setHideOnClick(false);
    item.setMnemonicParsing(false);
    return item;
}
项目:StreamSis    文件:ActorContextMenuBuilder.java   
private static Menu generateAddExistingActorMenu(boolean onItem) {
    String menuText;
    if (onItem) {
        menuText = "Add existing Actor below...";
    } else {
        menuText = "Add existing...";
    }
    Menu addExistingActorMenu = new Menu(menuText);
    ArrayList<Actor> existingActors = new ArrayList<Actor>(
            ProjectManager.getProject().getGlobalActorsUnmodifiable());
    ObservableList<Actor> currentActors = ProjectManager.getProject().getCurrentActorsUnmodifiable();
    existingActors.removeAll(currentActors);
    for (Actor actor : existingActors) {
        ElementInfo info = actor.getElementInfo();
        String params = "Name: " + info.getName() + "\nCheck Interval: "
                + actor.getCheckInterval() + " ms\nRepeat Interval: "
                + actor.getRepeatInterval() + " ms\nRepeat On Actions: " + actor.getDoOnRepeat()
                + "\nRepeat Off Actions: " + actor.getDoOffRepeat() + "\nIs broken: "
                + actor.getElementInfo().isBroken();
        CustomMenuItem existingActorMenuItem = GUIUtil
                .createTooltipedMenuItem(actor.getElementInfo().getName(), params);
        existingActorMenuItem.setOnAction((ActionEvent event) -> {
            ProjectManager.getProject().addExistingActorToCurrentSisScene(actor);
        });
        addExistingActorMenu.getItems().add(existingActorMenuItem);
    }
    return addExistingActorMenu;
}
项目:StreamSis    文件:SisSceneContextMenuBuilder.java   
public static ContextMenu createSisSceneListContextMenu() {
    ContextMenu cm = new ContextMenu();
    CustomMenuItem addSisSceneMenuItem = GUIUtil.createTooltipedMenuItem("Add new",
            "Add new SisScene in which you can add Actors later.\n\n" + aboutSisScene);
    addSisSceneMenuItem.setOnAction((ActionEvent event) -> {
        addSisScene();
    });
    cm.getItems().add(addSisSceneMenuItem);
    cm.autoHideProperty().set(true);
    return cm;
}
项目:PeerWasp    文件:CustomizedTreeCell.java   
public CustomizedTreeCell(IFileEventManager fileEventManager,
        Provider<IFileRecoveryHandler> recoverFileHandlerProvider,
        Provider<IShareFolderHandler> shareFolderHandlerProvider,
        Provider<IForceSyncHandler> forceSyncHandlerProvider){

    this.fileEventManager = fileEventManager;
    this.shareFolderHandlerProvider = shareFolderHandlerProvider;
    this.recoverFileHandlerProvider = recoverFileHandlerProvider;
    this.forceSyncHandlerProvider = forceSyncHandlerProvider;

    menu = new ContextMenu();

    deleteItem = new CustomMenuItem(new Label("Delete from network"));
    deleteItem.setOnAction(new DeleteAction());
    menu.getItems().add(deleteItem);

    shareItem = new CustomMenuItem(new Label("Share"));
    shareItem.setOnAction(new ShareFolderAction());
    menu.getItems().add(shareItem);

    propertiesItem = new MenuItem("Properties");
    propertiesItem.setOnAction(new ShowPropertiesAction());
    menu.getItems().add(propertiesItem);

    forceSyncItem = new MenuItem("Force synchronization");
    forceSyncItem.setOnAction(new ForceSyncAction());
    menu.getItems().add(forceSyncItem);

    recoverMenuItem = createRecoveMenuItem();
    menu.getItems().add(recoverMenuItem);

    menu.setOnShowing(new ShowMenuHandler());
       setContextMenu(menu);
}
项目:jabref    文件:ConversionMenu.java   
public ConversionMenu(StringProperty text) {
    super(Localization.lang("Convert"));

    // create menu items, one for each converter
    for (Formatter converter : Formatters.CONVERTERS) {
        CustomMenuItem menuItem = new CustomMenuItem(new Label(converter.getName()));
        Tooltip toolTip = new Tooltip(converter.getDescription());
        Tooltip.install(menuItem.getContent(), toolTip);
        menuItem.setOnAction(event -> text.set(converter.format(text.get())));
        this.getItems().add(menuItem);
    }
}
项目:jabref    文件:EditorMenus.java   
/**
 * The default context menu with a specific menu for normalizing person names regarding to BibTex rules.
 *
 * @param textArea text-area that this menu will be connected to
 * @return menu containing items of the default menu and an item for normalizing person names
 */
public static Supplier<List<MenuItem>> getNameMenu(TextArea textArea) {
    return () -> {
        CustomMenuItem normalizeNames = new CustomMenuItem(new Label(Localization.lang("Normalize to BibTeX name format")));
        normalizeNames.setOnAction(event -> textArea.setText(new NormalizeNamesFormatter().format(textArea.getText())));
        Tooltip toolTip = new Tooltip(Localization.lang("If possible, normalize this list of names to conform to standard BibTeX name formatting"));
        Tooltip.install(normalizeNames.getContent(), toolTip);
        List<MenuItem> menuItems = new ArrayList<>(6);
        menuItems.add(normalizeNames);
        menuItems.addAll(getDefaultMenu(textArea).get());
        return menuItems;
    };
}
项目:jabref    文件:CaseChangeMenu.java   
public CaseChangeMenu(final StringProperty text) {
    super(Localization.lang("Change case"));
    Objects.requireNonNull(text);

    // create menu items, one for each case changer
    for (final Formatter caseChanger : Formatters.CASE_CHANGERS) {
        CustomMenuItem menuItem = new CustomMenuItem(new Label(caseChanger.getName()));
        Tooltip toolTip = new Tooltip(caseChanger.getDescription());
        Tooltip.install(menuItem.getContent(), toolTip);
        menuItem.setOnAction(event -> text.set(caseChanger.format(text.get())));

        this.getItems().add(menuItem);
    }
}
项目:openjfx-8u-dev-tests    文件:MenuItemApp.java   
public Constructors() {
    super(CONSTRUCTORS_ID);
    setId(CONSTRUCTORS_ID);

    MenuItem void_menu_item = new MenuItem();
    void_menu_item.setId(MENU_ITEM_VOID_ID);
    MenuItem string_menu_item = new MenuItem(MENU_ITEM_STRING_ID);
    string_menu_item.setId(MENU_ITEM_STRING_ID);
    MenuItem graphics_menu_item = new MenuItem(MENU_ITEM_GRAPHICS_ID, new Rectangle(10, 10));
    graphics_menu_item.setId(MENU_ITEM_GRAPHICS_ID);

    CheckMenuItem void_check_menu_item = new CheckMenuItem();
    void_check_menu_item.setId(CHECK_MENU_ITEM_VOID_ID);
    CheckMenuItem string_check_menu_item = new CheckMenuItem(CHECK_MENU_ITEM_ID);
    string_check_menu_item.setId(CHECK_MENU_ITEM_ID);
    CheckMenuItem graphics_check_menu_item = new CheckMenuItem(CHECK_MENU_ITEM_GRAPHICS_ID, new Rectangle(10, 10));
    graphics_check_menu_item.setId(CHECK_MENU_ITEM_GRAPHICS_ID);

    RadioMenuItem string_radio_menu_item_parameterless = new RadioMenuItem();
    string_radio_menu_item_parameterless.setId(RADIO_MENU_ITEM_PARAMETERLESS_ID);
    RadioMenuItem string_radio_menu_item = new RadioMenuItem(RADIO_MENU_ITEM_ID);
    string_radio_menu_item.setId(RADIO_MENU_ITEM_ID);
    RadioMenuItem graphics_radio_menu_item = new RadioMenuItem(RADIO_MENU_ITEM_GRAPHICS_ID, new Rectangle(10, 10));
    graphics_radio_menu_item.setId(RADIO_MENU_ITEM_GRAPHICS_ID);

    CustomMenuItem void_node_menu_item = new CustomMenuItem();
    HBox void_node_box = new HBox();
    void_node_box.getChildren().addAll(new Rectangle(10, 10), new Label(NODE_MENU_ITEM_VOID_ID));
    void_node_menu_item.setContent(void_node_box);
    void_node_menu_item.setId(NODE_MENU_ITEM_VOID_ID);
    HBox node_box = new HBox();
    node_box.getChildren().addAll(new Rectangle(10, 10), new Label(NODE_MENU_ITEM_ID));
    CustomMenuItem node_menu_item = new CustomMenuItem(node_box);
    node_menu_item.setId(NODE_MENU_ITEM_ID);
    HBox node_box_bool = new HBox();
    node_box_bool.getChildren().addAll(new Rectangle(10, 10), new Label(NODE_MENU_ITEM_BOOL_ID));
    CustomMenuItem graphics_node_menu_item = new CustomMenuItem(node_box_bool, true);
    graphics_node_menu_item.setId(NODE_MENU_ITEM_BOOL_ID);

    SeparatorMenuItem separator_menu_item = new SeparatorMenuItem();
    separator_menu_item.setId(SEPARATOR_MENU_ITEM_VOID_ID);

    getItems().addAll(void_menu_item, string_menu_item, graphics_menu_item,
            void_check_menu_item, string_check_menu_item, graphics_check_menu_item,
            string_radio_menu_item_parameterless, string_radio_menu_item, graphics_radio_menu_item,
            void_node_menu_item, node_menu_item, graphics_node_menu_item,
            separator_menu_item);
}
项目:StreamSis    文件:TreeContextMenuBuilder.java   
/**
 * Creates the {@link ContextMenu} for the chosen {@link CuteTreeCell}.
 *
 * @param treeCell
 *            the CuteTreeCell for which ContextMenu will be created.
 * @return the ContextMenu
 */
public static ContextMenu createCuteTreeCellContextMenu(CuteTreeCell treeCell) {
    CuteElement cuteElement = (CuteElement) treeCell.getItem();
    if (cuteElement == null)
        return null;
    ContextMenu cm = new ContextMenu();
    CustomMenuItem moveUpMenuItem = GUIUtil.createTooltipedMenuItem("Move Up",
            "This will move the thingy Up");
    moveUpMenuItem.setOnAction(createMovementEventHandler(treeCell, true));
    CustomMenuItem moveDownMenuItem = GUIUtil.createTooltipedMenuItem("Move Down",
            "This will move the thingy Down");
    moveDownMenuItem.setOnAction(createMovementEventHandler(treeCell, false));
    CustomMenuItem deleteMenuItem = GUIUtil.createTooltipedMenuItem("Delete",
            "Are you sure?\nAre you going to throw this little item away..?");
    deleteMenuItem.setOnAction((ActionEvent event) -> {
        ObservableList<? extends CuteElement> list = treeCell.getTreeItem().getParent()
                .getValue().getChildren();
        if (list != null) {
            if (!list.isEmpty()) {
                if (list.contains(cuteElement)) {
                    list.remove(cuteElement);
                    // Initialize whole project to reinitialize any parents that might get
                    // broken.
                    ProjectManager.initProjectFromGUI();
                } else {
                    logger.error("Nothing to remove from list");
                }
            } else {
                logger.error("list is empty");
            }
        } else {
            logger.error("list is null");
        }
    });

    // Let's determine where the Item can move.
    // By default let's have ability to move in both directions.
    PossibleMoves possibleMoves = PossibleMoves.UPORDOWN;
    TreeItem<CuteElement> treeItem = treeCell.getTreeItem();
    int treeItemIndex = treeItem.getParent().getChildren().indexOf(treeItem);
    int sizeOfList = treeItem.getParent().getChildren().size();
    if (sizeOfList != 1) {
        if (treeItemIndex == 0)
            possibleMoves = PossibleMoves.ONLYDOWN;
        if (treeItemIndex == sizeOfList - 1)
            possibleMoves = PossibleMoves.ONLYUP;
    } else {
        possibleMoves = PossibleMoves.NOWHERE;
    }

    // Let's add all MenuItems to Context Menu
    if (canChildrenBeAdded(cuteElement)) {
        cm.getItems().add(generateNewCuteElementMenu(cuteElement));
    }
    if (!possibleMoves.equals(PossibleMoves.NOWHERE)) {
        if (possibleMoves.equals(PossibleMoves.UPORDOWN)) {
            cm.getItems().add(moveUpMenuItem);
            cm.getItems().add(moveDownMenuItem);
        } else {
            if (possibleMoves.equals(PossibleMoves.ONLYUP))
                cm.getItems().add(moveUpMenuItem);
            if (possibleMoves.equals(PossibleMoves.ONLYDOWN))
                cm.getItems().add(moveDownMenuItem);
        }
    }
    if (!CuteElement.MaxAddableChildrenCount.UNDEFINEDORZERO.equals(
            treeCell.getTreeItem().getParent().getValue().getMaxAddableChildrenCount())) {
        cm.getItems().add(deleteMenuItem);
    }
    cm.autoHideProperty().set(true);
    return cm;
}
项目:StreamSis    文件:TreeContextMenuBuilder.java   
/**
 * Generate {@link Menu} for adding new {@link CuteElementContainer}s as children to the chosen
 * CuteElement.
 *
 * @param whereToAdd
 *            the CuteElement where to add new child using generated Menu
 * @return the Menu
 */
private static Menu generateMenuForAddingNewContainer(CuteElement whereToAdd) {
    ContainerCreationParams params = whereToAdd.getChildContainerCreationParams();
    Menu menu = new Menu("Add new " + params.containerFakeTypeName + "...");

    CustomMenuItem newContainerMenuItem = GUIUtil
            .createTooltipedMenuItem(params.containerFakeTypeName, params.GUIDescription);
    newContainerMenuItem.setOnAction((ActionEvent event) -> {
        CuteElement cuteElementContainerToAdd = null;

        // This list will later help to generate name for the new Container.
        List<String> existingChildrenNames = new ArrayList<String>();
        for (CuteElement element : whereToAdd.getChildren()) {
            existingChildrenNames.add(element.getElementInfo().getName());
        }

        try {
            // Determine proper name for new container
            String name = GUIUtil.generateUniqueNameForNewItem(params.creationBaseName,
                    existingChildrenNames);
            // Instantiate Container
            cuteElementContainerToAdd = CuteElementContainer.createEmptyCuteElementContainer(
                    name, params.childrenType, params.childrenMaxCount,
                    params.childrenMinCount, params.containerFakeTypeName);
            cuteElementContainerToAdd.getElementInfo().setEditable(params.editable);
            cuteElementContainerToAdd.getElementInfo()
                    .setEmptyNameAllowed(params.emptyNameAllowed);

        } catch (Exception e) {
            throw new RuntimeException("Can't instantiate Container inside "
                    + whereToAdd.getClass().getSimpleName(), e);
        }
        if (cuteElementContainerToAdd != null) {
            @SuppressWarnings("unchecked")
            ObservableList<CuteElement> whereToAddCasted = (ObservableList<CuteElement>) whereToAdd
                    .getChildren();
            whereToAddCasted.add(cuteElementContainerToAdd);
            // Initialize whole project to reinitialize any parents that might get broken.
            ProjectManager.initProjectFromGUI();
        }
    });
    menu.getItems().add(newContainerMenuItem);
    return menu;
}
项目:PeerWasp    文件:CustomizedTreeCell.java   
private MenuItem createRecoveMenuItem() {
    Label label = new Label("Recover File");
    MenuItem menuItem = new CustomMenuItem(label);
    menuItem.setOnAction(new RecoverFileAction());
    return menuItem;
}
项目:StreamSis    文件:GUIUtil.java   
/**
 * Creates the tooltiped menu item. <br>
 * It's impossible to add Tooltip to default MenuItem, so creating label, adding tooltip inside
 * of it and putting this label inside CustomMenuItem.
 *
 * @param text
 *            the menu item's text
 * @param tooltip
 *            the tooltip to install to newly created custom menu item
 * @return newly created custom menu item
 */
public static CustomMenuItem createTooltipedMenuItem(String text, String tooltip) {
    Label l = new Label(text);
    // If we dont' set up preferred size, tooltips and mouse clicks will be processed only on
    // text area
    l.setPrefSize(200, 20);
    CustomMenuItem menuItem = new CustomMenuItem(l);
    Tooltip tp = new Tooltip(tooltip);
    Tooltip.install(l, tp);
    return menuItem;
}
项目:HubTurbo    文件:SuggestionsMenu.java   
/**
 * @param event
 * @return text content from an event's source
 */
public static Optional<String> getTextOnAction(ActionEvent event) {
    return Optional.of(((CustomMenuItem) event.getSource()).getText());
}