Top Description Inners Fields Constructors Methods
org.controlsfx.control.spreadsheet

public Class GridBase

extends Object
implements Grid, EventTarget
Class Inheritance
All Implemented Interfaces
javafx.event.EventTarget, org.controlsfx.control.spreadsheet.Grid
Imports
com.sun.javafx.event.EventHandlerManager, java.util.BitSet, .Collection, .HashMap, .Map, .TreeSet, javafx.beans.Observable, javafx.beans.property.BooleanProperty, .SimpleBooleanProperty, javafx.collections.FXCollections, .ObservableList, javafx.event.Event, .EventDispatchChain, .EventHandler, .EventTarget, .EventType, javafx.util.Callback

A base implementation of the Grid interface.

How to span

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);

Row Height

You can specify some row height for some of your rows at the beginning. You have to use the method 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.
If you just have a Map available, you can use the MapBasedRowHeightFactory that will construct the Callback for you. The default height is 24.0.

Cell values

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);
            }
        });

Display selection

By default, the SpreadsheetView will display a black rectangle around your selection if it's contiguous. Some may want to disable that effect. Therefore a simple call to setDisplaySelection(boolean) with a false value will make that rectangle disappear.

Headers

The SpreadsheetView is displaying row numbers and column letters by default. Just like any other spreadsheet would do. However, some may want to customize theose headers. You can use the getColumnHeaders() and getRowHeaders() in order to customize what will appear in these headers.
If you put some long text in the row headers, it will not fit. Thus you may consider using SpreadsheetView#setRowHeaderWidth(double) in order to enlarge the row header so that your text can fit properly.
See Also
Grid, GridChange

Nested and Inner Type Summary

Modifier and TypeClass and Description
public 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).

Field Summary

Modifier and TypeField and Description
private int
private final ObservableList<String>
private final BooleanProperty
private final TreeSet<Long>
private final EventHandlerManager
private final BooleanProperty
private final TreeSet<Long>
private BitSet
private int
private Callback<Integer, Double>
private ObservableList<ObservableList<SpreadsheetCell>>
rows

Private Fields

private final ObservableList<String>

Constructor Summary

AccessConstructor and Description
public
GridBase(int
the number of rows
rowCount
,
int
the numbers of columns
columnCount
)

Creates a GridBase with a fixed number of rows and columns.

Method Summary

Modifier and TypeMethod and Description
public <E extends Event> void
addEventHandler(EventType<E> eventType, EventHandler<? super E> eventHandler)

Overrides default javafx.event.EventTarget.addEventHandler.

Implements org.controlsfx.control.spreadsheet.Grid.addEventHandler.

Registers an event handler to this Grid.

public EventDispatchChain
buildEventDispatchChain(EventDispatchChain tail)

Implements javafx.event.EventTarget.buildEventDispatchChain.

Construct an event dispatch chain for this target.

public BooleanProperty
displaySelectionProperty()

Implements org.controlsfx.control.spreadsheet.Grid.displaySelectionProperty.

Returns the Boolean property associated with the displayed selection of the Grid.

public int
getColumnCount()

Implements org.controlsfx.control.spreadsheet.Grid.getColumnCount.

Returns how many columns are inside the Grid.

public ObservableList<String>
getColumnHeaders()

Implements org.controlsfx.control.spreadsheet.Grid.getColumnHeaders.

Returns an ObservableList of String to display in the column headers.

public int
getRowCount()

Implements org.controlsfx.control.spreadsheet.Grid.getRowCount.

Returns how many rows are inside the Grid.

public ObservableList<String>
getRowHeaders()

Implements org.controlsfx.control.spreadsheet.Grid.getRowHeaders.

Returns an ObservableList of String to display in the row headers.

public double
getRowHeight(int row)

Implements org.controlsfx.control.spreadsheet.Grid.getRowHeight.

Returns the height of a row.

public ObservableList<ObservableList<SpreadsheetCell>>
getRows()

Implements org.controlsfx.control.spreadsheet.Grid.getRows.

Returns an ObservableList of ObservableList of SpreadsheetCell instances.

public boolean
isCellDisplaySelection(int row, int column)

Implements org.controlsfx.control.spreadsheet.Grid.isCellDisplaySelection.

Returns true if the given cell will display a selection rectangle when selected.

