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 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
| Modifier and Type | Class and Description |
|---|---|
| public static class | GridBase.
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). |
| Modifier and Type | Field and Description |
|---|---|
| private int | |
| private final ObservableList | |
| private final BooleanProperty | |
| private final TreeSet | |
| private final EventHandlerManager | |
| private final BooleanProperty | |
| private final TreeSet | |
| private BitSet | |
| private int | |
| private Callback | |
| private ObservableList | rows
Private Fields |
| private final ObservableList |
| Access | Constructor and Description |
|---|---|
| public | GridBase(int
the number of rows rowCount, int the numbers of columns columnCount)Creates a |
| Modifier and Type | Method and Description |
|---|---|
| public <E extends Event> void | addEventHandler(EventType<E> eventType, EventHandler<? super E> eventHandler)
Overrides default javafx. Implements org. Registers an event handler to this Grid. |
| public EventDispatchChain | buildEventDispatchChain(EventDispatchChain tail)
Implements javafx. Construct an event dispatch chain for this target. |
| public BooleanProperty | displaySelectionProperty()
Implements org. Returns the Boolean property associated with the displayed selection of the
|
| public int | getColumnCount()
Implements org. Returns how many columns are inside the |
| public ObservableList | getColumnHeaders()
Implements org. Returns an |
| public int | getRowCount()
Implements org. Returns how many rows are inside the |
| public ObservableList | getRowHeaders()
Implements org. Returns an |
| public double | getRowHeight(int row)
Implements org. Returns the height of a row. |
| public ObservableList | getRows()
Implements org. Returns an |
| public boolean | isCellDisplaySelection(int row, int column)
Implements org. Returns true if the given cell will display a selection rectangle when selected. |
| public boolean | isDisplaySelection()
Implements org. Return |
| public boolean | |
| public boolean | isRowResizable(int row)
Implements org. Returns true if the specified row is resizable. |
| public BooleanProperty | Returns: a BooleanProperty associated with the locked grid state.Returns a BooleanProperty associated with the locked grid state. |
| public <E extends Event> void | removeEventHandler(EventType<E> eventType, EventHandler<? super E> eventHandler)
Overrides default javafx. Implements org. Unregisters a previously registered event handler from this Grid. |
| public void | setCellDisplaySelection(int row, int column, boolean displaySelection)
Implements org. Overrides the value defined by |
| public void | setCellValue(int modelRow, int column, Object value)
Implements org. Changes the value situated at the intersection if possible. |
| private void | |
| public void | setDisplaySelection(boolean value)
Implements org. If set to true, the selection (black rectangle) will be displayed on the
|
| public void | |
| public void | setResizableRows(BitSet
a resizableRow)BitSet where the bits set to true
represent the resizable rowsSets the resizable state of all rows. |
| private void | |
| public void | setRowHeightCallback(Callback<Integer, Double>
the rowHeight)Callback to use for rown height computationSets a new |
| public void | setRows(Collection<ObservableList<SpreadsheetCell>> rows)
Implements org. Sets the rows used by the grid, and updates the rowCount. |
| public void | spanColumn(int count, int rowIndex, int colIndex)
Implements org. Spans in column the cell situated at rowIndex and colIndex by the number count. |
| public void | spanRow(int count, int rowIndex, int colIndex)
Implements org. Spans in row the cell situated at rowIndex and colIndex by the number count. |
| columnCount | back to summary |
|---|---|
| private int columnCount | |
| columnsHeader | back to summary |
|---|---|
| private final ObservableList<String> columnsHeader | |
| displaySelection | back to summary |
|---|---|
| private final BooleanProperty displaySelection | |
| displaySelectionCells | back to summary |
|---|---|
| private final TreeSet<Long> displaySelectionCells | |
| eventHandlerManager | back to summary |
|---|---|
| private final EventHandlerManager eventHandlerManager | |
| locked | back to summary |
|---|---|
| private final BooleanProperty locked | |
| noDisplaySelectionCells | back to summary |
|---|---|
| private final TreeSet<Long> noDisplaySelectionCells | |
| resizableRow | back to summary |
|---|---|
| private BitSet resizableRow | |
| rowCount | back to summary |
|---|---|
| private int rowCount | |
| rowHeightFactory | back to summary |
|---|---|
| private Callback<Integer, Double> rowHeightFactory | |
| rows | back to summary |
|---|---|
| private ObservableList<ObservableList<SpreadsheetCell>> rows Private Fields | |
| rowsHeader | back to summary |
|---|---|
| private final ObservableList<String> rowsHeader | |
| GridBase | back to summary |
|---|---|
| public GridBase(int rowCount, int columnCount) Creates a
| |
| addEventHandler | back to summary |
|---|---|
| public <E extends Event> void addEventHandler(EventType<E> eventType, EventHandler<? super E> eventHandler) Overrides default javafx. Implements org. Doc from org. Registers an event handler to this Grid. The Grid class allows
registration of listeners which will be notified as a | |
| buildEventDispatchChain | back to summary |
|---|---|
| public EventDispatchChain buildEventDispatchChain(EventDispatchChain tail) Implements javafx. Doc from javafx. Construct an event dispatch chain for this target. The event dispatch
chain contains event dispatchers which might be interested in processing
of events targeted at this In the case the event target is part of some hierarchy, the chain for it is usually built from event dispatchers collected from the root of the hierarchy to the event target. The event dispatch chain is constructed by modifications to the provided initial event dispatch chain. The returned chain should have the initial chain at its end so the dispatchers should be prepended to the initial chain. The caller shouldn't assume that the initial chain remains unchanged nor that the returned value will reference a different chain.
| |
| displaySelectionProperty | back to summary |
|---|---|
| public BooleanProperty displaySelectionProperty() Implements org. Doc from org. Returns the Boolean property associated with the displayed selection of the
| |
| getColumnCount | back to summary |
|---|---|
| public int getColumnCount() Implements org. Doc from org. Returns how many columns are inside the
| |
| getColumnHeaders | back to summary |
|---|---|
| public ObservableList Implements org. Doc from org. Returns an
| |
| getRowCount | back to summary |
|---|---|
| public int getRowCount() Implements org. Doc from org. Returns how many rows are inside the
| |
| getRowHeaders | back to summary |
|---|---|
| public ObservableList Implements org. Doc from org. Returns an
| |
| getRowHeight | back to summary |
|---|---|
| public double getRowHeight(int row) Implements org. Doc from org. Returns the height of a row.
| |
| getRows | back to summary |
|---|---|
| public ObservableList Implements org. Doc from org. Returns an
| |
| isCellDisplaySelection | back to summary |
|---|---|
| public boolean isCellDisplaySelection(int row, int column) Implements org. Doc from org. Returns true if the given cell will display a selection rectangle when
selected. If nothing is defined for this cell,
| |
| isDisplaySelection | back to summary |
|---|---|
| public boolean isDisplaySelection() Implements org. Doc from org. Return
| |
| isLocked | back to summary |
|---|---|
| public boolean isLocked() Returns whether this
| |
| isRowResizable | back to summary |
|---|---|
| public boolean isRowResizable(int row) Implements org. Doc from org. Returns true if the specified row is resizable.
| |
| lockedProperty | back to summary |
|---|---|
| public BooleanProperty lockedProperty() Returns a BooleanProperty associated with the locked grid state. It means
that the Grid is in a read-only mode and that no SpreadsheetCell can be
modified, no regards for their own
| |
| removeEventHandler | back to summary |
|---|---|
| public <E extends Event> void removeEventHandler(EventType<E> eventType, EventHandler<? super E> eventHandler) Overrides default javafx. Implements org. Doc from org. Unregisters a previously registered event handler from this Grid. One handler might have been registered for different event types, so the caller needs to specify the particular event type from which to unregister the handler. | |
| setCellDisplaySelection | back to summary |
|---|---|
| public void setCellDisplaySelection(int row, int column, boolean displaySelection) Implements org. Doc from org. Overrides the value defined by
| |
| setCellValue | back to summary |
|---|---|
| public void setCellValue(int modelRow, int column, Object value) Implements org. Doc from org. Changes the value situated at the intersection if possible. Verification
and conversion of the value should be done before with
| |
| setColumnCount | back to summary |
|---|---|
| private void setColumnCount(int columnCount) Set a new columnCount for the grid. | |
| setDisplaySelection | back to summary |
|---|---|
| public void setDisplaySelection(boolean value) Implements org. Doc from org. If set to true, the selection (black rectangle) will be displayed on the
| |
| setLocked | back to summary |
|---|---|
| public void setLocked(Boolean lock) Locks or unlocks this
| |
| setResizableRows | back to summary |
|---|---|
| public void setResizableRows(BitSet resizableRow) Sets the resizable state of all rows. If a bit is set to true in the
| |
| setRowCount | back to summary |
|---|---|
| private void setRowCount(int rowCount) Set a new rowCount for the grid. | |
| setRowHeightCallback | back to summary |
|---|---|
| public void setRowHeightCallback(Callback<Integer, Double> rowHeight) Sets a new | |
| setRows | back to summary |
|---|---|
| public void setRows(Collection<ObservableList<SpreadsheetCell>> rows) Implements org. Doc from org. Sets the rows used by the grid, and updates the rowCount. This method
should be called before the
| |
| spanColumn | back to summary |
|---|---|
| public void spanColumn(int count, int rowIndex, int colIndex) Implements org. Doc from org. Spans in column the cell situated at rowIndex and colIndex by the number count.
| |
| spanRow | back to summary |
|---|---|
| public void spanRow(int count, int rowIndex, int colIndex) Implements org. Doc from org. Spans in row the cell situated at rowIndex and colIndex by the number count.
| |
| Access | Constructor and Description |
|---|---|
| public |
| Modifier and Type | Method and Description |
|---|---|
| public Double | call(Integer index)
Implements javafx. The |
| rowHeightMap | back to summary |
|---|---|
| private final Map<Integer, Double> rowHeightMap | |
| MapBasedRowHeightFactory | back to summary |
|---|---|
| public MapBasedRowHeightFactory(Map<Integer, Double> rowHeightMap) | |
| call | back to summary |
|---|---|
| public Double call(Integer index) Implements javafx. Doc from javafx. The
| |