1
|
/*******************************************************************************
|
2
|
* Copyright (c) 2004, 2010 IBM Corporation and others.
|
3
|
* All rights reserved. This program and the accompanying materials
|
4
|
* are made available under the terms of the Eclipse Public License v1.0
|
5
|
* which accompanies this distribution, and is available at
|
6
|
* http://www.eclipse.org/legal/epl-v10.html
|
7
|
*
|
8
|
* Contributors:
|
9
|
* IBM Corporation - initial API and implementation
|
10
|
*******************************************************************************/
|
11
|
|
12
|
package org.eclipse.gef.commands;
|
13
|
|
14
|
import java.util.EventObject;
|
15
|
|
16
|
/**
|
17
|
* Instances of this class are sent whenever stack events occur. The type of
|
18
|
* event can be determined by calling {@link #getDetail()}, and comparing the
|
19
|
* return value to constants defined by {@link CommandStack}.
|
20
|
* <P>
|
21
|
* Warning: this class is not intended to be subclassed.
|
22
|
*
|
23
|
* @since 3.1
|
24
|
*/
|
25
|
public class CommandStackEvent extends EventObject {
|
26
|
|
27
|
private final Command command;
|
28
|
private final int detail;
|
29
|
|
30
|
/**
|
31
|
* Constructs a new event instance. The stack specifies the source of the
|
32
|
* event. If a command is relevant to the event context, one should be
|
33
|
* specified. The detail indicates the type of event occurring.
|
34
|
*
|
35
|
* @since 3.1
|
36
|
* @param stack
|
37
|
* the command stack
|
38
|
* @param c
|
39
|
* a command or <code>null</code>
|
40
|
* @param detail
|
41
|
* an integer identifier
|
42
|
*/
|
43
|
public CommandStackEvent(CommandStack stack, Command c, int detail) {
|
44
|
super(stack);
|
45
|
this.command = c;
|
46
|
this.detail = detail;
|
47
|
}
|
48
|
|
49
|
/**
|
50
|
* Returns <code>null</code> or a Command if a command is relevant to the
|
51
|
* current event.
|
52
|
*
|
53
|
* @since 3.1
|
54
|
* @return <code>null</code> or a command
|
55
|
*/
|
56
|
public Command getCommand() {
|
57
|
return command;
|
58
|
}
|
59
|
|
60
|
/**
|
61
|
* Returns <code>true</code> if this event is fired prior to the stack
|
62
|
* changing.
|
63
|
*
|
64
|
* @return <code>true</code> if pre-change event
|
65
|
* @since 3.2
|
66
|
*/
|
67
|
public final boolean isPreChangeEvent() {
|
68
|
return 0 != (getDetail() & CommandStack.PRE_MASK);
|
69
|
}
|
70
|
|
71
|
/**
|
72
|
* Returns <code>true</code> if this event is fired after the stack having
|
73
|
* changed.
|
74
|
*
|
75
|
* @return <code>true</code> if post-change event
|
76
|
* @since 3.2
|
77
|
*/
|
78
|
public final boolean isPostChangeEvent() {
|
79
|
return 0 != (getDetail() & CommandStack.POST_MASK);
|
80
|
}
|
81
|
|
82
|
/**
|
83
|
* Returns an integer identifying the type of event which has occurred.
|
84
|
*
|
85
|
* @since 3.1
|
86
|
* @return the detail of the event
|
87
|
*/
|
88
|
public int getDetail() {
|
89
|
return detail;
|
90
|
}
|
91
|
|
92
|
}
|