public boolean
isDisplaySelection()

Implements org.controlsfx.control.spreadsheet.Grid.isDisplaySelection.

Return true if the selection (black rectangle) is displayed on the Grid.

public boolean

Returns:

true if this GridBase is locked
isLocked
()

Returns whether this GridBase id locked or not.

public boolean
isRowResizable(int row)

Implements org.controlsfx.control.spreadsheet.Grid.isRowResizable.

Returns true if the specified row is resizable.

public BooleanProperty

Returns:

a BooleanProperty associated with the locked grid state.
lockedProperty
()

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.event.EventTarget.removeEventHandler.

Implements org.controlsfx.control.spreadsheet.Grid.removeEventHandler.

Unregisters a previously registered event handler from this Grid.

public void
setCellDisplaySelection(int row, int column, boolean displaySelection)

Implements org.controlsfx.control.spreadsheet.Grid.setCellDisplaySelection.

Overrides the value defined by isDisplaySelection() so that no matter what is defined on the grid, the given cell will always have its selection set to the displaySelection parameter.

public void
setCellValue(int modelRow, int column, Object value)

Implements org.controlsfx.control.spreadsheet.Grid.setCellValue.

Changes the value situated at the intersection if possible.

private void
setColumnCount(int columnCount)

Set a new columnCount for the grid.

public void
setDisplaySelection(boolean value)

Implements org.controlsfx.control.spreadsheet.Grid.setDisplaySelection.

If set to true, the selection (black rectangle) will be displayed on the Grid.

public void
setLocked(Boolean
true to lock this GridBase
lock
)

Locks or unlocks this GridBase.

public void
setResizableRows(BitSet
a BitSet where the bits set to true represent the resizable rows
resizableRow
)

Sets the resizable state of all rows.

private void
setRowCount(int rowCount)

Set a new rowCount for the grid.

public void
setRowHeightCallback(Callback<Integer, Double>
the Callback to use for rown height computation
rowHeight
)

Sets a new Callback for this grid in order to specify height of each row.

public void
setRows(Collection<ObservableList<SpreadsheetCell>> rows)

Implements org.controlsfx.control.spreadsheet.Grid.setRows.

Sets the rows used by the grid, and updates the rowCount.

public void
spanColumn(int count, int rowIndex, int colIndex)

Implements org.controlsfx.control.spreadsheet.Grid.spanColumn.

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.controlsfx.control.spreadsheet.Grid.spanRow.

Spans in row the cell situated at rowIndex and colIndex by the number count.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

columnCountback to summary
private int columnCount
columnsHeaderback to summary
private final ObservableList<String> columnsHeader
displaySelectionback to summary
private final BooleanProperty displaySelection
displaySelectionCellsback to summary
private final TreeSet<Long> displaySelectionCells
eventHandlerManagerback to summary
private final EventHandlerManager eventHandlerManager
lockedback to summary
private final BooleanProperty locked
noDisplaySelectionCellsback to summary
private final TreeSet<Long> noDisplaySelectionCells
resizableRowback to summary
private BitSet resizableRow
rowCountback to summary
private int rowCount
rowHeightFactoryback to summary
private Callback<Integer, Double> rowHeightFactory
rowsback to summary
private ObservableList<ObservableList<SpreadsheetCell>> rows

Private Fields

rowsHeaderback to summary
private final ObservableList<String> rowsHeader

Constructor Detail

GridBaseback to summary
public GridBase(int rowCount, int columnCount)

Creates a GridBase with a fixed number of rows and columns.

Parameters
rowCount:int

the number of rows

columnCount:int

the numbers of columns

Method Detail

addEventHandlerback to summary
public <E extends Event> void addEventHandler(EventType<E> eventType, EventHandler<? super E> eventHandler)

Overrides default javafx.event.EventTarget.addEventHandler.

Implements org.controlsfx.control.spreadsheet.Grid.addEventHandler.

Doc from org.controlsfx.control.spreadsheet.Grid.addEventHandler.

Registers an event handler to this Grid. The Grid class allows registration of listeners which will be notified as a SpreadsheetCell's value will change.

buildEventDispatchChainback to summary
public EventDispatchChain buildEventDispatchChain(EventDispatchChain tail)

Implements javafx.event.EventTarget.buildEventDispatchChain.

