9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package java.awt.event;
27
28 import java.awt.AWTEvent;
29 import java.awt.Event;
30 import java.lang.annotation.Native;
31
32 /**
33 * A semantic event which indicates that a component-defined action occurred.
34 * This high-level event is generated by a component (such as a
35 * {@code Button}) when
36 * the component-specific action occurs (such as being pressed).
37 * The event is passed to every {@code ActionListener} object
38 * that registered to receive such events using the component's
39 * {@code addActionListener} method.
40 * <p>
41 * <b>Note:</b> To invoke an {@code ActionEvent} on a
42 * {@code Button} using the keyboard, use the Space bar.
43 * <P>
44 * The object that implements the {@code ActionListener} interface
45 * gets this {@code ActionEvent} when the event occurs. The listener
46 * is therefore spared the details of processing individual mouse movements
47 * and mouse clicks, and can instead process a "meaningful" (semantic)
48 * event like "button pressed".
49 * <p>
50 * An unspecified behavior will be caused if the {@code id} parameter
51 * of any particular {@code ActionEvent} instance is not
52 * in the range from {@code ACTION_FIRST} to {@code ACTION_LAST}.
53 *
54 * @see ActionListener
55 * @see <a href="http://docs.oracle.com/javase/tutorial/uiswing/events/actionlistener.html">Tutorial: How to Write an Action Listener</a>
56 *
57 * @author Carl Quinn
58 * @since 1.1
59 */
60 public class ActionEvent extends AWTEvent {
61
62 /**
63 * The shift modifier. An indicator that the shift key was held
64 * down during the event.
65 */
66 public static final int SHIFT_MASK = Event.SHIFT_MASK;
67
68 /**
69 * The control modifier. An indicator that the control key was held
70 * down during the event.
71 */
72 public static final int CTRL_MASK = Event.CTRL_MASK;
73
74 /**
75 * The meta modifier. An indicator that the meta key was held
76 * down during the event.
77 */
78 public static final int META_MASK = Event.META_MASK;
79
80 /**
81 * The alt modifier. An indicator that the alt key was held
82 * down during the event.
83 */
84 public static final int ALT_MASK = Event.ALT_MASK;
85
86
87 /**
88 * The first number in the range of ids used for action events.
89 */
90 public static final int ACTION_FIRST = 1001;
91
92 /**
93 * The last number in the range of ids used for action events.
94 */
95 public static final int ACTION_LAST = 1001;
96
97 /**
98 * This event id indicates that a meaningful action occurred.
99 */
100 @Native public static final int ACTION_PERFORMED = ACTION_FIRST; //Event.ACTION_EVENT
101
102 /**
103 * The nonlocalized string that gives more details
104 * of what actually caused the event.
257 */
258 public long getWhen() {
259 return when;
260 }
261
262 /**
263 * Returns the modifier keys held down during this action event.
264 *
265 * @return the bitwise-or of the modifier constants
266 */
267 public int getModifiers() {
268 return modifiers;
269 }
270
271 /**
272 * Returns a parameter string identifying this action event.
273 * This method is useful for event-logging and for debugging.
274 *
275 * @return a string identifying the event and its associated command
276 */
277 public String paramString() {
278 String typeStr;
279 switch(id) {
280 case ACTION_PERFORMED:
281 typeStr = "ACTION_PERFORMED";
282 break;
283 default:
284 typeStr = "unknown type";
285 }
286 return typeStr + ",cmd="+actionCommand+",when="+when+",modifiers="+
287 KeyEvent.getKeyModifiersText(modifiers);
288 }
289 }
|
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package java.awt.event;
27
28 import java.awt.AWTEvent;
29 import java.lang.annotation.Native;
30
31 /**
32 * A semantic event which indicates that a component-defined action occurred.
33 * This high-level event is generated by a component (such as a
34 * {@code Button}) when
35 * the component-specific action occurs (such as being pressed).
36 * The event is passed to every {@code ActionListener} object
37 * that registered to receive such events using the component's
38 * {@code addActionListener} method.
39 * <p>
40 * <b>Note:</b> To invoke an {@code ActionEvent} on a
41 * {@code Button} using the keyboard, use the Space bar.
42 * <P>
43 * The object that implements the {@code ActionListener} interface
44 * gets this {@code ActionEvent} when the event occurs. The listener
45 * is therefore spared the details of processing individual mouse movements
46 * and mouse clicks, and can instead process a "meaningful" (semantic)
47 * event like "button pressed".
48 * <p>
49 * An unspecified behavior will be caused if the {@code id} parameter
50 * of any particular {@code ActionEvent} instance is not
51 * in the range from {@code ACTION_FIRST} to {@code ACTION_LAST}.
52 *
53 * @see ActionListener
54 * @see <a href="http://docs.oracle.com/javase/tutorial/uiswing/events/actionlistener.html">Tutorial: How to Write an Action Listener</a>
55 *
56 * @author Carl Quinn
57 * @since 1.1
58 */
59 public class ActionEvent extends AWTEvent {
60
61 /**
62 * The shift modifier. An indicator that the shift key was held
63 * down during the event.
64 */
65 public static final int SHIFT_MASK = 1 << 0;
66
67 /**
68 * The control modifier. An indicator that the control key was held
69 * down during the event.
70 */
71 public static final int CTRL_MASK = 1 << 1;
72
73 /**
74 * The meta modifier. An indicator that the meta key was held
75 * down during the event.
76 */
77 public static final int META_MASK = 1 << 2;
78
79 /**
80 * The alt modifier. An indicator that the alt key was held
81 * down during the event.
82 */
83 public static final int ALT_MASK = 1 << 3;
84
85
86 /**
87 * The first number in the range of ids used for action events.
88 */
89 public static final int ACTION_FIRST = 1001;
90
91 /**
92 * The last number in the range of ids used for action events.
93 */
94 public static final int ACTION_LAST = 1001;
95
96 /**
97 * This event id indicates that a meaningful action occurred.
98 */
99 @Native public static final int ACTION_PERFORMED = ACTION_FIRST; //Event.ACTION_EVENT
100
101 /**
102 * The nonlocalized string that gives more details
103 * of what actually caused the event.
256 */
257 public long getWhen() {
258 return when;
259 }
260
261 /**
262 * Returns the modifier keys held down during this action event.
263 *
264 * @return the bitwise-or of the modifier constants
265 */
266 public int getModifiers() {
267 return modifiers;
268 }
269
270 /**
271 * Returns a parameter string identifying this action event.
272 * This method is useful for event-logging and for debugging.
273 *
274 * @return a string identifying the event and its associated command
275 */
276 @SuppressWarnings("deprecation")
277 public String paramString() {
278 String typeStr;
279 switch(id) {
280 case ACTION_PERFORMED:
281 typeStr = "ACTION_PERFORMED";
282 break;
283 default:
284 typeStr = "unknown type";
285 }
286 return typeStr + ",cmd="+actionCommand+",when="+when+",modifiers="+
287 KeyEvent.getKeyModifiersText(modifiers);
288 }
289 }
|