Source for org.jfree.report.modules.gui.swing.pdf.PdfExportActionPlugin

   1: /**
   2:  * ========================================
   3:  * JFreeReport : a free Java report library
   4:  * ========================================
   5:  *
   6:  * Project Info:  http://reporting.pentaho.org/
   7:  *
   8:  * (C) Copyright 2000-2007, by Object Refinery Limited, Pentaho Corporation and Contributors.
   9:  *
  10:  * This library is free software; you can redistribute it and/or modify it under the terms
  11:  * of the GNU Lesser General Public License as published by the Free Software Foundation;
  12:  * either version 2.1 of the License, or (at your option) any later version.
  13:  *
  14:  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  15:  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  16:  * See the GNU Lesser General Public License for more details.
  17:  *
  18:  * You should have received a copy of the GNU Lesser General Public License along with this
  19:  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  20:  * Boston, MA 02111-1307, USA.
  21:  *
  22:  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
  23:  * in the United States and other countries.]
  24:  *
  25:  * ------------
  26:  * $Id: PdfExportActionPlugin.java 3525 2007-10-16 11:43:48Z tmorgner $
  27:  * ------------
  28:  * (C) Copyright 2000-2005, by Object Refinery Limited.
  29:  * (C) Copyright 2005-2007, by Pentaho Corporation.
  30:  */
  31: 
  32: package org.jfree.report.modules.gui.swing.pdf;
  33: 
  34: import javax.swing.Icon;
  35: import javax.swing.KeyStroke;
  36: 
  37: import org.jfree.report.ReportConfigurationException;
  38: import org.jfree.report.flow.ReportJob;
  39: import org.jfree.report.modules.gui.swing.common.AbstractExportActionPlugin;
  40: import org.jfree.report.modules.gui.swing.common.SwingGuiContext;
  41: import org.jfree.util.ResourceBundleSupport;
  42: 
  43: /**
  44:  * Creation-Date: 02.12.2006, 15:27:01
  45:  *
  46:  * @author Thomas Morgner
  47:  */
  48: public class PdfExportActionPlugin extends AbstractExportActionPlugin
  49: {
  50:   private ResourceBundleSupport resources;
  51:   private static final String EXPORT_DIALOG_KEY =
  52:       "org.jfree.report.modules.gui.swing.pdf.ExportDialog";
  53: 
  54:   public PdfExportActionPlugin()
  55:   {
  56:   }
  57: 
  58:   protected String getConfigurationPrefix()
  59:   {
  60:     return "org.jfree.report.modules.gui.swing.pdf.export.";
  61:   }
  62: 
  63:   public boolean initialize(final SwingGuiContext context)
  64:   {
  65:     super.initialize(context);
  66:     resources = new ResourceBundleSupport(context.getLocale(),
  67:         SwingPdfModule.BUNDLE_NAME);
  68:     return true;
  69:   }
  70: 
  71:   /**
  72:    * Returns the display name for the export action.
  73:    *
  74:    * @return The display name.
  75:    */
  76:   public String getDisplayName()
  77:   {
  78:     return resources.getString("action.export-to-pdf.name");
  79:   }
  80: 
  81:   /**
  82:    * Returns the short description for the export action.
  83:    *
  84:    * @return The short description.
  85:    */
  86:   public String getShortDescription()
  87:   {
  88:     return resources.getString("action.export-to-pdf.description");
  89:   }
  90: 
  91:   /**
  92:    * Returns the small icon for the export action.
  93:    *
  94:    * @return The icon.
  95:    */
  96:   public Icon getSmallIcon()
  97:   {
  98:     return null;
  99:   }
 100: 
 101:   /**
 102:    * Returns the large icon for the export action.
 103:    *
 104:    * @return The icon.
 105:    */
 106:   public Icon getLargeIcon()
 107:   {
 108:     return null;
 109:   }
 110: 
 111:   /**
 112:    * Returns the accelerator key for the export action.
 113:    *
 114:    * @return The accelerator key.
 115:    */
 116:   public KeyStroke getAcceleratorKey()
 117:   {
 118:     return resources.getOptionalKeyStroke("action.export-to-pdf.accelerator");
 119:   }
 120: 
 121:   /**
 122:    * Returns the mnemonic key code.
 123:    *
 124:    * @return The code.
 125:    */
 126:   public Integer getMnemonicKey()
 127:   {
 128:     return resources.getOptionalMnemonic("action.export-to-pdf.mnemonic");
 129:   }
 130: 
 131:   /**
 132:    * Exports a report.
 133:    *
 134:    * @param report the report.
 135:    * @return A boolean.
 136:    */
 137:   public boolean performExport(final ReportJob job)
 138:   {
 139:     if (performShowExportDialog(job, EXPORT_DIALOG_KEY) == false)
 140:     {
 141:       return false;
 142:     }
 143: 
 144:     try
 145:     {
 146:       final PdfExportTask task = new PdfExportTask(job);
 147:       final Thread worker = new Thread(task);
 148:       setStatusText("Started Job");
 149:       worker.start();
 150:       return true;
 151:     }
 152:     catch (ReportConfigurationException e)
 153:     {
 154:       setStatusText("Failed to configure the export task.");
 155:       return false;
 156:     }
 157:   }
 158: }