javafx.scene.control.ContextMenu Java Examples

The following examples show how to use javafx.scene.control.ContextMenu. 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: SelectionTable.java    From pdfsam with GNU Affero General Public License v3.0 6 votes vote down vote up
private void initTopSectionContextMenu(ContextMenu contextMenu, boolean hasRanges) {
    MenuItem setDestinationItem = createMenuItem(DefaultI18nContext.getInstance().i18n("Set destination"),
            MaterialDesignIcon.AIRPLANE_LANDING);
    setDestinationItem.setOnAction(e -> eventStudio().broadcast(
            requestDestination(getSelectionModel().getSelectedItem().descriptor().getFile(), getOwnerModule()),
            getOwnerModule()));
    setDestinationItem.setAccelerator(new KeyCodeCombination(KeyCode.O, KeyCombination.ALT_DOWN));

    selectionChangedConsumer = e -> setDestinationItem.setDisable(!e.isSingleSelection());
    contextMenu.getItems().add(setDestinationItem);

    if (hasRanges) {
        MenuItem setPageRangesItem = createMenuItem(DefaultI18nContext.getInstance().i18n("Set as range for all"),
                MaterialDesignIcon.FORMAT_INDENT_INCREASE);
        setPageRangesItem.setOnAction(e -> eventStudio().broadcast(
                new SetPageRangesRequest(getSelectionModel().getSelectedItem().pageSelection.get()),
                getOwnerModule()));
        setPageRangesItem.setAccelerator(new KeyCodeCombination(KeyCode.R, KeyCombination.CONTROL_DOWN));
        selectionChangedConsumer = selectionChangedConsumer
                .andThen(e -> setPageRangesItem.setDisable(!e.isSingleSelection()));
        contextMenu.getItems().add(setPageRangesItem);
    }
    contextMenu.getItems().add(new SeparatorMenuItem());
}
 
Example #2
Source File: BytecodeContextHandling.java    From Recaf with MIT License 6 votes vote down vote up
private void handleLabelType(LabelSelection selection) {
	ContextMenu menu = new ContextMenu();
	Menu refs = new Menu(LangUtil.translate("ui.edit.method.referrers"));
	for (AST ast : root.getChildren()) {
		if ((ast instanceof FlowController && ((FlowController) ast).targets().contains(selection.name)) ||
				(ast instanceof LineInsnAST && ((LineInsnAST) ast).getLabel().getName().equals(selection.name))) {
			MenuItem ref = new ActionMenuItem(ast.getLine() + ": " + ast.print(), () -> {
				int line = ast.getLine() - 1;
				codeArea.moveTo(line, 0);
				codeArea.requestFollowCaret();
			});
			refs.getItems().add(ref);
		}
	}
	if (refs.getItems().isEmpty())
		refs.setDisable(true);
	menu.getItems().add(refs);
	codeArea.setContextMenu(menu);
}
 
Example #3
Source File: BytecodeContextHandling.java    From Recaf with MIT License 6 votes vote down vote up
private void handleJumpType(JumpSelection selection) {
	ContextMenu menu = new ContextMenu();
	MenuItem jump = new ActionMenuItem(LangUtil.translate("ui.edit.method.follow"), () -> {
		for (AST ast : root.getChildren()) {
			if (ast instanceof LabelAST) {
				String name = ((LabelAST) ast).getName().getName();
				if(name.equals(selection.destination)) {
					int line = ast.getLine() - 1;
					codeArea.moveTo(line, 0);
					codeArea.requestFollowCaret();
				}
			}
		}
	});
	menu.getItems().add(jump);
	codeArea.setContextMenu(menu);
}
 
