public class GridBase extends java.lang.Object implements Grid, javafx.event.EventTarget
Grid interface.
First of all, the Grid must have all its rows filled with the same number of
SpreadsheetCell. A span is materialized by the same cell (same
instance of SpreadsheetCell) repeated all over the covered part. In order to
materialize span, you have two ways :
- First way is to manually add the same cell where you want to span. For example, we will make the first cell span on two columns :
//I create a sample grid
int rowCount = 15;
int columnCount = 10;
GridBase grid = new GridBase(rowCount, columnCount);
ObservableList<ObservableList<SpreadsheetCell>> rows = FXCollections.observableArrayList();
for (int row = 0; row < grid.getRowCount(); ++row) {
final ObservableList<SpreadsheetCell> list = FXCollections.observableArrayList();
for (int column = 0; column < grid.getColumnCount(); ++column) {
list.add(SpreadsheetCellType.STRING.createCell(row, column, 1, 1,"value"));
}
rows.add(list);
}
//I create my SpreadsheetCell spanning on two columns.
SpreadsheetCell cell = SpreadsheetCellType.STRING.createCell(0, 0, 1, 2,"value");
//I add them in the area covered by the span.
rows.get(0).set(0, cell);
rows.get(0).set(1, cell);
grid.setRows(rows);
SpreadsheetView spv = new SpreadsheetView(grid);
- The second way is to build the SpreadsheetView, but to use the spanRow(int, int, int) or spanColumn(int, int, int) methods. These methods will take the
SpreadsheetCell at the specified position, and enlarge the span by modifying
the rowSpan or columnSpan of the cell. And also put the SpreadsheetCell in
the area covered by the span.
//I create a sample grid
int rowCount = 15;
int columnCount = 10;
GridBase grid = new GridBase(rowCount, columnCount);
ObservableList<ObservableList<SpreadsheetCell>> rows = FXCollections.observableArrayList();
for (int row = 0; row < grid.getRowCount(); ++row) {
final ObservableList<SpreadsheetCell> list = FXCollections.observableArrayList();
for (int column = 0; column < grid.getColumnCount(); ++column) {
list.add(SpreadsheetCellType.STRING.createCell(row, column, 1, 1,"value"));
}
rows.add(list);
}
//I First set the rows in the grid.
grid.setRows(rows);
//Then I simply tell the grid to span the first cell
grid.spanColumn(2,0,0);
SpreadsheetView spv = new SpreadsheetView(grid);
setRowHeightCallback(javafx.util.Callback)
in order to specify a Callback that will give you the index of the row, and you
will give back the height of the row.
Map available, you can use the GridBase.MapBasedRowHeightFactory
that will construct the Callback for you.
The default height is 24.0.
If you want to change the value of a cell, you have to go through the API
with setCellValue(int, int, Object). This method will verify that
the value is corresponding to the SpreadsheetCellType of the cell and
try to convert it if possible. It will also fire a GridChange event
in order to notify all listeners that a value has changed.
If you want to listen to those changes, you can use the
addEventHandler(EventType, EventHandler) and
removeEventHandler(EventType, EventHandler) methods.
A basic listener for implementing a undo/redo in the SpreadsheetView could be
like that:
Grid grid = ...;
Stack<GridChange> undoStack = ...;
grid.addEventHandler(GridChange.GRID_CHANGE_EVENT, new EventHandler<GridChange>() {
public void handle(GridChange change) {
undoStack.push(change);
}
});
setDisplaySelection(boolean) with a false value
will make that rectangle disappear.
getColumnHeaders() and getRowHeaders() in order to customize what will appear in these headers.
SpreadsheetView.setRowHeaderWidth(double)
in order to enlarge the row header so that your text can fit properly.Grid,
GridChange| Type | Property and Description |
|---|---|
javafx.beans.property.BooleanProperty |
displaySelection
Returns the Boolean property associated with the displayed selection of the
Grid. |
javafx.beans.property.BooleanProperty |
locked
Returns a BooleanProperty associated with the locked grid state.
|
| Modifier and Type | Class and Description |
|---|---|
static class |
GridBase.MapBasedRowHeightFactory
This class serves as a bridge between row height Callback needed by the
GridBase and a Map<Integer,Double> that one could have (each Integer
specify a row index and its associated height).
|
| Constructor and Description |
|---|
GridBase(int rowCount,
int columnCount)
Creates a
GridBase with a fixed number of rows and columns. |
| Modifier and Type | Method and Description |
|---|---|
<E extends GridChange> |
addEventHandler(javafx.event.EventType<E> eventType,
javafx.event.EventHandler<E> eventHandler)
Registers an event handler to this Grid.
|
javafx.event.EventDispatchChain |
buildEventDispatchChain(javafx.event.EventDispatchChain tail) |
javafx.beans.property.BooleanProperty |
displaySelectionProperty()
Returns the Boolean property associated with the displayed selection of the
Grid. |
int |
getColumnCount()
Returns how many columns are inside the
Grid. |
javafx.collections.ObservableList<java.lang.String> |
getColumnHeaders()
Returns an
ObservableList of String to display in the
column headers. |
int |
getRowCount()
Returns how many rows are inside the
Grid. |
javafx.collections.ObservableList<java.lang.String> |
getRowHeaders()
Returns an
ObservableList of String to display in the row
headers. |
double |
getRowHeight(int row)
Returns the height of a row.
|
javafx.collections.ObservableList<javafx.collections.ObservableList<SpreadsheetCell>> |
getRows()
|
boolean |
isCellDisplaySelection(int row,
int column)
Returns true if the given cell will display a selection rectangle when
selected.
|
boolean |
isDisplaySelection()
Return
true if the selection (black rectangle) is displayed on
the Grid. |
boolean |
isLocked()
Returns whether this
GridBase id locked or not. |
boolean |
isRowResizable(int row)
Returns true if the specified row is resizable.
|
javafx.beans.property.BooleanProperty |
lockedProperty()
Returns a BooleanProperty associated with the locked grid state.
|
<E extends GridChange> |
removeEventHandler(javafx.event.EventType<E> eventType,
javafx.event.EventHandler<E> eventHandler)
Unregisters a previously registered event handler from this Grid.
|
void |
setCellDisplaySelection(int row,
int column,
boolean displaySelection)
Overrides the value defined by
Grid.isDisplaySelection()
so that no matter what is defined on the grid, the given cell will always
have its selection set to the displaySelection parameter. |
void |
setCellValue(int modelRow,
int column,
java.lang.Object value)
Changes the value situated at the intersection if possible.
|
void |
setDisplaySelection(boolean value)
If set to true, the selection (black rectangle) will be displayed on the
Grid. |
void |
setLocked(java.lang.Boolean lock)
Locks or unlocks this
GridBase. |
void |
setResizableRows(java.util.BitSet resizableRow)
Sets the resizable state of all rows.
|
void |
setRowHeightCallback(javafx.util.Callback<java.lang.Integer,java.lang.Double> rowHeight)
Sets a new
Callback for this grid in order to specify height of
each row. |
void |
setRows(java.util.Collection<javafx.collections.ObservableList<SpreadsheetCell>> rows)
Sets the rows used by the grid, and updates the rowCount.
|
void |
spanColumn(int count,
int rowIndex,
int colIndex)
Spans in column the cell situated at rowIndex and colIndex by the number
count.
|
void |
spanRow(int count,
int rowIndex,
int colIndex)
Spans in row the cell situated at rowIndex and colIndex by the number
count.
|
public javafx.beans.property.BooleanProperty lockedProperty
SpreadsheetCell.isEditable()
state.isLocked(),
setLocked(Boolean)public javafx.beans.property.BooleanProperty displaySelectionProperty
Grid.displaySelectionProperty in interface GridisDisplaySelection(),
setDisplaySelection(boolean)public GridBase(int rowCount,
int columnCount)
GridBase with a fixed number of rows and columns.rowCount - the number of rowscolumnCount - the numbers of columnspublic javafx.collections.ObservableList<javafx.collections.ObservableList<SpreadsheetCell>> getRows()
ObservableList of ObservableList of
SpreadsheetCell instances. Refer to the Grid class
javadoc for more detail.getRows in interface GridObservableList of ObservableList of
SpreadsheetCell instancespublic void setCellValue(int modelRow,
int column,
java.lang.Object value)
SpreadsheetCellType.match(Object) and
SpreadsheetCellType.convertValue(Object).setCellValue in interface GridmodelRow - the row index issued from the SpreadsheetCellcolumn - the column index issued from the SpreadsheetCellvalue - the value to set to the SpreadsheetCellpublic int getRowCount()
Grid.getRowCount in interface GridGrid.public int getColumnCount()
Grid.getColumnCount in interface GridGrid.public double getRowHeight(int row)
Grid.AUTOFIT can be returned in order
to let the system compute the best row height.getRowHeight in interface Gridrow - the row indexpublic void setRowHeightCallback(javafx.util.Callback<java.lang.Integer,java.lang.Double> rowHeight)
Callback for this grid in order to specify height of
each row.rowHeight - the Callback to use for rown height computationpublic javafx.collections.ObservableList<java.lang.String> getRowHeaders()
ObservableList of String to display in the row
headers.getRowHeaders in interface GridObservableList of String to display in the row
headerspublic javafx.collections.ObservableList<java.lang.String> getColumnHeaders()
ObservableList of String to display in the
column headers.getColumnHeaders in interface GridObservableList of String to display in the
column headerspublic javafx.beans.property.BooleanProperty lockedProperty()
SpreadsheetCell.isEditable()
state.isLocked(),
setLocked(Boolean)public boolean isLocked()
GridBase id locked or not.true if this GridBase is lockedpublic void setLocked(java.lang.Boolean lock)
GridBase.lock - true to lock this GridBasepublic void spanRow(int count,
int rowIndex,
int colIndex)
public void spanColumn(int count,
int rowIndex,
int colIndex)
spanColumn in interface Gridcount - the span rangerowIndex - the row indexcolIndex - the column indexpublic void setRows(java.util.Collection<javafx.collections.ObservableList<SpreadsheetCell>> rows)
Grid is actually given to a
SpreadsheetView. If this method is called after, you should give
the Grid again to the SpreadsheetView by using SpreadsheetView.setGrid(org.controlsfx.control.spreadsheet.Grid).public void setResizableRows(java.util.BitSet resizableRow)
BitSet, it means the row is resizable.
The BitSet.length() must be equal to the getRowCount()resizableRow - a BitSet where the bits set to true
represent the resizable rowspublic boolean isRowResizable(int row)
isRowResizable in interface Gridrow - the row indextrue if the specified row is resizablepublic boolean isDisplaySelection()
true if the selection (black rectangle) is displayed on
the Grid. Cells may override this property with Grid.setCellDisplaySelection(int, int, boolean).isDisplaySelection in interface Gridtrue if the selection (black rectangle) is displayed on
the Gridpublic void setDisplaySelection(boolean value)
Grid. Cells may override this property with Grid.setCellDisplaySelection(int, int, boolean).setDisplaySelection in interface Gridvalue - true if the selection should be displayedpublic javafx.beans.property.BooleanProperty displaySelectionProperty()
Grid.displaySelectionProperty in interface GridisDisplaySelection(),
setDisplaySelection(boolean)public void setCellDisplaySelection(int row,
int column,
boolean displaySelection)
Grid.isDisplaySelection()
so that no matter what is defined on the grid, the given cell will always
have its selection set to the displaySelection parameter.setCellDisplaySelection in interface Gridrow - the row indexcolumn - the column indexdisplaySelection - true is the selection should always be
displayed on this cellpublic boolean isCellDisplaySelection(int row,
int column)
Grid.isDisplaySelection() is returned.isCellDisplaySelection in interface Gridrow - the row indexcolumn - the column indextrue if the given cell will display a selection rectanglepublic <E extends GridChange> void addEventHandler(javafx.event.EventType<E> eventType, javafx.event.EventHandler<E> eventHandler)
SpreadsheetCell's value
will change.addEventHandler in interface GrideventType - the type of the events to receive by the handlereventHandler - the handler to registerpublic <E extends GridChange> void removeEventHandler(javafx.event.EventType<E> eventType, javafx.event.EventHandler<E> eventHandler)
removeEventHandler in interface GrideventType - the event type from which to unregistereventHandler - the handler to unregisterpublic javafx.event.EventDispatchChain buildEventDispatchChain(javafx.event.EventDispatchChain tail)
buildEventDispatchChain in interface javafx.event.EventTarget