Top Description Inners Fields Constructors Methods
org.controlsfx.control

public Class SegmentedBar<T extends SegmentedBar.Segment>

extends ControlsFXControl
Class Inheritance
Imports
impl.org.controlsfx.skin.SegmentedBarSkin, javafx.beans.InvalidationListener, .Observable, .WeakInvalidationListener, javafx.beans.property.*, javafx.collections.FXCollections, .ObservableList, javafx.css.CssMetaData, .PseudoClass, .Styleable, .StyleableObjectProperty, .StyleableProperty, javafx.css.converter.EnumConverter, javafx.geometry.Insets, .Orientation, .Pos, javafx.scene.Node, javafx.scene.control.Control, .Label, .OverrunStyle, .Skin, javafx.scene.layout.StackPane, javafx.util.Callback, java.util.ArrayList, .Collections, .List, java.util.stream.Collectors

A control that makes it easy to create a horizontal bar that visualizes the segmentation of a total value. It consists of several segments, each segment representing a value. The sum of all values is the total value of the bar (see totalProperty()). The bar can be customized by setting a factory for the creation of the segment views. Another factory can be set for for the creation of info nodes shown by a PopOver.
Segmented Bar

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 org.controlsfx.control.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
setSegmentViewFactory(Callback), setInfoNodeFactory(Callback)

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
SegmentedBar.Segment

A model class used by the SegmentedBar control.

public class
SegmentedBar.SegmentView

The view class used by the default segment view factory.

private static class

Field Summary

Modifier and TypeField and Description
private static final String
private static final PseudoClass
private final ObjectProperty<Callback<T, Node>>
private ObjectProperty<Orientation>
private final ListProperty<T>
private final ObjectProperty<Callback<T, Node>>
private final InvalidationListener
private final ReadOnlyDoubleWrapper
private static final PseudoClass
private final WeakInvalidationListener

Constructor Summary

AccessConstructor and Description
public
SegmentedBar()

Constructs a new segmented bar.

Method Summary

Modifier and TypeMethod and Description
protected Skin<?>
createDefaultSkin()

Overrides javafx.scene.control.Control.createDefaultSkin.

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

public static List<CssMetaData<? extends Styleable, ?>>

Returns:

The CssMetaData associated with this class, which may include the CssMetaData of its super classes.
getClassCssMetaData
()

Hides javafx.scene.control.Control.getClassCssMetaData.

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

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

Overrides javafx.scene.control.Control.getControlCssMetaData.

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

public final Callback<T, Node>

Returns:

the info node factory
getInfoNodeFactory
()

Returns the value of infoNodeFactoryProperty().

public final Orientation

Returns:

the current orientation of the control
getOrientation
()

Returns the value of the orientation property.

public final ObservableList<T>

Returns:

the list of segments shown by the bar
getSegments
()

Returns the list of segments (the model).

public final Callback<T, Node>

Returns:

the segment view factory
getSegmentViewFactory
()

Returns the value of segmentViewFactoryProperty().

public final double

Returns:

the total value of the bar (sum of segments)
getTotal
()

Returns the value of totalProperty().

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<Callback<T, Node>>

Returns:

the info node factory property
infoNodeFactoryProperty
()

Stores a factory callback for creating nodes that will be shown by a popover when the mouse enters a segment.

private void
public final ObjectProperty<Orientation>

Returns:

the orientation property
orientationProperty
()

Returns the styleable object property used for storing the orientation of the segmented bar.

public final ListProperty<T>

Returns:

the segment list
segmentsProperty
()

A property used to store the list of segments shown by the bar.

public final ObjectProperty<Callback<T, Node>>

Returns:

the property that stores the factory
segmentViewFactoryProperty
()

Stores the segment view factory that is used to create one view for each segment added to the control.

public void
setInfoNodeFactory(Callback<T, Node>
the info node factory
factory
)

Sets the value of infoNodeFactoryProperty().

public final void
setOrientation(Orientation
the new orientation (horizontal, vertical).
value
)

Sets the value of the orientation property.

public void
setSegments(ObservableList<T>
the list of segments shown by the bar
segments
)

Sets the list of segments (the model).

public final void
setSegmentViewFactory(Callback<T, Node>
the segment view factory
factory
)

Sets the value of segmentViewFactoryProperty().

public final ReadOnlyDoubleProperty

Returns:

the total value of the bar (sum of segments)
totalProperty
()

A read-only property that stores the sum of all segment values attached to the bar.

