Source for org.jfree.report.modules.gui.swing.preview.actions.GoToActionPlugin

   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: GoToActionPlugin.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.preview.actions;
  33: 
  34: import java.util.Locale;
  35: import javax.swing.Icon;
  36: import javax.swing.JOptionPane;
  37: import javax.swing.KeyStroke;
  38: 
  39: import org.jfree.report.modules.gui.swing.common.AbstractActionPlugin;
  40: import org.jfree.report.modules.gui.swing.common.SwingGuiContext;
  41: import org.jfree.report.modules.gui.swing.preview.PreviewPane;
  42: import org.jfree.report.modules.gui.swing.preview.SwingPreviewModule;
  43: import org.jfree.util.Log;
  44: import org.jfree.util.ResourceBundleSupport;
  45: 
  46: /**
  47:  * Creation-Date: 16.11.2006, 16:34:55
  48:  *
  49:  * @author Thomas Morgner
  50:  */
  51: public class GoToActionPlugin extends AbstractActionPlugin
  52:     implements ControlActionPlugin
  53: {
  54:   private ResourceBundleSupport resources;
  55: 
  56:   public GoToActionPlugin()
  57:   {
  58:   }
  59: 
  60:   public boolean initialize(final SwingGuiContext context)
  61:   {
  62:     super.initialize(context);
  63:     resources = new ResourceBundleSupport(context.getLocale(),
  64:         SwingPreviewModule.BUNDLE_NAME);
  65:     return true;
  66:   }
  67: 
  68:   protected String getConfigurationPrefix()
  69:   {
  70:     return "org.jfree.report.modules.gui.swing.preview.go-to.";
  71:   }
  72: 
  73:   /**
  74:    * Returns the display name for the export action.
  75:    *
  76:    * @return The display name.
  77:    */
  78:   public String getDisplayName()
  79:   {
  80:     return resources.getString("action.gotopage.name");
  81:   }
  82: 
  83:   /**
  84:    * Returns the short description for the export action.
  85:    *
  86:    * @return The short description.
  87:    */
  88:   public String getShortDescription()
  89:   {
  90:     return resources.getString("action.gotopage.description");
  91:   }
  92: 
  93:   /**
  94:    * Returns the small icon for the export action.
  95:    *
  96:    * @return The icon.
  97:    */
  98:   public Icon getSmallIcon()
  99:   {
 100:     final Locale locale = getContext().getLocale();
 101:     return getIconTheme().getSmallIcon(locale, "action.gotopage.small-icon");
 102:   }
 103: 
 104:   /**
 105:    * Returns the large icon for the export action.
 106:    *
 107:    * @return The icon.
 108:    */
 109:   public Icon getLargeIcon()
 110:   {
 111:     final Locale locale = getContext().getLocale();
 112:     return getIconTheme().getLargeIcon(locale, "action.gotopage.icon");
 113:   }
 114: 
 115:   /**
 116:    * Returns the accelerator key for the export action.
 117:    *
 118:    * @return The accelerator key.
 119:    */
 120:   public KeyStroke getAcceleratorKey()
 121:   {
 122:     return resources.getKeyStroke("action.gotopage.accelerator");
 123:   }
 124: 
 125:   /**
 126:    * Returns the mnemonic key code.
 127:    *
 128:    * @return The code.
 129:    */
 130:   public Integer getMnemonicKey()
 131:   {
 132:     return resources.getMnemonic("action.gotopage.mnemonic");
 133:   }
 134: 
 135:   public boolean configure(final PreviewPane reportPane)
 136:   {
 137:     final String result = JOptionPane.showInputDialog(getContext().getWindow(),
 138:             resources.getString("dialog.gotopage.title"),
 139:             resources.getString("dialog.gotopage.message"),
 140:             JOptionPane.OK_CANCEL_OPTION);
 141:     if (result == null)
 142:     {
 143:       return false;
 144:     }
 145:     try
 146:     {
 147:       final int page = Integer.parseInt(result);
 148: 
 149:       if (page > 0 && page <= reportPane.getNumberOfPages())
 150:       {
 151:         reportPane.setPageNumber(page);
 152:       }
 153:     }
 154:     catch (Exception ex)
 155:     {
 156:       Log.info("DefaultGotoAction: swallowed an exception");
 157:     }
 158:     return false;
 159:   }
 160: 
 161: }