package NET.worlds.console; import NET.worlds.scape.World; import java.text.MessageFormat; import java.util.Enumeration; import java.util.Vector; class FileSaver implements DialogReceiver { private Vector saveList = new Vector(); private int state; public static final int QUIT = 0; public static final int SAVING = 1; public static final int CANCEL = 2; FileSaver() { Enumeration e = World.getWorlds(); while (e.hasMoreElements()) { World w = e.nextElement(); if (w.getEdited()) { this.saveList.addElement(w); } } this.saveNext(false); } public int getState() { return this.state; } private World getWorld() { return this.saveList.elementAt(0); } private void saveNext(boolean removeFirst) { if (removeFirst) { this.saveList.removeElementAt(0); } if (this.saveList.size() != 0) { this.state = 1; Object[] arguments = new Object[]{new String(this.getWorld().getName())}; new YesNoCancelDialog(Console.getFrame(), this, Console.message("Save-Changes2"), MessageFormat.format(Console.message("has-changed"), arguments)); } else { this.state = 0; } } @Override public void dialogDone(Object who, boolean confirmed) { if (who instanceof YesNoCancelDialog) { switch (((YesNoCancelDialog)who).getChoice()) { case -1: this.state = 2; break; case 0: this.saveNext(true); break; case 1: new FileSysDialog( Console.getFrame(), this, Console.message("Save-World"), 1, "World Save Files|*.world", Shaper.getSaveName(this.getWorld()), true ); } } else { if (confirmed) { FileSysDialog fileDialog = (FileSysDialog)who; if (Shaper.doSave(fileDialog.fileName(), this.getWorld(), false)) { this.saveNext(true); return; } } this.state = 2; } } }