Top Description Inners Fields Constructors Methods
com.dlsc.gemsfx

public Class PhotoView

extends Control
Class Inheritance
Imports
com.dlsc.gemsfx.skins.PhotoViewSkin, javafx.beans.property.BooleanProperty, .DoubleProperty, .ObjectProperty, .ReadOnlyObjectProperty, .ReadOnlyObjectWrapper, .SimpleBooleanProperty, .SimpleDoubleProperty, .SimpleObjectProperty, javafx.collections.MapChangeListener, javafx.css.PseudoClass, javafx.scene.Node, javafx.scene.control.ContentDisplay, .Control, .Label, .Skin, javafx.scene.effect.Effect, .SepiaTone, javafx.scene.image.Image, javafx.scene.input.Dragboard, .TransferMode, javafx.scene.text.TextAlignment, javafx.stage.FileChooser, .FileChooser.ExtensionFilter, org.kordamp.ikonli.javafx.FontIcon, org.kordamp.ikonli.materialdesign.MaterialDesign, java.io.File, .FileInputStream, .IOException, java.util.Arrays, .List, .Objects, java.util.function.Supplier, java.util.logging.Level, .Logger

The photo view is mostly used to display a user profile picture.

Features

Note

the values for the zoom and translate properties will all be reset when a new photo is set.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static enum

Field Summary

Modifier and TypeField and Description
private final ObjectProperty<PhotoView.ClipShape>
public final BooleanProperty
private final ReadOnlyObjectWrapper<Image>
private final BooleanProperty
private static final PseudoClass
private FileChooser
private final Logger
private final DoubleProperty
private final ObjectProperty<Image>
private final ObjectProperty<Effect>
private final ObjectProperty<Supplier<Image>>
private final DoubleProperty
private final DoubleProperty
private final DoubleProperty
private final ObjectProperty<Node>
private static final String[]

Constructor Summary

AccessConstructor and Description
public
PhotoView()

Constructs a new photo view.

Method Summary

Modifier and TypeMethod and Description
public ObjectProperty<PhotoView.ClipShape>

Returns:

the clip shape (circle, rectangle)
clipShapeProperty
()

The clip shape determines whether the control will clip the photo via a circle or a rectangle shape.

public final BooleanProperty

Returns:

true if the view should create the cropped image
createCroppedImageProperty
()

Specifies whether the view should constantly create a cropped image version of the original image whenever the user edits the original.

protected Skin<?>
createDefaultSkin()

Overrides javafx.scene.control.Control.createDefaultSkin.

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

public final ReadOnlyObjectProperty<Image>

Returns:

the cropped image version of the original image
croppedImageProperty
()

A read-only property that contains the cropped version of the original image.

public final BooleanProperty

Returns:

"true" if the view is editable
editableProperty
()

Controls whether the user will be able to edit the photo / image.

public PhotoView.ClipShape
public final Image
public final double
public final Image
public final Effect
public Supplier<Image>
public final double
public final double
public final double
public final Node
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 boolean
public final boolean
public final DoubleProperty

Returns:

the maximum zoom value (default 5)
maxZoomProperty
()

Stores the maximum amount that the user will be allowed to zoom into the view.

public final ObjectProperty<Effect>

Returns:

the photo effect
photoEffectProperty
()

An effect that will be applied to the image, not the whole control.

public final ObjectProperty<Image>

Returns:

the photo
photoProperty
()

Stores the original photo.

public ObjectProperty<Supplier<Image>>

Returns:

the photo supplier
photoSupplierProperty
()

The photo supplier will be invoked when the user clicks on the control (or hits space oder enter keys).

public final DoubleProperty

Returns:

the translate x value (in percent)
photoTranslateXProperty
()

Stores the percentage-based amount of the horizontal translation.

public final DoubleProperty

Returns:

the translate y value (in percent)
photoTranslateYProperty
()

Stores the percentage-based amount of the vertical translation.

public final DoubleProperty

Returns:

the photo zoom
photoZoomProperty
()

The zoom applied to the photo so that the photo's content fills out the view as good as possible.

public final ObjectProperty<Node>

Returns:

the placeholder node
placeholderProperty
()

