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: * GoToActionPlugin.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, 16:34:55
047: *
048: * @author Thomas Morgner
049: */
050: public class GoToActionPlugin extends AbstractActionPlugin implements
051: ControlActionPlugin {
052: private ResourceBundleSupport resources;
053:
054: private Messages messages;
055:
056: public GoToActionPlugin() {
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.go-to."; //$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.gotopage.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.gotopage.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.gotopage.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.gotopage.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.getKeyStroke("action.gotopage.accelerator"); //$NON-NLS-1$
122: }
123:
124: /**
125: * Returns the mnemonic key code.
126: *
127: * @return The code.
128: */
129: public Integer getMnemonicKey() {
130: return resources.getMnemonic("action.gotopage.mnemonic"); //$NON-NLS-1$
131: }
132:
133: public boolean configure(final PreviewPane reportPane) {
134: final Integer result = NumericInputDialog.showInputDialog(
135: getContext().getWindow(), JOptionPane.QUESTION_MESSAGE,
136: resources.getString("dialog.gotopage.title"), //$NON-NLS-1$
137: resources.getString("dialog.gotopage.message"), //$NON-NLS-1$
138: 1, reportPane.getNumberOfPages(), reportPane
139: .getPageNumber(), true);
140: if (result == null) {
141: return false;
142: }
143: try {
144: final int page = result.intValue();
145: if (page > 0 && page <= reportPane.getNumberOfPages()) {
146: reportPane.setPageNumber(page);
147: }
148: } catch (Exception ex) {
149: if (messages != null) {
150: Log
151: .info(messages
152: .getString("GoToActionPlugin.INFO_EXCEPTION_SWALLOWED")); //$NON-NLS-1$
153: }
154: }
155: return false;
156: }
157:
158: }
|