Top Description Inners Fields Constructors Methods
com.dlsc.gemsfx

public Class AvatarView

extends Control
Class Inheritance
Imports
com.dlsc.gemsfx.skins.AvatarViewSkin, javafx.beans.property.DoubleProperty, .IntegerProperty, .ObjectProperty, .SimpleIntegerProperty, .SimpleObjectProperty, .SimpleStringProperty, .StringProperty, javafx.css.CssMetaData, .Styleable, .StyleableDoubleProperty, .StyleableObjectProperty, .StyleableProperty, javafx.css.converter.EnumConverter, .SizeConverter, javafx.scene.control.Control, .Skin, javafx.scene.image.Image, org.apache.commons.lang3.StringUtils, java.util.ArrayList, .Collections, .List, .Objects

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:

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

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
AvatarView.AvatarShape

Enumeration representing the shape of the avatar.

private static class

Field Summary

Modifier and TypeField and Description
private final DoubleProperty
private final StyleableObjectProperty<AvatarView.AvatarShape>
private static final double
private static final AvatarView.AvatarShape
private static final double
private static final String
private final ObjectProperty<Image>
private final StringProperty
private final IntegerProperty
private final IntegerProperty
private final DoubleProperty

Constructor Summary

AccessConstructor and Description
public
AvatarView()

Constructs a new avatar view with no initials and no image.

public
AvatarView(String
the initials
initials
,
Image
the image
image
)

Constructs a new avatar view with the given initials and image.

public
AvatarView(String
the initials
initials
)

Constructs a new avatar view with the given initials.

public
AvatarView(Image
the image to show
image
)

Constructs a new avatar view with the given image.

Method Summary

Modifier and TypeMethod and Description
public final DoubleProperty

Returns:

the round size property
arcSizeProperty
()

The round size property of the avatar.

public final ObjectProperty<AvatarView.AvatarShape>

Returns:

the clip type property
avatarShapeProperty
()

The clip type property of the avatar.

protected Skin<?>
createDefaultSkin()

Overrides javafx.scene.control.Control.createDefaultSkin.

Create a new instance of the default skin for this control.

public final double
public final AvatarView.AvatarShape
public static List<CssMetaData<? extends Styleable, ?>>
getClassCssMetaData()

Hides javafx.scene.control.Control.getClassCssMetaData.

Gets the CssMetaData associated with this class, which may include the CssMetaData of its superclasses.

protected List<CssMetaData<? extends Styleable, ?>>
getControlCssMetaData()

Overrides javafx.scene.control.Control.getControlCssMetaData.

Gets the unmodifiable list of the control's CSS-styleable properties.

public final Image
public final String
public final int
public final double
public String
getUserAgentStylesheet()

Overrides javafx.scene.layout.Region.getUserAgentStylesheet.

An implementation may specify its own user-agent styles for this Region, and its children, by overriding this method.

public final ObjectProperty<Image>

Returns:

the image property
imageProperty
()

The image of the user that should be displayed in the avatar.

public final StringProperty

Returns:

the initials property
initialsProperty
()

The initials of the user that should be displayed in the avatar.

public final IntegerProperty

Returns:

the number of supported styles
numberOfStylesProperty
()

A property used to specify how many different styles the application wants to support for styling the view based on the initials.

public final void
setArcSize(double arcSize)

public final void
public final void
setImage(Image image)

public final void
setInitials(String initials)

public final void
setNumberOfStyles(int numberOfStyles)

public final void
setSize(double size)

public final DoubleProperty

Returns:

the size property
sizeProperty
()

The size property of the avatar.

private void
Inherited from javafx.scene.control.Control:
computeMaxHeightcomputeMaxWidthcomputeMinHeightcomputeMinWidthcomputePrefHeightcomputePrefWidthcontextMenuPropertyexecuteAccessibleActiongetBaselineOffsetgetContextMenugetCssMetaDatagetInitialFocusTraversablegetSkingetTooltipisResizablelayoutChildrenqueryAccessibleAttributesetContextMenusetSkinsetTooltipskinPropertytooltipProperty

Field Detail

arcSizeback to summary
private final DoubleProperty arcSize
avatarShapeback to summary
private final StyleableObjectProperty<AvatarView.AvatarShape> avatarShape
DEFAULT_ARC_SIZEback to summary
private static final double DEFAULT_ARC_SIZE
DEFAULT_AVATAR_SHAPEback to summary
private static final AvatarView.AvatarShape DEFAULT_AVATAR_SHAPE
DEFAULT_SIZEback to summary
private static final double DEFAULT_SIZE
DEFAULT_STYLE_CLASSback to summary
private static final String DEFAULT_STYLE_CLASS
imageback to summary
private final ObjectProperty<Image> image
initialsback to summary
private final StringProperty initials
magicNumberback to summary
private final IntegerProperty magicNumber
numberOfStylesback to summary
private final IntegerProperty numberOfStyles
sizeback to summary
private final DoubleProperty size

Constructor Detail

AvatarViewback to summary
public AvatarView()

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

