📄 gamewindow.java
字号:
backKibButton = makeImageButton("backkib.gif");
fwdBranchButton = makeImageButton("fwdbranch.gif");
backBranchButton = makeImageButton("backbranch.gif");
addComponentListener(new SizeListener());
sizeString = bsizeString + " " + game.size() + "x" + game.size();
try {
opser.expressOwnership(gwinTermOutString, Optionizer.TYPE_BOOLEAN, null, F);
opser.expressOwnership(savePromptString, Optionizer.TYPE_BOOLEAN, null, F);
opser.expressOwnership(NcoordString, Optionizer.TYPE_BOOLEAN, null, T);
opser.expressOwnership(WcoordString, Optionizer.TYPE_BOOLEAN, null, T);
opser.expressOwnership(EcoordString, Optionizer.TYPE_BOOLEAN, null, T);
opser.expressOwnership(ScoordString, Optionizer.TYPE_BOOLEAN, null, T);
opser.expressOwnership(variationString, Optionizer.TYPE_BOOLEAN, null, T);
opser.expressOwnership(kibitzString, Optionizer.TYPE_BOOLEAN,
this, T); // listen for this.
opser.expressOwnership(statusString, Optionizer.TYPE_STRING,
this, null); // listen for this.
opser.expressOwnership(getSizeString(), Optionizer.TYPE_SIZE,
null, new Dimension(550,550)); // don't listen!!
opser.expressOwnership(GlobalOptions.textfontString, Optionizer.TYPE_FONT,
this, null);
opser.expressOwnership(GlobalOptions.gwinColorString,
Optionizer.TYPE_COLOR, this, new ColorSpec("255 255 255"));
opser.expressOwnership(GlobalOptions.stoneString,
Optionizer.TYPE_INTEGER, this, new Integer(Styles.STONE_3D));
opser.expressOwnership(GlobalOptions.boardStyleString,
Optionizer.TYPE_INTEGER, this, new Integer(Styles.BOARD_WOOD));
setBackground(opser.getColorOption(GlobalOptions.gwinColorString));
} catch (Exception e) {}
try {
String statusStatus = (String) opser.getOption(statusString);
if (statusStatus == null)
statusStatus = "Right";
if (statusStatus.equalsIgnoreCase("None"))
statusGroup.init(showStatusNoneItem);
else if (statusStatus.equalsIgnoreCase("Right")) {
statusGroup.init(showStatusRightItem);
tallConfiguration = false;
}
else if (statusStatus.equalsIgnoreCase("Bottom")) {
statusGroup.init(showStatusBottomItem);
tallConfiguration = true;
}
}
catch (ErgoException fart) {
Debug.backtrace(fart);
}
kibitzGroup.init(kibitzAllItem);
stonesGroup.init(stonesItems[opser.getIntegerOption(GlobalOptions.stoneString)]);
boardGroup.init(boardItems[opser.getIntegerOption(GlobalOptions.boardStyleString)]);
TextColorManager.expressAll(this, 2);
kibitzArea.setColorVec(TextColorManager.getColorVec());
kibitzArea.setFont(opser.getFontOption(GlobalOptions.textfontString));
inputField.addKeyListener(new KeyboardListener());
northCanvas = new CoordinateCanvas("North", this);
southCanvas = new CoordinateCanvas("South", this);
eastCanvas = new CoordinateCanvas("East", this);
westCanvas = new CoordinateCanvas("West", this);
boardCanvas = new BoardCanvas(this, game.getSize(), game.ss);
statusPanel = configureStatus(opser.getStringOption(statusString));
// applet/application differences.
if (Ergo.inApplet) {
copyAsSGFItem.setEnabled(false);
saveOutputItem.setEnabled(false);
saveAsItem.setEnabled(false);
saveItem.setEnabled(false);
loadItem.setEnabled(false);
}
else {
setSound(false);
soundItem.setEnabled(false);
}
// View menu
refreshHostItem.setEnabled(false);
setKibitzState(showKibitzes, showKibitzesForThisMoveOnly);
browsingItem.setState(isBrowsing());
localScoringItem.setState(game.scoringMode());
focusHere = opser.getBooleanOption(gwinTermOutString);
updateFocus();
showCoordinatesItem.setState(showCoordinates = opser.getBooleanOption(ScoordString));
showVariationsItem.setState(showVariations = opser.getBooleanOption(variationString));
// Windows menu
window.registrar.registerMenu(windowsMenu, this);
// The following line commented out for now since it's not implemented.
//window.registrar.registerWindowsMenuCommand(duplicateItem);
//window.registrar.registerWindowsMenuCommand(separatorItem);
class HandicapMenuCommand extends MenuCommand {
private int stones;
HandicapMenuCommand (int stones) {
super(stones + ((stones == 1) ? " stone" : " stones"));
this.stones = stones;
}
public void executeCommand (Object event) {
Move last = game.getCurrentMove();
int movenum = (last == null) ? 1 : last.moveNumber() + 1;
int timeleft = 0;
if (isLocalGame() || isBrowsing()) {
// The user is a playing a local game or browsing, just place the move.
placeMove(new HandicapMove(last, timeleft, movenum, isBrowsing(),
stones, game.getSize()),
false);
game.ss.emit();
}
else {
if (game.firstMove() == null && gameStatus == PLAYING) {
conn.send("handicap " + stones);
//boardCanvas.enqueueMove(new TempHandiMove(stones, game.size()));
}
else
Util.beep();
}
}
}
// Game menu
for (int i = 2; i <= 9; i++) {
handicapMenu.add(new HandicapMenuCommand(i));
}
if (!isParticipating()) {
// +++ Should disable this until in scoring mode, for server games.
doneItem.setEnabled(false);
adjournItem.setEnabled(false);
resignItem.setEnabled(false);
}
// Font f = new Font("Monospaced", Font.BOLD, 18);
layoutComponents();
configureCoordinates();
addWindowListener(new WindowAdapter() {
public void windowClosing (WindowEvent e) {
close();
}
});
// Set the focus to inputField when the window is initially shown.
addComponentListener(new ComponentAdapter () {
public void componentShown (ComponentEvent e) {
inputField.requestFocus();
}
});
inputField.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent ae) {
inputField.setText("");
window.processCommand(ae.getActionCommand(), GameWindow.this);
}
});
noteCurrentMoveChanged(); // note the root move placed.
// Splatter popup menu listeners over all the components that should
// allow a popup menu.
northCanvas.addMouseListener(popupControl);
southCanvas.addMouseListener(popupControl);
eastCanvas.addMouseListener(popupControl);
westCanvas.addMouseListener(popupControl);
boardCanvas.addMouseListener(popupControl);
kibitzArea.addMouseListener(popupControl);
boardPanel.addMouseListener(popupControl);
statusPanel.addMouseListener(popupControl);
stepBackButton.addMouseListener(popupControl);
stepForwardButton.addMouseListener(popupControl);
} // end init()
private void layoutComponents () {
topPanel.setLayout(new BorderLayout());
topPanel.add("Center", boardPanel);
if (tallConfiguration)
topPanel.add("South", statusPanel);
else
topPanel.add("East", statusPanel);
bottomPanel.setLayout(new BorderLayout());
bottomPanel.add("North", kibitzArea);
bottomPanel.add("South", inputField);
MosaicPanel mPanel = new MosaicPanel();
MosaicLayout mLayout = new MosaicLayout();
mPanel.setLayout(mLayout);
mLayout.setConstraints("less expansion", new MosaicConstraints(
MosaicConstraints.CENTER, MosaicConstraints.BOTH, 0.5 ) );
mLayout.setConstraints("none", new MosaicConstraints(MosaicConstraints.CENTER,
MosaicConstraints.BOTH, 0));
mLayout.setPos(0, 0);
mPanel.add("less expansion", topPanel);
mLayout.setPos(0, 1);
mPanel.add("none", bottomPanel);
setLayout(new BorderLayout());
add("Center", mPanel);
add("South", inputField); // Commands are entered in the inputField.
boardPanel.setLayout(new BoardLayout(game.size()));
boardPanel.add("Board", boardCanvas);
}
public void run () {
updateTitle();
// returns null, in contrast to other getXxxx.
Dimension d = opser.getSizeOption(getSizeString());
if (d != null)
setSize(d);
else
pack();
setLocation(opser.getNextCascade(getSize()));
show();
}
/***********************************
* Implement WindowsMenuCommand interface *
***********************************/
public String menuString () { return title(); }
public MenuShortcut menuShortcut () {
return null; // +++ Should use Ctrl+1, Ctrl+2, etc to access game windows.
}
public int menuPriority () { return 999; }
public void menuSelect (Frame f) {
// It would be nice if this would deiconify the window when it
// has been iconified. I couldn't find a way to do that. -sigue
// It is impossible - AMB. (reputedly)
toFront();
}
public Class appliesTo () {
return null; // applies to all windows.
}
/*****************************************
* Implement the OutputFocus interface *
*****************************************/
public void displayString (String s) {
kibitzArea.appendText(s);
}
public void displayString (String s, Color c) {
kibitzArea.appendText(s, c);
}
public void noteFocusLost () {
focusHere = false;
focusHereItem.setState(focusHere);
}
/****************************
* Miscellaneous code *
****************************/
// Duplicate a GameWindow.
private void duplicate () {
/* GameWindow copy = new GameWindow(game.size(),
game.whiteName, game.whiteRank,
game.blackName, game.blackRank,
game.komi, window, conn, -1, -1);
*/
}
public void setKoPosition (Position p) {
if (statusPanel != null)
statusPanel.setKoPosition(p);
}
public CommandHistory getCommandHistory () {
return commandHistory;
}
public boolean gameInProgress () {
return gameStatus == PLAYING || gameStatus == SCORING;
}
// Add a kibitz to this game.
// It should already have been sent to the server if necessary.
public void addKibitz (String kibitzer, String rank, String kibitz,
boolean addToCurrent) {
String fullKib
= ((kibitzer == null ? "Local" : kibitzer)
+ (rank == null ? "" : (" " + rank)) + ": " + kibitz);
addKibitz1(fullKib, addToCurrent);
}
// This is separated out for use by Controller.handleSay().
public void addKibitz1 (String fullKib, boolean addToCurrent) {
if (!Ergo.inApplet) {
saveItem.setEnabled(true);
saveAsItem.setEnabled(true);
}
if (!isNetGame())
addToCurrent = true;
// The theory here is that if this is a server game in progress
// the kibitz should always go with the latest server move since
// that is where observer kibitzes will go, and the local user
// may be referring to those kibitzes in his/her own. If the user
// wants to add kibitzes to a specific move before the current
// server move they should do it in a post-mortem kibitz.
// (Or with the new localkibitz command.)
Move move = (addToCurrent ? game.getCurrentMove() : game.finalServerMove());
move.addKibitz(fullKib);
displayOneKibitz(fullKib, move.moveNumber() + 1);
}
private void displayOneKibitz (String kibitz, int movenum) {
if (showKibitzes) {
String numster = showKibitzesForThisMoveOnly ? " " : "#" + movenum + " ";
kibitzArea.appendText(numster + kibitz, TerminalWindow.kibitzColor);
}
}
// If the user has this option set, the kibitz area is cleared each
// time the user browses to a new move, and that move's kibitzes are
// displayed.
private void updateKibitzArea () {
if (showKibitzesForThisMoveOnly) {
Move move = game.getCurrentMove();
kibitzArea.clearAll();
Vector kibs = move.kibitzes();
if (kibs != null) {
for (int i = 0; i < kibs.size(); i++) {
displayOneKibitz((String) kibs.elementAt(i), move.moveNumber() + 1);
}
}
}
}
// Used when the user turns on display of all kibitzes
// Note that it doesn't make much sense to display k
// private void displayAllKibitzes () {
// Move m = game.rootMove();
public void setKibitzState (boolean show, boolean currentOnly) {
if (show != showKibitzes) {
showKibitzes = show;
if (showKibitzes) {
bottomPanel.add("South", kibitzArea);
}
else
bottomPanel.remove(kibitzArea);
validate();
}
showKibitzesForThisMoveOnly = currentOnly;
}
// Called whenever the Game enters or exits scoring mode.
public void noteScoringMode (boolean b) {
localScoringItem.setState(b);
if (b)
savedBrowsing = browsing;
else
setBrowsing(savedBrowsing);
statusPanel.refresh();
}
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -