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
|
package NET.worlds.console;
import java.awt.Button;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Event;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Label;
import java.awt.Point;
import java.awt.TextField;
public class AttributeSortPanel extends Frame implements MainCallback, MainTerminalCallback {
private static final long serialVersionUID = -7230661745931320369L;
private AttributeList list;
private Button addButton = new Button("Add");
private Button deleteButton = new Button("Delete");
private Button moveUpButton = new Button("MoveUp");
private Button moveDownButton = new Button("MoveDown");
private Button okButton = new Button("Ok");
private Button cancelButton = new Button("Cancel");
private Button clearButton = new Button("Clear");
private TextField attNameField = new TextField(32);
private Label attNameLabel = new Label("Attribute Name: ");
public AttributeSortPanel(java.awt.Window parent) {
super("Attribute Sorting");
this.list = new AttributeList(10);
GridBagLayout gbag = new GridBagLayout();
GridBagConstraints c = new GridBagConstraints();
this.setLayout(gbag);
this.setBackground(Color.gray);
c.gridx = 1;
c.gridy = 1;
c.gridheight = 7;
c.gridwidth = 3;
c.anchor = 18;
gbag.setConstraints(this.list, c);
this.add(this.list);
c.gridx = 4;
c.gridy = 1;
c.gridwidth = 1;
c.gridheight = 1;
gbag.setConstraints(this.moveUpButton, c);
this.add(this.moveUpButton);
c.gridx = 4;
c.gridy = 2;
c.gridwidth = 1;
c.gridheight = 1;
gbag.setConstraints(this.moveDownButton, c);
this.add(this.moveDownButton);
c.gridx = 4;
c.gridy = 5;
c.gridheight = 1;
c.gridwidth = 3;
gbag.setConstraints(this.attNameLabel, c);
this.add(this.attNameLabel);
c.gridy = 6;
c.gridheight = 1;
c.gridwidth = 3;
gbag.setConstraints(this.attNameField, c);
this.add(this.attNameField);
c.gridx = 7;
c.gridy = 6;
c.gridheight = 1;
c.gridwidth = 1;
gbag.setConstraints(this.addButton, c);
this.add(this.addButton);
c.gridx = 7;
c.gridy = 1;
c.gridwidth = 1;
c.gridheight = 1;
gbag.setConstraints(this.deleteButton, c);
this.add(this.deleteButton);
c.gridx = 7;
c.gridy = 2;
gbag.setConstraints(this.clearButton, c);
this.add(this.clearButton);
c.gridx = 5;
c.gridy = 8;
gbag.setConstraints(this.okButton, c);
this.add(this.okButton);
c.gridx = 7;
gbag.setConstraints(this.cancelButton, c);
this.add(this.cancelButton);
this.pack();
Point loc = parent.location();
Dimension size = parent.getSize();
this.reshape(loc.x + (size.width - 512) / 2, loc.y + (size.height - 240) / 2, 512, 240);
this.show();
Main.register(this);
}
@Override
public boolean handleEvent(Event ev) {
switch (ev.id) {
case 201:
this.dispose();
return true;
default:
return super.handleEvent(ev);
}
}
@Override
public boolean action(Event e, Object o) {
if (e.target == this.addButton) {
String attToAdd = this.attNameField.getText();
if (attToAdd != "") {
this.list.add(attToAdd);
}
this.attNameField.setText("");
return true;
} else if (e.target == this.deleteButton) {
this.list.remove(this.list.getSelectedIndex());
return true;
} else if (e.target == this.moveUpButton) {
int index = this.list.getSelectedIndex();
if (index > 0) {
String toPutBack = this.list.getItem(index - 1);
this.list.remove(index - 1);
this.list.add(toPutBack, index);
}
return true;
} else if (e.target == this.moveDownButton) {
int index = this.list.getSelectedIndex();
if (index < this.list.getItemCount()) {
String toPutBack = this.list.getItem(index + 1);
this.list.remove(index + 1);
this.list.add(toPutBack, index);
}
return true;
} else if (e.target == this.cancelButton) {
this.dispose();
return true;
} else if (e.target == this.clearButton) {
this.list.removeAll();
return true;
} else if (e.target == this.okButton) {
this.list.save();
this.dispose();
return true;
} else {
return false;
}
}
@Override
public void mainCallback() {
}
@Override
public void terminalCallback() {
Main.unregister(this);
}
}
|