Inherited from org.controlsfx.control.ControlsFXControl:
getUserAgentStylesheet

Field Detail

DEFAULT_STYLEback to summary
private static final String DEFAULT_STYLE
HORIZONTAL_PSEUDOCLASS_STATEback to summary
private static final PseudoClass HORIZONTAL_PSEUDOCLASS_STATE
infoNodeFactoryback to summary
private final ObjectProperty<Callback<T, Node>> infoNodeFactory
orientationback to summary
private ObjectProperty<Orientation> orientation
segmentsback to summary
private final ListProperty<T> segments
segmentViewFactoryback to summary
private final ObjectProperty<Callback<T, Node>> segmentViewFactory
sumListenerback to summary
private final InvalidationListener sumListener
totalback to summary
private final ReadOnlyDoubleWrapper total
VERTICAL_PSEUDOCLASS_STATEback to summary
private static final PseudoClass VERTICAL_PSEUDOCLASS_STATE
weakSumListenerback to summary
private final WeakInvalidationListener weakSumListener

Constructor Detail

SegmentedBarback to summary
public SegmentedBar()

Constructs a new segmented bar.

Method Detail

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
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.

Returns:List<CssMetaData<? extends Styleable, ?>>

The CssMetaData associated with this class, which may include the CssMetaData of its super classes.

getControlCssMetaDataback to summary
public 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
getInfoNodeFactoryback to summary
public final Callback<T, Node> getInfoNodeFactory()

Returns the value of infoNodeFactoryProperty().

Returns:Callback<T, Node>

the info node factory

getOrientationback to summary
public final Orientation getOrientation()

Returns the value of the orientation property.

Returns:Orientation

the current orientation of the control

See Also
orientationProperty()
getSegmentsback to summary
public final ObservableList<T> getSegments()

Returns the list of segments (the model).

Returns:ObservableList<T>

the list of segments shown by the bar

getSegmentViewFactoryback to summary
public final Callback<T, Node> getSegmentViewFactory()

Returns the value of segmentViewFactoryProperty().

Returns:Callback<T, Node>

the segment view factory

getTotalback to summary
public final double getTotal()

Returns the value of totalProperty().

Returns:double

the total value of the bar (sum of segments)

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
infoNodeFactoryPropertyback to summary
public final ObjectProperty<Callback<T, Node>> infoNodeFactoryProperty()

Stores a factory callback for creating nodes that will be shown by a popover when the mouse enters a segment. The popover / node can provide detailed information about a segment.

Returns:ObjectProperty<Callback<T, Node>>

the info node factory property

listenToValuesback to summary
private void listenToValues()
orientationPropertyback to summary
public final ObjectProperty<Orientation> orientationProperty()

Returns the styleable object property used for storing the orientation of the segmented bar. The CSS property "-fx-orientation" can be used to initialize this value.

Returns:ObjectProperty<Orientation>

the orientation property

segmentsPropertyback to summary
public final ListProperty<T> segmentsProperty()

A property used to store the list of segments shown by the bar.

Returns:ListProperty<T>

the segment list

segmentViewFactoryPropertyback to summary
public final ObjectProperty<Callback<T, Node>> segmentViewFactoryProperty()

Stores the segment view factory that is used to create one view for each segment added to the control.

Returns:ObjectProperty<Callback<T, Node>>

the property that stores the factory

setInfoNodeFactoryback to summary
public void setInfoNodeFactory(Callback<T, Node> factory)

Sets the value of infoNodeFactoryProperty().

Parameters
factory:Callback<T, Node>

the info node factory

setOrientationback to summary
public final void setOrientation(Orientation value)

Sets the value of the orientation property.

Parameters
value:Orientation

the new orientation (horizontal, vertical).

See Also
orientationProperty()
setSegmentsback to summary
public void setSegments(ObservableList<T> segments)

Sets the list of segments (the model).

Parameters
segments:ObservableList<T>

the list of segments shown by the bar

setSegmentViewFactoryback to summary
public final void setSegmentViewFactory(Callback<T, Node> factory)

Sets the value of segmentViewFactoryProperty().

Parameters
factory:Callback<T, Node>

the segment view factory

totalPropertyback to summary
public final ReadOnlyDoubleProperty totalProperty()

A read-only property that stores the sum of all segment values attached to the bar.

Returns:ReadOnlyDoubleProperty

the total value of the bar (sum of segments)

org.controlsfx.control back to summary

public Class SegmentedBar.Segment

extends Object
Class Inheritance

