public class SpreadsheetCell extends Object
SpreadsheetView. Grid.
SpreadsheetCellType which has its own SpreadsheetCellEditor
in order to control very closely the possible modifications.
Different SpreadsheetCellTypes are available
depending on the data you want to represent in your SpreadsheetView.
You can use the different static method provided in
SpreadsheetCellType in order to create the specialized
SpreadsheetCell that suits your need.
If you want to create a SpreadsheetCell of your own, you simply have to
create your own SpreadsheetCellType and implement the abstract method
SpreadsheetCellType.createCell(int, int, int, int, Object). You will
also have to provide a custom SpreadsheetCellEditor.
row and column span. You
can specify if you want the cell to be editable or not using
setEditable(boolean). Be advised that a cell with a rowSpan means
that the cell will replace all the cells situated in the rowSpan range. Same
with the column span. The best way to handle spanning is to fill your grid
with unique cells, and then call GridBase.spanColumn(int, int, int)
or GridBase.spanRow(int, int, int). SpreadsheetCellType and then specify for each cell their format with
setFormat(String). You will then have the guaranty that all your
cells will have a LocalDate as a value, but the value will be displayed
differently for each cell. This will also guaranty that copy/paste and other
operation will be compatible since every cell will share the same
SpreadsheetCellType.
SpreadsheetCell cell = SpreadsheetCellType.DATE.createCell(row, column, rowSpan, colSpan,
LocalDate.now().plusDays((int) (Math.random() * 10))); // Random value
// given here
final double random = Math.random();
if (random < 0.25) {
cell.setFormat("EEEE d");
} else if (random < 0.5) {
cell.setFormat("dd/MM :YY");
} else {
cell.setFormat("dd/MM/YYYY");
}

setGraphic(Node) in order to specify the graphic you want.
If you specify an ImageView, the SpreadsheetView will try to resize it in
order to fit the space available in the cell.
For example :
cell.setGraphic(new ImageView(new Image(getClass().getResourceAsStream("icons/exclamation.png"))));

commentedProperty(). This allow you to specify whether
this cell has or not a unique property (here a comment). Therefore, you will
have a visual feedback for every cell that has that property set to true.
Right now it's a little red triangle but you can modify this in your CSS by
using the "comment" style class.
.comment{
-fx-background-color: red;
-fx-shape : "M 0 0 L -1 0 L 0 1 z";
}

