コード例 #1
0
ファイル: ServerGUI.java プロジェクト: jeffrey-ng/halma
 /** Change the currently displayed board. Pass -1 for no board displayed. */
 protected void setCurrentBoard(int index) {
   if (moveList.getSelectedIndex() != index) {
     moveList.setSelectedIndex(index);
     moveList.ensureIndexIsVisible(index);
   }
   // If a move was requested, but we're changing from the
   // last board, cancel the request
   if (userMoveRequested && index != boardHistory.size() - 1) {
     boardPanel.cancelMoveRequest();
     userMoveRequested = false;
   }
   if (currentBoard != index) {
     currentBoard = index;
     // Might be no board, index -1
     if (index < 0) {
       boardPanel.setCurrentBoard(null);
       fromHereAction.setEnabled(false);
     } else {
       Board b = (Board) boardHistory.get(index);
       // Might be the last board, in which case there is no
       // matching board in the list
       if (b == null) b = (Board) boardHistory.get(boardHistory.size() - 1);
       boardPanel.setCurrentBoard(b);
       fromHereAction.setEnabled(
           b != null && b.getWinner() == Board.NOBODY && b.getTurnsPlayed() > 0 && server == null);
     }
     backAction.setEnabled(index > 0);
     firstAction.setEnabled(index > 0);
     fwdAction.setEnabled(index < boardHistory.size() - 1);
     lastAction.setEnabled(index < boardHistory.size() - 1);
   }
   // If we need a move, and this is the last board, request it
   if (userMoveNeeded && index == boardHistory.size() - 1 && !userMoveRequested) {
     boardPanel.requestMove(this);
     userMoveRequested = true;
   }
 }