- java.lang.Object
-
- javafx.scene.Node
-
- javafx.scene.Parent
-
- javafx.scene.layout.Region
-
- javafx.scene.control.Control
-
- org.controlsfx.control.Rating
-
- All Implemented Interfaces:
Styleable
,EventTarget
,Skinnable
public class Rating extends Control
A control for allowing users to provide a rating. This control supportspartial ratings
(i.e. not whole numbers and dependent upon where the user clicks in the control) andupdating the rating on hover
. Read on for more examples!Examples
It can be hard to appreciate some of the features of the Rating control, so hopefully the following screenshots will help. Firstly, here is what the standard (horizontal) Rating control looks like when it has five stars, and a rating of two:
To create a Rating control that looks like this is simple:
final Rating rating = new Rating();
This creates a default horizontal rating control. To create a vertical Rating control, simply change the orientation, as such:
final Rating rating = new Rating(); rating.setOrientation(Orientation.VERTICAL);
The end result of making this one line change is shown in the screenshot below:
One of the features of the Rating control is that it doesn't just allow for 'integer' ratings: it also allows for the user to click anywhere within the rating area to set a 'float' rating. This is hard to describe, but easy to show in a picture:
In essence, in the screenshot above, the user clicked roughly in the middle of the third star. This results in a rating of approximately 2.44. To enable
partial ratings
, simply do the following when instantiating the Rating control:final Rating rating = new Rating(); rating.setPartialRating(true);
So far all of the Rating controls demonstrated above have required the user to click on the stars to register their rating. This may not be the preferred user interaction - often times the preferred approach is to simply allow for the rating to be registered by the user hovering their mouse over the rating stars. This mode is also supported by the Rating control, using the
update on hover
property, as such:final Rating rating = new Rating(); rating.setUpdateOnHover(true);
It is also allowable to have a Rating control that both updates on hover and allows for partial values: the 'golden fill' of the default graphics will automatically follow the users mouse as they move it along the Rating scale. To enable this, just set both properties to true.
-
-
Property Summary
Properties Type Property Description IntegerProperty
max
The maximum-allowed rating value.ObjectProperty<Orientation>
orientation
TheOrientation
of theRating
- this can either be horizontal or vertical.BooleanProperty
partialRating
If true this allows for users to set a rating as a floating point value.DoubleProperty
rating
The current rating value.BooleanProperty
updateOnHover
If true this allows for therating property
to be updated simply by the user hovering their mouse over the control.-
Properties inherited from class javafx.scene.control.Control
contextMenu, skin, tooltip
-
Properties inherited from class javafx.scene.layout.Region
background, border, cacheShape, centerShape, height, insets, maxHeight, maxWidth, minHeight, minWidth, opaqueInsets, padding, prefHeight, prefWidth, scaleShape, shape, snapToPixel, width
-
Properties inherited from class javafx.scene.Parent
needsLayout
-
Properties inherited from class javafx.scene.Node
accessibleHelp, accessibleRoleDescription, accessibleRole, accessibleText, blendMode, boundsInLocal, boundsInParent, cacheHint, cache, clip, cursor, depthTest, disabled, disable, effectiveNodeOrientation, effect, eventDispatcher, focused, focusTraversable, hover, id, inputMethodRequests, layoutBounds, layoutX, layoutY, localToParentTransform, localToSceneTransform, managed, mouseTransparent, nodeOrientation, onContextMenuRequested, onDragDetected, onDragDone, onDragDropped, onDragEntered, onDragExited, onDragOver, onInputMethodTextChanged, onKeyPressed, onKeyReleased, onKeyTyped, onMouseClicked, onMouseDragEntered, onMouseDragExited, onMouseDragged, onMouseDragOver, onMouseDragReleased, onMouseEntered, onMouseExited, onMouseMoved, onMousePressed, onMouseReleased, onRotate, onRotationFinished, onRotationStarted, onScrollFinished, onScroll, onScrollStarted, onSwipeDown, onSwipeLeft, onSwipeRight, onSwipeUp, onTouchMoved, onTouchPressed, onTouchReleased, onTouchStationary, onZoomFinished, onZoom, onZoomStarted, opacity, parent, pickOnBounds, pressed, rotate, rotationAxis, scaleX, scaleY, scaleZ, scene, style, translateX, translateY, translateZ, viewOrder, visible
-
-
Field Summary
-
Fields inherited from class javafx.scene.layout.Region
USE_COMPUTED_SIZE, USE_PREF_SIZE
-
Fields inherited from class javafx.scene.Node
BASELINE_OFFSET_SAME_AS_HEIGHT
-
-
Constructor Summary
Constructors Constructor Description Rating()
Creates a default instance with a minimum rating of 0 and a maximum rating of 5.Rating(int max)
Creates a default instance with a minimum rating of 0 and a maximum rating as provided by the argument.Rating(int max, int rating)
Creates a Rating instance with a minimum rating of 0, a maximum rating as provided by themax
argument, and a current rating as provided by therating
argument.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Skin<?>
createDefaultSkin()
int
getMax()
Returns the maximum-allowed rating value.Orientation
getOrientation()
Returns theOrientation
of theRating
- this can either be horizontal or vertical.double
getRating()
Returns the current rating value.String
getUserAgentStylesheet()
protected String
getUserAgentStylesheet(Class<?> clazz, String fileName)
A helper method that ensures that the resource based lookup of the user agent stylesheet only happens once.boolean
isPartialRating()
Returns whetherpartial rating
support is enabled or not.boolean
isUpdateOnHover()
Returns whetherupdate on hover
support is enabled or not.IntegerProperty
maxProperty()
The maximum-allowed rating value.ObjectProperty<Orientation>
orientationProperty()
TheOrientation
of theRating
- this can either be horizontal or vertical.BooleanProperty
partialRatingProperty()
If true this allows for users to set a rating as a floating point value.DoubleProperty
ratingProperty()
The current rating value.void
setMax(int value)
Sets the maximum-allowed rating value.void
setOrientation(Orientation value)
Sets theOrientation
of theRating
- this can either be horizontal or vertical.void
setPartialRating(boolean value)
Sets whetherpartial rating
support is enabled or not.void
setRating(double value)
Sets the current rating value.void
setUpdateOnHover(boolean value)
Sets whetherupdate on hover
support is enabled or not.BooleanProperty
updateOnHoverProperty()
If true this allows for therating property
to be updated simply by the user hovering their mouse over the control.-
Methods inherited from class javafx.scene.control.Control
computeMaxHeight, computeMaxWidth, computeMinHeight, computeMinWidth, computePrefHeight, computePrefWidth, contextMenuProperty, executeAccessibleAction, getBaselineOffset, getClassCssMetaData, getContextMenu, getControlCssMetaData, getCssMetaData, getInitialFocusTraversable, getSkin, getTooltip, isResizable, layoutChildren, queryAccessibleAttribute, setContextMenu, setSkin, setTooltip, skinProperty, tooltipProperty
-
Methods inherited from class javafx.scene.layout.Region
backgroundProperty, borderProperty, cacheShapeProperty, centerShapeProperty, getBackground, getBorder, getHeight, getInsets, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getOpaqueInsets, getPadding, getPrefHeight, getPrefWidth, getShape, getWidth, heightProperty, insetsProperty, isCacheShape, isCenterShape, isScaleShape, isSnapToPixel, layoutInArea, layoutInArea, layoutInArea, layoutInArea, maxHeight, maxHeightProperty, maxWidth, maxWidthProperty, minHeight, minHeightProperty, minWidth, minWidthProperty, opaqueInsetsProperty, paddingProperty, positionInArea, positionInArea, prefHeight, prefHeightProperty, prefWidth, prefWidthProperty, resize, scaleShapeProperty, setBackground, setBorder, setCacheShape, setCenterShape, setHeight, setMaxHeight, setMaxSize, setMaxWidth, setMinHeight, setMinSize, setMinWidth, setOpaqueInsets, setPadding, setPrefHeight, setPrefSize, setPrefWidth, setScaleShape, setShape, setSnapToPixel, setWidth, shapeProperty, snappedBottomInset, snappedLeftInset, snappedRightInset, snappedTopInset, snapPosition, snapPositionX, snapPositionY, snapSize, snapSizeX, snapSizeY, snapSpace, snapSpaceX, snapSpaceY, snapToPixelProperty, widthProperty
-
Methods inherited from class javafx.scene.Parent
getChildren, getChildrenUnmodifiable, getManagedChildren, getStylesheets, isNeedsLayout, layout, lookup, needsLayoutProperty, requestLayout, requestParentLayout, setNeedsLayout, updateBounds
-
Methods inherited from class javafx.scene.Node
accessibleHelpProperty, accessibleRoleDescriptionProperty, accessibleRoleProperty, accessibleTextProperty, addEventFilter, addEventHandler, applyCss, autosize, blendModeProperty, boundsInLocalProperty, boundsInParentProperty, buildEventDispatchChain, cacheHintProperty, cacheProperty, clipProperty, computeAreaInScreen, contains, contains, cursorProperty, depthTestProperty, disabledProperty, disableProperty, effectiveNodeOrientationProperty, effectProperty, eventDispatcherProperty, fireEvent, focusedProperty, focusTraversableProperty, getAccessibleHelp, getAccessibleRole, getAccessibleRoleDescription, getAccessibleText, getBlendMode, getBoundsInLocal, getBoundsInParent, getCacheHint, getClip, getContentBias, getCursor, getDepthTest, getEffect, getEffectiveNodeOrientation, getEventDispatcher, getId, getInitialCursor, getInputMethodRequests, getLayoutBounds, getLayoutX, getLayoutY, getLocalToParentTransform, getLocalToSceneTransform, getNodeOrientation, getOnContextMenuRequested, getOnDragDetected, getOnDragDone, getOnDragDropped, getOnDragEntered, getOnDragExited, getOnDragOver, getOnInputMethodTextChanged, getOnKeyPressed, getOnKeyReleased, getOnKeyTyped, getOnMouseClicked, getOnMouseDragEntered, getOnMouseDragExited, getOnMouseDragged, getOnMouseDragOver, getOnMouseDragReleased, getOnMouseEntered, getOnMouseExited, getOnMouseMoved, getOnMousePressed, getOnMouseReleased, getOnRotate, getOnRotationFinished, getOnRotationStarted, getOnScroll, getOnScrollFinished, getOnScrollStarted, getOnSwipeDown, getOnSwipeLeft, getOnSwipeRight, getOnSwipeUp, getOnTouchMoved, getOnTouchPressed, getOnTouchReleased, getOnTouchStationary, getOnZoom, getOnZoomFinished, getOnZoomStarted, getOpacity, getParent, getProperties, getPseudoClassStates, getRotate, getRotationAxis, getScaleX, getScaleY, getScaleZ, getScene, getStyle, getStyleableParent, getStyleClass, getTransforms, getTranslateX, getTranslateY, getTranslateZ, getTypeSelector, getUserData, getViewOrder, hasProperties, hoverProperty, idProperty, inputMethodRequestsProperty, intersects, intersects, isCache, isDisable, isDisabled, isFocused, isFocusTraversable, isHover, isManaged, isMouseTransparent, isPickOnBounds, isPressed, isVisible, layoutBoundsProperty, layoutXProperty, layoutYProperty, localToParent, localToParent, localToParent, localToParent, localToParent, localToParentTransformProperty, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToScene, localToSceneTransformProperty, localToScreen, localToScreen, localToScreen, localToScreen, localToScreen, lookupAll, managedProperty, mouseTransparentProperty, nodeOrientationProperty, notifyAccessibleAttributeChanged, onContextMenuRequestedProperty, onDragDetectedProperty, onDragDoneProperty, onDragDroppedProperty, onDragEnteredProperty, onDragExitedProperty, onDragOverProperty, onInputMethodTextChangedProperty, onKeyPressedProperty, onKeyReleasedProperty, onKeyTypedProperty, onMouseClickedProperty, onMouseDragEnteredProperty, onMouseDragExitedProperty, onMouseDraggedProperty, onMouseDragOverProperty, onMouseDragReleasedProperty, onMouseEnteredProperty, onMouseExitedProperty, onMouseMovedProperty, onMousePressedProperty, onMouseReleasedProperty, onRotateProperty, onRotationFinishedProperty, onRotationStartedProperty, onScrollFinishedProperty, onScrollProperty, onScrollStartedProperty, onSwipeDownProperty, onSwipeLeftProperty, onSwipeRightProperty, onSwipeUpProperty, onTouchMovedProperty, onTouchPressedProperty, onTouchReleasedProperty, onTouchStationaryProperty, onZoomFinishedProperty, onZoomProperty, onZoomStartedProperty, opacityProperty, parentProperty, parentToLocal, parentToLocal, parentToLocal, parentToLocal, parentToLocal, pickOnBoundsProperty, pressedProperty, pseudoClassStateChanged, relocate, removeEventFilter, removeEventHandler, requestFocus, resizeRelocate, rotateProperty, rotationAxisProperty, scaleXProperty, scaleYProperty, scaleZProperty, sceneProperty, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, sceneToLocal, screenToLocal, screenToLocal, screenToLocal, setAccessibleHelp, setAccessibleRole, setAccessibleRoleDescription, setAccessibleText, setBlendMode, setCache, setCacheHint, setClip, setCursor, setDepthTest, setDisable, setDisabled, setEffect, setEventDispatcher, setEventHandler, setFocused, setFocusTraversable, setHover, setId, setInputMethodRequests, setLayoutX, setLayoutY, setManaged, setMouseTransparent, setNodeOrientation, setOnContextMenuRequested, setOnDragDetected, setOnDragDone, setOnDragDropped, setOnDragEntered, setOnDragExited, setOnDragOver, setOnInputMethodTextChanged, setOnKeyPressed, setOnKeyReleased, setOnKeyTyped, setOnMouseClicked, setOnMouseDragEntered, setOnMouseDragExited, setOnMouseDragged, setOnMouseDragOver, setOnMouseDragReleased, setOnMouseEntered, setOnMouseExited, setOnMouseMoved, setOnMousePressed, setOnMouseReleased, setOnRotate, setOnRotationFinished, setOnRotationStarted, setOnScroll, setOnScrollFinished, setOnScrollStarted, setOnSwipeDown, setOnSwipeLeft, setOnSwipeRight, setOnSwipeUp, setOnTouchMoved, setOnTouchPressed, setOnTouchReleased, setOnTouchStationary, setOnZoom, setOnZoomFinished, setOnZoomStarted, setOpacity, setPickOnBounds, setPressed, setRotate, setRotationAxis, setScaleX, setScaleY, setScaleZ, setStyle, setTranslateX, setTranslateY, setTranslateZ, setUserData, setViewOrder, setVisible, snapshot, snapshot, startDragAndDrop, startFullDrag, styleProperty, toBack, toFront, toString, translateXProperty, translateYProperty, translateZProperty, usesMirroring, viewOrderProperty, visibleProperty
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface javafx.css.Styleable
getStyleableNode
-
-
-
-
Property Detail
-
rating
public final DoubleProperty ratingProperty
The current rating value.- See Also:
getRating()
,setRating(double)
-
max
public final IntegerProperty maxProperty
The maximum-allowed rating value.- See Also:
getMax()
,setMax(int)
-
orientation
public final ObjectProperty<Orientation> orientationProperty
TheOrientation
of theRating
- this can either be horizontal or vertical.- See Also:
getOrientation()
,setOrientation(Orientation)
-
partialRating
public final BooleanProperty partialRatingProperty
If true this allows for users to set a rating as a floating point value. In other words, the range of the rating 'stars' can be thought of as a range between [0, max], and whereever the user clicks will be calculated as the new rating value. If this is false the more typical approach is used where the selected 'star' is used as the rating.- See Also:
isPartialRating()
,setPartialRating(boolean)
-
updateOnHover
public final BooleanProperty updateOnHoverProperty
If true this allows for therating property
to be updated simply by the user hovering their mouse over the control. If false the user is required to click on their preferred rating to register the new rating with this control.- See Also:
isUpdateOnHover()
,setUpdateOnHover(boolean)
-
-
Constructor Detail
-
Rating
public Rating()
Creates a default instance with a minimum rating of 0 and a maximum rating of 5.
-
Rating
public Rating(int max)
Creates a default instance with a minimum rating of 0 and a maximum rating as provided by the argument.- Parameters:
max
- The maximum allowed rating value.
-
Rating
public Rating(int max, int rating)
Creates a Rating instance with a minimum rating of 0, a maximum rating as provided by themax
argument, and a current rating as provided by therating
argument.- Parameters:
max
- The maximum allowed rating value.
-
-
Method Detail
-
createDefaultSkin
protected Skin<?> createDefaultSkin()
- Overrides:
createDefaultSkin
in classControl
-
getUserAgentStylesheet
public String getUserAgentStylesheet()
- Overrides:
getUserAgentStylesheet
in classRegion
-
ratingProperty
public final DoubleProperty ratingProperty()
The current rating value.- See Also:
getRating()
,setRating(double)
-
setRating
public final void setRating(double value)
Sets the current rating value.
-
getRating
public final double getRating()
Returns the current rating value.
-
maxProperty
public final IntegerProperty maxProperty()
The maximum-allowed rating value.- See Also:
getMax()
,setMax(int)
-
setMax
public final void setMax(int value)
Sets the maximum-allowed rating value.
-
getMax
public final int getMax()
Returns the maximum-allowed rating value.
-
orientationProperty
public final ObjectProperty<Orientation> orientationProperty()
TheOrientation
of theRating
- this can either be horizontal or vertical.- See Also:
getOrientation()
,setOrientation(Orientation)
-
setOrientation
public final void setOrientation(Orientation value)
Sets theOrientation
of theRating
- this can either be horizontal or vertical.
-
getOrientation
public final Orientation getOrientation()
Returns theOrientation
of theRating
- this can either be horizontal or vertical.
-
partialRatingProperty
public final BooleanProperty partialRatingProperty()
If true this allows for users to set a rating as a floating point value. In other words, the range of the rating 'stars' can be thought of as a range between [0, max], and whereever the user clicks will be calculated as the new rating value. If this is false the more typical approach is used where the selected 'star' is used as the rating.- See Also:
isPartialRating()
,setPartialRating(boolean)
-
setPartialRating
public final void setPartialRating(boolean value)
Sets whetherpartial rating
support is enabled or not.
-
isPartialRating
public final boolean isPartialRating()
Returns whetherpartial rating
support is enabled or not.
-
updateOnHoverProperty
public final BooleanProperty updateOnHoverProperty()
If true this allows for therating property
to be updated simply by the user hovering their mouse over the control. If false the user is required to click on their preferred rating to register the new rating with this control.- See Also:
isUpdateOnHover()
,setUpdateOnHover(boolean)
-
setUpdateOnHover
public final void setUpdateOnHover(boolean value)
Sets whetherupdate on hover
support is enabled or not.
-
isUpdateOnHover
public final boolean isUpdateOnHover()
Returns whetherupdate on hover
support is enabled or not.
-
getUserAgentStylesheet
protected final String getUserAgentStylesheet(Class<?> clazz, String fileName)
A helper method that ensures that the resource based lookup of the user agent stylesheet only happens once. Caches the external form of the resource.- Parameters:
clazz
- the class used for the resource lookupfileName
- the name of the user agent stylesheet- Returns:
- the external form of the user agent stylesheet (the path)
-
-