/**
   * Display defence minus attack potential on a square.
   *
   * @param x the x
   * @param y the y
   */
  public void displayDefenceMinusAttackPotential(int x, int y) {
    if (matrix[x][y] != null && !(matrix[x][y] instanceof Mountain)) {
      MovableEntity unit = board.getUnit(x, y);
      if (unit == null) squares[x][y].setBackground(COLOR_EMPTY);
      else {
        Font fnt = new Font("Serif", Font.PLAIN, windowHeight / 50);

        int diff = (unit.getAllyDefence() - unit.getEnemyAttack());
        JLabel tmp = new JLabel(Integer.toString(diff), SwingConstants.RIGHT);
        tmp.setFont(fnt);
        squares[x][y].add(tmp);
        if (board.getUnit(x, y).getOwner() == 0)
          squares[x][y].setBackground(
              new Color(
                  Math.min(240, Math.max(0, 75 + 4 * diff)),
                  Math.min(240, Math.max(0, 75 + 4 * diff)),
                  255));
        else
          squares[x][y].setBackground(
              new Color(
                  255,
                  Math.min(240, Math.max(0, 75 + 4 * diff)),
                  Math.min(240, Math.max(0, 75 + 4 * diff))));
      }
    }
  }
  /**
   * Displays the defence potential on a square.
   *
   * @param x the x
   * @param y the y
   */
  public void displayDefencePotential(int x, int y) {
    if (matrix[x][y] != null && !(matrix[x][y] instanceof Mountain)) {
      MovableEntity unit = board.getUnit(x, y);
      if (unit != null) {
        Font fnt = new Font("Serif", Font.PLAIN, windowHeight / 50);

        JLabel tmp = new JLabel(Integer.toString(unit.getAllyDefence()), SwingConstants.RIGHT);
        tmp.setFont(fnt);
        squares[x][y].add(tmp);
      }
    }
  }
  /** Displays the GUI. */
  public void displayGUI() {
    for (int j = 0; j < Board.HEIGHT; j++) {
      for (int i = 0; i < Board.WIDTH; i++) {

        JPanel currentSquare = squares[i][j];
        Entity currentEntity = matrix[i][j];
        // squares[i][j].setBackground(new Color(r.nextInt(255),r.nextInt(255),r.nextInt(255)));
        currentSquare.removeAll();

        if (currentEntity == null) currentSquare.setBackground(COLOR_EMPTY);
        else {
          switch (displayMode) {
            case DISPLAY_UNITS:
              displayUnit(i, j);
              break;
            case DISPLAY_ATTACK:
              resetSelectedSquare();
              displayAttackPotential(i, j);
              break;
            case DISPLAY_DEFENCE:
              resetSelectedSquare();
              displayDefencePotential(i, j);
              break;
            case DISPLAY_DEFENCE_MINUS_ATTACK:
              resetSelectedSquare();
              displayDefenceMinusAttackPotential(i, j);
              break;
            default:
              resetSelectedSquare();
              break;
          }

          if (currentEntity instanceof Mountain) currentSquare.setBackground(COLOR_MOUTAIN);

          if (currentEntity.canContain()) currentEntity = board.getUnit(i, j);

          if (displayMode != DISPLAY_DEFENCE_MINUS_ATTACK) colorSquareByOwner(i, j);
          if (currentEntity instanceof MovableEntity
              && displayMode != DISPLAY_ATTACK_EVAL_TEAM0
              && displayMode != DISPLAY_ATTACK_EVAL_TEAM1
              && displayMode != DISPLAY_DEFENCE_EVAL_TEAM0
              && displayMode != DISPLAY_DEFENCE_EVAL_TEAM1
              && displayMode != DISPLAY_DEFENCE_MINUS_ATTACK_EVAL_TEAM0
              && displayMode != DISPLAY_DEFENCE_MINUS_ATTACK_EVAL_TEAM1) {
            MovableEntity currentMovable = ((MovableEntity) currentEntity);
            if (currentMovable.canBeKilled()) {
              ((JLabel) currentSquare.getComponent(0))
                  .setText("(" + ((JLabel) currentSquare.getComponent(0)).getText() + ")");
            }
            if (currentMovable.mustRetreat()) {
              ((JLabel) currentSquare.getComponent(0))
                  .setText("[" + ((JLabel) currentSquare.getComponent(0)).getText() + "]");
            }
          }
        }
      }
    }

    if (selectedSquare != null) drawPossibleMovement(selectedSquare.x, selectedSquare.y);
    else drawCommunications();

    if (displayMode == DISPLAY_ATTACK_EVAL_TEAM0) displayAttackEvaluator(0);
    if (displayMode == DISPLAY_ATTACK_EVAL_TEAM1) displayAttackEvaluator(1);

    if (displayMode == DISPLAY_DEFENCE_EVAL_TEAM0) displayDefenceEvaluator(0);
    if (displayMode == DISPLAY_DEFENCE_EVAL_TEAM1) displayDefenceEvaluator(1);
    if (displayMode == DISPLAY_DEFENCE_MINUS_ATTACK_EVAL_TEAM0)
      displayDefenceMinusAttackEvaluator(0);
    if (displayMode == DISPLAY_DEFENCE_MINUS_ATTACK_EVAL_TEAM1)
      displayDefenceMinusAttackEvaluator(1);

    this.repaint();
    this.setVisible(true);
  }