OSDN Git Service

* java/awt/MenuItem.java (paramString): Now protected.
[pf3gnuchains/gcc-fork.git] / libjava / java / awt / MenuShortcut.java
1 /* Copyright (C) 2000  Free Software Foundation
2
3    This file is part of libgcj.
4
5 This software is copyrighted work licensed under the terms of the
6 Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
7 details.  */
8
9 package java.awt;
10
11 import java.awt.event.KeyEvent;
12
13 /* Status: Complete, except for hashCode(). Untested. */
14
15 public class MenuShortcut implements java.io.Serializable
16 {
17   // Fields from the serialization spec. Decalare others "transient".
18   int key;
19   boolean usesShift;
20
21   public MenuShortcut(int key)
22   {
23     this.key = key;
24   }
25
26   public MenuShortcut(int key, boolean useShiftModifier)
27   {
28     this.key = key;
29     this.usesShift = useShiftModifier;
30   }
31
32   public int getKey()
33   {
34     return key;
35   }
36
37   public boolean usesShiftModifier()
38   {
39     return usesShift;
40   }
41
42   public boolean equals(MenuShortcut ms)
43   {
44     return (ms.key == key && ms.usesShift == usesShift);
45   }
46
47   public boolean equals(Object obj)
48   {
49     if (obj instanceof MenuShortcut)
50       {
51         MenuShortcut ms = (MenuShortcut) obj;
52         return (ms.key == key && ms.usesShift == usesShift);
53       }      
54     return false;
55   }
56
57   public int hashCode()
58   {
59     // FIXME: find/implement the correct algorithm for this
60     if (usesShift)
61       return (2 * key);
62     else
63       return key;
64   }
65
66   public String toString()
67   {
68     return paramString(); // ?
69   }
70   
71   protected String paramString()
72   {
73     return KeyEvent.getKeyText(key);
74   }
75 }