- java.lang.Object
-
- com.googlecode.lanterna.gui2.table.TableModel<V>
-
public class TableModel<V> extends java.lang.Object
ATableModel
contains the data model behind a table, here is where all the action cell values and header labels are stored.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
TableModel.Listener<V>
Listener interface for theTableModel
class which can be attached to aTableModel
to be notified of changes to the table model.
-
Constructor Summary
Constructors Constructor Description TableModel(java.lang.String... columnLabels)
Default constructor, creates a new model with same number of columns as labels supplied
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TableModel<V>
addColumn(java.lang.String label, V[] newColumnValues)
Adds a new column into the table model as the last column.TableModel<V>
addListener(TableModel.Listener<V> listener)
Adds a listener to this table model that will be notified whenever the model changesTableModel<V>
addRow(java.util.Collection<V> values)
Adds a new row to the table model at the end.TableModel<V>
addRow(V... values)
Adds a new row to the table model at the end.TableModel<V>
clear()
Removes all rows from the table, this will trigger listeners for each rowV
getCell(int columnIndex, int rowIndex)
Returns the cell value stored at a specific column/row coordinate.int
getColumnCount()
Returns the number of columns in the modeljava.lang.String
getColumnLabel(int index)
Returns the label of a column headerjava.util.List<java.lang.String>
getColumnLabels()
Returns all column header label as a list of stringsjava.util.List<V>
getRow(int index)
Returns a row from the table as a list of the cell dataint
getRowCount()
Returns number of rows in the modeljava.util.List<java.util.List<V>>
getRows()
Returns all rows in the model as a list of lists containing the data as elementsTableModel<V>
insertColumn(int index, java.lang.String label, V[] newColumnValues)
Adds a new column into the table model at a specified index.TableModel<V>
insertRow(int index, java.util.Collection<V> values)
Inserts a new row to the table model at a particular index.TableModel<V>
removeColumn(int index)
Removes a column from the table modelTableModel<V>
removeListener(TableModel.Listener<V> listener)
Removes a listener from this model so that it will no longer receive any notifications when the model changesTableModel<V>
removeRow(int index)
Removes a row at a particular index from the table model.TableModel<V>
setCell(int columnIndex, int rowIndex, V value)
Updates the call value stored at a specific column/row coordinate.TableModel<V>
setColumnLabel(int index, java.lang.String newLabel)
Updates the label of a column header
-
-
-
Field Detail
-
columns
private final java.util.List<java.lang.String> columns
-
rows
private final java.util.List<java.util.List<V>> rows
-
listeners
private final java.util.List<TableModel.Listener<V>> listeners
-
-
Method Detail
-
getColumnCount
public int getColumnCount()
Returns the number of columns in the model- Returns:
- Number of columns in the model
-
getRowCount
public int getRowCount()
Returns number of rows in the model- Returns:
- Number of rows in the model
-
getRows
public java.util.List<java.util.List<V>> getRows()
Returns all rows in the model as a list of lists containing the data as elements- Returns:
- All rows in the model as a list of lists containing the data as elements
-
getColumnLabels
public java.util.List<java.lang.String> getColumnLabels()
Returns all column header label as a list of strings- Returns:
- All column header label as a list of strings
-
getRow
public java.util.List<V> getRow(int index)
Returns a row from the table as a list of the cell data- Parameters:
index
- Index of the row to return- Returns:
- Row from the table as a list of the cell data
-
addRow
@SafeVarargs public final TableModel<V> addRow(V... values)
Adds a new row to the table model at the end. This may update the selection to make sure the same row is selected.- Parameters:
values
- Data to associate with the new row, mapped column by column in order- Returns:
- Itself
-
addRow
public TableModel<V> addRow(java.util.Collection<V> values)
Adds a new row to the table model at the end. This may update the selection to make sure the same row is selected.- Parameters:
values
- Data to associate with the new row, mapped column by column in order- Returns:
- Itself
-
insertRow
public TableModel<V> insertRow(int index, java.util.Collection<V> values)
Inserts a new row to the table model at a particular index. This may update the selection to make sure the same row is selected.- Parameters:
index
- Index the new row should have, 0 means the first row and row count will append the row at the endvalues
- Data to associate with the new row, mapped column by column in order- Returns:
- Itself
-
removeRow
public TableModel<V> removeRow(int index)
Removes a row at a particular index from the table model. This may update the selection to make sure the same row is selected.- Parameters:
index
- Index of the row to remove- Returns:
- Itself
-
clear
public TableModel<V> clear()
Removes all rows from the table, this will trigger listeners for each row- Returns:
- Itself
-
getColumnLabel
public java.lang.String getColumnLabel(int index)
Returns the label of a column header- Parameters:
index
- Index of the column to retrieve the header label for- Returns:
- Label of the column selected
-
setColumnLabel
public TableModel<V> setColumnLabel(int index, java.lang.String newLabel)
Updates the label of a column header- Parameters:
index
- Index of the column to update the header label fornewLabel
- New label to assign to the column header- Returns:
- Itself
-
addColumn
public TableModel<V> addColumn(java.lang.String label, V[] newColumnValues)
Adds a new column into the table model as the last column. You can optionally supply values for the existing rows through thenewColumnValues
.- Parameters:
label
- Label for the header of the new columnnewColumnValues
- Optional values to assign to the existing rows, where the first element in the array will be the value of the first row and so on...- Returns:
- Itself
-
insertColumn
public TableModel<V> insertColumn(int index, java.lang.String label, V[] newColumnValues)
Adds a new column into the table model at a specified index. You can optionally supply values for the existing rows through thenewColumnValues
.- Parameters:
index
- Index for the new columnlabel
- Label for the header of the new columnnewColumnValues
- Optional values to assign to the existing rows, where the first element in the array will be the value of the first row and so on...- Returns:
- Itself
-
removeColumn
public TableModel<V> removeColumn(int index)
Removes a column from the table model- Parameters:
index
- Index of the column to remove- Returns:
- Itself
-
getCell
public V getCell(int columnIndex, int rowIndex)
Returns the cell value stored at a specific column/row coordinate.- Parameters:
columnIndex
- Column index of the cellrowIndex
- Row index of the cell- Returns:
- The data value stored in this cell
-
setCell
public TableModel<V> setCell(int columnIndex, int rowIndex, V value)
Updates the call value stored at a specific column/row coordinate.- Parameters:
columnIndex
- Column index of the cellrowIndex
- Row index of the cellvalue
- New value to assign to the cell- Returns:
- Itself
-
addListener
public TableModel<V> addListener(TableModel.Listener<V> listener)
Adds a listener to this table model that will be notified whenever the model changes- Parameters:
listener
-TableModel.Listener
to register with this model- Returns:
- Itself
-
removeListener
public TableModel<V> removeListener(TableModel.Listener<V> listener)
Removes a listener from this model so that it will no longer receive any notifications when the model changes- Parameters:
listener
-TableModel.Listener
to deregister from this model- Returns:
- Itself
-
-