Java Code Examples for javafx.scene.control.Tab#setContextMenu()

The following examples show how to use javafx.scene.control.Tab#setContextMenu() . 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: ViewportTabs.java    From Recaf with MIT License 6 votes vote down vote up
/**
 * @param resource
 * 		Resource containing the class.
 * @param name
 * 		Name of class to open.
 *
 * @return Viewport of the class.
 */
public ClassViewport openClass(JavaResource resource, String name) {
	if(nameToTab.containsKey(name))
		return getClassViewport(name);
	// Create new tab
	ClassViewport view = new ClassViewport(controller, resource, name);
	view.updateView();
	Tab tab = createTab(name, view);
	int access = ClassUtil.getAccess(resource.getClasses().get(name));
	tab.setGraphic(UiUtil.createClassGraphic(access));
	// Setup context menu
	tab.setContextMenu(ContextBuilder.menu().view(view).ofClassTab());
	// Select & return
	select(tab);
	return view;
}
 
Example 2
Source File: ViewportTabs.java    From Recaf with MIT License 6 votes vote down vote up
/**
 * @param resource
 * 		Resource containing the resource.
 * @param name
 * 		Name of resource to open.
 *
 * @return Viewport of the file.
 */
public FileViewport openFile(JavaResource resource, String name) {
	if(nameToTab.containsKey(name)) {
		return getFileViewport(name);
	}
	// Create new tab
	FileViewport view = new FileViewport(controller, resource, name);
	view.updateView();
	Tab tab = createTab(name, view);
	BorderPane wrap = new BorderPane(UiUtil.createFileGraphic(name));
	UiUtil.createFileGraphic(name).fitWidthProperty().bind(wrap.widthProperty());
	tab.setGraphic(wrap);
	// Setup context menu
	tab.setContextMenu(ContextBuilder.menu().view(view).ofFileTab());
	// Select and return
	select(tab);
	return view;
}
 
Example 3
Source File: TabDockingContainer.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private Tab newTab(Dockable dockable) {
    DockKey dockKey = dockable.getDockKey();
    Tab tab = new Tab(dockKey.getName(), dockable.getComponent());
    if (dockKey.getPolicy() == TabPolicy.NotClosable) {
        tab.setClosable(false);
    }
    if (dockKey.isCloseOptionsNeeded()) {
        MenuItem closeMenuItem = new MenuItem("Close");
        closeMenuItem.setOnAction((e) -> requestClose(tab));
        ContextMenu contextMenu = new ContextMenu(closeMenuItem);
        contextMenu.showingProperty().addListener((obs, wasShowing, isNowShowing) -> {
            if (isNowShowing) {
                populateMenuItems(contextMenu, tab);
            }
        });
        tab.setContextMenu(contextMenu);
    }
    dockKey.nameProperty().addListener((event, o, n) -> tab.setText(n));
    tab.setOnClosed((event) -> {
        remove(dockable);
    });
    tab.setGraphic(dockKey.getIcon());
    tab.setOnCloseRequest((event) -> {
        desktop.fireDockableStateWillChangeEvent(dockable, State.DOCKED, State.CLOSED, event);
    });
    return tab;
}