< prev index next >

test/java/awt/print/PrinterJob/MultiMonPrintDlgTest.java

Print this page

        

*** 41,60 **** * always displayed on primary * @run main/manual MultiMonPrintDlgTest */ public class MultiMonPrintDlgTest implements ActionListener { ! Frame primaryFrame = null; ! Frame secFrame = null; ! GraphicsDevice gd[] = GraphicsEnvironment.getLocalGraphicsEnvironment(). getScreenDevices(); ! public MultiMonPrintDlgTest() throws Exception { ! if (gd.length <= 1) { ! System.out.println("This test should be run only on dual-monitor systems. Aborted!!"); ! return; ! } String[] instructions = { " This test should be running on a dual-monitor setup.", "A frame will be created on each of the 2 monitor. ", --- 41,62 ---- * always displayed on primary * @run main/manual MultiMonPrintDlgTest */ public class MultiMonPrintDlgTest implements ActionListener { ! private static boolean testPassed; ! private static Thread mainThread; ! private static boolean testGeneratedInterrupt; ! private static int sleepTime = 30000; ! private static String message = "User has not executed the test"; ! ! static Frame primaryFrame = null; ! static Frame secFrame = null; ! static GraphicsDevice gd[] = GraphicsEnvironment.getLocalGraphicsEnvironment(). getScreenDevices(); ! private static void init() throws Exception { String[] instructions = { " This test should be running on a dual-monitor setup.", "A frame will be created on each of the 2 monitor. ",
*** 68,77 **** --- 70,83 ---- JOptionPane.showMessageDialog( (Component) null, instructions, "information", JOptionPane.INFORMATION_MESSAGE); }); + } + + private void executeTest() { + GraphicsDevice defDev = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(); int x = 0; Frame f = null; for (x = 0; x < gd.length; x ++) { if (gd[x] != defDev) {
*** 93,125 **** f.setVisible(true); } } public void actionPerformed (ActionEvent ae) { - try { javax.print.attribute.PrintRequestAttributeSet prSet = new javax.print.attribute.HashPrintRequestAttributeSet(); java.awt.print.PrinterJob.getPrinterJob().pageDialog(prSet); Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); int dialogButton = JOptionPane.showConfirmDialog (w, "Did the pageDialog shown in non-default monitor?", null, JOptionPane.YES_NO_OPTION); if(dialogButton == JOptionPane.NO_OPTION) { ! throw new RuntimeException("PageDialog is shown in wrong monitor"); ! } java.awt.print.PrinterJob.getPrinterJob().printDialog(prSet); dialogButton = JOptionPane.showConfirmDialog (w, "Did the printDialog shown in non-default monitor?", null, JOptionPane.YES_NO_OPTION); if(dialogButton == JOptionPane.NO_OPTION) { ! throw new RuntimeException("PrintDialog is shown in wrong monitor"); } ! } finally { primaryFrame.dispose(); secFrame.dispose(); } } public static void main (String args[]) throws Exception { MultiMonPrintDlgTest test = new MultiMonPrintDlgTest(); } } --- 99,167 ---- f.setVisible(true); } } public void actionPerformed (ActionEvent ae) { javax.print.attribute.PrintRequestAttributeSet prSet = new javax.print.attribute.HashPrintRequestAttributeSet(); java.awt.print.PrinterJob.getPrinterJob().pageDialog(prSet); Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); int dialogButton = JOptionPane.showConfirmDialog (w, "Did the pageDialog shown in non-default monitor?", null, JOptionPane.YES_NO_OPTION); if(dialogButton == JOptionPane.NO_OPTION) { ! fail("PageDialog is shown in wrong monitor"); ! } else { java.awt.print.PrinterJob.getPrinterJob().printDialog(prSet); dialogButton = JOptionPane.showConfirmDialog (w, "Did the printDialog shown in non-default monitor?", null, JOptionPane.YES_NO_OPTION); if(dialogButton == JOptionPane.NO_OPTION) { ! fail("PrintDialog is shown in wrong monitor"); ! } else { ! pass(); ! } ! } } ! ! private static void dispose() { primaryFrame.dispose(); secFrame.dispose(); } + + public static synchronized void pass() { + testPassed = true; + testGeneratedInterrupt = true; + mainThread.interrupt(); + } + + public static synchronized void fail(String msg) { + testPassed = false; + message = msg; + testGeneratedInterrupt = true; + mainThread.interrupt(); } public static void main (String args[]) throws Exception { + if (gd.length <= 1) { + System.out.println("This test should be run only on dual-monitor systems. Aborted!!"); + return; + } + init(); MultiMonPrintDlgTest test = new MultiMonPrintDlgTest(); + test.executeTest(); + mainThread = Thread.currentThread(); + + try { + mainThread.sleep(sleepTime); + } catch (InterruptedException ex) { + dispose(); + if (!testPassed && testGeneratedInterrupt) { + throw new RuntimeException(message); + } + } + if (!testGeneratedInterrupt) { + dispose(); + throw new RuntimeException(message); + } } }
< prev index next >