javafx.stage.PopupWindow Java Examples

The following examples show how to use javafx.stage.PopupWindow. 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: PopupSelectbox.java    From logbook-kai with MIT License 6 votes vote down vote up
public void show(Node anchorNode) {
    PopupSelectboxContainer<T> container = new PopupSelectboxContainer<>();
    container.setItems(this.items.get());
    container.setCellFactory(this.cellFactory.get());
    container.setSelectedItem(this.selectedItem);
    container.getStylesheets().addAll(this.styleSheets);
    container.headerContents().addAll(this.headerContents);
    container.init();

    Popup stage = new Popup();
    stage.getContent().addAll(container);
    stage.setAutoHide(true);
    stage.setAnchorLocation(PopupWindow.AnchorLocation.CONTENT_TOP_LEFT);

    Bounds screen = anchorNode.localToScreen(anchorNode.getLayoutBounds());
    stage.show(anchorNode.getScene().getWindow(), screen.getMinX(), screen.getMaxY());
}
 
Example #2
Source File: SubWindowChecker.java    From scenic-view with GNU General Public License v3.0 5 votes vote down vote up
public SubWindowChecker(final StageControllerImpl model) {
    super(new WindowFilter() {
        @Override public boolean accept(final Window window) {
            return window instanceof PopupWindow;
        }
    }, model.getID().toString());
    this.model = model;
}
 
Example #3
Source File: SubWindowChecker.java    From scenic-view with GNU General Public License v3.0 5 votes vote down vote up
@Override protected void onWindowsFound(final List<Window> tempPopups) {
    tree.clear();
    windows.clear();

    for (final Window popupWindow : tempPopups) {
        final Map<PopupWindow, Map> pos = valid((PopupWindow) popupWindow, tree);
        if (pos != null) {
            pos.put((PopupWindow) popupWindow, new HashMap<PopupWindow, Map>());
            windows.add((PopupWindow) popupWindow);
        }
    }
    if (!tree.equals(previousTree)) {
        previousTree.clear();
        previousTree.putAll(tree);
        final List<PopupWindow> actualWindows = new ArrayList<>(windows);
        Platform.runLater(new Runnable() {

            @Override public void run() {
                // No need for synchronization here
                model.popupWindows.clear();
                model.popupWindows.addAll(actualWindows);
                model.update();

            }
        });

    }

}
 
Example #4
Source File: SubWindowChecker.java    From scenic-view with GNU General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked") Map<PopupWindow, Map> valid(final PopupWindow window, final Map<PopupWindow, Map> tree) {
    if (window.getOwnerWindow() == model.targetWindow)
        return tree;
    for (final Iterator<PopupWindow> iterator = tree.keySet().iterator(); iterator.hasNext();) {
        final PopupWindow type = iterator.next();
        if (type == window.getOwnerWindow()) {
            return tree.get(type);
        } else {
            final Map<PopupWindow, Map> lower = valid(window, tree.get(type));
            if (lower != null)
                return lower;
        }
    }
    return null;
}
 
Example #5
Source File: StageControllerImpl.java    From scenic-view with GNU General Public License v3.0 5 votes vote down vote up
@Override public void update() {
    updateListeners(target, true, false);
    SVNode root = createNode(target);
    /**
     * If the target is the root node of the scene include subwindows
     */
    if (targetScene != null && targetScene.getRoot() == target) {
        String title = "App";
        Image targetStageImage = null;
        if (targetScene.getWindow() instanceof Stage) {
            final Stage s = ((Stage) targetScene.getWindow());
            if (!s.getIcons().isEmpty()) {
                targetStageImage = ((Stage) targetScene.getWindow()).getIcons().get(0);
            }
            title = s.getTitle() != null ? s.getTitle() : "App";
        }
        final SVDummyNode app = new SVDummyNode(title, "Stage", getID().getStageID(), NodeType.STAGE);
        app.setIcon(targetStageImage);
        app.setRemote(remote);
        app.setExpanded(true);
        app.getChildren().add(root);
        if (!popupWindows.isEmpty()) {
            final SVNode subWindows = new SVDummyNode("SubWindows", "Popup", getID().getStageID(), NodeType.SUBWINDOWS_ROOT);
            for (int i = 0; i < popupWindows.size(); i++) {
                final PopupWindow window = popupWindows.get(i);
                final SVNode subWindow = new SVDummyNode("SubWindow -" + ConnectorUtils.nodeClass(window), ConnectorUtils.nodeClass(window), window.hashCode(), NodeType.SUBWINDOW);
                subWindow.getChildren().add(createNode(window.getScene().getRoot()));
                subWindows.getChildren().add(subWindow);
            }
            app.getChildren().add(subWindows);
        }
        root = app;
    }
    dispatchEvent(new NodeAddRemoveEvent(SVEventType.ROOT_UPDATED, getID(), root));
    updateSceneDetails();
}
 
Example #6
Source File: ContextMenuHandler.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
public ContextMenuHandler(IJSONRecorder recorder, RFXComponentFactory finder) {
    popup = new PopupWindow() {
    };
    root = new AssertionPanel(popup, recorder, finder);
    root.setPrefWidth(300.0);
    popup.getScene().setRoot(root);
    popup.sizeToScene();
}
 
