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: * GoToNextPageActionPlugin.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.beans.PropertyChangeEvent;
032: import java.beans.PropertyChangeListener;
033: import java.util.Locale;
034: import javax.swing.Icon;
035: import javax.swing.KeyStroke;
036:
037: import org.jfree.report.modules.gui.base.PreviewPane;
038: import org.jfree.report.modules.gui.base.SwingPreviewModule;
039: import org.jfree.report.modules.gui.commonswing.AbstractActionPlugin;
040: import org.jfree.report.modules.gui.commonswing.ReportEventSource;
041: import org.jfree.report.modules.gui.commonswing.SwingGuiContext;
042: import org.jfree.util.ResourceBundleSupport;
043:
044: /**
045: * Creation-Date: 16.11.2006, 16:34:55
046: *
047: * @author Thomas Morgner
048: */
049: public class GoToNextPageActionPlugin extends AbstractActionPlugin
050: implements ControlActionPlugin {
051: private class PageUpdateListener implements PropertyChangeListener {
052: protected PageUpdateListener() {
053: }
054:
055: public void propertyChange(final PropertyChangeEvent evt) {
056: revalidate();
057: }
058:
059: }
060:
061: private ResourceBundleSupport resources;
062: private ReportEventSource eventSource;
063:
064: public GoToNextPageActionPlugin() {
065: }
066:
067: private void revalidate() {
068: if (eventSource.isPaginated() == false) {
069: setEnabled(false);
070: return;
071: }
072: if (eventSource.getPageNumber() < 1) {
073: setEnabled(false);
074: return;
075: }
076: if (eventSource.getPageNumber() == eventSource
077: .getNumberOfPages()) {
078: setEnabled(false);
079: return;
080: }
081: setEnabled(true);
082: }
083:
084: public boolean initialize(final SwingGuiContext context) {
085: super .initialize(context);
086: resources = new ResourceBundleSupport(context.getLocale(),
087: SwingPreviewModule.BUNDLE_NAME);
088: eventSource = context.getEventSource();
089: eventSource.addPropertyChangeListener(new PageUpdateListener());
090: revalidate();
091: return true;
092: }
093:
094: protected String getConfigurationPrefix() {
095: return "org.jfree.report.modules.gui.base.go-to-next."; //$NON-NLS-1$
096: }
097:
098: /**
099: * Returns the display name for the export action.
100: *
101: * @return The display name.
102: */
103: public String getDisplayName() {
104: return resources.getString("action.forward.name"); //$NON-NLS-1$
105: }
106:
107: /**
108: * Returns the short description for the export action.
109: *
110: * @return The short description.
111: */
112: public String getShortDescription() {
113: return resources.getString("action.forward.description"); //$NON-NLS-1$
114: }
115:
116: /**
117: * Returns the small icon for the export action.
118: *
119: * @return The icon.
120: */
121: public Icon getSmallIcon() {
122: final Locale locale = getContext().getLocale();
123: return getIconTheme().getSmallIcon(locale,
124: "action.forward.small-icon"); //$NON-NLS-1$
125: }
126:
127: /**
128: * Returns the large icon for the export action.
129: *
130: * @return The icon.
131: */
132: public Icon getLargeIcon() {
133: final Locale locale = getContext().getLocale();
134: return getIconTheme().getLargeIcon(locale,
135: "action.forward.icon"); //$NON-NLS-1$
136: }
137:
138: /**
139: * Returns the accelerator key for the export action.
140: *
141: * @return The accelerator key.
142: */
143: public KeyStroke getAcceleratorKey() {
144: return resources.getKeyStroke("action.forward.accelerator"); //$NON-NLS-1$
145: }
146:
147: /**
148: * Returns the mnemonic key code.
149: *
150: * @return The code.
151: */
152: public Integer getMnemonicKey() {
153: return resources.getMnemonic("action.forward.mnemonic"); //$NON-NLS-1$
154: }
155:
156: public boolean configure(final PreviewPane reportPane) {
157: reportPane.setPageNumber(Math.min(
158: reportPane.getNumberOfPages(), reportPane
159: .getPageNumber() + 1));
160: return true;
161: }
162:
163: }
|