001: /* *************************************************************************
002:
003: Millstone(TM)
004: Open Sourced User Interface Library for
005: Internet Development with Java
006:
007: Millstone is a registered trademark of IT Mill Ltd
008: Copyright (C) 2000-2005 IT Mill Ltd
009:
010: *************************************************************************
011:
012: This library is free software; you can redistribute it and/or
013: modify it under the terms of the GNU Lesser General Public
014: license version 2.1 as published by the Free Software Foundation.
015:
016: This library is distributed in the hope that it will be useful,
017: but WITHOUT ANY WARRANTY; without even the implied warranty of
018: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
019: Lesser General Public License for more details.
020:
021: You should have received a copy of the GNU Lesser General Public
022: License along with this library; if not, write to the Free Software
023: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
024:
025: *************************************************************************
026:
027: For more information, contact:
028:
029: IT Mill Ltd phone: +358 2 4802 7180
030: Ruukinkatu 2-4 fax: +358 2 4802 7181
031: 20540, Turku email: info@itmill.com
032: Finland company www: www.itmill.com
033:
034: Primary source for MillStone information and releases: www.millstone.org
035:
036: ********************************************************************** */
037:
038: package org.millstone.base.event;
039:
040: import org.millstone.base.terminal.*;
041:
042: /** Implements the MillStone action framework. This class contains
043: * subinterfaces for action handling and listing, and for action handler
044: * registrations and unregistration.
045: *
046: * @author IT Mill Ltd.
047: * @version 3.1.1
048: * @since 3.0
049: */
050: public class Action {
051:
052: /** Action title */
053: private String caption;
054:
055: /** Action icon */
056: private Resource icon = null;
057:
058: /** Constructs a new action with the given caption.
059: *
060: * @param caption caption for the new action.
061: */
062: public Action(String caption) {
063: this .caption = caption;
064: }
065:
066: /** Constructs a new action with the given caption string and icon.
067: *
068: * @param caption caption for the new action.
069: * @param icon icon for the new action
070: */
071: public Action(String caption, Resource icon) {
072: this .caption = caption;
073: this .icon = icon;
074: }
075:
076: /** Returns the action's caption.
077: *
078: * @return the action's caption as a <code>String</code>
079: */
080: public String getCaption() {
081: return caption;
082: }
083:
084: /** Returns the action's icon.
085: *
086: * @return Icon
087: */
088: public Resource getIcon() {
089: return icon;
090: }
091:
092: /** Interface implemented by classes who wish to handle actions.
093: * @author IT Mill Ltd.
094: * @version 3.1.1
095: * @since 3.0
096: */
097: public interface Handler {
098:
099: /** Returns the list of actions applicable to this handler.
100: *
101: * @param target The target handler to list actions for. For item
102: * containers this is the item id.
103: * @param sender The party that would be sending the actions.
104: * Most of this is the action container.
105: */
106: public Action[] getActions(Object target, Object sender);
107:
108: /** Handles an action for the given target. The handler method
109: * may just discard the action if it's not suitable.
110: *
111: * @param action The action to be handled
112: * @param sender The sender of the action. This is most often the
113: * action container.
114: * @param target The target of the <code>action</code>. For item
115: * containers this is the item id.
116: */
117: public void handleAction(Action action, Object sender,
118: Object target);
119: }
120:
121: /** Interface implemented by all components where actions can be
122: * registered. This means that the components lets others to register
123: * as action handlers to it. When the component receives an action
124: * targeting its contents it should loop all action handlers registered
125: * to it and let them hanle the action.
126: * @author IT Mill Ltd.
127: * @version 3.1.1
128: * @since 3.0
129: */
130: public interface Container {
131:
132: /** Registers a new action handler for this container
133: *
134: * @param actionHandler the new handler to be added.
135: */
136: public void addActionHandler(Action.Handler actionHandler);
137:
138: /** Remove a previously registered action handler for the contents
139: * of this container.
140: *
141: * @param actionHandler the handler to be removed
142: */
143: public void removeActionHandler(Action.Handler actionHandler);
144: }
145:
146: /** Sets the caption.
147: * @param caption The caption to set
148: */
149: public void setCaption(String caption) {
150: this .caption = caption;
151: }
152:
153: /** Sets the icon.
154: * @param icon The icon to set
155: */
156: public void setIcon(Resource icon) {
157: this.icon = icon;
158: }
159:
160: }
|