Top Description Inners Fields Constructors Methods
org.controlsfx.control

public Class SnapshotView

extends ControlsFXControl
Class Inheritance
Static Imports
javafx.beans.binding.Bindings.and, .Bindings.isNotNull, .Bindings.notEqual

A SnapshotView is a control which allows the user to select an area of a node in the typical manner used by picture editors and crate snapshots of the selection.

While holding the left mouse key down, a rectangular selection can be drawn. This selection can be moved, resized in eight cardinal directions and removed. Additionally, the selection's ratio can be fixed in which case the user's resizing will be limited such that the ratio is always upheld.

The area where the selection is possible is either this entire control or limited to the displayed node.

Screenshots

Screenshot of SnapshotView

Code Samples

The following snippet creates a new instance with the ControlsFX logo loaded from the web, sets a selected area and fixes its ratio:
ImageView controlsFxView = new ImageView(
        "http://cache.fxexperience.com/wp-content/uploads/2013/05/ControlsFX.png");
SnapshotView snapshotView = new SnapshotView(controlsFxView);
snapshotView.setSelection(33, 50, 100, 100);
snapshotView.setFixedSelectionRatio(1); // (this is actually the default value)
snapshotView.setSelectionRatioFixed(true);

Functionality Overview

This is just a vague overview. The linked properties provide a more detailed explanation.

Node

The node which this control displays is held by the node property.

Selection

There are several properties which interact to manage and indicate the selection.
State
Interaction
Visualization

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum
SnapshotView.Boundary

The selectionArea, in which the user can create a selection, and the unselectedArea, in which the unselected area is visualized, are limited to a certain area of the control.

private static class
SnapshotView.Css

The class which holds this control's CssMetaData for the different StyleableProperties.

private class
SnapshotView.SelectionSizeUpdater

Updates the size of the selection whenever necessary.

Field Summary

Modifier and TypeField and Description
private static final String
DEFAULT_STYLE_CLASS

The name of the style class used in CSS for instances of this class.

private final DoubleProperty
private final BooleanProperty
public static final double
MAX_SELECTION_RATIO_DIVERGENCE

The maximal divergence between a selection's ratio and the fixedselectionRatio for the selection to still have the correct ratio (see hasCorrectRatio).

private final ObjectProperty<Node>
private final ObjectProperty<Rectangle2D>
public static final String
SELECTION_CHANGING_PROPERTY_KEY

The key of the property which is used to update selectionChanging.

private final BooleanProperty
private final BooleanProperty
private final ObjectProperty<SnapshotView.Boundary>
private final ObjectProperty<Paint>
private final ObjectProperty<Paint>
private final DoubleProperty
private final BooleanProperty
private final BooleanProperty
private final BooleanProperty
private final ObjectProperty<SnapshotView.Boundary>
private final ObjectProperty<Paint>

Constructor Summary

AccessConstructor and Description
public
SnapshotView()

Creates a new SnapshotView.

public
SnapshotView(Node
the node to show after construction
node
)

Creates a new SnapshotView using the specified node.

Method Summary

Modifier and TypeMethod and Description
private void
addStateUpdatingListeners()

Adds listeners to the properties which update the control's state.

private static <S extends Styleable, T> CssMetaData<S, T>

Returns:

an instance of CssMetaData
createCssMetaData
(Function<S, Property<T>>
a function from the Styleable which owns the styled property to the property styled by the returned CssMetaData
getProperty
,
String
the name by which the styled property is referenced in CSS files
cssPropertyName
,
StyleConverter<?, T>
the StyleConverter used to convert the CSS parsed value to a Java object
styleConverter
)

Creates an instance of CssMetaData with the specified arguments.

protected Skin<?>
createDefaultSkin()

Overrides javafx.scene.control.Control.createDefaultSkin.

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

public WritableImage

Returns:

the WritableImage that holds the rendered selection
createSnapshot
()

Creates a snapshot of the selected area of the node.

public WritableImage

Returns:

the WritableImage that holds the rendered viewport
createSnapshot
(SnapshotParameters
the SnapshotParameters used for the snapshot (must not be null); the viewport will be interpreted relative to this control (like the selection)
parameters
)

Creates a snapshot of the node with the specified parameters.

