1 /* MenuShortcut.java -- A class for menu accelerators
2 Copyright (C) 1999, 2002 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
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)
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.
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
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
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. */
42 * This class implements a keyboard accelerator for a menu item.
44 * @author Aaron M. Renn (arenn@urbanophile.com)
46 public class MenuShortcut
implements java
.io
.Serializable
53 // Serialization Constant
54 private static final long serialVersionUID
= 143448358473180225L;
56 /*************************************************************************/
63 * @serial The virtual keycode for the shortcut.
68 * @serial <code>true</code> if the shift key was used with this shortcut,
69 * or <code>false</code> otherwise.
71 private boolean usesShift
;
73 /*************************************************************************/
76 * Initializes a new instance of <code>MenuShortcut</code> with the
77 * specified virtual key value.
79 * @param key The virtual keycode for the shortcut.
87 /*************************************************************************/
90 * Initializes a new instance of <code>MenuShortcut</code> with the
91 * specified virtual key value and shift setting.
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.
98 MenuShortcut(int key
, boolean usesShift
)
101 this.usesShift
= usesShift
;
104 /*************************************************************************/
111 * Returns the virtual keycode for this shortcut.
113 * @return The virtual keycode for this shortcut.
121 /*************************************************************************/
124 * Returns the shift setting for this shortcut.
126 * @return <code>true</code> if the shift key was pressed, <code>false</code>
135 /*************************************************************************/
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.
143 * @param obj The object to test for equality against.
145 * @return <code>true</code> if the two objects are equal, <code>false</code>
149 equals(MenuShortcut obj
)
154 if (obj
.key
!= this.key
)
157 if (obj
.usesShift
!= this.usesShift
)
166 if (obj
instanceof MenuShortcut
)
168 MenuShortcut ms
= (MenuShortcut
) obj
;
169 return (ms
.key
== key
&& ms
.usesShift
== usesShift
);
174 /*************************************************************************/
177 * Returns a string representation of this shortcut.
179 * @return A string representation of this shortcut.
184 return(getClass().getName() + "[" + paramString () + "]");
191 return key
+ (usesShift ?
23 : 57);
194 /*************************************************************************/
197 * Returns a debugging string for this object.
199 * @return A debugging string for this object.
204 return "key=" + key
+ ",usesShift=" + usesShift
;
207 } // class MenuShortcut