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: * PrintingPlugin.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.modules.gui.print;
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.SwingGuiContext;
040: import org.jfree.ui.RefineryUtilities;
041: import org.jfree.util.ResourceBundleSupport;
042:
043: /**
044: * An export plugin for the <code>java.awt.print</code> API.
045: * <p/>
046: *
047: * @author Thomas Morgner
048: */
049: public class PrintingPlugin extends AbstractExportActionPlugin {
050: /**
051: * Localised resources.
052: */
053: private final ResourceBundleSupport resources;
054:
055: /**
056: * The base resource class.
057: */
058: public static final String BASE_RESOURCE_CLASS = "org.jfree.report.modules.gui.print.messages.messages"; //$NON-NLS-1$
059: public static final String PROGRESS_DIALOG_ENABLE_KEY = "org.jfree.report.modules.gui.print.ProgressDialogEnabled"; //$NON-NLS-1$
060:
061: /**
062: * DefaultConstructor.
063: */
064: public PrintingPlugin() {
065: resources = new ResourceBundleSupport(BASE_RESOURCE_CLASS);
066: }
067:
068: public boolean initialize(final SwingGuiContext context) {
069: if (super .initialize(context) == false) {
070: return false;
071: }
072: if (JFreeReportBoot.getInstance().isModuleAvailable(
073: AWTPrintingGUIModule.class.getName()) == false) {
074: return false;
075: }
076: return true;
077: }
078:
079: /**
080: * Returns the resourcebundle used to translate strings.
081: *
082: * @return the resourcebundle.
083: */
084: protected ResourceBundleSupport getResources() {
085: return resources;
086: }
087:
088: /**
089: * Creates the progress dialog that monitors the export process.
090: *
091: * @return the progress monitor dialog.
092: */
093: protected ReportProgressDialog createProgressDialog() {
094: final ReportProgressDialog progressDialog = super
095: .createProgressDialog();
096: progressDialog
097: .setDefaultCloseOperation(ReportProgressDialog.DO_NOTHING_ON_CLOSE);
098: progressDialog.setMessage(resources
099: .getString("printing-export.progressdialog.message")); //$NON-NLS-1$
100: progressDialog.pack();
101: RefineryUtilities.positionFrameRandomly(progressDialog);
102: return progressDialog;
103: }
104:
105: protected String getConfigurationPrefix() {
106: return "org.jfree.report.modules.gui.print.print."; //$NON-NLS-1$
107: }
108:
109: /**
110: * Exports a report.
111: *
112: * @param report the report.
113: * @return true, if the export was successfull, false otherwise.
114: */
115: public boolean performExport(final JFreeReport report) {
116: // need to connect to the report pane to receive state updates ...
117: final ReportProgressDialog progressDialog;
118: if ("true".equals(report.getReportConfiguration().getConfigProperty(PROGRESS_DIALOG_ENABLE_KEY, "false"))) //$NON-NLS-1$ //$NON-NLS-2$
119: {
120: progressDialog = createProgressDialog();
121: if (report.getName() == null) {
122: progressDialog.setTitle(getResources().getString(
123: "ProgressDialog.EMPTY_TITLE"));
124: } else {
125: progressDialog.setTitle(getResources().formatMessage(
126: "ProgressDialog.TITLE", report.getName()));
127: }
128: } else {
129: progressDialog = null;
130: }
131:
132: final PrintExportTask task = new PrintExportTask(report,
133: progressDialog, getContext());
134: final Thread worker = new Thread(task);
135: worker.start();
136: return true;
137: }
138:
139: /**
140: * Returns the display name for the export action.
141: *
142: * @return The display name.
143: */
144: public String getDisplayName() {
145: return (resources.getString("action.print.name")); //$NON-NLS-1$
146: }
147:
148: /**
149: * Returns the short description for the export action.
150: *
151: * @return The short description.
152: */
153: public String getShortDescription() {
154: return (resources.getString("action.print.description")); //$NON-NLS-1$
155: }
156:
157: /**
158: * Returns the small icon for the export action.
159: *
160: * @return The icon.
161: */
162: public Icon getSmallIcon() {
163: final Locale locale = getContext().getLocale();
164: return getIconTheme().getSmallIcon(locale,
165: "action.print.small-icon"); //$NON-NLS-1$
166: }
167:
168: /**
169: * Returns the large icon for the export action.
170: *
171: * @return The icon.
172: */
173: public Icon getLargeIcon() {
174: final Locale locale = getContext().getLocale();
175: return getIconTheme().getLargeIcon(locale, "action.print.icon"); //$NON-NLS-1$
176: }
177:
178: /**
179: * Returns the accelerator key for the export action.
180: *
181: * @return The accelerator key.
182: */
183: public KeyStroke getAcceleratorKey() {
184: return (resources.getKeyStroke("action.print.accelerator")); //$NON-NLS-1$
185: }
186:
187: /**
188: * Returns the mnemonic key code.
189: *
190: * @return The code.
191: */
192: public Integer getMnemonicKey() {
193: return (resources.getMnemonic("action.print.mnemonic")); //$NON-NLS-1$
194: }
195:
196: }
|