| 1 | /* MenuShortcut.java -- A class for menu accelerators
|
|---|
| 2 | Copyright (C) 1999, 2002 Free Software Foundation, Inc.
|
|---|
| 3 |
|
|---|
| 4 | This file is part of GNU Classpath.
|
|---|
| 5 |
|
|---|
| 6 | GNU Classpath is free software; you can redistribute it and/or modify
|
|---|
| 7 | it under the terms of the GNU General Public License as published by
|
|---|
| 8 | the Free Software Foundation; either version 2, or (at your option)
|
|---|
| 9 | any later version.
|
|---|
| 10 |
|
|---|
| 11 | GNU Classpath is distributed in the hope that it will be useful, but
|
|---|
| 12 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|---|
| 14 | General Public License for more details.
|
|---|
| 15 |
|
|---|
| 16 | You should have received a copy of the GNU General Public License
|
|---|
| 17 | along with GNU Classpath; see the file COPYING. If not, write to the
|
|---|
| 18 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
|
|---|
| 19 | 02111-1307 USA.
|
|---|
| 20 |
|
|---|
| 21 | Linking this library statically or dynamically with other modules is
|
|---|
| 22 | making a combined work based on this library. Thus, the terms and
|
|---|
| 23 | conditions of the GNU General Public License cover the whole
|
|---|
| 24 | combination.
|
|---|
| 25 |
|
|---|
| 26 | As a special exception, the copyright holders of this library give you
|
|---|
| 27 | permission to link this library with independent modules to produce an
|
|---|
| 28 | executable, regardless of the license terms of these independent
|
|---|
| 29 | modules, and to copy and distribute the resulting executable under
|
|---|
| 30 | terms of your choice, provided that you also meet, for each linked
|
|---|
| 31 | independent module, the terms and conditions of the license of that
|
|---|
| 32 | module. An independent module is a module which is not derived from
|
|---|
| 33 | or based on this library. If you modify this library, you may extend
|
|---|
| 34 | this exception to your version of the library, but you are not
|
|---|
| 35 | obligated to do so. If you do not wish to do so, delete this
|
|---|
| 36 | exception statement from your version. */
|
|---|
| 37 |
|
|---|
| 38 |
|
|---|
| 39 | package java.awt;
|
|---|
| 40 |
|
|---|
| 41 | /**
|
|---|
| 42 | * This class implements a keyboard accelerator for a menu item.
|
|---|
| 43 | *
|
|---|
| 44 | * @author Aaron M. Renn ([email protected])
|
|---|
| 45 | */
|
|---|
| 46 | public class MenuShortcut implements java.io.Serializable
|
|---|
| 47 | {
|
|---|
| 48 |
|
|---|
| 49 | /*
|
|---|
| 50 | * Static Variables
|
|---|
| 51 | */
|
|---|
| 52 |
|
|---|
| 53 | // Serialization Constant
|
|---|
| 54 | private static final long serialVersionUID = 143448358473180225L;
|
|---|
| 55 |
|
|---|
| 56 | /*************************************************************************/
|
|---|
| 57 |
|
|---|
| 58 | /*
|
|---|
| 59 | * Instance Variables
|
|---|
| 60 | */
|
|---|
| 61 |
|
|---|
| 62 | /**
|
|---|
| 63 | * @serial The virtual keycode for the shortcut.
|
|---|
| 64 | */
|
|---|
| 65 | private int key;
|
|---|
| 66 |
|
|---|
| 67 | /**
|
|---|
| 68 | * @serial <code>true</code> if the shift key was used with this shortcut,
|
|---|
| 69 | * or <code>false</code> otherwise.
|
|---|
| 70 | */
|
|---|
| 71 | private boolean usesShift;
|
|---|
| 72 |
|
|---|
| 73 | /*************************************************************************/
|
|---|
| 74 |
|
|---|
| 75 | /**
|
|---|
| 76 | * Initializes a new instance of <code>MenuShortcut</code> with the
|
|---|
| 77 | * specified virtual key value.
|
|---|
| 78 | *
|
|---|
| 79 | * @param key The virtual keycode for the shortcut.
|
|---|
| 80 | */
|
|---|
| 81 | public
|
|---|
| 82 | MenuShortcut(int key)
|
|---|
| 83 | {
|
|---|
| 84 | this(key, false);
|
|---|
| 85 | }
|
|---|
| 86 |
|
|---|
| 87 | /*************************************************************************/
|
|---|
| 88 |
|
|---|
| 89 | /**
|
|---|
| 90 | * Initializes a new instance of <code>MenuShortcut</code> with the
|
|---|
| 91 | * specified virtual key value and shift setting.
|
|---|
| 92 | *
|
|---|
| 93 | * @param key The virtual keycode for the shortcut.
|
|---|
| 94 | * @param usesShift <code>true</code> if the shift key was pressed,
|
|---|
| 95 | * <code>false</code> otherwise.
|
|---|
| 96 | */
|
|---|
| 97 | public
|
|---|
| 98 | MenuShortcut(int key, boolean usesShift)
|
|---|
| 99 | {
|
|---|
| 100 | this.key = key;
|
|---|
| 101 | this.usesShift = usesShift;
|
|---|
| 102 | }
|
|---|
| 103 |
|
|---|
| 104 | /*************************************************************************/
|
|---|
| 105 |
|
|---|
| 106 | /*
|
|---|
| 107 | * Instance Methods
|
|---|
| 108 | */
|
|---|
| 109 |
|
|---|
| 110 | /**
|
|---|
| 111 | * Returns the virtual keycode for this shortcut.
|
|---|
| 112 | *
|
|---|
| 113 | * @return The virtual keycode for this shortcut.
|
|---|
| 114 | */
|
|---|
| 115 | public int
|
|---|
| 116 | getKey()
|
|---|
| 117 | {
|
|---|
| 118 | return(key);
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | /*************************************************************************/
|
|---|
| 122 |
|
|---|
| 123 | /**
|
|---|
| 124 | * Returns the shift setting for this shortcut.
|
|---|
| 125 | *
|
|---|
| 126 | * @return <code>true</code> if the shift key was pressed, <code>false</code>
|
|---|
| 127 | * otherwise.
|
|---|
| 128 | */
|
|---|
| 129 | public boolean
|
|---|
| 130 | usesShiftModifier()
|
|---|
| 131 | {
|
|---|
| 132 | return(usesShift);
|
|---|
| 133 | }
|
|---|
| 134 |
|
|---|
| 135 | /*************************************************************************/
|
|---|
| 136 |
|
|---|
| 137 | /**
|
|---|
| 138 | * Tests this object for equality against the specified object. The two
|
|---|
| 139 | * objects will be considered equal if and only if the specified object
|
|---|
| 140 | * is an instance of <code>MenuShortcut</code> and has the same key value
|
|---|
| 141 | * and shift setting as this object.
|
|---|
| 142 | *
|
|---|
| 143 | * @param obj The object to test for equality against.
|
|---|
| 144 | *
|
|---|
| 145 | * @return <code>true</code> if the two objects are equal, <code>false</code>
|
|---|
| 146 | * otherwise.
|
|---|
| 147 | */
|
|---|
| 148 | public boolean
|
|---|
| 149 | equals(MenuShortcut obj)
|
|---|
| 150 | {
|
|---|
| 151 | if (obj == null)
|
|---|
| 152 | return(false);
|
|---|
| 153 |
|
|---|
| 154 | if (obj.key != this.key)
|
|---|
| 155 | return(false);
|
|---|
| 156 |
|
|---|
| 157 | if (obj.usesShift != this.usesShift)
|
|---|
| 158 | return(false);
|
|---|
| 159 |
|
|---|
| 160 | return(true);
|
|---|
| 161 | }
|
|---|
| 162 |
|
|---|
| 163 | public boolean
|
|---|
| 164 | equals(Object obj)
|
|---|
| 165 | {
|
|---|
| 166 | if (obj instanceof MenuShortcut)
|
|---|
| 167 | {
|
|---|
| 168 | MenuShortcut ms = (MenuShortcut) obj;
|
|---|
| 169 | return (ms.key == key && ms.usesShift == usesShift);
|
|---|
| 170 | }
|
|---|
| 171 | return false;
|
|---|
| 172 | }
|
|---|
| 173 |
|
|---|
| 174 | /*************************************************************************/
|
|---|
| 175 |
|
|---|
| 176 | /**
|
|---|
| 177 | * Returns a string representation of this shortcut.
|
|---|
| 178 | *
|
|---|
| 179 | * @return A string representation of this shortcut.
|
|---|
| 180 | */
|
|---|
| 181 | public String
|
|---|
| 182 | toString()
|
|---|
| 183 | {
|
|---|
| 184 | return(getClass().getName() + "[" + paramString () + "]");
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | public int
|
|---|
| 188 | hashCode()
|
|---|
| 189 | {
|
|---|
| 190 | // Arbitrary.
|
|---|
| 191 | return key + (usesShift ? 23 : 57);
|
|---|
| 192 | }
|
|---|
| 193 |
|
|---|
| 194 | /*************************************************************************/
|
|---|
| 195 |
|
|---|
| 196 | /**
|
|---|
| 197 | * Returns a debugging string for this object.
|
|---|
| 198 | *
|
|---|
| 199 | * @return A debugging string for this object.
|
|---|
| 200 | */
|
|---|
| 201 | protected String
|
|---|
| 202 | paramString()
|
|---|
| 203 | {
|
|---|
| 204 | return "key=" + key + ",usesShift=" + usesShift;
|
|---|
| 205 | }
|
|---|
| 206 |
|
|---|
| 207 | } // class MenuShortcut
|
|---|