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: * HtmlDirExportPlugin.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.modules.gui.html;
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 HtmlExportDialog into a separate plugin.
047: *
048: * @author Thomas Morgner
049: */
050: public class HtmlDirExportPlugin 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.html.messages.messages"; //$NON-NLS-1$
060:
061: /**
062: * DefaultConstructor.
063: */
064: public HtmlDirExportPlugin() {
065: resources = new ResourceBundleSupport(
066: HtmlDirExportPlugin.BASE_RESOURCE_CLASS);
067: }
068:
069: public boolean initialize(final SwingGuiContext context) {
070: if (super .initialize(context) == false) {
071: return false;
072: }
073: if (JFreeReportBoot.getInstance().isModuleAvailable(
074: HtmlExportGUIModule.class.getName()) == false) {
075: return false;
076: }
077: return true;
078: }
079:
080: protected String getConfigurationPrefix() {
081: return "org.jfree.report.modules.gui.html.export.file."; //$NON-NLS-1$
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("html-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: * Excel 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.html.file.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.html.file.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 HtmlDirExportTask task = new HtmlDirExportTask(
133: report, 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 HTML export", e); //$NON-NLS-1$
139: getContext()
140: .getStatusListener()
141: .setStatus(
142: StatusType.ERROR,
143: resources
144: .getString("HtmlDirExportPlugin.USER_FAILED")); //$NON-NLS-1$
145: return false;
146: }
147: }
148:
149: /**
150: * Returns the action display name.
151: *
152: * @return The display name.
153: */
154: public String getDisplayName() {
155: return resources.getString("action.export-to-html.file.name"); //$NON-NLS-1$
156: }
157:
158: /**
159: * Returns the short description for the action.
160: *
161: * @return The short description.
162: */
163: public String getShortDescription() {
164: return resources
165: .getString("action.export-to-html.file.description"); //$NON-NLS-1$
166: }
167:
168: /**
169: * Returns the small icon for the action.
170: *
171: * @return The icon.
172: */
173: public Icon getSmallIcon() {
174: final Locale locale = getContext().getLocale();
175: return getIconTheme().getSmallIcon(locale,
176: "action.export-to-html.file.small-icon"); //$NON-NLS-1$
177: }
178:
179: /**
180: * Returns the large icon for the action.
181: *
182: * @return The icon.
183: */
184: public Icon getLargeIcon() {
185: final Locale locale = getContext().getLocale();
186: return getIconTheme().getLargeIcon(locale,
187: "action.export-to-html.file.icon"); //$NON-NLS-1$
188: }
189:
190: /**
191: * Returns the accelerator key for the action.
192: *
193: * @return The accelerator key.
194: */
195: public KeyStroke getAcceleratorKey() {
196: return resources
197: .getOptionalKeyStroke("action.export-to-html.file.accelerator"); //$NON-NLS-1$
198: }
199:
200: /**
201: * Returns the mnemonic key code for the action.
202: *
203: * @return The key code.
204: */
205: public Integer getMnemonicKey() {
206: return resources
207: .getMnemonic("action.export-to-html.file.mnemonic"); //$NON-NLS-1$
208: }
209:
210: /**
211: * Returns the resourcebundle to be used to translate strings into localized content.
212: *
213: * @return the resourcebundle for the localisation.
214: */
215: protected ResourceBundleSupport getResources() {
216: return resources;
217: }
218: }
|