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 17.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 de.uka.ilkd.key.gui.AutoModeListener;
018: import de.uka.ilkd.key.gui.KeYMediator;
019: import de.uka.ilkd.key.gui.notification.actions.*;
020: import de.uka.ilkd.key.gui.notification.events.NotificationEvent;
021: import de.uka.ilkd.key.proof.ProofEvent;
022:
023: /**
024: * The notificatin manager controls the list of active
025: * notification tasks. It receives KeY System events and looks
026: * for an appropriate task
027: * @author bubel
028: */
029: public class NotificationManager {
030:
031: /** list of notification tasks */
032: private List notificationTasks = new ArrayList();
033:
034: /** true if we are currently in automode */
035: private boolean automode;
036:
037: private KeYMediator mediator;
038:
039: // Dummy task to avoid null pointer checks
040: private static final NotificationTask DUMMY_TASK = new NotificationTask() {
041:
042: protected void executeImpl(NotificationEvent event,
043: NotificationManager manager) {
044: }
045:
046: public int getEventID() {
047: return NotificationEventID.RESERVED;
048: }
049: };
050:
051: private NotificationListener notificationListener;
052:
053: /**
054: * %%HACK: move these methods
055: * set default with or without sound
056: */
057: public void setDefaultNotification(boolean sound) {
058:
059: notificationTasks.clear();
060:
061: final ProofClosedNotification pcn = new ProofClosedNotification();
062: final GeneralFailureNotification gfn = new GeneralFailureNotification();
063: final GeneralInformationNotification gin = new GeneralInformationNotification();
064: final AbandonNotification an = new AbandonNotification();
065: final ExitKeYNotification en = new ExitKeYNotification();
066:
067: if (sound) {
068: pcn.addNotificationAction(new ProofClosedSoundPlay());
069: gfn.addNotificationAction(new GeneralFailureSoundPlay());
070: gin
071: .addNotificationAction(new GeneralInformationSoundPlay());
072: an.addNotificationAction(new AbandonTaskSoundPlay());
073: en.addNotificationAction(new ExitKeYSoundPlay());
074: }
075:
076: gfn.addNotificationAction(new GeneralFailureJTextPaneDisplay(
077: mediator.mainFrame()));
078: gin
079: .addNotificationAction(new GeneralInformationJTextPaneDisplay(
080: mediator.mainFrame()));
081: pcn.addNotificationAction(new ProofClosedJTextPaneDisplay(
082: mediator.mainFrame()));
083:
084: addNotificationTask(pcn);
085: addNotificationTask(gfn);
086: addNotificationTask(gin);
087: addNotificationTask(an);
088: addNotificationTask(en);
089: }
090:
091: /**
092: * creates an instance of the notification manager
093: */
094: public NotificationManager(KeYMediator mediator) {
095:
096: notificationListener = new NotificationListener();
097: this .mediator = mediator;
098: mediator.addAutoModeListener(notificationListener);
099: }
100:
101: /**
102: * adds a notification task to this manager
103: * @param task the NotificationTask to be added
104: */
105: public void addNotificationTask(NotificationTask task) {
106: notificationTasks.add(task);
107: }
108:
109: /**
110: * removes the given notification task from the list of active
111: * tasks
112: * @param task the task to be removed
113: */
114: public void removeNotificationTask(NotificationTask task) {
115: notificationTasks.remove(task);
116: }
117:
118: /**
119: * returns the registered notifications
120: * @return the registered notifications
121: */
122: public Iterator getNotificationTasks() {
123: return notificationTasks.iterator();
124: }
125:
126: /**
127: * find the notificatin task associated with the given event id
128: * @param eventId int identifying the event
129: * @return the notificatin task associated with the given event id
130: */
131: private NotificationTask getNotificationTask(int eventId) {
132: final Iterator it = getNotificationTasks();
133: while (it.hasNext()) {
134: final NotificationTask task = (NotificationTask) it.next();
135: if (task.getEventID() == eventId) {
136: return task;
137: }
138: }
139: return DUMMY_TASK;
140: }
141:
142: /**
143: * @return true if the prover is currently in automode
144: */
145: public boolean inAutoMode() {
146: return automode;
147: }
148:
149: // Listener section with inner classes used to receive
150: // KeY system events
151: private class NotificationListener implements AutoModeListener {
152:
153: /**
154: * auto mode started
155: */
156: public void autoModeStarted(ProofEvent e) {
157: automode = true;
158: }
159:
160: /**
161: * auto mode stopped
162: */
163: public void autoModeStopped(ProofEvent e) {
164: automode = false;
165: }
166:
167: }
168:
169: /**
170: * dispatches the received notification event an triggers
171: * the corresponding task
172: * @param event
173: */
174: public void notify(NotificationEvent event) {
175: getNotificationTask(event.getEventID()).execute(event,
176: NotificationManager.this);
177: }
178:
179: }
|