1 /* 2 * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24 import javafx.application.Application; 25 import javafx.event.ActionEvent; 26 import javafx.geometry.Pos; 27 import javafx.print.PrinterJob; 28 import javafx.scene.Scene; 29 import javafx.scene.control.Button; 30 import javafx.scene.layout.HBox; 31 import javafx.scene.layout.VBox; 32 import javafx.scene.paint.Color; 33 import javafx.stage.Stage; 34 import javafx.stage.Window; 35 import javafx.scene.text.Text; 36 37 public class PrintDialogModalityTest extends Application { 38 39 static final String infoText = 40 "NOTE: if there are no printers installed this test is not valid " + 41 "since depending on O/S no dialog may be displayed.\n" + 42 "This tests that a print dialog can be made modal w.r.t " + 43 "a parent window. Cycle through in any order the different " + 44 "dialog options via pressing the buttons. For the modal cases " + 45 "when the dialog is displayed, the original window should be " + 46 "unresponsive to input, for example preventing you launching " + 47 "another dialog, and also should stay below the dialog. " + 48 "Depending on platform the dialog may stay above just the "+ 49 "parent, or all application or even all desktop windows.\n" + 50 "Non-modal dialogs will generally allow you to click on the "+ 51 "main window and raise it above the dialog. However " + 52 "depending on platform, even the non-modal cases may behave " + 53 "as if they are modal. Notably this is the case on MacOS as " + 54 "that is the behaviour enforced by the O/S"; 55 56 @Override 57 public void start(Stage primaryStage) { 58 59 VBox vbox; 60 61 Text info = new Text(infoText); 62 info.setWrappingWidth(450); 63 final PrinterJob job = PrinterJob.createPrinterJob(); 64 if (job != null) { 65 66 Button b1 = new Button("Modal Print"); 67 Button b2 = new Button("Modal Page Setup"); 68 Button b3 = new Button("Non-modal Print"); 69 Button b4 = new Button("Non-modal Page Setup"); 70 71 b1.setOnAction((ActionEvent event) -> { 72 Window w = b1.getScene().getWindow(); 73 job.showPrintDialog(w); 74 }); 75 b2.setOnAction((ActionEvent event) -> { 76 Window w = b2.getScene().getWindow(); 77 job.showPageSetupDialog(w); 78 }); 79 b3.setOnAction((ActionEvent event) -> { 80 job.showPrintDialog(null); 81 }); 82 b4.setOnAction((ActionEvent event) -> { 83 job.showPageSetupDialog(null); 84 }); 85 HBox hbox1 = new HBox(2, b1, b2); 86 HBox hbox2 = new HBox(2, b3, b4); 87 hbox1.setAlignment(Pos.CENTER); 88 hbox2.setAlignment(Pos.CENTER); 89 vbox = new VBox(3, info, hbox1, hbox2); 90 } else { 91 Text noprinters = new Text("No printers found!"); 92 noprinters.setFill(Color.RED); 93 vbox = new VBox(2, info, noprinters); 94 } 95 vbox.setAlignment(Pos.TOP_CENTER); 96 Scene scene = new Scene(vbox, 500, 400); 97 primaryStage.setScene(scene); 98 primaryStage.show(); 99 } 100 101 public static void main(String[] args) { 102 launch(args); 103 } 104 }