private Stage getStage() { return (Stage) commitButton.getScene().getWindow(); }
public void start(Stage stage) throws Exception { FXMLLoader ldr = new FXMLLoader(getClass() .getResource("Application.fxml")); Parent root = (Parent) ldr.load(); appCtrl = (ApplicationController) ldr.getController(); Scene scene = new Scene(root); stage.setScene(scene); stage.show(); scene.getWindow().setOnCloseRequest(new EventHandler<WindowEvent>() { public void handle(WindowEvent ev) { if (!appCtrl.shutdown()) { ev.consume(); } } }); }
public static void applyBrandToScene(Injector injector, Scene scene) { final Brand brand = injector.getOrThrow(Brand.class); final UserInterfaceComponent ui = injector.getOrThrow(UserInterfaceComponent.class); final InfoComponent info = injector.getOrThrow(InfoComponent.class); final Stage stage = scene.getWindow() == null ? ui.getStage() : (Stage) scene.getWindow(); apply(brand, info, stage, scene); }
public static EventHandler<ActionEvent> newCloseHandler() { return event -> { final Node source = (Node) event.getSource(); final Stage stage = (Stage) source.getScene().getWindow(); stage.close(); }; }
private void closeWindow() { issueComponent.clear(); final Stage stage = (Stage) btnClose.getScene().getWindow(); stage.close(); } }
private static void apply(Brand brand, InfoComponent info, Stage stage, Scene scene) { if (stage != null) { stage.setTitle(info.getTitle()); } brand.logoSmall() .map(Image::new) .ifPresent(icon -> { if (stage != null) { stage.getIcons().add(icon); } @SuppressWarnings("unchecked") final Stage dialogStage = (Stage) scene.getWindow(); if (dialogStage != null) { dialogStage.getIcons().add(icon); } }); brand.stylesheets().forEachOrdered(scene.getStylesheets()::add); }
public void show(Node node){ if(!isShowing()){ if(node.getScene() == null || node.getScene().getWindow() == null) throw new IllegalStateException("Can not show popup. The node must be attached to a scene/window."); Window parent = node.getScene().getWindow(); this.show(parent, parent.getX() + node.localToScene(0, 0).getX() + node.getScene().getX(), parent.getY() + node.localToScene(0, 0).getY() + node.getScene().getY() + ((Region)node).getHeight()); ((JFXAutoCompletePopupSkin<T>)getSkin()).animate(); } }
private Stage createStage(Stage mainStage) { FXMLLoader loader = new FXMLLoader(DesignerUtil.getFxml("event-log.fxml")); loader.setController(this); final Stage dialog = new Stage(); dialog.initOwner(mainStage.getScene().getWindow()); dialog.initModality(Modality.NONE); Parent root; try { root = loader.load(); } catch (IOException e) { throw new IllegalStateException(e); } Scene scene = new Scene(root); dialog.setScene(scene); return dialog; }
/** * show the popup according to the specified position with a certain offset * * @param vAlign can be TOP/BOTTOM * @param hAlign can be LEFT/RIGHT * @param initOffsetX on the x axis * @param initOffsetY on the y axis */ public void show(Node node, PopupVPosition vAlign, PopupHPosition hAlign, double initOffsetX, double initOffsetY) { if (!isShowing()) { if (node.getScene() == null || node.getScene().getWindow() == null) { throw new IllegalStateException("Can not show popup. The node must be attached to a scene/window."); } Window parent = node.getScene().getWindow(); final Point2D origin = node.localToScene(0, 0); final double anchorX = parent.getX() + origin.getX() + node.getScene().getX() + (hAlign == PopupHPosition.RIGHT ? ((Region) node).getWidth() : 0); final double anchorY = parent.getY() + origin.getY() + node.getScene() .getY() + (vAlign == PopupVPosition.BOTTOM ? ((Region) node).getHeight() : 0); this.show(parent, anchorX, anchorY); ((JFXPopupSkin) getSkin()).reset(vAlign, hAlign, initOffsetX, initOffsetY); Platform.runLater(() -> ((JFXPopupSkin) getSkin()).animate()); } }
private Stage createEditPropertyDialog() { EditPropertyDialogController wizard = new EditPropertyDialogController(); FXMLLoader loader = new FXMLLoader(DesignerUtil.getFxml("edit-property-dialog.fxml")); loader.setController(wizard); final Stage dialog = new Stage(); dialog.initOwner(this.getScene().getWindow()); dialog.initModality(Modality.WINDOW_MODAL); dialog.initStyle(StageStyle.UNDECORATED); Parent root; try { root = loader.load(); } catch (IOException e) { throw new IllegalStateException(e); } Scene scene = new Scene(root); dialog.setTitle("Edit property"); dialog.setScene(scene); dialog.setUserData(wizard); return dialog; }
public void show(Node node) { if (text == null) { text = (Text) node.lookup(".text"); } node = text; if (!isShowing()) { if (node.getScene() == null || node.getScene().getWindow() == null) { throw new IllegalStateException("Can not show popup. The node must be attached to a scene/window."); } Window parent = node.getScene().getWindow(); this.show(parent, parent.getX() + node.localToScene(0, 0).getX() + node.getScene().getX(), parent.getY() + node.localToScene(0, 0).getY() + node.getScene().getY() + node.getLayoutBounds().getHeight() + shift); ((JFXAutoCompletePopupSkin<T>) getSkin()).animate(); } else { // if already showing update location if needed Window parent = node.getScene().getWindow(); this.show(parent, parent.getX() + node.localToScene(0, 0).getX() + node.getScene().getX(), parent.getY() + node.localToScene(0, 0).getY() + node.getScene().getY() + node.getLayoutBounds().getHeight() + shift); } } }
JFXAlert alert = new JFXAlert((Stage) alertButton.getScene().getWindow()); alert.initModality(Modality.APPLICATION_MODAL); alert.setOverlayClose(false);
eventHandlerManager.addEventHandler(DialogEvent.DIALOG_HIDDEN, event -> removeLayoutListeners()); getDialogPane().getScene().getWindow().addEventFilter(KeyEvent.KEY_PRESSED, keyEvent -> { if (keyEvent.getCode() == KeyCode.ESCAPE) { if (!isHideOnEscape()) {
@Override public void handle(ActionEvent event) { RememberingLatestFileChooserWrapper fileChooser = FileChoosers.getFileChooser(fileType, getBrowseWindowTitle()); String currentSelection = getTextField().getText(); if (isNotBlank(currentSelection)) { Path path = Paths.get(currentSelection); if (Files.exists(path)) { fileChooser.setInitialDirectory(path.getParent().toFile()); fileChooser.setInitialFileName(path.getFileName().toString()); } } setTextFromFile(fileChooser.showDialog(getTextField().getScene().getWindow(), openType)); } }
public void loadDocuments(ActionEvent event) { RememberingLatestFileChooserWrapper fileChooser = FileChoosers.getFileChooser(FileType.PDF, DefaultI18nContext.getInstance().i18n("Select pdf documents to load")); List<File> chosenFiles = fileChooser.showOpenMultipleDialog(this.getScene().getWindow()); if (chosenFiles != null && !chosenFiles.isEmpty()) { PdfLoadRequestEvent loadEvent = new PdfLoadRequestEvent(getOwnerModule()); chosenFiles.stream().map(PdfDocumentDescriptor::newDescriptorNoPassword).forEach(loadEvent::add); eventStudio().broadcast(loadEvent, getOwnerModule()); } } }
@Override public void handle(ActionEvent event) { RememberingLatestDirectoryChooserWrapper fileChooser = FileChoosers .getDirectoryChooser(getBrowseWindowTitle()); String currentSelection = getTextField().getText(); if (isNotBlank(currentSelection)) { Path path = Paths.get(currentSelection); if (Files.exists(path)) { fileChooser.setInitialDirectory(path.toFile()); } } setTextFromFile(fileChooser.showDialog(getTextField().getScene().getWindow())); } }
public void saveLog() { RememberingLatestFileChooserWrapper fileChooser = FileChoosers.getFileChooser(FileType.LOG, DefaultI18nContext.getInstance().i18n("Select where to save the log file")); fileChooser.setInitialFileName("PDFsam.log"); File chosenFile = fileChooser.showDialog(this.getScene().getWindow(), OpenType.SAVE); if (chosenFile != null) { if (chosenFile.exists()) { // TODO show dialog? investigate. On Ubuntu it already asks confirmation. } writeContent(logView.getItems()).to(chosenFile); } }
private void showPasswordFieldPopup() { Scene scene = this.getScene(); if (scene != null) { Window owner = scene.getWindow(); if (owner != null && owner.isShowing()) { Point2D nodeCoord = encryptionIndicator.localToScene(encryptionIndicator.getWidth() / 2, encryptionIndicator.getHeight() / 1.5); double anchorX = Math.round(owner.getX() + scene.getX() + nodeCoord.getX() + 2); double anchorY = Math.round(owner.getY() + scene.getY() + nodeCoord.getY() + 2); passwordPopup.showFor(this, descriptor, anchorX, anchorY); } } }
@EventListener public void showPasswordFieldPopup(ShowPasswordFieldPopupRequest request) { Scene scene = this.getScene(); if (scene != null) { Window owner = scene.getWindow(); if (owner != null && owner.isShowing()) { Point2D nodeCoord = request.getRequestingNode().localToScene(request.getRequestingNode().getWidth() / 2, request.getRequestingNode().getHeight() / 1.5); double anchorX = Math.round(owner.getX() + scene.getX() + nodeCoord.getX() + 2); double anchorY = Math.round(owner.getY() + scene.getY() + nodeCoord.getY() + 2); passwordPopup.showFor(this, request.getPdfDescriptor(), anchorX, anchorY); } } }
private ErrorTooltipManager(String message) { require(isNotBlank(message), "Tooltip message cannot be blank"); this.tooltip = new Tooltip(message); this.tooltip.getStyleClass().add(ERROR_TOOLTIP_CLASS); hideTimer.getKeyFrames().add(new KeyFrame(new Duration(5000))); hideTimer.setOnFinished(e -> { tooltip.hide(); ErrorTooltipManager.this.active = false; }); activationTimer.getKeyFrames().add(new KeyFrame(new Duration(250))); activationTimer.setOnFinished(e -> { if (!ErrorTooltipManager.this.active) { Scene scene = getScene(); if (scene != null) { Window owner = scene.getWindow(); if (owner != null && owner.isShowing() && ValidableTextField.this.isVisible()) { Point2D where = getDisplayCoordiantes(owner, scene); tooltip.show(ValidableTextField.this, where.getX(), where.getY()); ErrorTooltipManager.this.active = true; hideTimer.playFromStart(); } } } }); }