/* */ package NET.worlds.console; /* */ /* */ import NET.worlds.network.URL; /* */ import NET.worlds.scape.EditTile; /* */ import NET.worlds.scape.LibrariesTile; /* */ import NET.worlds.scape.LoadedURLSelf; /* */ import NET.worlds.scape.Manifest; /* */ import NET.worlds.scape.Pilot; /* */ import NET.worlds.scape.Saver; /* */ import NET.worlds.scape.TeleportAction; /* */ import NET.worlds.scape.URLSelf; /* */ import NET.worlds.scape.World; /* */ import java.awt.Container; /* */ import java.awt.Event; /* */ import java.awt.Menu; /* */ import java.awt.MenuItem; /* */ import java.io.IOException; /* */ import java.util.Enumeration; /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public class Shaper /* */ implements MainCallback, DialogReceiver, LoadedURLSelf /* */ { /* */ MenuItem newItem; /* */ MenuItem openItem; /* */ MenuItem saveItem; /* */ MenuItem propItem; /* */ MenuItem consolePropItem; /* */ MenuItem pilotPropItem; /* */ MenuItem undoItem; /* */ MenuItem cutItem; /* */ MenuItem copyItem; /* */ MenuItem pasteItem; /* */ MenuItem sortAttributesItem; /* */ MenuItem snapToolItem; /* */ MenuItem newLibraryItem; /* */ MenuItem newLibraryEntryItem; /* */ MenuItem iconsVisibleLibraryItem; /* */ Menu worldsMenu; /* */ MenuItem shaperVisibleItem; /* */ private World newWorldTemplate; /* */ /* */ public Shaper() /* */ { /* 76 */ Main.register(this); /* */ } /* */ /* */ /* */ /* */ public void activate(Console c, Container f, Console prev) /* */ { /* 83 */ this.newItem = c.addMenuItem(Console.message("New"), "File", 78, /* 84 */ false); /* 85 */ this.openItem = c.addMenuItem(Console.message("Open"), "File", /* 86 */ 79, false); /* 87 */ this.saveItem = c.addMenuItem(Console.message("Save"), "File", /* 88 */ 83, false); /* 89 */ this.propItem = c.addMenuItem(Console.message("World-Prop"), "File"); /* 90 */ this.consolePropItem = c /* 91 */ .addMenuItem(Console.message("Console-Prop"), "File"); /* 92 */ this.pilotPropItem = c.addMenuItem(Console.message("Pilot-Prop"), "File"); /* */ /* 94 */ this.undoItem = c.addMenuItem(Console.message("Undo"), "Edit", /* 95 */ 90, false); /* 96 */ c.getMenu("Edit").addSeparator(); /* 97 */ this.cutItem = c.addMenuItem(Console.message("Cut"), "Edit", 88, /* 98 */ false); /* 99 */ this.copyItem = c.addMenuItem(Console.message("Copy"), "Edit", /* 100 */ 67, false); /* 101 */ this.pasteItem = c.addMenuItem(Console.message("Paste"), "Edit", /* 102 */ 86, false); /* 103 */ this.sortAttributesItem = c.addMenuItem(Console.message("Sort-Attributes"), /* 104 */ "Edit"); /* 105 */ this.snapToolItem = c.addMenuItem(Console.message("Snap-Tool-Settings"), /* 106 */ "Edit"); /* */ /* */ /* 109 */ this.newLibraryItem = c.addMenuItem(Console.message("New-Library"), /* 110 */ "Libraries"); /* 111 */ this.newLibraryEntryItem = c.addMenuItem( /* 112 */ Console.message("New-Library-Entry"), "Libraries"); /* 113 */ this.iconsVisibleLibraryItem = c.addMenuItem( /* 114 */ Console.message("Icons-On-Off"), "Libraries", 73, /* 115 */ false); /* */ /* 117 */ this.worldsMenu = c.getMenu("Worlds"); /* 118 */ worldListChange(); /* */ /* 120 */ this.shaperVisibleItem = c.addMenuItem(Console.message("Shaper-On-Off"), /* 121 */ "Options"); /* */ } /* */ /* */ /* */ /* */ public void deactivate() /* */ { /* 128 */ this.worldsMenu = null; /* */ } /* */ /* */ /* */ /* */ /* */ public boolean action(Event event, Object what) /* */ { /* 136 */ GammaFrame f = Console.getFrame(); /* */ /* 138 */ if (event.target == this.newItem) { /* 139 */ this.makeNew = true; /* 140 */ } else if (event.target == this.openItem) { /* 141 */ new FileSysDialog(f, this, Console.message("Open-World"), /* 142 */ 0, "World Save Files|*.world|World Class Files|*.class|World Files|*.class;*.world", /* */ /* 144 */ "", true); /* 145 */ } else if (event.target == this.saveItem) { /* 146 */ new FileSysDialog(f, this, Console.message("Save-World"), /* 147 */ 1, "World Save Files|*.world|World Manifest (text) Files|*.mft", /* */ /* 149 */ getSaveName(), true); /* 150 */ } else if (event.target == this.propItem) { /* 151 */ if (Pilot.getActiveRoom() != null) /* 152 */ f.getEditTile().viewProperties(Pilot.getActiveWorld()); /* 153 */ } else if (event.target == this.consolePropItem) { /* 154 */ f.getEditTile().viewProperties(Console.getActive()); /* 155 */ } else if (event.target == this.pilotPropItem) { /* 156 */ f.getEditTile().viewProperties(Pilot.getActive()); /* 157 */ } else if (event.target == this.sortAttributesItem) { /* 158 */ new AttributeSortPanel(f); /* 159 */ } else if (event.target == this.snapToolItem) { /* 160 */ new SnapToolPanel(f); /* 161 */ } else if (event.target == this.undoItem) { /* 162 */ f.getEditTile().undo(); /* 163 */ } else if (event.target == this.cutItem) { /* 164 */ f.getEditTile().cut(); /* 165 */ } else if (event.target == this.copyItem) { /* 166 */ f.getEditTile().copy(); /* 167 */ } else if (event.target == this.pasteItem) { /* 168 */ f.getEditTile().paste(); /* */ /* */ /* */ /* */ /* */ /* */ /* */ } /* 176 */ else if (event.target == this.newLibraryItem) { /* 177 */ f.getLibrariesTile().addLibrary(); /* 178 */ } else if (event.target == this.newLibraryEntryItem) { /* 179 */ f.getLibrariesTile().addElement(); /* 180 */ } else if (event.target == this.iconsVisibleLibraryItem) { /* 181 */ f.getLibrariesTile().setIconsVisible( /* 182 */ !f.getLibrariesTile().isIconsVisible()); /* 183 */ } else if (event.target == this.shaperVisibleItem) { /* 184 */ f.setShaperVisible(!f.isShaperVisible()); /* */ /* */ } /* */ else /* */ { /* 189 */ int i = this.worldsMenu.getItemCount(); /* 190 */ do { if (this.worldsMenu.getItem(i) == event.target) { /* */ break; /* */ } /* 189 */ i--; } while (i >= 0); /* */ /* */ /* */ /* 193 */ if (i < 0) { /* 194 */ return false; /* */ } /* 196 */ String url = (String)what; /* 197 */ if (url.endsWith(" (changed)")) /* 198 */ url = url.substring(0, url.length() - 10); /* 199 */ TeleportAction.teleport(url, null); /* */ } /* */ /* 202 */ return true; /* */ } /* */ /* */ public String getSaveName() { /* 206 */ return getSaveName(Pilot.getActive().getWorld()); /* */ } /* */ /* */ public static String getSaveName(World w) { /* 210 */ URL url = w.getSourceURL(); /* 211 */ String name = url.unalias(); /* */ /* 213 */ int index = name.indexOf(':'); /* 214 */ if ((index == -1) || (index == 1)) { /* 215 */ return name.replace('/', '\\'); /* */ } /* 217 */ return url.getBase(); /* */ } /* */ /* */ public void dialogDone(Object who, boolean confirmed) { /* 221 */ if (confirmed) { /* 222 */ FileSysDialog fileDialog = (FileSysDialog)who; /* 223 */ String name = fileDialog.fileName(); /* 224 */ if (fileDialog.getMode() == 0) { /* 225 */ TeleportAction.teleport(name, null, true); /* */ } else { /* 227 */ doSave(name); /* */ } /* */ } /* */ } /* */ /* */ /* */ public void loadedURLSelf(URLSelf o, URL url, String err) /* */ { /* 235 */ this.newWorldTemplate = ((World)o); /* */ } /* */ /* */ /* */ /* */ /* 241 */ private boolean makeNew = true; /* */ /* 243 */ private static URL newworld = URL.make("home:NewWorld.world"); /* */ private boolean quitFlag; /* */ private FileSaver fileSaver; /* */ /* */ public void mainCallback() /* */ { /* 249 */ if (this.quitFlag) { /* 250 */ if (this.fileSaver == null) /* 251 */ this.fileSaver = new FileSaver(); /* 252 */ switch (this.fileSaver.getState()) { /* */ case 0: /* 254 */ GammaFrameState.saveBorder(); /* 255 */ Main.end(); /* 256 */ break; /* */ case 2: /* 258 */ this.quitFlag = false; /* 259 */ this.fileSaver = null; /* */ } /* */ /* */ } /* */ /* */ /* 265 */ if (this.newWorldTemplate != null) { /* 266 */ this.newWorldTemplate.incRef(); /* */ } /* 268 */ if (this.makeNew) { /* 269 */ this.makeNew = false; /* */ /* */ /* */ /* 273 */ if (this.newWorldTemplate == null) { /* 274 */ World.load(newworld, this, true); /* */ } else { /* 276 */ World w = (World)this.newWorldTemplate.clone(); /* 277 */ w.setEdited(true); /* 278 */ TeleportAction.teleport(w.getSourceURL().getAbsolute(), null); /* */ } /* */ } /* */ /* 282 */ if (this.worldListHasChanged) { /* 283 */ this.worldListHasChanged = false; /* */ /* 285 */ rebuildWorldsMenu(); /* */ } /* */ } /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public void maybeQuit() /* */ { /* 300 */ this.quitFlag = true; /* */ } /* */ /* 303 */ private boolean worldListHasChanged = false; /* */ /* */ /* */ /* */ /* */ public void worldListChange() /* */ { /* 310 */ this.worldListHasChanged = true; /* */ } /* */ /* */ /* */ /* */ /* */ /* */ private void rebuildWorldsMenu() /* */ { /* 319 */ if (this.worldsMenu == null) { /* 320 */ return; /* */ } /* */ /* 323 */ while (this.worldsMenu.getItemCount() > 0) { /* 324 */ this.worldsMenu.remove(0); /* */ } /* */ /* 327 */ for (Enumeration e = World.getWorlds(); e.hasMoreElements();) { /* 328 */ World w = (World)e.nextElement(); /* 329 */ URL url = w.getSourceURL(); /* */ String name; /* */ String name; /* 332 */ if (url == null) { /* 333 */ name = w.getName(); /* */ } else { /* 335 */ name = url.getAbsolute(); /* */ /* 337 */ if (url.equals(newworld)) { /* */ continue; /* */ } /* */ } /* 341 */ if (w.getEdited()) /* 342 */ name = name + " (changed)"; /* 343 */ this.worldsMenu.add(new MenuItem(name)); /* */ } /* */ } /* */ /* */ public void doSave(String name) { /* 348 */ doSave(name, Pilot.getActive().getWorld(), true); /* */ } /* */ /* */ public static boolean doSave(String name, World world, boolean allowManifest) { /* 352 */ if ((allowManifest) && (name.endsWith(".mft"))) /* */ { /* */ try { /* 355 */ Manifest mft = new Manifest(name); /* 356 */ mft.saveProps(world); /* 357 */ mft.done(); /* 358 */ return true; /* */ } catch (IOException ioe) { /* 360 */ Console.println( /* 361 */ Console.message("Error-manifest") + ioe.toString()); /* */ } /* */ } /* */ else { /* 365 */ if (name.toLowerCase().endsWith(".wor")) { /* 366 */ name = name.substring(0, name.length() - 4); /* */ } /* 368 */ if (!name.toLowerCase().endsWith(".world")) { /* 369 */ name = name + ".world"; /* */ } /* */ try { /* 372 */ Saver saver = new Saver(new URL(URL.getCurDir(), name)); /* 373 */ saver.save(world); /* 374 */ saver.done(); /* 375 */ world.setEdited(false); /* 376 */ return true; /* */ } catch (IOException ioe) { /* 378 */ Console.println( /* 379 */ Console.message("Error-saving") + ioe.toString()); /* */ } /* */ } /* 382 */ return false; /* */ } /* */ } /* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\console\Shaper.class * Java compiler version: 6 (50.0) * JD-Core Version: 0.7.1 */