Class AvatarView

java.lang.Object
javafx.scene.Node
javafx.scene.Parent
javafx.scene.layout.Region
javafx.scene.control.Control
com.dlsc.gemsfx.AvatarView
All Implemented Interfaces:
javafx.css.Styleable, javafx.event.EventTarget, javafx.scene.control.Skinnable

public class AvatarView extends javafx.scene.control.Control
A custom control representing an avatar view.

The AvatarView can display either an image or the user's initials if no image is provided. The appearance of the avatar can be customized with properties such as clip type (circular or rectangular), round size for rectangular avatars, and the size of the avatar.

The following CSS properties can be used to style the AvatarView:

  • -fx-clip-type: Defines the clipping type of the avatar (circular or rectangular).
  • -fx-round-size: Defines the corner roundness of rectangular avatars.
  • -fx-avatar-size: Defines the size of the avatar.

The default style class for this control is "avatar-view".

  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static enum 
    Enumeration representing the shape of the avatar.
  • Property Summary

    Properties
    Type
    Property
    Description
    final javafx.beans.property.DoubleProperty
    The round size property of the avatar.
    final javafx.beans.property.ObjectProperty<AvatarView.AvatarShape>
    The clip type property of the avatar.
    final javafx.beans.property.ObjectProperty<javafx.scene.image.Image>
    The image of the user that should be displayed in the avatar.
    final javafx.beans.property.StringProperty
    The initials of the user that should be displayed in the avatar.
    final javafx.beans.property.IntegerProperty
    A property used to specify how many different styles the application wants to support for styling the view based on the initials.
    final javafx.beans.property.DoubleProperty
    The size property of the avatar.

    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, focusVisible, focusWithin, 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
    Constructs a new avatar view with no initials and no image.
    AvatarView(String initials)
    Constructs a new avatar view with the given initials.
    AvatarView(String initials, javafx.scene.image.Image image)
    Constructs a new avatar view with the given initials and image.
    AvatarView(javafx.scene.image.Image image)
    Constructs a new avatar view with the given image.
  • Method Summary

    Modifier and Type
    Method
    Description
    final javafx.beans.property.DoubleProperty
    The round size property of the avatar.
    final javafx.beans.property.ObjectProperty<AvatarView.AvatarShape>
    The clip type property of the avatar.
    protected javafx.scene.control.Skin<?>
     
    final double
    Gets the value of the arcSize property.
    Gets the value of the avatarShape property.
    static List<javafx.css.CssMetaData<? extends javafx.css.Styleable, ?>>
     
    protected List<javafx.css.CssMetaData<? extends javafx.css.Styleable, ?>>
     
    final javafx.scene.image.Image
    Gets the value of the image property.
    final String
    Gets the value of the initials property.
    final int
    Gets the value of the numberOfStyles property.
    final double
    Gets the value of the size property.
     
    final javafx.beans.property.ObjectProperty<javafx.scene.image.Image>
    The image of the user that should be displayed in the avatar.
    final javafx.beans.property.StringProperty
    The initials of the user that should be displayed in the avatar.
    final javafx.beans.property.IntegerProperty
    A property used to specify how many different styles the application wants to support for styling the view based on the initials.
    final void
    setArcSize(double arcSize)
    Sets the value of the arcSize property.
    final void
    Sets the value of the avatarShape property.
    final void
    setImage(javafx.scene.image.Image image)
    Sets the value of the image property.
    final void
    setInitials(String initials)
    Sets the value of the initials property.
    final void
    setNumberOfStyles(int numberOfStyles)
    Sets the value of the numberOfStyles property.
    final void
    setSize(double size)
    Sets the value of the size property.
    final javafx.beans.property.DoubleProperty
    The size property of the avatar.

    Methods inherited from class javafx.scene.control.Control

    computeMaxHeight, computeMaxWidth, computeMinHeight, computeMinWidth, computePrefHeight, computePrefWidth, contextMenuProperty, executeAccessibleAction, getBaselineOffset, getContextMenu, 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, focusVisibleProperty, focusWithinProperty, 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, isFocusVisible, isFocusWithin, 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, requestFocusTraversal, 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 Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface javafx.css.Styleable

    getStyleableNode
  • Property Details

    • numberOfStyles

      public final javafx.beans.property.IntegerProperty numberOfStylesProperty
      A property used to specify how many different styles the application wants to support for styling the view based on the initials. By default, this value is "5", which means that the view will have styles like this: style0, style1, style2, style3, style4 (but always only one of them). These five styles will use five different background colors. Please be aware that changing the number of styles requires you to define additional CSS rules as the default agent stylesheet that ships with this control only supports five different styles out of the box.
      See Also:
    • initials

      public final javafx.beans.property.StringProperty initialsProperty
      The initials of the user that should be displayed in the avatar.

      The initials are used as a fallback if no image is provided. If an image is provided and has finished loading, the initials are not displayed.

      See Also:
    • image

      public final javafx.beans.property.ObjectProperty<javafx.scene.image.Image> imageProperty
      The image of the user that should be displayed in the avatar.
      See Also:
    • arcSize

      public final javafx.beans.property.DoubleProperty arcSizeProperty
      The round size property of the avatar.

      This property represents the degree of rounding applied to the corners of a rectangular avatar. If the avatar is circular, this property is not used.

      Can be set via CSS using the -fx-avatar-arc-size property. Valid values are: positive numbers. The default value is 10.

      See Also:
    • size

      public final javafx.beans.property.DoubleProperty sizeProperty
      The size property of the avatar.

      This property represents the diameter (size) of the avatar.

      Can be set via CSS using the -fx-avatar-size property. Valid values are: positive numbers. The default value is 50.

      See Also:
    • avatarShape

      public final javafx.beans.property.ObjectProperty<AvatarView.AvatarShape> avatarShapeProperty
      The clip type property of the avatar.

      This property determines the shape of the avatar, whether it is circular or rectangular.

      Can be set via CSS using the -fx-avatar-shape property. Valid values are: round, square. The default value is square.

      See Also:
  • Constructor Details

    • AvatarView

      public AvatarView()
      Constructs a new avatar view with no initials and no image. The view will fall back to showing the default icon.
    • AvatarView

      public AvatarView(String initials, javafx.scene.image.Image image)
      Constructs a new avatar view with the given initials and image. The view will display the image unless it is null. Should the image be removed at a later point in time then the initials will be shown.
      Parameters:
      initials - the initials
      image - the image
    • AvatarView

      public AvatarView(String initials)
      Constructs a new avatar view with the given initials. If an image gets added later on then the image will be shown.
      Parameters:
      initials - the initials
    • AvatarView

      public AvatarView(javafx.scene.image.Image image)
      Constructs a new avatar view with the given image.
      Parameters:
      image - the image to show
  • Method Details

    • createDefaultSkin

      protected javafx.scene.control.Skin<?> createDefaultSkin()
      Overrides:
      createDefaultSkin in class javafx.scene.control.Control
    • getUserAgentStylesheet

      public String getUserAgentStylesheet()
      Overrides:
      getUserAgentStylesheet in class javafx.scene.layout.Region
    • getNumberOfStyles

      public final int getNumberOfStyles()
      Gets the value of the numberOfStyles property.
      Property description:
      A property used to specify how many different styles the application wants to support for styling the view based on the initials. By default, this value is "5", which means that the view will have styles like this: style0, style1, style2, style3, style4 (but always only one of them). These five styles will use five different background colors. Please be aware that changing the number of styles requires you to define additional CSS rules as the default agent stylesheet that ships with this control only supports five different styles out of the box.
      Returns:
      the value of the numberOfStyles property
      See Also:
    • numberOfStylesProperty

      public final javafx.beans.property.IntegerProperty numberOfStylesProperty()
      A property used to specify how many different styles the application wants to support for styling the view based on the initials. By default, this value is "5", which means that the view will have styles like this: style0, style1, style2, style3, style4 (but always only one of them). These five styles will use five different background colors. Please be aware that changing the number of styles requires you to define additional CSS rules as the default agent stylesheet that ships with this control only supports five different styles out of the box.
      Returns:
      the number of supported styles
      See Also:
    • setNumberOfStyles

      public final void setNumberOfStyles(int numberOfStyles)
      Sets the value of the numberOfStyles property.
      Property description:
      A property used to specify how many different styles the application wants to support for styling the view based on the initials. By default, this value is "5", which means that the view will have styles like this: style0, style1, style2, style3, style4 (but always only one of them). These five styles will use five different background colors. Please be aware that changing the number of styles requires you to define additional CSS rules as the default agent stylesheet that ships with this control only supports five different styles out of the box.
      Parameters:
      numberOfStyles - the value for the numberOfStyles property
      See Also:
    • getInitials

      public final String getInitials()
      Gets the value of the initials property.
      Property description:
      The initials of the user that should be displayed in the avatar.

      The initials are used as a fallback if no image is provided. If an image is provided and has finished loading, the initials are not displayed.

      Returns:
      the value of the initials property
      See Also:
    • initialsProperty

      public final javafx.beans.property.StringProperty initialsProperty()
      The initials of the user that should be displayed in the avatar.

      The initials are used as a fallback if no image is provided. If an image is provided and has finished loading, the initials are not displayed.

      Returns:
      the initials property
      See Also:
    • setInitials

      public final void setInitials(String initials)
      Sets the value of the initials property.
      Property description:
      The initials of the user that should be displayed in the avatar.

      The initials are used as a fallback if no image is provided. If an image is provided and has finished loading, the initials are not displayed.

      Parameters:
      initials - the value for the initials property
      See Also:
    • imageProperty

      public final javafx.beans.property.ObjectProperty<javafx.scene.image.Image> imageProperty()
      The image of the user that should be displayed in the avatar.
      Returns:
      the image property
      See Also:
    • getImage

      public final javafx.scene.image.Image getImage()
      Gets the value of the image property.
      Property description:
      The image of the user that should be displayed in the avatar.
      Returns:
      the value of the image property
      See Also:
    • setImage

      public final void setImage(javafx.scene.image.Image image)
      Sets the value of the image property.
      Property description:
      The image of the user that should be displayed in the avatar.
      Parameters:
      image - the value for the image property
      See Also:
    • getArcSize

      public final double getArcSize()
      Gets the value of the arcSize property.
      Property description:
      The round size property of the avatar.

      This property represents the degree of rounding applied to the corners of a rectangular avatar. If the avatar is circular, this property is not used.

      Can be set via CSS using the -fx-avatar-arc-size property. Valid values are: positive numbers. The default value is 10.

      Returns:
      the value of the arcSize property
      See Also:
    • arcSizeProperty

      public final javafx.beans.property.DoubleProperty arcSizeProperty()
      The round size property of the avatar.

      This property represents the degree of rounding applied to the corners of a rectangular avatar. If the avatar is circular, this property is not used.

      Can be set via CSS using the -fx-avatar-arc-size property. Valid values are: positive numbers. The default value is 10.

      Returns:
      the round size property
      See Also:
    • setArcSize

      public final void setArcSize(double arcSize)
      Sets the value of the arcSize property.
      Property description:
      The round size property of the avatar.

      This property represents the degree of rounding applied to the corners of a rectangular avatar. If the avatar is circular, this property is not used.

      Can be set via CSS using the -fx-avatar-arc-size property. Valid values are: positive numbers. The default value is 10.

      Parameters:
      arcSize - the value for the arcSize property
      See Also:
    • getSize

      public final double getSize()
      Gets the value of the size property.
      Property description:
      The size property of the avatar.

      This property represents the diameter (size) of the avatar.

      Can be set via CSS using the -fx-avatar-size property. Valid values are: positive numbers. The default value is 50.

      Returns:
      the value of the size property
      See Also:
    • sizeProperty

      public final javafx.beans.property.DoubleProperty sizeProperty()
      The size property of the avatar.

      This property represents the diameter (size) of the avatar.

      Can be set via CSS using the -fx-avatar-size property. Valid values are: positive numbers. The default value is 50.

      Returns:
      the size property
      See Also:
    • setSize

      public final void setSize(double size)
      Sets the value of the size property.
      Property description:
      The size property of the avatar.

      This property represents the diameter (size) of the avatar.

      Can be set via CSS using the -fx-avatar-size property. Valid values are: positive numbers. The default value is 50.

      Parameters:
      size - the value for the size property
      See Also:
    • avatarShapeProperty

      public final javafx.beans.property.ObjectProperty<AvatarView.AvatarShape> avatarShapeProperty()
      The clip type property of the avatar.

      This property determines the shape of the avatar, whether it is circular or rectangular.

      Can be set via CSS using the -fx-avatar-shape property. Valid values are: round, square. The default value is square.

      Returns:
      the clip type property
      See Also:
    • getAvatarShape

      public final AvatarView.AvatarShape getAvatarShape()
      Gets the value of the avatarShape property.
      Property description:
      The clip type property of the avatar.

      This property determines the shape of the avatar, whether it is circular or rectangular.

      Can be set via CSS using the -fx-avatar-shape property. Valid values are: round, square. The default value is square.

      Returns:
      the value of the avatarShape property
      See Also:
    • setAvatarShape

      public final void setAvatarShape(AvatarView.AvatarShape type)
      Sets the value of the avatarShape property.
      Property description:
      The clip type property of the avatar.

      This property determines the shape of the avatar, whether it is circular or rectangular.

      Can be set via CSS using the -fx-avatar-shape property. Valid values are: round, square. The default value is square.

      Parameters:
      type - the value for the avatarShape property
      See Also:
    • getControlCssMetaData

      protected List<javafx.css.CssMetaData<? extends javafx.css.Styleable, ?>> getControlCssMetaData()
      Overrides:
      getControlCssMetaData in class javafx.scene.control.Control
    • getClassCssMetaData

      public static List<javafx.css.CssMetaData<? extends javafx.css.Styleable, ?>> getClassCssMetaData()