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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
package NET.worlds.console;
import java.awt.Button;
import java.awt.Event;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
public class YesNoCancelDialog extends PolledDialog {
private static final long serialVersionUID = 4497394464783317237L;
private Button yesButton = new Button(Console.message("Yes"));
private Button noButton = new Button(Console.message("No"));
private Button cancelButton = new Button(Console.message("Cancel"));
private GridBagLayout gbag = new GridBagLayout();
private String prompt;
private int choice = -2;
public static final int UNDECIDED = -2;
public static final int CANCEL = -1;
public static final int NO = 0;
public static final int YES = 1;
public YesNoCancelDialog(java.awt.Window parent, DialogReceiver receiver, String title, String prompt) {
super(parent, receiver, title, true);
this.prompt = prompt;
this.setLayout(this.gbag);
this.ready();
}
public int getChoice() {
return this.choice;
}
@Override
protected void build() {
GridBagConstraints c = new GridBagConstraints();
c.weightx = 1.0;
c.weighty = 1.0;
c.gridwidth = 0;
this.add(this.gbag, new MultiLineLabel(this.prompt, 5, 5), c);
c.gridwidth = 3;
c.weightx = 1.0;
c.weighty = 0.0;
this.add(this.gbag, this.yesButton, c);
this.add(this.gbag, this.noButton, c);
this.add(this.gbag, this.cancelButton, c);
}
@Override
public void show() {
super.show();
this.yesButton.requestFocus();
}
private boolean yes() {
this.choice = 1;
return this.done(true);
}
private boolean no() {
this.choice = 0;
return this.done(false);
}
private boolean cancel() {
this.choice = -1;
return this.done(false);
}
@Override
public boolean handleEvent(Event event) {
return event.id == 201 ? this.cancel() : super.handleEvent(event);
}
@Override
public boolean action(Event event, Object what) {
Object target = event.target;
if (target == this.yesButton) {
return this.yes();
} else if (target == this.noButton) {
return this.no();
} else {
return target == this.cancelButton ? this.cancel() : false;
}
}
@Override
public boolean keyDown(Event event, int key) {
return key == 27 ? this.cancel() : super.keyDown(event, key);
}
}
|