Example #4
Source File: ChartContainerController.java    From trex-stateless-gui with Apache License 2.0 6 votes vote down vote up
public ChartContainerController(String selectedType, IntegerProperty interval) {
    Initialization.initializeFXML(this, "/fxml/dashboard/charts/ChartContainer.fxml");

    this.interval = interval;

    chartType = new SimpleStringProperty();
    chartType.addListener(this::handleChartTypeChanged);
    chartType.set(selectedType);

    contextMenu = new ContextMenu();
    contextMenu.getItems().addAll(
            createContextMenuItem(ChartsFactory.ChartTypes.TX_PPS),
            createContextMenuItem(ChartsFactory.ChartTypes.RX_PPS),
            createContextMenuItem(ChartsFactory.ChartTypes.TX_BPS_L1),
            createContextMenuItem(ChartsFactory.ChartTypes.TX_BPS_L2),
            createContextMenuItem(ChartsFactory.ChartTypes.RX_BPS_L2),
            createContextMenuItem(ChartsFactory.ChartTypes.PACKET_LOSS),
            new SeparatorMenuItem(),
            createContextMenuItem(ChartsFactory.ChartTypes.MAX_LATENCY, runningConfiguration.latencyEnabledProperty()),
            createContextMenuItem(ChartsFactory.ChartTypes.AVG_LATENCY, runningConfiguration.latencyEnabledProperty()),
            createContextMenuItem(ChartsFactory.ChartTypes.JITTER_LATENCY, runningConfiguration.latencyEnabledProperty()),
            createContextMenuItem(ChartsFactory.ChartTypes.TEMPORARY_MAX_LATENCY, runningConfiguration.latencyEnabledProperty()),
            createContextMenuItem(ChartsFactory.ChartTypes.LATENCY_HISTOGRAM, runningConfiguration.latencyEnabledProperty())
    );
}
 
Example #5
Source File: DisplayableListCell.java    From Quelea with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Provide a callback that sets the given context menu on each cell, if and
 * only if the constraint given passes. If the constraint is null, it will
 * always pass.
 * <p/>
 * @param <T> the generic type of the cell.
 * @param contextMenu the context menu to show.
 * @param cellFactory the cell factory to use.
 * @param constraint the constraint placed on showing the context menu - it
 * will only be shown if this constraint passes, or it is null.
 * @return a callback that sets the given context menu on each cell.
 */
public static <T> Callback<ListView<T>, ListCell<T>> forListView(final ContextMenu contextMenu, final Callback<ListView<T>, ListCell<T>> cellFactory,
        final Constraint<T> constraint) {
    return new Callback<ListView<T>, ListCell<T>>() {
        @Override
        public ListCell<T> call(ListView<T> listView) {
            final ListCell<T> cell = cellFactory == null ? new DefaultListCell<T>() : cellFactory.call(listView);
            cell.itemProperty().addListener(new ChangeListener<T>() {
                @Override
                public void changed(ObservableValue<? extends T> ov, T oldVal, T newVal) {
                    if(newVal == null || (constraint != null && !constraint.isTrue(newVal))) {
                        cell.setContextMenu(null);
                    }
                    else {
                        cell.setContextMenu(contextMenu);
                    }
                }
            });
            return cell;
        }
    };
}
 
Example #6
Source File: LyricsTextArea.java    From Quelea with GNU General Public License v3.0 6 votes vote down vote up
public LyricsTextArea() {
    textArea = new InlineCssTextArea();
    ContextMenu contextMenu = new ContextMenu();
    Clipboard systemClipboard = Clipboard.getSystemClipboard();
    MenuItem paste = new MenuItem(LabelGrabber.INSTANCE.getLabel("paste.label"));
    contextMenu.setOnShown(e -> {
        paste.setDisable(!systemClipboard.hasContent(DataFormat.PLAIN_TEXT));
    });

    paste.setOnAction(e -> {
        String clipboardText = systemClipboard.getString();
        textArea.insertText(textArea.getCaretPosition(), clipboardText);
    });

    contextMenu.getItems().add(paste);
    textArea.setContextMenu(contextMenu);
    textArea.textProperty().addListener((ObservableValue<? extends String> observable, String oldValue, String newValue) -> {
        Platform.runLater(this::refreshStyle);
    });

    textArea.setStyle("-fx-font-family: monospace; -fx-font-size: 10pt;");
    textArea.setUndoManager(UndoManagerFactory.zeroHistorySingleChangeUM(textArea.richChanges()));
    getChildren().add(new VirtualizedScrollPane<>(textArea));
    textArea.getStyleClass().add("text-area");
}
 
