📄 gamewindow.java
字号:
}
}
else if (isNetGame() && isParticipating() && !isBrowsing()) {
if (conn != null)
conn.send(new Position(row, column).toString(), false);
else
Debug.println(">>> Ergo: No connection to server. Move discarded.");
}
else {
Move var = parent.variationAt(new Position(row, column));
if (var != null)
goForward(1, var, false, false);
else {
int movenum = parent.moveNumber() + 1;
int timeleft = timeLeft();
StoneMove move = new StoneMove(parent, timeleft, movenum,
parent.nextColor(), isBrowsing(),
row, column);
placeMove(move, false);
}
}
}
// Hmmm. This should trace the path back from m and then replay it, no?
public void goToMove (Move m) {
if (m != null && m != game.getCurrentMove()) {
int n = m.moveNumber();
int c = game.getCurrentMove().moveNumber();
if (n > c)
goForward(n - c);
else
goBackward(c - n, false);
}
}
/*
* Backup to the previous move. This is basically a local undo.
*/
public void goBackward (int nmoves, boolean stopAtBranch) {
boolean smode = game.scoringMode();
Move cm = game.getCurrentMove();
game.goBackward(nmoves, stopAtBranch);
if (cm != game.getCurrentMove()) {
noteCurrentMoveChanged();
game.ss.emit();
statusPanel.refresh();
// Scoring mode may be exited if the user has backed past where
// scoring mode was entered. Update the menus.
if (smode && !game.scoringMode())
noteScoringMode(false);
else
setBrowsing(true);
}
}
public void goBackToKibitz () {
boolean smode = game.scoringMode();
Move cm = game.getCurrentMove();
game.goBackToKibitz();
if (cm != game.getCurrentMove()) {
noteCurrentMoveChanged();
game.ss.emit();
statusPanel.refresh();
// Scoring mode may be exited if the user has backed past where
// scoring mode was entered.
if (smode && !game.scoringMode())
noteScoringMode(false);
else
setBrowsing(true);
}
}
public void goForward (int nmoves) {
goForward(nmoves, null, false, false);
}
public void goForward (int nmoves, Move variation, boolean stopAtBranch,
boolean stopAtKibitz) {
Move cm = game.getCurrentMove();
game.goForward(nmoves, variation, stopAtBranch, null, stopAtKibitz);
if (cm != game.getCurrentMove()) {
noteCurrentMoveChanged();
game.ss.emit();
statusPanel.refresh();
// Browsing to end of game exits browsing.
if (game.finalServerMove() == game.getCurrentMove())
setBrowsing(false);
}
}
/*
* Go to the end of the current branch. Do not stop at variations.
*/
public void goToEnd () {
Move cm = game.getCurrentMove();
game.goToEnd();
if (cm != game.getCurrentMove()) {
noteCurrentMoveChanged();
game.ss.emit();
statusPanel.refresh();
setBrowsing(false);
}
}
public void undoDuringServerScoring () {
while (game.finalServerMove() instanceof RemovalMove)
game.undo();
}
/*
* Permanently undo the previous move.
*/
public void undo () {
if (game.scoringMode())
undoDuringServerScoring();
if (conn.server.isNNGStype())
game.undo();
noteCurrentMoveChanged();
game.ss.emit();
needsSaving = true;
if (!Ergo.inApplet) {
saveItem.setEnabled(true);
saveAsItem.setEnabled(true);
}
if (game.getCurrentMove().parent() instanceof RootMove)
handicapMenu.setEnabled(true);
}
/** Add any variations at the current move to the Variations menu, after removing old ones.
*/
public void updateVariationsMenu () {
Move current = game.getCurrentMove();
variationsMenu.removeAll();
if (current != null) {
for (int i = -1; ; i++) {
Move var = current.variationAt(i);
if (var == null)
break;
else {
String itemName = (char) (i + 1 + (int) 'a') + " (" + var.toString() + ")";
variationsMenu.add(new VariationMenuItem(itemName, var) {
public void executeCommand (Object event) {
placeMove(getVariation(), false);
game.ss.emit();
}
});
}
}
}
}
/*************************************************
* Event handling *
*************************************************/
class checkboxListener extends urCheckboxListener {
// This is called when a CheckboxMenuItem is clicked.
public void itemStateChanged (ItemEvent e) {
Object item = e.getSource();
// Coordinates fairly internal. Unlikely to be optioned from elsewhere.
if (item == showCoordinatesItem)
toggleCoordinates();
else if (item == browsingItem) {
boolean b = browsing;
setBrowsing(!browsing);
if (b) exitBrowsingMode();
}
else if (item == soundItem)
setSound(!sound);
else if (item == localScoringItem) {
if (game.scoringMode())
game.exitScoringMode();
else {
game.enterScoringMode(true);
// Enter browsing mode if this is a network game and the user
// enters scoring mode. +++ Might want to exit browsing mode
// when scoring mode is exited. For now this is safer.
if (isNetGame() && game.scoringMode())
setBrowsing(true);
}
noteScoringMode(game.scoringMode());
}
else if (item == focusHereItem) {
focusHere = !focusHere;
updateFocus();
}
else if (item == showVariationsItem) {
opser.updateOption(GlobalOptions.variationString,
new Boolean(showVariationsItem.getState()));
}
}
}
/** Called when the Show Terminal Output menu item is selected.
*/
private void updateFocus () {
focusHereItem.setState(focusHere);
if (focusHereItem.getState())
window.addOutputFocus(GameWindow.this);
else
window.removeOutputFocus(GameWindow.this);
}
class exclusiveCheckboxListener implements ItemListener {
public void itemStateChanged(ItemEvent ie) {
CheckboxMenuItem item = (CheckboxMenuItem) ie.getSource();
if (item == kibitzAllItem)
setKibitzState(true, false);
else if (item == kibitzCurrentItem)
setKibitzState(true, true);
else if (item == kibitzNoneItem)
setKibitzState(false, showKibitzesForThisMoveOnly);
else if (item == stonesItems[Styles.STONE_BASIC])
opser.updateOption(GlobalOptions.stoneString, new Integer(Styles.STONE_BASIC));
else if (item == stonesItems[Styles.STONE_ANTIN])
opser.updateOption(GlobalOptions.stoneString, new Integer(Styles.STONE_ANTIN));
else if (item == stonesItems[Styles.STONE_3D])
opser.updateOption(GlobalOptions.stoneString, new Integer(Styles.STONE_3D));
else if (item == boardItems[Styles.BOARD_BASIC])
opser.updateOption(GlobalOptions.boardStyleString, new Integer(Styles.BOARD_BASIC));
else if (item == boardItems[Styles.BOARD_WOOD])
opser.updateOption(GlobalOptions.boardStyleString, new Integer(Styles.BOARD_WOOD));
else if (item == showStatusNoneItem)
statusPanel = configureStatus("None");
else if (item == showStatusRightItem)
statusPanel = configureStatus("Right");
else if (item == showStatusBottomItem)
statusPanel = configureStatus("Bottom");
}
}
class menuListener extends urMenuListener {
public void itemSelected (MenuItem source) {
if (source == closeItem)
close();
else if (source == refreshLocalItem)
refresh();
else if (source == refreshHostItem) {
if (isNetGame())
conn.send("refresh"); }
else if (source == saveItem)
save();
else if (source == saveAsItem)
saveAs();
else if (source == loadItem)
window.load();
else if (source == saveOutputItem)
window.saveTerminalOutput(kibitzArea);
else if (source == passItem) {
if (isNetGame() && !isBrowsing())
conn.send("pass");
else {
Move last = game.getCurrentMove();
int movenum = last.moveNumber() + 1;
int timeleft = 300;
placeMove(new PassMove(last, timeleft, movenum, last.nextColor(),
isBrowsing()),
false);
game.ss.emit();
}
}
else if (source == undoItem) {
if (isNetGame() && isParticipating() && !isBrowsing())
conn.send("undo");
else
goBackward(1, false); // local undo only
game.ss.emit();
}
else if (source == doneItem) {
if (isNetGame() && isParticipating() && !isBrowsing())
conn.send("done");
}
else if (source == adjournItem) {
if (isNetGame() && isParticipating())
conn.send("adjourn");
}
else if (source == resignItem) {
if (isNetGame() && isParticipating() && !isBrowsing()) {
ActionListener listener = new ActionListener() {
public void actionPerformed (ActionEvent e) {
String cmd = e.getActionCommand();
if ("yes".equalsIgnoreCase(cmd))
conn.send("resign");
}
};
new YNCDialog(GameWindow.this, "Resign?", true,
"Are you sure you want to resign?",
listener, false).open();
}
}
else if (source == copyAsSGFItem
|| source.getLabel().equals(copyAsSGFString)) {
copyAsSGF();
}
else if (source == dumpBoardItem) {
displayBoard();
}
else if (source == dumpGroupsItem) {
displayGroups();
}
}
}
class KeyboardListener extends KeyAdapter {
public void keyPressed (KeyEvent e) {
boolean alt = e.isAltDown() || e.isMetaDown();
switch (e.getKeyCode()) {
case KeyEvent.VK_UP:
if (alt)
goForward(-1, null, true, false); // forward to branch
else {
String prev = commandHistory.getPreviousElement();
if (prev != null) {
inputField.setText(prev);
inputField.setCaretPosition(prev.length() - 1);
}
}
return;
case KeyEvent.VK_DOWN:
if (alt)
goBackward(-1, true); // back to branch
else {
String next = commandHistory.getNextElement();
if (next != null) {
inputField.setText(next);
inputField.setCaretPosition(next.length() - 1);
}
}
return;
case KeyEvent.VK_LEFT:
if (alt)
goBackward(1, false); // step backward
return;
case KeyEvent.VK_RIGHT:
if (alt)
goForward(1); // step forward
return;
}
}
} // end inner class KeyboardListener
// Implement MouseListener
class mouseListener extends MouseAdapter {
public void mouseReleased (MouseEvent e) {
Component c = (Component) e.getComponent();
if (c instanceof ImageButton && !e.isPopupTrigger()) {
ImageButton button = (ImageButton) c;
if (button == stepBackButton)
goBackward(1, false);
else if (button == stepForwardButton)
goForward(1);
else if (button == toBeginningButton)
goBackward(-1, false);
else if (button == toEndButton)
goToEnd();
else if (button == backKibButton)
goBackToKibitz();
else if (button == fwdKibButton)
goForward(-1, null, true, true);
else if (button == backBranchButton)
goBackward(-1, true);
else if (button == fwdBranchButton)
goForward(-1, null, true, false);
}
}
} // end inner class mouseListener
/**************************************************
* Manage window Opening/Closing, and Game Save *
**************************************************/
// Save a game using the current file name, if any. If not, prompt
// for a file name. Return true if save dialog cancelled, else false.
private boolean save () {
if (filename == null)
return saveAs();
else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -