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
|
package NET.worlds.console;
import java.awt.Button;
import java.awt.Event;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Label;
import java.awt.Panel;
import java.awt.TextField;
class SavedAvAddDialog extends PolledDialog {
private static final long serialVersionUID = 6413925837010864629L;
private TextField nameField = new TextField(40);
private Button okButton = new Button(Console.message("OK"));
private Button cancelButton = new Button(Console.message("Cancel"));
private String newName;
private static Font font = new Font(Console.message("MenuFont"), 0, 12);
private static Font bfont = new Font(Console.message("ButtonFont"), 0, 12);
public SavedAvAddDialog(java.awt.Window parent, SavedAvPart avatars) {
super(parent, avatars, Console.message("Save-Avatar"), true);
this.ready();
}
@Override
protected void build() {
GridBagLayout gbag = new GridBagLayout();
this.setLayout(gbag);
GridBagConstraints c = new GridBagConstraints();
c.fill = 0;
c.weightx = 1.0;
c.weighty = 1.0;
c.gridwidth = 2;
c.gridheight = 1;
this.add(gbag, new Label(Console.message("Name")), c);
c.gridwidth = 0;
c.fill = 2;
this.nameField.setFont(font);
this.add(gbag, this.nameField, c);
Panel buttons = new Panel();
this.okButton.setFont(bfont);
this.cancelButton.setFont(bfont);
buttons.add(this.okButton);
buttons.add(this.cancelButton);
c.gridwidth = 0;
c.fill = 0;
this.add(gbag, buttons, c);
}
@Override
public boolean action(Event event, Object what) {
Object target = event.target;
if (target == this.okButton && this.mayConfirm()) {
return this.done(true);
} else {
return target == this.cancelButton ? this.done(false) : false;
}
}
@Override
public String getName() {
return this.newName;
}
private boolean mayConfirm() {
this.newName = this.nameField.getText().trim();
return this.newName.length() != 0;
}
@Override
public boolean keyDown(Event event, int key) {
if (key == 27) {
return this.done(false);
} else {
return key == 10 && this.mayConfirm() ? this.done(true) : super.keyDown(event, key);
}
}
}
|