A model class used by the SegmentedBar control. Applications usually subclass this type for their own specific needs. A segment always carries a value and an optional text. Changing the value of the segment will trigger a rebuild of the control.

Field Summary

Modifier and TypeField and Description
private final StringProperty
private final DoubleProperty

Constructor Summary

AccessConstructor and Description
public
Segment(double
the segment's value
value
)

Constructs a new segment with the given value.

public
Segment(double
the segment's value
value
,
String
the segment's text
text
)

Constructs a new segment with the given value.

Method Summary

Modifier and TypeMethod and Description
public final String

Returns:

the segment's text
getText
()

Returns the value of textProperty().

public final double

Returns:

the segment's value
getValue
()

Returns the value of valueProperty().

public final void
setText(String
the new text
text
)

Sets the value of textProperty().

public final void
setValue(double
the new value
value
)

Sets the value of valueProperty().

public final StringProperty

Returns:

the text property
textProperty
()

Stores the text of the segment (optional).

public final DoubleProperty

Returns:

the value property
valueProperty
()

Stores the current value of the segment.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

textback to summary
private final StringProperty text
valueback to summary
private final DoubleProperty value

Constructor Detail

Segmentback to summary
public Segment(double value)

Constructs a new segment with the given value.

Parameters
value:double

the segment's value

Segmentback to summary
public Segment(double value, String text)

Constructs a new segment with the given value.

Parameters
value:double

the segment's value

text:String

the segment's text

Method Detail

getTextback to summary
public final String getText()

Returns the value of textProperty().

Returns:String

the segment's text

getValueback to summary
public final double getValue()

Returns the value of valueProperty().

Returns:double

the segment's value

setTextback to summary
public final void setText(String text)

Sets the value of textProperty().

Parameters
text:String

the new text

setValueback to summary
public final void setValue(double value)

Sets the value of valueProperty().

Parameters
value:double

the new value

textPropertyback to summary
public final StringProperty textProperty()

Stores the text of the segment (optional).

Returns:StringProperty

the text property

valuePropertyback to summary
public final DoubleProperty valueProperty()

Stores the current value of the segment. The value has to be larger or equal to zero.

Returns:DoubleProperty

the value property

org.controlsfx.control back to summary

public Class SegmentedBar.SegmentView

extends StackPane
Class Inheritance

The view class used by the default segment view factory. The view is a simple StackPane that contains a label. The default style class is "segment-view".
See Also
setSegmentViewFactory(Callback)

Field Summary

Modifier and TypeField and Description
private Label

Constructor Summary

AccessConstructor and Description
public
SegmentView(T
the segment for which the view will be created.
segment
)

Constructs a new segment view.

Method Summary

Modifier and TypeMethod and Description
protected void
layoutChildren()

Overrides javafx.scene.layout.StackPane.layoutChildren.

The layout method has been overridden to ensure that the label used for displaying the text of a segment will be made invisible when there is not enough space to show the entire text.

Inherited from javafx.scene.layout.StackPane:
alignmentPropertyclearConstraintscomputeMinHeightcomputeMinWidthcomputePrefHeightcomputePrefWidthgetAlignmentgetAlignmentgetClassCssMetaDatagetContentBiasgetCssMetaDatagetMarginrequestLayoutsetAlignmentsetAlignmentsetMargin

Field Detail

labelback to summary
private Label label

Constructor Detail

SegmentViewback to summary
public SegmentView(T segment)

Constructs a new segment view.

Parameters
segment:T

the segment for which the view will be created.

Method Detail

layoutChildrenback to summary
protected void layoutChildren()

Overrides javafx.scene.layout.StackPane.layoutChildren.

The layout method has been overridden to ensure that the label used for displaying the text of a segment will be made invisible when there is not enough space to show the entire text.

Annotations
@Override
org.controlsfx.control back to summary

private Class SegmentedBar.StyleableProperties

extends Object
Class Inheritance

Field Summary

Modifier and TypeField and Description
private static final CssMetaData<SegmentedBar<T extends SegmentedBar.Segment>, Orientation>
private static final List<CssMetaData<? extends Styleable, ?>>

Constructor Summary

AccessConstructor and Description
private

Method Summary

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

ORIENTATIONback to summary
private static final CssMetaData<SegmentedBar<T extends SegmentedBar.Segment>, Orientation> ORIENTATION
STYLEABLESback to summary
private static final List<CssMetaData<? extends Styleable, ?>> STYLEABLES

Constructor Detail

StyleablePropertiesback to summary
private StyleableProperties()