- java.lang.Object
-
- javafx.scene.Node
-
- javafx.scene.Parent
-
- javafx.scene.layout.Region
-
- javafx.scene.control.Control
-
- org.controlsfx.control.SnapshotView
-
- All Implemented Interfaces:
Styleable,EventTarget,Skinnable
public class SnapshotView extends Control
ASnapshotViewis 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

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 thenodeproperty.Selection
There are several properties which interact to manage and indicate the selection.State
- the selection is held by the
selectionproperty - the
hasSelectionproperty indicates whether a selection exists - the
selectionActiveproperty indicates whether the current selection is active (it is only displayed if it is); by default this property is updated by this control which is determined by theselectionActivityManagedproperty
Interaction
- if the selection is changing due to the user interacting with the control, this is indicated by the
selectionChangingproperty - whether the user can select any area of the control or only one above the node is determined by the
selectionAreaBoundaryproperty - with the
selectionMouseTransparentproperty the control can be made mouse transparent so the user can interact with the displayed node - the selection's ratio of width to height can be fixed with the
selectionRatioFixedand thefixedSelectionRatioproperties
Visualization
-
selectionAreaFillproperty for the selected area's paint -
selectionBorderPaintproperty for the selection border's paint -
selectionBorderWidthproperty for the selection border's width -
unselectedAreaFillproperty for the area outside of the selection -
unselectedAreaBoundaryproperty which defined what the unselected area covers
-
-
Property Summary
Properties Type Property Description DoublePropertyfixedSelectionRatioThe value to which the selection ratio is fixed.ReadOnlyBooleanPropertyhasSelectionIndicates whether there currently is a selection.ObjectProperty<Node>nodeTheNodewhich will be displayed in the center of this control.BooleanPropertyselectionActiveIndicates whether the selection is currently active.BooleanPropertyselectionActivityManagedIndicates whether the value of theselectionActiveproperty is managed by this control.ObjectProperty<SnapshotView.Boundary>selectionAreaBoundaryIndicates whichSnapshotView.Boundaryis set for the area the user can select.ObjectProperty<Paint>selectionAreaFillDetermines the visualization of the selected area.ObjectProperty<Paint>selectionBorderPaintDetermines the visualization of the selection's border.DoublePropertyselectionBorderWidthDetermines the width of the selection's border.ReadOnlyBooleanPropertyselectionChangingIndicates whether theselectionis currently changing due to user interaction with the control.BooleanPropertyselectionMouseTransparentIndicates whether the overlay which displays the selection is mouse transparent.ObjectProperty<Rectangle2D>selectionThe current selection as aRectangle2D.BooleanPropertyselectionRatioFixedIndicates whether the ratio of theselectionis fixed.ObjectProperty<SnapshotView.Boundary>unselectedAreaBoundaryIndicates whichSnapshotView.Boundaryis set for the visualization of the unselected area (i.e.ObjectProperty<Paint>unselectedAreaFillDetermines the visualization of the area outside of the selection.-
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, 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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSnapshotView.BoundaryTheselectionArea, in which the user can create a selection, and theunselectedArea, in which the unselected area is visualized, are limited to a certain area of the control.
-
Field Summary
Fields Modifier and Type Field Description static doubleMAX_SELECTION_RATIO_DIVERGENCEThe maximal divergence between a selection's ratio and thefixedselectionRatiofor the selection to still have the correct ratio (seehasCorrectRatio).static StringSELECTION_CHANGING_PROPERTY_KEYThe key of thepropertywhich is used to updateselectionChanging.-
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 SnapshotView()Creates a new SnapshotView.SnapshotView(Node node)Creates a new SnapshotView using the specified node.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Skin<?>createDefaultSkin()WritableImagecreateSnapshot()Creates a snapshot of the selected area of the node.WritableImagecreateSnapshot(SnapshotParameters parameters)Creates a snapshot of the node with the specified parameters.DoublePropertyfixedSelectionRatioProperty()The value to which the selection ratio is fixed.static List<CssMetaData<? extends Styleable,?>>getClassCssMetaData()List<CssMetaData<? extends Styleable,?>>getControlCssMetaData()doublegetFixedSelectionRatio()NodegetNode()Rectangle2DgetSelection()SnapshotView.BoundarygetSelectionAreaBoundary()PaintgetSelectionAreaFill()PaintgetSelectionBorderPaint()doublegetSelectionBorderWidth()SnapshotView.BoundarygetUnselectedAreaBoundary()PaintgetUnselectedAreaFill()StringgetUserAgentStylesheet()protected StringgetUserAgentStylesheet(Class<?> clazz, String fileName)A helper method that ensures that the resource based lookup of the user agent stylesheet only happens once.booleanhasSelection()ReadOnlyBooleanPropertyhasSelectionProperty()Indicates whether there currently is a selection.booleanisSelectionActive()booleanisSelectionActivityManaged()booleanisSelectionChanging()booleanisSelectionMouseTransparent()booleanisSelectionRatioFixed()ObjectProperty<Node>nodeProperty()TheNodewhich will be displayed in the center of this control.BooleanPropertyselectionActiveProperty()Indicates whether the selection is currently active.BooleanPropertyselectionActivityManagedProperty()Indicates whether the value of theselectionActiveproperty is managed by this control.ObjectProperty<SnapshotView.Boundary>selectionAreaBoundaryProperty()Indicates whichSnapshotView.Boundaryis set for the area the user can select.ObjectProperty<Paint>selectionAreaFillProperty()Determines the visualization of the selected area.ObjectProperty<Paint>selectionBorderPaintProperty()Determines the visualization of the selection's border.DoublePropertyselectionBorderWidthProperty()Determines the width of the selection's border.ReadOnlyBooleanPropertyselectionChangingProperty()Indicates whether theselectionis currently changing due to user interaction with the control.BooleanPropertyselectionMouseTransparentProperty()Indicates whether the overlay which displays the selection is mouse transparent.ObjectProperty<Rectangle2D>selectionProperty()The current selection as aRectangle2D.BooleanPropertyselectionRatioFixedProperty()Indicates whether the ratio of theselectionis fixed.voidsetFixedSelectionRatio(double fixedSelectionRatio)voidsetNode(Node node)voidsetSelection(double upperLeftX, double upperLeftY, double width, double height)Creates a newRectangle2Dfrom the specified arguments and sets it as the newselection.voidsetSelection(Rectangle2D selection)voidsetSelectionActive(boolean selectionActive)voidsetSelectionActivityManaged(boolean selectionActivityManaged)voidsetSelectionAreaBoundary(SnapshotView.Boundary selectionAreaBoundary)voidsetSelectionAreaFill(Paint selectionAreaFill)voidsetSelectionBorderPaint(Paint selectionBorderPaint)voidsetSelectionBorderWidth(double selectionBorderWidth)voidsetSelectionMouseTransparent(boolean selectionMouseTransparent)voidsetSelectionRatioFixed(boolean selectionRatioFixed)voidsetUnselectedAreaBoundary(SnapshotView.Boundary unselectedAreaBoundary)voidsetUnselectedAreaFill(Paint unselectedAreaFill)Rectangle2DtransformSelectionToNodeCoordinates()Transforms theselectionto node coordinates by callingtransformToNodeCoordinates.Rectangle2DtransformToNodeCoordinates(Rectangle2D area)Transforms the specified area's coordinates to coordinates relative to the node.ObjectProperty<SnapshotView.Boundary>unselectedAreaBoundaryProperty()Indicates whichSnapshotView.Boundaryis set for the visualization of the unselected area (i.e.ObjectProperty<Paint>unselectedAreaFillProperty()Determines the visualization of the area outside of the selection.-
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, 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, 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, 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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface javafx.css.Styleable
getStyleableNode
-
-
-
-
Property Detail
-
node
public final ObjectProperty<Node> nodeProperty
TheNodewhich will be displayed in the center of this control.The node's
boundsInParentshow its relative position inside this control. Since theselectionproperty also uses this control as its reference coordinate system, the bounds can be used to compute which area of the node is selected.If this control or the node behaves strangely when resized, try embedding the original node in a
Paneand setting the pane here.- Returns:
- the property holding the displayed node
-
selection
public final ObjectProperty<Rectangle2D> selectionProperty
The current selection as aRectangle2D. As such an instance is immutable a new one must be set to chane the selection.The rectangle's coordinates are interpreted relative to this control. The top left corner is the origin (0, 0) and the lower right corner is (
width,height). It is guaranteed that the selection always lies within these bounds. If the control is resized, so is the selection. If a selection which violates these bounds is set, anIllegalArgumentExceptionis thrown.The same is true if the
selectionAreaBoundaryis set toNODEbut with the stricter condition that the selection must lie within thenode'sboundsInParent.If the selection ratio is
fixed, any new selection must have thefixedSelectionRatio. Otherwise, anIllegalArgumentExceptionis thrown.An
IllegalArgumentExceptionis also thrown if not all of the selection's values (e.g. width and height) are finite.The selection might be
nullorRectangle2D.EMPTYin which case no selection is displayed andhasSelectionisfalse.- Returns:
- the property holding the current selection
- See Also:
hasSelectionProperty()
-
hasSelection
public final ReadOnlyBooleanProperty hasSelectionProperty
Indicates whether there currently is a selection. This will befalseif theselectionproperty holdsnullorRectangle2D.EMPTY.- Returns:
- a property indicating whether there currently is a selection
-
selectionActive
public final BooleanProperty selectionActiveProperty
Indicates whether the selection is currently active. Only an active selection will be displayed by the control.See
selectionActivityManagedfor documentation on how this property might be changed by this control.- Returns:
- the property indicating whether the selection is active
-
selectionChanging
public final ReadOnlyBooleanProperty selectionChangingProperty
Indicates whether theselectionis currently changing due to user interaction with the control. It will be set totruewhen changing the selection begins and set tofalsewhen it ends.If a selection is set by the code using this control (e.g. by calling
setSelection) this property does not change its value.- Returns:
- a property indicating whether the selection is changing by user interaction
-
selectionRatioFixed
public final BooleanProperty selectionRatioFixedProperty
Indicates whether the ratio of theselectionis fixed.By default this property is
falseand the user interacting with this control can make arbitrary selections with any ratio of width to height. If it istrue, the user is limited to making selections with the ratio defined by thefixedSelectionRatioproperty. If the ratio is fixed and a selection with a different ratio is set, anIllegalArgumentExceptionis thrown.If a selection exists and this property is set to
true, the selection is immediately resized to the currently set ratio.- Default value:
false- Returns:
- the property indicating whether the selection ratio is fixed
-
fixedSelectionRatio
public final DoubleProperty fixedSelectionRatioProperty
The value to which the selection ratio is fixed. The ratio is defined aswidth / heightand its value must be strictly positive.If
selectionRatioFixedistrue, this ratio will be upheld by all changes made by user interaction with this control. If the ratio is fixed and a selection is set by code (e.g. by callingsetSelection), this ratio is checked and if violated anIllegalArgumentExceptionis thrown.If a selection exists and
selectionRatioFixedis set totrue, the selection is immediately resized to this ratio. Similarly, if a selection exists and its ratio is fixed, setting a new value resizes the selection to the new ratio.- Default value:
- 1.0
- Returns:
- a property containing the fixed selection ratio
-
selectionAreaBoundary
public final ObjectProperty<SnapshotView.Boundary> selectionAreaBoundaryProperty
Indicates whichSnapshotView.Boundaryis set for the area the user can select.By default the user can select any area of the control. If this should be limited to the area over the displayed node instead, this property can be set to
NODE. If the value is changed fromCONTROLtoNODEa possibly existing selection is resized accordingly.If the boundary is set to
NODE, this is also respected when a newselectionis set. This means the condition for the new selection's coordinates is made stricter and setting a selection out of the node's bounds (instead of only out of the control's bounds) throws anIllegalArgumentException.Note that this does not change the reference coordinate system! The selection's coordinates are still interpreted relative to the
node'sboundsInParent.- Default value:
CONTROL- Returns:
- the property indicating the
SnapshotView.Boundaryfor the area the user can select
-
selectionActivityManaged
public final BooleanProperty selectionActivityManagedProperty
Indicates whether the value of theselectionActiveproperty is managed by this control.If this property is set to
true(which is the default) this control will update theselectionActiveproperty immediately after a new selection is set: if the new selection isnullorRectangle2D.EMPTY, it will be set tofalse; otherwise totrue.If this property is
falsethis control will never changeselectionActive's value. In this case it must be managed by the using code but it is possible to unidirectionally bind it to another property without this control interfering.- Default value:
true- Returns:
- the property indicating whether the value of the
selectionActiveproperty is managed by this control
-
selectionMouseTransparent
public final BooleanProperty selectionMouseTransparentProperty
Indicates whether the overlay which displays the selection is mouse transparent.By default all mouse events are captured by this control and used to interact with the selection. If this property is set to
true, this behavior changes and the user is able to interact with the displayednode.- Default value:
false- Returns:
- the property indicating whether the selection is mouse transparent
-
unselectedAreaBoundary
public final ObjectProperty<SnapshotView.Boundary> unselectedAreaBoundaryProperty
Indicates whichSnapshotView.Boundaryis set for the visualization of the unselected area (i.e. the area outside of the selection rectangle).If it is set to
CONTROL(which is the default), the unselected area covers the whole control.If it is set to
NODE, the area only covers the displayednode. In most cases this only makes sense if theselectionAreaBoundaryis also set toNODE.- Default value:
SnapshotView.Boundary.CONTROL- Returns:
- the property defining the
SnapshotView.Boundaryof the unselected area
-
selectionBorderPaint
public final ObjectProperty<Paint> selectionBorderPaintProperty
Determines the visualization of the selection's border.- Default value:
Color.WHITESMOKE- Returns:
- the property holding the
Paintof the selection border - See Also:
selectionBorderWidthProperty()
-
selectionBorderWidth
public final DoubleProperty selectionBorderWidthProperty
Determines the width of the selection's border. The border is always painted to the outside of the selected area, i.e. the selected area is never covered by the border.- Default value:
- 2.5
- Returns:
- the property defining the selection border's width
- See Also:
selectionBorderPaintProperty(),Shape.strokeWidthProperty()
-
selectionAreaFill
public final ObjectProperty<Paint> selectionAreaFillProperty
Determines the visualization of the selected area.- Default value:
Color.TRANSPARENT- Returns:
- the property holding the
Paintof the selected area
-
unselectedAreaFill
public final ObjectProperty<Paint> unselectedAreaFillProperty
Determines the visualization of the area outside of the selection.
-
-
Field Detail
-
MAX_SELECTION_RATIO_DIVERGENCE
public static final double MAX_SELECTION_RATIO_DIVERGENCE
The maximal divergence between a selection's ratio and thefixedselectionRatiofor the selection to still have the correct ratio (seehasCorrectRatio).The divergence is expressed relative to the
fixedselectionRatio.- See Also:
- Constant Field Values
-
SELECTION_CHANGING_PROPERTY_KEY
public static final String SELECTION_CHANGING_PROPERTY_KEY
The key of thepropertywhich is used to updateselectionChanging.
-
-
Constructor Detail
-
SnapshotView
public SnapshotView()
Creates a new SnapshotView.
-
SnapshotView
public SnapshotView(Node node)
Creates a new SnapshotView using the specified node.- Parameters:
node- the node to show after construction
-
-
Method Detail
-
transformSelectionToNodeCoordinates
public Rectangle2D transformSelectionToNodeCoordinates()
Transforms theselectionto node coordinates by callingtransformToNodeCoordinates.- Returns:
- a
Rectangle2Dwhich expresses the selection in the node's coordinates - Throws:
IllegalStateException- ifnodeisnullorhasSelectionisfalse- See Also:
transformToNodeCoordinates(Rectangle2D)
-
transformToNodeCoordinates
public Rectangle2D transformToNodeCoordinates(Rectangle2D area) throws IllegalStateException
Transforms the specified area's coordinates to coordinates relative to the node. (The node's coordinate system has its origin in the upper left corner of the node.)- Parameters:
area- theRectangle2Dwhich will be transformed (must not benull); its coordinates will be interpreted relative to the control (like theselection)- Returns:
- a
Rectangle2Dwith the same width and height as the specifiedareabut with coordinates which are relative to the currentnode - Throws:
IllegalStateException- ifnodeisnull
-
createSnapshot
public WritableImage createSnapshot() throws IllegalStateException
Creates a snapshot of the selected area of the node.- Returns:
- the
WritableImagethat holds the rendered selection - Throws:
IllegalStateException- ifnodeisnullorhasSelectionisfalse- See Also:
Node.snapshot(javafx.scene.SnapshotParameters, javafx.scene.image.WritableImage)
-
createSnapshot
public WritableImage createSnapshot(SnapshotParameters parameters) throws IllegalStateException
Creates a snapshot of the node with the specified parameters.- Parameters:
parameters- theSnapshotParametersused for the snapshot (must not benull); the viewport will be interpreted relative to this control (like theselection)- Returns:
- the
WritableImagethat holds the rendered viewport - Throws:
IllegalStateException- ifnodeisnull- See Also:
Node.snapshot(javafx.scene.SnapshotParameters, javafx.scene.image.WritableImage)
-
getUserAgentStylesheet
public String getUserAgentStylesheet()
- Overrides:
getUserAgentStylesheetin classRegion
-
getClassCssMetaData
public static List<CssMetaData<? extends Styleable,?>> getClassCssMetaData()
- Returns:
- the
CssMetaDataassociated with this class, which includes theCssMetaDataof its super classes
-
getControlCssMetaData
public List<CssMetaData<? extends Styleable,?>> getControlCssMetaData()
- Overrides:
getControlCssMetaDatain classControl
-
createDefaultSkin
protected Skin<?> createDefaultSkin()
- Overrides:
createDefaultSkinin classControl
-
nodeProperty
public final ObjectProperty<Node> nodeProperty()
TheNodewhich will be displayed in the center of this control.The node's
boundsInParentshow its relative position inside this control. Since theselectionproperty also uses this control as its reference coordinate system, the bounds can be used to compute which area of the node is selected.If this control or the node behaves strangely when resized, try embedding the original node in a
Paneand setting the pane here.- Returns:
- the property holding the displayed node
-
getNode
public final Node getNode()
- Returns:
- the displayed node
- See Also:
nodeProperty()
-
setNode
public final void setNode(Node node)
- Parameters:
node- the node to display- See Also:
nodeProperty()
-
selectionProperty
public final ObjectProperty<Rectangle2D> selectionProperty()
The current selection as aRectangle2D. As such an instance is immutable a new one must be set to chane the selection.The rectangle's coordinates are interpreted relative to this control. The top left corner is the origin (0, 0) and the lower right corner is (
width,height). It is guaranteed that the selection always lies within these bounds. If the control is resized, so is the selection. If a selection which violates these bounds is set, anIllegalArgumentExceptionis thrown.The same is true if the
selectionAreaBoundaryis set toNODEbut with the stricter condition that the selection must lie within thenode'sboundsInParent.If the selection ratio is
fixed, any new selection must have thefixedSelectionRatio. Otherwise, anIllegalArgumentExceptionis thrown.An
IllegalArgumentExceptionis also thrown if not all of the selection's values (e.g. width and height) are finite.The selection might be
nullorRectangle2D.EMPTYin which case no selection is displayed andhasSelectionisfalse.- Returns:
- the property holding the current selection
- See Also:
hasSelectionProperty()
-
getSelection
public final Rectangle2D getSelection()
- Returns:
- the current selection
- See Also:
selectionProperty()
-
setSelection
public final void setSelection(Rectangle2D selection)
- Parameters:
selection- the new selection- Throws:
IllegalArgumentException- if the selection is out of the bounds defined by theselectionAreaBoundaryor the selection ratio isfixedand the new selection does not have thefixedSelectionRatio.- See Also:
selectionProperty()
-
setSelection
public final void setSelection(double upperLeftX, double upperLeftY, double width, double height)Creates a newRectangle2Dfrom the specified arguments and sets it as the newselection. It will have (upperLeftX,upperLeftY) as its upper left point and spanwidthto the right andheightdown.- Parameters:
upperLeftX- the x coordinate of the selection's upper left pointupperLeftY- the y coordinate of the selection's upper left pointwidth- the selection's widthheight- the selection's height- Throws:
IllegalArgumentException- if the selection is out of the bounds defined by theselectionAreaBoundaryor the selection ratio isfixedand the new selection does not have thefixedSelectionRatio.- See Also:
selectionProperty()
-
hasSelectionProperty
public final ReadOnlyBooleanProperty hasSelectionProperty()
Indicates whether there currently is a selection. This will befalseif theselectionproperty holdsnullorRectangle2D.EMPTY.- Returns:
- a property indicating whether there currently is a selection
-
hasSelection
public final boolean hasSelection()
- Returns:
- whether there currently is a selection
- See Also:
hasSelectionProperty()
-
selectionActiveProperty
public final BooleanProperty selectionActiveProperty()
Indicates whether the selection is currently active. Only an active selection will be displayed by the control.See
selectionActivityManagedfor documentation on how this property might be changed by this control.- Returns:
- the property indicating whether the selection is active
-
isSelectionActive
public final boolean isSelectionActive()
- Returns:
- whether the selection is active
- See Also:
selectionActiveProperty()
-
setSelectionActive
public final void setSelectionActive(boolean selectionActive)
- Parameters:
selectionActive- the new selection active status- See Also:
selectionActiveProperty()
-
selectionChangingProperty
public final ReadOnlyBooleanProperty selectionChangingProperty()
Indicates whether theselectionis currently changing due to user interaction with the control. It will be set totruewhen changing the selection begins and set tofalsewhen it ends.If a selection is set by the code using this control (e.g. by calling
setSelection) this property does not change its value.- Returns:
- a property indicating whether the selection is changing by user interaction
-
isSelectionChanging
public final boolean isSelectionChanging()
- Returns:
- whether the selection is changing by user interaction
- See Also:
selectionChangingProperty()
-
selectionRatioFixedProperty
public final BooleanProperty selectionRatioFixedProperty()
Indicates whether the ratio of theselectionis fixed.By default this property is
falseand the user interacting with this control can make arbitrary selections with any ratio of width to height. If it istrue, the user is limited to making selections with the ratio defined by thefixedSelectionRatioproperty. If the ratio is fixed and a selection with a different ratio is set, anIllegalArgumentExceptionis thrown.If a selection exists and this property is set to
true, the selection is immediately resized to the currently set ratio.- Default value:
false- Returns:
- the property indicating whether the selection ratio is fixed
-
isSelectionRatioFixed
public final boolean isSelectionRatioFixed()
- Returns:
- whether the selection ratio is fixed
- See Also:
selectionRatioFixedProperty()
-
setSelectionRatioFixed
public final void setSelectionRatioFixed(boolean selectionRatioFixed)
- Parameters:
selectionRatioFixed- whether the selection ratio will be fixed- See Also:
selectionRatioFixedProperty()
-
fixedSelectionRatioProperty
public final DoubleProperty fixedSelectionRatioProperty()
The value to which the selection ratio is fixed. The ratio is defined aswidth / heightand its value must be strictly positive.If
selectionRatioFixedistrue, this ratio will be upheld by all changes made by user interaction with this control. If the ratio is fixed and a selection is set by code (e.g. by callingsetSelection), this ratio is checked and if violated anIllegalArgumentExceptionis thrown.If a selection exists and
selectionRatioFixedis set totrue, the selection is immediately resized to this ratio. Similarly, if a selection exists and its ratio is fixed, setting a new value resizes the selection to the new ratio.- Default value:
- 1.0
- Returns:
- a property containing the fixed selection ratio
-
getFixedSelectionRatio
public final double getFixedSelectionRatio()
- Returns:
- the fixedSelectionRatio, which will always be a strictly positive value
- See Also:
fixedSelectionRatioProperty()
-
setFixedSelectionRatio
public final void setFixedSelectionRatio(double fixedSelectionRatio)
- Parameters:
fixedSelectionRatio- the fixed selection ratio to set- Throws:
IllegalArgumentException- iffixedSelectionRatiois not strictly positive- See Also:
fixedSelectionRatioProperty()
-
selectionAreaBoundaryProperty
public final ObjectProperty<SnapshotView.Boundary> selectionAreaBoundaryProperty()
Indicates whichSnapshotView.Boundaryis set for the area the user can select.By default the user can select any area of the control. If this should be limited to the area over the displayed node instead, this property can be set to
NODE. If the value is changed fromCONTROLtoNODEa possibly existing selection is resized accordingly.If the boundary is set to
NODE, this is also respected when a newselectionis set. This means the condition for the new selection's coordinates is made stricter and setting a selection out of the node's bounds (instead of only out of the control's bounds) throws anIllegalArgumentException.Note that this does not change the reference coordinate system! The selection's coordinates are still interpreted relative to the
node'sboundsInParent.- Default value:
CONTROL- Returns:
- the property indicating the
SnapshotView.Boundaryfor the area the user can select
-
getSelectionAreaBoundary
public final SnapshotView.Boundary getSelectionAreaBoundary()
- Returns:
- the
SnapshotView.Boundaryfor the area the user can select
-
setSelectionAreaBoundary
public final void setSelectionAreaBoundary(SnapshotView.Boundary selectionAreaBoundary)
- Parameters:
selectionAreaBoundary- the newSnapshotView.Boundaryfor the area the user can select
-
selectionActivityManagedProperty
public final BooleanProperty selectionActivityManagedProperty()
Indicates whether the value of theselectionActiveproperty is managed by this control.If this property is set to
true(which is the default) this control will update theselectionActiveproperty immediately after a new selection is set: if the new selection isnullorRectangle2D.EMPTY, it will be set tofalse; otherwise totrue.If this property is
falsethis control will never changeselectionActive's value. In this case it must be managed by the using code but it is possible to unidirectionally bind it to another property without this control interfering.- Default value:
true- Returns:
- the property indicating whether the value of the
selectionActiveproperty is managed by this control
-
isSelectionActivityManaged
public final boolean isSelectionActivityManaged()
- Returns:
- whether the selection activity is managed by this control
- See Also:
selectionActivityManagedProperty()
-
setSelectionActivityManaged
public final void setSelectionActivityManaged(boolean selectionActivityManaged)
- Parameters:
selectionActivityManaged- whether the selection activity will be managed by this control- See Also:
selectionActivityManagedProperty()
-
selectionMouseTransparentProperty
public final BooleanProperty selectionMouseTransparentProperty()
Indicates whether the overlay which displays the selection is mouse transparent.By default all mouse events are captured by this control and used to interact with the selection. If this property is set to
true, this behavior changes and the user is able to interact with the displayednode.- Default value:
false- Returns:
- the property indicating whether the selection is mouse transparent
-
isSelectionMouseTransparent
public final boolean isSelectionMouseTransparent()
- Returns:
- whether the selection is mouse transparent
- See Also:
selectionMouseTransparentProperty()
-
setSelectionMouseTransparent
public final void setSelectionMouseTransparent(boolean selectionMouseTransparent)
- Parameters:
selectionMouseTransparent- whether the selection will be mouse transparent- See Also:
selectionMouseTransparentProperty()
-
unselectedAreaBoundaryProperty
public final ObjectProperty<SnapshotView.Boundary> unselectedAreaBoundaryProperty()
Indicates whichSnapshotView.Boundaryis set for the visualization of the unselected area (i.e. the area outside of the selection rectangle).If it is set to
CONTROL(which is the default), the unselected area covers the whole control.If it is set to
NODE, the area only covers the displayednode. In most cases this only makes sense if theselectionAreaBoundaryis also set toNODE.- Default value:
SnapshotView.Boundary.CONTROL- Returns:
- the property defining the
SnapshotView.Boundaryof the unselected area
-
getUnselectedAreaBoundary
public final SnapshotView.Boundary getUnselectedAreaBoundary()
- Returns:
- the
SnapshotView.Boundaryfor the unselected area - See Also:
unselectedAreaBoundaryProperty()
-
setUnselectedAreaBoundary
public final void setUnselectedAreaBoundary(SnapshotView.Boundary unselectedAreaBoundary)
- Parameters:
unselectedAreaBoundary- the newSnapshotView.Boundaryfor the unselected area- See Also:
unselectedAreaBoundaryProperty()
-
selectionBorderPaintProperty
public final ObjectProperty<Paint> selectionBorderPaintProperty()
Determines the visualization of the selection's border.- Default value:
Color.WHITESMOKE- Returns:
- the property holding the
Paintof the selection border - See Also:
selectionBorderWidthProperty()
-
getSelectionBorderPaint
public final Paint getSelectionBorderPaint()
- Returns:
- the
Paintof the selection border - See Also:
selectionBorderPaintProperty()
-
setSelectionBorderPaint
public final void setSelectionBorderPaint(Paint selectionBorderPaint)
- Parameters:
selectionBorderPaint- the newPaintof the selection border- See Also:
selectionBorderPaintProperty()
-
selectionBorderWidthProperty
public final DoubleProperty selectionBorderWidthProperty()
Determines the width of the selection's border. The border is always painted to the outside of the selected area, i.e. the selected area is never covered by the border.- Default value:
- 2.5
- Returns:
- the property defining the selection border's width
- See Also:
selectionBorderPaintProperty(),Shape.strokeWidthProperty()
-
getSelectionBorderWidth
public final double getSelectionBorderWidth()
- Returns:
- the selection border width
- See Also:
selectionBorderWidthProperty()
-
setSelectionBorderWidth
public final void setSelectionBorderWidth(double selectionBorderWidth)
- Parameters:
selectionBorderWidth- the selection border width to set- See Also:
selectionBorderWidthProperty()
-
selectionAreaFillProperty
public final ObjectProperty<Paint> selectionAreaFillProperty()
Determines the visualization of the selected area.- Default value:
Color.TRANSPARENT- Returns:
- the property holding the
Paintof the selected area
-
getSelectionAreaFill
public final Paint getSelectionAreaFill()
- Returns:
- the
Paintof the selected area - See Also:
selectionAreaFillProperty()
-
setSelectionAreaFill
public final void setSelectionAreaFill(Paint selectionAreaFill)
- Parameters:
selectionAreaFill- the newPaintof the selected area- See Also:
selectionAreaFillProperty()
-
unselectedAreaFillProperty
public final ObjectProperty<Paint> unselectedAreaFillProperty()
Determines the visualization of the area outside of the selection.
-
getUnselectedAreaFill
public final Paint getUnselectedAreaFill()
- Returns:
- the
Paintof the area outside of the selection - See Also:
unselectedAreaFillProperty()
-
setUnselectedAreaFill
public final void setUnselectedAreaFill(Paint unselectedAreaFill)
- Parameters:
unselectedAreaFill- the newPaintof the area outside of the selection- See Also:
unselectedAreaFillProperty()
-
getUserAgentStylesheet
protected final String getUserAgentStylesheet(Class<?> clazz, String fileName)
A helper method that ensures that the resource based lookup of the user agent stylesheet only happens once. Caches the external form of the resource.- Parameters:
clazz- the class used for the resource lookupfileName- the name of the user agent stylesheet- Returns:
- the external form of the user agent stylesheet (the path)
-
-