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 /**
  25  * @test
  26  * @bug 4040668
  27  * @summary Checks that banner titles which contain double quotation marks
  28  * or backslashes still print correctly.
  29  * @author dpm
  30  */
  31 
  32 import java.awt.*;
  33 import java.awt.event.*;
  34 
  35 
  36 public class QuoteAndBackslashTest {
  37     public static void main(String[] args) {
  38         new QuoteAndBackslashTest().start();
  39     }
  40     public void start() {
  41         new QuoteAndBackslashTestFrame();
  42     }
  43 }
  44 
  45 class QuoteAndBackslashTestFrame extends Frame implements ActionListener {
  46     PrintCanvas canvas;
  47 
  48     public QuoteAndBackslashTestFrame () {
  49         super("QuoteAndBackslashTest");
  50         canvas = new PrintCanvas ();
  51         add("Center", canvas);
  52 
  53         Button b = new Button("Print");
  54         b.setActionCommand ("print");
  55         b.addActionListener (this);
  56         add("South", b);
  57 
  58         pack();
  59         setVisible(true);
  60     }
  61 
  62 
  63     public void actionPerformed(ActionEvent e) {
  64         String cmd = e.getActionCommand();
  65         if (cmd.equals("print")) {
  66             PrintJob pjob = getToolkit().getPrintJob(this, "\\\"\"\\\"",
  67                                                      null);
  68             if (pjob != null) {
  69                 Graphics pg = pjob.getGraphics();
  70 
  71                 if (pg != null)  {
  72                     canvas.printAll(pg);
  73                     pg.dispose();  //flush page
  74                 }
  75 
  76                 pjob.end();
  77             }
  78         }
  79     }
  80 }
  81 
  82 class PrintCanvas extends Canvas {
  83     public Dimension getPreferredSize() {
  84         return new Dimension(659, 792);
  85     }
  86 
  87     public void paint (Graphics g) {
  88         setBackground(Color.white);
  89         g.setColor(Color.blue);
  90         g.fillRoundRect(50, 50, 100, 200, 50, 50);
  91     }
  92 }