package NET.worlds.scape; import NET.worlds.console.Console; import NET.worlds.console.PolledDialog; import NET.worlds.core.Sort; import java.awt.Button; import java.awt.Choice; import java.awt.Font; import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Label; import java.awt.Panel; import java.util.Enumeration; import java.util.Hashtable; import java.util.Vector; class EditRoomDialog extends PolledDialog { private Choice roomChoice = new Choice(); private Choice musicChoice = new Choice(); private Button okButton = new Button(Console.message("OK")); private Button cancelButton = new Button(Console.message("Cancel")); private MusicManagerDialog parent; private MusicRoom room; private String startSelect; private static String lastMusic; private static Font font = new Font(Console.message("MenuFont"), 0, 12); private static Font bfont = new Font(Console.message("ButtonFont"), 0, 12); public EditRoomDialog(MusicManagerDialog parent, MusicRoom room, String startSelect) { super(parent, parent, Console.message("Assign-Music"), true); this.parent = parent; this.room = room; this.startSelect = startSelect; this.ready(); } @Override protected void build() { GridBagLayout gbag = new GridBagLayout(); this.setLayout(gbag); GridBagConstraints c = new GridBagConstraints(); c.fill = 0; c.anchor = 13; Label lName = new Label(Console.message("Room-name"), 2); lName.setFont(font); this.add(gbag, lName, c); c.gridwidth = 0; c.anchor = 17; this.roomChoice.setFont(font); this.add(gbag, this.roomChoice, c); c.gridwidth = 1; c.anchor = 13; Label lMusic = new Label(Console.message("Music"), 2); lMusic.setFont(font); this.add(gbag, lMusic, c); c.gridwidth = 0; c.anchor = 17; this.musicChoice.setFont(font); this.add(gbag, this.musicChoice, c); c.anchor = 10; Panel p = new Panel(); p.setFont(bfont); p.add(this.okButton); p.add(this.cancelButton); this.add(gbag, p, c); this.roomChoice.setFont(font); this.musicChoice.setFont(font); if (this.room != null) { this.roomChoice.add(this.room.getRoomName()); } Enumeration e = this.parent.getAllRooms().elements(); Hashtable roomsWithMusic = this.parent.getManager().getRooms(); Vector v = new Vector(); while (e.hasMoreElements()) { String name = (String)e.nextElement(); if (!roomsWithMusic.containsKey(name)) { v.addElement(name); } } Sort.sortInto(this.roomChoice, v); Sort.sortInto(this.musicChoice, this.parent.getManager().getMusic()); if (this.room != null) { this.roomChoice.select(this.room.getRoomName()); this.musicChoice.select(this.room.getMusicName()); } else { this.roomChoice.select(this.startSelect); if (lastMusic != null) { this.musicChoice.select(lastMusic); } } } @Override public boolean action(java.awt.Event event, Object what) { Object target = event.target; if (target == this.okButton) { return this.done(true); } else { return target == this.cancelButton ? this.done(false) : false; } } public boolean isEditor() { return this.room != null; } public MusicRoom getMusicRoom() { String roomName = this.roomChoice.getSelectedItem(); String musicName = this.musicChoice.getSelectedItem(); lastMusic = musicName; if (this.room == null) { return new MusicRoom(roomName, musicName); } else { this.room.setRoomName(roomName); this.room.setMusicName(musicName); return this.room; } } }