Ejemplo n.º 1
0
  /**
   * Initializes the data that is displayed in this panel.
   *
   * @param servers A list of <code>ServerInfo</code>-objects to be displayed.
   */
  public void initialize(List<ServerInfo> servers) {
    // TODO: This should be added as a filtering rule:
    // Remove servers with an incorrect version from the list:
    Iterator<ServerInfo> it = servers.iterator();
    while (it.hasNext()) {
      ServerInfo si = it.next();
      if (!si.getVersion().equals(FreeCol.getVersion())) {
        it.remove();
      }
    }

    tableModel.setItems(servers);
    setEnabled(true);
    if (servers.size() == 0) {
      connect.setEnabled(false);
    } else {
      table.setRowSelectionInterval(0, 0);
    }
  }
Ejemplo n.º 2
0
  /** {@inheritDoc} */
  public void actionPerformed(ActionEvent event) {
    final String command = event.getActionCommand();

    try {
      switch (Integer.valueOf(command).intValue()) {
        case CONNECT:
          ServerInfo si = tableModel.getItem(table.getSelectedRow());
          connectController.joinMultiplayerGame(si.getAddress(), si.getPort());
          break;
        case CANCEL:
          getGUI().removeFromCanvas(this);
          getGUI().showNewPanel();
          break;
        default:
          super.actionPerformed(event);
      }
    } catch (NumberFormatException e) {
      logger.warning("Invalid ActionEvent, not a number: " + command);
    }
  }
Ejemplo n.º 3
0
 /**
  * Returns the value at the requested location.
  *
  * @param row The requested row.
  * @param column The requested column.
  * @return The value at the requested location.
  */
 public Object getValueAt(int row, int column) {
   if ((row < getRowCount()) && (column < getColumnCount()) && (row >= 0) && (column >= 0)) {
     ServerInfo si = items.get(row);
     switch (column) {
       case 0:
         return si.getName();
       case 1:
         return si.getAddress();
       case 2:
         return Integer.toString(si.getPort());
       case 3:
         return Integer.toString(si.getCurrentlyPlaying())
             + "/"
             + Integer.toString(si.getCurrentlyPlaying() + si.getSlotsAvailable());
       case 4:
         return Messages.message("gameState." + Integer.toString(si.getGameState()));
       default:
         return null;
     }
   }
   return null;
 }