Package org.zkoss.zkmax.zul

## Class Cropper

- java.lang.Object
- - org.zkoss.zk.ui.AbstractComponent
  - - org.zkoss.zk.ui.HtmlBasedComponent
    - - org.zkoss.zkmax.zul.Cropper

- All Implemented Interfaces:
    `java.io.Serializable`, `java.lang.Cloneable`, `Component`, `Scope`, `ComponentCtrl`

      public class Cropper
      extends HtmlBasedComponent

  An image cropper that can select a range to get the cropped result.
  Since:
    8.6.0
  Author:
    wenninghsu
  See Also:
    Serialized Form

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class | Description
    --- | --- | ---
    `protected class` | `Cropper.ExtraCtrl` |

    - ### Nested classes/interfaces inherited from class org.zkoss.zk.ui.AbstractComponent

      `AbstractComponent.Children, AbstractComponent.ForwardInfo, AbstractComponent.TargetInfo`

  - ### Field Summary

    - ### Fields inherited from class org.zkoss.zk.ui.HtmlBasedComponent

      `_zclass`

    - ### Fields inherited from interface org.zkoss.zk.ui.Component

      `APPLICATION_SCOPE, COMPONENT_SCOPE, DESKTOP_SCOPE, PAGE_SCOPE, REQUEST_SCOPE, SESSION_SCOPE, SPACE_SCOPE`

    - ### Fields inherited from interface org.zkoss.zk.ui.sys.ComponentCtrl

      `AFTER_CHILD_ADDED, AFTER_CHILD_REMOVED, AFTER_CLONED, AFTER_PAGE_ATTACHED, AFTER_PAGE_DETACHED, AFTER_PARENT_CHANGED, CE_BUSY_IGNORE, CE_DUPLICATE_IGNORE, CE_IMPORTANT, CE_NON_DEFERRABLE, CE_REPEAT_IGNORE`

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `Cropper()` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `void` | `cancel()` | To cancel the selected area.
    `void` | `crop()` | Request cropper JavaScript widget to crop the selected area and send it back to the server.
    `double` | `getAspectRatio()` | Returns the aspect ratio of the cropped area.
    `Image` | `getContent()` | Returns the content set by `setContent(org.zkoss.image.Image)`.
    `java.lang.String` | `getCroppedFormat()` | Get the cropped image format, e.g., image/png, image/jpeg.
    `AImage` | `getCroppedImage()` | Returns the cropped image as an `AImage`.
    `java.lang.String` | `getCrossOrigin()` | Returns the crossOrigin of the img of this cropper, could be "anonymous", "use-credentials" or null.
    `java.lang.Object` | `getExtraCtrl()` | Returns the client control for this component.
    `int` | `getH()` | Returns the height of the crop area in pixel.
    `int` | `getMaxHeight()` | Returns the maximum height of the selected crop area.
    `int` | `getMaxWidth()` | Returns the maximum width of the selected crop area.
    `int` | `getMinHeight()` | Returns the minimum height of the selected crop area.
    `int` | `getMinWidth()` | Returns the minimum width of the selected crop area.
    `java.lang.String` | `getSrc()` | Returns the source URI of the image.
    `int` | `getW()` | Returns the width of the crop area in pixel.
    `int` | `getX()` | Returns the left position of the crop area relates to the left edge of the child image in pixel.
    `int` | `getY()` | Returns the top position of the crop area relates to the top edge of the child image in pixel.
    `protected boolean` | `isChildable()` | Not childable.
    `boolean` | `isInstant()` | Returns whether to send back onChange event immediately while the user is resizing the selected area.
    `boolean` | `isToolbarVisible()` | Returns whether the toolbar is visible.
    `void` | `move​(int deltaX, int deltaY)` | Moves the crop area according to the delta x and y.
    `void` | `moveTo​(int x, int y)` | Moves the crop area to the specified left and top related position.
    `protected void` | `renderProperties​(ContentRenderer renderer)` | Renders the content of this component, excluding the enclosing tags and children.
    `void` | `resize​(int deltaW, int deltaH)` | Resize the crop area according to the delta width and height in pixel.
    `void` | `resizeTo​(int width, int height)` | Resize the crop area to the specified width and height in pixel.
    `void` | `service​(AuRequest request, boolean everError)` | Processes an AU request.
    `void` | `setAspectRatio​(double aspectRatio)` | Sets the aspect ratio of the selected area.
    `void` | `setContent​(java.awt.image.RenderedImage image)` | Sets the content directly with the rendered image.
    `void` | `setContent​(Image image)` | Sets the content directly.
    `void` | `setCroppedFormat​(java.lang.String croppedFormat)` | Set the cropped image format, e.g., image/png, image/jpeg.
    `void` | `setCrossOrigin​(java.lang.String crossOrigin)` | Could be "anonymous" or "use-credentials", an invalid string and an empty string will be handled as the "anonymous".
    `void` | `setH​(int h)` | Sets the height of the crop area in pixel.
    `void` | `setInstant​(boolean instant)` | Sets whether to send back onChange event as soon as possible while the user is resizing the selected area.
    `void` | `setMaxHeight​(int maxHeight)` | Sets the maximum height of the selected crop area.
    `void` | `setMaxWidth​(int maxWidth)` | Sets the maximum width of the selected crop area.
    `void` | `setMinHeight​(int minHeight)` | Sets the minimum height of the selected crop area.
    `void` | `setMinWidth​(int minWidth)` | Sets the minimum width of the selected crop area.
    `void` | `setSrc​(java.lang.String src)` | Sets the source URI of the image.
    `void` | `setToolbarVisible​(boolean toolbarVisible)` | Sets the visibility of the cropper toolbar.
    `void` | `setW​(int w)` | Sets the width of the crop area in pixel.
    `void` | `setX​(int x)` | Sets the left position of the crop area relates to the left edge of the child image in pixel.
    `void` | `setY​(int y)` | Sets the top position of the crop area relates to the top edge of the child image in pixel.

    - ### Methods inherited from class org.zkoss.zk.ui.HtmlBasedComponent

      `addSclass, clone, evalCSSFlex, focus, getAction, getClientAction, getDraggable, getDroppable, getHeight, getHflex, getLeft, getPropertyAccess, getRenderdefer, getSclass, getStyle, getTabindex, getTabindexInteger, getTooltiptext, getTop, getVflex, getWidth, getZclass, getZindex, getZIndex, removeSclass, removeSclass, setAction, setClass, setClientAction, setDraggable, setDroppable, setFocus, setHeight, setHeight0, setHeightDirectly, setHflex, setHflex0, setHflexDirectly, setLeft, setLeftDirectly, setRenderdefer, setSclass, setStyle, setTabindex, setTabindex, setTooltiptext, setTop, setTopDirectly, setVflex, setVflex0, setVflexDirectly, setWidth, setWidth0, setWidthDirectly, setZclass, setZindex, setZIndex, setZIndexDirectly`

    - ### Methods inherited from class org.zkoss.zk.ui.AbstractComponent

      `addAnnotation, addCallback, addClientEvent, addEventHandler, addEventListener, addEventListener, addForward, addForward, addForward, addForward, addMoved, addRedrawCallback, addScopeListener, addShadowRoot, addShadowRootBefore, addSharedEventHandlerMap, appendChild, applyProperties, beforeChildAdded, beforeChildRemoved, beforeParentChanged, destroyIndexCacheMap, detach, didActivate, didActivate, didDeserialize, didDeserialize, disableBindingAnnotation, disableClientUpdate, disableHostChanged, enableBindingAnnotation, enableHostChanged, getAnnotatedProperties, getAnnotatedPropertiesBy, getAnnotation, getAnnotations, getAnnotations, getAttribute, getAttribute, getAttribute, getAttributeOrFellow, getAttributes, getAttributes, getAuService, getAutag, getCallback, getChildren, getClientAttribute, getClientDataAttribute, getClientEvents, getDefaultMold, getDefinition, getDesktop, getEventHandler, getEventHandlerNames, getEventListenerMap, getEventListeners, getFellow, getFellow, getFellowIfAny, getFellowIfAny, getFellows, getFirstChild, getForwards, getId, getIndexCacheMap, getLastChild, getMold, getNextSibling, getPage, getParent, getPreviousSibling, getRedrawCallback, getRoot, getShadowFellowIfAny, getShadowRoots, getShadowVariable, getShadowVariable, getShadowVariable0, getSpaceOwner, getSpecialRendererOutput, getStubonly, getSubBindingAnnotationCount, getTemplate, getTemplateNames, getUuid, getWidgetAttributeNames, getWidgetClass, getWidgetListener, getWidgetListenerNames, getWidgetOverride, getWidgetOverrideNames, hasAttribute, hasAttribute, hasAttribute, hasAttributeOrFellow, hasBindingAnnotation, hasFellow, hasFellow, hasSubBindingAnnotation, initIndexCacheMap, insertBefore, invalidate, isDisabledHostChanged, isInitialized, isInvalidated, isListenerAvailable, isVisible, onChildAdded, onChildRemoved, onPageAttached, onPageDetached, onParentChanged, onWrongValue, query, queryAll, redraw, redrawChildren, removeAttribute, removeAttribute, removeAttribute, removeCallback, removeChild, removeEventListener, removeForward, removeForward, removeRedrawCallback, removeScopeListener, removeShadowRoot, render, render, render, renderPropertiesOnly, replace, response, response, response, service, sessionDidActivate, sessionWillPassivate, setAttribute, setAttribute, setAttribute, setAuService, setAutag, setClientAttribute, setClientDataAttribute, setDefinition, setDefinition, setId, setMold, setPage, setPageBefore, setParent, setStubonly, setStubonly, setSubBindingAnnotationCount, setTemplate, setVisible, setVisibleDirectly, setWidgetClass, setWidgetListener, setWidgetOverride, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdate, smartUpdateWidgetListener, smartUpdateWidgetOverride, toString, updateByClient, updateSubBindingAnnotationCount, willPassivate, willPassivate, willSerialize, willSerialize`

    - ### Methods inherited from class java.lang.Object

      `equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### Cropper

          public Cropper()

  - ### Method Detail

    - #### getAspectRatio

          public double getAspectRatio()

      Returns the aspect ratio of the cropped area.

      Default: 0 Means the ratio has no restrict

      Returns:
        double the ratio of the cropped area

    - #### setAspectRatio

          public void setAspectRatio​(double aspectRatio)

      Sets the aspect ratio of the selected area.

      Default: 0. Means the ratio has no restrict

      Parameters:
        `aspectRatio` - the ratio of the selected area

    - #### getMinWidth

          public int getMinWidth()

      Returns the minimum width of the selected crop area.
      Returns:
        int as the minimum width

    - #### setMinWidth

          public void setMinWidth​(int minWidth)

      Sets the minimum width of the selected crop area.
      Parameters:
        `minWidth` - the minimum width of the selected crop area

    - #### getMinHeight

          public int getMinHeight()

      Returns the minimum height of the selected crop area.
      Returns:
        int as the minimum height of the selected crop area

    - #### setMinHeight

          public void setMinHeight​(int minHeight)

      Sets the minimum height of the selected crop area.
      Parameters:
        `minHeight` - the minimum height of the selected crop area

    - #### getMaxWidth

          public int getMaxWidth()

      Returns the maximum width of the selected crop area.
      Returns:
        int as the maximum width of the selected crop area

    - #### setMaxWidth

          public void setMaxWidth​(int maxWidth)

      Sets the maximum width of the selected crop area.
      Parameters:
        `maxWidth` - the maximum width of the selected crop area

    - #### getMaxHeight

          public int getMaxHeight()

      Returns the maximum height of the selected crop area.
      Returns:
        int as the maximum height of the selected crop area

    - #### setMaxHeight

          public void setMaxHeight​(int maxHeight)

      Sets the maximum height of the selected crop area.
      Parameters:
        `maxHeight` - the maximum height of the selected crop area

    - #### getX

          public int getX()

      Returns the left position of the crop area relates to the left edge of the child image in pixel.
      Returns:
        int as the left position.

    - #### setX

          public void setX​(int x)

      Sets the left position of the crop area relates to the left edge of the child image in pixel.
      Parameters:
        `x` - as the left related pixel

    - #### getY

          public int getY()

      Returns the top position of the crop area relates to the top edge of the child image in pixel.
      Returns:
        int as the top position.

    - #### setY

          public void setY​(int y)

      Sets the top position of the crop area relates to the top edge of the child image in pixel.
      Parameters:
        `y` - as the top related pixel

    - #### getW

          public int getW()

      Returns the width of the crop area in pixel.
      Returns:
        int as the width of the crop area.

    - #### setW

          public void setW​(int w)

      Sets the width of the crop area in pixel.
      Parameters:
        `w` - as the width of the crop area

    - #### getH

          public int getH()

      Returns the height of the crop area in pixel.
      Returns:
        int as the height of the crop area

    - #### setH

          public void setH​(int h)

      Sets the height of the crop area in pixel.
      Parameters:
        `h` - as the height of the crop area

    - #### getCroppedImage

          public AImage getCroppedImage()

      Returns the cropped image as an `AImage`.
      Returns:
        the `AImage` cropped image

    - #### isToolbarVisible

          public boolean isToolbarVisible()

      Returns whether the toolbar is visible.
      Returns:
        true if the toolbar is visible

    - #### setToolbarVisible

          public void setToolbarVisible​(boolean toolbarVisible)

      Sets the visibility of the cropper toolbar.
      Parameters:
        `toolbarVisible` - true or false to set the visibility of toolbar

    - #### getCroppedFormat

          public java.lang.String getCroppedFormat()

      Get the cropped image format, e.g., image/png, image/jpeg. If the requested type is invalid or unspecified, it will use image/png.

      Default: `"image/png"`.

      Returns:
        cropped image format

    - #### setCroppedFormat

          public void setCroppedFormat​(java.lang.String croppedFormat)

      Set the cropped image format, e.g., image/png, image/jpeg. If the requested type is invalid or unspecified, it will use image/png.
      Parameters:
        `croppedFormat` - cropped image format

    - #### getSrc

          public java.lang.String getSrc()

      Returns the source URI of the image.

      Default: null.

    - #### setSrc

          public void setSrc​(java.lang.String src)

      Sets the source URI of the image.

      Calling this method implies setContent(null). In other words, the last invocation of `setSrc(java.lang.String)` overrides the previous `setContent(org.zkoss.image.Image)`, if any.

      Parameters:
        `src` - the URI of the image source
      See Also:
        `setContent(org.zkoss.image.Image)`, `setContent(RenderedImage)`

    - #### setContent

          public void setContent​(Image image)

      Sets the content directly.

      Default: null.

      Calling this method implies setSrc(null). In other words, the last invocation of `setContent(org.zkoss.image.Image)` overrides the previous `setSrc(java.lang.String)`, if any.

      Parameters:
        `image` - the image to display.
      See Also:
        `setSrc(java.lang.String)`

    - #### setContent

          public void setContent​(java.awt.image.RenderedImage image)

      Sets the content directly with the rendered image. It actually encodes the rendered image to an PNG image (`Image`) with `Images.encode(java.lang.String, java.awt.image.RenderedImage, float, boolean)`, and then invoke `setContent(org.zkoss.image.Image)`.

    - #### getContent

          public Image getContent()

      Returns the content set by `setContent(org.zkoss.image.Image)`.

      Note: it won't fetch what is set thru by `setSrc(java.lang.String)`. It simply returns what is passed to `setContent(org.zkoss.image.Image)`.

      Since:
        10.0.0

    - #### getCrossOrigin

          public java.lang.String getCrossOrigin()

      Returns the crossOrigin of the img of this cropper, could be "anonymous", "use-credentials" or null.

      Default: null.

      Returns:
        the crossOrigin of the img of this cropper.

    - #### setCrossOrigin

          public void setCrossOrigin​(java.lang.String crossOrigin)

      Could be "anonymous" or "use-credentials", an invalid string and an empty string will be handled as the "anonymous". Notice that this attribute refers to the corresponding attribute of the HTML5 specification. Hence, it would still be rendered to client-side as a DOM attribute even if the browser doesn’t support it.

      Parameters:
        `crossOrigin` - the crossOrigin of the img of this cropper.

    - #### isInstant

          public boolean isInstant()

      Returns whether to send back onChange event immediately while the user is resizing the selected area.
      Returns:
        boolean

    - #### setInstant

          public void setInstant​(boolean instant)

      Sets whether to send back onChange event as soon as possible while the user is resizing the selected area. Default: false.
      Parameters:
        `instant` -

    - #### resize

          public void resize​(int deltaW,
                             int deltaH)

      Resize the crop area according to the delta width and height in pixel. Positive means larger, negative means smaller.
      Parameters:
        `deltaW` - the delta width to resize
        `deltaH` - the delta height to resize

    - #### resizeTo

          public void resizeTo​(int width,
                               int height)

      Resize the crop area to the specified width and height in pixel.
      Parameters:
        `width` - the width of the crop area
        `height` - the height of the crop area

    - #### move

          public void move​(int deltaX,
                           int deltaY)

      Moves the crop area according to the delta x and y. Positive for x means move right, negative means move left. Positive for y means move down, negative means move top.
      Parameters:
        `deltaX` - the x difference to move
        `deltaY` - the y difference to move

    - #### moveTo

          public void moveTo​(int x,
                             int y)

      Moves the crop area to the specified left and top related position.
      Parameters:
        `x` - the x position to move to
        `y` - the y position to move to

    - #### crop

          public void crop()

      Request cropper JavaScript widget to crop the selected area and send it back to the server. You can't call `getCroppedImage()` immediately in the same event listener. You need to complete the listener calling, let the response back to the browser to crop the image. It will fire an onCrop event to invoke onCrop event listener, then you can get cropped image in the onCrop listener.

    - #### cancel

          public void cancel()

      To cancel the selected area.

    - #### isChildable

          protected boolean isChildable()

      Not childable.
      Overrides:
        `isChildable` in class `AbstractComponent`

    - #### renderProperties

          protected void renderProperties​(ContentRenderer renderer)
                                   throws java.io.IOException

      Description copied from class: `HtmlBasedComponent`
      Renders the content of this component, excluding the enclosing tags and children.

      See also ZK Client-side Reference: Property Rendering

      Overrides:
        `renderProperties` in class `HtmlBasedComponent`
      Throws:
        `java.io.IOException`

    - #### service

          public void service​(AuRequest request,
                              boolean everError)

      Description copied from class: `HtmlBasedComponent`
      Processes an AU request.

      Default: it handles onClick, onDoubleClick, onRightClick onMove, onSize, onZIndex.

      Specified by:
        `service` in interface `ComponentCtrl`
      Overrides:
        `service` in class `HtmlBasedComponent`
        `everError` - whether any error ever occurred before processing this request.
      See Also:
        `AbstractComponent.setAuService(org.zkoss.zk.au.AuService)`

    - #### getExtraCtrl

          public java.lang.Object getExtraCtrl()

      Description copied from class: `HtmlBasedComponent`
      Returns the client control for this component. It is used only by component developers.

      Default: creates an instance of `HtmlBasedComponent.ExtraCtrl`.

      Specified by:
        `getExtraCtrl` in interface `ComponentCtrl`
      Overrides:
        `getExtraCtrl` in class `HtmlBasedComponent`
      Returns:
        null if no special handling required. If the component requires some special controls, it could return an object that implements one or several interfaces in the org.zkoss.zk.ui.ext.render package. For example, `Cropper`.
      See Also:
        `ComponentCtrl.getExtraCtrl()`