Package adams.gui.core
Class SpreadSheetTableModel
- java.lang.Object
-
- javax.swing.table.AbstractTableModel
-
- adams.gui.core.AbstractBaseTableModel
-
- adams.gui.core.SpreadSheetTableModel
-
- All Implemented Interfaces:
CleanUpHandler
,LoggingLevelHandler
,LoggingSupporter
,SpreadSheetSupporter
,ComparableTableModel
,Serializable
,TableModel
- Direct Known Subclasses:
SpreadSheetCellSelector.TableModel
public class SpreadSheetTableModel extends AbstractBaseTableModel implements ComparableTableModel, CleanUpHandler
The table model for displaying a SpreadSheet object.- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_MAX_COLUMN_CHARS
the default maximum column width.protected CellRenderingCustomizer
m_CellRenderingCustomizer
for customizing the cell rendering.protected Cell.ContentType[]
m_ColumnType
the types of the columns.protected boolean
m_Modified
whether the model is modified.protected int
m_NumDecimals
the number of decimals to display.protected boolean
m_ReadOnly
whether the model is read-only (default).protected SpreadSheet
m_Sheet
the underlying spreadsheet.protected boolean
m_ShowCellTypes
whether to show the types instead of the values.protected boolean
m_ShowFormulas
whether to show formulas rather than the result.protected boolean
m_ShowRowColumn
whether to show the row column as well.protected boolean
m_UseSimpleHeader
whether to use a simple header.protected static Integer
MAX_COLUMN_CHARS
the maximum column width.static String
MAX_COLUMN_CHARS_KEY
the key in GUIHelper.props for looking up the maximum chars in columns.-
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 SpreadSheetTableModel()
Initializes the model with an empty spread sheet.SpreadSheetTableModel(SpreadSheet sheet)
Initializes the model with the given spread sheet.SpreadSheetTableModel(SpreadSheet sheet, int numDec)
Initializes the model with the given spread sheet and number of decimals to display.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
cleanUp()
Cleans up data structures, frees up memory.protected Cell.ContentType
determineContentType(int columnIndex)
Determines the content type of the specified column.Cell
getCellAt(int rowIndex, int columnIndex)
Returns the spread sheet cell at the specified location.CellRenderingCustomizer
getCellRenderingCustomizer()
Returns the customizer for cell rendering.Class
getColumnClass(int columnIndex)
Returns the most specific superclass for all the cell values in the column.int
getColumnCount()
Returns the number of columns in the sheet.String
getColumnName(int columnIndex)
Returns the name of the column atcolumnIndex
.Class
getComparisonColumnClass(int columnIndex)
Returns the class type of the column that is used for comparisons.Object
getComparisonValueAt(int row, int column)
Returns the field at the given position.int
getNumDecimals()
Returns the currently set number of decimals.int
getRowCount()
Returns the number of rows in the sheet.SpreadSheet
getSheet()
Returns the underlying spreadsheet.boolean
getShowCellTypes()
Returns whether to show the cell types rather than the cell values.boolean
getShowFormulas()
Returns whether to display the formulas or their calculated values.boolean
getShowRowColumn()
Returns whether the column with the row numbers is displayed.boolean
getUseSimpleHeader()
Returns whether to display a simple header or an HTML one with the column indices.Object
getValueAt(int rowIndex, int columnIndex)
Returns the value for the cell at columnIndex and rowIndex.boolean
isCellEditable(int rowIndex, int columnIndex)
Returns true if the cell atrowIndex
andcolumnIndex
is editable.boolean
isModified()
Returns whether the table model has been modified.boolean
isReadOnly()
Returns whether the table model is read-only.SpreadSheetTableModel
newModel(SpreadSheet sheet)
Creates a new model with the same settings for the provided spreadsheet.void
setCellRenderingCustomizer(CellRenderingCustomizer value)
Sets the customizer for cell rendering.void
setModified(boolean value)
Sets whether the table model has been modified.void
setNumDecimals(int value)
Sets the number of decimals to display.void
setReadOnly(boolean value)
Sets whether the table model is read-only.void
setShowCellTypes(boolean value)
Sets whether to show the cell types rather than the cell values.void
setShowFormulas(boolean value)
Sets whether to display the formulas or their calculated values.void
setShowRowColumn(boolean value)
Whether to display the column with the row numbers.void
setUseSimpleHeader(boolean value)
Whether to display a simple header or an HTML one with the column indices.void
setValueAt(Object aValue, int rowIndex, int columnIndex)
Sets the value in the cell atcolumnIndex
androwIndex
toaValue
.protected String
shortenColumnName(String name)
Shortens the column name, if necessary.SpreadSheet
toSpreadSheet()
Returns the underlying sheet.-
Methods inherited from class adams.gui.core.AbstractBaseTableModel
configureLogger, getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled, setLoggingLevel, 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
-
-
-
-
Field Detail
-
DEFAULT_MAX_COLUMN_CHARS
public static final int DEFAULT_MAX_COLUMN_CHARS
the default maximum column width.- See Also:
- Constant Field Values
-
MAX_COLUMN_CHARS_KEY
public static final String MAX_COLUMN_CHARS_KEY
the key in GUIHelper.props for looking up the maximum chars in columns.- See Also:
- Constant Field Values
-
MAX_COLUMN_CHARS
protected static Integer MAX_COLUMN_CHARS
the maximum column width.
-
m_Sheet
protected SpreadSheet m_Sheet
the underlying spreadsheet.
-
m_NumDecimals
protected int m_NumDecimals
the number of decimals to display.
-
m_CellRenderingCustomizer
protected CellRenderingCustomizer m_CellRenderingCustomizer
for customizing the cell rendering.
-
m_ShowFormulas
protected boolean m_ShowFormulas
whether to show formulas rather than the result.
-
m_ShowRowColumn
protected boolean m_ShowRowColumn
whether to show the row column as well.
-
m_UseSimpleHeader
protected boolean m_UseSimpleHeader
whether to use a simple header.
-
m_ReadOnly
protected boolean m_ReadOnly
whether the model is read-only (default).
-
m_Modified
protected boolean m_Modified
whether the model is modified.
-
m_ShowCellTypes
protected boolean m_ShowCellTypes
whether to show the types instead of the values.
-
m_ColumnType
protected Cell.ContentType[] m_ColumnType
the types of the columns.
-
-
Constructor Detail
-
SpreadSheetTableModel
public SpreadSheetTableModel()
Initializes the model with an empty spread sheet.
-
SpreadSheetTableModel
public SpreadSheetTableModel(SpreadSheet sheet)
Initializes the model with the given spread sheet.- Parameters:
sheet
- the spread sheet to display
-
SpreadSheetTableModel
public SpreadSheetTableModel(SpreadSheet sheet, int numDec)
Initializes the model with the given spread sheet and number of decimals to display.- Parameters:
sheet
- the spread sheet to displaynumDec
- the number of decimals to display
-
-
Method Detail
-
setShowRowColumn
public void setShowRowColumn(boolean value)
Whether to display the column with the row numbers.- Parameters:
value
- true if to display column
-
getShowRowColumn
public boolean getShowRowColumn()
Returns whether the column with the row numbers is displayed.- Returns:
- true if column displayed
-
setUseSimpleHeader
public void setUseSimpleHeader(boolean value)
Whether to display a simple header or an HTML one with the column indices.- Parameters:
value
- true if to display simple header
-
getUseSimpleHeader
public boolean getUseSimpleHeader()
Returns whether to display a simple header or an HTML one with the column indices.- Returns:
- true if simple header displayed
-
setReadOnly
public void setReadOnly(boolean value)
Sets whether the table model is read-only.- Parameters:
value
- true if read-only
-
isReadOnly
public boolean isReadOnly()
Returns whether the table model is read-only.- Returns:
- true if read-only
-
setModified
public void setModified(boolean value)
Sets whether the table model has been modified.- Parameters:
value
- true if modified
-
isModified
public boolean isModified()
Returns whether the table model has been modified.- Returns:
- true if modified
-
setShowCellTypes
public void setShowCellTypes(boolean value)
Sets whether to show the cell types rather than the cell values.- Parameters:
value
- true if to show cell types
-
getShowCellTypes
public boolean getShowCellTypes()
Returns whether to show the cell types rather than the cell values.- Returns:
- true if showing the cell types
-
getRowCount
public int getRowCount()
Returns the number of rows in the sheet.- Specified by:
getRowCount
in interfaceTableModel
- Returns:
- the number of rows
-
getColumnCount
public int getColumnCount()
Returns the number of columns in the sheet.- Specified by:
getColumnCount
in interfaceTableModel
- Returns:
- the number of columns
-
shortenColumnName
protected String shortenColumnName(String name)
Shortens the column name, if necessary.- Parameters:
name
- the original name- Returns:
- the shortened name
- See Also:
DEFAULT_MAX_COLUMN_CHARS
-
getColumnName
public String getColumnName(int columnIndex)
Returns the name of the column atcolumnIndex
. This is used to initialize the table's column header name. Note: this name does not need to be unique; two columns in a table can have the same name.- Specified by:
getColumnName
in interfaceTableModel
- Overrides:
getColumnName
in classAbstractTableModel
- Parameters:
columnIndex
- the index of the column- Returns:
- the name of the column
-
determineContentType
protected Cell.ContentType determineContentType(int columnIndex)
Determines the content type of the specified column.- Parameters:
columnIndex
- the index of the column to determine the type for- Returns:
- the content type
-
getColumnClass
public Class getColumnClass(int columnIndex)
Returns the most specific superclass for all the cell values in the column.- Specified by:
getColumnClass
in interfaceTableModel
- Overrides:
getColumnClass
in classAbstractTableModel
- Parameters:
columnIndex
- the index of the column- Returns:
- the class of the specified column
-
isCellEditable
public boolean isCellEditable(int rowIndex, int columnIndex)
Returns true if the cell atrowIndex
andcolumnIndex
is editable. Otherwise,setValueAt
on the cell will not change the value of that cell.- Specified by:
isCellEditable
in interfaceTableModel
- Overrides:
isCellEditable
in classAbstractTableModel
- Parameters:
rowIndex
- the row whose value to be queriedcolumnIndex
- the column whose value to be queried- Returns:
- true if the cell is editable
-
setValueAt
public void setValueAt(Object aValue, int rowIndex, int columnIndex)
Sets the value in the cell atcolumnIndex
androwIndex
toaValue
.- Specified by:
setValueAt
in interfaceTableModel
- Overrides:
setValueAt
in classAbstractTableModel
- Parameters:
aValue
- the new valuerowIndex
- the row whose value is to be changedcolumnIndex
- the column whose value is to be changed
-
getValueAt
public Object getValueAt(int rowIndex, int columnIndex)
Returns the value for the cell at columnIndex and rowIndex.- Specified by:
getValueAt
in interfaceTableModel
- Parameters:
rowIndex
- the rowcolumnIndex
- the column- Returns:
- the value of the sepcified cell
-
getCellAt
public Cell getCellAt(int rowIndex, int columnIndex)
Returns the spread sheet cell at the specified location.- Parameters:
rowIndex
- the current display row indexcolumnIndex
- the column index- Returns:
- the cell or null if invalid coordinates
-
setNumDecimals
public void setNumDecimals(int value)
Sets the number of decimals to display. Use -1 to display all.- Parameters:
value
- the number of decimals
-
getNumDecimals
public int getNumDecimals()
Returns the currently set number of decimals. -1 if displaying all.- Returns:
- the number of decimals
-
setCellRenderingCustomizer
public void setCellRenderingCustomizer(CellRenderingCustomizer value)
Sets the customizer for cell rendering.- Parameters:
value
- the customizer
-
getCellRenderingCustomizer
public CellRenderingCustomizer getCellRenderingCustomizer()
Returns the customizer for cell rendering.- Returns:
- the customizer
-
setShowFormulas
public void setShowFormulas(boolean value)
Sets whether to display the formulas or their calculated values.- Parameters:
value
- true if to display the formulas rather than the calculated values
-
getShowFormulas
public boolean getShowFormulas()
Returns whether to display the formulas or their calculated values.- Returns:
- true if to display the formulas rather than the calculated values
-
toSpreadSheet
public SpreadSheet toSpreadSheet()
Returns the underlying sheet.- Specified by:
toSpreadSheet
in interfaceSpreadSheetSupporter
- Overrides:
toSpreadSheet
in classAbstractBaseTableModel
- Returns:
- the spread sheet
-
getComparisonColumnClass
public Class getComparisonColumnClass(int columnIndex)
Returns the class type of the column that is used for comparisons.- Specified by:
getComparisonColumnClass
in interfaceComparableTableModel
- Parameters:
columnIndex
- the column to get the class for- Returns:
- the class for the column
-
getComparisonValueAt
public Object getComparisonValueAt(int row, int column)
Returns the field at the given position.- Specified by:
getComparisonValueAt
in interfaceComparableTableModel
- Parameters:
row
- the rowcolumn
- the column (ignored, since only 1 column)- Returns:
- the field
-
newModel
public SpreadSheetTableModel newModel(SpreadSheet sheet)
Creates a new model with the same settings for the provided spreadsheet.- Parameters:
sheet
- the spreadsheet to create a new model for- Returns:
- the new model
-
getSheet
public SpreadSheet getSheet()
Returns the underlying spreadsheet.- Returns:
- the spreadsheet
-
cleanUp
public void cleanUp()
Cleans up data structures, frees up memory.- Specified by:
cleanUp
in interfaceCleanUpHandler
-
-