001 /**
002 * ========================================
003 * JFreeReport : a free Java report library
004 * ========================================
005 *
006 * Project Info: http://reporting.pentaho.org/
007 *
008 * (C) Copyright 2000-2007, by Object Refinery Limited, 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 * $Id: ZoomCustomActionPlugin.java,v 1.4 2007/06/10 15:54:22 taqua Exp $
027 * ------------
028 * (C) Copyright 2000-2005, by Object Refinery Limited.
029 * (C) Copyright 2005-2007, by Pentaho Corporation.
030 */
031
032 package org.jfree.report.modules.gui.swing.preview.actions;
033
034 import java.awt.Window;
035 import java.util.Locale;
036 import javax.swing.Icon;
037 import javax.swing.JOptionPane;
038 import javax.swing.KeyStroke;
039 import javax.swing.SwingUtilities;
040
041 import org.jfree.report.modules.gui.swing.common.AbstractActionPlugin;
042 import org.jfree.report.modules.gui.swing.common.SwingGuiContext;
043 import org.jfree.report.modules.gui.swing.preview.PreviewPane;
044 import org.jfree.report.modules.gui.swing.preview.SwingPreviewModule;
045 import org.jfree.util.Log;
046 import org.jfree.util.ResourceBundleSupport;
047
048 /**
049 * Creation-Date: 16.11.2006, 18:52:30
050 *
051 * @author Thomas Morgner
052 */
053 public class ZoomCustomActionPlugin extends AbstractActionPlugin
054 implements ControlActionPlugin
055 {
056 private ResourceBundleSupport resources;
057
058 public ZoomCustomActionPlugin()
059 {
060 }
061
062 public boolean initialize(SwingGuiContext context)
063 {
064 super.initialize(context);
065 resources = new ResourceBundleSupport(context.getLocale(),
066 SwingPreviewModule.BUNDLE_NAME);
067 return true;
068 }
069
070 protected String getConfigurationPrefix()
071 {
072 return "org.jfree.report.modules.gui.swing.preview.zoom-custom.";
073 }
074
075 /**
076 * Returns the display name for the export action.
077 *
078 * @return The display name.
079 */
080 public String getDisplayName()
081 {
082 return resources.getString("action.zoomCustom.name");
083 }
084
085 /**
086 * Returns the short description for the export action.
087 *
088 * @return The short description.
089 */
090 public String getShortDescription()
091 {
092 return resources.getString("action.zoomCustom.description");
093 }
094
095 /**
096 * Returns the small icon for the export action.
097 *
098 * @return The icon.
099 */
100 public Icon getSmallIcon()
101 {
102 final Locale locale = getContext().getLocale();
103 return getIconTheme().getSmallIcon(locale, "action.zoomCustom.small-icon");
104 }
105
106 /**
107 * Returns the large icon for the export action.
108 *
109 * @return The icon.
110 */
111 public Icon getLargeIcon()
112 {
113 final Locale locale = getContext().getLocale();
114 return getIconTheme().getLargeIcon(locale, "action.zoomCustom.icon");
115 }
116
117 /**
118 * Returns the accelerator key for the export action.
119 *
120 * @return The accelerator key.
121 */
122 public KeyStroke getAcceleratorKey()
123 {
124 return resources.getOptionalKeyStroke("action.zoomCustom.accelerator");
125 }
126
127 /**
128 * Returns the mnemonic key code.
129 *
130 * @return The code.
131 */
132 public Integer getMnemonicKey()
133 {
134 return resources.getOptionalMnemonic("action.zoomCustom.mnemonic");
135 }
136
137 public boolean configure(PreviewPane reportPane)
138 {
139 Window window = SwingUtilities.windowForComponent(reportPane);
140 final String result = JOptionPane.showInputDialog(window,
141 resources.getString("dialog.zoom.title"),
142 resources.getString("dialog.zoom.message"),
143 JOptionPane.OK_CANCEL_OPTION);
144 if (result == null)
145 {
146 return false;
147 }
148 try
149 {
150 final double zoom = Double.parseDouble(result);
151
152 if (zoom > 0 && zoom <= 4000)
153 {
154 reportPane.setZoom(zoom / 100.0);
155 return true;
156 }
157
158 }
159 catch (Exception ex)
160 {
161 Log.info("ZoomAction: swallowed an exception");
162 }
163 return false;
164 }
165
166
167 }