private static StyleableDoubleProperty
createStylableDoubleProperty(Object
the bean the created property belongs to
bean
,
String
the property's name
name
,
double
the property's initial value
initialValue
,
CssMetaData<? extends Styleable, Number>
the CssMetaData for the created property
cssMetaData
)

Creates a StyleableDoubleProperty with the specified arguments.

private static <T> StyleableObjectProperty<T>
createStylableObjectProperty(Object
the bean the created property belongs to
bean
,
String
the property's name
name
,
T
the property's initial value
initialValue
,
CssMetaData<? extends Styleable, T>
the CssMetaData for the created property
cssMetaData
)

Creates a StyleableObjectProperty with the specified arguments.

public final DoubleProperty

Returns:

a property containing the fixed selection ratio
fixedSelectionRatioProperty
()

The value to which the selection ratio is fixed.

private void
fixSelectionRatio()

Resizes the current selection (if it exists) to the fixedSelectionRatio.

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

Returns:

the CssMetaData associated with this class, which includes 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 double
getFixedSelectionRatio()

Returns: the fixedSelectionRatio, which will always be a strictly positive value

public final Node
getNode()

Returns: the displayed node

public final Rectangle2D
getSelection()

Returns: the current selection

public final SnapshotView.Boundary
getSelectionAreaBoundary()

Returns: the Boundary for the area the user can select

public final Paint
getSelectionAreaFill()

Returns: the Paint of the selected area

public final Paint
getSelectionBorderPaint()

Returns: the Paint of the selection border

public final double
getSelectionBorderWidth()

Returns: the selection border width

private Rectangle2D
getSelectionBounds()

Returns: the bounds of the current selection according to the selectionAreaBoundary.

public final SnapshotView.Boundary
getUnselectedAreaBoundary()

Returns: the Boundary for the unselected area

public final Paint
getUnselectedAreaFill()

Returns: the Paint of the area outside of the selection

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.

private boolean

Returns:

true if the selection has the correct ratio.
hasCorrectRatio
(Rectangle2D
the selection to check as a Rectangle2D
selection
)

Indicates whether the specified selection has the correct ratio (which depends on whether the ratio is even fixed).

public final boolean
hasSelection()

Returns: whether there currently is a selection

public final ReadOnlyBooleanProperty

Returns:

a property indicating whether there currently is a selection
hasSelectionProperty
()

Indicates whether there currently is a selection.

private boolean

Returns:

true if the selection is fully contained in the bounds; otherwise false
inBounds
(Rectangle2D
the non-null and non-empty selection as a Rectangle2D
selection
)

Indicates whether the specified selection is inside the bounds determined by the selectionAreaBoundary property.

private static boolean

Returns:

true if the selection is fully contained in the bounds; otherwise false
inBounds
(Rectangle2D
the selection as a Rectangle2D
selection
,
Bounds
the Bounds to check the selection against
bounds
)

Indicates whether the specified selection is inside the specified bounds.

public final boolean
isSelectionActive()

Returns: whether the selection is active

public final boolean
isSelectionActivityManaged()

Returns: whether the selection activity is managed by this control

public final boolean
isSelectionChanging()

Returns: whether the selection is changing by user interaction

public final boolean
isSelectionMouseTransparent()

Returns: whether the selection is mouse transparent

public final boolean
isSelectionRatioFixed()

Returns: whether the selection ratio is fixed

private boolean

Returns:

true if the selection is valid; false otherwise
isSelectionValid
(Rectangle2D
the selection to check as a Rectangle2D
selection
)

Checks whether the specified selection is valid.

private static <T> void
listenToProperty(ObservableMap<Object, Object>
the ObservableMap which contains the properties; typically Control#getProperties()
properties
,
Object
the key for whose value is listened
key
,
Consumer<T>
the Consumer for the new value
processValue
)

Listens to the specified properties.

public final ObjectProperty<Node>

Returns:

the property holding the displayed node
nodeProperty
()

The Node which will be displayed in the center of this control.

public final BooleanProperty

Returns:

the property indicating whether the selection is active
selectionActiveProperty
()

Indicates whether the selection is currently active.

public final BooleanProperty

Returns:

the property indicating whether the value of the selectionActive property is managed by this control
selectionActivityManagedProperty
()

Indicates whether the value of the selectionActive property is managed by this control.

public final ObjectProperty<SnapshotView.Boundary>

Returns:

the property indicating the Boundary for the area the user can select
selectionAreaBoundaryProperty
()