Doc from javafx.event.EventTarget.buildEventDispatchChain.

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 EventTarget. This event target is not automatically added to the chain, so if it wants to process events, it needs to add an EventDispatcher for itself to the chain.

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.

Annotations
@Override
displaySelectionPropertyback to summary
public BooleanProperty displaySelectionProperty()

Implements org.controlsfx.control.spreadsheet.Grid.displaySelectionProperty.

Doc from org.controlsfx.control.spreadsheet.Grid.displaySelectionProperty.

Returns the Boolean property associated with the displayed selection of the Grid.

Annotations
@Override
getColumnCountback to summary
public int getColumnCount()

Implements org.controlsfx.control.spreadsheet.Grid.getColumnCount.

Doc from org.controlsfx.control.spreadsheet.Grid.getColumnCount.

Returns how many columns are inside the Grid.

Annotations
@Override
getColumnHeadersback to summary
public ObservableList<String> getColumnHeaders()

Implements org.controlsfx.control.spreadsheet.Grid.getColumnHeaders.

Doc from org.controlsfx.control.spreadsheet.Grid.getColumnHeaders.

Returns an ObservableList of String to display in the column headers.

Annotations
@Override
getRowCountback to summary
public int getRowCount()

Implements org.controlsfx.control.spreadsheet.Grid.getRowCount.

Doc from org.controlsfx.control.spreadsheet.Grid.getRowCount.

Returns how many rows are inside the Grid.

Annotations
@Override
getRowHeadersback to summary
public ObservableList<String> getRowHeaders()

Implements org.controlsfx.control.spreadsheet.Grid.getRowHeaders.

Doc from org.controlsfx.control.spreadsheet.Grid.getRowHeaders.

Returns an ObservableList of String to display in the row headers.

Annotations
@Override
getRowHeightback to summary
public double getRowHeight(int row)

Implements org.controlsfx.control.spreadsheet.Grid.getRowHeight.

Doc from org.controlsfx.control.spreadsheet.Grid.getRowHeight.

Returns the height of a row. AUTOFIT can be returned in order to let the system compute the best row height.

Annotations
@Override
getRowsback to summary
public ObservableList<ObservableList<SpreadsheetCell>> getRows()

Implements org.controlsfx.control.spreadsheet.Grid.getRows.

Doc from org.controlsfx.control.spreadsheet.Grid.getRows.

Returns an ObservableList of ObservableList of SpreadsheetCell instances. Refer to the Grid class javadoc for more detail.

Annotations
@Override
isCellDisplaySelectionback to summary
public boolean isCellDisplaySelection(int row, int column)

Implements org.controlsfx.control.spreadsheet.Grid.isCellDisplaySelection.

Doc from org.controlsfx.control.spreadsheet.Grid.isCellDisplaySelection.

Returns true if the given cell will display a selection rectangle when selected. If nothing is defined for this cell, isDisplaySelection() is returned.

Annotations
@Override
isDisplaySelectionback to summary
public boolean isDisplaySelection()

Implements org.controlsfx.control.spreadsheet.Grid.isDisplaySelection.

Doc from org.controlsfx.control.spreadsheet.Grid.isDisplaySelection.

Return true if the selection (black rectangle) is displayed on the Grid. Cells may override this property with setCellDisplaySelection(int, int, boolean).

Annotations
@Override
isLockedback to summary
public boolean isLocked()

Returns whether this GridBase id locked or not.

Returns:boolean

true if this GridBase is locked

isRowResizableback to summary
public boolean isRowResizable(int row)

Implements org.controlsfx.control.spreadsheet.Grid.isRowResizable.

Doc from org.controlsfx.control.spreadsheet.Grid.isRowResizable.

Returns true if the specified row is resizable.

Annotations
@Override
lockedPropertyback 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 SpreadsheetCell#isEditable() state.

Returns:BooleanProperty

a BooleanProperty associated with the locked grid state.

removeEventHandlerback to summary
public <E extends Event> void removeEventHandler(EventType<E> eventType, EventHandler<? super E> eventHandler)

Overrides default javafx.event.EventTarget.removeEventHandler.

Implements org.controlsfx.control.spreadsheet.Grid.removeEventHandler.

Doc from org.controlsfx.control.spreadsheet.Grid.removeEventHandler.

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.

