📄 servergamecontainer.java
字号:
package ergo.ui;
// $Id: ServerGameContainer.java,v 1.3 1999/08/13 01:20:10 sigue Exp $
/*
* Copyright (C) 1999 Carl L. Gay and Antranig M. Basman.
* See the file copyright.txt, distributed with this software,
* for further information.
*/
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.util.Enumeration;
import java.util.Hashtable;
import ergo.*;
import ergo.server.*;
import ergo.util.Debug;
import ergo.util.ParseException;
/**
* Implements the Games View window.
*
* @see ServerPlayerContainer
* @version $Revision: 1.3 $ - $Date: 1999/08/13 01:20:10 $
*/
public class ServerGameContainer
implements MultiCallBackable, MultiWindowBackable, Optionizable {
public static final int SORT_NUM = 0;
public static final int SORT_RANK = 1;
public static final int SORT_MOVE = 2;
private static final String[] sortMethods = { "by Number", "by Rank", "by Move" };
private Hashtable serverGames = new Hashtable(); // hashtable lookup by bi-name....
private boolean filled = false;
private Controller control;
private ServerConnection conn;
private GoClient client;
private MultiBox mb;
private MultiWindow sgcw;
private urMenuBar menuBar = new urMenuBar(null);
private menuListener mListen = new menuListener();
// Menu items to be attached to MultiWindow
private Menu viewMenu = menuBar.generate("View");
private MenuItem refreshItem
= mListen.generate(viewMenu, "Refresh", new MenuShortcut(KeyEvent.VK_R));
private MenuItem refreshaItem
= mListen.generateWithSep(viewMenu, "Refresh All",
new MenuShortcut(KeyEvent.VK_R, true));
private MenuItem closeItem
= mListen.generate(viewMenu, "Close", new MenuShortcut(KeyEvent.VK_W));
private MenuItem obsItem
= new MenuItem("Observe", new MenuShortcut(KeyEvent.VK_O));
private MenuItem unobsItem
= new MenuItem("Unobserve", new MenuShortcut(KeyEvent.VK_U));
private MenuItem allItem = new MenuItem("Show Observers");
// The title "Options" is pretty vague but sufficiently general. On some platforms
// (notably Linux) there must be a menu title or the menu looks odd.
private PopupMenu obspm = new PopupMenu("Options");
private String sgcvisibleString = "Games View Lines";
private String sgcposString = "Games View Position";
public String sgcsortString = "Games View Sort";
private Optionizer opser = Ergo.opser;
public ServerGameContainer(Controller cn1, ServerConnection conn, GoClient client) {
control = cn1;
this.conn = conn;
this.client = client;
String b = "";
String l = "l";
String[] formatw = {l,l,l,l,l,l,l,l,l,l,l,l};
String[] headingsw = {"Game", "White Name", "W Rank", "Black Name", "B Rank",
"Move", "Size", "Hc", "Komi", "Byo", "FR", "Obs"};
String[] widtherw = {"99.", "WWWWWWWWWW", "99k*", "WWWWWWWWWW", "99k*",
"999", "19", "9", "-0.5", "99", "T", "99"};
opser.expressOwnership(sgcvisibleString, Optionizer.TYPE_INTEGER, null,
new Integer(10));
opser.expressOwnership(sgcsortString, Optionizer.TYPE_INTEGER, null,
new Integer(SORT_NUM));
opser.expressOwnership(opser.savingString, Optionizer.TYPE_BOOLEAN, this,
new Boolean(true)); // listen for saving event.
TextColorManager.expressAll(this, 4);
opser.expressOwnership(GlobalOptions.infofontString, Optionizer.TYPE_FONT, this,
null);
int sortMethod = opser.getIntegerOption(sgcsortString);
try {
mb = new MultiBox(this, formatw, widtherw, headingsw,
opser.getIntegerOption(sgcvisibleString), sortMethod) ;
}
catch (Exception e) {
Debug.backtrace(e);
}
sgcw = new MultiWindow(this, mb, sortMethod);
Object o = new PositionListener(sgcposString, sgcw, new Point(100,500), opser);
TerminalWindow.registrar.registerWindowsMenuCommand(sgcw);
mb.setColorVec(TextColorManager.getColorVec());
mb.setFont(opser.getFontOption(GlobalOptions.infofontString));
mb.add(obspm); // multibox, not menubar
MenuBar mbear = new MenuBar();
mbear.add(viewMenu);
mbear.add(sgcw.getSortMenu());
mbear.add(TerminalWindow.registrar.registerMenu(new Menu("Window"), sgcw));
sgcw.setMenuBar(mbear);
}
public void winDestroyed() { // just sent away.
filled = false;
// control.window.registrar.deregisterWindowsMenuCommand(sgcw);
}
public String[] sortMethods() { return sortMethods; }
public int defaultSortMethod() { return SORT_NUM; }
public String windowName() { return conn.toString()+" - Games View"; }
public String menuString() { return "Games View"; }
public MenuShortcut menuShortcut () {
return new MenuShortcut(KeyEvent.VK_G);
}
public int menuPriority() { return 101; }
public void menuSelect(Frame f) {
// Always show the window immediately. It would be really nice to
// add some sort of "busy" animation until filled == true, but a
// simple fix might be to display a "Getting games list from server"
// in the window until the games info is ready. -sigue
sgcw.setVisible(true);
sgcw.toFront();
if (filled == false) {
filled = true;
conn.send("games", false);
}
}
/** @see WindowsMenuCommand */
public Class appliesTo () { return null; }
public void optionEvent(String arg, Object value) {
if (opser.isSameKey(opser.savingString, arg)) {
opser.updateOption(sgcvisibleString, new Integer(mb.visLines()));
}
else if (TextColorManager.isColorString(arg)) {
mb.setColorVec(TextColorManager.getColorVec());
}
else if (opser.isSameKey(arg, GlobalOptions.infofontString)) {
mb.setFont(opser.getFontOption(GlobalOptions.infofontString));
sgcw.pack(); // interesting attempt.
}
}
ServerGame stashedUseful; // store this between invocations of eventOn and actionOn.
public int eventOn(Object theUseful, MouseEvent e, int field) {
ServerGame sg = (ServerGame)theUseful;
if (e.getID() == MouseEvent.MOUSE_PRESSED) {
if (e.isMetaDown()) {
obspm.removeAll();
if (sg.gw == null) obspm.add(obsItem);
else obspm.add(unobsItem);
obspm.add(allItem);
obspm.show(mb.listCanvas, e.getX(), e.getY());
} // end if metadown
else
if (e.getClickCount() == 2) {
if (sg.gw == null)
conn.send("observe " + stashedUseful.num, false);
else
sg.gw.menuSelect(null);
} // end if not metadown
} // end if mousedown.
stashedUseful = sg;
// System.out.println("Event "+e+" received on player "+sp+", field "+field);
return 0;
}
class menuListener extends urMenuListener {
public void itemSelected(MenuItem source) {
if (source == refreshItem) {
conn.send("games", false); // this should make use of stashed parameters.
}
else if (source == refreshaItem) {
conn.send("games", false);
}
else if (source == closeItem) {
// may the Lord forgive me for my sins.
sgcw.destroyed();
}
}
}
public boolean actionOn(Event e, Object arg) {
if (e.target == obsItem) {
conn.send("observe " + stashedUseful.num, false);
}
else if (e.target == unobsItem) {
conn.send("unobserve " + stashedUseful.num, false);
}
else if (e.target == allItem) {
conn.send("all " + stashedUseful.num, false);
}
return true;
}
public Enumeration Games() {
return serverGames.elements();
}
public ServerGame nextGame(Enumeration e) {
return (ServerGame)e.nextElement();
}
private ServerGame tsg = new ServerGame(); // removed "static" -sigue 99-01-04
// called when a new GameWindow is constructed.
public void inform(GameWindow gw) {
ServerGame sg = byNames(gw.game.whiteName, gw.game.blackName);
// We cannot avoid having sg, since we cannot create a GameWindow without
// issuing the "games" command for the game in question.....
if (sg == null) return; // fail silently
sg.gw = gw;
updateGame(sg, false);
}
// called when a GameWindow is destroyed, or a game ends.
public void uninform(GameWindow gw) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -