/* */ package NET.worlds.scape; /* */ /* */ import NET.worlds.console.ConfirmDialog; /* */ import NET.worlds.console.Console; /* */ import NET.worlds.console.DialogReceiver; /* */ import NET.worlds.console.GammaFrame; /* */ import NET.worlds.console.OkCancelDialog; /* */ import NET.worlds.console.PolledDialog; /* */ import NET.worlds.core.Sort; /* */ import NET.worlds.network.URL; /* */ import java.awt.BorderLayout; /* */ import java.awt.Button; /* */ import java.awt.Checkbox; /* */ import java.awt.CheckboxGroup; /* */ import java.awt.Event; /* */ import java.awt.Font; /* */ import java.awt.GridBagConstraints; /* */ import java.awt.GridBagLayout; /* */ import java.awt.Label; /* */ import java.awt.List; /* */ import java.awt.Panel; /* */ import java.awt.Point; /* */ import java.util.Enumeration; /* */ import java.util.Hashtable; /* */ import java.util.Vector; /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ /* */ class MusicManagerDialog /* */ extends PolledDialog /* */ implements DialogReceiver /* */ { /* */ private static final long serialVersionUID = 1L; /* */ private MusicManager manager; /* 285 */ private String lastRoom = ""; /* 286 */ private Label curRoom = new Label(); /* 287 */ private Label curMusic = new Label(); /* 288 */ private Button assignCurButton = new Button( /* 289 */ Console.message("Assign-Current")); /* 290 */ private Checkbox autoAssign = new Checkbox(Console.message("Auto-assign")); /* 291 */ private CheckboxGroup group = new CheckboxGroup(); /* 292 */ private Checkbox musicBox = new Checkbox(Console.message("Music"), this.group, /* 293 */ true); /* 294 */ private Checkbox aRoomsBox = new Checkbox( /* 295 */ Console.message("Assigned-rooms"), this.group, false); /* 296 */ private Checkbox uRoomsBox = new Checkbox( /* 297 */ Console.message("Unassigned-rooms"), this.group, false); /* 298 */ private List list = new List(10); /* 299 */ private Button editButton = new Button(Console.message("Edit")); /* 300 */ private Button addButton = new Button(Console.message("Add")); /* 301 */ private Button delButton = new Button(Console.message("Delete")); /* 302 */ private Button assignButton = new Button(Console.message("Assign")); /* 303 */ private Button saveButton = new Button(Console.message("Save-Changes")); /* 304 */ private Button okButton = new Button(Console.message("OK")); /* 305 */ private Button cancelButton = new Button(Console.message("Cancel")); /* */ private PolledDialog subDialog; /* */ private Vector allRooms; /* */ private boolean madeChanges; /* */ private boolean confirmingState; /* 310 */ static Point lastWindowLocation = null; /* 311 */ private static Font font = new Font(Console.message("MenuFont"), /* 312 */ 0, 12); /* 313 */ private static Font bfont = new Font(Console.message("ButtonFont"), /* 314 */ 0, 12); /* */ /* 316 */ private static final String title = Console.message("Music-Manager"); /* */ /* */ public MusicManagerDialog(MusicManager manager) { /* 319 */ super(Console.getFrame(), manager, title + manager.getName(), false); /* 320 */ setAlignment(2); /* 321 */ this.manager = manager; /* 322 */ ready(); /* */ } /* */ /* */ public MusicManager getManager() { /* 326 */ return this.manager; /* */ } /* */ /* */ public String getCurRoom() { /* 330 */ return this.curRoom.getText(); /* */ } /* */ /* */ public Vector getAllRooms() { /* 334 */ return this.allRooms; /* */ } /* */ /* */ protected void build() { /* 338 */ GridBagLayout gbag = new GridBagLayout(); /* 339 */ setLayout(gbag); /* 340 */ GridBagConstraints c = new GridBagConstraints(); /* 341 */ Panel p = new Panel(new BorderLayout()); /* 342 */ this.musicBox.setFont(font); /* 343 */ this.aRoomsBox.setFont(font); /* 344 */ this.uRoomsBox.setFont(font); /* 345 */ p.add("West", this.musicBox); /* 346 */ p.add("Center", this.aRoomsBox); /* 347 */ p.add("East", this.uRoomsBox); /* 348 */ c.weightx = 0.0D; /* 349 */ c.gridwidth = 0; /* 350 */ add(gbag, p, c); /* 351 */ c.fill = 1; /* 352 */ c.weightx = 1.0D; /* 353 */ c.weighty = 1.0D; /* 354 */ c.gridwidth = 2; /* 355 */ c.gridheight = 6; /* 356 */ this.list.setFont(font); /* 357 */ add(gbag, this.list, c); /* 358 */ c.fill = 2; /* 359 */ c.weightx = 0.0D; /* 360 */ c.weighty = 0.0D; /* 361 */ c.gridwidth = 0; /* 362 */ c.gridheight = 1; /* 363 */ this.assignButton.setFont(bfont); /* 364 */ this.editButton.setFont(bfont); /* 365 */ this.addButton.setFont(bfont); /* 366 */ this.delButton.setFont(bfont); /* 367 */ add(gbag, this.assignButton, c); /* 368 */ add(gbag, this.editButton, c); /* 369 */ add(gbag, this.addButton, c); /* 370 */ add(gbag, this.delButton, c); /* 371 */ for (int i = 0; i < 2; i++) /* 372 */ add(gbag, new Label(""), c); /* 373 */ c.gridwidth = 1; /* 374 */ c.fill = 0; /* 375 */ Label cRoom = new Label(Console.message("Current-room")); /* 376 */ cRoom.setFont(font); /* 377 */ add(gbag, cRoom, c); /* 378 */ c.gridwidth = 0; /* 379 */ c.weightx = 1.0D; /* 380 */ c.fill = 2; /* 381 */ this.curRoom.setFont(font); /* 382 */ add(gbag, this.curRoom, c); /* 383 */ c.gridwidth = 1; /* 384 */ c.weightx = 0.0D; /* 385 */ Label aMusic = new Label(Console.message("Assigned-music")); /* 386 */ aMusic.setFont(font); /* 387 */ add(gbag, aMusic, c); /* 388 */ c.fill = 0; /* 389 */ c.gridwidth = 0; /* 390 */ c.fill = 2; /* 391 */ c.weightx = 1.0D; /* 392 */ this.curMusic.setFont(font); /* 393 */ add(gbag, this.curMusic, c); /* 394 */ c.weightx = 0.0D; /* 395 */ c.weighty = 0.0D; /* 396 */ c.gridwidth = 1; /* 397 */ c.fill = 0; /* 398 */ this.assignCurButton.setFont(bfont); /* 399 */ this.autoAssign.setFont(bfont); /* 400 */ add(gbag, this.assignCurButton, c); /* 401 */ c.gridwidth = 0; /* 402 */ add(gbag, this.autoAssign, c); /* 403 */ p = new Panel(); /* 404 */ p.setFont(bfont); /* 405 */ p.add(this.saveButton); /* 406 */ p.add(this.okButton); /* 407 */ p.add(this.cancelButton); /* 408 */ c.fill = 2; /* 409 */ add(gbag, p, c); /* 410 */ rebuildList(false); /* 411 */ buildAllRoomsList(); /* */ } /* */ /* */ protected boolean done(boolean confirmed) { /* 415 */ lastWindowLocation = getLocation(); /* 416 */ return super.done(confirmed); /* */ } /* */ /* */ protected void initialSize(int width, int height) { /* 420 */ if (lastWindowLocation == null) { /* 421 */ super.initialSize(width, height); /* */ } else { /* 423 */ setLocation(lastWindowLocation); /* 424 */ setSize(width, height); /* */ } /* */ } /* */ /* */ private void buildAllRoomsList() { /* 429 */ this.allRooms = new Vector(); /* 430 */ Pilot pilot = Pilot.getActive(); /* 431 */ if (pilot != null) { /* 432 */ World world = pilot.getWorld(); /* 433 */ if (world != null) { /* 434 */ Enumeration rooms = world.getRooms(); /* 435 */ while (rooms.hasMoreElements()) /* 436 */ this.allRooms.addElement(((Room)rooms.nextElement()).getName()); /* */ } /* */ } /* */ } /* */ /* */ private void rebuildList(boolean changed) { /* 442 */ boolean enable = !this.uRoomsBox.getState(); /* 443 */ this.assignButton.setEnabled(!this.musicBox.getState()); /* 444 */ this.editButton.setEnabled(enable); /* 445 */ this.addButton.setEnabled(enable); /* 446 */ this.delButton.setEnabled(enable); /* 447 */ this.list.removeAll(); /* 448 */ if (this.musicBox.getState()) { /* 449 */ Sort.sortInto(this.list, this.manager.getMusic()); /* 450 */ } else if (this.aRoomsBox.getState()) { /* 451 */ String[] content = Sort.sortKeys(this.manager.getRooms()); /* 452 */ for (int i = 0; i < content.length; i++) { /* 453 */ String name = content[i]; /* 454 */ this.list.add(name + " (" + this.manager.getRoom(name).getMusicName() + /* 455 */ ")"); /* */ } /* */ } else { /* 458 */ Enumeration e = this.allRooms.elements(); /* 459 */ Hashtable aRooms = this.manager.getRooms(); /* 460 */ Vector v = new Vector(); /* 461 */ while (e.hasMoreElements()) { /* 462 */ String name = (String)e.nextElement(); /* 463 */ if (!aRooms.containsKey(name)) /* 464 */ v.addElement(name); /* */ } /* 466 */ Sort.sortInto(this.list, v); /* */ } /* 468 */ if (changed) { /* 469 */ this.madeChanges = true; /* 470 */ this.manager.maybeChangedMusic(); /* */ } /* */ } /* */ /* */ protected synchronized void activeCallback() { /* 475 */ Pilot pilot = Pilot.getActive(); /* 476 */ if (pilot != null) { /* 477 */ World world = pilot.getWorld(); /* 478 */ if (world != null) /* */ { /* 480 */ if (world.getSourceURL().equals(this.manager.getWorld().getSourceURL())) { /* 481 */ Room room = pilot.getRoom(); /* 482 */ if (room != null) { /* 483 */ String name = room.getName(); /* 484 */ if (!name.equals(this.lastRoom)) { /* 485 */ this.lastRoom = name; /* 486 */ this.curRoom.setText(name); /* 487 */ MusicRoom mr = this.manager.getRoom(name); /* 488 */ if (mr != null) { /* 489 */ this.curMusic.setText(mr.getMusicName()); /* */ } else { /* 491 */ this.curMusic.setText(""); /* 492 */ if ((this.autoAssign.getState()) && (this.subDialog == null)) /* 493 */ this.subDialog = new EditRoomDialog(this, null, name); /* */ } /* */ } /* 496 */ return; /* */ } /* */ } } /* */ } /* 500 */ this.curRoom.setText(""); /* 501 */ this.curMusic.setText(""); /* */ } /* */ /* */ @Deprecated /* */ public synchronized boolean action(Event event, Object what) { /* 506 */ Object target = event.target; /* 507 */ String selected = this.list.getSelectedItem(); /* 508 */ boolean isMusic = this.musicBox.getState(); /* 509 */ boolean haveMusic = this.manager.getMusic().size() != 0; /* 510 */ if ((isMusic) && (target == this.editButton) && (selected != null)) { /* 511 */ this.subDialog = new EditMusicDialog(this, this.manager.getMusic(selected)); /* 512 */ } else if ((isMusic) && (target == this.addButton)) { /* 513 */ this.subDialog = new EditMusicDialog(this, null); /* 514 */ } else if ((isMusic) && (target == this.delButton) && (selected != null)) { /* 515 */ if (!isMusicInUse(selected)) { /* 516 */ this.manager.getMusic().remove(selected); /* 517 */ if (this.manager.getMusic().size() == 0) /* 518 */ this.autoAssign.setState(false); /* 519 */ rebuildList(true); /* */ } else { /* 521 */ cantChangeMusic(); /* 522 */ } } else if ((!isMusic) && (target == this.editButton) && (selected != null) && /* 523 */ (haveMusic)) { /* 524 */ selected = selected.substring(0, selected.lastIndexOf('(') - 1); /* 525 */ this.subDialog = new EditRoomDialog(this, this.manager.getRoom(selected), /* 526 */ selected); /* 527 */ } else if ((!isMusic) && (target == this.addButton)) { /* 528 */ if (haveMusic) { /* 529 */ this.subDialog = new EditRoomDialog(this, null, getCurRoom()); /* */ } else /* 531 */ needMusic(); /* 532 */ } else if ((!isMusic) && (target == this.delButton) && (selected != null)) { /* 533 */ selected = selected.substring(0, selected.lastIndexOf('(') - 1); /* 534 */ this.manager.getRooms().remove(selected); /* 535 */ rebuildList(true); /* 536 */ } else if (target == this.saveButton) { /* 537 */ this.manager.save(); /* 538 */ this.madeChanges = false; /* 539 */ } else if (target == this.okButton) { /* 540 */ if (this.madeChanges) { /* 541 */ this.confirmingState = true; /* 542 */ new ConfirmDialog(this, this, Console.message("Save-Changes2"), /* 543 */ Console.message("sure-save")); /* */ } else { /* 545 */ done(false); /* 546 */ } } else if (target == this.cancelButton) { /* 547 */ if (this.madeChanges) { /* 548 */ this.confirmingState = false; /* 549 */ new ConfirmDialog(this, this, /* 550 */ Console.message("Abandon-Changes"), /* 551 */ Console.message("sure-cancel")); /* */ } else { /* 553 */ done(false); /* 554 */ } } else if ((target == this.musicBox) || (target == this.aRoomsBox) || /* 555 */ (target == this.uRoomsBox)) { /* 556 */ rebuildList(false); /* 557 */ } else if (((target == this.assignButton) && (selected != null)) || /* 558 */ (target == this.assignCurButton)) { /* 559 */ if (haveMusic) { /* 560 */ String selection = target == this.assignButton ? selected : this.lastRoom; /* 561 */ this.subDialog = new EditRoomDialog(this, /* 562 */ this.manager.getRoom(selection), selection); /* */ } else { /* 564 */ needMusic(); /* 565 */ } } else if ((target == this.autoAssign) && (this.autoAssign.getState())) { /* 566 */ if (haveMusic) { /* 567 */ if (this.manager.getRoom(this.lastRoom) == null) /* 568 */ this.subDialog = new EditRoomDialog(this, null, this.lastRoom); /* */ } else { /* 570 */ this.autoAssign.setState(false); /* 571 */ needMusic(); /* */ } /* */ } else { /* 574 */ return false; } /* 575 */ return true; /* */ } /* */ /* */ @Deprecated /* */ public boolean handleEvent(Event event) { /* 580 */ if ((event.key == 1004) || (event.key == 1005) || /* 581 */ (event.key == 1006) || (event.key == 1007)) { /* 582 */ Console.getFrame().requestFocus(); /* 583 */ return true; /* */ } /* 585 */ return super.handleEvent(event); /* */ } /* */ /* */ private void needMusic() { /* 589 */ this.subDialog = new OkCancelDialog(this, this, /* 590 */ Console.message("Need-Music"), null, Console.message("OK"), /* 591 */ Console.message("at-least-one"), true); /* */ } /* */ /* */ private boolean isMusicInUse(String name) { /* 595 */ Enumeration e = this.manager.getRooms().elements(); /* 596 */ while (e.hasMoreElements()) /* 597 */ if (name.equals(((MusicRoom)e.nextElement()).getMusicName())) /* 598 */ return true; /* 599 */ return false; /* */ } /* */ /* */ private void cantChangeMusic() { /* 603 */ this.subDialog = new OkCancelDialog(this, this, /* 604 */ Console.message("Cant-Change"), null, Console.message("OK"), /* 605 */ Console.message("may-not-delete"), true); /* */ } /* */ /* */ public synchronized void dialogDone(Object who, boolean confirmed) { /* 609 */ boolean showCantChange = false; /* 610 */ if (confirmed) { /* 611 */ if ((who instanceof EditMusicDialog)) { /* 612 */ EditMusicDialog em = (EditMusicDialog)who; /* 613 */ MusicTrack music = em.getMusicTrack(); /* 614 */ String oldName = em.getOldName(); /* 615 */ if ((oldName != null) && (!oldName.equals(music.getName())) && /* 616 */ (isMusicInUse(oldName))) { /* 617 */ music.setName(oldName); /* 618 */ showCantChange = true; /* */ } /* 620 */ this.manager.getMusic().put(music.getName(), music); /* 621 */ rebuildList(true); /* 622 */ } else if ((who instanceof EditRoomDialog)) { /* 623 */ EditRoomDialog er = (EditRoomDialog)who; /* 624 */ MusicRoom room = er.getMusicRoom(); /* 625 */ this.manager.getRooms().put(room.getRoomName(), room); /* 626 */ rebuildList(true); /* 627 */ } else if ((who instanceof ConfirmDialog)) { /* 628 */ done(this.confirmingState); } /* 629 */ if (this.lastRoom != null) { /* 630 */ MusicRoom mr = this.manager.getRoom(this.lastRoom); /* 631 */ if (mr != null) /* 632 */ this.curMusic.setText(mr.getMusicName()); /* */ } /* */ } /* 635 */ this.subDialog = null; /* 636 */ if (showCantChange) { /* 637 */ cantChangeMusic(); /* */ } /* */ } /* */ } /* Location: C:\Program Files (x86)\Worlds Inc\WorldsPlayer - Win7\lib\worlds.jar!\NET\worlds\scape\MusicManagerDialog.class * Java compiler version: 6 (50.0) * JD-Core Version: 0.7.1 */