-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoteController.java
More file actions
44 lines (34 loc) · 1 KB
/
RemoteController.java
File metadata and controls
44 lines (34 loc) · 1 KB
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
package org.fade.pattern.bp.command;
/**
* 命令模式
* 遥控器
* @author fade
* */
public class RemoteController {
private Command[] onCommands;
private Command[] offCommands;
private Command undoCommand;
public RemoteController(){
this.onCommands = new Command[5];
this.offCommands = new Command[5];
for (int i = 0;i<5;i++){
this.onCommands[i] = new NullCommand();
this.offCommands[i] = new NullCommand();
}
}
public void setCommands(int no,Command onCommand,Command offCommand){
this.onCommands[no] = onCommand;
this.offCommands[no] = offCommand;
}
public void onOpenButtonPushed(int no){
this.onCommands[no].execute();
this.undoCommand = this.onCommands[no];
}
public void onCloseButtonPushed(int no){
this.offCommands[no].execute();
this.undoCommand = this.offCommands[no];
}
public void onUndoButtonPushed(){
this.undoCommand.undo();
}
}