/test/java/awt/PrintJob/PrintArcTest/PrintArcTest.java

https://github.com/ikeji/openjdk7-jdk · Java · 105 lines · 61 code · 16 blank · 28 comment · 6 complexity · 4edd173eb4d4d680a21e50b6acd7e30e MD5 · raw file

  1. /*
  2. * Copyright (c) 1998, 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. @test
  25. @bug 4105609
  26. @summary Test printing of drawArc preceded by drawString
  27. @author robi.khan
  28. */
  29. import java.awt.*;
  30. import java.awt.event.*;
  31. public class PrintArcTest extends Panel implements ActionListener {
  32. PrintCanvas canvas;
  33. public PrintArcTest () {
  34. setLayout(new BorderLayout());
  35. canvas = new PrintCanvas ();
  36. add("North", canvas);
  37. Button b = new Button("Click Me to Print!");
  38. b.setActionCommand ("print");
  39. b.addActionListener (this);
  40. add("South", b);
  41. validate();
  42. }
  43. public void actionPerformed(ActionEvent e) {
  44. String cmd = e.getActionCommand();
  45. if (cmd.equals("print")) {
  46. PrintJob pjob = getToolkit().getPrintJob(getFrame(), "Printing Test", null);
  47. if (pjob != null) {
  48. Graphics pg = pjob.getGraphics();
  49. if (pg != null) {
  50. canvas.printAll(pg);
  51. pg.dispose(); //flush page
  52. }
  53. pjob.end();
  54. }
  55. }
  56. }
  57. private Frame getFrame() {
  58. Container cont = getParent();;
  59. while ( !(cont instanceof Frame ) ) {
  60. cont = cont.getParent();
  61. }
  62. return (Frame)cont;
  63. }
  64. public static void main(String args[]) {
  65. PrintArcTest test = new PrintArcTest();
  66. Frame f = new Frame( "PrintArcTest for Bug #4105609");
  67. f.add( test );
  68. f.setSize(500,400);
  69. f.show();
  70. f.addWindowListener( new WindowAdapter() {
  71. public void windowClosing(WindowEvent ev) {
  72. System.exit(0);
  73. }
  74. }
  75. );
  76. }
  77. }
  78. class PrintCanvas extends Canvas {
  79. public Dimension getPreferredSize() {
  80. return new Dimension(300,300);
  81. }
  82. public void paint (Graphics g) {
  83. g.drawString("drawArc(25,50,150,100,45,90);",25,25);
  84. g.drawArc(25,50,150,100,45,90);
  85. g.drawString("drawOval(25,200,200,40);",25,175);
  86. g.drawOval(25,200,200,40);
  87. g.dispose();
  88. }
  89. }