View Javadoc

1   /*
2   @See License.txt@
3    */
4   
5   package spellcast.ui;
6   
7   import java.util.*;
8   import javax.swing.table.*;
9   import spellcast.net.*;
10  
11  /***
12   * This class represents the table model for storing a server list.
13   * It is necessary because a JTable requires a model for displaying
14   * the table's data and we want to be able to work with <code>ServerStatus</class>  
15   * classes more closely.
16   *
17   * @author Barrie Treloar
18   */
19  public class ServerListTableModel extends AbstractTableModel
20  {
21      private ArrayList servers;
22      private String[] columnHeaders;
23  
24      public ServerListTableModel()
25      {
26          columnHeaders = ServerStatus.getColumnHeaders();
27          servers = new ArrayList( 5 );
28      }
29  
30      public void add( ServerStatus ss )
31      {
32          if ( ! servers.contains( ss ) )
33          {
34              servers.add( ss );
35              fireTableDataChanged();
36          }
37      }
38  
39      public void remove( ServerStatus ss )
40      {
41          servers.remove( ss );
42          fireTableDataChanged();
43      }
44  
45      public void clear()
46      {
47          servers.clear();
48          fireTableDataChanged();
49      }
50      
51      public boolean contains( ServerStatus ss )
52      {
53          return servers.contains( ss );
54      }
55  
56      public Iterator servers()
57      {
58          return servers.iterator();
59      }
60      
61      public ServerStatus get( int row )
62      {
63          return (ServerStatus)servers.get( row );
64      }
65  
66      public int getColumnCount() 
67      { 
68          return columnHeaders.length;
69      }
70      public int getRowCount() 
71      { 
72          return servers.size();
73      }
74  
75      public Object getValueAt( int row, int col ) 
76      {
77          ServerStatus obj = (ServerStatus)servers.get( row );
78          
79          return obj.get( col );
80      }
81  
82      public String getColumnName( int column ) 
83      { 
84          return columnHeaders[column];
85      }
86  
87      public Class getColumnClass( int col ) 
88      {
89          return getValueAt(0,col).getClass();
90      }
91  
92      public boolean isCellEditable( int row, int col ) 
93      {
94          return false;
95      }
96  }