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: * AbstractActionPlugin.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.modules.gui.commonswing;
030:
031: import java.awt.Dialog;
032: import java.awt.Frame;
033: import java.awt.Window;
034: import java.beans.PropertyChangeListener;
035: import java.beans.PropertyChangeSupport;
036:
037: import org.jfree.report.modules.gui.common.IconTheme;
038: import org.jfree.util.ExtendedConfiguration;
039: import org.jfree.util.ExtendedConfigurationWrapper;
040: import org.jfree.util.ResourceBundleSupport;
041:
042: /**
043: * The AbstractExportPlugin provides a basic implementation of the ExportPlugin
044: * interface.
045: *
046: * @author Thomas Morgner
047: */
048: public abstract class AbstractActionPlugin implements ActionPlugin {
049: public static final String ENABLED_PROPERTY = "enabled"; //$NON-NLS-1$
050: private PropertyChangeSupport propertyChangeSupport;
051:
052: /**
053: * Localised resources.
054: */
055: private ResourceBundleSupport baseResources;
056: private IconTheme iconTheme;
057:
058: /**
059: * The base resource class.
060: */
061: private SwingGuiContext context;
062: private ExtendedConfiguration configuration;
063: private boolean enabled;
064:
065: protected AbstractActionPlugin() {
066: enabled = true;
067: propertyChangeSupport = new PropertyChangeSupport(this );
068: }
069:
070: public boolean isEnabled() {
071: return enabled;
072: }
073:
074: public void setEnabled(final boolean enabled) {
075: final boolean oldEnabled = this .enabled;
076: this .enabled = enabled;
077: propertyChangeSupport.firePropertyChange(ENABLED_PROPERTY,
078: oldEnabled, enabled);
079: }
080:
081: public boolean initialize(final SwingGuiContext context) {
082: if (context == null) {
083: throw new NullPointerException(
084: "AbstractActionPlugin.initialize(..): Context parameter cannot be null");
085: }
086:
087: this .context = context;
088: this .baseResources = new ResourceBundleSupport(context
089: .getLocale(), SwingCommonModule.BUNDLE_NAME);
090: this .iconTheme = context.getIconTheme();
091: this .configuration = new ExtendedConfigurationWrapper(context
092: .getConfiguration());
093: return true;
094: }
095:
096: public ResourceBundleSupport getBaseResources() {
097: return baseResources;
098: }
099:
100: protected PropertyChangeSupport getPropertyChangeSupport() {
101: return propertyChangeSupport;
102: }
103:
104: public SwingGuiContext getContext() {
105: return context;
106: }
107:
108: public ExtendedConfiguration getConfig() {
109: return configuration;
110: }
111:
112: /**
113: * Returns true if the action is separated, and false otherwise. A separated
114: * action starts a new action group and will be spearated from previous
115: * actions on the menu and toolbar.
116: *
117: * @return true, if the action should be separated from previous actions,
118: * false otherwise.
119: */
120: public boolean isSeparated() {
121: return getConfig().getBoolProperty(
122: getConfigurationPrefix() + "separated"); //$NON-NLS-1$
123: }
124:
125: /**
126: * Returns true if the action should be added to the toolbar, and false
127: * otherwise.
128: *
129: * @return true, if the plugin should be added to the toolbar, false
130: * otherwise.
131: */
132: public boolean isAddToToolbar() {
133: return getConfig().getBoolProperty(
134: getConfigurationPrefix() + "add-to-toolbar"); //$NON-NLS-1$
135: }
136:
137: /**
138: * Returns true if the action should be added to the menu, and false
139: * otherwise.
140: *
141: * @return A boolean.
142: */
143: public boolean isAddToMenu() {
144: final String name = getConfigurationPrefix() + "add-to-menu"; //$NON-NLS-1$
145: return getConfig().getBoolProperty(name);
146: }
147:
148: /**
149: * Creates a progress dialog, and tries to assign a parent based on the given
150: * preview proxy.
151: *
152: * @return the progress dialog.
153: */
154: protected ReportProgressDialog createProgressDialog() {
155: final Window proxy = context.getWindow();
156: if (proxy instanceof Frame) {
157: return new ReportProgressDialog((Frame) proxy);
158: } else if (proxy instanceof Dialog) {
159: return new ReportProgressDialog((Dialog) proxy);
160: } else {
161: return new ReportProgressDialog();
162: }
163: }
164:
165: public void addPropertyChangeListener(final PropertyChangeListener l) {
166: propertyChangeSupport.addPropertyChangeListener(l);
167: }
168:
169: public void addPropertyChangeListener(final String property,
170: final PropertyChangeListener l) {
171: propertyChangeSupport.addPropertyChangeListener(property, l);
172: }
173:
174: public void removePropertyChangeListener(
175: final PropertyChangeListener l) {
176: propertyChangeSupport.removePropertyChangeListener(l);
177: }
178:
179: public IconTheme getIconTheme() {
180: return iconTheme;
181: }
182:
183: protected abstract String getConfigurationPrefix();
184:
185: /**
186: * A sort key used to enforce a certain order within the actions.
187: *
188: * @return
189: */
190: public int getMenuOrder() {
191: return getConfig().getIntProperty(
192: getConfigurationPrefix() + "menu-order", 0); //$NON-NLS-1$
193: }
194:
195: public int getToolbarOrder() {
196: return getConfig().getIntProperty(
197: getConfigurationPrefix() + "toolbar-order", 0); //$NON-NLS-1$
198: }
199:
200: public String getRole() {
201: return getConfig().getConfigProperty(
202: getConfigurationPrefix() + "role"); //$NON-NLS-1$
203: }
204:
205: public int getRolePreference() {
206: return getConfig().getIntProperty(
207: getConfigurationPrefix() + "role-preference", 0); //$NON-NLS-1$
208: }
209: }
|