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: * RTFExportPlugin.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.modules.gui.rtf;
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.ResourceBundleSupport;
043:
044: /**
045: * Encapsulates the ExcelExportDialog into a separate plugin.
046: *
047: * @author Thomas Morgner
048: */
049: public class RTFExportPlugin 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.rtf.messages.messages"; //$NON-NLS-1$
059:
060: /**
061: * DefaultConstructor.
062: */
063: public RTFExportPlugin() {
064: resources = new ResourceBundleSupport(BASE_RESOURCE_CLASS);
065: }
066:
067: public boolean initialize(final SwingGuiContext context) {
068: if (super .initialize(context) == false) {
069: return false;
070: }
071: if (JFreeReportBoot.getInstance().isModuleAvailable(
072: RTFExportGUIModule.class.getName()) == false) {
073: return false;
074: }
075: return true;
076: }
077:
078: protected String getConfigurationPrefix() {
079: return "org.jfree.report.modules.gui.rtf.export."; //$NON-NLS-1$
080: }
081:
082: /**
083: * Creates the progress dialog that monitors the export process.
084: *
085: * @return the progress monitor dialog.
086: */
087: protected ReportProgressDialog createProgressDialog() {
088: final ReportProgressDialog progressDialog = super
089: .createProgressDialog();
090: progressDialog
091: .setDefaultCloseOperation(ReportProgressDialog.DO_NOTHING_ON_CLOSE);
092: progressDialog.setMessage(resources
093: .getString("rtf-export.progressdialog.message")); //$NON-NLS-1$
094: progressDialog.pack();
095: RefineryUtilities.positionFrameRandomly(progressDialog);
096: return progressDialog;
097: }
098:
099: /**
100: * Shows this dialog and (if the dialog is confirmed) saves the complete report into an
101: * Excel file.
102: *
103: * @param report the report being processed.
104: * @return true or false.
105: */
106: public boolean performExport(final JFreeReport report) {
107: final boolean result = performShowExportDialog(report,
108: "org.jfree.report.modules.gui.rtf.Dialog"); //$NON-NLS-1$
109: if (result == false) {
110: // user canceled the dialog ...
111: return false;
112: }
113:
114: final ReportProgressDialog progressDialog;
115: if (isProgressDialogEnabled(report,
116: "org.jfree.report.modules.gui.rtf.ProgressDialogEnabled")) {
117: progressDialog = createProgressDialog();
118: if (report.getName() == null) {
119: progressDialog.setTitle(getResources().getString(
120: "ProgressDialog.EMPTY_TITLE"));
121: } else {
122: progressDialog.setTitle(getResources().formatMessage(
123: "ProgressDialog.TITLE", report.getName()));
124: }
125: } else {
126: progressDialog = null;
127: }
128:
129: try {
130: final RTFExportTask task = new RTFExportTask(report,
131: progressDialog, getContext());
132: final Thread worker = new Thread(task);
133: worker.start();
134: return true;
135: } catch (Exception e) {
136: getContext().getStatusListener().setStatus(
137: StatusType.ERROR,
138: resources.getString("RTFExportPlugin.USER_FAILED")); //$NON-NLS-1$
139: return false;
140: }
141: }
142:
143: /**
144: * Returns a short description for the Excel dialog.
145: *
146: * @return The description.
147: */
148: public String getShortDescription() {
149: return resources.getString("action.export-to-rtf.description"); //$NON-NLS-1$
150: }
151:
152: /**
153: * Returns the small icon for the dialog.
154: *
155: * @return The icon.
156: */
157: public Icon getSmallIcon() {
158: final Locale locale = getContext().getLocale();
159: return getIconTheme().getSmallIcon(locale,
160: "action.export-to-rtf.small-icon"); //$NON-NLS-1$
161: }
162:
163: /**
164: * Returns the large icon for the dialog.
165: *
166: * @return The icon.
167: */
168: public Icon getLargeIcon() {
169: final Locale locale = getContext().getLocale();
170: return getIconTheme().getLargeIcon(locale,
171: "action.export-to-rtf.icon"); //$NON-NLS-1$
172: }
173:
174: /**
175: * Returns the accelerator key for the action associated with the dialog.
176: *
177: * @return The key stroke.
178: */
179: public KeyStroke getAcceleratorKey() {
180: return resources
181: .getKeyStroke("action.export-to-rtf.accelerator"); //$NON-NLS-1$
182: }
183:
184: /**
185: * Returns the mnemonic key code for the action associated with the dialog.
186: *
187: * @return The key code.
188: */
189: public Integer getMnemonicKey() {
190: return resources.getMnemonic("action.export-to-rtf.mnemonic"); //$NON-NLS-1$
191: }
192:
193: /**
194: * Returns the display name.
195: *
196: * @return The display name.
197: */
198: public String getDisplayName() {
199: return resources.getString("action.export-to-rtf.name"); //$NON-NLS-1$
200: }
201:
202: /**
203: * Returns the resourcebundle to be used to translate strings into localized content.
204: *
205: * @return the resourcebundle for the localisation.
206: */
207: protected ResourceBundleSupport getResources() {
208: return resources;
209: }
210: }
|