Module MaterialFX

Class MFXMagnifierPane

All Implemented Interfaces:
Styleable, EventTarget, Skinnable

public class MFXMagnifierPane extends Control
MaterialFX implementation of a pane/control capable of "zooming" its content (any Node).

This control is quite complex and has a lot of features. A lens (part of the skin), controlled/positioned by the mouse, is responsible for zooming a portion of the content by the specified zoomProperty().

The mouse wheel controls the zoomProperty() by incrementing/decrementing it by the specified amount, zoomIncrementProperty().

The zoom level can be constrained between a min and max by setting minZoomProperty() and maxZoomProperty().

You can also position the lens manually by setting the positionProperty().

The magnifierViewProperty() specifies the portion of the content that is currently zoomed, it is a bound property, managed by the skin, any attempt to set an Image will fail with an exception.

MFXMagnifierPane also includes a color picker tool. The lens has a custom cursor (that can also be hidden) that tells the user which pixel is currently selected. By calling updatePickedColor() the tool will read the selected pixel's color. The color picker tool also shows a label for the picked color (can also be hidden), the color is converted to a String using a function specified by the user, by default uses ColorUtils.rgb(Color). This mechanism allows you to customize the way the picker works. For example if you want the color picker to update the color in real-time (thus also update the picked color label in real-time) you could do something like:

 
      MFXMagnifierPane mp = new MFXMagnifierPane(content);
      mp.magnifierViewProperty().addListener(invalidated -> mp.updatePickedColor());
 
 
