Search in sources :

Example 1 with DockPane

use of org.phoebus.ui.docking.DockPane in project phoebus by ControlSystemStudio.

the class PhoebusApplication method createMenu.

private MenuBar createMenu(final Stage stage) {
    final MenuBar menuBar = new MenuBar();
    // For Mac OS X, use it's menu bar on top of screen
    if (PlatformInfo.is_mac_os_x)
        menuBar.setUseSystemMenuBar(true);
    // File
    final MenuItem open = new MenuItem(Messages.Open, ImageCache.getImageView(getClass(), "/icons/fldr_obj.png"));
    open.setOnAction(event -> fileOpen(stage, false));
    final MenuItem open_with = new MenuItem(Messages.OpenWith, ImageCache.getImageView(getClass(), "/icons/fldr_obj.png"));
    open_with.setOnAction(event -> fileOpen(stage, true));
    top_resources_menu = new Menu(Messages.TopResources, ImageCache.getImageView(getClass(), "/icons/fldr_obj.png"));
    top_resources_menu.setDisable(true);
    final MenuItem file_save = new MenuItem(Messages.Save, ImageCache.getImageView(getClass(), "/icons/save_edit.png"));
    file_save.setOnAction(event -> JobManager.schedule(Messages.Save, monitor -> active_item_with_input.get().save(monitor)));
    final MenuItem file_save_as = new MenuItem(Messages.SaveAs, ImageCache.getImageView(getClass(), "/icons/saveas_edit.png"));
    file_save_as.setOnAction(event -> JobManager.schedule(Messages.SaveAs, monitor -> active_item_with_input.get().save_as(monitor)));
    final MenuItem exit = new MenuItem(Messages.Exit);
    exit.setOnAction(event -> closeMainStage());
    final Menu file = new Menu(Messages.File, null, open, open_with, top_resources_menu, new SeparatorMenuItem(), file_save, file_save_as, new SeparatorMenuItem(), exit);
    file.setOnShowing(event -> {
        final DockItemWithInput input_item = active_item_with_input.get();
        if (input_item == null) {
            file_save.setDisable(true);
            file_save_as.setDisable(true);
        } else {
            file_save.setDisable(!input_item.isDirty());
            file_save_as.setDisable(!input_item.isSaveAsSupported());
        }
    });
    menuBar.getMenus().add(file);
    // Application Contributions
    final Menu applicationsMenu = new Menu(Messages.Applications);
    final MenuTreeNode node = MenuEntryService.getInstance().getMenuEntriesTree();
    addMenuNode(applicationsMenu, node);
    menuBar.getMenus().add(applicationsMenu);
    // Window
    show_tabs = new CheckMenuItem(Messages.AlwaysShowTabs);
    show_tabs.setSelected(DockPane.isAlwaysShowingTabs());
    show_tabs.setOnAction(event -> DockPane.alwaysShowTabs(show_tabs.isSelected()));
    show_toolbar = new CheckMenuItem(Messages.ShowToolbar);
    show_toolbar.setOnAction(event -> showToolbar(show_toolbar.isSelected()));
    show_statusbar = new CheckMenuItem(Messages.ShowStatusbar);
    show_statusbar.setOnAction(event -> showStatusbar(show_statusbar.isSelected()));
    save_layout = new SaveLayoutMenuItem(this, memento_files);
    delete_layouts = new DeleteLayoutsMenuItem(this, memento_files);
    final Menu menu = new Menu(Messages.Window, null, show_tabs, show_toolbar, show_statusbar, new SeparatorMenuItem(), selectTabMenu, closeAllTabsMenuItem, new SeparatorMenuItem(), save_layout, load_layout, delete_layouts, new SeparatorMenuItem(), /* Full Screen placeholder */
    new FullScreenAction(stage));
    // Update Full screen action when shown to get correct enter/exit FS mode
    menu.setOnShowing(event -> {
        // Last menu item
        final int full_screen_index = menu.getItems().size() - 1;
        final FullScreenAction full_screen = new FullScreenAction(stage);
        if (!AuthorizationService.hasAuthorization("full_screen"))
            full_screen.setDisable(true);
        menu.getItems().set(full_screen_index, full_screen);
    });
    menuBar.getMenus().add(menu);
    // Help
    final MenuItem content = createMenuItem(new OpenHelp());
    final MenuItem about = createMenuItem(new OpenAbout());
    menuBar.getMenus().add(new Menu(Messages.Help, null, about, content));
    selectTabMenu.getParentMenu().setOnShowing(e -> {
        List<MenuItem> menuItems = new ArrayList<>();
        for (Stage s : DockStage.getDockStages()) {
            for (DockPane dockPane : DockStage.getDockPanes(s)) {
                for (DockItem dockItem : dockPane.getDockItems()) {
                    CheckMenuItem menuItem = new CheckMenuItem(dockItem.getLabel());
                    menuItem.setSelected(dockItem.isSelected());
                    menuItem.setOnAction(ae -> dockItem.select());
                    menuItems.add(menuItem);
                }
            }
        }
        menuItems.sort(Comparator.comparing(MenuItem::getText));
        selectTabMenu.getItems().clear();
        selectTabMenu.getItems().addAll(menuItems);
    });
    closeAllTabsMenuItem.setOnAction(ae -> closeAllTabs());
    return menuBar;
}
Also used : Button(javafx.scene.control.Button) JobManager(org.phoebus.framework.jobs.JobManager) Arrays(java.util.Arrays) CheckMenuItem(javafx.scene.control.CheckMenuItem) DockPaneListener(org.phoebus.ui.docking.DockPaneListener) VBox(javafx.scene.layout.VBox) KeyCombination(javafx.scene.input.KeyCombination) Preferences(org.phoebus.ui.Preferences) Application(javafx.application.Application) FullScreenAction(org.phoebus.ui.javafx.FullScreenAction) MenuTreeNode(org.phoebus.ui.application.MenuEntryService.MenuTreeNode) AlertType(javafx.scene.control.Alert.AlertType) Map(java.util.Map) DockPane(org.phoebus.ui.docking.DockPane) URI(java.net.URI) Alert(javafx.scene.control.Alert) MenuEntry(org.phoebus.ui.spi.MenuEntry) ImageCache(org.phoebus.ui.javafx.ImageCache) ResponsivenessMonitor(org.phoebus.ui.monitoring.ResponsivenessMonitor) MenuItem(javafx.scene.control.MenuItem) OpenHelp(org.phoebus.ui.help.OpenHelp) Collection(java.util.Collection) AppDescriptor(org.phoebus.framework.spi.AppDescriptor) Logger(java.util.logging.Logger) Collectors(java.util.stream.Collectors) Platform(javafx.application.Platform) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) List(java.util.List) SubJobMonitor(org.phoebus.framework.jobs.SubJobMonitor) MenuButton(javafx.scene.control.MenuButton) AppResourceDescriptor(org.phoebus.framework.spi.AppResourceDescriptor) Optional(java.util.Optional) BorderPane(javafx.scene.layout.BorderPane) Welcome(org.phoebus.ui.welcome.Welcome) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) DialogHelper(org.phoebus.ui.dialog.DialogHelper) ButtonType(javafx.scene.control.ButtonType) MouseEvent(javafx.scene.input.MouseEvent) JobMonitor(org.phoebus.framework.jobs.JobMonitor) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HashMap(java.util.HashMap) AuthorizationService(org.phoebus.security.authorization.AuthorizationService) ApplicationService(org.phoebus.framework.workbench.ApplicationService) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) StatusBar(org.phoebus.ui.statusbar.StatusBar) ResourceParser(org.phoebus.framework.util.ResourceParser) OpenFileDialog(org.phoebus.ui.dialog.OpenFileDialog) WeakReference(java.lang.ref.WeakReference) Tooltip(javafx.scene.control.Tooltip) DockItemWithInput(org.phoebus.ui.docking.DockItemWithInput) MementoHelper(org.phoebus.ui.internal.MementoHelper) KeyCode(javafx.scene.input.KeyCode) ListPickerDialog(org.phoebus.ui.dialog.ListPickerDialog) Dialog(javafx.scene.control.Dialog) MenuBar(javafx.scene.control.MenuBar) PlatformInfo(org.phoebus.ui.javafx.PlatformInfo) Iterator(java.util.Iterator) ToolBar(javafx.scene.control.ToolBar) DockStage(org.phoebus.ui.docking.DockStage) Node(javafx.scene.Node) MementoTree(org.phoebus.framework.persistence.MementoTree) DockItem(org.phoebus.ui.docking.DockItem) OpenAbout(org.phoebus.ui.help.OpenAbout) FileInputStream(java.io.FileInputStream) File(java.io.File) Menu(javafx.scene.control.Menu) KeyCodeCombination(javafx.scene.input.KeyCodeCombination) TimeUnit(java.util.concurrent.TimeUnit) ActionEvent(javafx.event.ActionEvent) Stage(javafx.stage.Stage) XMLMementoTree(org.phoebus.framework.persistence.XMLMementoTree) ImageView(javafx.scene.image.ImageView) Window(javafx.stage.Window) Locations(org.phoebus.framework.workbench.Locations) Comparator(java.util.Comparator) Image(javafx.scene.image.Image) DockPane(org.phoebus.ui.docking.DockPane) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) MenuBar(javafx.scene.control.MenuBar) FullScreenAction(org.phoebus.ui.javafx.FullScreenAction) CheckMenuItem(javafx.scene.control.CheckMenuItem) MenuItem(javafx.scene.control.MenuItem) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) MenuTreeNode(org.phoebus.ui.application.MenuEntryService.MenuTreeNode) OpenHelp(org.phoebus.ui.help.OpenHelp) SeparatorMenuItem(javafx.scene.control.SeparatorMenuItem) OpenAbout(org.phoebus.ui.help.OpenAbout) CheckMenuItem(javafx.scene.control.CheckMenuItem) DockItemWithInput(org.phoebus.ui.docking.DockItemWithInput) DockStage(org.phoebus.ui.docking.DockStage) Stage(javafx.stage.Stage) Menu(javafx.scene.control.Menu) DockItem(org.phoebus.ui.docking.DockItem)

