org.mars_sim.msp.ui.standard.tool.monitor
Class UnitTableModel

java.lang.Object
  extended by javax.swing.table.AbstractTableModel
      extended by org.mars_sim.msp.ui.standard.tool.monitor.UnitTableModel
All Implemented Interfaces:
java.io.Serializable, javax.swing.table.TableModel, UnitListener
Direct Known Subclasses:
PersonTableModel, SettlementTableModel, VehicleTableModel

public abstract class UnitTableModel
extends javax.swing.table.AbstractTableModel
implements UnitListener

The UnitTableModel that maintains a table model of Units objects. It is only a partial implementation of the TableModel interface.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
 
Constructor Summary
protected UnitTableModel(java.lang.String name, java.lang.String suffix, java.lang.String[] names, java.lang.Class[] types)
          Constructs a UnitTableModel object.
 
Method Summary
protected  void addAll(java.util.Collection<Unit> newUnits)
          Adds a collection of units to the model.
protected  void addUnit(Unit newUnit)
          Add a unit to the model.
protected  void clear()
          Clears out units from the model.
protected  boolean containsUnit(Unit unit)
          Checks if unit is in table model already.
 void destroy()
          Prepares the model for deletion.
 boolean equals(java.lang.Object o)
           
 java.lang.Class<?> getColumnClass(int columnIndex)
          Return the type of the column requested.
 int getColumnCount()
          Return the number of columns
 java.lang.String getColumnName(int columnIndex)
          Return the name of the column requested.
 java.lang.String getCountString()
          Gets the model count string.
 java.lang.String getName()
          Get the name of the model.
 java.lang.Object getObject(int row)
          Get the unit at the specified row.
 boolean getOrdered()
          Is this model already ordered according to some external criteria.
 int getRowCount()
          Get the number of rows in the model.
protected  Unit getUnit(int index)
          Get the unit at the specified row.
protected  int getUnitIndex(Unit unit)
          Gets the index of the row a given unit is at.
protected  int getUnitNumber()
          Gets the number of units in the model.
protected  void removeUnit(Unit oldUnit)
          Remove a unit to the model.
 
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, isCellEditable, removeTableModelListener, setValueAt
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.swing.table.TableModel
addTableModelListener, getValueAt, isCellEditable, removeTableModelListener, setValueAt
 
Methods inherited from interface org.mars_sim.msp.simulation.UnitListener
unitUpdate
 

Constructor Detail

UnitTableModel

protected UnitTableModel(java.lang.String name,
                         java.lang.String suffix,
                         java.lang.String[] names,
                         java.lang.Class[] types)
Constructs a UnitTableModel object.

Parameters:
name - Name of the model.
suffix - A string to add to the status message.
names - Names of the columns displayed.
types - The Classes of the individual columns.
Method Detail

addUnit

protected void addUnit(Unit newUnit)
Add a unit to the model.

Parameters:
newUnit - Unit to add to the model.

removeUnit

protected void removeUnit(Unit oldUnit)
Remove a unit to the model.

Parameters:
oldUnit - Unit to remove from the model.

addAll

protected void addAll(java.util.Collection<Unit> newUnits)
Adds a collection of units to the model.

Parameters:
newUnits - the units to add.

clear

protected void clear()
Clears out units from the model.


containsUnit

protected boolean containsUnit(Unit unit)
Checks if unit is in table model already.

Parameters:
unit - the unit to check.
Returns:
true if unit is in table.

getUnitNumber

protected int getUnitNumber()
Gets the number of units in the model.

Returns:
number of units.

getColumnCount

public int getColumnCount()
Return the number of columns

Specified by:
getColumnCount in interface javax.swing.table.TableModel
Returns:
column count.

getColumnClass

public java.lang.Class<?> getColumnClass(int columnIndex)
Return the type of the column requested.

Specified by:
getColumnClass in interface javax.swing.table.TableModel
Overrides:
getColumnClass in class javax.swing.table.AbstractTableModel
Parameters:
columnIndex - Index of column.
Returns:
Class of specified column.

getColumnName

public java.lang.String getColumnName(int columnIndex)
Return the name of the column requested.

Specified by:
getColumnName in interface javax.swing.table.TableModel
Overrides:
getColumnName in class javax.swing.table.AbstractTableModel
Parameters:
columnIndex - Index of column.
Returns:
name of specified column.

getName

public java.lang.String getName()
Get the name of the model.

Returns:
model name.

getRowCount

public int getRowCount()
Get the number of rows in the model.

Specified by:
getRowCount in interface javax.swing.table.TableModel
Returns:
the number of Units.

getOrdered

public boolean getOrdered()
Is this model already ordered according to some external criteria.

Returns:
FALSE as the Units have no natural order.

getUnit

protected Unit getUnit(int index)
Get the unit at the specified row.

Parameters:
index - Index of the row.
Returns:
Unit matching row

getUnitIndex

protected int getUnitIndex(Unit unit)
Gets the index of the row a given unit is at.

Parameters:
unit - the unit to find.
Returns:
the row index or -1 if not in table model.

getObject

public java.lang.Object getObject(int row)
Get the unit at the specified row.

Parameters:
row - Indexes of Unit to retrieve.
Returns:
Unit at specified position.

getCountString

public java.lang.String getCountString()
Gets the model count string.


destroy

public void destroy()
Prepares the model for deletion.


equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object