Example #7
Source File: WebViewContextMenuTest.java    From oim-fx with MIT License 6 votes vote down vote up
private void createContextMenu(WebView webView) {
	ContextMenu contextMenu = new ContextMenu();
	MenuItem reload = new MenuItem("Reload");
	reload.setOnAction(e -> webView.getEngine().reload());
	MenuItem savePage = new MenuItem("Save Page");
	savePage.setOnAction(e -> System.out.println("Save page..."));
	MenuItem hideImages = new MenuItem("Hide Images");
	hideImages.setOnAction(e -> System.out.println("Hide Images..."));
	contextMenu.getItems().addAll(reload, savePage, hideImages);

	webView.setOnMousePressed(e -> {
		if (e.getButton() == MouseButton.SECONDARY) {
			contextMenu.show(webView, e.getScreenX(), e.getScreenY());
		} else {
			contextMenu.hide();
		}
	});
}
 
Example #8
Source File: BytecodeContextHandling.java    From Recaf with MIT License 6 votes vote down vote up
private void handleVariableType(VariableSelection selection) {
	ContextMenu menu = new ContextMenu();
	Menu refs = new Menu(LangUtil.translate("ui.edit.method.referrers"));
	for (AST ast : root.getChildren()) {
		if (ast instanceof VarInsnAST && ((VarInsnAST) ast).getVariableName().getName().equals(selection.name)) {
			MenuItem ref = new ActionMenuItem(ast.getLine() + ": " + ast.print(), () -> {
				int line = ast.getLine() - 1;
				codeArea.moveTo(line, 0);
				codeArea.requestFollowCaret();
			});
			refs.getItems().add(ref);
		}
	}
	if (refs.getItems().isEmpty())
		refs.setDisable(true);
	menu.getItems().add(refs);
	codeArea.setContextMenu(menu);
}
 
Example #9
Source File: RequestTypeManager.java    From milkman with MIT License 6 votes vote down vote up
@SneakyThrows
private CompletableFuture<Optional<RequestTypePlugin>> getRequestTypePluginQuick(Node node) {
	List<RequestTypePlugin> requestTypePlugins = plugins.loadRequestTypePlugins();
	
	if (requestTypePlugins.size() == 0)
		throw new IllegalArgumentException("No RequestType plugins found");
	
	ContextMenu ctxMenu = new ContextMenu();
	CompletableFuture<RequestTypePlugin> f = new CompletableFuture<RequestTypePlugin>();
	requestTypePlugins.forEach(rtp -> {
		var itm = new MenuItem(rtp.getRequestType());
		itm.setOnAction(e -> {
			f.complete(rtp);
		});
		ctxMenu.getItems().add(itm);
	});
	ctxMenu.setOnCloseRequest(e -> f.complete(null));
	
	Point location = MouseInfo.getPointerInfo().getLocation();
	ctxMenu.show(node, location.getX(), location.getY());
	return f.thenApply(Optional::ofNullable);
}
 
Example #10
Source File: FXTree.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
private void createContextMenu()
{
    final ContextMenu menu = new ContextMenu();
    tree_view.setOnContextMenuRequested(event ->
    {
        menu.getItems().clear();
        if (ContextMenuHelper.addSupportedEntries(tree_view, menu))
            menu.getItems().add(new SeparatorMenuItem());
        menu.getItems().add(new PrintAction(tree_view));
        menu.getItems().add(new SaveSnapshotAction(tree_view));
        menu.getItems().add(new SendEmailAction(tree_view, "PV Snapshot", () -> "See attached screenshot.", () -> Screenshot.imageFromNode(tree_view)));
        menu.getItems().add(new SendLogbookAction(tree_view, "PV Snapshot", () -> "See attached screenshot.", () -> Screenshot.imageFromNode(tree_view)));
        menu.show(tree_view.getScene().getWindow(), event.getScreenX(), event.getScreenY());
    });
    tree_view.setContextMenu(menu);
}
 