Indicates which Boundary is set for the area the user can select.

public final ObjectProperty<Paint>

Returns:

the property holding the Paint of the selected area
selectionAreaFillProperty
()

Determines the visualization of the selected area.

public final ObjectProperty<Paint>

Returns:

the property holding the Paint of the selection border
selectionBorderPaintProperty
()

Determines the visualization of the selection's border.

public final DoubleProperty

Returns:

the property defining the selection border's width
selectionBorderWidthProperty
()

Determines the width of the selection's border.

public final ReadOnlyBooleanProperty

Returns:

a property indicating whether the selection is changing by user interaction
selectionChangingProperty
()

Indicates whether the selection is currently changing due to user interaction with the control.

public final BooleanProperty

Returns:

the property indicating whether the selection is mouse transparent
selectionMouseTransparentProperty
()

Indicates whether the overlay which displays the selection is mouse transparent.

public final ObjectProperty<Rectangle2D>

Returns:

the property holding the current selection
selectionProperty
()

The current selection as a Rectangle2D.

public final BooleanProperty

Returns:

the property indicating whether the selection ratio is fixed
selectionRatioFixedProperty
()

Indicates whether the ratio of the selection is fixed.

public final void
setFixedSelectionRatio(double
the fixed selection ratio to set
fixedSelectionRatio
)

public final void
setNode(Node
the node to display
node
)

public final void
setSelection(Rectangle2D
the new selection
selection
)

public final void
setSelection(double
the x coordinate of the selection's upper left point
upperLeftX
,
double
the y coordinate of the selection's upper left point
upperLeftY
,
double
the selection's width
width
,
double
the selection's height
height
)

Creates a new Rectangle2D from the specified arguments and sets it as the new selection.

public final void
setSelectionActive(boolean
the new selection active status
selectionActive
)

public final void
setSelectionActivityManaged(boolean
whether the selection activity will be managed by this control
selectionActivityManaged
)

public final void
setSelectionAreaBoundary(SnapshotView.Boundary
the new Boundary for the area the user can select
selectionAreaBoundary
)

public final void
setSelectionAreaFill(Paint
the new Paint of the selected area
selectionAreaFill
)

public final void
setSelectionBorderPaint(Paint
the new Paint of the selection border
selectionBorderPaint
)

public final void
setSelectionBorderWidth(double
the selection border width to set
selectionBorderWidth
)

public final void
setSelectionMouseTransparent(boolean
whether the selection will be mouse transparent
selectionMouseTransparent
)

public final void
setSelectionRatioFixed(boolean
whether the selection ratio will be fixed
selectionRatioFixed
)

public final void
setUnselectedAreaBoundary(SnapshotView.Boundary
the new Boundary for the unselected area
unselectedAreaBoundary
)

public final void
setUnselectedAreaFill(Paint
the new Paint of the area outside of the selection
unselectedAreaFill
)

public Rectangle2D

Returns:

a Rectangle2D which expresses the selection in the node's coordinates
transformSelectionToNodeCoordinates
()

Transforms the selection to node coordinates by calling transformToNodeCoordinates.

public Rectangle2D

Returns:

a Rectangle2D with the same width and height as the specified area but with coordinates which are relative to the current node
transformToNodeCoordinates
(Rectangle2D
the Rectangle2D which will be transformed (must not be null); its coordinates will be interpreted relative to the control (like the selection)
area
)

Transforms the specified area's coordinates to coordinates relative to the node.

public final ObjectProperty<SnapshotView.Boundary>

Returns:

the property defining the Boundary of the unselected area
unselectedAreaBoundaryProperty
()

Indicates which Boundary is set for the visualization of the unselected area (i.e. the area outside of the selection rectangle).

public final ObjectProperty<Paint>

Returns:

the property holding the Paint of the area outside of the selection
unselectedAreaFillProperty
()

Determines the visualization of the area outside of the selection.

private void
updateSelectionActivityState()

Updates the selectionActive property if the selectionActivityManaged property indicates that it is managed by this control.

private static boolean

Returns:

true if the selection has only finite values.
valuesFinite
(Rectangle2D
the selection as a Rectangle2D
selection
)

Indicates whether the specified selection has only finite values (e.g. width and height).

Inherited from org.controlsfx.control.ControlsFXControl:
getUserAgentStylesheet