001: /**
002: * ===========================================
003: * JFreeReport : a free Java reporting library
004: * ===========================================
005: *
006: * Project Info: http://reporting.pentaho.org/
007: *
008: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
009: *
010: * This library is free software; you can redistribute it and/or modify it under the terms
011: * of the GNU Lesser General Public License as published by the Free Software Foundation;
012: * either version 2.1 of the License, or (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
015: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016: * See the GNU Lesser General Public License for more details.
017: *
018: * You should have received a copy of the GNU Lesser General Public License along with this
019: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020: * Boston, MA 02111-1307, USA.
021: *
022: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023: * in the United States and other countries.]
024: *
025: * ------------
026: * PdfExportPlugin.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.modules.gui.pdf;
030:
031: import java.util.Locale;
032: import javax.swing.Icon;
033: import javax.swing.KeyStroke;
034:
035: import org.jfree.report.JFreeReport;
036: import org.jfree.report.JFreeReportBoot;
037: import org.jfree.report.modules.gui.commonswing.AbstractExportActionPlugin;
038: import org.jfree.report.modules.gui.commonswing.ReportProgressDialog;
039: import org.jfree.report.modules.gui.commonswing.StatusType;
040: import org.jfree.report.modules.gui.commonswing.SwingGuiContext;
041: import org.jfree.ui.RefineryUtilities;
042: import org.jfree.util.Log;
043: import org.jfree.util.ResourceBundleSupport;
044:
045: /**
046: * Encapsulates the PDF export into a separate export plugin.
047: *
048: * @author Thomas Morgner
049: */
050: public class PdfExportPlugin extends AbstractExportActionPlugin {
051: /**
052: * Localised resources.
053: */
054: private final ResourceBundleSupport resources;
055:
056: /**
057: * The base resource class.
058: */
059: public static final String BASE_RESOURCE_CLASS = "org.jfree.report.modules.gui.pdf.messages.messages"; //$NON-NLS-1$
060: public static final String PROGRESS_DIALOG_ENABLE_KEY = "org.jfree.report.modules.gui.pdf.ProgressDialogEnabled"; //$NON-NLS-1$
061:
062: protected String getConfigurationPrefix() {
063: return "org.jfree.report.modules.gui.pdf.export."; //$NON-NLS-1$
064: }
065:
066: /**
067: * DefaultConstructor.
068: */
069: public PdfExportPlugin() {
070: resources = new ResourceBundleSupport(BASE_RESOURCE_CLASS);
071: }
072:
073: public boolean initialize(final SwingGuiContext context) {
074: if (super .initialize(context) == false) {
075: return false;
076: }
077: if (JFreeReportBoot.getInstance().isModuleAvailable(
078: PdfExportGUIModule.class.getName()) == false) {
079: return false;
080: }
081: return true;
082: }
083:
084: /**
085: * Creates the progress dialog that monitors the export process.
086: *
087: * @return the progress monitor dialog.
088: */
089: protected ReportProgressDialog createProgressDialog() {
090: final ReportProgressDialog progressDialog = super
091: .createProgressDialog();
092: progressDialog
093: .setDefaultCloseOperation(ReportProgressDialog.DO_NOTHING_ON_CLOSE);
094: progressDialog.setMessage(resources
095: .getString("pdf-export.progressdialog.message")); //$NON-NLS-1$
096: progressDialog.pack();
097: RefineryUtilities.positionFrameRandomly(progressDialog);
098: return progressDialog;
099: }
100:
101: /**
102: * Shows this dialog and (if the dialog is confirmed) saves the complete report into an
103: * PDF file.
104: *
105: * @param report the report being processed.
106: * @return true or false.
107: */
108: public boolean performExport(final JFreeReport report) {
109: final boolean result = performShowExportDialog(report,
110: "org.jfree.report.modules.gui.pdf.Dialog"); //$NON-NLS-1$
111: if (result == false) {
112: // user canceled the dialog ...
113: return false;
114: }
115:
116: final ReportProgressDialog progressDialog;
117: if (isProgressDialogEnabled(report,
118: "org.jfree.report.modules.gui.pdf.ProgressDialogEnabled")) {
119: progressDialog = createProgressDialog();
120: if (report.getName() == null) {
121: progressDialog.setTitle(getResources().getString(
122: "ProgressDialog.EMPTY_TITLE"));
123: } else {
124: progressDialog.setTitle(getResources().formatMessage(
125: "ProgressDialog.TITLE", report.getName()));
126: }
127: } else {
128: progressDialog = null;
129: }
130:
131: try {
132: final PdfExportTask task = new PdfExportTask(report,
133: progressDialog, getContext());
134: final Thread worker = new Thread(task);
135: worker.start();
136: return true;
137: } catch (Exception e) {
138: Log.error("Failure while preparing the PDF export", e); //$NON-NLS-1$
139: getContext().getStatusListener().setStatus(
140: StatusType.ERROR,
141: resources.getString("PdfExportPlugin.USER_FAILED")); //$NON-NLS-1$
142: return false;
143: }
144: }
145:
146: /**
147: * Returns the display name.
148: *
149: * @return The display name.
150: */
151: public String getDisplayName() {
152: return resources.getString("action.save-as.name"); //$NON-NLS-1$
153: }
154:
155: /**
156: * Returns the short description for the action.
157: *
158: * @return The short description.
159: */
160: public String getShortDescription() {
161: return resources.getString("action.save-as.description"); //$NON-NLS-1$
162: }
163:
164: /**
165: * Returns the small icon for the action.
166: *
167: * @return The icon.
168: */
169: public Icon getSmallIcon() {
170: final Locale locale = getContext().getLocale();
171: return getIconTheme().getSmallIcon(locale,
172: "action.export-to-pdf.small-icon"); //$NON-NLS-1$
173: }
174:
175: /**
176: * Returns the large icon for the action.
177: *
178: * @return The icon.
179: */
180: public Icon getLargeIcon() {
181: final Locale locale = getContext().getLocale();
182: return getIconTheme().getLargeIcon(locale,
183: "action.export-to-pdf.icon"); //$NON-NLS-1$
184: }
185:
186: /**
187: * Returns the accelerator key for the action.
188: *
189: * @return The accelerator key.
190: */
191: public KeyStroke getAcceleratorKey() {
192: return resources.getKeyStroke("action.save-as.accelerator"); //$NON-NLS-1$
193: }
194:
195: /**
196: * Returns the mnemonic key code.
197: *
198: * @return The key code.
199: */
200: public Integer getMnemonicKey() {
201: return resources.getMnemonic("action.save-as.mnemonic"); //$NON-NLS-1$
202: }
203:
204: /**
205: * Returns the resourcebundle to be used to translate strings into localized content.
206: *
207: * @return the resourcebundle for the localisation.
208: */
209: protected ResourceBundleSupport getResources() {
210: return resources;
211: }
212: }
|