< prev index next >

test/java/awt/print/PageFormat/PDialogTest.java

Print this page


   1 /*
   2  * Copyright (c) 2007, 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 /**
  25  * @test
  26  * @bug 4855801

  27  * @summary Changing margins in the page format does not have any effect
  28  * @run main/manual PDialogTest
  29  */
  30 import java.awt.print.*;
  31 import javax.print.attribute.*;
  32 import javax.print.attribute.standard.*;














  33 
  34 public class PDialogTest
  35 {



































































































































































  36 
  37     public static void main(String[] args) {
  38         PageFormat page=new PageFormat();
  39         while(true){
  40             page=java.awt.print.PrinterJob.getPrinterJob().pageDialog(page);
  41         }
  42 


  43     }
  44 }
   1 /*
   2  * Copyright (c) 2007, 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 /**
  25  * @test
  26  * @bug 4855801 6949753
  27  * @requires (os.family == "Windows") | (os.family == "Linux")
  28  * @summary Changing margins in the page format does not have any effect
  29  * @run main/manual PDialogTest
  30  */
  31 
  32 import java.awt.GridBagConstraints;
  33 import java.awt.GridBagLayout;
  34 import java.awt.event.ActionEvent;
  35 import java.awt.print.PageFormat;
  36 import java.awt.print.Paper;
  37 import java.awt.print.PrinterException;
  38 import java.util.concurrent.CountDownLatch;
  39 import java.util.concurrent.TimeUnit;
  40 import javax.swing.BorderFactory;
  41 import javax.swing.Box;
  42 import javax.swing.JButton;
  43 import javax.swing.JFrame;
  44 import javax.swing.JLabel;
  45 import javax.swing.JPanel;
  46 import javax.swing.JTextArea;
  47 import javax.swing.SwingUtilities;
  48 
  49 public class PDialogTest
  50 {
  51     public static void main(String args[]) throws Exception {
  52         final CountDownLatch latch = new CountDownLatch(1);
  53         TestUI test = new TestUI(latch);
  54 
  55         SwingUtilities.invokeAndWait(() -> {
  56             test.createUI();
  57         });
  58 
  59         PageFormat pageFormat = new PageFormat();
  60 
  61         createNewPrintPageSetup(pageFormat);
  62 
  63         setValuesForPrintPageSetup(pageFormat, 2);
  64 
  65         createNewPrintPageSetup(pageFormat);
  66 
  67         setValuesForPrintPageSetup(pageFormat, 3);
  68 
  69         createNewPrintPageSetup(pageFormat);
  70 
  71         boolean status = latch.await(5, TimeUnit.MINUTES);
  72 
  73         if (!status) {
  74             throw new RuntimeException("Test timed out.");
  75         }
  76 
  77         SwingUtilities.invokeAndWait(() -> {
  78             test.disposeUI();
  79         });
  80 
  81         if (test.testResult == false) {
  82             throw new RuntimeException("Test Failed.");
  83         }
  84     }
  85 
  86     public static void createNewPrintPageSetup(PageFormat pageFormat)
  87             throws PrinterException {
  88 
  89         // Display printer default setup dialog
  90         java.awt.print.PrinterJob.getPrinterJob().pageDialog(pageFormat);
  91     }
  92 
  93     public static void setValuesForPrintPageSetup(PageFormat pageFormat,
  94                                                   int marginValue) throws PrinterException {
  95         Paper paper = new Paper();
  96 
  97         double paperHeight = paper.getHeight();
  98         double paperWidth = paper.getWidth();
  99         double paperX = paper.getImageableX();
 100         double paperY = paper.getImageableY();
 101         paper.setImageableArea(paperX * marginValue, paperY * marginValue,
 102                 paperWidth - (paperX * 2 * marginValue),
 103                 paperHeight - (paperY * 2 * marginValue));
 104         pageFormat.setPaper(paper);
 105 
 106         java.awt.print.PrinterJob.getPrinterJob().pageDialog(pageFormat);
 107     }
 108 }
 109 
 110 class TestUI {
 111 
 112     private static JFrame mainFrame;
 113     private static JPanel mainControlPanel;
 114 
 115     private static JTextArea instructionTextArea;
 116 
 117     private static JPanel resultButtonPanel;
 118     private static JButton passButton;
 119     private static JButton failButton;
 120 
 121     private static JPanel testPanel;
 122     private static JButton testButton;
 123     private static JLabel buttonPressCountLabel;
 124 
 125     private static GridBagLayout layout;
 126     private final CountDownLatch latch;
 127     public boolean testResult = false;
 128 
 129     public TestUI(CountDownLatch latch) throws Exception {
 130         this.latch = latch;
 131     }
 132 
 133     public final void createUI() {
 134 
 135         mainFrame = new JFrame("PDialogTest");
 136 
 137         layout = new GridBagLayout();
 138         mainControlPanel = new JPanel(layout);
 139         resultButtonPanel = new JPanel(layout);
 140         testPanel = new JPanel(layout);
 141 
 142         GridBagConstraints gbc = new GridBagConstraints();
 143 
 144         // Create Test instructions
 145         String instructions
 146                 = "This test displays the print setup dialog with margins \n"
 147                 + "displayed as inches(Use equivalent conversion if different)\n"
 148                 + "\n"
 149                 + "Step 1: Verify that margins displays as 1 for left, right,\n"
 150                 + "        top and bottom margins, then click OK.\n"
 151                 + "Step 2: Verify that margins displays as 2 for left, right,\n"
 152                 + "        top and bottom margins, then click OK (A new value \n"
 153                 + "        2 has been set by setting a new imagable area).\n"
 154                 + "Step 3: Verify that margins dipslays as 2 for left, right,\n"
 155                 + "        top and bottom margins, then click OK (The newly set\n"
 156                 + "        imageable area retains even after closing in the\n"
 157                 + "        previous step).\n"
 158                 + "Step 4: Verify that margins displays as 3 for left, right,\n"
 159                 + "        top and bottom margins, then click OK (A new value \n"
 160                 + "        3 has been set by setting a new imagable area).\n"
 161                 + "Step 5: Verify that margins dipslays as 3 for left, right,\n"
 162                 + "        top and bottom margins, then click OK (The newly set\n"
 163                 + "        imageable area retains even after closing in the\n"
 164                 + "        previous step).\n"
 165                 + "Click on 'pass' if successful else click on 'fail'\n";
 166 
 167         instructionTextArea = new JTextArea();
 168         instructionTextArea.setText(instructions);
 169         instructionTextArea.setEditable(false);
 170         instructionTextArea.setBorder(BorderFactory.
 171                 createTitledBorder("Test Instructions"));
 172 
 173         gbc.gridx = 0;
 174         gbc.gridy = 0;
 175         gbc.fill = GridBagConstraints.HORIZONTAL;
 176         mainControlPanel.add(instructionTextArea, gbc);
 177 
 178         gbc.gridx = 0;
 179         gbc.gridy = 1;
 180         testPanel.add(Box.createVerticalStrut(50));
 181 
 182         mainControlPanel.add(testPanel);
 183 
 184         // Create resultButtonPanel with Pass, Fail buttons
 185         passButton = new JButton("Pass");
 186         passButton.setActionCommand("Pass");
 187         passButton.addActionListener((ActionEvent e) -> {
 188             System.out.println("Pass Button pressed!");
 189             testResult = true;
 190             latch.countDown();
 191             disposeUI();
 192         });
 193 
 194         failButton = new JButton("Fail");
 195         failButton.setActionCommand("Fail");
 196         failButton.addActionListener((ActionEvent e) -> {
 197             System.out.println("Fail Button pressed!");
 198             testResult = false;
 199             latch.countDown();
 200             disposeUI();
 201         });
 202 
 203         gbc.gridx = 0;
 204         gbc.gridy = 0;
 205         resultButtonPanel.add(passButton, gbc);
 206 
 207         gbc.gridx = 1;
 208         gbc.gridy = 0;
 209         resultButtonPanel.add(failButton, gbc);
 210 
 211         gbc.gridx = 0;
 212         gbc.gridy = 1;
 213         mainControlPanel.add(resultButtonPanel, gbc);
 214 
 215         mainFrame.add(mainControlPanel);
 216         mainFrame.pack();
 217         mainFrame.setVisible(true);

 218     }
 219 
 220     public void disposeUI() {
 221         mainFrame.dispose();
 222     }
 223 }
< prev index next >