|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.swing.table.AbstractTableModel
javax.swing.table.DefaultTableModel
zinger.bsheet.BSHTableModel
public class BSHTableModel
Core Bean Sheet functionality. This class provides integration between Bean Shell and Swing. Also contains some parsing and formatting logic.
Nested Class Summary | |
---|---|
class |
BSHTableModel.BSHCellEditor
Extentions to default cell editing. |
class |
BSHTableModel.BSHCellRenderer
Extensions to default cell rendering. |
Field Summary | |
---|---|
protected java.util.Map |
appearanceMap
|
protected bsh.Interpreter |
bsh
Instance of Bean Shell interpreter. |
protected java.lang.Object[][] |
cache
Evaluation cache. |
protected java.util.regex.Pattern |
cellRangePattern
Regular expression object representing a cell range iterator (e.g. |
protected java.util.regex.Pattern |
cellRefPattern
Regular expression object representing a cell address reference (e.g. |
protected java.util.regex.Pattern |
cellRelativeRefPattern
Regular expression object representing a relative cell reference (e.g. |
protected java.util.Map |
columnFormats
A map of column format arrays. |
protected Dependencies |
dependencies
Two-way dependencies tracker. |
protected int |
editingColumn
Current column being edited. |
protected int |
editingRow
Current row being edited. |
protected boolean |
rowIndexes
Controls whether the left-most column (index 0) shows row index. |
protected ObjectPool |
setRecycler
Object pool for Set objects. |
protected ObjectPool |
stringBufferRecycler
Object pool for StringBuffer objects. |
protected boolean |
suppressDependencies
|
protected java.util.BitSet[] |
valuesCached
|
Fields inherited from class javax.swing.table.DefaultTableModel |
---|
columnIdentifiers, dataVector |
Fields inherited from class javax.swing.table.AbstractTableModel |
---|
listenerList |
Constructor Summary | |
---|---|
BSHTableModel(int rowCount,
int columnCount)
Instantiates the model using initial row and column counts. |
Method Summary | |
---|---|
void |
editingCanceled(javax.swing.event.ChangeEvent ev)
|
void |
editingStopped(javax.swing.event.ChangeEvent ev)
|
java.lang.Object |
evalValueAt(int column,
int row)
Evaluates a value at the given cell address. |
void |
fireTableChanged(javax.swing.event.TableModelEvent ev)
|
void |
fireTableStructureChanged()
|
void |
followDependencies(int column,
int row)
Calls recursive followDependencies(Point, Set). |
protected void |
followDependencies(java.awt.Point coord,
java.util.Set processed)
Recursively runs according to cell's dependencies. |
java.lang.Object |
formatValueAt(java.lang.Object value,
int column,
int row)
Formats the given value using formatting rules for the given address. |
Appearance |
getAppearance(int column,
int row,
boolean mutable)
|
java.util.Map |
getAppearanceMap()
|
java.lang.Class |
getColumnClass(int column)
Extends default behavior to return a class object representing JTableHeader
for column 0. |
java.lang.String |
getColumnName(int column)
Extends default behavior to return null for column 0. |
java.text.Format |
getFormat(int column,
int row)
Returns the format object associated with the given cell or column. |
java.util.Map |
getFormats()
Returns internal format map. |
int |
getLastNonEmptyColumn()
|
int |
getLastNonEmptyRow()
|
java.lang.Object |
getValueAt(int row,
int column)
Extends default behavior to always return row index for column 0. |
boolean |
isCellEditable(int row,
int column)
Extends default behavior to return false for column 0. |
protected boolean |
isValueCached(int column,
int row)
Checks for cache state for a specific cell. |
protected void |
refreshCacheAndDependencies()
Recreates internal value cache and dependencies objects ( cache and dependencies ). |
protected void |
refreshLastNonEmpty()
|
Appearance |
removeAppearance(int column,
int row)
|
java.lang.String |
replaceReferences(java.lang.String evalString,
java.util.Set dependencies)
Replaces cell address references with Bean Shell-compatible statements. |
void |
requestDependency(int causeCol,
int causeRow,
int effectCol,
int effectRow)
Requests a dependency from one cell to another. |
void |
setAppearanceMap(java.util.Map appearanceMap)
|
void |
setFormat(java.text.Format format,
int column,
int row)
Associates the given format object with the given cell or column. |
void |
setFormats(java.util.Map formats)
Sets internal format map. |
void |
setValueAt(java.lang.Object value,
int row,
int column)
Sets a value at the given address. |
protected void |
setValueCached(boolean cached,
int column,
int row)
Sets cache state for a specific cell. |
void |
sort(int startRow,
int nRows,
int[] cols,
java.util.Comparator[] comps)
Sorts rows of data in the model in the specified columns spanning nRows rows
starting with startRow . |
Methods inherited from class javax.swing.table.DefaultTableModel |
---|
addColumn, addColumn, addColumn, addRow, addRow, convertToVector, convertToVector, getColumnCount, getDataVector, getRowCount, insertRow, insertRow, moveRow, newDataAvailable, newRowsAdded, removeRow, rowsRemoved, setColumnCount, setColumnIdentifiers, setColumnIdentifiers, setDataVector, setDataVector, setNumRows, setRowCount |
Methods inherited from class javax.swing.table.AbstractTableModel |
---|
addTableModelListener, findColumn, fireTableCellUpdated, fireTableDataChanged, fireTableRowsDeleted, fireTableRowsInserted, fireTableRowsUpdated, getListeners, getTableModelListeners, removeTableModelListener |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected int editingRow
protected int editingColumn
protected final bsh.Interpreter bsh
protected final java.util.regex.Pattern cellRefPattern
[B10]
).
protected final java.util.regex.Pattern cellRangePattern
[B2:C15]
).
protected final java.util.regex.Pattern cellRelativeRefPattern
[-1+2]
).
protected final ObjectPool stringBufferRecycler
StringBuffer
objects.
This object is thread safe.
protected final ObjectPool setRecycler
Set
objects.
This object is thread safe.
protected transient Dependencies dependencies
protected transient java.lang.Object[][] cache
evalValueAt(int, int)
method.
As of 0.8, the model accomodates cached null
values by means of explicity cached status flags.
evalValueAt(int, int)
,
isValueCached(int, int)
,
setValueCached(boolean, int, int)
,
valuesCached
protected transient java.util.BitSet[] valuesCached
evalValueAt(int, int)
,
isValueCached(int, int)
,
setValueCached(boolean, int, int)
,
dependencies
protected java.util.Map columnFormats
getFormat(int, int)
,
setFormat(java.text.Format, int, int)
protected java.util.Map appearanceMap
protected boolean rowIndexes
TableSort.ComparatorTableModel
and other future extensions of this class.
May become deprecated in favor of cleaner API.
protected boolean suppressDependencies
Constructor Detail |
---|
public BSHTableModel(int rowCount, int columnCount)
Method Detail |
---|
public void setValueAt(java.lang.Object value, int row, int column)
Format
object is available for
the given address, parsing the value is attempted using the Format
object.
If the parsing is successful, the object stored in the model itself is the result
of the parsing. For example, if the format is an instance of SimpleDateFormat
,
and its pattern is set to "yyyy-MM-dd
", then the value string
"1977-9-6
" would be parsed and stored as an instance of Date
representing September 6, 1977.
setValueAt
in interface javax.swing.table.TableModel
setValueAt
in class javax.swing.table.DefaultTableModel
getFormat(int, int)
public java.lang.Object formatValueAt(java.lang.Object value, int column, int row)
getFormat(int, int)
public java.lang.Object getValueAt(int row, int column)
getValueAt
in interface javax.swing.table.TableModel
getValueAt
in class javax.swing.table.DefaultTableModel
public java.lang.String getColumnName(int column)
null
for column 0.
Column 0 is a special column that is used as a row header.
getColumnName
in interface javax.swing.table.TableModel
getColumnName
in class javax.swing.table.DefaultTableModel
public java.lang.Class getColumnClass(int column)
JTableHeader
for column 0.
Column 0 is a special column that is used as a row header.
getColumnClass
in interface javax.swing.table.TableModel
getColumnClass
in class javax.swing.table.AbstractTableModel
public boolean isCellEditable(int row, int column)
false
for column 0.
Column 0 is a special column that is used as a row header.
isCellEditable
in interface javax.swing.table.TableModel
isCellEditable
in class javax.swing.table.DefaultTableModel
public Appearance removeAppearance(int column, int row)
public Appearance getAppearance(int column, int row, boolean mutable)
public void setFormat(java.text.Format format, int column, int row)
row
is 0
, the format is associated with the entire column.
getFormat(int, int)
public java.text.Format getFormat(int column, int row)
row
is 0
, the returned format is for the entire column.
Also if there is no format available for the given cell, the format for the column is then
returned.
setFormat(java.text.Format, int, int)
protected boolean isValueCached(int column, int row)
setValueCached(boolean, int, int)
protected void setValueCached(boolean cached, int column, int row)
isValueCached(int, int)
public java.lang.Object evalValueAt(int column, int row)
=
, then
the formula is processed using internal preprocessing rules and then passed on
to the Bean Shell interpreter (bsh
).
The preprocessing rules encompass the following steps:
col
, row
);
isValueCached(int, int)
,
setValueCached(boolean, int, int)
,
replaceReferences(java.lang.String, java.util.Set)
,
bsh
public java.lang.String replaceReferences(java.lang.String evalString, java.util.Set dependencies)
Type | Syntax | Example | Equivalent |
---|---|---|---|
Explicit | [<column name><row index>] | [B10] |
model.evalValueAt(model.findColumn("B"), 10) |
Relative | [<column index delta><row index delta>] | [-1+2] |
model.evalValueAt(col - 1, row + 2) |
Range | [<start column name><start row index>:<end column name><end row index>] | [B2:C15] |
range("[B2:C15]") |
public void editingCanceled(javax.swing.event.ChangeEvent ev)
editingCanceled
in interface javax.swing.event.CellEditorListener
public void editingStopped(javax.swing.event.ChangeEvent ev)
editingStopped
in interface javax.swing.event.CellEditorListener
public void followDependencies(int column, int row)
followDependencies(Point, Set).
- See Also:
followDependencies(java.awt.Point, java.util.Set)
protected void followDependencies(java.awt.Point coord, java.util.Set processed)
public void requestDependency(int causeCol, int causeRow, int effectCol, int effectRow)
[]
cell address notation. This is especially
useful when defining Bean Shell commands or processing logic within a spreadsheet,
such as operations on ranges defined by their start and end points.
protected void refreshCacheAndDependencies()
cache
and dependencies
).
This is useful when the model structure (dimensions) changes.
cache
,
dependencies
protected void refreshLastNonEmpty()
public int getLastNonEmptyRow()
public int getLastNonEmptyColumn()
public void fireTableStructureChanged()
fireTableStructureChanged
in class javax.swing.table.AbstractTableModel
public void fireTableChanged(javax.swing.event.TableModelEvent ev)
fireTableChanged
in class javax.swing.table.AbstractTableModel
public java.util.Map getFormats()
columnFormats
,
setFormats(java.util.Map)
public void setFormats(java.util.Map formats)
columnFormats
,
getFormats()
public java.util.Map getAppearanceMap()
public void setAppearanceMap(java.util.Map appearanceMap)
public void sort(int startRow, int nRows, int[] cols, java.util.Comparator[] comps)
nRows
rows
starting with startRow
.
Custom comparators can be provided in an array. Provided comparators are matched
against their corresponding columns using array indexes. If comparator array is shorter
than the column index array, the rest of the columns are sorted in their natural order.
Each element in the comparator array represents a comparator used for that particular column's
sorting. A null
comparator represents natural data order. It may be assumed that
no null
column values will be passed to the custom comparators for comparison.
null
values are handled entirely by BSHTableModelComparable
.
startRow
- starting rownRows
- number of rowscols
- column indexescomps
- custom comparators. Must not be null
.BSHTableModelComparable
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |