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
|
package NET.worlds.scape;
import NET.worlds.console.Console;
import NET.worlds.console.OkCancelDialog;
import java.awt.Choice;
import java.awt.GridBagConstraints;
import java.awt.List;
import java.awt.TextField;
import java.util.Enumeration;
import java.util.StringTokenizer;
class LibEntContentEditorDialog extends OkCancelDialog {
private Property property;
private TextField strField = new TextField(40);
private List list = new List();
private Choice choice = new Choice();
private EditTile parent;
private static String[] choices = new String[]{"WObject files", "Behavior/Action files", "Texture files"};
private static String[] dirs = new String[]{LibrariesTile.getLibSubdir(), LibrariesTile.getLibSubdir(), LibrariesTile.getLibSubdir()};
private static String[] exts = new String[]{WObject.getSaveExtension(), "class", TextureDecoder.getAllExts()};
LibEntContentEditorDialog(EditTile parent, String title, Property property) {
super(Console.getFrame(), parent, title);
this.property = property;
this.parent = parent;
this.ready();
}
private void matchExt(String name) {
int lastDot = name.lastIndexOf(46);
if (lastDot != -1) {
String ext = name.substring(lastDot + 1).toLowerCase();
for (int i = 0; i < exts.length; i++) {
StringTokenizer t = new StringTokenizer(exts[i], ";");
while (t.hasMoreTokens()) {
if (ext.equals(t.nextToken())) {
this.choice.select(i);
return;
}
}
}
}
}
@Override
protected void build() {
for (int i = 0; i < choices.length; i++) {
this.choice.addItem(choices[i]);
}
String name = (String)this.property.get();
if (name == null) {
name = "";
}
this.strField.setText(name);
this.matchExt(name);
this.setListContents();
GridBagConstraints c = new GridBagConstraints();
c.fill = 2;
c.weightx = 1.0;
c.weighty = 1.0;
c.gridwidth = 0;
this.add(this.gbag, this.strField, c);
c.gridheight = 6;
this.add(this.gbag, this.list, c);
c.gridheight = 1;
this.add(this.gbag, this.choice, c);
super.build();
}
private void setListContents() {
int count = this.list.countItems();
if (count != 0) {
this.list.delItems(0, count - 1);
}
int chosen = this.choice.getSelectedIndex();
Enumeration files = new FileList(dirs[chosen], exts[chosen]).getList().elements();
while (files.hasMoreElements()) {
this.list.addItem((String)files.nextElement());
}
String s = (String)this.property.get();
this.strField.setText(s != null ? s : "");
}
@Override
public boolean handleEvent(java.awt.Event event) {
if (event.id == 701) {
this.strField.setText(this.list.getSelectedItem());
this.strField.selectAll();
}
return super.handleEvent(event);
}
@Override
public boolean action(java.awt.Event event, Object what) {
if (event.target == this.list) {
event.target = this.okButton;
}
if (event.target == this.choice) {
this.setListContents();
}
return super.action(event, what);
}
@Override
protected boolean setValue() {
String text = this.strField.getText().trim();
if (text.length() != 0) {
this.parent.addUndoableSet(this.property, text);
return true;
} else {
return false;
}
}
@Override
public void show() {
super.show();
this.strField.requestFocus();
this.strField.selectAll();
}
}
|