01: /**
02: * ===========================================
03: * JFreeReport : a free Java reporting library
04: * ===========================================
05: *
06: * Project Info: http://reporting.pentaho.org/
07: *
08: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
09: *
10: * This library is free software; you can redistribute it and/or modify it under the terms
11: * of the GNU Lesser General Public License as published by the Free Software Foundation;
12: * either version 2.1 of the License, or (at your option) any later version.
13: *
14: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16: * See the GNU Lesser General Public License for more details.
17: *
18: * You should have received a copy of the GNU Lesser General Public License along with this
19: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20: * Boston, MA 02111-1307, USA.
21: *
22: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
23: * in the United States and other countries.]
24: *
25: * ------------
26: * PrintExportTask.java
27: * ------------
28: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
29: */package org.jfree.report.modules.gui.print;
30:
31: import org.jfree.report.JFreeReport;
32: import org.jfree.report.modules.gui.common.StatusListener;
33: import org.jfree.report.modules.gui.commonswing.ReportProgressDialog;
34: import org.jfree.report.modules.gui.commonswing.StatusType;
35: import org.jfree.report.modules.gui.commonswing.SwingGuiContext;
36: import org.jfree.report.util.i18n.Messages;
37: import org.jfree.util.Log;
38:
39: /**
40: * An export task implementation that prints a report using the AWT printing API.
41: *
42: * @author Thomas Morgner
43: */
44: public class PrintExportTask implements Runnable {
45: private Messages messages;
46: private JFreeReport job;
47: private ReportProgressDialog progressListener;
48: private StatusListener statusListener;
49:
50: public PrintExportTask(final JFreeReport job,
51: final ReportProgressDialog progressListener,
52: final SwingGuiContext swingGuiContext) {
53: this .job = job;
54: this .progressListener = progressListener;
55: if (swingGuiContext != null) {
56: this .statusListener = swingGuiContext.getStatusListener();
57: this .messages = new Messages(swingGuiContext.getLocale(),
58: PrintingPlugin.BASE_RESOURCE_CLASS);
59: }
60: }
61:
62: /**
63: * When an object implementing interface <code>Runnable</code> is used to
64: * create a thread, starting the thread causes the object's <code>run</code>
65: * method to be called in that separately executing thread.
66: * <p/>
67: * The general contract of the method <code>run</code> is that it may take any
68: * action whatsoever.
69: *
70: * @see Thread#run()
71: */
72: public void run() {
73: try {
74: if (progressListener != null) {
75: progressListener.setVisible(true);
76: }
77: PrintUtil.print(job, progressListener);
78: } catch (Exception e) {
79: if (statusListener != null) {
80: statusListener
81: .setStatus(
82: StatusType.ERROR,
83: messages
84: .getString("PrintExportTask.USER_EXPORT_FAILED")); //$NON-NLS-1$
85: }
86: Log.error("Failed"); //$NON-NLS-1$
87: } finally {
88: if (progressListener != null) {
89: progressListener.setVisible(false);
90: }
91: }
92: }
93:
94: }
|