Or, if you want to update it only when a mouse event occurs you could do something like:
 
      MFXMagnifierPane mp = new MFXMagnifierPane(content);
      mp.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> {
          if (event.getButton() == MouseButton.PRIMARY) {
              mp.updatePickedColor();
          }
      });
 
 
  • Property Details

  • Constructor Details

    • MFXMagnifierPane

      public MFXMagnifierPane(Node content)
  • Method Details

    • updatePickedColor

      public void updatePickedColor()
      Updates the pickedColorProperty().

      Attempts to read the selected pixel's color by getting the current zoomed portion of the content (if null exits), then uses the image's PixelReader to read the color.

    • createDefaultSkin

      protected Skin<?> createDefaultSkin()
      Overrides:
      createDefaultSkin in class Control
    • getUserAgentStylesheet

      public String getUserAgentStylesheet()
      Overrides:
      getUserAgentStylesheet in class Region
    • getLensSize

      public double getLensSize()
      Gets the value of the property lensSize.
      Property description:
      Specifies the size of the lens.

      The default lens by default is a square, but then it is clipped to be a circle. You can think of this property as the diameter of the circle.

    • lensSizeProperty

      public StyleableDoubleProperty lensSizeProperty()
      Specifies the size of the lens.

      The default lens by default is a square, but then it is clipped to be a circle. You can think of this property as the diameter of the circle.

      See Also:
    • setLensSize

      public void setLensSize(double lensSize)
      Sets the value of the property lensSize.
      Property description:
      Specifies the size of the lens.

      The default lens by default is a square, but then it is clipped to be a circle. You can think of this property as the diameter of the circle.

    • getZoom

      public double getZoom()
      Gets the value of the property zoom.
      Property description:
      Specifies the current zoom level of the lens.
    • zoomProperty

      public StyleableDoubleProperty zoomProperty()
      Specifies the current zoom level of the lens.
      See Also:
    • setZoom

      public void setZoom(double zoom)
      Sets the value of the property zoom.
      Property description:
      Specifies the current zoom level of the lens.
    • getZoomIncrement

      public double getZoomIncrement()
      Gets the value of the property zoomIncrement.
      Property description:
      Specifies the zoom increment/decrement when using the mouse wheel.
    • zoomIncrementProperty

      public StyleableDoubleProperty zoomIncrementProperty()
      Specifies the zoom increment/decrement when using the mouse wheel.
      See Also:
    • setZoomIncrement

      public void setZoomIncrement(double zoomIncrement)
      Sets the value of the property zoomIncrement.
      Property description:
      Specifies the zoom increment/decrement when using the mouse wheel.
    • getMinZoom

      public double getMinZoom()
      Gets the value of the property minZoom.
      Property description:
      Specifies the minimum zoom level allowed.
    • minZoomProperty

      public StyleableDoubleProperty minZoomProperty()
      Specifies the minimum zoom level allowed.
      See Also:
    • setMinZoom

      public void setMinZoom(double minZoom)
      Sets the value of the property minZoom.
      Property description:
      Specifies the minimum zoom level allowed.
    • getMaxZoom

      public double getMaxZoom()
      Gets the value of the property maxZoom.
      Property description:
      Specifies the maximum zoom level allowed.
    • maxZoomProperty

      public StyleableDoubleProperty maxZoomProperty()
      Specifies the maximum zoom level allowed.
      See Also:
    • setMaxZoom

      public void setMaxZoom(double maxZoom)
      Sets the value of the property maxZoom.
      Property description:
      Specifies the maximum zoom level allowed.
    • getPickerPos

      public VPos getPickerPos()
      Gets the value of the property pickerPos.
      Property description:
      Specifies the position of the color picker tool.

      Only two positions are allowed, above the lens (TOP) or below the lens (BOTTOM).

    • pickerPosProperty

      public StyleableObjectProperty<VPos> pickerPosProperty()
      Specifies the position of the color picker tool.

      Only two positions are allowed, above the lens (TOP) or below the lens (BOTTOM).

      See Also:
    • setPickerPos

      public void setPickerPos(VPos pickerPos)
      Sets the value of the property pickerPos.
      Property description:
      Specifies the position of the color picker tool.

      Only two positions are allowed, above the lens (TOP) or below the lens (BOTTOM).

    • getPickerSpacing

      public double getPickerSpacing()
      Gets the value of the property pickerSpacing.
      Property description:
      Specifies the gap between the lens and the color picker tool.
    • pickerSpacingProperty

      public StyleableDoubleProperty pickerSpacingProperty()
      Specifies the gap between the lens and the color picker tool.
      See Also:
    • setPickerSpacing

      public void setPickerSpacing(double pickerSpacing)
      Sets the value of the property pickerSpacing.
      Property description:
      Specifies the gap between the lens and the color picker tool.
    • isHideCursor

      public boolean isHideCursor()
      Gets the value of the property hideCursor.
      Property description:
      Specifies whether to show or hide the custom cursor.

      Node that to use the custom cursor by default the magnifier pane's cursor is set to Cursor.NONE.

    • hideCursorProperty

      public StyleableBooleanProperty hideCursorProperty()
      Specifies whether to show or hide the custom cursor.

      Node that to use the custom cursor by default the magnifier pane's cursor is set to Cursor.NONE.

      See Also:
    • setHideCursor

      public void setHideCursor(boolean hideCursor)
      Sets the value of the property hideCursor.
      Property description:
      Specifies whether to show or hide the custom cursor.

      Node that to use the custom cursor by default the magnifier pane's cursor is set to Cursor.NONE.

    • isShowZoomLabel

      public boolean isShowZoomLabel()
      Gets the value of the property showZoomLabel.
      Property description:
      Specifies whether to show a label that indicates the current zoom level.

      The label is shown only when the zoomProperty() changes, and is hidden after hideZoomLabelAfterProperty().

    • showZoomLabelProperty

      public StyleableBooleanProperty showZoomLabelProperty()
      Specifies whether to show a label that indicates the current zoom level.

      The label is shown only when the zoomProperty() changes, and is hidden after hideZoomLabelAfterProperty().

      See Also:
    • setShowZoomLabel

      public void setShowZoomLabel(boolean showZoomLabel)
      Sets the value of the property showZoomLabel.
      Property description:
      Specifies whether to show a label that indicates the current zoom level.

      The label is shown only when the zoomProperty() changes, and is hidden after hideZoomLabelAfterProperty().

    • getHideZoomLabelAfter

      public double getHideZoomLabelAfter()
      Gets the value of the property hideZoomLabelAfter.
      Property description:
    • hideZoomLabelAfterProperty

      public StyleableDoubleProperty hideZoomLabelAfterProperty()
      See Also:
    • setHideZoomLabelAfter

      public void setHideZoomLabelAfter(double hideZoomLabelAfter)
      Sets the value of the property hideZoomLabelAfter.
      Property description:
    • getClassCssMetaData

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

      protected List<CssMetaData<? extends Styleable,?>> getControlCssMetaData()
      Overrides:
      getControlCssMetaData in class Control
    • getContent

      public Node getContent()
      Gets the value of the property content.
      Property description:
      Specifies the magnifier's content.
    • contentProperty

      public ObjectProperty<Node> contentProperty()
      Specifies the magnifier's content.
      See Also:
    • setContent

      public void setContent(Node content)
      Sets the value of the property content.
      Property description:
      Specifies the magnifier's content.
    • getPosition

      public PositionBean getPosition()
      Gets the value of the property position.
      Property description:
      Specifies the position of the lens.
    • positionProperty

      public ObjectProperty<PositionBean> positionProperty()
      Specifies the position of the lens.
      See Also:
    • setPosition

      public void setPosition(PositionBean position)
      Sets the value of the property position.
      Property description:
      Specifies the position of the lens.
    • getMagnifierView

      public Image getMagnifierView()
      Gets the value of the property magnifierView.
      Property description:
      Specifies the current zoomed portion of the content.
    • magnifierViewProperty

      public ObjectProperty<Image> magnifierViewProperty()
      Specifies the current zoomed portion of the content.
      See Also:
    • getPickedColor

      public Color getPickedColor()
      Gets the value of the property pickedColor.
      Property description:
      Specifies the picked color.

      Not updated automatically, you must call updatePickedColor(), see class documentation for examples.

    • pickedColorProperty

      public ReadOnlyObjectProperty<Color> pickedColorProperty()
      Specifies the picked color.

      Not updated automatically, you must call updatePickedColor(), see class documentation for examples.

      See Also:
    • getColorConverter

      public StringConverter<Color> getColorConverter()
      Gets the value of the property colorConverter.
      Property description:
      Specifies the StringConverter used to convert a Color to a String.
    • colorConverterProperty

      public ObjectProperty<StringConverter<Color>> colorConverterProperty()
      Specifies the StringConverter used to convert a Color to a String.
      See Also:
    • setColorConverter

      public void setColorConverter(StringConverter<Color> colorConverter)
      Sets the value of the property colorConverter.
      Property description:
      Specifies the StringConverter used to convert a Color to a String.