コード例 #1
0
 public Object getValueAt(int rowIndex, int columnIndex) {
   if (currentActor == null) return null;
   Attack attack = currentActor.getAttack(rowIndex);
   switch (columns.values()[columnIndex]) {
     case Name:
       return attack.name;
     case Skill:
       return attack.skill;
     case Damage:
       return attack.damage;
     case Unbalanced:
       return attack.unbalanced;
     default:
       return null;
   }
 }
コード例 #2
0
  /**
   * Set the value at the row/col specified For cloned actors, this will update all clones (and fire
   * table updated events)
   *
   * @param value : Must be either int (for hp/damage/health) or String (for name/State/Type)
   * @param row : The row where the actor lives. Any clones will be updated also.
   * @param col : The column of the value to edit: use 'columns' enum to address.
   */
  @Override
  public void setValueAt(Object value, int row, int col) {
    if (LOG.isLoggable(Level.FINER)) {
      LOG.finer(
          "Setting value at "
              + row
              + ","
              + col
              + " to "
              + value
              + " (an instance of "
              + value.getClass()
              + ")");
    }

    // Check if there is any actual change
    if (getValueAt(row, col).equals(value)) {
      if (LOG.isLoggable(Level.FINER)) {
        LOG.finer("Values are identical. Exiting.");
      }
      return;
    }

    Attack a = currentActor.getAttack(row);
    switch (columns.values()[col]) {
      case Name:
        a.name = (String) value;
        break;
      case Skill:
        a.skill = (Integer) value;
        break;
      case Damage:
        a.damage = (String) value;
        break;
      case Unbalanced:
        a.unbalanced = (Boolean) value;
    }
    currentActor.setAttack(a, row);
    // Update the entire row, since changing state or type may affect formatting for all cells in
    // the row.
    fireTableRowsUpdated(row, row);
  }