2122N/A/*
2362N/A * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
2122N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2122N/A *
2122N/A * This code is free software; you can redistribute it and/or modify it
2122N/A * under the terms of the GNU General Public License version 2 only, as
2122N/A * published by the Free Software Foundation.
2122N/A *
2122N/A * This code is distributed in the hope that it will be useful, but WITHOUT
2122N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
2122N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
2122N/A * version 2 for more details (a copy is included in the LICENSE file that
2122N/A * accompanied this code).
2122N/A *
2122N/A * You should have received a copy of the GNU General Public License version
2122N/A * 2 along with this work; if not, write to the Free Software Foundation,
2122N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
2122N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
2122N/A */
2122N/A
2122N/A/**
2122N/A * @test
2122N/A * @bug 6195901 6195923 6195928 6195933 6491273 6888734
2122N/A * @summary No SecurityException should be thrown when printing to a file
2122N/A using the given policy.
2122N/A Print to file option should be selected.
2122N/A * @run main/othervm/policy=policy SecurityDialogTest
2122N/A */
2122N/Aimport java.awt.*;
2122N/Aimport java.awt.event.*;
2122N/Aimport java.util.*;
2122N/Aimport java.io.*;
2122N/A
2122N/A
2122N/Apublic class SecurityDialogTest extends Frame implements ActionListener {
2122N/A // Declare things used in the test, like buttons and labels here
2122N/A
2122N/A Button nativeDlg, setSecurity;
2122N/A boolean isNative = true;
2122N/A
2122N/A public SecurityDialogTest() {
2122N/A
2122N/A nativeDlg = new Button("Print Dialog");
2122N/A nativeDlg.addActionListener(this);
2122N/A setSecurity = new Button("Toggle Dialog");
2122N/A setSecurity.addActionListener(this);
2122N/A add("South", nativeDlg);
2122N/A add("North", setSecurity);
2122N/A setSize(300, 300);
2122N/A setVisible(true);
2122N/A }
2122N/A
2122N/A public static void main(String args[]) {
2122N/A System.out.println("Native dialog is the default");
2122N/A SecurityDialogTest test = new SecurityDialogTest();
2122N/A }
2122N/A
2122N/A public void actionPerformed(ActionEvent e) {
2122N/A
2122N/A if (e.getSource() == setSecurity) {
2122N/A if (isNative) {
2122N/A isNative = false;
2122N/A System.out.println("Common dialog is the default");
2122N/A
2122N/A } else {
2122N/A isNative = true;
2122N/A System.out.println("Native dialog is the default");
2122N/A }
2122N/A return;
2122N/A }
2122N/A
2122N/A JobAttributes ja = new JobAttributes();
2122N/A PageAttributes pa = new PageAttributes();
2122N/A
2122N/A if (isNative) {
2122N/A ja.setDialog(JobAttributes.DialogType.NATIVE);
2122N/A } else {
2122N/A ja.setDialog(JobAttributes.DialogType.COMMON);
2122N/A }
2122N/A ja.setDestination(JobAttributes.DestinationType.FILE);
2122N/A ja.setFileName("mohan.ps");
2122N/A
2122N/A
2122N/A PrintJob pjob = getToolkit().getPrintJob(this, null, ja, pa);
2122N/A
2122N/A if (pjob != null) {
2122N/A Graphics pg = pjob.getGraphics();
2122N/A System.out.println("PJOB: " + pjob);
2122N/A if (pg != null) {
2122N/A System.out.println("Printer Graphics: " + pg);
2122N/A this.printAll(pg);
2122N/A pg.dispose();
2122N/A } else {
2122N/A System.out.println("Printer Graphics is null");
2122N/A }
2122N/A pjob.end();
2122N/A System.out.println("DONE");
2122N/A } else {
2122N/A System.out.println("PJOB is null");
2122N/A }
2122N/A }
2122N/A}