Example #11
Source File: SwordController.java    From Sword_emulator with GNU General Public License v3.0 6 votes vote down vote up
public void onViewMemory(Event event) {
//        if (memoryStage == null) {
//            memoryStage = FxUtils.newStage(null, "内存查看",
//                    "memory.fxml", "main.css");
//        }
//        memoryStage.show();
//        memoryStage.toFront();
        if (machine.getRomFile() == null) {
            onViewRAM(event);
        } else {
            MenuItem ramViewItem = new MenuItem("查看RAM");
            ramViewItem.setOnAction(event1 -> onViewRAM(event1));
            MenuItem romViewItem = new MenuItem("查看ROM");
            romViewItem.setOnAction(event1 -> onViewROM(event1));
            new ContextMenu(ramViewItem, romViewItem).show(memoryButton, Side.TOP, 0, 0);
        }

    }
 
Example #12
Source File: WaveformView.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
private void createContextMenu()
{
    final ContextMenu menu = new ContextMenu();
    plot.setOnContextMenuRequested(event ->
    {
        menu.getItems().setAll(new ToggleToolbarMenuItem(plot));

        final List<Trace<Double>> traces = new ArrayList<>();
        plot.getTraces().forEach(traces::add);
        if (! traces.isEmpty())
            menu.getItems().add(new ToggleLinesMenuItem(plot, traces));


        menu.getItems().addAll(new SeparatorMenuItem(),
                               new PrintAction(plot),
                               new SaveSnapshotAction(plot));

        menu.show(getScene().getWindow(), event.getScreenX(), event.getScreenY());
    });
}
 
Example #13
Source File: SearchView.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
private void updateContextMenu(final ContextMenuEvent event)
{
    final ContextMenu menu = channel_table.getContextMenu();
    final List<ChannelInfo> selection = channel_table.getSelectionModel().getSelectedItems();
    if (selection.isEmpty())
        menu.getItems().clear();
    else
    {
        menu.getItems().setAll(new AddToPlotAction(channel_table, model, undo, selection),
                               new SeparatorMenuItem());

        SelectionService.getInstance().setSelection(channel_table, selection);
        ContextMenuHelper.addSupportedEntries(channel_table, menu);
        menu.show(channel_table.getScene().getWindow(), event.getScreenX(), event.getScreenY());
    }
}
 
Example #14
Source File: MyBoxController.java    From MyBox with Apache License 2.0 6 votes vote down vote up
@FXML
private void showRecentMenu(MouseEvent event) {
    hideMenu(event);

    popMenu = new ContextMenu();
    popMenu.setAutoHide(true);
    popMenu.getItems().addAll(getRecentMenu());

    popMenu.getItems().add(new SeparatorMenuItem());
    MenuItem closeMenu = new MenuItem(message("MenuClose"));
    closeMenu.setStyle("-fx-text-fill: #2e598a;");
    closeMenu.setOnAction((ActionEvent cevent) -> {
        popMenu.hide();
        popMenu = null;
    });
    popMenu.getItems().add(closeMenu);

    showMenu(recentBox, event);

    view.setImage(new Image("img/RecentAccess.png"));
    text.setText(message("RecentAccessImageTips"));
    locateImage(recentBox, true);
}
 
