/**
   * Invoked when a mouse button was pressed.
   *
   * @param e The MouseEvent that holds all the information.
   */
  @Override
  public void mousePressed(MouseEvent e) {
    if (!e.getComponent().isEnabled()) return;

    int me = e.getButton();
    if (e.isPopupTrigger()) me = MouseEvent.BUTTON3;
    Tile tile = canvas.convertToMapTile(e.getX(), e.getY());

    switch (me) {
      case MouseEvent.BUTTON1:
        // Record initial click point for purposes of dragging
        canvas.setDragPoint(e.getX(), e.getY());
        if (canvas.isGotoStarted()) {
          PathNode path = canvas.getGotoPath();
          if (path != null) {
            canvas.stopGoto();
            // Move the unit
            freeColClient
                .getInGameController()
                .goToTile(canvas.getActiveUnit(), path.getLastNode().getTile());
          }
        } else if (doubleClickTimer.isRunning()) {
          doubleClickTimer.stop();
        } else {
          centerX = e.getX();
          centerY = e.getY();
          doubleClickTimer.start();
        }
        canvas.requestFocus();
        break;
      case MouseEvent.BUTTON2:
        if (tile != null) {
          Unit unit = canvas.getActiveUnit();
          if (unit != null && unit.getTile() != tile) {
            PathNode dragPath = unit.findPath(tile);
            canvas.startGoto();
            canvas.setGotoPath(dragPath);
          }
        }
        break;
      case MouseEvent.BUTTON3:
        // Cancel goto if one is active
        if (canvas.isGotoStarted()) canvas.stopGoto();
        canvas.showTilePopup(tile, e.getX(), e.getY());
        break;
      default:
        break;
    }
  }
 /**
  * Evaluate a potential cashin mission for a given unit and path.
  *
  * @param aiUnit The <code>AIUnit</code> to do the mission.
  * @param path A <code>PathNode</code> to take to the target.
  * @return A score for the proposed mission.
  */
 public static int scorePath(AIUnit aiUnit, PathNode path) {
   Location loc;
   if (path == null
       || (loc = extractTarget(aiUnit, path)) == null
       || (loc instanceof Colony && invalidFullColonyReason(aiUnit, loc.getColony()) != null))
     return Integer.MIN_VALUE;
   return aiUnit.getUnit().getTreasureAmount() / (path.getTotalTurns() + 1);
 }
 /**
  * Extract a valid target for this mission from a path.
  *
  * @param aiUnit A <code>AIUnit</code> to perform the mission.
  * @param path A <code>PathNode</code> to extract a target from, (uses the unit location if null).
  * @return A target for this mission, or null if none found.
  */
 public static Location extractTarget(AIUnit aiUnit, PathNode path) {
   if (path == null) return null;
   final Location loc = path.getLastNode().getLocation();
   Colony colony = loc.getColony();
   return (loc instanceof Europe && invalidReason(aiUnit, loc) == null)
       ? loc
       : (colony != null && invalidReason(aiUnit, colony) == null) ? colony : null;
 }
  /**
   * Invoked when a mouse button was released.
   *
   * @param e The MouseEvent that holds all the information.
   */
  @Override
  public void mouseReleased(MouseEvent e) {
    try {
      if (canvas.getGotoPath() != null) { // A mouse drag has ended.
        PathNode temp = canvas.getGotoPath();
        canvas.stopGoto();

        freeColClient
            .getInGameController()
            .goToTile(canvas.getActiveUnit(), temp.getLastNode().getTile());

      } else if (canvas.isGotoStarted()) {
        canvas.stopGoto();
      }
    } catch (Exception ex) {
      logger.log(Level.WARNING, "Error in mouseReleased!", ex);
    }
  }