summaryrefslogtreecommitdiff
path: root/NET/worlds/scape/LibEntContentEditorDialog.java
diff options
context:
space:
mode:
Diffstat (limited to 'NET/worlds/scape/LibEntContentEditorDialog.java')
-rw-r--r--NET/worlds/scape/LibEntContentEditorDialog.java131
1 files changed, 131 insertions, 0 deletions
diff --git a/NET/worlds/scape/LibEntContentEditorDialog.java b/NET/worlds/scape/LibEntContentEditorDialog.java
new file mode 100644
index 0000000..2311d8c
--- /dev/null
+++ b/NET/worlds/scape/LibEntContentEditorDialog.java
@@ -0,0 +1,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();
+ }
+}