Module MaterialFX

Class MFXCircleRippleGenerator

All Implemented Interfaces:
IRippleGenerator<MFXCircleRippleGenerator.CircleRipple>, Styleable, EventTarget

public class MFXCircleRippleGenerator extends AbstractMFXRippleGenerator<MFXCircleRippleGenerator.CircleRipple>
Concrete implementation of AbstractMFXRippleGenerator<MFXCircleRippleGenerator.CircleRipple>.

This is the most basic ripple generator that generates circular ripples. Accepted ripples are MFXCircleRippleGenerator.CircleRipple or subclasses.

Usage example:
 
      Region region = ...
      MFXCircleRippleGenerator generator = new MFXCircleRippleGenerator(region) // It's needed to pass the region reference
      generator.setRipplePositionFunction(mouseEvent -> ...) // This is needed to specify where the ripple should be placed when generated
      region.getChildren().add(generator) // Ripples are added to the generator's container so the generator must be added to the region
      region.addEventHandler(MouseEvent.MOUSE_PRESSED, generator::generateRipple)
 
 
  • Property Details

  • Constructor Details

    • MFXCircleRippleGenerator

      public MFXCircleRippleGenerator(Region region)
  • Method Details

    • initialize

      protected void initialize()
      Overrides:
      initialize in class AbstractMFXRippleGenerator<MFXCircleRippleGenerator.CircleRipple>
    • generateRipple

      public void generateRipple(MouseEvent event)
      Generates a ripple.

      - If AbstractMFXRippleGenerator.checkBoundsProperty() is true calls AbstractMFXRippleGenerator.isWithinBounds(MouseEvent). Exits if returns false.

      - Sets the generator clip/bounds by calling buildClip().

      - Computes the ripple coordinates by calling getRipplePositionFunction() applied on the passed mouse event.

      - Creates the ripple by calling getRippleSupplier(). Sets the center and fill properties of the ripple.

      - Creates the animations by calling MFXCircleRippleGenerator.CircleRipple.getAnimation()

      - If AbstractMFXRippleGenerator.animateBackgroundProperty() and AbstractMFXRippleGenerator.animateShadowProperty() are true, creates the respective animations by calling getBackgroundAnimation() and getShadowAnimation().

      - The animations are added to a ParallelTransition which is added to the animation stack.

      - The ripple is added to the generator's children list.

      - The animation starts.

      Specified by:
      generateRipple in class AbstractMFXRippleGenerator<MFXCircleRippleGenerator.CircleRipple>
      See Also:
    • getBackgroundAnimation

      protected Animation getBackgroundAnimation()
      Builds the background animation. It consists in a temporary shape added to the generator's children list in position 0. The opacity of the shape is increased to the value specified by backgroundOpacityProperty(), and then dropped to 0. When the opacity is 0 it is removed from the children list.
    • getShadowAnimation

      protected Animation getShadowAnimation()
      Builds the animation of the DropShadow effect. If the region's effect is not a DropShadow or its level is not recognized by DepthLevel.from(DropShadow) then an empty animation is returned.

      If the effect is recognized then builds two new DropShadow effects, a start one and an end one. The start effect is the same level as the region's one and the end is computed by MFXDepthManager.shadowOf(DepthLevel, int) using AbstractMFXRippleGenerator.depthLevelOffsetProperty() as argument.

      N.B: as stated above the animation works only for shadows defined by DepthLevel

    • computeRadiusMultiplier

      protected double computeRadiusMultiplier(double xCoordinate)
      Attempts to compute the radius multiplier from the starting ripple radius and the x position at which the ripple will be generated.

      Currently the value is computed by finding the region' side closest to the specified x coordinate. The final radius is computed as the starting radius plus "Math.abs(xCoordinate - nearestBound)". Then the multiplier is calculated as the final radius divided by the starting radius.

      This method works in most cases. Sometimes the computed multiplier is not enough to cover the entire region. This is probably because the right way would be to consider the farthermost vertex rather than side. However, it's not a big issue since you can also manipulate the initial radius or set the multiplier manually.

      Parameters:
      xCoordinate - the x coordinate at which the ripple will be generated
      See Also:
    • buildClip

      protected Node buildClip()
      Responsible for building the ripple generator's clip, which avoids ripple ending outside the region.
      See Also:
    • isComputeRadiusMultiplier

      public boolean isComputeRadiusMultiplier()
      Gets the value of the property computeRadiusMultiplier.
      Property description:
      Specifies if the ripple's radius multiplier should be computed automatically. If this is true the value specified by radiusMultiplierProperty() will be ignored and computeRadiusMultiplier(double) will be called instead.
    • computeRadiusMultiplierProperty

      public BooleanProperty computeRadiusMultiplierProperty()
      Specifies if the ripple's radius multiplier should be computed automatically. If this is true the value specified by radiusMultiplierProperty() will be ignored and computeRadiusMultiplier(double) will be called instead.
      See Also:
    • setComputeRadiusMultiplier

      public void setComputeRadiusMultiplier(boolean computeRadiusMultiplier)
      Sets the value of the property computeRadiusMultiplier.
      Property description:
      Specifies if the ripple's radius multiplier should be computed automatically. If this is true the value specified by radiusMultiplierProperty() will be ignored and computeRadiusMultiplier(double) will be called instead.
    • getRadiusMultiplier

      public double getRadiusMultiplier()
      Gets the value of the property radiusMultiplier.
      Property description:
      Specifies the multiplier used to obtain the final ripple's radius.

      If you are still wondering what the heck is this multiplier then read this.

      The ripple is basically a shape, in this case a circle with initial radius 0, created at specified coordinates.

      Generally speaking:

      The first phase of the ripple animation consists in increasing the radius to the value specified by rippleRadiusProperty().

      The second phase is to further expand that radius (like a ripple in a lake lol) to make the circle cover entirely or almost the region.

      The last phase is to drop the circle opacity to 0 and remove the ripple.

    • radiusMultiplierProperty

      public DoubleProperty radiusMultiplierProperty()
      Specifies the multiplier used to obtain the final ripple's radius.

      If you are still wondering what the heck is this multiplier then read this.

      The ripple is basically a shape, in this case a circle with initial radius 0, created at specified coordinates.

      Generally speaking:

      The first phase of the ripple animation consists in increasing the radius to the value specified by rippleRadiusProperty().

      The second phase is to further expand that radius (like a ripple in a lake lol) to make the circle cover entirely or almost the region.

      The last phase is to drop the circle opacity to 0 and remove the ripple.

      See Also:
    • setRadiusMultiplier

      public void setRadiusMultiplier(double radiusMultiplier)
      Sets the value of the property radiusMultiplier.
      Property description:
      Specifies the multiplier used to obtain the final ripple's radius.

      If you are still wondering what the heck is this multiplier then read this.

      The ripple is basically a shape, in this case a circle with initial radius 0, created at specified coordinates.

      Generally speaking:

      The first phase of the ripple animation consists in increasing the radius to the value specified by rippleRadiusProperty().

      The second phase is to further expand that radius (like a ripple in a lake lol) to make the circle cover entirely or almost the region.

      The last phase is to drop the circle opacity to 0 and remove the ripple.

    • getRegion

      public Region getRegion()
      Returns:
      the region on which the ripple will be generated
    • defaultClipSupplier

      public void defaultClipSupplier()
      Description copied from interface: IRippleGenerator
      Every ripple generator should have a default clip supplier.
    • getClipSupplier

      public Supplier<Shape> getClipSupplier()
      Returns:
      the current generator's clip supplier
    • setClipSupplier

      public void setClipSupplier(Supplier<Shape> clipSupplier)
      Description copied from interface: IRippleGenerator
      Sets the generator's clip supplier to the specified one.

      This is responsible for creating the clip node of the generator, which is built and set everytime the ripple is generated, before the animation is started, and defines the bounds beyond which the ripple must not go.

      Although the supplier accepts any Shape it is highly recommended to build clips using RippleClipTypeFactory.

    • defaultPositionFunction

      public void defaultPositionFunction()
      Description copied from interface: IRippleGenerator
      Every ripple generator should have a default position for the ripples.
    • getRipplePositionFunction

      public Function<MouseEvent,PositionBean> getRipplePositionFunction()
      Returns:
      the current generator's position function
    • setRipplePositionFunction

      public void setRipplePositionFunction(Function<MouseEvent,PositionBean> positionFunction)
      Description copied from interface: IRippleGenerator
      Sets the generator's ripple position function to the specified one.

      This Function is responsible for computing the ripple's x and y coordinates before the animation is played. The function takes a MouseEvent as the input (since in most controls the coordinates are the x and y coordinates of the mouse event) and returns a PositionBean bean.

    • defaultRippleSupplier

      public void defaultRippleSupplier()
      Description copied from interface: IRippleGenerator
      Every ripple generator should have a default ripple supplier.
    • getRippleSupplier

      public Supplier<MFXCircleRippleGenerator.CircleRipple> getRippleSupplier()
      Returns:
      the current generator's ripple supplier
    • setRippleSupplier

      public void setRippleSupplier(Supplier<MFXCircleRippleGenerator.CircleRipple> rippleSupplier)
      Description copied from interface: IRippleGenerator
      Sets the generator's ripple supplier to the specified one.

      This Supplier is responsible for creating the ripple shape before the animation is played.

    • getAnimationSpeed

      public double getAnimationSpeed()
      Gets the value of the property animationSpeed.
      Property description:
      Specifies the speed on the ripples' animation. This is done by setting the animations rate property, Animation.setRate(double)
    • animationSpeedProperty

      public StyleableDoubleProperty animationSpeedProperty()
      Specifies the speed on the ripples' animation. This is done by setting the animations rate property, Animation.setRate(double)
      See Also:
    • setAnimationSpeed

      public void setAnimationSpeed(double animationSpeed)
      Sets the value of the property animationSpeed.
      Property description:
      Specifies the speed on the ripples' animation. This is done by setting the animations rate property, Animation.setRate(double)
    • isAutoClip

      public boolean isAutoClip()
      Gets the value of the property autoClip.
      Property description:
      Specifies whether the generator should try to buildClip() automatically, this means also trying to fetch the background/border radius.

      EXPERIMENTAL, may not work in all situations

    • autoClipProperty

      public StyleableBooleanProperty autoClipProperty()
      Specifies whether the generator should try to buildClip() automatically, this means also trying to fetch the background/border radius.

      EXPERIMENTAL, may not work in all situations

      See Also:
    • setAutoClip

      public void setAutoClip(boolean autoClip)
      Sets the value of the property autoClip.
      Property description:
      Specifies whether the generator should try to buildClip() automatically, this means also trying to fetch the background/border radius.

      EXPERIMENTAL, may not work in all situations

    • getBackgroundOpacity

      public double getBackgroundOpacity()
      Gets the value of the property backgroundOpacity.
      Property description:
      Specifies the strength of the background animation.
    • backgroundOpacityProperty

      public StyleableDoubleProperty backgroundOpacityProperty()
      Specifies the strength of the background animation.
      See Also:
    • setBackgroundOpacity

      public void setBackgroundOpacity(double backgroundOpacity)
      Sets the value of the property backgroundOpacity.
      Property description:
      Specifies the strength of the background animation.
    • isPaused

      public boolean isPaused()
      Gets the value of the property paused.
      Property description:
      Property to enable/disable the ripple generator.
    • pausedProperty

      public StyleableBooleanProperty pausedProperty()
      Property to enable/disable the ripple generator.
      See Also:
    • setPaused

      public void setPaused(boolean paused)
      Sets the value of the property paused.
      Property description:
      Property to enable/disable the ripple generator.
    • getRippleColor

      public Paint getRippleColor()
      Gets the value of the property rippleColor.
      Property description:
      Specifies the ripples' color.
    • rippleColorProperty

      public StyleableObjectProperty<Paint> rippleColorProperty()
      Specifies the ripples' color.
      See Also:
    • setRippleColor

      public void setRippleColor(Paint rippleColor)
      Sets the value of the property rippleColor.
      Property description:
      Specifies the ripples' color.
    • getRippleOpacity

      public double getRippleOpacity()
      Gets the value of the property rippleOpacity.
      Property description:
      Specifies the initial ripple's opacity.
    • rippleOpacityProperty

      public StyleableDoubleProperty rippleOpacityProperty()
      Specifies the initial ripple's opacity.
      See Also:
    • setRippleOpacity

      public void setRippleOpacity(double rippleOpacity)
      Sets the value of the property rippleOpacity.
      Property description:
      Specifies the initial ripple's opacity.
    • getRippleRadius

      public double getRippleRadius()
      Gets the value of the property rippleRadius.
      Property description:
      Specifies the ripples' initial radius.
    • rippleRadiusProperty

      public StyleableDoubleProperty rippleRadiusProperty()
      Specifies the ripples' initial radius.
      See Also:
    • setRippleRadius

      public void setRippleRadius(double radius)
      Sets the value of the property rippleRadius.
      Property description:
      Specifies the ripples' initial radius.
    • getControlCssMetaDataList

      public static List<CssMetaData<? extends Styleable,?>> getControlCssMetaDataList()
    • getCssMetaData

      public List<CssMetaData<? extends Styleable,?>> getCssMetaData()
      Specified by:
      getCssMetaData in interface Styleable
      Overrides:
      getCssMetaData in class Region