public class SpreadsheetCellBase extends java.lang.Object implements SpreadsheetCell, javafx.event.EventTarget
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
use one of the provided constructor. Usually you will let your SpreadsheetCellType
create the cells. For example
SpreadsheetCellType.StringType.createCell(int, int, int, int, java.lang.String).
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.
GridBase.spanColumn(int, int, int)
or GridBase.spanRow(int, int, int). These methods will handle the span
for you.
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");
}
Popup when clicked. This is useful when some
non editable cell wants to display several actions to take on the grid. This
feature is completely different from the Filter. Filters are shown on
one particular row whereas popup can be added to every cell.
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"))));
If you only want to only provide Graphics for visible cells (for example a
WebView), you can toggle setCellGraphic(boolean) and
provide the graphics with the factory in SpreadsheetView.setCellGraphicFactory(org.controlsfx.control.spreadsheet.CellGraphicFactory).

activateCorner(org.controlsfx.control.spreadsheet.SpreadsheetCell.CornerPosition). This allow you to activate or deactivate some graphics on the cell in
every corner. Right now it's a little red triangle but you can modify this in
your CSS by using the "cell-corner" style class.
.cell-corner.top-left{
-fx-background-color: red;
-fx-shape : "M 0 0 L 1 0 L 0 1 z";
}
setTooltip(java.lang.String).
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 |
|---|---|
javafx.beans.property.StringProperty |
format
Returns the
StringProperty linked with the format. |
javafx.beans.property.ObjectProperty<javafx.scene.Node> |
graphic
Returns the
ObjectProperty representing this cell graphic. |
javafx.beans.property.ObjectProperty<java.lang.Object> |
item
The item property represents the currently-set value inside this
SpreadsheetCell. |
javafx.beans.property.StringProperty |
style
A string representation of the CSS style associated with this specific
Node.
|
javafx.beans.property.ReadOnlyStringProperty |
text
Returns the StringProperty of the representation of the value.
|
SpreadsheetCell.CornerPositionCORNER_EVENT_TYPE, EDITABLE_EVENT_TYPE, WRAP_EVENT_TYPE| Constructor and Description |
|---|
SpreadsheetCellBase(int row,
int column,
int rowSpan,
int columnSpan)
Constructs a SpreadsheetCell with the given configuration.
|
SpreadsheetCellBase(int row,
int column,
int rowSpan,
int columnSpan,
SpreadsheetCellType<?> type)
Constructs a SpreadsheetCell with the given configuration.
|
| Modifier and Type | Method and Description |
|---|---|
void |
activateCorner(SpreadsheetCell.CornerPosition position)
Activates the given
CornerPosition in order to display a little
triangle in the cell. |
void |
addEventHandler(javafx.event.EventType<javafx.event.Event> eventType,
javafx.event.EventHandler<javafx.event.Event> eventHandler)
Registers an event handler to this SpreadsheetCell.
|
javafx.event.EventDispatchChain |
buildEventDispatchChain(javafx.event.EventDispatchChain tail) |
void |
deactivateCorner(SpreadsheetCell.CornerPosition position)
This deactivates the given
CornerPosition so that no triangle
will be shown for this cell. |
boolean |
equals(java.lang.Object obj) |
javafx.beans.property.StringProperty |
formatProperty()
Returns the
StringProperty linked with the format. |
SpreadsheetCellType |
getCellType()
Returns the
SpreadsheetCellType of this cell. |
int |
getColumn()
Returns the column index of this cell.
|
int |
getColumnSpan()
Returns how much this cell is spanning in column, 1 means the cell is not
spanning.
|
java.lang.String |
getFormat()
Returns the format of this cell or an empty string if no format has been
specified.
|
javafx.scene.Node |
getGraphic()
Returns the graphic node associated with this cell.
|
java.lang.Object |
getItem()
Returns the value contained in this cell.
|
java.util.List<java.lang.Object> |
getOptionsForEditor()
If some options cannot be factorized in a
SpreadsheetCellType and
are specific to a cell, you can return them here and the
SpreadsheetCellEditor will receive them. |
java.util.List<javafx.scene.control.MenuItem> |
getPopupItems()
If
SpreadsheetCell.hasPopup() is set to true, this method will be called when
the user clicks on the cell in order to gather the MenuItem to
show in the Popup. |
int |
getRow()
Returns the row index of this cell.
|
int |
getRowSpan()
Returns how much this cell is spanning in row, 1 means the cell is not
spanning.
|
java.lang.String |
getStyle()
A string representation of the CSS style associated with this specific
Node.
|
javafx.collections.ObservableSet<java.lang.String> |
getStyleClass()
Returns an
ObservableList of String of all the style
class associated with this cell. |
java.lang.String |
getText()
Returns the String representation currently used for display in the
SpreadsheetView. |
java.util.Optional<java.lang.String> |
getTooltip()
Returns the tooltip for this cell.
|
javafx.beans.property.ObjectProperty<javafx.scene.Node> |
graphicProperty()
Returns the
ObjectProperty representing this cell graphic. |
int |
hashCode() |
boolean |
hasPopup()
Returns true if this cell needs to display a popup when clicked in order
to show some
MenuItem like a MenuButton. |
boolean |
isCellGraphic()
Returns
true if this cell contains something particular in its
item and a Node given by the CellGraphicFactory will be used to
display it. |
boolean |
isCornerActivated(SpreadsheetCell.CornerPosition position)
Returns
true if a triangle is displayed in the cell for the given
CornerPosition. |
boolean |
isEditable()
Returns
true if this cell can be edited. |
boolean |
isWrapText()
If a run of text exceeds the width of the Labeled, then this variable
indicates whether the text should wrap onto another line.
|
javafx.beans.property.ObjectProperty<java.lang.Object> |
itemProperty()
The item property represents the currently-set value inside this
SpreadsheetCell. |
boolean |
match(java.lang.Object value)
Verifies that the upcoming cell value can be set to the current cell.
|
void |
removeEventHandler(javafx.event.EventType<javafx.event.Event> eventType,
javafx.event.EventHandler<javafx.event.Event> eventHandler)
Unregisters a previously registered event handler from this SpreadsheetCell.
|
void |
setCellGraphic(boolean isBrowser)
If
isCellGraphic is true, this cell item contains
something particular and should be display by using a Node provided by
CellGraphicFactory object in the CellView. |
void |
setColumnSpan(int columnSpan)
Sets how much this cell is spanning in column.
|
void |
setEditable(boolean editable)
Change the editable state of this cell
|
void |
setFormat(java.lang.String format)
Sets a new format for this cell.
|
void |
setGraphic(javafx.scene.Node graphic)
Sets a graphic for this cell.
|
void |
setHasPopup(boolean value)
Sets to
true if this cell needs to display a popup when clicked
in order to show some MenuItem like a MenuButton. |
void |
setItem(java.lang.Object value)
Sets the value of the property Item.
|
void |
setRowSpan(int rowSpan)
Sets how much this cell is spanning in row.
|
void |
setStyle(java.lang.String style)
A string representation of the CSS style associated with this specific
Node.
|
void |
setTooltip(java.lang.String tooltip)
Set a new tooltip for this cell.
|
void |
setWrapText(boolean wrapText)
If a run of text exceeds the width of the Labeled, then this variable
indicates whether the text should wrap onto another line.
|
javafx.beans.property.StringProperty |
styleProperty()
A string representation of the CSS style associated with this specific
Node.
|
javafx.beans.property.ReadOnlyStringProperty |
textProperty()
Returns the StringProperty of the representation of the value.
|
java.lang.String |
toString() |
protected void |
updateText()
Update the text for the SpreadsheetView.
|
public final javafx.beans.property.ObjectProperty<java.lang.Object> itemProperty
SpreadsheetCell.itemProperty in interface SpreadsheetCellgetItem(),
setItem(Object)public final javafx.beans.property.StringProperty formatProperty
StringProperty linked with the format.formatProperty in interface SpreadsheetCellgetFormat(),
setFormat(String)public final javafx.beans.property.ReadOnlyStringProperty textProperty
textProperty in interface SpreadsheetCellgetText()public javafx.beans.property.StringProperty styleProperty
styleProperty in interface SpreadsheetCellgetStyle(),
setStyle(String)public javafx.beans.property.ObjectProperty<javafx.scene.Node> graphicProperty
ObjectProperty representing this cell graphic.graphicProperty in interface SpreadsheetCellgetGraphic(),
setGraphic(Node)public SpreadsheetCellBase(int row,
int column,
int rowSpan,
int columnSpan)
SpreadsheetCellType.OBJECT type.row - column - rowSpan - columnSpan - public SpreadsheetCellBase(int row,
int column,
int rowSpan,
int columnSpan,
SpreadsheetCellType<?> type)
row - column - rowSpan - columnSpan - type - public boolean match(java.lang.Object value)
match in interface SpreadsheetCellvalue - the value that needs to be testedtrue if the upcoming cell value can be set to the current
cellpublic final void setItem(java.lang.Object value)
Grid.setCellValue(int, int, Object) after
because it will compute correctly the modifiedCell. If
SpreadsheetCell.isEditable() return false, nothing is done.setItem in interface SpreadsheetCellpublic final java.lang.Object getItem()
getItem in interface SpreadsheetCellpublic final javafx.beans.property.ObjectProperty<java.lang.Object> itemProperty()
SpreadsheetCell.itemProperty in interface SpreadsheetCellgetItem(),
setItem(Object)public final boolean isEditable()
true if this cell can be edited.isEditable in interface SpreadsheetCelltrue if this cell is editablepublic final void setEditable(boolean editable)
setEditable in interface SpreadsheetCelleditable - true if this cell should be editablepublic boolean isWrapText()
isWrapText in interface SpreadsheetCelltrue if the text should wrap onto another line if it
exceeds the width of the Labeledpublic boolean isCellGraphic()
true if this cell contains something particular in its
item and a Node given by the CellGraphicFactory will be used to
display it.isCellGraphic in interface SpreadsheetCelltrue if this cell item needs to be given to a particular
Nodepublic void setCellGraphic(boolean isBrowser)
isCellGraphic is true, this cell item contains
something particular and should be display by using a Node provided by
CellGraphicFactory object in the CellView.
If you only seek to place a simple Node for this cell, simply use SpreadsheetCell.setGraphic(javafx.scene.Node).setCellGraphic in interface SpreadsheetCellisBrowser - if true, a Node will be used to display
something particular for the cellpublic void setWrapText(boolean wrapText)
setWrapText in interface SpreadsheetCellwrapText - true if the text should wrap onto another line if
it exceeds the width of the Labeledpublic java.util.List<java.lang.Object> getOptionsForEditor()
SpreadsheetCellType and
are specific to a cell, you can return them here and the
SpreadsheetCellEditor will receive them.getOptionsForEditor in interface SpreadsheetCellList of options for the SpreadsheetCellEditorpublic boolean hasPopup()
MenuItem like a MenuButton.
The items can be set in SpreadsheetCell.getPopupItems().hasPopup in interface SpreadsheetCelltrue if this cell needs to display a popuppublic void setHasPopup(boolean value)
true if this cell needs to display a popup when clicked
in order to show some MenuItem like a MenuButton.setHasPopup in interface SpreadsheetCellvalue - true to display a Popup when clickedpublic java.util.List<javafx.scene.control.MenuItem> getPopupItems()
SpreadsheetCell.hasPopup() is set to true, this method will be called when
the user clicks on the cell in order to gather the MenuItem to
show in the Popup.getPopupItems in interface SpreadsheetCellMenuItem to show in the Popuppublic final javafx.beans.property.StringProperty formatProperty()
StringProperty linked with the format.formatProperty in interface SpreadsheetCellgetFormat(),
setFormat(String)public final java.lang.String getFormat()
getFormat in interface SpreadsheetCellpublic final void setFormat(java.lang.String format)
SpreadsheetCellType.toString(java.lang.Object, java.lang.String). This should be used by numbers for example.setFormat in interface SpreadsheetCellformat - a string pattern understood by the
SpreadsheetCellTypepublic final javafx.beans.property.ReadOnlyStringProperty textProperty()
textProperty in interface SpreadsheetCellgetText()public final java.lang.String getText()
SpreadsheetView.getText in interface SpreadsheetCellpublic final SpreadsheetCellType getCellType()
SpreadsheetCellType of this cell.getCellType in interface SpreadsheetCellSpreadsheetCellType of this cell.public final int getRow()
getRow in interface SpreadsheetCellpublic final int getColumn()
getColumn in interface SpreadsheetCellpublic final int getRowSpan()
getRowSpan in interface SpreadsheetCellpublic final void setRowSpan(int rowSpan)
SpreadsheetCell
description for information. You should use
Grid.spanRow(int, int, int) instead of using this method
directly.
1 means the cell is not spanning. Thus, the rowSpan should not be
inferior to 1.setRowSpan in interface SpreadsheetCellrowSpan - the rowSpan for this cellpublic final int getColumnSpan()
getColumnSpan in interface SpreadsheetCellpublic final void setColumnSpan(int columnSpan)
SpreadsheetCell description for information. You should use
Grid.spanColumn(int, int, int) instead of using this method
directly.
1 means the cell is not spanning. Thus, the rowSpan should not be
inferior to 1.setColumnSpan in interface SpreadsheetCellcolumnSpan - the columnSpan for this cellpublic final javafx.collections.ObservableSet<java.lang.String> getStyleClass()
ObservableList of String of all the style
class associated with this cell. You can easily modify its appearance by
adding a style class (previously set in CSS).getStyleClass in interface SpreadsheetCellObservableList of String of all the style
class of this cellpublic void setStyle(java.lang.String style)
setStyle in interface SpreadsheetCellstyle - a string representation of the CSS style associated with
this specific Nodepublic java.lang.String getStyle()
getStyle in interface SpreadsheetCellpublic javafx.beans.property.StringProperty styleProperty()
styleProperty in interface SpreadsheetCellgetStyle(),
setStyle(String)public javafx.beans.property.ObjectProperty<javafx.scene.Node> graphicProperty()
ObjectProperty representing this cell graphic.graphicProperty in interface SpreadsheetCellgetGraphic(),
setGraphic(Node)public void setGraphic(javafx.scene.Node graphic)
setGraphic in interface SpreadsheetCellgraphic - a graphic to display for this cellpublic javafx.scene.Node getGraphic()
getGraphic in interface SpreadsheetCellpublic java.util.Optional<java.lang.String> getTooltip()
getTooltip in interface SpreadsheetCellSpreadsheetCellpublic void setTooltip(java.lang.String tooltip)
tooltip - public void activateCorner(SpreadsheetCell.CornerPosition position)
CornerPosition in order to display a little
triangle in the cell.activateCorner in interface SpreadsheetCellposition - the position where the triangle should be displayedpublic void deactivateCorner(SpreadsheetCell.CornerPosition position)
CornerPosition so that no triangle
will be shown for this cell.deactivateCorner in interface SpreadsheetCellposition - the position where the triangle should be removed if
displayedpublic boolean isCornerActivated(SpreadsheetCell.CornerPosition position)
true if a triangle is displayed in the cell for the given
CornerPosition.isCornerActivated in interface SpreadsheetCelltrue if a triangle is displayed in the cell for the given
CornerPositionpublic javafx.event.EventDispatchChain buildEventDispatchChain(javafx.event.EventDispatchChain tail)
buildEventDispatchChain in interface javafx.event.EventTargetpublic java.lang.String toString()
toString in class java.lang.Objectpublic final boolean equals(java.lang.Object obj)
equals in class java.lang.Objectpublic final int hashCode()
hashCode in class java.lang.Objectpublic void addEventHandler(javafx.event.EventType<javafx.event.Event> eventType,
javafx.event.EventHandler<javafx.event.Event> eventHandler)
addEventHandler in interface SpreadsheetCelleventType - the type of the events to receive by the handlereventHandler - the handler to registerjava.lang.NullPointerException - if the event type or handler is nullpublic void removeEventHandler(javafx.event.EventType<javafx.event.Event> eventType,
javafx.event.EventHandler<javafx.event.Event> eventHandler)
removeEventHandler in interface SpreadsheetCelleventType - the event type from which to unregistereventHandler - the handler to unregisterjava.lang.NullPointerException - if the event type or handler is nullprotected void updateText()