001: /*
002: * Copyright (C) 2004 NNL Technology AB
003: * Visit www.infonode.net for information about InfoNode(R)
004: * products and how to contact NNL Technology AB.
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
019: * MA 02111-1307, USA.
020: */
021:
022: // $Id: DockingWindowAction.java,v 1.4 2005/02/16 11:28:14 jesper Exp $
023: package net.infonode.docking.action;
024:
025: import net.infonode.docking.DockingWindow;
026: import net.infonode.gui.action.SimpleAction;
027: import net.infonode.gui.icon.IconProvider;
028:
029: import javax.swing.*;
030: import java.io.Serializable;
031:
032: /**
033: * An action that can be performed on a {@link DockingWindow}. It has a name and an optional icon.
034: *
035: * @author $Author: jesper $
036: * @version $Revision: 1.4 $
037: * @since IDW 1.3.0
038: */
039: abstract public class DockingWindowAction implements Serializable,
040: IconProvider {
041: private static final long serialVersionUID = 1;
042:
043: /**
044: * Returns the name of this action.
045: *
046: * @return the name of this action
047: */
048: abstract public String getName();
049:
050: /**
051: * Performs this action on a window.
052: *
053: * @param window the window on which to perform the action
054: */
055: abstract public void perform(DockingWindow window);
056:
057: /**
058: * Returns true if this action is performable on a window.
059: *
060: * @param window the window on which the action will be performed
061: * @return true if this action is performable on the window
062: */
063: abstract public boolean isPerformable(DockingWindow window);
064:
065: /**
066: * Creates a simple action that performs this action on a window.
067: *
068: * @param window the window on which to perform the action
069: * @return the action that performs this action on a window.
070: */
071: public SimpleAction getAction(final DockingWindow window) {
072: return new SimpleAction() {
073: public String getName() {
074: return DockingWindowAction.this .getName();
075: }
076:
077: public boolean isEnabled() {
078: return DockingWindowAction.this .isPerformable(window);
079: }
080:
081: public void perform() {
082: DockingWindowAction.this .perform(window);
083: }
084:
085: public Icon getIcon() {
086: return DockingWindowAction.this .getIcon();
087: }
088: };
089: }
090:
091: /**
092: * Returns the optional icon of this action.
093: *
094: * @return the optional icon of this action, null if there is no icon
095: */
096: public Icon getIcon() {
097: return null;
098: }
099:
100: public String toString() {
101: return getName();
102: }
103:
104: }
|