private void fixPosition() { Window w = dialog.getOwner(); Screen s = com.sun.javafx.util.Utils.getScreen(w); Rectangle2D sb = s.getBounds(); double xR = w.getX() + w.getWidth(); double xL = w.getX() - dialog.getWidth(); double x; double y; if (sb.getMaxX() >= xR + dialog.getWidth()) { x = xR; } else if (sb.getMinX() <= xL) { x = xL; } else { x = Math.max(sb.getMinX(), sb.getMaxX() - dialog.getWidth()); } y = Math.max(sb.getMinY(), Math.min(sb.getMaxY() - dialog.getHeight(), w.getY())); dialog.setX(x); dialog.setY(y); }
public void show() { dialog.setOpacity(0); // pickerDecorator.setOpacity(0); if (dialog.getOwner() != null) { dialog.widthProperty().addListener(positionAdjuster); dialog.heightProperty().addListener(positionAdjuster); positionAdjuster.invalidated(null); } if (dialog.getScene() == null) { dialog.setScene(customScene); } curvedColorPicker.preAnimate(); dialog.show(); if (initOnce) { initRun.run(); initOnce = false; } Timeline timeline = new Timeline(new KeyFrame(Duration.millis(120), new KeyValue(dialog.opacityProperty(), 1, Interpolator.EASE_BOTH))); timeline.setOnFinished((finish) -> curvedColorPicker.animate()); timeline.play(); }
public void print(WritableImage writableImage, Stage primaryStage) { ImageView imageView =new ImageView(writableImage); Printer printer = Printer.getDefaultPrinter(); PageLayout pageLayout = printer.createPageLayout(Paper.A4, PageOrientation.LANDSCAPE, Printer.MarginType.DEFAULT); double scaleX = pageLayout.getPrintableWidth() / imageView.getBoundsInParent().getWidth(); double scaleY = pageLayout.getPrintableHeight() / imageView.getBoundsInParent().getHeight(); imageView.getTransforms().add(new Scale(scaleX, scaleY)); PrinterJob job = PrinterJob.createPrinterJob(); if (job != null) { boolean successPrintDialog = job.showPrintDialog(primaryStage.getOwner()); if(successPrintDialog){ boolean success = job.printPage(pageLayout,imageView); if (success) { job.endJob(); } } } }
/** * Returns whether the stage is modal. * * @param stage the stage * @return true if effectively modal */ public boolean isModal(Stage stage) { boolean modal = false; if (stage != null) { switch(stage.getModality()) { case APPLICATION_MODAL: modal = true; break; case WINDOW_MODAL: modal = stage.getOwner() != null; break; default: // NONE } } return modal; }
@Override public boolean apply( Window input ) { Window parent = null; if( input instanceof Stage ) { parent = ( ( Stage )input ).getOwner(); } else if( input instanceof PopupWindow ) { parent = ( ( PopupWindow )input ).getOwnerWindow(); } return parent == lastSeenWindow || parent != null && apply( parent ); } };
@Override public boolean apply( Window input ) { Window parent = null; if( input instanceof Stage) { parent = ( ( Stage )input ).getOwner(); } else if( input instanceof PopupWindow) { parent = ( ( PopupWindow )input ).getOwnerWindow(); } return parent == window || parent != null && apply( parent ); } };
/** * Closes the hierarchy of stages from the given node stopping at given stage. * * @param node the node * @param stopStage the stop stage, null to close the whole application */ public void closeStageHierarchy(Node node, Stage stopStage) { Stage stage = getStage(node); while (stage != null && stage != stopStage) { stage.close(); Window owner = stage.getOwner(); if (owner instanceof Stage) { stage = (Stage) owner; } else { break; } } }
@Override public void start(Stage primaryStage) { Button btn = new Button(); btn.setText("Open Custom Color Dialog"); btn.setOnAction(e -> { CustomColorDialog dialog = new CustomColorDialog(primaryStage.getOwner()); dialog.show(); }); Scene scene = new Scene(new StackPane(btn), 300, 250); primaryStage.setTitle("CustomColorDialog"); primaryStage.setScene(scene); primaryStage.show(); }
Window owner; if( window instanceof Stage ) { owner = ((Stage)window).getOwner(); } else if( window instanceof PopupWindow ) { owner = ((PopupWindow)window).getOwnerWindow();
fc.getExtensionFilters().addAll(xmlfilter,mffilter); fc.setSelectedExtensionFilter(xmlfilter); File f = fc.showSaveDialog(primaryStage.getOwner()); System.out.println("f = " + f); if(null == f) {
private void fixPosition() { Window w = dialog.getOwner(); Screen s = com.sun.javafx.util.Utils.getScreen(w); Rectangle2D sb = s.getBounds(); double xR = w.getX() + w.getWidth(); double xL = w.getX() - dialog.getWidth(); double x; double y; if (sb.getMaxX() >= xR + dialog.getWidth()) { x = xR; } else if (sb.getMinX() <= xL) { x = xL; } else { x = Math.max(sb.getMinX(), sb.getMaxX() - dialog.getWidth()); } y = Math.max(sb.getMinY(), Math.min(sb.getMaxY() - dialog.getHeight(), w.getY())); dialog.setX(x); dialog.setY(y); }
/** * Checks if a stage would overlay any other stage that belongs to the same owner. * * @param stage the stage * @param location the requested location for this stage * @param dx maximum overlapping width * @param dy maximum overlapping height * @return true if overlapping, false if on free space */ private boolean isStageOverlapping(Stage stage, Point2D location, double dx, double dy) { Window owner = stage.getOwner(); if (dx < 0.0) { dx = -dx; } if (dy < 0.0) { dy = -dy; } for (Stage w: getAllShowingStages()) { Window o = w.getOwner(); if (w != stage && o == owner && ((location.getX() <= w.getX() + dx && location.getX() + stage.getWidth() + dx >= w.getX() + w.getWidth()) || (location.getY() <= w.getY() + dy && location.getY() + stage.getHeight() + dy >= w.getY() + w.getHeight()))) { return true; } } return false; }
if (stage.getOwner() == null) { isPrimaryClosing = true;
/** * Calculates the position of a stage on the screen so that * it is being display in an optimal manner. * * @param stage the stage to be positioned on the screen * @return the location */ public Point2D determinePreferredStageLocation(Stage stage) { Point2D location = new Point2D(stage.getX(), stage.getY()); if (location.getX() == 0.0 && location.getY() == 0.0) { // if no position yet // place in the middle of the owner if possibe Window owner = stage.getOwner(); if (owner != null) { location = new Point2D(owner.getX() + (owner.getWidth() - stage.getWidth()) / 2.0, owner.getY() + (owner.getHeight() - stage.getHeight()) / 2.0); } else { // not much we can do: center it location = determineCenteredLocation(stage); } } return determineAlignedStageLocation(stage, location); }
public void show() { dialog.setOpacity(0); // pickerDecorator.setOpacity(0); if (dialog.getOwner() != null) { dialog.widthProperty().addListener(positionAdjuster); dialog.heightProperty().addListener(positionAdjuster); positionAdjuster.invalidated(null); } if (dialog.getScene() == null) { dialog.setScene(customScene); } curvedColorPicker.preAnimate(); dialog.show(); if (initOnce) { initRun.run(); initOnce = false; } Timeline timeline = new Timeline(new KeyFrame(Duration.millis(120), new KeyValue(dialog.opacityProperty(), 1, Interpolator.EASE_BOTH))); timeline.setOnFinished((finish) -> curvedColorPicker.animate()); timeline.play(); }