1 /*
2 * Copyright (c) 2005, 2006, 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
45 * are not. Please see
46 * <A HREF="http://docs.oracle.com/javase/tutorial/uiswing/concurrency/index.html">Concurrency
47 * in Swing</A> for more information.
48 *
49 * @author Alexander Potochkin
50 * @since 1.6
51 */
52
53 public class PrintingStatus {
54
55 private final PrinterJob job;
56 private final Component parent;
57 private JDialog abortDialog;
58
59 private JButton abortButton;
60 private JLabel statusLabel;
61 private MessageFormat statusFormat;
62 private final AtomicBoolean isAborted = new AtomicBoolean(false);
63
64 // the action that will abort printing
65 private final Action abortAction = new AbstractAction() {
66 public void actionPerformed(ActionEvent ae) {
67 if (!isAborted.get()) {
68 isAborted.set(true);
69
70 // update the status abortDialog to indicate aborting
71 abortButton.setEnabled(false);
72 abortDialog.setTitle(
73 UIManager.getString("PrintingDialog.titleAbortingText"));
74 statusLabel.setText(
75 UIManager.getString("PrintingDialog.contentAbortingText"));
76
77 // cancel the PrinterJob
78 job.cancel();
79 }
80 }
81 };
82
83 private final WindowAdapter closeListener = new WindowAdapter() {
84 public void windowClosing(WindowEvent we) {
|
1 /*
2 * Copyright (c) 2005, 2014, 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
45 * are not. Please see
46 * <A HREF="http://docs.oracle.com/javase/tutorial/uiswing/concurrency/index.html">Concurrency
47 * in Swing</A> for more information.
48 *
49 * @author Alexander Potochkin
50 * @since 1.6
51 */
52
53 public class PrintingStatus {
54
55 private final PrinterJob job;
56 private final Component parent;
57 private JDialog abortDialog;
58
59 private JButton abortButton;
60 private JLabel statusLabel;
61 private MessageFormat statusFormat;
62 private final AtomicBoolean isAborted = new AtomicBoolean(false);
63
64 // the action that will abort printing
65 @SuppressWarnings("serial") // anonymous class
66 private final Action abortAction = new AbstractAction() {
67 public void actionPerformed(ActionEvent ae) {
68 if (!isAborted.get()) {
69 isAborted.set(true);
70
71 // update the status abortDialog to indicate aborting
72 abortButton.setEnabled(false);
73 abortDialog.setTitle(
74 UIManager.getString("PrintingDialog.titleAbortingText"));
75 statusLabel.setText(
76 UIManager.getString("PrintingDialog.contentAbortingText"));
77
78 // cancel the PrinterJob
79 job.cancel();
80 }
81 }
82 };
83
84 private final WindowAdapter closeListener = new WindowAdapter() {
85 public void windowClosing(WindowEvent we) {
|