1 /*
2 * Copyright 2006-2016 The JGUIraffe Team.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License")
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 package net.sf.jguiraffe.gui.cmd;
17
18 import java.util.EventObject;
19
20 /**
21 * <p>
22 * An event class for notifying listeners about the state of a
23 * {@link CommandQueue}.
24 * </p>
25 * <p>
26 * Event objects of this class are sent to registered listeners if certain
27 * changes in the command queue's life cycle occur. Registered listeners can
28 * react on these changes, i.g. by displaying some signs if currently commands
29 * are executed.
30 * </p>
31 *
32 * @author Oliver Heger
33 * @version $Id: CommandQueueEvent.java 205 2012-01-29 18:29:57Z oheger $
34 */
35 public class CommandQueueEvent extends EventObject
36 {
37 /**
38 * The serial version UID.
39 */
40 private static final long serialVersionUID = 7434520871707897320L;
41
42 /** Stores the <code>Command</code> object affected by this event. */
43 private final transient Command command;
44
45 /** Stores the event's type. */
46 private final Type type;
47
48 /**
49 * Creates a new instance of <code>CommandQueueEvent</code> and fully
50 * initializes it.
51 *
52 * @param q the affected command queue
53 * @param c the affected command object
54 * @param t the event's type
55 */
56 public CommandQueueEvent(CommandQueue q, Command c, Type t)
57 {
58 super(q);
59 command = c;
60 type = t;
61 }
62
63 /**
64 * Returns the <code>Command</code> object affected by this event. This
65 * may be <b>null</b> if this event is not related to a
66 * <code>Command</code> object.
67 *
68 * @return the affected command
69 */
70 public Command getCommand()
71 {
72 return command;
73 }
74
75 /**
76 * Returns the <code>CommandQueue</code> that caused this event.
77 *
78 * @return the command queue
79 */
80 public CommandQueue getCommandQueue()
81 {
82 return (CommandQueue) getSource();
83 }
84
85 /**
86 * Returns the type of this event. This is one of the <code>QE_XXXX</code>
87 * constants.
88 *
89 * @return the type of this event
90 */
91 public Type getType()
92 {
93 return type;
94 }
95
96 /**
97 * <p>
98 * An enumeration for the types supported by the
99 * <code>CommandQueueEvent</code> class.
100 * </p>
101 */
102 public static enum Type
103 {
104 /**
105 * A command was added to the queue. Events of this type are generated
106 * by the <code>execute()</code> method for each passed in
107 * <code>Command</code> object.
108 */
109 COMMAND_ADDED,
110
111 /**
112 * A command is about to be executed. This event is triggered if a
113 * worker thread fetches a command object and starts with its execution.
114 */
115 COMMAND_EXECUTING,
116
117 /**
118 * Execution of a command is finished. This event is triggered after a
119 * worker thread has executed a command.
120 */
121 COMMAND_EXECUTED,
122
123 /**
124 * A command was added to an empty queue. This event is triggered if the
125 * queue has been idle and then the processing of commands starts. After
126 * all pending commands have been executed an event of type
127 * <code>QUEUE_IDLE</code> is triggered. As long as the queue is in
128 * the <em>BUSY</em> state, the <code>isPending()</code> method
129 * returns <b>true</b>.
130 */
131 QUEUE_BUSY,
132
133 /**
134 * The last command contained in the queue was processed. This is the
135 * opposite event of <code>QUEUE_BUSY</code>. It indicates that all
136 * pending commands have been processed, and the queue is now empty.
137 */
138 QUEUE_IDLE
139 }
140 }