Example #15
Source File: AxesTab.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
private void createContextMenu()
{
    final MenuItem add_axis = new MenuItem(Messages.AddAxis, Activator.getIcon("add"));
    add_axis.setOnAction(event -> new AddAxisCommand(undo, model));

    final ContextMenu menu = new ContextMenu();
    axes_table.setOnContextMenuRequested(event ->
    {
        final ObservableList<MenuItem> items = menu.getItems();
        items.setAll(add_axis);

        final List<AxisConfig> selection = axes_table.getSelectionModel().getSelectedItems();

        if (selection.size() > 0)
            items.add(new DeleteAxes(axes_table, model, undo, selection));

        if (model.getEmptyAxis().isPresent())
            items.add(new RemoveUnusedAxes(model, undo));

        menu.show(axes_table.getScene().getWindow(), event.getScreenX(), event.getScreenY());
    });
}
 
Example #16
Source File: BrokerConfigView.java    From kafka-message-tool with MIT License 6 votes vote down vote up
private void bindPopupMenuToSelectedRow(KafkaClusterProxy proxy, TableRow<TopicAggregatedSummary> row) {

        final MenuItem deleteTopicMenuItem = createMenuItemForDeletingTopic();
        final MenuItem createTopicMenuItem = createMenuItemForCreatingNewTopic();
        final MenuItem alterTopicMenuItem = createMenuItemForAlteringTopic();
        final MenuItem topicPropertiesMenuItem = createMenuItemForShowingTopicProperties();

        final ContextMenu contextMenu = getTopicManagementContextMenu(deleteTopicMenuItem,
                                                                      createTopicMenuItem,
                                                                      alterTopicMenuItem,
                                                                      topicPropertiesMenuItem);

        row.contextMenuProperty().bind(new ReadOnlyObjectWrapper<>(contextMenu));
        topicPropertiesMenuItem.disableProperty().bind(row.emptyProperty());

        if (proxy.isTopicDeletionEnabled() != TriStateConfigEntryValue.True) {
            deleteTopicMenuItem.setText("Delete topic (disabled by broker)");
            deleteTopicMenuItem.disableProperty().setValue(true);
        } else {
            deleteTopicMenuItem.disableProperty().bind(row.emptyProperty());
        }
        alterTopicMenuItem.disableProperty().bind(row.emptyProperty());
    }
 
Example #17
Source File: PVList.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
private void createContextMenu()
{
    // Publish selected items as PV
    final ListChangeListener<PVInfo> sel_changed = change ->
    {
        final List<ProcessVariable> pvs = change.getList()
                                                .stream()
                                                .map(info -> new ProcessVariable(info.name.get()))
                                                .collect(Collectors.toList());
        SelectionService.getInstance().setSelection(PVListApplication.DISPLAY_NAME, pvs);
    };
    table.getSelectionModel().getSelectedItems().addListener(sel_changed);
    table.getSelectionModel().setSelectionMode(SelectionMode.MULTIPLE);

    // Context menu with selection-based entries, i.e. PV contributions
    final ContextMenu menu = new ContextMenu();
    table.setOnContextMenuRequested(event ->
    {
        menu.getItems().clear();
        ContextMenuHelper.addSupportedEntries(table, menu);
        menu.show(table.getScene().getWindow());
    });
    table.setContextMenu(menu);
}
 
Example #18
Source File: EyePhotoPairNode.java    From Augendiagnose with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Create the context menu for the date.
 *
 * @return the context menu.
 */
private ContextMenu createDateContextMenu() {
	ContextMenu menu = new ContextMenu();

	MenuItem menuItemRemove = new MenuItem();
	menuItemRemove.setText(ResourceUtil.getString(ResourceConstants.MENU_DELETE_IMAGES));

	menuItemRemove.setOnAction(new EventHandler<ActionEvent>() {
		@Override
		public void handle(final ActionEvent event) {
			DialogUtil.displayConfirmationMessage(new ConfirmDialogListener() {

				@Override
				public void onDialogPositiveClick() {
					mParentController.removeItem(EyePhotoPairNode.this);
					mPair.delete();
				}

				@Override
				public void onDialogNegativeClick() {
					// do nothing
				}
			}, ResourceConstants.BUTTON_DELETE,
					ResourceConstants.MESSAGE_DIALOG_CONFIRM_DELETE_DATE, mPair.getPersonName(), mLabelDate.getText());
		}
	});
	menu.getItems().add(menuItemRemove);

	return menu;
}
 