Example 2 with DockPane

use of org.phoebus.ui.docking.DockPane in project phoebus by ControlSystemStudio.

the class OpenAbout method import_preferences.

/**
 * Prompt for settings.ini to import, then offer restart
 */
private void import_preferences() {
    final DockPane parent = DockPane.getActiveDockPane();
    final ExtensionFilter[] ini = new ExtensionFilter[] { new ExtensionFilter("Preference settings.ini", List.of("*.ini")) };
    final File file = new OpenFileDialog().promptForFile(parent.getScene().getWindow(), Messages.Open, null, ini);
    if (file == null)
        return;
    JobManager.schedule("Load preferences", monitor -> {
        PropertyPreferenceLoader.load(new FileInputStream(file));
        Platform.runLater(() -> {
            final Alert restart = new Alert(AlertType.CONFIRMATION);
            restart.setHeaderText("Restart to activate loaded settings");
            restart.setContentText("For performance reasons, preference settings are only loaded once on startup.\n" + "Exit application so you can then start it again?");
            restart.getDialogPane().setPrefSize(500, 300);
            restart.setResizable(true);
            DialogHelper.positionDialog(restart, parent, -400, -300);
            if (restart.showAndWait().orElse(ButtonType.CANCEL) == ButtonType.OK)
                System.exit(0);
        });
    });
}
Also used : DockPane(org.phoebus.ui.docking.DockPane) ExtensionFilter(javafx.stage.FileChooser.ExtensionFilter) OpenFileDialog(org.phoebus.ui.dialog.OpenFileDialog) Alert(javafx.scene.control.Alert) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 3 with DockPane

