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: * ZoomCustomActionPlugin.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.util.Locale;
032: import javax.swing.Icon;
033: import javax.swing.JOptionPane;
034: import javax.swing.KeyStroke;
035:
036: import org.jfree.report.modules.gui.base.PreviewPane;
037: import org.jfree.report.modules.gui.base.SwingPreviewModule;
038: import org.jfree.report.modules.gui.base.internal.NumericInputDialog;
039: import org.jfree.report.modules.gui.commonswing.AbstractActionPlugin;
040: import org.jfree.report.modules.gui.commonswing.SwingGuiContext;
041: import org.jfree.report.util.i18n.Messages;
042: import org.jfree.util.Log;
043: import org.jfree.util.ResourceBundleSupport;
044:
045: /**
046: * Creation-Date: 16.11.2006, 18:52:30
047: *
048: * @author Thomas Morgner
049: */
050: public class ZoomCustomActionPlugin extends AbstractActionPlugin
051: implements ControlActionPlugin {
052: private ResourceBundleSupport resources;
053:
054: private Messages messages;
055:
056: public ZoomCustomActionPlugin() {
057: }
058:
059: public boolean initialize(final SwingGuiContext context) {
060: super .initialize(context);
061: resources = new ResourceBundleSupport(context.getLocale(),
062: SwingPreviewModule.BUNDLE_NAME);
063: messages = new Messages(context.getLocale(),
064: SwingPreviewModule.BUNDLE_NAME);
065: context.getEventSource().addPropertyChangeListener(
066: new PaginatedUpdateListener(this ));
067: setEnabled(context.getEventSource().isPaginated());
068: return true;
069: }
070:
071: protected String getConfigurationPrefix() {
072: return "org.jfree.report.modules.gui.base.zoom-custom."; //$NON-NLS-1$
073: }
074:
075: /**
076: * Returns the display name for the export action.
077: *
078: * @return The display name.
079: */
080: public String getDisplayName() {
081: return resources.getString("action.zoomCustom.name"); //$NON-NLS-1$
082: }
083:
084: /**
085: * Returns the short description for the export action.
086: *
087: * @return The short description.
088: */
089: public String getShortDescription() {
090: return resources.getString("action.zoomCustom.description"); //$NON-NLS-1$
091: }
092:
093: /**
094: * Returns the small icon for the export action.
095: *
096: * @return The icon.
097: */
098: public Icon getSmallIcon() {
099: final Locale locale = getContext().getLocale();
100: return getIconTheme().getSmallIcon(locale,
101: "action.zoomCustom.small-icon"); //$NON-NLS-1$
102: }
103:
104: /**
105: * Returns the large icon for the export action.
106: *
107: * @return The icon.
108: */
109: public Icon getLargeIcon() {
110: final Locale locale = getContext().getLocale();
111: return getIconTheme().getLargeIcon(locale,
112: "action.zoomCustom.icon"); //$NON-NLS-1$
113: }
114:
115: /**
116: * Returns the accelerator key for the export action.
117: *
118: * @return The accelerator key.
119: */
120: public KeyStroke getAcceleratorKey() {
121: return resources
122: .getOptionalKeyStroke("action.zoomCustom.accelerator"); //$NON-NLS-1$
123: }
124:
125: /**
126: * Returns the mnemonic key code.
127: *
128: * @return The code.
129: */
130: public Integer getMnemonicKey() {
131: return resources
132: .getOptionalMnemonic("action.zoomCustom.mnemonic"); //$NON-NLS-1$
133: }
134:
135: public boolean configure(final PreviewPane reportPane) {
136: final Integer result = NumericInputDialog.showInputDialog(
137: getContext().getWindow(), JOptionPane.QUESTION_MESSAGE,
138: resources.getString("dialog.zoom.title"), //$NON-NLS-1$
139: resources.getString("dialog.zoom.message"), //$NON-NLS-1$
140: 25, 400, (int) (reportPane.getZoom() * 100), false);
141:
142: if (result == null) {
143: return false;
144: }
145: try {
146: final double zoom = result.doubleValue();
147: reportPane.setZoom(zoom / 100.0);
148: return true;
149: } catch (Exception ex) {
150: if (messages != null) {
151: Log
152: .info(messages
153: .getString("ZoomCustomActionPlugin.INFO_EXCEPTION_SWALLOWED")); //$NON-NLS-1$
154: }
155: }
156: return false;
157: }
158:
159: }
|