File Source: AliasTableModel.java

         /* 
    P/P   *  Method: com.dmdirc.addons.ui_swing.dialogs.aliases.AliasTableModel__static_init
          */
     1  /*
     2   * Copyright (c) 2006-2009 Chris Smith, Shane Mc Cormack, Gregory Holmes
     3   *
     4   * Permission is hereby granted, free of charge, to any person obtaining a copy
     5   * of this software and associated documentation files (the "Software"), to deal
     6   * in the Software without restriction, including without limitation the rights
     7   * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     8   * copies of the Software, and to permit persons to whom the Software is
     9   * furnished to do so, subject to the following conditions:
    10   *
    11   * The above copyright notice and this permission notice shall be included in
    12   * all copies or substantial portions of the Software.
    13   *
    14   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    15   * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    16   * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
    17   * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    18   * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    19   * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
    20   * SOFTWARE.
    21   */
    22  
    23  package com.dmdirc.addons.ui_swing.dialogs.aliases;
    24  
    25  import com.dmdirc.actions.wrappers.Alias;
    26  import com.dmdirc.actions.ActionCondition;
    27  
    28  import java.util.ArrayList;
    29  import java.util.List;
    30  
    31  import javax.swing.table.AbstractTableModel;
    32  
    33  /**
    34   * Table model for displaying aliases.
    35   */
    36  public final class AliasTableModel extends AbstractTableModel {
    37      
    38      /**
    39       * A version number for this class. It should be changed whenever the class
    40       * structure is changed (or anything else that would prevent serialized
    41       * objects being unserialized with the new class).
    42       */
    43      private static final long serialVersionUID = 3;
    44      
    45      /** Data list. */
    46      private List<Alias> aliases;
    47      
    48      /** Creates a new instance of AliasTableModel. */
    49      public AliasTableModel() {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.dialogs.aliases.AliasTableModel()
                  * 
                  *  Postconditions:
                  *    this.aliases == &amp;new ArrayList(AliasTableModel#1)
                  *    new ArrayList(AliasTableModel#1) num objects == 1
                  */
    50          this(new ArrayList<Alias>());
    51      }
    52      
    53      /**
    54       * Creates a new instance of AliasTableModel.
    55       *
    56       * @param aliases List of aliases
    57       */
    58      public AliasTableModel(final List<Alias> aliases) {
                 /* 
    P/P           *  Method: void com.dmdirc.addons.ui_swing.dialogs.aliases.AliasTableModel(List)
                  * 
                  *  Postconditions:
                  *    this.aliases == &amp;new ArrayList(AliasTableModel#1)
                  *    new ArrayList(AliasTableModel#1) num objects == 1
                  */
    59          super();
    60          
    61          this.aliases = new ArrayList<Alias>(aliases);
    62      }
    63      
    64      /**
    65       * Sets the alias list.
    66       *
    67       * @param aliases List of aliases
    68       */
    69      public void setAliases(final List<Alias> aliases) {
                 /* 
    P/P           *  Method: void setAliases(List)
                  * 
                  *  Postconditions:
                  *    this.aliases == &amp;new ArrayList(setAliases#1)
                  *    new ArrayList(setAliases#1) num objects == 1
                  */
    70          this.aliases = new ArrayList<Alias>(aliases);
    71          
    72          fireTableDataChanged();
    73      }
    74      
    75      /** {@inheritDoc} */
    76      public int getRowCount() {
                 /* 
    P/P           *  Method: int getRowCount()
                  * 
                  *  Preconditions:
                  *    this.aliases != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
    77          return aliases.size();
    78      }
    79      
    80      /** {@inheritDoc} */
    81      public int getColumnCount() {
                 /* 
    P/P           *  Method: int getColumnCount()
                  * 
                  *  Postconditions:
                  *    return_value == 3
                  */
    82          return 3;
    83      }
    84      
    85      /** {@inheritDoc} */
    86      public String getColumnName(final int columnIndex) {
                 /* 
    P/P           *  Method: String getColumnName(int)
                  * 
                  *  Preconditions:
                  *    columnIndex in {0..2}
                  * 
                  *  Postconditions:
                  *    return_value in Addr_Set{&amp;"Command",&amp;"# of Arguments",&amp;"Response"}
                  * 
                  *  Test Vectors:
                  *    columnIndex: {0}, {1}, {2}
                  */
    87          switch(columnIndex) {
    88              case 0:
    89                  return "Command";
    90              case 1:
    91                  return "# of Arguments";
    92              case 2:
    93                  return "Response";
    94              default:
    95                  throw new IllegalArgumentException("Unknown column: "
    96                          + columnIndex);
    97          }
    98      }
    99      
   100      /** {@inheritDoc} */
   101      public Class<?> getColumnClass(final int columnIndex) {
                 /* 
    P/P           *  Method: Class getColumnClass(int)
                  * 
                  *  Preconditions:
                  *    columnIndex in {0..2}
                  * 
                  *  Test Vectors:
                  *    columnIndex: {0}, {1}, {2}
                  */
   102          switch(columnIndex) {
   103              case 0:
   104                  return String.class;
   105              case 1:
   106                  return ActionCondition.class;
   107              case 2:
   108                  return String[].class;
   109              default:
   110                  throw new IllegalArgumentException("Unknown column: "
   111                          + columnIndex);
   112          }
   113      }
   114      
   115      /** {@inheritDoc} */
   116      public boolean isCellEditable(final int rowIndex, final int columnIndex) {
                 /* 
    P/P           *  Method: bool isCellEditable(int, int)
                  * 
                  *  Postconditions:
                  *    return_value == 0
                  */
   117          return false;
   118      }
   119      
   120      /** {@inheritDoc} */
   121      public Object getValueAt(final int rowIndex, final int columnIndex) {
                 /* 
    P/P           *  Method: Object getValueAt(int, int)
                  * 
                  *  Preconditions:
                  *    columnIndex in {0..2}
                  *    rowIndex in {0..232-2}
                  *    this.aliases != null
                  * 
                  *  Presumptions:
                  *    java.util.List:get(...)@130 != null
                  *    java.util.List:get(...)@132 != null
                  *    java.util.List:get(...)@134 != null
                  *    java.util.List:size(...)@122 >= 1
                  *    java.util.List:size(...)@122 - rowIndex in {1..232-1}
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  * 
                  *  Test Vectors:
                  *    columnIndex: {0}, {1}, {2}
                  */
   122          if (aliases.size() <= rowIndex) {
   123              throw new IndexOutOfBoundsException(rowIndex + " >= " + aliases.size());
   124          }
   125          if (rowIndex < 0) {
   126              throw new IllegalArgumentException("Must specify a positive integer");
   127          }
   128          switch(columnIndex) {
   129              case 0:
   130                  return aliases.get(rowIndex).getCommand();
   131              case 1:
   132                  return aliases.get(rowIndex).getArgsArgument();
   133              case 2:
   134                  return aliases.get(rowIndex).getResponse();
   135              default:
   136                  throw new IllegalArgumentException("Unknown column: "
   137                          + columnIndex);
   138          }
   139      }
   140      
   141      /** {@inheritDoc} */
   142      public void setValueAt(final Object aValue, final int rowIndex,
   143              final int columnIndex) {
                 /* 
    P/P           *  Method: void setValueAt(Object, int, int)
                  * 
                  *  Preconditions:
                  *    columnIndex in {0..2}
                  *    rowIndex in {0..232-2}
                  *    this.aliases != null
                  * 
                  *  Presumptions:
                  *    com.dmdirc.actions.wrappers.Alias:getArguments(...)@155 != null
                  *    java.util.List:get(...)@152 != null
                  *    java.util.List:get(...)@155 != null
                  *    java.util.List:get(...)@158 != null
                  *    java.util.List:size(...)@144 >= 1
                  *    ...
                  * 
                  *  Test Vectors:
                  *    columnIndex: {0}, {1}, {2}
                  */
   144          if (aliases.size() <= rowIndex) {
   145              throw new IndexOutOfBoundsException(rowIndex + " >= " + aliases.size());
   146          }
   147          if (rowIndex < 0) {
   148              throw new IllegalArgumentException("Must specify a positive integer");
   149          }
   150          switch(columnIndex) {
   151              case 0:
   152                  aliases.get(rowIndex).setCommand((String) aValue);
   153                  break;
   154              case 1:
   155                  aliases.get(rowIndex).getArguments().set(1, (ActionCondition) aValue);
   156                  break;
   157              case 2:
   158                  aliases.get(rowIndex).setResponse((String[]) aValue);
   159                  break;
   160              default:
   161                  throw new IllegalArgumentException("Unknown column: "
   162                          + columnIndex);
   163          }
   164          fireTableCellUpdated(rowIndex, columnIndex);
   165      }
   166      
   167      /**
   168       * Gets the alias at the specified row.
   169       *
   170       * @param rowIndex Row to retrieve
   171       *
   172       * @return Specified Alias
   173       */
   174      public Alias getAlias(final int rowIndex) {
                 /* 
    P/P           *  Method: Alias getAlias(int)
                  * 
                  *  Preconditions:
                  *    this.aliases != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   175          return aliases.get(rowIndex);
   176      }
   177      
   178      /**
   179       * Gets a list of all aliases (including deleted ones).
   180       *
   181       * @return Complete alias list
   182       */
   183      public List<Alias> getAliases() {
                 /* 
    P/P           *  Method: List getAliases()
                  * 
                  *  Preconditions:
                  *    init'ed(this.aliases)
                  * 
                  *  Postconditions:
                  *    return_value == &amp;new ArrayList(getAliases#1)
                  *    new ArrayList(getAliases#1) num objects == 1
                  */
   184          return new ArrayList<Alias>(aliases);
   185      }
   186      
   187      /**
   188       * Adds an alias to the list.
   189       *
   190       * @param alias Alias to add
   191       */
   192      public void addRow(final Alias alias) {
                 /* 
    P/P           *  Method: void addRow(Alias)
                  * 
                  *  Preconditions:
                  *    this.aliases != null
                  */
   193          aliases.add(alias);
   194          fireTableRowsInserted(aliases.indexOf(alias), aliases.indexOf(alias));
   195      }
   196      
   197      /**
   198       * Removes a specified row from the list.
   199       *
   200       * @param row Row to remove
   201       */
   202      public void removeRow(final int row) {
                 /* 
    P/P           *  Method: void removeRow(int)
                  * 
                  *  Preconditions:
                  *    this.aliases != null
                  */
   203          aliases.remove(row);
   204          fireTableRowsDeleted(row, row);
   205      }
   206      
   207      /**
   208       * Returns the index of the specified alias.
   209       *
   210       * @param alias Alias to get index of
   211       *
   212       * @return Index of the alias or -1 if not found.
   213       */
   214      public int indexOf(final Alias alias) {
                 /* 
    P/P           *  Method: int indexOf(Alias)
                  * 
                  *  Preconditions:
                  *    this.aliases != null
                  * 
                  *  Postconditions:
                  *    init'ed(return_value)
                  */
   215          return aliases.indexOf(alias);
   216      }
   217  }








SofCheck Inspector Build Version : 2.17854
AliasTableModel.java 2009-Jun-25 01:54:24
AliasTableModel.class 2009-Sep-02 17:04:16