use of org.phoebus.ui.docking.DockPane in project phoebus by ControlSystemStudio.

the class PhoebusApplication method openResource.

/**
 * @param resource Resource received as command line argument
 * @param prompt   Prompt if there are multiple applications, or use first one?
 */
private void openResource(final URI resource, final boolean prompt) {
    final AppResourceDescriptor application = findApplication(resource, prompt);
    if (application == null)
        return;
    final String query = resource.getQuery();
    if (query != null) {
        // Query could contain _anything_, to be used by the application.
        // Perform a simplistic search for "target=window" or "target=pane_name".
        final int i = query.indexOf("target=");
        if (i >= 0) {
            int end = query.indexOf('&', i + 7);
            if (end < 0)
                end = query.length();
            final String target = query.substring(i + 7, end);
            if (!target.equals("window")) {
                // Should the new panel open in a specific, named pane?
                final DockPane existing = DockStage.getDockPaneByName(target);
                if (existing != null)
                    DockPane.setActiveDockPane(existing);
                else {
                    // Open new Stage with pane for that name
                    final Stage new_stage = new Stage();
                    DockStage.configureStage(new_stage);
                    new_stage.show();
                    DockPane.getActiveDockPane().setName(target);
                }
            }
        }
    }
    logger.log(Level.INFO, "Opening " + resource + " with " + application.getName());
    application.create(resource);
}
Also used : DockPane(org.phoebus.ui.docking.DockPane) DockStage(org.phoebus.ui.docking.DockStage) Stage(javafx.stage.Stage) AppResourceDescriptor(org.phoebus.framework.spi.AppResourceDescriptor)

