1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package javax.microedition.lcdui;
22
23 public class Command {
24
25 public static final int SCREEN = 1;
26
27 public static final int BACK = 2;
28
29 public static final int CANCEL = 3;
30
31 public static final int OK = 4;
32
33 public static final int HELP = 5;
34
35 public static final int STOP = 6;
36
37 public static final int EXIT = 7;
38
39 public static final int ITEM = 8;
40
41
42
43
44
45 private Command originalCommand;
46
47 private Item focusedItem;
48
49 private Command itemCommand;
50
51 String label;
52
53 int commandType;
54
55 int priority;
56
57 public Command(String label, int commandType, int priority) {
58 this.label = label;
59 this.commandType = commandType;
60 this.priority = priority;
61 }
62
63 public Command(String shortLabel, String longLabel, int commandType,
64 int priority) {
65
66 this(shortLabel, commandType, priority);
67 }
68
69 public int getCommandType() {
70 return commandType;
71 }
72
73 public String getLabel() {
74 return label;
75 }
76
77 public String getLongLabel() {
78
79 return label;
80 }
81
82 public int getPriority() {
83 return priority;
84 }
85
86 Item getFocusedItem() {
87 if (isRegularCommand()) {
88 throw new IllegalStateException();
89 }
90
91 return focusedItem;
92 }
93
94 Command getItemCommand(Item item) {
95 if (!isRegularCommand()) {
96 throw new IllegalStateException();
97 }
98 if (item == null) {
99 throw new NullPointerException();
100 }
101
102
103 if (itemCommand == null) {
104 itemCommand = new Command(getLabel(), Command.ITEM, getPriority());
105 itemCommand.originalCommand = this;
106 }
107 itemCommand.focusedItem = item;
108 return itemCommand;
109 }
110
111 Command getOriginalCommand() {
112 if (isRegularCommand()) {
113 throw new IllegalStateException();
114 }
115
116 return originalCommand;
117 }
118
119 boolean isRegularCommand() {
120 return originalCommand == null;
121 }
122 }