A placeholder that will be shown when no photo / image has been specified.

public void
public final void
setCreateCroppedImage(boolean createCroppedImage)

public final void
setEditable(boolean editable)

public final void
setMaxZoom(double maxZoom)

public final void
setPhoto(Image photo)

public final void
setPhotoEffect(Effect photoEffect)

public void
public final void
setPhotoTranslateX(double photoTranslateX)

public final void
setPhotoTranslateY(double photoTranslateY)

public final void
setPhotoZoom(double photoZoom)

public final void
setPlaceholder(Node placeholder)

Inherited from javafx.scene.control.Control:
computeMaxHeightcomputeMaxWidthcomputeMinHeightcomputeMinWidthcomputePrefHeightcomputePrefWidthcontextMenuPropertyexecuteAccessibleActiongetBaselineOffsetgetClassCssMetaDatagetContextMenugetControlCssMetaDatagetCssMetaDatagetInitialFocusTraversablegetSkingetTooltipisResizablelayoutChildrenqueryAccessibleAttributesetContextMenusetSkinsetTooltipskinPropertytooltipProperty

Field Detail

clipShapeback to summary
private final ObjectProperty<PhotoView.ClipShape> clipShape
createCroppedImageback to summary
public final BooleanProperty createCroppedImage
croppedImageback to summary
private final ReadOnlyObjectWrapper<Image> croppedImage
editableback to summary
private final BooleanProperty editable
EMPTY_PSEUDO_CLASSback to summary
private static final PseudoClass EMPTY_PSEUDO_CLASS
fileChooserback to summary
private FileChooser fileChooser
LOGback to summary
private final Logger LOG
maxZoomback to summary
private final DoubleProperty maxZoom
photoback to summary
private final ObjectProperty<Image> photo
photoEffectback to summary
private final ObjectProperty<Effect> photoEffect
photoSupplierback to summary
private final ObjectProperty<Supplier<Image>> photoSupplier
photoTranslateXback to summary
private final DoubleProperty photoTranslateX
photoTranslateYback to summary
private final DoubleProperty photoTranslateY
photoZoomback to summary
private final DoubleProperty photoZoom
placeholderback to summary
private final ObjectProperty<Node> placeholder
SUPPORTED_EXTENSIONSback to summary
private static final String[] SUPPORTED_EXTENSIONS

Constructor Detail

PhotoViewback to summary
public PhotoView()

Constructs a new photo view.

Method Detail

clipShapePropertyback to summary
public ObjectProperty<PhotoView.ClipShape> clipShapeProperty()

The clip shape determines whether the control will clip the photo via a circle or a rectangle shape.

Returns:ObjectProperty<PhotoView.ClipShape>

the clip shape (circle, rectangle)

createCroppedImagePropertyback to summary
public final BooleanProperty createCroppedImageProperty()

Specifies whether the view should constantly create a cropped image version of the original image whenever the user edits the original. Creating a cropped image can have a performance impact on slower hardware (e.g. embedded).

Returns:BooleanProperty

true if the view should create the cropped image

See Also
croppedImageProperty()
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
croppedImagePropertyback to summary
public final ReadOnlyObjectProperty<Image> croppedImageProperty()

A read-only property that contains the cropped version of the original image. An image becomes cropped when the user moves it around or zooms into it. The cropped image is a good candidate for saving it to the server or database. However, applications can choose freely whether they prefer to store the original image or not.

Returns:ReadOnlyObjectProperty<Image>

the cropped image version of the original image

editablePropertyback to summary
public final BooleanProperty editableProperty()

Controls whether the user will be able to edit the photo / image. If editable the control will display a slider below the photo for zooming. The user will also be able to zoom in via pinch zoom or scroll wheel. Via mouse dragging the user can move the photo around.

Returns:BooleanProperty

"true" if the view is editable

