package NET.worlds.scape; import NET.worlds.console.PolledDialog; import NET.worlds.network.URL; import java.util.Enumeration; import java.util.Vector; public class URLPropertyEditor extends PropEditor { private FileList files; private Enumeration additions; private boolean acceptAnyExt = false; private boolean acceptDrops; private URLPropertyEditor(Property property, String extList, Enumeration additions, boolean acceptDrops) { super(property); this.acceptDrops = acceptDrops; URL dir = URL.getContainingOrCurDir((SuperRoot)property.getOwner()); if (extList == null) { this.acceptAnyExt = true; } else { if (extList.startsWith("*")) { extList = extList.substring(1); this.acceptAnyExt = true; } this.files = new FileList(dir.unalias(), extList); } this.additions = additions; } @Override public PolledDialog edit(EditTile parent, String title) { Vector v = this.files == null ? new Vector() : this.files.getList(); if (this.additions != null) { while (this.additions.hasMoreElements()) { v.addElement(this.additions.nextElement().toString()); } } return new URLEditorDialog(parent, title, this.property, v, this.acceptAnyExt ? null : this.files); } public static Property make(Property property, String extList) { return make(property, extList, null, true); } public static Property make(Property property, String extList, boolean acceptDrops) { return make(property, extList, null, acceptDrops); } public static Property make(Property property, String extList, Enumeration additions) { return make(property, extList, additions, true); } public static Property make(Property property, String extList, Enumeration additions, boolean acceptDrops) { property.setPropertyType(10); return property.setEditor(new URLPropertyEditor(property, extList, additions, acceptDrops)); } @Override public boolean libraryDrop(EditTile target, Object obj, boolean isPaste, boolean doDrop) { if (!isPaste && this.acceptDrops && obj instanceof URL && (this.acceptAnyExt || this.files.extMatches(((URL)obj).getExt()))) { if (doDrop) { target.addUndoableSet(this.property, obj); } return true; } else { return false; } } }