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 4254954 27 * @summary PageFormat would fail on solaris when setting orientation 28 */ 29 30 import java.awt.*; 31 import java.awt.event.*; 32 import java.awt.print.*; 33 34 public class ReverseLandscapeTest extends Frame { 35 36 private TextCanvas c; 37 38 public static void main(String args[]) { 39 ReverseLandscapeTest f = new ReverseLandscapeTest(); 40 f.show(); 41 } 42 43 public ReverseLandscapeTest() { 44 super("JDK 1.2 Text Printing"); 45 46 c = new TextCanvas(); 47 add("Center", c); 48 49 PrinterJob pj = PrinterJob.getPrinterJob(); 50 51 PageFormat pf = pj.defaultPage(); 52 pf.setOrientation(PageFormat.REVERSE_LANDSCAPE); 53 54 // This code can be added if one wishes to test printing 55 // pf = pj.pageDialog(pf); 56 57 // if (pj != null && pj.printDialog()) { 58 59 // pj.setPrintable(c, pf); 60 // try { 61 // pj.print(); 62 // } catch (PrinterException pe) { 63 // } finally { 64 // System.err.println("PRINT RETURNED"); 65 // } 66 // } 67 68 addWindowListener(new WindowAdapter() { 69 public void windowClosing(WindowEvent e) { 70 System.exit(0); 71 } 72 }); 73 74 pack(); 75 } 76 77 class TextCanvas extends Panel implements Printable { 78 79 public int print(Graphics g, PageFormat pgFmt, int pgIndex) { 80 int iw = getWidth(); 81 int ih = getHeight(); 82 Graphics2D g2d = (Graphics2D)g; 83 84 if (pgIndex > 0) 85 return Printable.NO_SUCH_PAGE; 86 87 g2d.translate(pgFmt.getImageableX(), pgFmt.getImageableY()); 88 g2d.translate(iw/2, ih/2); 89 g2d.setFont(new Font("Times",Font.PLAIN, 12)); 90 g2d.setPaint(new Color(0,0,0)); 91 g2d.setStroke(new BasicStroke(1f)); 92 g2d.drawString("Print REVERSE_LANDSCAPE", 30, 40); 93 94 return Printable.PAGE_EXISTS; 95 } 96 97 public void paint(Graphics g) { 98 g.drawString("Print REVERSE_LANDSCAPE", 30, 40); 99 } 100 101 public Dimension getPreferredSize() { 102 return new Dimension(250, 100); 103 } 104 } 105 106 }