getClipShapeback to summary
public PhotoView.ClipShape getClipShape()
getCroppedImageback to summary
public final Image getCroppedImage()
getMaxZoomback to summary
public final double getMaxZoom()
getPhotoback to summary
public final Image getPhoto()
getPhotoEffectback to summary
public final Effect getPhotoEffect()
getPhotoSupplierback to summary
public Supplier<Image> getPhotoSupplier()
getPhotoTranslateXback to summary
public final double getPhotoTranslateX()
getPhotoTranslateYback to summary
public final double getPhotoTranslateY()
getPhotoZoomback to summary
public final double getPhotoZoom()
getPlaceholderback to summary
public final Node getPlaceholder()
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
isCreateCroppedImageback to summary
public final boolean isCreateCroppedImage()
isEditableback to summary
public final boolean isEditable()
maxZoomPropertyback to summary
public final DoubleProperty maxZoomProperty()

Stores the maximum amount that the user will be allowed to zoom into the view. The default value is 5.

Returns:DoubleProperty

the maximum zoom value (default 5)

photoEffectPropertyback to summary
public final ObjectProperty<Effect> photoEffectProperty()

An effect that will be applied to the image, not the whole control. Applications could for example apply a sepia effect (see SepiaTone).

Returns:ObjectProperty<Effect>

the photo effect

photoPropertyback to summary
public final ObjectProperty<Image> photoProperty()

Stores the original photo.

Returns:ObjectProperty<Image>

the photo

photoSupplierPropertyback to summary
public ObjectProperty<Supplier<Image>> photoSupplierProperty()

The photo supplier will be invoked when the user clicks on the control (or hits space oder enter keys). The default photo supplier registered on the control will bring up a file chooser so that the user can select the image file.

Returns:ObjectProperty<Supplier<Image>>

the photo supplier

photoTranslateXPropertyback to summary
public final DoubleProperty photoTranslateXProperty()

Stores the percentage-based amount of the horizontal translation. We can not use pixel-based translation as the view might change its size. This value changes when the user drags the photo left or right.

Returns:DoubleProperty

the translate x value (in percent)

photoTranslateYPropertyback to summary
public final DoubleProperty photoTranslateYProperty()

Stores the percentage-based amount of the vertical translation. We can not use pixel-based translation as the view might change its size. This value changes when the user drags the photo up or down.

Returns:DoubleProperty

the translate y value (in percent)

photoZoomPropertyback to summary
public final DoubleProperty photoZoomProperty()

The zoom applied to the photo so that the photo's content fills out the view as good as possible.

Returns:DoubleProperty

the photo zoom

placeholderPropertyback to summary
public final ObjectProperty<Node> placeholderProperty()

A placeholder that will be shown when no photo / image has been specified. The default placeholder prompts the user to "click to add or drop a file".

Returns:ObjectProperty<Node>

the placeholder node

setClipShapeback to summary
public void setClipShape(PhotoView.ClipShape clipShape)
setCreateCroppedImageback to summary
public final void setCreateCroppedImage(boolean createCroppedImage)
setEditableback to summary
public final void setEditable(boolean editable)
setMaxZoomback to summary
public final void setMaxZoom(double maxZoom)
setPhotoback to summary
public final void setPhoto(Image photo)
setPhotoEffectback to summary
public final void setPhotoEffect(Effect photoEffect)
setPhotoSupplierback to summary
public void setPhotoSupplier(Supplier<Image> photoSupplier)
setPhotoTranslateXback to summary
public final void setPhotoTranslateX(double photoTranslateX)
setPhotoTranslateYback to summary
public final void setPhotoTranslateY(double photoTranslateY)
setPhotoZoomback to summary
public final void setPhotoZoom(double photoZoom)
setPlaceholderback to summary
public final void setPlaceholder(Node placeholder)
com.dlsc.gemsfx back to summary

public final Enum PhotoView.ClipShape

extends Enum<PhotoView.ClipShape>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final PhotoView.ClipShape
public static final PhotoView.ClipShape

Constructor Summary

AccessConstructor and Description
private

Method Summary

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

Field Detail

CIRCLEback to summary
public static final PhotoView.ClipShape CIRCLE
RECTANGLEback to summary
public static final PhotoView.ClipShape RECTANGLE

Constructor Detail

ClipShapeback to summary
private ClipShape()

Method Detail

valueOfback to summary
public static PhotoView.ClipShape valueOf(String name)
valuesback to summary
public static PhotoView.ClipShape[] values()