Package com.jk.core.model.table
Class JKTableModel
java.lang.Object
javax.swing.table.AbstractTableModel
com.jk.core.model.table.JKTableModel
- All Implemented Interfaces:
Serializable
,TableModel
- Direct Known Subclasses:
JKMapTableModel
This class is a table model that extends
AbstractTableModel
to
provide flexibility and control over table data and behavior.- Version:
- 1.0
- Author:
- Dr. Jalal H. Kiswani
- See Also:
-
Field Summary
Fields inherited from class javax.swing.table.AbstractTableModel
listenerList
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
This method adds a new column to the table model.void
addJKTableColumn
(String keyLabel) This method adds a new column to the table with the specified header name.This method adds a new record to the table model.void
addRecord
(JKTableRecord record) This method adds a new record to the table model.void
This method clears all the records contained within this table model.protected JKTableRecord
This method creates a newJKTableRecord
which is empty.deleteRow
(int selectedRow) This method deletes an entire row from the table that is at the given index.void
deleteRows
(int[] rows) This method deletes the rows that are at the given indices.void
fireTableColumnDataChanged
(int col) This method notifies the listeners that all the values in the specified columns have been changed.int
This method gets the number of actual columns.int
getActualColumnIndexFromVisible
(int visibleIndex) This method gets the actual column index from the visible index.getActualColumnName
(int index) This method gets the column name using the actual index.getCellEditor
(int column) This method gets the cell editor using the column this cell is in.getCellRenderer
(int column) This method gets the cell renderer using the column this cell is in.getColumnClass
(int columnIndex) This method gets the column class whose index is specified.int
Returns the number of columns in the model.getColumnName
(int visibleColumnIndex) This method gets the column name using the given visible column index.int
getColumnType
(int col) This method gets the column type to the column whose index is provided.int
getColunmIndex
(String name) This method gets the column index using its name.int
getColunmIndexByName
(String colName) This method gets the column index by the column name.double
getColunmSum
(int col) This method sums all the values inside the column whose index is provided.This method gets the deleted records.This method gets the deleted records.getFormatter
(int col) This method gets the formatter associated with the specified column.int
getIntegerColunmSum
(int col) This method sums all the values inside the column whose index is provided.int
getPrefferedWidth
(int column) This method gets the preferred width of the specified column.getRecord
(int row) This method gets the record associated with the given index.This method gets all the records.This method gets all the records.int
Returns the number of rows in the model.getTableColumn
(int visibleColumnIndex) This method gets the table column associated with the provided visible index.getTableColumn
(int col, boolean visibleIndex) This method gets the table column using the provided index.This method returns all the table columns model.getValueAt
(int row, int visibleColumnIndex) Returns the value for the cell atcolumnIndex
androwIndex
.double
getValueAtAsDouble
(int row, int col) This method gets the value at the cell with the provided coordinate as a double.float
getValueAtAsFloat
(int row, int col) This method gets the value at the cell with the provided coordinate as a float.int
getValueAtAsInteger
(int row, int col) This method gets the value at the cell with the provided coordinate as a integer.int
getVisibleColumnIndexFromActual
(int actualIndex) This method gets the visible column index from the provided actual index.void
insertRecord
(int selectedRow) This method insert an empty record at the specified row index.void
insertRecord
(int row, JKTableRecord record) This method insert the specified record at the provided row index.boolean
This method checks that the column values do not containnull
values.boolean
This method checks if this table allow deletion of data.boolean
This method checks if the data have been modified.boolean
This method checks if this table is editable.boolean
isEditable
(int column) This method checks that the column at the provided index is editable.boolean
isEditable
(int row, int column) This method checks if the cell at the provided coordinate is editable.boolean
isNumericClumn
(int visibleColIndex) This method checks whether this column contains numeric value or not.protected boolean
isValidTableColumnIndex
(int actualIndex) This method checks the provided index if it belongs to a valid column or not.boolean
isVisible
(int col) This method checks whether the column associated with the provided index is visible or not.void
This method re-index all the visible columns indices.removeRecord
(int row) This method remove the record associated with the provided index.void
This method clears all the records inside the table.void
setAllowDelete
(boolean allowDelete) This method specify whether this table should allow cell deletion or not.void
setColumnValue
(int row, int col, Object value, boolean visibleIndex) This method changes the value of the cell at the provided coordinate.void
setEditable
(boolean editable) This method specify whether this table is editable or not.void
setEditable
(int column, boolean editable) This method specify whether the provided column is editable or not.void
setEditable
(int row, int col, boolean enable) This method specify whether the cell at the provided coordinate is editable or not.void
setEditor
(int colunm, TableCellEditor cellEditor) This method sets the column editor to the provided editor.void
setFormatter
(int col, Format formatter) This method sets the column formatter to the provided formatter.void
setPreferredWidth
(int col, int width) This method sets the column preferred width.void
setRenderer
(int col, TableCellRenderer cellRenderer) This method sets the column renderer to the provided renderer.void
setRequired
(int col, boolean required) This method specify whether the provided column is required or not.void
setValueAt
(Object value, int rowIndex, int visibleIndex) Sets the value in the cell at specified coordinate to the provided value.void
setVisible
(int col, boolean visible) This method specify whether the provided column is visible or not.void
setVisibleByActualIndex
(int colunmIndex, boolean visible) This method specify whether the provided column is visible or not.Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, isCellEditable, removeTableModelListener
-
Constructor Details
-
JKTableModel
public JKTableModel()This method constructs a newJKTableModel
.
-
-
Method Details
-
addJKTableColumn
This method adds a new column to the table model.- Parameters:
col
- Specifies the new column.
-
addRecord
This method adds a new record to the table model.- Returns:
- the newly added record.
-
addRecord
This method adds a new record to the table model.- Parameters:
record
- Specifies the new record.
-
clearRecords
public void clearRecords()This method clears all the records contained within this table model.This table model will have no records after this method call.
-
createEmptyRecord
This method creates a newJKTableRecord
which is empty.- Returns:
- the newly generated table record.
-
deleteRow
This method deletes an entire row from the table that is at the given index.- Parameters:
selectedRow
- Specifies the selected row index.- Returns:
- returns the row that got deleted.
-
deleteRows
public void deleteRows(int[] rows) This method deletes the rows that are at the given indices.- Parameters:
rows
- Specifies the rows that are to be removed indices.
-
fireTableColumnDataChanged
public void fireTableColumnDataChanged(int col) This method notifies the listeners that all the values in the specified columns have been changed.- Parameters:
col
- Specifies the column index whose cells have been changed.
-
getActualColumnCount
public int getActualColumnCount()This method gets the number of actual columns.- Returns:
- the number of actual columns.
-
getActualColumnIndexFromVisible
public int getActualColumnIndexFromVisible(int visibleIndex) This method gets the actual column index from the visible index.- Parameters:
visibleIndex
- Specifies the visible index.- Returns:
- the actual column index.
-
getActualColumnName
This method gets the column name using the actual index.- Parameters:
index
- Specifies the column index.- Returns:
- the column name.
-
getCellEditor
This method gets the cell editor using the column this cell is in.- Parameters:
column
- Specifies the column the cell is in.- Returns:
- the cell editor.
-
getCellRenderer
This method gets the cell renderer using the column this cell is in.- Parameters:
column
- Specifies the column the cell is in.- Returns:
- the cell renderer.
-
getColumnClass
This method gets the column class whose index is specified.- Specified by:
getColumnClass
in interfaceTableModel
- Overrides:
getColumnClass
in classAbstractTableModel
- Parameters:
columnIndex
- Specifies the column index.- Returns:
- the column class.
-
getColumnCount
public int getColumnCount()Returns the number of columns in the model. AJTable
uses this method to determine how many columns it should create and display by default.- Returns:
- the number of columns in the model
-
getColumnName
This method gets the column name using the given visible column index.- Specified by:
getColumnName
in interfaceTableModel
- Overrides:
getColumnName
in classAbstractTableModel
- Parameters:
visibleColumnIndex
- Specifies the visible column index.- Returns:
- the column name.
-
getColumnType
public int getColumnType(int col) This method gets the column type to the column whose index is provided.- Parameters:
col
- Specifies the column index.- Returns:
- the column type whose index is provided.
-
getColunmIndex
This method gets the column index using its name.- Parameters:
name
- Specifies the column name.- Returns:
- the column index.
-
getColunmIndexByName
This method gets the column index by the column name.- Parameters:
colName
- Specifies the column name.- Returns:
- the column index.
-
getColunmSum
public double getColunmSum(int col) This method sums all the values inside the column whose index is provided.- Parameters:
col
- Specifies the column index whose values are to be summed.- Returns:
- the sum of the values inside the specified column.
-
getDeletedRecords
This method gets the deleted records.- Returns:
- the deleted records.
-
getDeletedRecordsAsDataVector
This method gets the deleted records.- Returns:
- the deleted records.
-
getFormatter
This method gets the formatter associated with the specified column.- Parameters:
col
- Specifies the column index.- Returns:
- the formatter.
-
getIntegerColunmSum
public int getIntegerColunmSum(int col) This method sums all the values inside the column whose index is provided.- Parameters:
col
- Specifies the column index whose values are to be summed.- Returns:
- the sum of the values inside the specified column.
-
getPrefferedWidth
public int getPrefferedWidth(int column) This method gets the preferred width of the specified column.- Parameters:
column
- Specifies the column index.- Returns:
- the preferred width
-
getRecord
This method gets the record associated with the given index.- Parameters:
row
- Specifies the record index.- Returns:
- the record.
-
getRecords
This method gets all the records.- Returns:
- the records.
-
getRecordsAsDataVector
This method gets all the records.- Returns:
- the records.
-
getRowCount
public int getRowCount()Returns the number of rows in the model. AJTable
uses this method to determine how many rows it should display. This method should be quick, as it is called frequently during rendering.- Returns:
- the number of rows in the model
-
getTableColumn
This method gets the table column associated with the provided visible index.- Parameters:
visibleColumnIndex
- Specifies the visible column index.- Returns:
- the table column.
-
getTableColumn
This method gets the table column using the provided index.if the provided boolean value is true, the provided index is visible index, if its false, the provided index is an actual index.
- Parameters:
col
- Specifies the column index.visibleIndex
- Indicated whether the index is a visible index or an actual index.- Returns:
- the table column.
-
getValueAt
Returns the value for the cell atcolumnIndex
androwIndex
.- Parameters:
row
- the row whose value is to be queriedvisibleColumnIndex
- the column whose value is to be queried- Returns:
- the value Object at the specified cell
-
getValueAtAsDouble
public double getValueAtAsDouble(int row, int col) This method gets the value at the cell with the provided coordinate as a double.- Parameters:
row
- Specifies the row the cell is atcol
- Specifies the visible index of the column the cell is in.- Returns:
- the value at the specified cell as double.
-
getValueAtAsFloat
public float getValueAtAsFloat(int row, int col) This method gets the value at the cell with the provided coordinate as a float.- Parameters:
row
- Specifies the row the cell is atcol
- Specifies the visible index of the column the cell is in.- Returns:
- the value at the specified cell as float.
-
getValueAtAsInteger
public int getValueAtAsInteger(int row, int col) This method gets the value at the cell with the provided coordinate as a integer.- Parameters:
row
- Specifies the row the cell is atcol
- Specifies the visible index of the column the cell is in.- Returns:
- the value at the specified cell as integer.
-
getVisibleColumnIndexFromActual
public int getVisibleColumnIndexFromActual(int actualIndex) This method gets the visible column index from the provided actual index.- Parameters:
actualIndex
- Specifies the column actual index.- Returns:
- the visible column index.
-
insertRecord
public void insertRecord(int selectedRow) This method insert an empty record at the specified row index.- Parameters:
selectedRow
- Specifies the new record index.
-
insertRecord
This method insert the specified record at the provided row index.- Parameters:
row
- Specifies the new record index.record
- Specifies the new record to be added.
-
isAllDataValid
public boolean isAllDataValid()This method checks that the column values do not containnull
values.- Returns:
- true, if all data are valid, false otherwise.
-
isAllowDelete
public boolean isAllowDelete()This method checks if this table allow deletion of data.- Returns:
- true, if this table allow cell deletion and is editable, false otherwise.
-
isDataModified
public boolean isDataModified()This method checks if the data have been modified.- Returns:
- true, if the data have been modified, false otherwise.
-
isEditable
public boolean isEditable()This method checks if this table is editable.This method will return true even if only one column is editable.
- Returns:
- true, if it is editable, false otherwise.
-
isEditable
public boolean isEditable(int column) This method checks that the column at the provided index is editable.- Parameters:
column
- Specifies the column index.- Returns:
- true, if it is editable, false otherwise.
-
isEditable
public boolean isEditable(int row, int column) This method checks if the cell at the provided coordinate is editable.- Parameters:
row
- Specifies the row the cell is at.column
- Specifies the column the cell is in.- Returns:
- true, if it is editable, false otherwise.
-
isNumericClumn
public boolean isNumericClumn(int visibleColIndex) This method checks whether this column contains numeric value or not.- Parameters:
visibleColIndex
- Specifies the visible column index.- Returns:
- true, if it contains numeric values, false otherwise.
-
isValidTableColumnIndex
protected boolean isValidTableColumnIndex(int actualIndex) This method checks the provided index if it belongs to a valid column or not.- Parameters:
actualIndex
- Specifies the actual column index.- Returns:
- true, if it is valid column index, false otherwise.
-
isVisible
public boolean isVisible(int col) This method checks whether the column associated with the provided index is visible or not.- Parameters:
col
- Specifies the column index.- Returns:
- true, if it is visible, false otherwise.
-
refreshVisibility
public void refreshVisibility()This method re-index all the visible columns indices. -
removeRecord
This method remove the record associated with the provided index.- Parameters:
row
- Specifies the row index.- Returns:
- the removed record.
-
resetRecords
public void resetRecords()This method clears all the records inside the table. -
setAllowDelete
public void setAllowDelete(boolean allowDelete) This method specify whether this table should allow cell deletion or not.- Parameters:
allowDelete
- Indicates the new allow deletion value.
-
setColumnValue
This method changes the value of the cell at the provided coordinate.if the provided column index is a visible index not an actual one, it will get the actual index associated with the visible index and use it instead.
- Parameters:
row
- Specifies the row the cell is at.col
- Specifies the column the cell is in.value
- Specifies the cell value.visibleIndex
- Indicates whether the provided column index is a visible index or an actual index.
-
setEditable
public void setEditable(boolean editable) This method specify whether this table is editable or not.- Parameters:
editable
- Indicates the new editable value.
-
setEditable
public void setEditable(int column, boolean editable) This method specify whether the provided column is editable or not.- Parameters:
column
- Specifies the column index.editable
- Indicates the new editable value of the column.
-
setEditable
public void setEditable(int row, int col, boolean enable) This method specify whether the cell at the provided coordinate is editable or not.- Parameters:
row
- Specifies the row the cell is at.col
- Specifies the column the cell is in.enable
- Indicates the new editable value of the cell.
-
setEditor
This method sets the column editor to the provided editor.- Parameters:
colunm
- Specifies the column index.cellEditor
- Specifies the new column editor.
-
setFormatter
This method sets the column formatter to the provided formatter.- Parameters:
col
- Specifies the column index.formatter
- Specifies the new column formatter.
-
setPreferredWidth
public void setPreferredWidth(int col, int width) This method sets the column preferred width.- Parameters:
col
- Specifies the column indexwidth
- Specifies the new width.
-
setRenderer
This method sets the column renderer to the provided renderer.- Parameters:
col
- Specifies the column index.cellRenderer
- Specifies the new column renderer.
-
setRequired
public void setRequired(int col, boolean required) This method specify whether the provided column is required or not.- Parameters:
col
- Specifies the column index.required
- Indicates the new required value of the column.
-
setValueAt
Sets the value in the cell at specified coordinate to the provided value.- Specified by:
setValueAt
in interfaceTableModel
- Overrides:
setValueAt
in classAbstractTableModel
- Parameters:
value
- Specifies the new value.rowIndex
- Specifies the row index where the cell is at.visibleIndex
- Specifies the column visible index where the cell is in.
-
setVisible
public void setVisible(int col, boolean visible) This method specify whether the provided column is visible or not.- Parameters:
col
- Specifies the column visible index.visible
- Indicates the new visible value of the column.
-
setVisibleByActualIndex
public void setVisibleByActualIndex(int colunmIndex, boolean visible) This method specify whether the provided column is visible or not.- Parameters:
colunmIndex
- Specifies the column actual index.visible
- Indicates the new visible value of the column.
-
addJKTableColumn
This method adds a new column to the table with the specified header name.- Parameters:
keyLabel
- Specifies the new column name.
-
getTableColumns
This method returns all the table columns model.- Returns:
- table columns model.
-