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: * GoToPreviousPageActionPlugin.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 GoToPreviousPageActionPlugin 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 GoToPreviousPageActionPlugin() {
065: }
066:
067: public boolean initialize(final SwingGuiContext context) {
068: super .initialize(context);
069: resources = new ResourceBundleSupport(context.getLocale(),
070: SwingPreviewModule.BUNDLE_NAME);
071: eventSource = context.getEventSource();
072: eventSource.addPropertyChangeListener(new PageUpdateListener());
073: revalidate();
074: return true;
075: }
076:
077: private void revalidate() {
078: if (eventSource.isPaginated() == false) {
079: setEnabled(false);
080: return;
081: }
082: if (eventSource.getPageNumber() <= 1) {
083: setEnabled(false);
084: return;
085: }
086: setEnabled(true);
087: }
088:
089: protected String getConfigurationPrefix() {
090: return "org.jfree.report.modules.gui.base.go-to-previous."; //$NON-NLS-1$
091: }
092:
093: /**
094: * Returns the display name for the export action.
095: *
096: * @return The display name.
097: */
098: public String getDisplayName() {
099: return resources.getString("action.back.name"); //$NON-NLS-1$
100: }
101:
102: /**
103: * Returns the short description for the export action.
104: *
105: * @return The short description.
106: */
107: public String getShortDescription() {
108: return resources.getString("action.back.description"); //$NON-NLS-1$
109: }
110:
111: /**
112: * Returns the small icon for the export action.
113: *
114: * @return The icon.
115: */
116: public Icon getSmallIcon() {
117: final Locale locale = getContext().getLocale();
118: return getIconTheme().getSmallIcon(locale,
119: "action.back.small-icon"); //$NON-NLS-1$
120: }
121:
122: /**
123: * Returns the large icon for the export action.
124: *
125: * @return The icon.
126: */
127: public Icon getLargeIcon() {
128: final Locale locale = getContext().getLocale();
129: return getIconTheme().getLargeIcon(locale, "action.back.icon"); //$NON-NLS-1$
130: }
131:
132: /**
133: * Returns the accelerator key for the export action.
134: *
135: * @return The accelerator key.
136: */
137: public KeyStroke getAcceleratorKey() {
138: return resources.getKeyStroke("action.back.accelerator"); //$NON-NLS-1$
139: }
140:
141: /**
142: * Returns the mnemonic key code.
143: *
144: * @return The code.
145: */
146: public Integer getMnemonicKey() {
147: return resources.getMnemonic("action.back.mnemonic"); //$NON-NLS-1$
148: }
149:
150: public boolean configure(final PreviewPane reportPane) {
151: reportPane.setPageNumber(Math.max(1,
152: reportPane.getPageNumber() - 1));
153: return true;
154: }
155:
156: }
|