diff options
Diffstat (limited to 'NET/worlds/console/FileSaver.java')
| -rw-r--r-- | NET/worlds/console/FileSaver.java | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/NET/worlds/console/FileSaver.java b/NET/worlds/console/FileSaver.java new file mode 100644 index 0000000..dce997d --- /dev/null +++ b/NET/worlds/console/FileSaver.java @@ -0,0 +1,77 @@ +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<World> saveList = new Vector<World>(); + private int state; + public static final int QUIT = 0; + public static final int SAVING = 1; + public static final int CANCEL = 2; + + FileSaver() { + Enumeration<World> 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; + } + } +} |