aboutsummaryrefslogtreecommitdiff
path: root/libjava/java/awt/MenuShortcut.java
blob: b19892627716a3f15fd89791e4d9652c153b1b23 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* Copyright (C) 2000  Free Software Foundation

   This file is part of libgcj.

This software is copyrighted work licensed under the terms of the
Libgcj License.  Please consult the file "LIBGCJ_LICENSE" for
details.  */

package java.awt;

import java.awt.event.KeyEvent;

/* Status: Complete, except for hashCode(). Untested. */

public class MenuShortcut
{
  // Fields from the serialization spec. Decalare others "transient".
  int key;
  boolean usesShift;

  public MenuShortcut(int key)
  {
    this.key = key;
  }

  public MenuShortcut(int key, boolean useShiftModifier)
  {
    this.key = key;
    this.usesShift = useShiftModifier;
  }

  public int getKey()
  {
    return key;
  }

  public boolean usesShiftModifier()
  {
    return usesShift;
  }

  public boolean equals(MenuShortcut ms)
  {
    return (ms.key == key && ms.usesShift == usesShift);
  }

  public boolean equals(Object obj)
  {
    if (obj instanceof MenuShortcut)
      {
        MenuShortcut ms = (MenuShortcut) obj;
	return (ms.key == key && ms.usesShift == usesShift);
      }      
    return false;
  }

  public int hashCode()
  {
    // FIXME: find/implement the correct algorithm for this
    if (usesShift)
      return (2 * key);
    else
      return key;
  }

  public String toString()
  {
    return paramString(); // ?
  }
  
  protected String paramString()
  {
    return KeyEvent.getKeyText(key);
  }
}