001: // This file is part of KeY - Integrated Deductive Software Design
002: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
003: // Universitaet Koblenz-Landau, Germany
004: // Chalmers University of Technology, Sweden
005: //
006: // The KeY system is protected by the GNU General Public License.
007: // See LICENSE.TXT for details.
008: /*
009: * Created on 3.03.2005
010: */
011: package de.uka.ilkd.key.gui.notification;
012:
013: import java.util.ArrayList;
014: import java.util.Iterator;
015: import java.util.List;
016:
017: import javax.swing.SwingUtilities;
018:
019: import de.uka.ilkd.key.gui.notification.events.NotificationEvent;
020:
021: /**
022: * A notification task maps a
023: * {@link de.uka.ilkd.key.gui.notification.events.NotificationEvent} to a list
024: * of actions to be performed when the event is encountered.
025: * @author bubel
026: */
027: public abstract class NotificationTask {
028:
029: /**
030: * the list of actions associated with this task
031: */
032: private List notificationActions = new ArrayList(5);
033:
034: /**
035: * @return returns the notification actions belonging to
036: * this task
037: */
038: public List getNotificationActions() {
039: return notificationActions;
040: }
041:
042: /**
043: * adds an notificatin action this task.
044: * @param action the NotificationAction to be added
045: */
046: public void addNotificationAction(NotificationAction action) {
047: this .notificationActions.add(action);
048: }
049:
050: /**
051: * @return an iterator about the registered actions
052: */
053: public Iterator getActions() {
054: return notificationActions.iterator();
055: }
056:
057: /**
058: *
059: * called to execute the notification task, but this method
060: * only takes care that we are in the even dispatcher thread
061: * @param event the NotificationEvent triggering this task
062: * @param manager the NotificationManager to which this
063: * tasks belongs to
064: */
065: public void execute(NotificationEvent event,
066: NotificationManager manager) {
067: // if we are in automode execute task only if it is
068: // automode enabled
069: if (manager.inAutoMode() && !automodeEnabledTask()) {
070: return;
071: }
072: // notify thread safe
073: if (SwingUtilities.isEventDispatchThread()) {
074: executeImpl(event, manager);
075: } else {
076: final NotificationEvent eventObject = event;
077: final NotificationManager notManager = manager;
078: SwingUtilities.invokeLater(new Runnable() {
079: public void run() {
080: executeImpl(eventObject, notManager);
081: }
082: });
083: }
084: }
085:
086: /**
087:
088: * called to execute the notification task
089: * @param manager the NotificationManager to which this
090: * tasks belongs to
091: * @param event the NotificationEvent triggering this task
092: */
093: protected abstract void executeImpl(NotificationEvent event,
094: NotificationManager manager);
095:
096: /**
097: * @return the event if of this task
098: */
099: public abstract int getEventID();
100:
101: /**
102: * returns if this task should be executed in auto mode
103: * @return if true execute task even if in automode
104: */
105: protected boolean automodeEnabledTask() {
106: return false;
107: }
108: }
|