Class SegmentedBar<T extends SegmentedBar.Segment>

java.lang.Object
javafx.scene.Node
javafx.scene.Parent
javafx.scene.layout.Region
javafx.scene.control.Control
com.dlsc.gemsfx.SegmentedBar<T>
Type Parameters:
T - the segment type
All Implemented Interfaces:
javafx.css.Styleable, javafx.event.EventTarget, javafx.scene.control.Skinnable

public class SegmentedBar<T extends SegmentedBar.Segment> extends javafx.scene.control.Control
A control that makes it easy to create a horizontal bar that visualises the segmentation of a total value. It consists of several segments, each segment is representing a value. The sum of all values is the total value of the bar (see totalProperty()). The bar can be customised by setting a factory for the creation of the segment views.

Example 1:

The most basic version of the bar. It is using the default segment view factory.
SegmentedBar bar = new SegmentedBar();
bar.getSegments().addAll(
    new Segment(10, "10"),
    new Segment(10, "10"),
    new Segment(10, "10"),
    new Segment(10, "10"),
    new Segment(10, "10"),
    new Segment(50, "50"));

Example 1:

In this example the bar is used to visualize the usage of disk space for various media types (photos, videos, music, ...). A special info node factory is supplied to present a useful detailed description of the segment. The type "TypeSegment" is a subclass of SegmentedBar.Segment
typesBar.setSegmentViewFactory(segment -> new TypeSegmentView(segment));
typesBar.setInfoNodeFactory(segment -> new InfoLabel(segment.getText() + " " + segment.getValue() + " GB"));
typesBar.getSegments().addAll(
    new TypeSegment(14, MediaType.PHOTOS),
    new TypeSegment(32, MediaType.VIDEO),
    new TypeSegment(9, MediaType.APPS),
    new TypeSegment(40, MediaType.MUSIC),
    new TypeSegment(5, MediaType.OTHER),
    new TypeSegment(35, MediaType.FREE));
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static class 
    A model class used by the SegmentedBar control.
    class 
    The view class used by the default segment view factory.
  • Property Summary

    Properties
    Type
    Property
    Description
    final javafx.beans.property.DoubleProperty
    The minimum width or height of a segment that will be used if the segment has a very small value compared to the total value of the bar.
    final javafx.beans.property.ObjectProperty<javafx.geometry.Orientation>
    Returns the styleable object property used for storing the orientation of the segmented bar.
    final javafx.beans.property.ListProperty<T>
    A property used to store the list of segments shown by the bar.
    final javafx.beans.property.ObjectProperty<javafx.util.Callback<T, javafx.scene.Node>>
    Stores the segment view factory that is used to create one view for each segment added to the control.
    final javafx.beans.property.ReadOnlyDoubleProperty
    A read-only property that stores the sum of all segment values attached to the bar.

    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 segmented bar.
  • Method Summary

    Modifier and Type
    Method
    Description
    protected javafx.scene.control.Skin<?>
     
    static List<javafx.css.CssMetaData<? extends javafx.css.Styleable, ?>>
     
    List<javafx.css.CssMetaData<? extends javafx.css.Styleable, ?>>
    final double
    Gets the value of the minSegmentSize property.
    final javafx.geometry.Orientation
    Returns the value of the orientation property.
    final javafx.collections.ObservableList<T>
    Returns the list of segments (the model).
    final javafx.util.Callback<T, javafx.scene.Node>
    Returns the value of segmentViewFactoryProperty().
    final double
    Returns the value of totalProperty().
     
    final javafx.beans.property.DoubleProperty
    The minimum width or height of a segment that will be used if the segment has a very small value compared to the total value of the bar.
    final javafx.beans.property.ObjectProperty<javafx.geometry.Orientation>
    Returns the styleable object property used for storing the orientation of the segmented bar.
    final javafx.beans.property.ListProperty<T>
    A property used to store the list of segments shown by the bar.
    final javafx.beans.property.ObjectProperty<javafx.util.Callback<T, javafx.scene.Node>>
    Stores the segment view factory that is used to create one view for each segment added to the control.
    final void
    setMinSegmentSize(double minSegmentSize)
    Sets the value of the minSegmentSize property.
    final void
    setOrientation(javafx.geometry.Orientation value)
    Sets the value of the orientation property.
    void
    setSegments(javafx.collections.ObservableList<T> segments)
    Sets the list of segments (the model).
    final void
    setSegmentViewFactory(javafx.util.Callback<T, javafx.scene.Node> factory)
    Sets the value of segmentViewFactoryProperty().
    final javafx.beans.property.ReadOnlyDoubleProperty
    A read-only property that stores the sum of all segment values attached to the bar.

    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

    • orientation

      public final javafx.beans.property.ObjectProperty<javafx.geometry.Orientation> orientationProperty
      Returns the styleable object property used for storing the orientation of the segmented bar.

      Can be set via CSS using the -fx-orientation property. Valid values are: horizontal or vertical. The default value is vertical.

      See Also:
    • minSegmentSize

      public final javafx.beans.property.DoubleProperty minSegmentSizeProperty
      The minimum width or height of a segment that will be used if the segment has a very small value compared to the total value of the bar. Without this, small segments would not be visible.

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

      See Also:
    • segmentViewFactory

      public final javafx.beans.property.ObjectProperty<javafx.util.Callback<T extends SegmentedBar.Segment, javafx.scene.Node>> segmentViewFactoryProperty
      Stores the segment view factory that is used to create one view for each segment added to the control.
      See Also:
    • segments

      public final javafx.beans.property.ListProperty<T extends SegmentedBar.Segment> segmentsProperty
      A property used to store the list of segments shown by the bar.
      See Also:
    • total

      public final javafx.beans.property.ReadOnlyDoubleProperty totalProperty
      A read-only property that stores the sum of all segment values attached to the bar.
      See Also:
  • Constructor Details

    • SegmentedBar

      public SegmentedBar()
      Constructs a new segmented bar.
  • 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
    • setOrientation

      public final void setOrientation(javafx.geometry.Orientation value)
      Sets the value of the orientation property.
      Parameters:
      value - the new orientation (horizontal, vertical).
      See Also:
    • getOrientation

      public final javafx.geometry.Orientation getOrientation()
      Returns the value of the orientation property.
      Returns:
      the current orientation of the control
      See Also:
    • orientationProperty

      public final javafx.beans.property.ObjectProperty<javafx.geometry.Orientation> orientationProperty()
      Returns the styleable object property used for storing the orientation of the segmented bar.

      Can be set via CSS using the -fx-orientation property. Valid values are: horizontal or vertical. The default value is vertical.

      Returns:
      the orientation property
      See Also:
    • getMinSegmentSize

      public final double getMinSegmentSize()
      Gets the value of the minSegmentSize property.
      Property description:
      The minimum width or height of a segment that will be used if the segment has a very small value compared to the total value of the bar. Without this, small segments would not be visible.

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

      Returns:
      the value of the minSegmentSize property
      See Also:
    • minSegmentSizeProperty

      public final javafx.beans.property.DoubleProperty minSegmentSizeProperty()
      The minimum width or height of a segment that will be used if the segment has a very small value compared to the total value of the bar. Without this, small segments would not be visible.

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

      Returns:
      the property
      See Also:
    • setMinSegmentSize

      public final void setMinSegmentSize(double minSegmentSize)
      Sets the value of the minSegmentSize property.
      Property description:
      The minimum width or height of a segment that will be used if the segment has a very small value compared to the total value of the bar. Without this, small segments would not be visible.

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

      Parameters:
      minSegmentSize - the value for the minSegmentSize property
      See Also:
    • segmentViewFactoryProperty

      public final javafx.beans.property.ObjectProperty<javafx.util.Callback<T, javafx.scene.Node>> segmentViewFactoryProperty()
      Stores the segment view factory that is used to create one view for each segment added to the control.
      Returns:
      the property that stores the factory
      See Also:
    • getSegmentViewFactory

      public final javafx.util.Callback<T, javafx.scene.Node> getSegmentViewFactory()
      Returns the value of segmentViewFactoryProperty().
      Returns:
      the segment view factory
    • setSegmentViewFactory

      public final void setSegmentViewFactory(javafx.util.Callback<T, javafx.scene.Node> factory)
      Sets the value of segmentViewFactoryProperty().
      Parameters:
      factory - the segment view factory
    • segmentsProperty

      public final javafx.beans.property.ListProperty<T> segmentsProperty()
      A property used to store the list of segments shown by the bar.
      Returns:
      the segment list
      See Also:
    • getSegments

      public final javafx.collections.ObservableList<T> getSegments()
      Returns the list of segments (the model).
      Returns:
      the list of segments shown by the bar
    • setSegments

      public void setSegments(javafx.collections.ObservableList<T> segments)
      Sets the list of segments (the model).
      Parameters:
      segments - the list of segments shown by the bar
    • totalProperty

      public final javafx.beans.property.ReadOnlyDoubleProperty totalProperty()
      A read-only property that stores the sum of all segment values attached to the bar.
      Returns:
      the total value of the bar (sum of segments)
      See Also:
    • getTotal

      public final double getTotal()
      Returns the value of totalProperty().
      Returns:
      the total value of the bar (sum of segments)
    • getClassCssMetaData

      public static List<javafx.css.CssMetaData<? extends javafx.css.Styleable, ?>> getClassCssMetaData()
      Returns:
      The CssMetaData associated with this class, which may include the CssMetaData of its super classes.
    • getControlCssMetaData

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