Example 4 with DockPane

use of org.phoebus.ui.docking.DockPane in project phoebus by ControlSystemStudio.

the class DockItemRepresentation method openNewWindow.

@Override
public ToolkitRepresentation<Parent, Node> openNewWindow(final DisplayModel model, final Consumer<DisplayModel> close_handler) {
    // If a display has already been opened, reuse it by bringing it to the front.
    final DockItemWithInput existing = DockStage.getDockItemWithInput(DisplayRuntimeApplication.NAME, DisplayInfo.forModel(model).toURI());
    if (existing != null) {
        final DisplayRuntimeInstance instance = existing.getApplication();
        instance.raise();
        return instance.getRepresentation();
    }
    // Open new Stage
    final Stage new_stage = new Stage();
    // Configure for docking, i.e. with DockPane
    DockStage.configureStage(new_stage);
    // Use location and size from model for the window
    double x = model.propX().getValue();
    double y = model.propY().getValue();
    if (x <= 0.0 && y <= 0.0) {
        // .. unless that's (0, 0), i.e. very likely nobody bothered to set it.
        // In that case, open new window close to the current window
        final DockPane parent = app_instance.getDockItem().getDockPane();
        if (parent != null && parent.getScene() != null && parent.getScene().getWindow() != null) {
            Window window = parent.getScene().getWindow();
            x = window.getX();
            y = window.getY();
        }
    }
    new_stage.setX(x);
    new_stage.setY(y);
    // Size needs to account for the border and toolbar.
    // Using fixed numbers, exact size of border and toolbar unknown
    // at this time in the code
    new_stage.setWidth(model.propWidth().getValue() + 18);
    new_stage.setHeight(model.propHeight().getValue() + 105);
    new_stage.show();
    // model will be opened in it.
    return representModelInNewDockItem(model);
}
Also used : Window(javafx.stage.Window) DockPane(org.phoebus.ui.docking.DockPane) DockItemWithInput(org.phoebus.ui.docking.DockItemWithInput) DockStage(org.phoebus.ui.docking.DockStage) Stage(javafx.stage.Stage)

Example 5 with DockPane

use of org.phoebus.ui.docking.DockPane in project phoebus by ControlSystemStudio.

the class DockItemRepresentation method openPanel.

@Override
public ToolkitRepresentation<Parent, Node> openPanel(final DisplayModel model, final String name, final Consumer<DisplayModel> close_handler) throws Exception {
    // By default, open in the pane used by this display
    DockPane pane = app_instance.getDockItem().getDockPane();
    if (name.length() > 0) {
        // Should the new panel open in a specific, named pane?
        final DockPane named = DockStage.getDockPaneByName(name);
        if (named != null)
            pane = named;
        else if (pane != null)
            // Create a new DockPane with that name
            pane = pane.split(name);
        else
            logger.log(Level.WARNING, "Cannot locate pane to create new '" + name + "'");
    }
    // System.out.println("Open panel in " + app_instance.dock_item.getDockPane());
    DockPane.setActiveDockPane(pane);
    return representModelInNewDockItem(model);
}
Also used : DockPane(org.phoebus.ui.docking.DockPane)

Aggregations

DockPane (org.phoebus.ui.docking.DockPane)9 Node (javafx.scene.Node)4 Stage (javafx.stage.Stage)4 DockStage (org.phoebus.ui.docking.DockStage)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 MementoTree (org.phoebus.framework.persistence.MementoTree)3 XMLMementoTree (org.phoebus.framework.persistence.XMLMementoTree)3 AppResourceDescriptor (org.phoebus.framework.spi.AppResourceDescriptor)3 DockItem (org.phoebus.ui.docking.DockItem)3 DockItemWithInput (org.phoebus.ui.docking.DockItemWithInput)3 SplitDock (org.phoebus.ui.docking.SplitDock)3 FileInputStream (java.io.FileInputStream)2 URI (java.net.URI)2 TimeUnit (java.util.concurrent.TimeUnit)2 Level (java.util.logging.Level)2 Platform (javafx.application.Platform)2 Rectangle2D (javafx.geometry.Rectangle2D)2 Alert (javafx.scene.control.Alert)2