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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
|
package NET.worlds.console;
import NET.worlds.scape.EventQueue;
import java.awt.Button;
import java.awt.Choice;
import java.awt.Color;
import java.awt.Event;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Label;
import java.awt.Panel;
import java.awt.Point;
import java.util.Vector;
public class AvatarDialog extends PolledDialog {
private static final long serialVersionUID = 8661992825430619335L;
private Button okButton = new Button(Console.message("Close"));
private AvatarDialogCallback callback;
private Vector<Choice> choices = new Vector<Choice>();
private Vector<int[]> changes = new Vector<int[]>();
private static Font font = new Font(Console.message("MenuFont"), 0, 12);
private static Font bfont = new Font(Console.message("ButtonFont"), 0, 12);
private int checkChanges;
static Point lastWindowLocation = null;
public AvatarDialog(java.awt.Window parent, DialogReceiver receiver, String title, AvatarDialogCallback callback) {
super(parent, receiver, title, false);
this.callback = callback;
this.setResizable(false);
this.setAlignment(3);
this.ready();
}
public void setChangeCheck() {
this.checkChanges = 2;
}
@Override
protected void build() {
Vector<String> headings = this.callback.getComponents();
int rows = headings.size();
Panel top = new Panel(new GridLayout(rows, 2, 2, 2));
top.setFont(font);
top.setBackground(Color.black);
for (int i = 0; i < rows; i++) {
Label label = new Label(headings.elementAt(i), 2);
label.setForeground(Color.white);
label.setFont(font);
top.add(label);
Choice choice = new Choice();
choice.setForeground(Color.white);
choice.setBackground(Color.black);
choice.setFont(font);
top.add(choice);
this.choices.addElement(choice);
Vector<String> items = this.callback.getChoices(i);
int count = items.size();
for (int j = 0; j < count; j++) {
choice.add(items.elementAt(j));
}
choice.select(this.callback.getCurrentSelection(i));
}
GridBagLayout gbag = new GridBagLayout();
this.setLayout(gbag);
GridBagConstraints c = new GridBagConstraints();
c.weightx = 1.0;
c.weighty = 1.0;
c.gridheight = rows;
c.gridwidth = 0;
c.fill = 0;
this.add(gbag, top, c);
Panel bottom = new Panel();
this.okButton.setFont(bfont);
bottom.add(this.okButton);
bottom.setBackground(Color.black);
c.gridheight = 1;
c.weightx = 0.0;
c.weighty = 0.0;
c.fill = 1;
this.add(gbag, bottom, c);
this.okButton.setBackground(Color.black);
this.okButton.setForeground(Color.white);
}
@Override
public boolean handleEvent(Event event) {
if (EventQueue.redirectDrivingKeys(event)) {
return true;
} else {
return event.id == 201 ? this.done(false) : super.handleEvent(event);
}
}
@Override
public boolean action(Event event, Object what) {
Object target = event.target;
if (target == this.okButton) {
return this.done(true);
} else {
int count = this.choices.size();
for (int i = 0; i < count; i++) {
Choice choice = this.choices.elementAt(i);
if (target == choice) {
int[] change = new int[]{i, choice.getSelectedIndex()};
this.changes.addElement(change);
return true;
}
}
return false;
}
}
@Override
public boolean done(boolean confirmed) {
lastWindowLocation = this.getLocation();
return super.done(confirmed);
}
public void closeWin() {
if (lastWindowLocation == null) {
this.done(true);
}
}
@Override
protected void initialSize(int width, int height) {
if (lastWindowLocation == null) {
super.initialSize(width, height);
} else {
this.setLocation(lastWindowLocation);
lastWindowLocation = null;
this.setSize(width, height);
}
}
@Override
protected void activeCallback() {
if (this.checkChanges > 0 && --this.checkChanges == 0) {
for (int i = 0; i < this.choices.size(); i++) {
this.choices.elementAt(i).select(this.callback.getCurrentSelection(i));
}
}
while (this.changes.size() != 0) {
int[] change = this.changes.elementAt(0);
this.callback.setCurrentSelection(change[0], change[1]);
this.checkChanges = 1;
this.changes.removeElementAt(0);
}
}
@Override
public boolean keyDown(Event event, int key) {
return key == 27 ? this.done(false) : super.keyDown(event, key);
}
}
|