getStyleClass(). You just have to create and custom that class in
your CSS stylesheet associated with your SpreadsheetView. Also note
that all SpreadsheetCell have a "spreadsheet-cell" styleClass
added by default. Here is a example :
cell.getStyleClass().add("row_header");
And in the CSS:
.spreadsheet-cell.row_header{
-fx-background-color: #b4d4ad ;
-fx-background-insets: 0, 0 1 1 0;
-fx-alignment: center;
}
SpreadsheetCellType
types. The generation is random here so you will want to replace the logic to
suit your needs.
private SpreadsheetCell<?> generateCell(int row, int column, int rowSpan, int colSpan) {
List<String?> stringListTextCell = Arrays.asList("Shanghai","Paris","New York City","Bangkok","Singapore","Johannesburg","Berlin","Wellington","London","Montreal");
final double random = Math.random();
if (random < 0.10) {
List<String?> stringList = Arrays.asList("China","France","New Zealand","United States","Germany","Canada");
cell = SpreadsheetCellType.LIST(stringList).createCell(row, column, rowSpan, colSpan, stringList.get((int) (Math.random() * 6)));
} else if (random ?>= 0.10 && random < 0.25) {
cell = SpreadsheetCellType.STRING.createCell(row, column, rowSpan, colSpan,stringListTextCell.get((int)(Math.random()*10)));
} else if (random ?>= 0.25 && random < 0.75) {
cell = SpreadsheetCellType.DOUBLE.createCell(row, column, rowSpan, colSpan,(double)Math.round((Math.random()*100)*100)/100);
} else {
cell = SpreadsheetCellType.DATE.createCell(row, column, rowSpan, colSpan, LocalDate.now().plusDays((int)(Math.random()*10)));
}
return cell;
}
SpreadsheetView,
SpreadsheetCellEditor,
SpreadsheetCellType| Type | Property and Description |
|---|---|
BooleanProperty |
commented
The
BooleanProperty linked with the commented state. |
BooleanProperty |
editable
The
BooleanProperty linked with the editable state. |
StringProperty |
format
The
StringProperty linked with the format. |
ObjectProperty<Node> |
graphic |
ObjectProperty<Object> |
item
The item property represents the currently-set value inside this
SpreadsheetCell instance.
|
ReadOnlyStringProperty |
text
Return the StringProperty of the representation of the value.
|
| Constructor and Description |
|---|
SpreadsheetCell(int row,
int column,
int rowSpan,
int columnSpan)
Constructor
|
SpreadsheetCell(int row,
int column,
int rowSpan,
int columnSpan,
SpreadsheetCellType<?> type)
Constructs a SpreadsheetCell with the given configuration.
|
| Modifier and Type | Method and Description |
|---|---|
BooleanProperty |
commentedProperty()
The
BooleanProperty linked with the commented state. |
BooleanProperty |
editableProperty()
The
BooleanProperty linked with the editable state. |
boolean |
equals(Object obj) |
StringProperty |
formatProperty()
The
StringProperty linked with the format. |
SpreadsheetCellType<?> |
getCellType()
Return the
SpreadsheetCellType of this particular cell. |
int |
getColumn()
Return the column of this cell.
|
int |
getColumnSpan()
Return how much this cell is spanning in column, 1 is normal.
|
String |
getFormat()
Return the format of this cell or an empty string if no format has been
specified.
|
Node |
getGraphic()
Return the graphic node associated with this cell.
|
Object |
getItem()
Return the value contained in the cell.
|
ObservableMap<Object,Object> |
getProperties()
Returns an observable map of properties on this node for use primarily by
application developers.
|
int |
getRow()
Return the row of this cell.
|
int |
getRowSpan()
Return how much this cell is spanning in row, 1 is normal.
|
ObservableSet<String> |
getStyleClass()
Return an ObservableList of String of all the style class associated with
this cell.
|
String |
getText()
Return the String representation currently used for display in the
SpreadsheetView. |
ObjectProperty<Node> |
graphicProperty() |
int |
hashCode() |
boolean |
hasProperties()
Tests if Node has properties.
|
boolean |
isCommented()
Return if this cell has a comment or not.
|
boolean |
isEditable()
Return if this cell can be edited or not.
|
ObjectProperty<Object> |
itemProperty()
The item property represents the currently-set value inside this
SpreadsheetCell instance.
|
boolean |
match(SpreadsheetCell cell)
Verify that the upcoming cell value can be set to the current cell.
|
void |
setColumnSpan(int columnSpan)
Sets how much this cell is spanning in column.
|
void |
setCommented(boolean flag)
Change the commented state of this cell.
|
void |
setEditable(boolean readOnly)
Change the editable state of this cell
|
void |
setFormat(String format)
Set a new format for this Cell.
|
void |
setGraphic(Node graphic)
Set a graphic for this cell to display aside with the text.
|
void |
setItem(Object value)
Sets the value of the property Item.
|
void |
setRowSpan(int rowSpan)
Sets how much this cell is spanning in row.
|
ReadOnlyStringProperty |
textProperty()
Return the StringProperty of the representation of the value.
|
String |
toString() |
public final ObjectProperty<Object> itemProperty
public final BooleanProperty editableProperty
BooleanProperty linked with the editable state.isEditable(),
setEditable(boolean)public final BooleanProperty commentedProperty
BooleanProperty linked with the commented state.isCommented(),
setCommented(boolean)public final StringProperty formatProperty
StringProperty linked with the format.getFormat(),
setFormat(String)public final ReadOnlyStringProperty textProperty
getText()public ObjectProperty<Node> graphicProperty
getGraphic(),
setGraphic(Node)public SpreadsheetCell(int row,
int column,
int rowSpan,
int columnSpan)
public SpreadsheetCell(int row,
int column,
int rowSpan,
int columnSpan,
SpreadsheetCellType<?> type)
row - column - rowSpan - columnSpan - type - public boolean match(SpreadsheetCell cell)
cell - public final void setItem(Object value)
Grid.setCellValue(int, int, Object) after
because it will compute correctly the modifiedCell. If
isEditable() return false, nothing is done.value - public final Object getItem()
public final ObjectProperty<Object> itemProperty()
public final boolean isEditable()
public final void setEditable(boolean readOnly)
readOnly - public final BooleanProperty editableProperty()
BooleanProperty linked with the editable state.isEditable(),
setEditable(boolean)public final boolean isCommented()
public final void setCommented(boolean flag)
flag - public final BooleanProperty commentedProperty()
BooleanProperty linked with the commented state.isCommented(),
setCommented(boolean)public final StringProperty formatProperty()
StringProperty linked with the format.getFormat(),
setFormat(String)public final String getFormat()
public final void setFormat(String format)
format - public final ReadOnlyStringProperty textProperty()
getText()public final String getText()
SpreadsheetView.public final SpreadsheetCellType<?> getCellType()
SpreadsheetCellType of this particular cell.SpreadsheetCellType of this particular cell.public final int getRow()
public final int getColumn()
public final int getRowSpan()
public final void setRowSpan(int rowSpan)
SpreadsheetCell
description for information. You should use
GridBase.spanRow(int, int, int) instead of using this method
directly.rowSpan - public final int getColumnSpan()
public final void setColumnSpan(int columnSpan)
SpreadsheetCell description for information. You should use
GridBase.spanColumn(int, int, int) instead of using this method
directly.columnSpan - public final ObservableSet<String> getStyleClass()
public final ObservableMap<Object,Object> getProperties()
public final boolean hasProperties()
public ObjectProperty<Node> graphicProperty()
getGraphic(),
setGraphic(Node)public void setGraphic(Node graphic)
graphic - public Node getGraphic()