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

The following examples show how to use javafx.scene.control.Tab#setOnClosed() . 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: FxDockTabPane.java    From FxDock with Apache License 2.0 6 votes vote down vote up
protected Tab newTab(Node nd)
{
	Node n = DockTools.prepareToAdd(nd);
		
	Tab t = new Tab(null, n);
	if(n instanceof FxDockPane)
	{
		FxDockPane p = (FxDockPane)n;
		t.setGraphic(p.titleField);
		t.setOnClosed((ev) -> 
		{
			Node pp = DockTools.getParent(this);
			DockTools.collapseEmptySpace(pp);
		});
	}
	return t;
}
 
Example 2
Source File: AllFilesViewerController.java    From standalone-app with Apache License 2.0 6 votes vote down vote up
private void openNewEditor(Tab fileTab, EditorView editor) {
    FileTabProperties properties = (FileTabProperties) fileTab.getUserData();
    TabPane filePane = (TabPane) fileTab.getContent();
    if (properties.getOpenedEditors().containsKey(editor.getDisplayName())) {
        Tab tab = properties.getOpenedEditors().get(editor.getDisplayName());
        filePane.getSelectionModel().select(tab);
        return;
    }
    Tab editorTab = new Tab(editor.getDisplayName());
    editorTab.setContent(editor.createView(properties.getFile(), properties.getPath()));
    editorTab.setOnClosed(event -> {
        properties.getOpenedEditors().remove(editor.getDisplayName());
    });
    filePane.getTabs().add(editorTab);
    filePane.getSelectionModel().select(editorTab);
    properties.getOpenedEditors().put(editor.getDisplayName(), editorTab);
}
 
Example 3
Source File: WebBrowserController.java    From MyBox with Apache License 2.0 5 votes vote down vote up
protected WebBrowserBoxController newTabAction(String address, boolean focus) {
    try {
        FXMLLoader fxmlLoader = new FXMLLoader(FxmlStage.class.getResource(
                CommonValues.WebBrowserBoxFxml), AppVariables.currentBundle);
        Pane pane = fxmlLoader.load();
        Tab tab = new Tab();
        ImageView tabImage = new ImageView("img/MyBox.png");
        tabImage.setFitWidth(20);
        tabImage.setFitHeight(20);
        tab.setGraphic(tabImage);
        tab.setContent(pane);
        tabPane.getTabs().add(tab);
        if (focus) {
            tabPane.getSelectionModel().select(tab);
        }

        WebBrowserBoxController controller = (WebBrowserBoxController) fxmlLoader.getController();
        controller.parent = this;
        controller.tab = tab;
        tabControllers.put(tab, controller);
        tab.setOnClosed(new EventHandler<Event>() {
            @Override
            public void handle(Event event) {
                tabControllers.remove(tab);
            }
        });

        if (address != null) {
            controller.loadLink(address);
        }
        return controller;

    } catch (Exception e) {
        logger.error(e.toString());
        return null;
    }
}
 
Example 4
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;
}
 
Example 5
Source File: ViewportTabs.java    From Recaf with MIT License 5 votes vote down vote up
private Tab createTab(String name, EditorViewport view) {
	// Normalize name
	String title = name;
	if(title.contains("/"))
		title = title.substring(title.lastIndexOf("/") + 1);
	Tab tab = new Tab(title, view);
	tab.setClosable(true);
	// Name lookup
	tab.setOnClosed(o -> nameToTab.remove(name));
	nameToTab.put(name, tab);
	// Add and return
	getTabs().add(tab);
	return tab;
}
 
Example 6
Source File: Perspective.java    From phoebus with Eclipse Public License 1.0 4 votes vote down vote up
public Perspective(final boolean minimal)
{
    property_panel = new PropertyPanel(model, plot.getPlot().getUndoableActionManager());
    properties_tab = new Tab(Messages.PropertiesTabName, property_panel);
    properties_tab.setGraphic(Activator.getIcon("properties"));
    properties_tab.setOnClosed(event ->
    {
        // Update pref that properties were last closed
        prefs.putBoolean(SHOW_PROPERTIES, false);
        autoMinimizeBottom();
    });

    if (! minimal)
    {
        // Check preferences
        if (prefs.getBoolean(SHOW_PROPERTIES, true))
            bottom_tabs.getTabs().setAll(properties_tab);
    }

    plot_and_tabs.setOrientation(Orientation.VERTICAL);
    plot_and_tabs.setDividerPositions(0.8);

    getItems().setAll(left_tabs, plot_and_tabs);
    setDividerPositions(0.2);

    createContextMenu();
    setupDrop();

    controller = new Controller(model, plot);
    try
    {
        controller.start();
    }
    catch (Exception ex)
    {
        logger.log(Level.SEVERE, "Cannot start data browser", ex);
    }

    // As pane is resized, assert that the minimzed left or bottom region stays minimized
    widthProperty().addListener(prop -> Platform.runLater(() -> autoMinimizeLeft()));
    heightProperty().addListener(prop -> Platform.runLater(() -> autoMinimizeBottom()));
}
 
Example 7
Source File: AllFilesViewerController.java    From standalone-app with Apache License 2.0 4 votes vote down vote up
private void constructFileTab(TreeNode node) {
        String uniqueKey = generateKey(node);

        if (fileTabs.containsKey(uniqueKey)) {
            // Already opened, and you double clicked. Let's just bring the focus to it

            Tab pane = fileTabs.get(uniqueKey);
            root.getSelectionModel().select(pane);
            return;
        }

        OpenedFile file = (OpenedFile) node.getMetadata().get(OpenedFile.OPENED_FILE);

        EditorView defaultTransformer = StandardEditors.HEX;

//        String extension = node.getDisplayName();
//        if (extension.lastIndexOf('.') != -1) {
//            extension = extension.substring(extension.lastIndexOf('.') + 1, extension.length());
//        }
//        JsonValue star = Settings.FILETYPE_ASSOCIATIONS.get().asObject().get(".*");
//        for (JsonObject.Member member : Settings.FILETYPE_ASSOCIATIONS.get().asObject()) {
//            if (member.getName().equals(extension)) {
//                if (defaultTransformer == null) {
//                    defaultTransformer = Transformer.getById(member.getValue().asString());
//                }
//            }
//        }
//        if (defaultTransformer == null && star != null) {
//            defaultTransformer = Transformer.getById(star.asString());
//        }
//        if (defaultTransformer == null) {
//            defaultTransformer = Transformer.HEX;
//        }

        try {
            GuiceFXMLLoader.Result tabResult = loader.load(getClass().getResource("/views/fileViewer.fxml"));
            TabPane fileTabPane = tabResult.getRoot();
            Tab allFilesTab = new Tab(node.getDisplayName());
            allFilesTab.setContent(fileTabPane);
            allFilesTab.setUserData(new FileTabProperties(file, (String) node.getMetadata().get(OpenedFile.FULL_PATH_KEY)));
            allFilesTab.setOnClosed(event -> {
                fileTabs.remove(uniqueKey);
            });

            fileTabs.put(uniqueKey, allFilesTab);

            root.getTabs().add(allFilesTab);
            root.getSelectionModel().select(allFilesTab);

            openNewEditor(allFilesTab, defaultTransformer);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }