1/* 2 * Licensed to the Apache Software Foundation (ASF) under one or more 3 * contributor license agreements. See the NOTICE file distributed with 4 * this work for additional information regarding copyright ownership. 5 * The ASF licenses this file to You under the Apache License, Version 2.0 6 * (the "License"); you may not use this file except in compliance with 7 * the License. You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17/** 18 * @author Michael Danilov 19 * @version $Revision$ 20 */ 21package java.awt.event; 22 23import java.awt.AWTEvent; 24 25/** 26 * This class is not supported in Android 1.0. It is merely provided to maintain 27 * interface compatibility with desktop Java implementations. 28 * 29 * @since Android 1.0 30 */ 31public class ActionEvent extends AWTEvent { 32 33 private static final long serialVersionUID = -7671078796273832149L; 34 35 public static final int SHIFT_MASK = 1; 36 37 public static final int CTRL_MASK = 2; 38 39 public static final int META_MASK = 4; 40 41 public static final int ALT_MASK = 8; 42 43 public static final int ACTION_FIRST = 1001; 44 45 public static final int ACTION_LAST = 1001; 46 47 public static final int ACTION_PERFORMED = 1001; 48 49 private long when; 50 private int modifiers; 51 private String command; 52 53 public ActionEvent(Object source, int id, String command) { 54 this(source, id, command, 0); 55 } 56 57 public ActionEvent(Object source, int id, String command, int modifiers) { 58 this(source, id, command, 0l, modifiers); 59 } 60 61 public ActionEvent(Object source, int id, String command, long when, int modifiers) { 62 super(source, id); 63 64 this.command = command; 65 this.when = when; 66 this.modifiers = modifiers; 67 } 68 69 public int getModifiers() { 70 return modifiers; 71 } 72 73 public String getActionCommand() { 74 return command; 75 } 76 77 public long getWhen() { 78 return when; 79 } 80 81 @Override 82 public String paramString() { 83 /* The format is based on 1.5 release behavior 84 * which can be revealed by the following code: 85 * 86 * ActionEvent e = new ActionEvent(new Component(){}, 87 * ActionEvent.ACTION_PERFORMED, "Command", 88 * ActionEvent.SHIFT_MASK|ActionEvent.CTRL_MASK| 89 * ActionEvent.META_MASK|ActionEvent.ALT_MASK); 90 * System.out.println(e); 91 */ 92 93 String idString = (id == ACTION_PERFORMED) ? 94 "ACTION_PERFORMED" : "unknown type"; //$NON-NLS-1$ //$NON-NLS-2$ 95 String modifiersString = ""; //$NON-NLS-1$ 96 97 if ((modifiers & SHIFT_MASK) > 0) { 98 modifiersString += "Shift"; //$NON-NLS-1$ 99 } 100 if ((modifiers & CTRL_MASK) > 0) { 101 modifiersString += modifiersString.length() == 0 ? "Ctrl" : "+Ctrl"; //$NON-NLS-1$ //$NON-NLS-2$ 102 } 103 if ((modifiers & META_MASK) > 0) { 104 modifiersString += modifiersString.length() == 0 ? "Meta" : "+Meta"; //$NON-NLS-1$ //$NON-NLS-2$ 105 } 106 if ((modifiers & ALT_MASK) > 0) { 107 modifiersString += modifiersString.length() == 0 ? "Alt" : "+Alt"; //$NON-NLS-1$ //$NON-NLS-2$ 108 } 109 110 return (idString + ",cmd=" + command + ",when=" + when + //$NON-NLS-1$ //$NON-NLS-2$ 111 ",modifiers=" + modifiersString); //$NON-NLS-1$ 112 } 113 114} 115