Example #7
Source File: RFXComponent.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private Stage getStage(Window window) {
    if (window instanceof Stage) {
        return (Stage) window;
    }
    if (window instanceof PopupWindow) {
        Node ownerNode = ((PopupWindow) window).getOwnerNode();
        ownerNode.getScene().getWindow();
        return getStage(ownerNode.getScene().getWindow());
    }
    return null;
}
 
Example #8
Source File: PopOver.java    From logbook-kai with MIT License 5 votes vote down vote up
/**
 * マウスがこのアンカーノードに入るときに呼び出される関数を定義します。
 *
 * @param event {@link MouseEvent}
 */
protected void setOnMouseEntered(MouseEvent event) {
    Node anchorNode = (Node) event.getSource();
    Popup popup = this.initPopup(anchorNode);
    Bounds screen = anchorNode.localToScreen(anchorNode.getLayoutBounds());
    popup.setAnchorLocation(PopupWindow.AnchorLocation.CONTENT_TOP_LEFT);
    popup.show(anchorNode.getScene().getWindow(), screen.getMinX(), screen.getMaxY());
    this.setLocation(popup, anchorNode, event);
}
 
Example #9
Source File: FxmlControl.java    From MyBox with Apache License 2.0 4 votes vote down vote up
public static void locateCenter(Region region, PopupWindow window) {
    Bounds bounds = region.localToScreen(region.getBoundsInLocal());
    window.show(region, bounds.getMinX() + bounds.getWidth() / 2, bounds.getMinY() + bounds.getHeight() / 2);
}
 
Example #10
Source File: FxmlControl.java    From MyBox with Apache License 2.0 4 votes vote down vote up
public static void locateBelow(Node node, PopupWindow window) {
    Bounds bounds = node.localToScreen(node.getBoundsInLocal());
    window.show(node, bounds.getMinX() + 2, bounds.getMinY() + bounds.getHeight() + 5);
}
 
Example #11
Source File: FxmlControl.java    From MyBox with Apache License 2.0 4 votes vote down vote up
public static void locateBelow(Region region, PopupWindow window) {
    Bounds bounds = region.localToScreen(region.getBoundsInLocal());
    window.show(region, bounds.getMinX() + 2, bounds.getMinY() + bounds.getHeight() + 5);
}
 
Example #12
Source File: FxmlControl.java    From MyBox with Apache License 2.0 4 votes vote down vote up
public static void locateRightTop(Region region, PopupWindow window) {
    Bounds bounds = region.localToScreen(region.getBoundsInLocal());
    window.show(region, bounds.getMaxX() - window.getWidth() - 20, bounds.getMinY() + 50);
}
 
Example #13
Source File: FxmlControl.java    From MyBox with Apache License 2.0 4 votes vote down vote up
public static void locateUp(Region region, PopupWindow window) {
    Bounds bounds = region.localToScreen(region.getBoundsInLocal());
    window.show(region, bounds.getMinX() + 2, bounds.getMinY() - 50);
}
 
Example #14
Source File: PopOver.java    From logbook-kai with MIT License 4 votes vote down vote up
/**
 * ポップアップの表示位置を設定します
 *
 * @param popup ポップアップ
 * @param anchorNode アンカーノード
 * @param event {@link MouseEvent}
 */
protected void setLocation(Popup popup, Node anchorNode, MouseEvent event) {
    double x = event.getScreenX();
    double y = event.getScreenY();
    double width = popup.getWidth();
    double height = popup.getHeight();
    double gapSize = this.getGapSize();

    PopupWindow.AnchorLocation anchorLocation = PopupWindow.AnchorLocation.CONTENT_TOP_LEFT;
    double gapX = gapSize;
    double gapY = gapSize;

    for (Screen screen : Screen.getScreens()) {
        Rectangle2D screenRect = screen.getVisualBounds();

        // 右下 に表示可能であれば
        if (screenRect.contains(x + gapSize, y + gapSize, width, height)) {
            // PopupWindow視点でアンカーノードがTOP_LEFTの位置
            anchorLocation = PopupWindow.AnchorLocation.CONTENT_TOP_LEFT;
            gapX = gapSize;
            gapY = gapSize;
            break;
        }
        // 左下
        if (screenRect.contains(x - gapSize - width, y + gapSize, width, height)) {
            anchorLocation = PopupWindow.AnchorLocation.CONTENT_TOP_RIGHT;
            gapX = -gapSize;
            gapY = gapSize;
            break;
        }
        // 右上
        if (screenRect.contains(x + gapSize, y - gapSize - height, width, height)) {
            anchorLocation = PopupWindow.AnchorLocation.CONTENT_BOTTOM_LEFT;
            gapX = gapSize;
            gapY = -gapSize;
            break;
        }
        // 左上
        if (screenRect.contains(x - gapSize - width, y - gapSize - height, width, height)) {
            anchorLocation = PopupWindow.AnchorLocation.CONTENT_BOTTOM_RIGHT;
            gapX = -gapSize;
            gapY = -gapSize;
            break;
        }
    }

    popup.setAnchorLocation(anchorLocation);
    popup.setAnchorX(x + gapX);
    popup.setAnchorY(y + gapY);
}