Example #19
Source File: LineView.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
private void addContextMenu()
{
    final MenuItem copy = new MenuItem("Copy");
    copy.setOnAction(event -> copy());

    final MenuItem clear = new MenuItem("Clear");
    clear.setOnAction(event -> clear());

    final ContextMenu menu = new ContextMenu(copy, clear);
    list.setContextMenu(menu);
}
 
Example #20
Source File: ContextMenuTests.java    From RichTextFX with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void start(Stage stage) throws Exception {
    super.start(stage);
    menu = new ContextMenu(new MenuItem("A menu item"));
    area.setContextMenu(menu);
    area.setContextMenuXOffset(offset);
    area.setContextMenuYOffset(offset);
}
 
Example #21
Source File: AlarmTableUI.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
private void createContextMenu(final TableView<AlarmInfoRow> table, final boolean active)
{
    final ContextMenu menu = new ContextMenu();
    table.setOnContextMenuRequested(event ->
    {
        final ObservableList<MenuItem> menu_items = menu.getItems();
        menu_items.clear();

        final List<AlarmTreeItem<?>> selection = new ArrayList<>();
        for (AlarmInfoRow row : table.getSelectionModel().getSelectedItems())
            selection.add(row.item);

        // Add guidance etc.
        new AlarmContextMenuHelper().addSupportedEntries(table, client, menu, selection);
        if (menu_items.size() > 0)
            menu_items.add(new SeparatorMenuItem());

        if (AlarmUI.mayConfigure(client)  &&   selection.size() == 1)
        {
            menu_items.add(new ConfigureComponentAction(table, client, selection.get(0)));
            menu_items.add(new SeparatorMenuItem());
        }
        menu_items.add(new PrintAction(this));
        menu_items.add(new SaveSnapshotAction(table));
        menu_items.add(new SendEmailAction(table, "Alarm Snapshot", this::list_alarms, () -> Screenshot.imageFromNode(this)));
        menu_items.add(new SendLogbookAction(table, "Alarm Snapshot", this::list_alarms, () -> Screenshot.imageFromNode(this)));

        menu.show(table.getScene().getWindow(), event.getScreenX(), event.getScreenY());
    });
}
 
Example #22
Source File: UICanvasEditor.java    From arma-dialog-creator with MIT License 5 votes vote down vote up
private void updateContextMenu() {
	ContextMenu cm = getContextMenu();

	if (cm != null && cm.isShowing()) {
		if (mouseOverNode != contextMenuControl && cm != canvasContextMenu) {
			cm.hide();
		} else if (cm == canvasContextMenu && mouseOverNode != null) {
			cm.hide();
		}
	}
}
 
Example #23
Source File: ListenerConfigView.java    From kafka-message-tool with MIT License 5 votes vote down vote up
private void addAdditionalEntryToConfigNameContextMenu() {
    TextFieldSkin customContextSkin = new TextFieldSkin(listenerNameTextField) {
        @Override
        public void populateContextMenu(ContextMenu contextMenu) {
            super.populateContextMenu(contextMenu);
            contextMenu.getItems().add(0, new SeparatorMenuItem());
            contextMenu.getItems().add(0, generateNameMenuItem);
        }
    };
    listenerNameTextField.setSkin(customContextSkin);

}
 
