/* */ package NET.worlds.scape; /* */ /* */ import NET.worlds.console.Console; /* */ import NET.worlds.console.Cursor; /* */ import NET.worlds.console.GammaFrame; /* */ import NET.worlds.console.Main; /* */ import NET.worlds.console.MainCallback; /* */ import NET.worlds.core.IniFile; /* */ import NET.worlds.network.URL; /* */ import java.awt.Color; /* */ import java.awt.Component; /* */ import java.awt.Point; /* */ import java.io.File; /* */ import java.util.Enumeration; /* */ import java.util.Vector; /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ public class LibrariesTile /* */ extends TabbedPanel /* */ implements LibEventHandler, Properties, MainCallback, LibraryDropTarget /* */ { /* */ private static final long serialVersionUID = 1L; /* */ private static final int NOTHING = 0; /* */ private static final int ADD_LIBRARY = 1; /* */ private static final int ADD_ELEMENT = 2; /* */ private static URL libURL; /* */ private static String libSubdir; /* */ /* */ static /* */ { /* 58 */ libURL = URL.make("home:libraries/"); /* */ /* */ /* */ /* */ /* 63 */ String s = libURL.unalias(); /* 64 */ libSubdir = s.substring(0, s.length() - 1); /* */ } /* */ /* */ /* 68 */ public static String getLibSubdir() { return libSubdir; } /* */ /* 70 */ private Vector libraries = new Vector(); /* 71 */ private int queue = 0; /* */ /* 73 */ private boolean iconsVisible = false; /* */ private Cursor dragCursor; /* */ private Cursor cantCursor; /* */ private LibraryEntry leftClickedOn; /* */ /* 78 */ public LibrariesTile() { setBackground(Color.lightGray); /* */ /* */ /* 81 */ Vector libNames = new FileList(libSubdir, "library").getList(); /* */ /* */ /* 84 */ Enumeration e = libNames.elements(); /* 85 */ while (e.hasMoreElements()) { /* 86 */ Library lib = Library.load( /* 87 */ URL.make(libURL, (String)e.nextElement())); /* 88 */ if (lib != null) /* 89 */ addLibrary(lib); /* */ } /* 91 */ if (this.libraries.size() != 0) /* 92 */ select(0); /* 93 */ Main.register(this); /* */ } /* */ /* */ public synchronized void addLibrary() /* */ { /* 98 */ if (this.queue == 0) { /* 99 */ this.queue = 1; /* */ } /* */ } /* */ /* */ public synchronized void addElement() { /* 104 */ if (this.queue == 0) { /* 105 */ this.queue = 2; /* */ } /* */ } /* */ /* */ public synchronized void mainCallback() { /* 110 */ switch (this.queue) { /* */ case 1: /* 112 */ syncAddLibrary(new Library()); /* 113 */ break; /* */ case 2: /* 115 */ syncAddElement(new LibraryEntry()); /* */ } /* */ /* 118 */ this.queue = 0; /* */ } /* */ /* */ /* */ private boolean isUniqueLibraryURL(URL name) /* */ { /* 124 */ if (name != null) { /* 125 */ Enumeration e = this.libraries.elements(); /* 126 */ while (e.hasMoreElements()) { /* 127 */ Library lib = (Library)e.nextElement(); /* 128 */ if (lib.getSourceURL().equals(name)) /* 129 */ return false; /* */ } /* 131 */ return true; /* */ } /* 133 */ return false; /* */ } /* */ /* */ private boolean isUniqueLibraryName(String name) /* */ { /* 138 */ if (name != null) { /* 139 */ Enumeration e = this.libraries.elements(); /* 140 */ while (e.hasMoreElements()) { /* 141 */ Library lib = (Library)e.nextElement(); /* 142 */ if (lib.getName().equals(name)) /* 143 */ return false; /* */ } /* 145 */ return true; /* */ } /* 147 */ return false; /* */ } /* */ /* */ private void syncAddLibrary(Library lib) /* */ { /* 152 */ boolean newEntry = lib.getNameMaybeNull() == null; /* */ /* */ /* 155 */ if (!isUniqueLibraryURL(lib.getSourceURL())) /* */ { /* 157 */ int i = 1; /* */ URL url; /* 159 */ do { url = URL.make(libURL, "lib" + i++ + ".library"); /* 160 */ } while (!isUniqueLibraryURL(url)); /* 161 */ lib.setSourceURL(url); /* */ } /* */ /* */ /* 165 */ if (this.libraries.size() == 0) { /* 166 */ File f = new File(libSubdir); /* 167 */ f.mkdir(); /* */ } /* */ /* */ /* 171 */ if (!isUniqueLibraryName(lib.getNameMaybeNull())) /* */ { /* 173 */ int num = 1; /* */ String libName; /* 175 */ do { libName = "Category" + num++; /* 176 */ } while (!isUniqueLibraryName(libName)); /* 177 */ lib.setName(libName); /* */ } /* 179 */ if (saveAllowed()) { /* 180 */ lib.save(); /* */ } else /* 182 */ Console.println(Console.message("AllowChangeLibrary")); /* 183 */ addLibrary(lib); /* */ /* 185 */ if (newEntry) { /* 186 */ select(this.libraries.indexOf(lib)); /* */ } /* */ } /* */ /* */ private void syncDeleteLibrary(Library lib) { /* 191 */ if (saveAllowed()) { /* 192 */ lib.delete(); /* */ } else /* 194 */ Console.println(Console.message("AllowChangeLibrary")); /* 195 */ int index = this.libraries.indexOf(lib); /* 196 */ this.libraries.removeElementAt(index); /* 197 */ removeItem(index); /* */ } /* */ /* */ private void syncAddElement(LibraryEntry ent) /* */ { /* 202 */ if (this.libraries.size() != 0) { /* 203 */ int selected = selected(); /* 204 */ Library lib = (Library)this.libraries.elementAt(selected); /* 205 */ lib.add(ent); /* */ } /* */ } /* */ /* */ private void addLibrary(Library lib) /* */ { /* 211 */ int count = this.libraries.size(); /* 212 */ String name = lib.getName(); /* */ /* 214 */ for (int i = 0; i < count; i++) { /* 215 */ if (name.compareTo(((Library)this.libraries.elementAt(i)).getName()) < 0) /* */ break; /* */ } /* 218 */ this.libraries.insertElementAt(lib, i); /* 219 */ insertItem(i, lib.getName(), /* 220 */ new ScrollingImagePanel(this, lib.getContents(), /* 221 */ this.iconsVisible)); /* 222 */ lib.setEventHandler(this); /* 223 */ lib.setOwningDialog(this); /* */ } /* */ /* 226 */ public boolean isIconsVisible() { return this.iconsVisible; } /* */ /* */ public void setIconsVisible(boolean showIcons) { /* 229 */ this.iconsVisible = showIcons; /* 230 */ int count = this.libraries.size(); /* */ /* 232 */ for (int i = 0; i < count; i++) { /* 233 */ ScrollingImagePanel c = (ScrollingImagePanel)getComponent(i); /* 234 */ c.setIconsVisible(showIcons); /* */ } /* */ } /* */ /* */ public void libraryChanged(Library lib) /* */ { /* 240 */ Library selected = (Library)this.libraries.elementAt(selected()); /* 241 */ int index = this.libraries.indexOf(lib); /* 242 */ this.libraries.removeElementAt(index); /* 243 */ removeItem(index); /* 244 */ addLibrary(lib); /* 245 */ select(this.libraries.indexOf(selected)); /* 246 */ if (saveAllowed()) { /* 247 */ lib.save(); /* */ } else { /* 249 */ Console.println(Console.message("AllowChangeLibrary")); /* */ } /* */ } /* */ /* */ private boolean saveAllowed() { /* 254 */ return IniFile.gamma().getIniInt("AllowChangeLibrary", 0) == 1; /* */ } /* */ /* */ private Library getLibrary(ScrollingImagePanel panel) /* */ { /* 259 */ int count = this.libraries.size(); /* 260 */ for (int i = 0; i < count; i++) /* 261 */ if (getComponent(i) == panel) /* 262 */ return (Library)this.libraries.elementAt(i); /* 263 */ return null; /* */ } /* */ /* */ private LibraryEntry getLibraryEntry(Component comp, Point location) /* */ { /* 268 */ if ((comp instanceof ScrollingImagePanel)) { /* 269 */ ScrollingImagePanel panel = (ScrollingImagePanel)comp; /* 270 */ Library lib = getLibrary(panel); /* 271 */ if (lib != null) { /* 272 */ int item = panel.itemAt(location); /* 273 */ if (item >= 0) /* 274 */ return lib.getEntry(item); /* */ } /* */ } /* 277 */ return null; /* */ } /* */ /* */ /* */ private boolean maybeMoveEntry(LibraryEntry src, Component comp, Point loc) /* */ { /* 283 */ LibraryEntry dst = getLibraryEntry(comp, loc); /* 284 */ if ((dst != null) && (dst != src)) { /* 285 */ Library srcOwner = (Library)src.getOwner(); /* 286 */ Library dstOwner = (Library)dst.getOwner(); /* 287 */ assert (srcOwner == dstOwner); /* 288 */ srcOwner.move(src, dst); /* 289 */ return true; /* */ } /* 291 */ if (comp == this) { /* 292 */ Library newLib = (Library)this.libraries.elementAt(itemAt(loc)); /* 293 */ Library oldLib = (Library)src.getOwner(); /* 294 */ if (newLib != oldLib) { /* 295 */ oldLib.delete(src); /* 296 */ newLib.add(src); /* 297 */ return true; /* */ } /* */ } /* 300 */ return false; /* */ } /* */ /* */ /* */ /* */ /* */ /* */ public void clickEvent(Component who, Point location, int flags) /* */ { /* 309 */ if ((flags & 0x1) != 0) /* */ { /* 311 */ if (((flags & 0x4) != 0) && (who == this)) { /* 312 */ Console.getFrame().getEditTile().viewProperties( /* 313 */ this.libraries.elementAt(itemAt(location))); } else { LibraryEntry ent; /* 314 */ if ((ent = getLibraryEntry(who, location)) != null) { /* 315 */ this.leftClickedOn = null; /* 316 */ if (ent != null) { /* 317 */ if ((flags & 0x4) != 0) { /* 318 */ Console.getFrame().getEditTile().viewProperties(ent); /* */ } else { /* 320 */ this.leftClickedOn = ent; /* 321 */ Console console = Console.getActive(); /* 322 */ if (this.dragCursor == null) { /* 323 */ this.dragCursor = new Cursor( /* 324 */ URL.make("home:drag.cur")); /* */ } else { /* 326 */ this.dragCursor.detach(); /* 327 */ console.addCursor(this.dragCursor); /* 328 */ this.dragCursor.activate(); /* */ } /* */ } /* */ } /* */ } /* */ } /* 334 */ } else if ((flags & 0x2) != 0) { /* 335 */ Cursor active = Cursor.getActive(); /* 336 */ if ((active != null) && ((active == this.dragCursor) || /* 337 */ (active == this.cantCursor))) /* 338 */ Console.getActive().getCursor().activate(); /* 339 */ if (this.leftClickedOn != null) { /* 340 */ if (!maybeMoveEntry(this.leftClickedOn, who, location)) { /* 341 */ URL url = this.leftClickedOn.getContentURL(); /* 342 */ String propName = this.leftClickedOn.getPropertyName(true); /* 343 */ if (url != null) /* 344 */ Console.getFrame().getEditTile().libraryDrop( /* 345 */ url, propName, who, location); /* */ } /* 347 */ this.leftClickedOn = null; /* */ } /* */ } /* */ else { /* 351 */ Cursor active = Cursor.getActive(); /* 352 */ boolean isDropTarget = who instanceof LibraryDropTarget; /* 353 */ if (active == this.dragCursor) { /* 354 */ if (!isDropTarget) { /* 355 */ Console console = Console.getActive(); /* 356 */ if (this.cantCursor == null) { /* 357 */ this.cantCursor = new Cursor( /* 358 */ URL.make("system:CANNOT_CURSOR")); /* */ } else { /* 360 */ this.cantCursor.detach(); /* 361 */ console.addCursor(this.cantCursor); /* 362 */ this.cantCursor.activate(); /* */ } /* 364 */ this.cantCursor.activate(); /* */ } /* 366 */ } else if ((active != null) && (active == this.cantCursor) && /* 367 */ (isDropTarget)) { /* 368 */ this.dragCursor.activate(); /* */ } /* */ } /* */ } /* */ /* */ public Object properties(int index, int offset, int mode, Object value) /* */ throws NoSuchPropertyException /* */ { /* 376 */ Object ret = null; /* 377 */ switch (index - offset) { /* */ case 0: /* 379 */ if (mode == 0) { /* 380 */ ret = PropAdder.make( /* 381 */ new VectorProperty(this, index, "Contents")); /* 382 */ } else if (mode == 1) { /* 383 */ ret = this.libraries; /* 384 */ } else if (mode == 3) { /* 385 */ syncAddLibrary((Library)value); /* 386 */ } else if (mode == 4) { /* 387 */ syncDeleteLibrary((Library)value); /* 388 */ } else if ((mode == 5) && ((value instanceof Library))) /* 389 */ ret = value; /* 390 */ break; /* */ default: /* 392 */ throw new NoSuchPropertyException(); /* */ } /* 394 */ return ret; /* */ } /* */ /* 397 */ public Object propertyParent() { return null; } /* */ /* 399 */ public String toString() { return "Libraries"; } /* */ } /* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\LibrariesTile.class * Java compiler version: 6 (50.0) * JD-Core Version: 0.7.1 */