org.statcato.spreadsheet
Class SpreadsheetModel
- java.lang.Object
-
- javax.swing.table.AbstractTableModel
-
- org.statcato.spreadsheet.SpreadsheetModel
-
- All Implemented Interfaces:
- java.io.Serializable, java.util.EventListener, javax.swing.event.TableModelListener, javax.swing.table.TableModel
public class SpreadsheetModel extends javax.swing.table.AbstractTableModel implements javax.swing.event.TableModelListenerA table model forSpreadsheet.The table data is represented by vectors of vectors of Cell. The first row of the table contains the column/variable names. The row and column numbers of table Cells are not guaranteed to be accurate. Their correctness is ensured when a row/column is retrieved.
- Since:
- 1.0
- See Also:
Spreadsheet, Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description SpreadsheetModel(Statcato app)Constructor given the parent frame.SpreadsheetModel(Statcato app, int rows, int columns)Constructor given the parent frame, number of rows, and number of columns.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidclearCell(int row, int col)Clears the contents in the cell at the specified row and column.voiddeleteCell(int row, int column)Deletes the cell at the specified row and column.voiddeleteCells(int minRow, int maxRow, int minCol, int maxCol)Deletes the cells within the specified range.voiddeleteColumn(int column)Deletes the entire column at the specified column number.voiddeleteRow(int row)Deletes the entire row at the specified row number.java.util.VectorgetAllColumnNumbers()Gets all the column numbers.java.util.Vector<Cell>getColumn(int col)Returns the vector of cells in the given column number.java.lang.ClassgetColumnClass(int c)intgetColumnCount()static java.lang.StringgetColumnLabel(int column)Returns the column label for the given column number.java.lang.StringgetColumnName(int col)Returns the column name at the given column.intgetColumnNumber(java.lang.String label)Returns the column number embedded in the given column label.java.util.VectorgetColumnsWithData()Returns the column number of columns that contain data.java.lang.StringgetCommaSeparatedValues()Returns the table data as a string of comma-separated values.intgetLastNonEmptyColumn()Returns the column number of the last column with data.intgetLastNonEmptyColumn(int row)returns the column number of the last non-empty column in the given row.intgetLastNonEmptyRow()Returns the row number of the last non-empty row.java.util.Vector<Cell>getRow(int row)Returns the vector of cells in the given row number.intgetRowCount()intgetRowNumber(java.lang.String label)Returns the row number from the given row label.java.lang.StringgetTabDelimitedValues()Returns the table data as a string of tab-dlimited values.java.lang.ObjectgetValueAt(int row, int col)java.lang.StringgetVariableName(int col)Returns the variable name at the given column.static booleanhasData(java.lang.Object cell)Returns true if and only if the given cell has data.voidinsertCell(int row, int col)Inserts a blank cell at the specified row and column.voidinsertColumn(int col)Inserts a blank column at the specified column number.voidinsertRow(int row)Inserts a blank row at the specified row number.booleanisCellEditable(int row, int col)voidprintDebugData()Prints debug data.voidsetCellColumn(int column, java.util.Vector<Cell> data)Sets the contents of the given column to the given cell vector.voidsetColumn(int column, java.util.Vector<java.lang.String> data)Sets the contents of the given column to the given data vector.voidsetData(java.util.Vector<java.util.Vector<java.lang.String>> data)Sets the underlying table structure to the given data matrix.voidsetRow(int row, java.util.Vector<java.lang.String> data)Sets the contents of the given row to the given data vector.voidsetStringValueAt(java.lang.String value, int row, int col)Set the string value at the specified row and column.voidsetValueAt(java.lang.Object value, int row, int col)Sets the value at the given row and column to the given value.voidtableChanged(javax.swing.event.TableModelEvent e)-
Methods inherited from class javax.swing.table.AbstractTableModel
addTableModelListener, findColumn, fireTableCellUpdated, fireTableChanged, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, fireTableStructureChanged, getListeners, getTableModelListeners, removeTableModelListener
-
-
-
-
Constructor Detail
-
SpreadsheetModel
public SpreadsheetModel(Statcato app)
Constructor given the parent frame.- Parameters:
app- parent frame
-
SpreadsheetModel
public SpreadsheetModel(Statcato app, int rows, int columns)
Constructor given the parent frame, number of rows, and number of columns.- Parameters:
app- parent framerows- number of rowscolumns- number of columns
-
-
Method Detail
-
getColumn
public java.util.Vector<Cell> getColumn(int col)
Returns the vector of cells in the given column number.- Parameters:
col- column number- Returns:
- vector of cells in the given column
-
getRow
public java.util.Vector<Cell> getRow(int row)
Returns the vector of cells in the given row number.- Parameters:
row- row number- Returns:
- vector of cells in the given row
-
getColumnLabel
public static java.lang.String getColumnLabel(int column)
Returns the column label for the given column number.- Parameters:
column- number- Returns:
- column label
-
getColumnNumber
public int getColumnNumber(java.lang.String label)
Returns the column number embedded in the given column label.- Parameters:
label- column label- Returns:
- column number
-
getRowNumber
public int getRowNumber(java.lang.String label)
Returns the row number from the given row label.- Parameters:
label- row label- Returns:
- row number
-
getLastNonEmptyRow
public int getLastNonEmptyRow()
Returns the row number of the last non-empty row.- Returns:
- row number
-
getLastNonEmptyColumn
public int getLastNonEmptyColumn(int row)
returns the column number of the last non-empty column in the given row.- Parameters:
row- number in which the last non-empty column is found- Returns:
- column number
-
getLastNonEmptyColumn
public int getLastNonEmptyColumn()
Returns the column number of the last column with data.- Returns:
- column number
-
tableChanged
public void tableChanged(javax.swing.event.TableModelEvent e)
- Specified by:
tableChangedin interfacejavax.swing.event.TableModelListener
-
getColumnCount
public int getColumnCount()
- Specified by:
getColumnCountin interfacejavax.swing.table.TableModel
-
getRowCount
public int getRowCount()
- Specified by:
getRowCountin interfacejavax.swing.table.TableModel
-
getColumnName
public java.lang.String getColumnName(int col)
Returns the column name at the given column.- Specified by:
getColumnNamein interfacejavax.swing.table.TableModel- Overrides:
getColumnNamein classjavax.swing.table.AbstractTableModel- Parameters:
col- column number- Returns:
- column name
-
getVariableName
public java.lang.String getVariableName(int col)
Returns the variable name at the given column.- Parameters:
col- column number- Returns:
- variable name
-
getValueAt
public java.lang.Object getValueAt(int row, int col)- Specified by:
getValueAtin interfacejavax.swing.table.TableModel
-
getColumnClass
public java.lang.Class getColumnClass(int c)
- Specified by:
getColumnClassin interfacejavax.swing.table.TableModel- Overrides:
getColumnClassin classjavax.swing.table.AbstractTableModel
-
isCellEditable
public boolean isCellEditable(int row, int col)- Specified by:
isCellEditablein interfacejavax.swing.table.TableModel- Overrides:
isCellEditablein classjavax.swing.table.AbstractTableModel
-
getColumnsWithData
public java.util.Vector getColumnsWithData()
Returns the column number of columns that contain data.- Returns:
- vector of Integers representing column numbers
-
getAllColumnNumbers
public java.util.Vector getAllColumnNumbers()
Gets all the column numbers.- Returns:
- a vector of integers (column numbers)
-
hasData
public static boolean hasData(java.lang.Object cell)
Returns true if and only if the given cell has data. A cell has data if its content is not an empty string.- Parameters:
cell- cell object to check if it contains data- Returns:
- true iff the given cell has data
-
setValueAt
public void setValueAt(java.lang.Object value, int row, int col)Sets the value at the given row and column to the given value. If the target row is the variable row, checks if the given variable name already exists.- Specified by:
setValueAtin interfacejavax.swing.table.TableModel- Overrides:
setValueAtin classjavax.swing.table.AbstractTableModel- Parameters:
value- Object to setrow- row numbercol- column number
-
setStringValueAt
public void setStringValueAt(java.lang.String value, int row, int col)Set the string value at the specified row and column.- Parameters:
value- string valuerow- rowcol- column
-
setColumn
public void setColumn(int column, java.util.Vector<java.lang.String> data)Sets the contents of the given column to the given data vector.- Parameters:
column- column numberdata- vector of strings
-
setCellColumn
public void setCellColumn(int column, java.util.Vector<Cell> data)Sets the contents of the given column to the given cell vector.- Parameters:
column- column numberdata- vector of cells
-
setRow
public void setRow(int row, java.util.Vector<java.lang.String> data)Sets the contents of the given row to the given data vector.- Parameters:
row- row numberdata- vector of strings
-
setData
public void setData(java.util.Vector<java.util.Vector<java.lang.String>> data)
Sets the underlying table structure to the given data matrix.- Parameters:
data- vector of vectors of strings
-
getTabDelimitedValues
public java.lang.String getTabDelimitedValues()
Returns the table data as a string of tab-dlimited values.- Returns:
- string containing table data values separated by tab
-
getCommaSeparatedValues
public java.lang.String getCommaSeparatedValues()
Returns the table data as a string of comma-separated values.- Returns:
- string containing table data values separated by comma
-
clearCell
public void clearCell(int row, int col)Clears the contents in the cell at the specified row and column.- Parameters:
row- row numbercol- column number
-
deleteRow
public void deleteRow(int row)
Deletes the entire row at the specified row number. Shifts all rows below upward by one row.- Parameters:
row- row number
-
deleteColumn
public void deleteColumn(int column)
Deletes the entire column at the specified column number. Shifts all columns on the right to the left by one column.- Parameters:
column- column number
-
deleteCell
public void deleteCell(int row, int column)Deletes the cell at the specified row and column. Shifts data up to replace the removed cell.- Parameters:
row- row numbercolumn- column number
-
deleteCells
public void deleteCells(int minRow, int maxRow, int minCol, int maxCol)Deletes the cells within the specified range.- Parameters:
minRow- minimum rowmaxRow- maximum rowminCol- minimum colmaxCol- maximum col
-
insertRow
public void insertRow(int row)
Inserts a blank row at the specified row number.- Parameters:
row- row number
-
insertColumn
public void insertColumn(int col)
Inserts a blank column at the specified column number.- Parameters:
col- column number
-
insertCell
public void insertCell(int row, int col)Inserts a blank cell at the specified row and column.- Parameters:
row- row numbercol- column number
-
printDebugData
public void printDebugData()
Prints debug data.
-
-
DMelt 3.0 © DataMelt by jWork.ORG