Package org.opensourcephysics.display
Class DataRowModel
java.lang.Object
javax.swing.table.AbstractTableModel
org.opensourcephysics.display.DataRowModel
- All Implemented Interfaces:
Serializable
,TableModel
BH 2020.03.30 note:
DataRowTable is used in ThreeStateNuclearDecay, where it tracks the three
nuclear states over time.
The symptom in SwingJS was that it was taking an inordinant amount of time to
append to the table and to scroll it, and there was a huge amount of activity
just in adding a new row.
The problem turned out to be calls to DataRowTable.refreshTable(), which was
firing a full table rebuild -- basically a clean sweep of all rows and
columns -- every time a row was added.
The solution was to disambiguate the calls to refreshTable() as
refreshTable(String type), allowing a more nuanced approach. In addition,
that functionality, arising from DataRowModel, was moved into DataRowModel as
refreshModel(String type).
This solved the basic problem of too many, too full, updates.
The second problem was that in SwingJS we don't necessarily have to repaint a
cell if nothing has changed, particularly during scrolling. "Repainting"
actually amounts to rebuilding the HTML5 structure of the table, leading to
expensive restyling of the DOM.
To avoid this, SwingJS was modified to allow for a null return from
DataRowTable.getCellRenderer(row, column). The new method is
getCellRendererOrNull(int row, int column, boolean isScrolling), which is
called whenever JSTableUI does not absolutely have to recreate a cell from
scratch -- during scrolling particularly.
- Author:
- hansonr and others
- See Also:
-
Field Summary
FieldsFields inherited from class javax.swing.table.AbstractTableModel
listenerList
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
Appends a row to this table.void
clear()
Clear the dataint
Gets the number of columns being shown.getColumnName
(int column) Gets the name of the specified column.int
Gets the number of rows.getValueAt
(int row, int column) Gets the value at the given cell.boolean
mustPaint
(int row, int column) boolean
setColumnNames
(int column, String name) Sets the column names in this table.void
setFirstRowIndex
(int index) Sets the first row's index.void
setMaxPoints
(int max) Sets the maximum number of rows the data can holdboolean
setRowNumberVisible
(boolean vis) Sets the display row number flag.void
setStride
(int stride) Sets the stride between rows.Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getColumnClass, getListeners, getTableModelListeners, isCellEditable, removeTableModelListener, setValueAt
-
Field Details
-
FINAL_UPDATE
- See Also:
-
-
Constructor Details
-
DataRowModel
public DataRowModel()Constructor DataRowModel
-
-
Method Details
-
setStride
public void setStride(int stride) Sets the stride between rows.- Parameters:
tableModel
-stride
-
-
setMaxPoints
public void setMaxPoints(int max) Sets the maximum number of rows the data can hold -
clear
public void clear()Clear the data -
appendRow
Appends a row to this table.- Parameters:
obj
- Object- Throws:
IllegalArgumentException
-
setRowNumberVisible
public boolean setRowNumberVisible(boolean vis) Sets the display row number flag. Table displays row number.- Parameters:
vis
-true<\code> if table display row number
- Returns:
- true if table display changed
-
setColumnNames
Sets the column names in this table.- Parameters:
column
- the column indexname
-- Returns:
- true if name changed or added
-
setFirstRowIndex
public void setFirstRowIndex(int index) Sets the first row's index.- Parameters:
index
-
-
getColumnCount
public int getColumnCount()Gets the number of columns being shown.- Returns:
- the column count
-
getColumnName
Gets the name of the specified column.- Specified by:
getColumnName
in interfaceTableModel
- Overrides:
getColumnName
in classAbstractTableModel
- Parameters:
column
- the column index- Returns:
- the column name
-
getRowCount
public int getRowCount()Gets the number of rows.- Returns:
- the row count
-
getValueAt
Gets the value at the given cell.- Parameters:
row
- the row indexcolumn
- the column index- Returns:
- the value
-
mustPaint
public boolean mustPaint(int row, int column)
-