1 7 package java.awt; 8 9 import java.awt.event.KeyEvent ; 10 11 28 public class MenuShortcut implements java.io.Serializable 29 { 30 45 int key; 46 47 56 boolean usesShift; 57 58 61 private static final long serialVersionUID = 143448358473180225L; 62 63 70 public MenuShortcut(int key) { 71 this(key, false); 72 } 73 74 83 public MenuShortcut(int key, boolean useShiftModifier) { 84 this.key = key; 85 this.usesShift = useShiftModifier; 86 } 87 88 94 public int getKey() { 95 return key; 96 } 97 98 104 public boolean usesShiftModifier() { 105 return usesShift; 106 } 107 108 117 public boolean equals(MenuShortcut s) { 118 return (s != null && (s.getKey() == key) && 119 (s.usesShiftModifier() == usesShift)); 120 } 121 122 131 public boolean equals(Object obj) { 132 if (obj instanceof MenuShortcut ) { 133 return equals( (MenuShortcut ) obj ); 134 } 135 return false; 136 } 137 138 143 public int hashCode() { 144 return (usesShift) ? (~key) : key; 145 } 146 147 152 public String toString() { 153 int modifiers = 0; 154 if (!GraphicsEnvironment.isHeadless()) { 155 modifiers = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); 156 } 157 if (usesShiftModifier()) { 158 modifiers |= Event.SHIFT_MASK; 159 } 160 return KeyEvent.getKeyModifiersText(modifiers) + "+" + 161 KeyEvent.getKeyText(key); 162 } 163 164 170 protected String paramString() { 171 String str = "key=" + key; 172 if (usesShiftModifier()) { 173 str += ",usesShiftModifier"; 174 } 175 return str; 176 } 177 } 178 | Popular Tags |