Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/awt/PrintJob/Security/SecurityDialogTest.java
38828 views
/*1* Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/**24* @test25* @bug 6195901 6195923 6195928 6195933 6491273 688873426* @summary No SecurityException should be thrown when printing to a file27using the given policy.28Print to file option should be selected.29* @run main/othervm/policy=policy SecurityDialogTest30*/31import java.awt.*;32import java.awt.event.*;33import java.util.*;34import java.io.*;353637public class SecurityDialogTest extends Frame implements ActionListener {38// Declare things used in the test, like buttons and labels here3940Button nativeDlg, setSecurity;41boolean isNative = true;4243public SecurityDialogTest() {4445nativeDlg = new Button("Print Dialog");46nativeDlg.addActionListener(this);47setSecurity = new Button("Toggle Dialog");48setSecurity.addActionListener(this);49add("South", nativeDlg);50add("North", setSecurity);51setSize(300, 300);52setVisible(true);53}5455public static void main(String args[]) {56System.out.println("Native dialog is the default");57SecurityDialogTest test = new SecurityDialogTest();58}5960public void actionPerformed(ActionEvent e) {6162if (e.getSource() == setSecurity) {63if (isNative) {64isNative = false;65System.out.println("Common dialog is the default");6667} else {68isNative = true;69System.out.println("Native dialog is the default");70}71return;72}7374JobAttributes ja = new JobAttributes();75PageAttributes pa = new PageAttributes();7677if (isNative) {78ja.setDialog(JobAttributes.DialogType.NATIVE);79} else {80ja.setDialog(JobAttributes.DialogType.COMMON);81}82ja.setDestination(JobAttributes.DestinationType.FILE);83ja.setFileName("mohan.ps");848586PrintJob pjob = getToolkit().getPrintJob(this, null, ja, pa);8788if (pjob != null) {89Graphics pg = pjob.getGraphics();90System.out.println("PJOB: " + pjob);91if (pg != null) {92System.out.println("Printer Graphics: " + pg);93this.printAll(pg);94pg.dispose();95} else {96System.out.println("Printer Graphics is null");97}98pjob.end();99System.out.println("DONE");100} else {101System.out.println("PJOB is null");102}103}104}105106107