001 /* 002 * SyncMsgTableModel.java 003 * 004 * Created on February 21, 2002, 11:52 AM 005 */ 006 007 package edu.tamu.gamebots.ui; 008 import edu.isi.gamebots.client.*; 009 010 /** 011 * <p> 012 * A table model for displaying vision messages from the server based on a 013 * MessageBlock object. Columns: 014 * <ul> 015 * <li>Column 1: Type</li> 016 * <li>Column 2: ID</li> 017 * <li>Column 3: Location</li> 018 * <li>Column 4: Reachable (Boolean)</li> 019 * <ul> 020 * </p> 021 * @author rtr7684 022 */ 023 public class SyncMsgTableModel extends javax.swing.table.AbstractTableModel { 024 025 private MessageBlock msgBlock; 026 private String properties[] = { "Type", "Id", "Location", "Reachable"}; 027 028 /** 029 * <p> 030 * Creates a new instance of SyncMsgTableModel 031 * </p> 032 * @param block The <CODE>MessageBlock</CODE> 033 */ 034 public SyncMsgTableModel(MessageBlock block) { 035 msgBlock = block.onlyNodeMessages(); 036 } 037 038 /** 039 * <p> 040 * Returns the vlaue at a row and column 041 * </p> 042 * @param row The row 043 * @param column THe column 044 * @return The object at the given position 045 */ 046 public Object getValueAt(int row, int column) { 047 Message msg = msgBlock.getMessageAt(row); 048 if(column==0) return msg.getType(); 049 else if(column==3) return Boolean.valueOf(msg.getProperty(properties[column])); 050 else return msg.getProperty(properties[column]); 051 } 052 053 /** 054 * <p> 055 * Given a column number, returns the name of the column. 056 * </p> 057 * @param column The column number 058 * @return The name of the column 059 */ 060 public String getColumnName(int column) { 061 return properties[column]; 062 } 063 064 /** 065 * <p> 066 * Returns the number of rows 067 * </p> 068 * @return The number of visible objects displayed in the table 069 */ 070 public int getRowCount() { 071 return msgBlock.getNumMessages(); 072 } 073 074 /** 075 * <p> 076 * False, no cells are editable 077 * </p> 078 * @param param row number 079 * @param param1 column number 080 * @return false 081 */ 082 public boolean isCellEditable(int param, int param1) { 083 return false; 084 } 085 086 /** 087 * <p> 088 * Set the value of a cell to an object 089 * </p> 090 * @param obj The object to set to 091 * @param param row number 092 * @param param2 column number 093 */ 094 public void setValueAt(Object obj, int param, int param2) { 095 } 096 097 /** 098 * <p> 099 * Returns the class of the data in a given column 100 * </p> 101 * @param col The Column numober 102 * @return the class of that column 103 */ 104 public Class getColumnClass(int col) { 105 if(col == 3) return Boolean.TRUE.getClass(); 106 else return (new String("")).getClass(); 107 } 108 109 /** 110 * <p> 111 * Returns the number of columns in the table 112 * </p> 113 * @return The number of columns 114 */ 115 public int getColumnCount() { 116 return properties.length; 117 } 118 119 }