source: trunk/gcc/libjava/java/awt/MenuShortcut.java

Last change on this file was 2, checked in by bird, 22 years ago

Initial revision

  • Property cvs2svn:cvs-rev set to 1.1
  • Property svn:eol-style set to native
  • Property svn:executable set to *
File size: 5.2 KB
Line 
1/* MenuShortcut.java -- A class for menu accelerators
2 Copyright (C) 1999, 2002 Free Software Foundation, Inc.
3
4This file is part of GNU Classpath.
5
6GNU Classpath is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU Classpath is distributed in the hope that it will be useful, but
12WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU Classpath; see the file COPYING. If not, write to the
18Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
1902111-1307 USA.
20
21Linking this library statically or dynamically with other modules is
22making a combined work based on this library. Thus, the terms and
23conditions of the GNU General Public License cover the whole
24combination.
25
26As a special exception, the copyright holders of this library give you
27permission to link this library with independent modules to produce an
28executable, regardless of the license terms of these independent
29modules, and to copy and distribute the resulting executable under
30terms of your choice, provided that you also meet, for each linked
31independent module, the terms and conditions of the license of that
32module. An independent module is a module which is not derived from
33or based on this library. If you modify this library, you may extend
34this exception to your version of the library, but you are not
35obligated to do so. If you do not wish to do so, delete this
36exception statement from your version. */
37
38
39package java.awt;
40
41/**
42 * This class implements a keyboard accelerator for a menu item.
43 *
44 * @author Aaron M. Renn (arenn@urbanophile.com)
45 */
46public class MenuShortcut implements java.io.Serializable
47{
48
49/*
50 * Static Variables
51 */
52
53// Serialization Constant
54private static final long serialVersionUID = 143448358473180225L;
55
56/*************************************************************************/
57
58/*
59 * Instance Variables
60 */
61
62/**
63 * @serial The virtual keycode for the shortcut.
64 */
65private 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 */
71private 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 */
81public
82MenuShortcut(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 */
97public
98MenuShortcut(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 */
115public int
116getKey()
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 */
129public boolean
130usesShiftModifier()
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 */
148public boolean
149equals(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
163public boolean
164equals(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 */
181public String
182toString()
183{
184 return(getClass().getName() + "[" + paramString () + "]");
185}
186
187public int
188hashCode()
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 */
201protected String
202paramString()
203{
204 return "key=" + key + ",usesShift=" + usesShift;
205}
206
207} // class MenuShortcut
Note: See TracBrowser for help on using the repository browser.