Frames | No Frames |
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: ZoomCustomActionPlugin.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.awt.Window; 35: import java.util.Locale; 36: import javax.swing.Icon; 37: import javax.swing.JOptionPane; 38: import javax.swing.KeyStroke; 39: import javax.swing.SwingUtilities; 40: 41: import org.jfree.report.modules.gui.swing.common.AbstractActionPlugin; 42: import org.jfree.report.modules.gui.swing.common.SwingGuiContext; 43: import org.jfree.report.modules.gui.swing.preview.PreviewPane; 44: import org.jfree.report.modules.gui.swing.preview.SwingPreviewModule; 45: import org.jfree.util.Log; 46: import org.jfree.util.ResourceBundleSupport; 47: 48: /** 49: * Creation-Date: 16.11.2006, 18:52:30 50: * 51: * @author Thomas Morgner 52: */ 53: public class ZoomCustomActionPlugin extends AbstractActionPlugin 54: implements ControlActionPlugin 55: { 56: private ResourceBundleSupport resources; 57: 58: public ZoomCustomActionPlugin() 59: { 60: } 61: 62: public boolean initialize(final SwingGuiContext context) 63: { 64: super.initialize(context); 65: resources = new ResourceBundleSupport(context.getLocale(), 66: SwingPreviewModule.BUNDLE_NAME); 67: return true; 68: } 69: 70: protected String getConfigurationPrefix() 71: { 72: return "org.jfree.report.modules.gui.swing.preview.zoom-custom."; 73: } 74: 75: /** 76: * Returns the display name for the export action. 77: * 78: * @return The display name. 79: */ 80: public String getDisplayName() 81: { 82: return resources.getString("action.zoomCustom.name"); 83: } 84: 85: /** 86: * Returns the short description for the export action. 87: * 88: * @return The short description. 89: */ 90: public String getShortDescription() 91: { 92: return resources.getString("action.zoomCustom.description"); 93: } 94: 95: /** 96: * Returns the small icon for the export action. 97: * 98: * @return The icon. 99: */ 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(final PreviewPane reportPane) 138: { 139: final 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: }