01: // This file is part of KeY - Integrated Deductive Software Design
02: // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
03: // Universitaet Koblenz-Landau, Germany
04: // Chalmers University of Technology, Sweden
05: //
06: // The KeY system is protected by the GNU General Public License.
07: // See LICENSE.TXT for details.
08: /*
09: * Created on 18.03.2005
10: */
11: package de.uka.ilkd.key.gui.notification;
12:
13: import java.lang.reflect.InvocationTargetException;
14: import java.util.Iterator;
15:
16: import javax.swing.SwingUtilities;
17:
18: import de.uka.ilkd.key.gui.notification.events.NotificationEvent;
19: import de.uka.ilkd.key.util.Debug;
20:
21: /**
22: * This task takes care for a notification when exiting KeY.
23: * @author bubel
24: */
25: public class ExitKeYNotification extends NotificationTask {
26:
27: /**
28: * overwritten as invokeAndWait is taken
29: * called to execute the notification task, but this method
30: * only takes care that we are in the even dispatcher thread
31: * @param manager the NotificationManager to which this
32: * tasks belongs to
33: * @param event the NotificationEvent triggering this task
34: */
35: public void execute(NotificationEvent event,
36: NotificationManager manager) {
37: // if we are in automode execute task only if it is
38: // automode enabled
39: if (manager.inAutoMode() && !automodeEnabledTask()) {
40: return;
41: }
42: // notify thread safe
43:
44: if (SwingUtilities.isEventDispatchThread()) {
45: executeImpl(event, manager);
46: } else {
47: final NotificationEvent eventObject = event;
48: final NotificationManager notManager = manager;
49: try {
50: SwingUtilities.invokeAndWait(new Runnable() {
51: public void run() {
52: executeImpl(eventObject, notManager);
53: }
54: });
55: } catch (InterruptedException e) {
56: Debug.out("unexpected exception during notification");
57: } catch (InvocationTargetException e) {
58: Debug.out("unexpected exception during notification");
59: }
60: }
61: }
62:
63: /**
64: * executes the actions of this task
65: */
66: protected void executeImpl(NotificationEvent event,
67: NotificationManager manager) {
68: final Iterator actions = getActions();
69: while (actions.hasNext()) {
70: ((NotificationAction) actions.next()).execute(event);
71: }
72: }
73:
74: /* (non-Javadoc)
75: * @see de.uka.ilkd.key.gui.notification.NotificationTask#getEventID()
76: */
77: public int getEventID() {
78: return NotificationEventID.EXIT_KEY;
79: }
80:
81: }
|