2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / libjava / java / awt / MenuShortcut.java
blob4d9ef601b5371bde01acd6e67cf50d36b43f9c8b
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)
9 any later version.
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
19 02111-1307 USA.
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.
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. */
39 package java.awt;
41 /**
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
50 * Static Variables
53 // Serialization Constant
54 private static final long serialVersionUID = 143448358473180225L;
56 /*************************************************************************/
59 * Instance Variables
62 /**
63 * @serial The virtual keycode for the shortcut.
65 private int key;
67 /**
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 /*************************************************************************/
75 /**
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.
81 public
82 MenuShortcut(int key)
84 this(key, false);
87 /*************************************************************************/
89 /**
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.
97 public
98 MenuShortcut(int key, boolean usesShift)
100 this.key = key;
101 this.usesShift = usesShift;
104 /*************************************************************************/
107 * Instance Methods
111 * Returns the virtual keycode for this shortcut.
113 * @return The virtual keycode for this shortcut.
115 public int
116 getKey()
118 return(key);
121 /*************************************************************************/
124 * Returns the shift setting for this shortcut.
126 * @return <code>true</code> if the shift key was pressed, <code>false</code>
127 * otherwise.
129 public boolean
130 usesShiftModifier()
132 return(usesShift);
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>
146 * otherwise.
148 public boolean
149 equals(MenuShortcut obj)
151 if (obj == null)
152 return(false);
154 if (obj.key != this.key)
155 return(false);
157 if (obj.usesShift != this.usesShift)
158 return(false);
160 return(true);
163 public boolean
164 equals(Object obj)
166 if (obj instanceof MenuShortcut)
168 MenuShortcut ms = (MenuShortcut) obj;
169 return (ms.key == key && ms.usesShift == usesShift);
171 return false;
174 /*************************************************************************/
177 * Returns a string representation of this shortcut.
179 * @return A string representation of this shortcut.
181 public String
182 toString()
184 return(getClass().getName() + "[" + paramString () + "]");
187 public int
188 hashCode()
190 // Arbitrary.
191 return key + (usesShift ? 23 : 57);
194 /*************************************************************************/
197 * Returns a debugging string for this object.
199 * @return A debugging string for this object.
201 protected String
202 paramString()
204 return "key=" + key + ",usesShift=" + usesShift;
207 } // class MenuShortcut