Example #24
Source File: ChannelTreeController.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
@FXML
public void createContextMenu() {

    final ContextMenu contextMenu = new ContextMenu();

    List<ContextMenuEntry> contextEntries = ContextMenuService.getInstance().listSupportedContextMenuEntries();
    contextEntries.forEach(entry -> {
        MenuItem item = new MenuItem(entry.getName(), new ImageView(entry.getIcon()));
        item.setOnAction(e -> {
            try {
                SelectionService.getInstance().getSelection();
                ObservableList<TreeItem<ChannelTreeByPropertyNode>> old = treeTableView.getSelectionModel()
                        .getSelectedItems();

                List<Object> supportedTypes = SelectionService.getInstance().getSelection().getSelections().stream()
                        .map(s -> {
                            return AdapterService.adapt(s, entry.getSupportedType()).get();
                        }).collect(Collectors.toList());
                // set the selection
                SelectionService.getInstance().setSelection(treeTableView, supportedTypes);
                entry.call(SelectionService.getInstance().getSelection());
                // reset the selection
                SelectionService.getInstance().setSelection(treeTableView, old);
            } catch (Exception ex) {
                logger.log(Level.WARNING, "Failed to execute action " + entry.getName(), ex);
            }
        });
        contextMenu.getItems().add(item);
    });

    treeTableView.setContextMenu(contextMenu);
}
 
Example #25
Source File: DisplayEditorInstance.java    From phoebus with Eclipse Public License 1.0 5 votes vote down vote up
DisplayEditorInstance(final DisplayEditorApplication app)
{
    this.app = app;

    final DockPane dock_pane = DockPane.getActiveDockPane();
    JFXRepresentation.setSceneStyle(dock_pane.getScene());
    EditorUtil.setSceneStyle(dock_pane.getScene());

    editor_gui = new EditorGUI();

    extendToolbar();

    dock_item = new DockItemWithInput(this, editor_gui.getParentNode(), null, FilenameSupport.file_extensions, this::doSave);
    dock_pane.addTab(dock_item);

    // Update tab's title when model has been loaded
    editor_gui.setModelListener(this::handleNewModel);

    // Mark 'dirty' whenever there's a change, i.e. something to un-do
    editor_gui.getDisplayEditor()
              .getUndoableActionManager()
              .addListener((to_undo, to_redo) -> dock_item.setDirty(to_undo != null));

    final ContextMenu menu = new ContextMenu();
    final Control menu_node = editor_gui.getDisplayEditor().getContextMenuNode();
    menu_node.setOnContextMenuRequested(event -> handleContextMenu(menu, event));
    menu_node.setContextMenu(menu);

    dock_item.addCloseCheck(this::okToClose);
    dock_item.addClosedNotification(this::dispose);
}
 
Example #26
Source File: ChartViewer.java    From jfreechart-fx with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Creates the context menu.
 * 
 * @return The context menu.
 */
private ContextMenu createContextMenu() {
    final ContextMenu menu = new ContextMenu();
    menu.setAutoHide(true);
    Menu export = new Menu("Export As");
    
    MenuItem pngItem = new MenuItem("PNG...");
    pngItem.setOnAction(e -> handleExportToPNG());        
    export.getItems().add(pngItem);
    
    MenuItem jpegItem = new MenuItem("JPEG...");
    jpegItem.setOnAction(e -> handleExportToJPEG());        
    export.getItems().add(jpegItem);
    
    if (ExportUtils.isOrsonPDFAvailable()) {
        MenuItem pdfItem = new MenuItem("PDF...");
        pdfItem.setOnAction(e -> handleExportToPDF());
        export.getItems().add(pdfItem);
    }
    if (ExportUtils.isJFreeSVGAvailable()) {
        MenuItem svgItem = new MenuItem("SVG...");
        svgItem.setOnAction(e -> handleExportToSVG());
        export.getItems().add(svgItem);        
    }
    menu.getItems().add(export);
    return menu;
}
 
