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