001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Michael Danilov
019: * @version $Revision$
020: */package java.awt.event;
021:
022: import java.awt.AWTEvent;
023:
024: public class ActionEvent extends AWTEvent {
025:
026: private static final long serialVersionUID = -7671078796273832149L;
027:
028: public static final int SHIFT_MASK = 1;
029:
030: public static final int CTRL_MASK = 2;
031:
032: public static final int META_MASK = 4;
033:
034: public static final int ALT_MASK = 8;
035:
036: public static final int ACTION_FIRST = 1001;
037:
038: public static final int ACTION_LAST = 1001;
039:
040: public static final int ACTION_PERFORMED = 1001;
041:
042: private long when;
043: private int modifiers;
044: private String command;
045:
046: public ActionEvent(Object source, int id, String command) {
047: this (source, id, command, 0);
048: }
049:
050: public ActionEvent(Object source, int id, String command,
051: int modifiers) {
052: this (source, id, command, 0l, modifiers);
053: }
054:
055: public ActionEvent(Object source, int id, String command,
056: long when, int modifiers) {
057: super (source, id);
058:
059: this .command = command;
060: this .when = when;
061: this .modifiers = modifiers;
062: }
063:
064: public int getModifiers() {
065: return modifiers;
066: }
067:
068: public String getActionCommand() {
069: return command;
070: }
071:
072: public long getWhen() {
073: return when;
074: }
075:
076: @Override
077: public String paramString() {
078: /* The format is based on 1.5 release behavior
079: * which can be revealed by the following code:
080: *
081: * ActionEvent e = new ActionEvent(new Component(){},
082: * ActionEvent.ACTION_PERFORMED, "Command",
083: * ActionEvent.SHIFT_MASK|ActionEvent.CTRL_MASK|
084: * ActionEvent.META_MASK|ActionEvent.ALT_MASK);
085: * System.out.println(e);
086: */
087:
088: String idString = (id == ACTION_PERFORMED) ? "ACTION_PERFORMED" : "unknown type"; //$NON-NLS-1$ //$NON-NLS-2$
089: String modifiersString = ""; //$NON-NLS-1$
090:
091: if ((modifiers & SHIFT_MASK) > 0) {
092: modifiersString += "Shift"; //$NON-NLS-1$
093: }
094: if ((modifiers & CTRL_MASK) > 0) {
095: modifiersString += modifiersString.length() == 0 ? "Ctrl" : "+Ctrl"; //$NON-NLS-1$ //$NON-NLS-2$
096: }
097: if ((modifiers & META_MASK) > 0) {
098: modifiersString += modifiersString.length() == 0 ? "Meta" : "+Meta"; //$NON-NLS-1$ //$NON-NLS-2$
099: }
100: if ((modifiers & ALT_MASK) > 0) {
101: modifiersString += modifiersString.length() == 0 ? "Alt" : "+Alt"; //$NON-NLS-1$ //$NON-NLS-2$
102: }
103:
104: return (idString + ",cmd=" + command + ",when=" + when + //$NON-NLS-1$ //$NON-NLS-2$
105: ",modifiers=" + modifiersString); //$NON-NLS-1$
106: }
107:
108: }
|