Example #27
Source File: TabDockingContainer.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private void populateMenuItems(ContextMenu contextMenu, Tab tab) {
    int tabCount = getTabs().size();
    int tabIndex = getTabs().indexOf(tab);
    ObservableList<MenuItem> items = contextMenu.getItems();
    items.clear();
    MenuItem closeMenuItem = new MenuItem("Close");
    closeMenuItem.setOnAction((e) -> requestClose(tab));
    items.add(closeMenuItem);
    if (tabCount > 1) {
        MenuItem closeRestMenuItem = new MenuItem("Close Others");
        closeRestMenuItem.setOnAction((e) -> closeOtherTabs(tab));
        items.add(closeRestMenuItem);
    }
    if (tabCount > 1 && tabIndex != 0) {
        MenuItem closeLeftTabsMenuItem = new MenuItem("Close Tabs to the Left");
        closeLeftTabsMenuItem.setOnAction((e) -> closeTabsToLeft(tab));
        items.add(closeLeftTabsMenuItem);
    }
    if (tabCount > 1 && tabIndex != tabCount - 1) {
        MenuItem closeRigthTabsMenuItem = new MenuItem("Close Tabs to the Right");
        closeRigthTabsMenuItem.setOnAction((e) -> closeTabsToRight(tab));
        items.add(closeRigthTabsMenuItem);
    }
    if (tabCount > 1) {
        MenuItem closeAllMenuItem = new MenuItem("Close All");
        closeAllMenuItem.setOnAction((e) -> closeAllTabs());
        items.addAll(new SeparatorMenuItem(), closeAllMenuItem);
    }
}
 
Example #28
Source File: MyTreeItem.java    From MythRedisClient with Apache License 2.0 5 votes vote down vote up
/**
 * 设置所有孩子节点的上下文菜单.
 * @param menu 上下文菜单
 */
public void setNextContextMenu(ContextMenu menu) {
    ObservableList<TreeItem<T>> items = this.getChildren();
    for (TreeItem item : items) {
        ((Label)item.getValue()).setContextMenu(menu);
    }
}
 
Example #29
Source File: TagBoard.java    From OpenLabeler with Apache License 2.0 5 votes vote down vote up
private void onContextMenuEvent(ContextMenuEvent event) {
   ObjectTag selected = selectedObjectProperty.get();
   if (selected == null) {
      return;
   }
   contextMenu = new ContextMenu();
   for (int i = 0; i < 10 && i < Settings.recentNamesProperty.size(); i++) {
      NameColor nameColor = Settings.recentNamesProperty.get(i);
      String name = nameColor.getName();
      if (name.isEmpty() || name.isBlank()) {
         continue;
      }
      MenuItem mi = new MenuItem(name);
      mi.setOnAction(value -> {
         selected.nameProperty().set(name);
         Settings.recentNamesProperty.addName(name);
      });
      contextMenu.getItems().add(mi);
   }
   if (!contextMenu.getItems().isEmpty()) {
      contextMenu.getItems().add(new SeparatorMenuItem());
   }
   MenuItem editName = new MenuItem(bundle.getString("menu.editName"));
   editName.setOnAction(value -> {
      NameEditor editor = new NameEditor(selected.nameProperty().get());
      String label = editor.showPopup(event.getScreenX(), event.getScreenY(), getScene().getWindow());
      selected.nameProperty().set(label);
      Settings.recentNamesProperty.addName(label);
   });
   MenuItem delete = new MenuItem(bundle.getString("menu.delete"));
   delete.setOnAction(value -> deleteSelected(bundle.getString("menu.delete")));
   contextMenu.getItems().addAll(editName, delete);
   contextMenu.setAutoHide(true);
   contextMenu.show(imageView, event.getScreenX(), event.getScreenY());
   event.consume();
}
 
Example #30
Source File: PrefixField.java    From pdfsam with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * @param placeholder
 *            default value for the text field. If null or empty a fallback is used
 */
public PrefixField(String placeholder) {
    super(ofNullable(placeholder).filter(StringUtils::isNotEmpty).orElse("PDFsam_"));
    this.setPromptText(DefaultI18nContext.getInstance().i18n("Prefix for the generated files names"));
    this.menu = new Menu(DefaultI18nContext.getInstance().i18n("Add prefix"));
    this.menu.setId("addPrefixMenu");
    this.menu.getItems().addAll(new PrefixMenuItem(Prefix.TIMESTAMP), new PrefixMenuItem(Prefix.BASENAME));
    this.setContextMenu(new ContextMenu(this.menu));
    setPrefWidth(300);
}