⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 terminalwindow.java

📁 ErGo是一个很早的Java通用围棋服务器(IGS/NNGS)客户端程序。有全部源码和文档
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
	((GameWindow) gameWindows.elementAt(i)).setVisible(visible);
    }
  }

  public String getRank () {
    return rank;
  }

  public String toString () {
    String s = "Ergo " + Ergo.version();
    if (conn != null) {
      s += "  (";
      if (getAccountName() != null)
	s += getAccountName() + " on ";
      s += conn.toString() + ")";
    }
    return s;
  }

  public void startLocalGame () {
    LocalGameDialog d = new LocalGameDialog(this);
    d.open();
  }


  /****************************
   * "GoClient" interface     *
   ****************************/

  // "Messages" are things like connect/disconnect and game notifications,
  // and they're displayed in a separate TextArea.
  public void displayNoiseString (String s) {
    displayStringInternal(s, messageArea, false, null);
  }

  public void displayShout (String s) {
    displayString(s, shoutColor);
  }
    
  public void updateTitle () {
    setTitle(toString());
  }

  public YNCDialog openYNCDialog (String title, boolean modal, String question,
				  String yes, String no, String cancel,
				  ActionListener listener) {
    YNCDialog d = new YNCDialog(this, title, modal, question, yes, no, cancel,
				listener);
    d.open();
    return d;
  }

  /**
   * This is called when a connection to the server is made.
   */
  public void noteConnected () {
    goConnectSubmenu.setEnabled(false);
    disconnectItem.setEnabled(true);
    matchItem.setEnabled(true);
    observeItem.setEnabled(true);
  }

  public void noteDisconnected () {
    setAccountName(null);
    adjournAll();
    updateTitle();
    // Update the menus
    goConnectSubmenu.setEnabled(true);
    disconnectItem.setEnabled(false);
    matchItem.setEnabled(false);
    observeItem.setEnabled(false);
  }

  public void beep () {
    if (getSoundEnabled())
      Util.beep();
  }

  public void updateGameStatus (int gameNumber,
				int wcapt, int wtime, int wstones,
				int bcapt, int btime, int bstones) {
    GameWindow gwin = getGameWindowByNumber(gameNumber);
    Debug.asser(gwin != null, "gwin != null");
    gwin.updateTimers(wcapt, wtime, wstones, bcapt, btime, bstones);
  }

  public boolean isDisplayingGame (String whiteName, String blackName, int gameNumber) {
    return null != getGameWindowByName(whiteName, blackName, gameNumber);
  }

  // If no game by this name, then this must be the "look" command.
  // Create a local game with one move, the result.
  public GameWindow createGame(int size, String white, String wrank,
			 String black, String brank, double komi) {
    try {
      GameWindow gwin = new GameWindow(size, white, wrank,
				       black, brank, komi, this);
      addGameWindow(gwin);
      return gwin;
    }
    catch (ErgoException ge) {
      Debug.backtrace(ge);
      return null;
    }
  }

  public void placeMove (String white, String black, int gameNumber,
			 Move m, boolean fromServer) {
    GameWindow gwin = getGameWindowByName(white, black, gameNumber);
    if (gwin != null) {
      gwin.placeMove(m, fromServer);
    }
  }

  public void resignGame (String whiteName, String blackName, int gameNumber,
			  String sgfResult) {
    GameWindow gwin = getGameWindowByName(whiteName, blackName, gameNumber);
    if (gwin != null)
      gwin.resign(sgfResult);
  }

  public void adjournGame (String whiteName, String blackName, int gameNumber) {
    GameWindow gwin = getGameWindowByName(whiteName, blackName, gameNumber);
    if (gwin != null)
      gwin.adjourn();
  }

  public void undoMove () {
    undoMoveInternal(getGameBeingPlayed());
  }

  public void undoMove (String whiteName, String blackName, int gameNumber) {
    undoMoveInternal(getGameWindowByName(whiteName, blackName, gameNumber));
  }

  private void undoMoveInternal (GameWindow gwin) {
    if (gwin != null) {
      gwin.undo();
      gwin.game.ss.emit();
    }
    else
      Debug.println("handleUndo: game window not found!");
  }

  public void setKomi (double komi, int gameNumber) {
    GameWindow gwin = ((gameNumber == -1)
        ? getGameBeingPlayed()
        : getGameWindowByNumber(gameNumber));
    if (gwin != null) {
      gwin.game.setKomi(komi);
      gwin.refresh();
    }
  }

  public void removeGroupAt (String position) {
    GameWindow gwin = getGameBeingPlayed();
    if (gwin != null) {
      try {
      Position pos = new Position(position, gwin.game.size());
      Move parent = gwin.game.finalServerMove();
      gwin.placeMove(new RemovalMove(parent, pos, parent.moveNumber() + 1,
				     false),
		     true);
      gwin.game.ss.emit();
      return;		// the message has been handled.
      }
      catch (ParseException e) { Debug.backtrace(e); }
    }
  }

  public boolean getRawMode () {
    return rawMode;
  }

  public void displayString (String s, Color c, boolean always) {
    if (always || rawMode == false)	// avoid displaying some strings twice
      displayStringInternal(s, mainArea, true, c);
  }

  public void displayStringInActiveGame (String s) {
    GameWindow gwin = getGameBeingPlayed();
    if (gwin != null)
      gwin.displayString(s);
    else
      displayString(s);
  }
  
  public void displayWarning (String message) {
    displayString(message, TerminalWindow.warningColor);
  }

  public void displayCommand (String message) {
    displayString(message, TerminalWindow.commandColor);
  }

  public void displayLoginDialog() {
    if (loginDialog == null)
      loginDialog = new LoginDialog(this, conn);
    // Weird bug...for some reason the loginDialog.open() method
    // seems to get called _after_ the dialog is closed by the
    // user.  Therefore loginDialog.hecho was getting set to false
    // after the dialog was finished, when it should have been true.
    // Setting it here instead of in open() works around the problem.
    loginDialog.hecho = false;
    loginDialog.passwordSent = false;
    if (!loginDialog.isShowing()) {
      loginDialog.setTitle("Login to " + conn.shortName());
      loginDialog.open();
    }
  }

  public void displayKibitz (String whiteName, String blackName, int gameNumber,
			     String kibitzer, String rank, String kibitz) {
    GameWindow gwin = getGameWindowByName(whiteName, blackName, gameNumber);
    if (gwin != null) {
      gwin.addKibitz(kibitzer, rank, kibitz, false);
    }
    else
      Debug.println("game window for kibitz not found");
  }

  public void displayMatchRequest (String opponent, String color, String size,
				   String time, String byotime) {
    MatchDialog d = new MatchDialog(this, true);
    d.open(conn, getAccountName(), opponent, color, size, time, byotime);
  }

  public void unobserveGame (int gameNumber) {
    GameWindow gwin = getGameWindowByNumber(gameNumber);
    // +++ This should be optionized.  I prefer the game window to remain
    //     open until i say to close it.  Others might want it to go away
    //     when they type "unobserve n".
    if (gwin != null) {
      gwin.adjourn();
      removeGameWindow(gwin);
    }
  }

  public void makeGameFree (int gameNumber) {  // -1 means active game
    GameWindow gwin = ((gameNumber == -1)
		       ? getGameBeingPlayed()
		       : getGameWindowByNumber(gameNumber));
    if (gwin != null)
      gwin.setOurColor(Move.BOTH);
    return;
  }

  public String getAccountName () {
    return accountName;
  }

  public void setAccountName (String name) {
    accountName = name;
    updateTitle();
  }

  public void setAccountRank (String rank) {
    this.rank = rank;
  }

  public void displayYell (String author, String message) {
    displayString("<" + author + "> " + message, yellColor);
  }

  public void displayTell (String message) {
    displayString(message, tellColor);
  }

  public void displaySay (String message) {
    GameWindow gwin = getGameBeingPlayed();
    if (gwin == null)
      displayString(message, kibitzColor); // should never get here
    else
      gwin.addKibitz1(message, false);
  }

  public boolean loginDialogExists () {
    return loginDialog != null;
  }

  public boolean loginDialogDone () {
    return loginDialog.hecho;
  }

  public boolean passwordSent () {
    return loginDialog.passwordSent;
  }

  public void sendPassword () {
    conn.send(loginDialog.password.getText(), false);
    loginDialog.passwordSent = true;
  }

  public GameWindow addGameWindow (int size, String w, String wr, String b,
				   String br, double komi, int n, int matchi,
				   int byotime, boolean freeGame) {
    try {
      GameWindow gwin = new GameWindow(size, w, wr, b, br, komi, this, conn, n,
				       matchi, byotime, freeGame);
      addGameWindow(gwin);
      return gwin;
    }
    catch (ErgoException foo) {
      return null;
    }
  }

  // end interface "GoClient"


  /****************************
   * "Focusable" interface    *
   ****************************/

  // Implement the Focusable interface.  Copied from Dialogs.java.
  // (Code re-use, java style = cut, paste, modify.)

  // Default method.
  public Component initialFocus () {
    return inputField;
  }

  public void focusOn (Component c) {
    if (c != null) {
      c.requestFocus();
      if (c instanceof TextField
	  && ((TextField) c).getText().length() > 0)
	((TextField) c).selectAll();
    }
  }

  public Vector focusOrder () {
    if (focusOrder == null) {
      focusOrder = new Vector(1);
      focusOrder.addElement(inputField);
    }
    return focusOrder;
  }


  /******************************************
   * Implement WindowsMenuCommand interface *
   ******************************************/

  public String menuString () { return "Terminal View"; }

  public MenuShortcut menuShortcut () {
    return new MenuShortcut('t');
  }

  public int menuPriority () { return 100; }

  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 cannot be done. AMB.
    // I believe it can now.  Not sure which version though. -sigue
    toFront();
    setVisible(true);
    inputField.requestFocus();
  }
  
  public Class appliesTo () {
    return null; // applies to all windows.
  }

  /*************************
   * NewServerDialog class *
   *************************/

  class NewServerDialog extends ErgoDialog implements ActionListener, ItemListener {
    private TextField domain = new TextField(30);
    private TextField nickname = new TextField(15);
    private TextField port = new TextField(4);
    private Choice type = new Choice();
    private Button okButton = new Button("  OK  ");
    private Button cancelButton = new Button("Cancel");
    // +++ Note extra spaces in label kludge.
    private Checkbox savep = new Checkbox("Save in init file                    ", true);

    NewServerDialog () {
      super(TerminalWindow.this, "New Go Server", true, false); // parent, title, modal
      okButton.addActionListener(this);
      cancelButton.addActionListener(this);
      domain.addActionListener(this);
      nickname.addActionListener(this);
      port.setText("9696");
      port.addActionListener(this);
      type.add("NNGS");
      type.add("IGS");
      type.select("NNGS");
      type.addItemListener(this);

      Panel p1 = new Panel();
      GridBagLayout gbl = new GridBagLayout();
      GridBagConstraints gbc = new GridBagConstraints();
      p1.setLayout(gbl);
      int marg = 10;
      int midh = 3;
      int midv = 7;
      gbc.gridwidth = 1;
      Insets i = new Insets(2, marg, 2, marg); // top, left, bot, right
      gbc.insets = i;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -