- java.lang.Object
-
- org.tentackle.fx.FxUtilities
-
@Service(FxUtilities.class) public class FxUtilities extends java.lang.Object
Utility methods for Fx.- Author:
- harald
-
-
Constructor Summary
Constructors Constructor Description FxUtilities()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddStyleSheet(java.lang.String url)Adds a stylesheet for the whole applicationvoidaddStyleSheets()Configures the application-wide CSS.protected booleanapplyBindingOption(FxTextComponent comp, org.tentackle.bind.BindingMember member, java.lang.String option)Applies a single binding option to a text component.protected booleanapplyBindingOption(TableColumnConfiguration columnConfiguration, org.tentackle.bind.BindingMember member, java.lang.String option)Processes an option for a table binding.voidapplyBindingOptions(FxTextComponent comp, org.tentackle.bind.BindingMember member, java.lang.String options)Applies the bindable options to a text component.voidapplyBindingOptions(TableColumnConfiguration columnConfiguration, org.tentackle.bind.BindingMember member, java.lang.String options)Applies the bindable options to a table column.voidcloseStageHierarchy(javafx.scene.Node node, javafx.stage.Stage stopStage)Closes the hierarchy of stages from the given node stopping at given stage.javafx.geometry.Point2DdetermineAlignedStageLocation(javafx.stage.Stage stage, javafx.geometry.Point2D location)Calculates the location of a stage so that it is completely visible on the screen, using a "free" spot.javafx.geometry.Point2DdetermineCenteredLocation(javafx.stage.Window window)Calculates the location of a window so that it will be centered on the screen.javafx.geometry.Point2DdeterminePreferredStageLocation(javafx.stage.Stage stage)Calculates the position of a stage on the screen so that it is being display in an optimal manner.java.lang.StringdumpComponentHierarchy(javafx.scene.Node node)Dumps the component hierarchy.voidfilterKeys(javafx.scene.control.Control control)Filters certain keys for special features.voidfocusGained(FxComponent component)Performs all necessary operations on an FxComponent when it gained the focus.voidfocusLost(FxComponent component)Performs all necessary operations on an FxComponent when it lost the focus.javafx.collections.ObservableList<javafx.stage.Stage>getAllShowingStages()Delivers a lis of all showing stages.java.lang.StringgetBindingOption(java.lang.String options, java.lang.String key)Gets a binding option from an options string.intgetDefaultTextAreaColumns(FxTextArea textArea)Gets the default column width for text areas if not set by the binding or the model's COLS= option.static FxUtilitiesgetInstance()The singleton.longgetPrefixSelectionTimeout()Gets the timeout for the prefix selection in dropdown lists such as in comboboxes.javafx.stage.StagegetStage(javafx.scene.Node node)Gets the stage for a node.booleanisLenientMoneyInput(FxTextComponent component)Returns whether decimal separator should be inserted automatically if missing in money input.
This is usually a global setting for the whole application, but it can be filtered according to the component (parent component, etc...).booleanisModal(javafx.stage.Stage stage)Returns whether the stage is modal.voidprint(javafx.scene.Node node)Prints a node.
The user selects the printer and the node is scaled down if too large for the paper.voidregisterWindowEventFilters(javafx.stage.Window window)Registers event filters for windows.voidremapKeys(javafx.scene.control.Control control)Remaps certain keys.voidresizeColumnsToFitContent(javafx.scene.control.TableView<?> table)Resizes the width of all columns of a table to fit the displayed content.
Unlike the "double-click on column separator"-feature this method computes the column widths according to the content currently displayed.voidrunAndWait(java.lang.Runnable runnable)Runs a command on the FX application thread and waits for its execution to finish.protected voidsetAlertMessage(javafx.scene.control.Alert alert, java.lang.String message)Workaround for the bug that messages are not completely displayed if text is wrapped.voidsetupFocusHandling(javafx.scene.control.Control control)Adds focus handling to sync with model.javafx.scene.control.AlertshowErrorDialog(java.lang.String message, java.lang.Throwable t, java.lang.String title)Shows an error dialog.javafx.stage.PopupWindowshowErrorPopup(ErrorPopupSupported component)Shows an error popup for a component.voidshowHelp(FxControl control)Opens the online help for a given component.javafx.scene.control.AlertshowInfoDialog(java.lang.String message, java.lang.String title)Shows an info dialog.javafx.stage.PopupWindowshowInfoPopup(InfoPopupSupported component)Shows an info popup for a component.javafx.scene.control.AlertshowQuestionDialog(java.lang.String message, boolean defaultYes, java.lang.String title, java.util.function.Consumer<java.lang.Boolean> answer)Shows a question dialog.
To avoid showAndWait, the method returns void and the result is provided via a Consumer.javafx.scene.control.AlertshowWarningDialog(java.lang.String message, java.lang.String title)Shows a warning dialog.
-
-
-
Method Detail
-
getInstance
public static FxUtilities getInstance()
The singleton.- Returns:
- the singleton
-
isLenientMoneyInput
public boolean isLenientMoneyInput(FxTextComponent component)
Returns whether decimal separator should be inserted automatically if missing in money input.
This is usually a global setting for the whole application, but it can be filtered according to the component (parent component, etc...).- Parameters:
component- the input component- Returns:
- true if insert separator according to scale if missing
-
getDefaultTextAreaColumns
public int getDefaultTextAreaColumns(FxTextArea textArea)
Gets the default column width for text areas if not set by the binding or the model's COLS= option.- Parameters:
textArea- the text area component- Returns:
- the column width (default is 30)
-
getPrefixSelectionTimeout
public long getPrefixSelectionTimeout()
Gets the timeout for the prefix selection in dropdown lists such as in comboboxes.- Returns:
- the timeout in milliseconds (default is 500)
-
showHelp
public void showHelp(FxControl control)
Opens the online help for a given component.- Parameters:
control- the Fx control
-
getStage
public javafx.stage.Stage getStage(javafx.scene.Node node)
Gets the stage for a node.- Parameters:
node- the node- Returns:
- the stage, null if node does not belong to a scene or scene does not belong to a stage.
-
isModal
public boolean isModal(javafx.stage.Stage stage)
Returns whether the stage is modal.- Parameters:
stage- the stage- Returns:
- true if effectively modal
-
closeStageHierarchy
public void closeStageHierarchy(javafx.scene.Node node, javafx.stage.Stage stopStage)Closes the hierarchy of stages from the given node stopping at given stage.- Parameters:
node- the nodestopStage- the stop stage, null to close the whole application
-
dumpComponentHierarchy
public java.lang.String dumpComponentHierarchy(javafx.scene.Node node)
Dumps the component hierarchy.- Parameters:
node- the node- Returns:
- the formatted string
-
runAndWait
public void runAndWait(java.lang.Runnable runnable)
Runs a command on the FX application thread and waits for its execution to finish.- Parameters:
runnable- the Runnable whose run method will be executed on the FX application thread- Throws:
FxRuntimeException- if the calling thread is the FX application thread- See Also:
Platform.runLater(java.lang.Runnable)
-
setAlertMessage
protected void setAlertMessage(javafx.scene.control.Alert alert, java.lang.String message)Workaround for the bug that messages are not completely displayed if text is wrapped.- Parameters:
alert- the alert dialogmessage- the text message
-
showInfoDialog
public javafx.scene.control.Alert showInfoDialog(java.lang.String message, java.lang.String title)Shows an info dialog.- Parameters:
message- the messagetitle- optional title- Returns:
- the alert dialog
-
showWarningDialog
public javafx.scene.control.Alert showWarningDialog(java.lang.String message, java.lang.String title)Shows a warning dialog.- Parameters:
message- the messagetitle- optional title- Returns:
- the alert dialog
-
showQuestionDialog
public javafx.scene.control.Alert showQuestionDialog(java.lang.String message, boolean defaultYes, java.lang.String title, java.util.function.Consumer<java.lang.Boolean> answer)Shows a question dialog.
To avoid showAndWait, the method returns void and the result is provided via a Consumer.- Parameters:
message- the messagedefaultYes- true if yes is the default buttontitle- optional titleanswer- the user's answer (invoked with Boolean.TRUE or Boolean.FALSE, never null)- Returns:
- the alert dialog
- See Also:
Consumer,Holder
-
showErrorDialog
public javafx.scene.control.Alert showErrorDialog(java.lang.String message, java.lang.Throwable t, java.lang.String title)Shows an error dialog.- Parameters:
message- the messaget- optional throwabletitle- optional title- Returns:
- the alert dialog
-
showErrorPopup
public javafx.stage.PopupWindow showErrorPopup(ErrorPopupSupported component)
Shows an error popup for a component.- Parameters:
component- the component- Returns:
- the popup, null if no errormessage in component
-
showInfoPopup
public javafx.stage.PopupWindow showInfoPopup(InfoPopupSupported component)
Shows an info popup for a component.- Parameters:
component- the component- Returns:
- the popup, null if no infomessage in component
-
setupFocusHandling
public void setupFocusHandling(javafx.scene.control.Control control)
Adds focus handling to sync with model.- Parameters:
control- the fx control
-
focusGained
public void focusGained(FxComponent component)
Performs all necessary operations on an FxComponent when it gained the focus.- Parameters:
component- the fx component
-
focusLost
public void focusLost(FxComponent component)
Performs all necessary operations on an FxComponent when it lost the focus.- Parameters:
component- the fx component
-
remapKeys
public void remapKeys(javafx.scene.control.Control control)
Remaps certain keys.- Parameters:
control- the fx control
-
filterKeys
public void filterKeys(javafx.scene.control.Control control)
Filters certain keys for special features.- Parameters:
control- the fx control
-
registerWindowEventFilters
public void registerWindowEventFilters(javafx.stage.Window window)
Registers event filters for windows.- Parameters:
window- the window
-
print
public void print(javafx.scene.Node node)
Prints a node.
The user selects the printer and the node is scaled down if too large for the paper.- Parameters:
node- the node to print
-
addStyleSheet
public void addStyleSheet(java.lang.String url)
Adds a stylesheet for the whole application- Parameters:
url- The file URL, either relative or absolute, as a String
-
addStyleSheets
public void addStyleSheets()
Configures the application-wide CSS.
-
getBindingOption
public java.lang.String getBindingOption(java.lang.String options, java.lang.String key)Gets a binding option from an options string.- Parameters:
options- the binding options stringkey- the option key- Returns:
- the option, null if no such option
-
applyBindingOptions
public void applyBindingOptions(FxTextComponent comp, org.tentackle.bind.BindingMember member, java.lang.String options)
Applies the bindable options to a text component.- Parameters:
comp- the componentmember- the binding memberoptions- the options from the @Bindableannotation
-
applyBindingOptions
public void applyBindingOptions(TableColumnConfiguration columnConfiguration, org.tentackle.bind.BindingMember member, java.lang.String options)
Applies the bindable options to a table column.- Parameters:
columnConfiguration- the column configurationmember- the binding memberoptions- the options from the @Bindableannotation
-
applyBindingOption
protected boolean applyBindingOption(FxTextComponent comp, org.tentackle.bind.BindingMember member, java.lang.String option)
Applies a single binding option to a text component.- Parameters:
comp- the componentmember- the binding memberoption- the option- Returns:
- true if option known and applied, false if unknown option
-
applyBindingOption
protected boolean applyBindingOption(TableColumnConfiguration columnConfiguration, org.tentackle.bind.BindingMember member, java.lang.String option)
Processes an option for a table binding.- Parameters:
columnConfiguration- the column configmember- the binding memberoption- the option- Returns:
- true if option known and processed, false if unknown option
-
resizeColumnsToFitContent
public void resizeColumnsToFitContent(javafx.scene.control.TableView<?> table)
Resizes the width of all columns of a table to fit the displayed content.
Unlike the "double-click on column separator"-feature this method computes the column widths according to the content currently displayed. For tables with a large number of rows this is much more efficient than scanning the whole table.- Parameters:
table- the table view
-
getAllShowingStages
public javafx.collections.ObservableList<javafx.stage.Stage> getAllShowingStages()
Delivers a lis of all showing stages.- Returns:
- the stages
-
determineCenteredLocation
public javafx.geometry.Point2D determineCenteredLocation(javafx.stage.Window window)
Calculates the location of a window so that it will be centered on the screen.- Parameters:
window- the window- Returns:
- the location (top left corner)
-
determinePreferredStageLocation
public javafx.geometry.Point2D determinePreferredStageLocation(javafx.stage.Stage stage)
Calculates the position of a stage on the screen so that it is being display in an optimal manner.- Parameters:
stage- the stage to be positioned on the screen- Returns:
- the location
-
determineAlignedStageLocation
public javafx.geometry.Point2D determineAlignedStageLocation(javafx.stage.Stage stage, javafx.geometry.Point2D location)Calculates the location of a stage so that it is completely visible on the screen, using a "free" spot.- Parameters:
stage- the current stagelocation- the desired (not necessarily current!) location- Returns:
- the aligned location
-
-