setCellDisplaySelectionback to summary
public void setCellDisplaySelection(int row, int column, boolean displaySelection)

Implements org.controlsfx.control.spreadsheet.Grid.setCellDisplaySelection.

Doc from org.controlsfx.control.spreadsheet.Grid.setCellDisplaySelection.

Overrides the value defined by isDisplaySelection() so that no matter what is defined on the grid, the given cell will always have its selection set to the displaySelection parameter.

Annotations
@Override
setCellValueback to summary
public void setCellValue(int modelRow, int column, Object value)

Implements org.controlsfx.control.spreadsheet.Grid.setCellValue.

Doc from org.controlsfx.control.spreadsheet.Grid.setCellValue.

Changes the value situated at the intersection if possible. Verification and conversion of the value should be done before with SpreadsheetCellType#match(Object) and SpreadsheetCellType#convertValue(Object).

Annotations
@Override
setColumnCountback to summary
private void setColumnCount(int columnCount)

Set a new columnCount for the grid.

setDisplaySelectionback to summary
public void setDisplaySelection(boolean value)

Implements org.controlsfx.control.spreadsheet.Grid.setDisplaySelection.

Doc from org.controlsfx.control.spreadsheet.Grid.setDisplaySelection.

If set to true, the selection (black rectangle) will be displayed on the Grid. Cells may override this property with setCellDisplaySelection(int, int, boolean).

Annotations
@Override
setLockedback to summary
public void setLocked(Boolean lock)

Locks or unlocks this GridBase.

Parameters
lock:Boolean

true to lock this GridBase

setResizableRowsback to summary
public void setResizableRows(BitSet resizableRow)

Sets the resizable state of all rows. If a bit is set to true in the BitSet, it means the row is resizable. The BitSet#length() must be equal to the getRowCount()

Parameters
resizableRow:BitSet

a BitSet where the bits set to true represent the resizable rows

setRowCountback to summary
private void setRowCount(int rowCount)

Set a new rowCount for the grid.

setRowHeightCallbackback to summary
public void setRowHeightCallback(Callback<Integer, Double> rowHeight)

Sets a new Callback for this grid in order to specify height of each row.

Parameters
rowHeight:Callback<Integer, Double>

the Callback to use for rown height computation

setRowsback to summary
public void setRows(Collection<ObservableList<SpreadsheetCell>> rows)

Implements org.controlsfx.control.spreadsheet.Grid.setRows.

Doc from org.controlsfx.control.spreadsheet.Grid.setRows.

Sets the rows used by the grid, and updates the rowCount. This method should be called before the 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).

Annotations
@Override
spanColumnback to summary
public void spanColumn(int count, int rowIndex, int colIndex)

Implements org.controlsfx.control.spreadsheet.Grid.spanColumn.

Doc from org.controlsfx.control.spreadsheet.Grid.spanColumn.

Spans in column the cell situated at rowIndex and colIndex by the number count.

Annotations
@Override
spanRowback to summary
public void spanRow(int count, int rowIndex, int colIndex)

Implements org.controlsfx.control.spreadsheet.Grid.spanRow.

Doc from org.controlsfx.control.spreadsheet.Grid.spanRow.

Spans in row the cell situated at rowIndex and colIndex by the number count.

Annotations
@Override
org.controlsfx.control.spreadsheet back to summary

public Class GridBase.MapBasedRowHeightFactory

extends Object
implements Callback<Integer, Double>
Class Inheritance
  • java.lang.Object
  • org.controlsfx.control.spreadsheet.GridBase.MapBasedRowHeightFactory
All Implemented Interfaces
javafx.util.Callback

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).

Field Summary

Modifier and TypeField and Description
private final Map<Integer, Double>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public Double
call(Integer index)

Implements javafx.util.Callback.call.

The call method is called when required, and is given a single argument of type P, with a requirement that an object of type R is returned.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

rowHeightMapback to summary
private final Map<Integer, Double> rowHeightMap

Constructor Detail

MapBasedRowHeightFactoryback to summary
public MapBasedRowHeightFactory(Map<Integer, Double> rowHeightMap)

Method Detail

callback to summary
public Double call(Integer index)

Implements javafx.util.Callback.call.

Doc from javafx.util.Callback.call.

The call method is called when required, and is given a single argument of type P, with a requirement that an object of type R is returned.

Annotations
@Override