Package adams.gui.core
Class KeyValuePairTableModel
- java.lang.Object
-
- javax.swing.table.AbstractTableModel
-
- adams.gui.core.AbstractBaseTableModel
-
- adams.gui.core.KeyValuePairTableModel
-
- All Implemented Interfaces:
LoggingLevelHandler
,LoggingSupporter
,SpreadSheetSupporter
,CustomSearchTableModel
,Serializable
,TableModel
- Direct Known Subclasses:
MapTableModel
,PropertiesTableModel
public class KeyValuePairTableModel extends AbstractBaseTableModel implements CustomSearchTableModel
The model for displaying key-value pairs. It is assumed that the key is always a string.- Version:
- $Revision$
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected String[]
m_ColumnNames
the names of the columns.protected Object[][]
m_Data
the data to display.protected boolean
m_Editable
whether the values can be edited.protected boolean
m_Modified
whether the values were modified.-
Fields inherited from class adams.gui.core.AbstractBaseTableModel
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
-
-
Constructor Summary
Constructors Constructor Description KeyValuePairTableModel(Object[][] data)
Initializes the table model.KeyValuePairTableModel(Object[][] data, String[] colNames)
Initializes the table model with custom column names.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Class
getColumnClass(int column)
Returns the class for the column.int
getColumnCount()
Returns the number of columns in the table.String
getColumnName(int column)
Returns the name of the column.String
getKeyAt(int row)
Returns the key at the given position.int
getRowCount()
Returns the number of rows.Object
getValueAt(int row)
Returns the value at the given position.Object
getValueAt(int row, int column)
Returns the value at the given position.boolean
isCellEditable(int rowIndex, int columnIndex)
Returns whether the values are editable.boolean
isEditable()
Returns whether the values are editable or not.boolean
isModified()
Returns whether the values were modified.boolean
isSearchMatch(SearchParameters params, int row)
Tests whether the search matches the specified row.void
setEditable(boolean value)
Sets whether the values will be editable or not.void
setModified(boolean value)
Sets whether the values will were modified.void
setValueAt(Object aValue, int rowIndex, int columnIndex)
Updates the value.-
Methods inherited from class adams.gui.core.AbstractBaseTableModel
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, setLoggingLevel, toSpreadSheet, toString
-
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface javax.swing.table.TableModel
addTableModelListener, removeTableModelListener
-
-
-
-
Constructor Detail
-
KeyValuePairTableModel
public KeyValuePairTableModel(Object[][] data)
Initializes the table model. The key is always assumed to be of type string.- Parameters:
data
- the key-value pairs to display
-
-
Method Detail
-
setEditable
public void setEditable(boolean value)
Sets whether the values will be editable or not.- Parameters:
value
- if true the values will be editable
-
isEditable
public boolean isEditable()
Returns whether the values are editable or not.- Returns:
- true if the value are editable
-
setModified
public void setModified(boolean value)
Sets whether the values will were modified.- Parameters:
value
- if true the values were modified
-
isModified
public boolean isModified()
Returns whether the values were modified.- Returns:
- true if the values were modified
-
getRowCount
public int getRowCount()
Returns the number of rows.- Specified by:
getRowCount
in interfaceTableModel
- Returns:
- the number of rows
-
getColumnCount
public int getColumnCount()
Returns the number of columns in the table.- Specified by:
getColumnCount
in interfaceTableModel
- Returns:
- always 2
-
getColumnName
public String getColumnName(int column)
Returns the name of the column.- Specified by:
getColumnName
in interfaceTableModel
- Overrides:
getColumnName
in classAbstractTableModel
- Parameters:
column
- the column to retrieve the name for- Returns:
- the name of the column
-
getValueAt
public Object getValueAt(int row, int column)
Returns the value at the given position. Multi-line content gets shortened.- Specified by:
getValueAt
in interfaceTableModel
- Parameters:
row
- the row in the tablecolumn
- the column in the table- Returns:
- the value
- See Also:
getValueAt(int, int)
-
getKeyAt
public String getKeyAt(int row)
Returns the key at the given position.- Parameters:
row
- the row in the table- Returns:
- the key
-
getValueAt
public Object getValueAt(int row)
Returns the value at the given position.- Parameters:
row
- the row in the table- Returns:
- the value
-
isCellEditable
public boolean isCellEditable(int rowIndex, int columnIndex)
Returns whether the values are editable.- Specified by:
isCellEditable
in interfaceTableModel
- Overrides:
isCellEditable
in classAbstractTableModel
- Parameters:
rowIndex
- the row being queriedcolumnIndex
- the column being queried- Returns:
- true if editable
-
setValueAt
public void setValueAt(Object aValue, int rowIndex, int columnIndex)
Updates the value.- Specified by:
setValueAt
in interfaceTableModel
- Overrides:
setValueAt
in classAbstractTableModel
- Parameters:
aValue
- value to assign to cellrowIndex
- row of cellcolumnIndex
- column of cell
-
getColumnClass
public Class getColumnClass(int column)
Returns the class for the column.- Specified by:
getColumnClass
in interfaceTableModel
- Overrides:
getColumnClass
in classAbstractTableModel
- Parameters:
column
- the column to retrieve the class for- Returns:
- the class
-
isSearchMatch
public boolean isSearchMatch(SearchParameters params, int row)
Tests whether the search matches the specified row.- Specified by:
isSearchMatch
in interfaceCustomSearchTableModel
- Parameters:
params
- the search parametersrow
- the row of the underlying, unsorted model- Returns:
- true if the search matches this row
-
-