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: * ExportAction.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.modules.gui.base.actions;
030:
031: import java.awt.event.ActionEvent;
032: import java.beans.PropertyChangeEvent;
033: import java.beans.PropertyChangeListener;
034: import javax.swing.AbstractAction;
035: import javax.swing.Action;
036:
037: import org.jfree.report.JFreeReport;
038: import org.jfree.report.modules.gui.base.PreviewPane;
039: import org.jfree.report.modules.gui.commonswing.ExportActionPlugin;
040: import org.jfree.report.modules.gui.commonswing.SwingCommonModule;
041: import org.jfree.ui.action.ActionDowngrade;
042: import org.jfree.util.Log;
043:
044: /**
045: * Creation-Date: 16.11.2006, 17:52:48
046: *
047: * @author Thomas Morgner
048: */
049: public class ExportAction extends AbstractAction {
050: private class EnableChangeListener implements
051: PropertyChangeListener {
052: protected EnableChangeListener() {
053: }
054:
055: public void propertyChange(final PropertyChangeEvent evt) {
056: setEnabled(actionPlugin.isEnabled());
057: }
058: }
059:
060: private ExportActionPlugin actionPlugin;
061: private PreviewPane previewPane;
062:
063: /**
064: * Defines an <code>Action</code> object with a default description string and
065: * default icon.
066: */
067: public ExportAction(final ExportActionPlugin actionPlugin,
068: final PreviewPane previewPane) {
069: if (actionPlugin == null) {
070: throw new NullPointerException();
071: }
072: if (previewPane == null) {
073: throw new NullPointerException();
074: }
075:
076: this .actionPlugin = actionPlugin;
077: this .previewPane = previewPane;
078: putValue(Action.NAME, actionPlugin.getDisplayName());
079: putValue(Action.SHORT_DESCRIPTION, actionPlugin
080: .getShortDescription());
081: putValue(ActionDowngrade.ACCELERATOR_KEY, actionPlugin
082: .getAcceleratorKey());
083: putValue(ActionDowngrade.MNEMONIC_KEY, actionPlugin
084: .getMnemonicKey());
085: putValue(Action.SMALL_ICON, actionPlugin.getSmallIcon());
086: putValue(SwingCommonModule.LARGE_ICON_PROPERTY, actionPlugin
087: .getLargeIcon());
088: this .actionPlugin.addPropertyChangeListener(
089: "enabled", new EnableChangeListener()); //$NON-NLS-1$
090:
091: setEnabled(actionPlugin.isEnabled());
092: }
093:
094: /**
095: * Invoked when an action occurs.
096: */
097: public void actionPerformed(final ActionEvent e) {
098: if (actionPlugin.isEnabled() == false) {
099: return;
100: }
101:
102: final JFreeReport reportJob = previewPane.getReportJob();
103: if (reportJob == null) {
104: return;
105: }
106:
107: try {
108: actionPlugin.performExport((JFreeReport) reportJob.clone());
109: } catch (CloneNotSupportedException e1) {
110: Log.error("Internal error: Failed to clone the report."); //$NON-NLS-1$
111: }
112: }
113: }
|