AvatarViewback to summary
public AvatarView(String initials, 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:String

the initials

image:Image

the image

AvatarViewback to summary
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:String

the initials

AvatarViewback to summary
public AvatarView(Image image)

Constructs a new avatar view with the given image.

Parameters
image:Image

the image to show

Method Detail

arcSizePropertyback to summary
public final 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.

Returns:DoubleProperty

the round size property

avatarShapePropertyback to summary
public final 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.

Returns:ObjectProperty<AvatarView.AvatarShape>

the clip type property

createDefaultSkinback to summary
protected Skin<?> createDefaultSkin()

Overrides javafx.scene.control.Control.createDefaultSkin.

Doc from javafx.scene.control.Control.createDefaultSkin.

Create a new instance of the default skin for this control. This is called to create a skin for the control if no skin is provided via CSS -fx-skin or set explicitly in a sub-class with setSkin(...).

Annotations
@Override
getArcSizeback to summary
public final double getArcSize()
getAvatarShapeback to summary
public final AvatarView.AvatarShape getAvatarShape()
getClassCssMetaDataback to summary
public static List<CssMetaData<? extends Styleable, ?>> getClassCssMetaData()

Hides javafx.scene.control.Control.getClassCssMetaData.

Doc from javafx.scene.control.Control.getClassCssMetaData.

Gets the CssMetaData associated with this class, which may include the CssMetaData of its superclasses.

getControlCssMetaDataback to summary
protected List<CssMetaData<? extends Styleable, ?>> getControlCssMetaData()

Overrides javafx.scene.control.Control.getControlCssMetaData.

Doc from javafx.scene.control.Control.getControlCssMetaData.

Gets the unmodifiable list of the control's CSS-styleable properties.

Annotations
@Override
getImageback to summary
public final Image getImage()
getInitialsback to summary
public final String getInitials()
getNumberOfStylesback to summary
public final int getNumberOfStyles()
getSizeback to summary
public final double getSize()
getUserAgentStylesheetback to summary
public String getUserAgentStylesheet()

Overrides javafx.scene.layout.Region.getUserAgentStylesheet.

Doc from javafx.scene.layout.Region.getUserAgentStylesheet.

An implementation may specify its own user-agent styles for this Region, and its children, by overriding this method. These styles are used in addition to whatever user-agent stylesheets are in use. This provides a mechanism for third parties to introduce styles for custom controls.

The URL is a hierarchical URI of the form [scheme:][//authority][path]. If the URL does not have a [scheme:] component, the URL is considered to be the [path] component only. Any leading '/' character of the [path] is ignored and the [path] is treated as a path relative to the root of the application's classpath.

Subclasses overriding this method should not assume any particular implementation approach as to the number and frequency with which it is called. For this reason, attempting any kind of dynamic implementation (i.e. returning different user agent stylesheet values) based on some state change is highly discouraged, as there is no guarantee when, or even if, this method will be called. Some JavaFX CSS implementations may choose to cache this response for an indefinite period of time, and therefore there should be no expectation around when this method is called.



package com.example.javafx.app;

import javafx.application.Application;
import javafx.scene.Group;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class MyApp extends Application {

    @Override public void start(Stage stage) {
        Scene scene = new Scene(new Group());
        scene.getStylesheets().add("/com/example/javafx/app/mystyles.css");
        stage.setScene(scene);
        stage.show();
    }

    public static void main(String[] args) {
        launch(args);
    }
}
For additional information about using CSS with the scene graph, see the CSS Reference Guide.
Annotations
@Override
imagePropertyback to summary
public final ObjectProperty<Image> imageProperty()

The image of the user that should be displayed in the avatar.

Returns:ObjectProperty<Image>

the image property

initialsPropertyback to summary
public final 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:StringProperty

the initials property

numberOfStylesPropertyback to summary
public final 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:IntegerProperty

the number of supported styles

setArcSizeback to summary
public final void setArcSize(double arcSize)
setAvatarShapeback to summary
public final void setAvatarShape(final AvatarView.AvatarShape type)
setImageback to summary
public final void setImage(Image image)
setInitialsback to summary
public final void setInitials(String initials)
setNumberOfStylesback to summary
public final void setNumberOfStyles(int numberOfStyles)
setSizeback to summary
public final void setSize(double size)
sizePropertyback to summary
public final DoubleProperty sizeProperty()

The size property of the avatar.

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

Returns:DoubleProperty

the size property

updateMagicNumberback to summary
private void updateMagicNumber()
com.dlsc.gemsfx back to summary

public final Enum AvatarView.AvatarShape

extends Enum<AvatarView.AvatarShape>
Class Inheritance

Enumeration representing the shape of the avatar.

Field Summary

Modifier and TypeField and Description
public static final AvatarView.AvatarShape
ROUND

The avatar will have a circular shape.

public static final AvatarView.AvatarShape
SQUARE

The avatar will have a rectangular shape.

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static AvatarView.AvatarShape
public static AvatarView.AvatarShape[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

ROUNDback to summary
public static final AvatarView.AvatarShape ROUND

The avatar will have a circular shape.

SQUAREback to summary
public static final AvatarView.AvatarShape SQUARE

The avatar will have a rectangular shape.

Constructor Detail

AvatarShapeback to summary
private AvatarShape()

Method Detail

valueOfback to summary
public static AvatarView.AvatarShape valueOf(String name)
valuesback to summary
public static AvatarView.AvatarShape[] values()
com.dlsc.gemsfx back to summary

private Class AvatarView.StyleableProperties

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final CssMetaData<AvatarView, Number>
private static final CssMetaData<AvatarView, AvatarView.AvatarShape>
private static final CssMetaData<AvatarView, Number>
private static final List<CssMetaData<? extends Styleable, ?>>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

AVATAR_ARC_SIZEback to summary
private static final CssMetaData<AvatarView, Number> AVATAR_ARC_SIZE
AVATAR_SHAPEback to summary
private static final CssMetaData<AvatarView, AvatarView.AvatarShape> AVATAR_SHAPE
AVATAR_SIZEback to summary
private static final CssMetaData<AvatarView, Number> AVATAR_SIZE
STYLEABLESback to summary
private static final List<CssMetaData<? extends Styleable, ?>> STYLEABLES

Constructor Detail

StyleablePropertiesback to summary
private StyleableProperties()