Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public class ZoomContainer

  1. Object
  2. Component
  3. Container
  4. ZoomContainer

ImplementsAnimation, Editable, Iterable<Component>, StyleListener

Shows one component that the user can zoom with a pinch or a double tap and pan with a drag while it is zoomed: a chart, a map drawn as a component, a page of a document.

Label picture = new Label(Image.createImage(400, 300, 0xff336699));
ZoomContainer zoom = new ZoomContainer(picture);
zoom.setMaxScale(4f);
Form f = new Form("Zoom", new BorderLayout());
f.add(BorderLayout.CENTER, zoom);
f.show();

The content is laid out at the container’s size and drawn scaled, so it zooms as a picture of itself: text grows instead of reflowing. While zoomed, the content cannot leave the viewport; there is always content to the edge. At scale 1 with no pan, pointer events reach the content’s own components as usual. While the content is zoomed or panned the container takes every pointer event over its area, so the content shows but does not respond to taps. A port without affine transforms never zooms: the content stays unscaled and keeps its pointer events.

Constructors

public ZoomContainer(Component content)Wraps a component.

Methods

public Component getContent()The component being zoomed.
public float getScale()The current zoom.
public void setScale(float scale)Zooms around the center of the container.
public void zoomAround(float newScale, float fx, float fy)Zooms keeping one point of the container still.
public float getMinScale()The smallest zoom.
public void setMinScale(float minScale)Sets the smallest zoom.
public float getMaxScale()The largest zoom.
public void setMaxScale(float maxScale)Sets the largest zoom.
public void setDoubleTapScale(float doubleTapScale)Sets the zoom a double tap goes to from the minimum.
public float getPanX()How far the content is moved from the left edge.
public float getPanY()How far the content is moved from the top edge.
public Component getComponentAt(int x, int y)Returns a Component at coordinate (x, y).
protected boolean isStickyDrag()Returns true if the component is interested in receiving drag/pointer release events even after the gesture exceeded its boundaries.
public void pointerPressed(int x, int y)If this Component is focused, the pointer pressed event will call this method
public void pointerDragged(int x, int y)If this Component is focused, the pointer dragged event will call this method
public void pointerReleased(int x, int y)If this Component is focused, the pointer released event will call this method
protected boolean pinch(int[] x, int[] y)Invoked by subclasses interested in handling pinch to do their own actions based on the position of the two fingers, if true is returned other drag events will not be broadcast
protected boolean pinch(float s)Invoked by subclasses interested in handling pinch to zoom events, if true is returned other drag events will not be broadcast
protected void pinchReleased(int x, int y)To be implemented by subclasses interested in being notified when a pinch zoom has ended (i.e the user has removed one of their fingers, but is still dragging).
public void layoutContainer()Performs the layout of the container if a layout is necessary
public void paint(Graphics g)This method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API’s to let the PLAF perform the rendering.

Inherited fields

Inherited methods

From Container

encloseIn, encloseIn, initLaf, getUIManager, setUIManager, isSurface, add, addAll, add, add, add, add, add, getLeadComponent, setLeadComponent, getLeadParent, keyPressed, keyReleased, getLayout, setLayout, invalidate, setShouldLayout, setShouldCalcPreferredSize, getLayoutWidth, getLayoutHeight, applyRTL, constrainWidthWhenScrollable, constrainHeightWhenScrollable, addComponent, addComponent, addComponent, addComponent, replaceAndWait, replaceAndWait, replace, replaceAndWait, replace, createReplaceTransition, isEnabled, setEnabled, removeComponent, cancelRepaints, flushReplace, removeAll, revalidateWithAnimationSafety, revalidate, revalidateLater, forceRevalidate, clearClientProperties, paintGlass, isSafeArea, setSafeArea, isSafeAreaRoot, getSafeAreaRoot, setSafeAreaRoot, getComponentCount, getComponentAt, getComponentIndex, contains, scrollComponentToVisible, getClosestComponentTo, getResponderAt, findDropTargetAt, calcPreferredSize, paramString, refreshTheme, isScrollableX, setScrollableX, isScrollableY, setScrollableY, getSideGap, getBottomGap, setScrollable, setCellRenderer, getScrollIncrement, setScrollIncrement, findFirstFocusable, dragInitiated, fireClicked, isSelectableInteraction, getGridPosY, paintComponentBackground, getGridPosX, animateHierarchyAndWait, createAnimateHierarchy, animateHierarchy, animateHierarchyFadeAndWait, createAnimateHierarchyFade, animateHierarchyFade, animateLayoutFadeAndWait, createAnimateLayoutFadeAndWait, animateLayoutFade, createAnimateLayoutFade, animateLayoutAndWait, animateLayout, updateTabIndices, createAnimateLayout, drop, createAnimateMotion, morph, morphAndWait, animateUnlayout, animateUnlayoutAndWait, createAnimateUnlayout, getChildrenAsList, iterator, iterator

From Component

setSameSize, isSetCursorSupported, parsePreferredSize, getDefaultDragTransparency, setDefaultDragTransparency, getEditingDelegate, setEditingDelegate, getCursor, setCursor, showNativeOverlay, hideNativeOverlay, updateNativeOverlay, getNativeOverlay, getAllStyles, getSameWidth, setSameWidth, getSameHeight, setSameHeight, getX, setX, getOuterX, getInnerX, getY, setY, getOuterY, getInnerY, isVisible, setVisible, getClientProperty, stripMarginAndPadding, putClientProperty, getDirtyRegion, setDirtyRegion, isOpaque, setOpaque, getWidth, setWidth, getOuterWidth, getInnerWidth, getHeight, setHeight, getOuterHeight, getInnerHeight, isDragRegion, getDragRegionStatus, getBaseline, getBaselineResizeBehavior, getPreferredSizeStr, setPreferredSizeStr, getPreferredSize, setPreferredSize, getScrollDimension, calcScrollSize, setScrollSize, getPreferredW, setPreferredW, getPreferredH, setPreferredH, getOuterPreferredH, getInnerPreferredH, getOuterPreferredW, getInnerPreferredW, setSize, getUIID, setUIID, setUIIDFinal, setUIID, getInlineAllStyles, setInlineAllStyles, getInlineSelectedStyles, setInlineSelectedStyles, getInlineUnselectedStyles, setInlineUnselectedStyles, getInlineDisabledStyles, setInlineDisabledStyles, getInlinePressedStyles, setInlinePressedStyles, remove, getParent, getOwner, setOwner, isOwnedBy, containsOrOwns, addFocusListener, removeFocusListener, addScrollListener, removeScrollListener, getSelectCommandText, setSelectCommandText, getLabelForComponent, setLabelForComponent, focusGained, focusLost, paintBackgrounds, paintShadows, getAbsoluteX, getAbsoluteY, isInClippingRegion, paintIntersectingComponentsAbove, paintScrollbars, paintScrollbarX, getScrollOpacity, getSelectedRect, paintScrollbarY, paintComponent, paintComponent, getBorder, getScrollable, paintBackground, isScrollable, getScrollX, setScrollX, getScrollY, setScrollY, onScrollX, onScrollY, getDraggedx, getDraggedy, contains, visibleBoundsContains, hasFixedPreferredSize, getBounds, getBounds, getVisibleBounds, getVisibleBounds, isFocusable, setFocusable, onSetFocusable, resetFocusable, getTabIndex, setTabIndex, getPreferredTabIndex, setPreferredTabIndex, isTraversable, setTraversable, handlesInput, setHandlesInput, consumesRawTextInput, hasFocus, setFocus, getComponentForm, getTopLevelContainer, repaint, repaint, longKeyPress, keyRepeated, registerForAnimation, deregisterFromAnimation, getAnimationManager, getScrollAnimationSpeed, setScrollAnimationSpeed, isBlockLead, setBlockLead, isIgnorePointerEvents, setIgnorePointerEvents, isRippleEffect, setRippleEffect, getInlineStylesTheme, setInlineStylesTheme, shouldRenderComponentSelection, isHideInLandscape, setHideInLandscape, createStyleAnimation, isSmoothScrolling, setSmoothScrolling, pointerHover, stopScrollMomentum, pointerHoverReleased, pointerHoverPressed, rotation, isPinchBlocksDragAndDrop, setPinchBlocksDragAndDrop, pointerDragged, getDragImage, getDragTransparency, setDragTransparency, toImage, drawDraggedImage, draggingOver, dragEnter, dragExit, addPullToRefresh, setPullToRefresh, respondsToPointerEvents, pointerPressed, isDragAndDropOperation, pointerReleased, longPointerPress, setVerticalScrollBounds, setHorizontalScrollBounds, isVScrollThumbGrabbed, isHScrollThumbGrabbed, isVScrollThumbHover, isHScrollThumbHover, isTensileDragEnabled, setTensileDragEnabled, getTextSelectionSupport, addDropListener, removeDropListener, addDragOverListener, removeDragOverListener, isNativeDragSource, setNativeDragSource, getNativeDragOperation, setNativeDragOperation, createNativeDragOperation, isNativeDropTarget, setNativeDropTarget, getAcceptedDropMimeTypes, setAcceptedDropMimeTypes, getAcceptedDropActions, setAcceptedDropActions, canAcceptNativeDrop, nativeDragEnter, nativeDragOver, nativeDragExit, nativeDrop, addNativeDropListener, removeNativeDropListener, addNativeDragOverListener, removeNativeDragOverListener, dragFinished, addDragFinishedListener, addStateChangeListener, removeStateChangeListener, addPointerPressedListener, addLongPressListener, addContextMenuListener, removeContextMenuListener, addMouseWheelListener, removeMouseWheelListener, addStylusListener, removeStylusListener, getContextMenuCommands, setContextMenuCommands, mouseWheel, paintRippleOverlay, removePointerPressedListener, removeLongPressListener, removeDragFinishedListener, addPointerReleasedListener, removePointerReleasedListener, addPointerDraggedListener, removePointerDraggedListener, getDragSpeed, getStyle, getPressedStyle, getHoverStyle, setHoverStyle, isHovered, setHovered, setPressedStyle, initUnselectedStyle, initPressedStyle, initDisabledStyle, initSelectedStyle, getUnselectedStyle, setUnselectedStyle, getSelectedStyle, setSelectedStyle, getDisabledStyle, setDisabledStyle, installDefaultPainter, requestFocus, toString, refreshTheme, refreshTheme, isDragActivated, animate, scrollRectToVisible, scrollRectToVisible, paintBorder, paintBorderBackground, isCellRenderer, isScrollVisible, setScrollVisible, setIsScrollVisible, startEditingAsync, stopEditing, isEditing, isEditable, laidOut, deinitialize, initComponent, isInitialized, setInitialized, styleChanged, getNextFocusDown, setNextFocusDown, getNextFocusUp, setNextFocusUp, getNextFocusLeft, setNextFocusLeft, getNextFocusRight, setNextFocusRight, getName, setName, initCustomStyle, deinitializeCustomStyle, isRTL, setRTL, isTactileTouch, isTactileTouch, setTactileTouch, getPropertyNames, getPropertyTypes, getPropertyTypeNames, getPropertyValue, setPropertyValue, paintLockRelease, paintLock, isSnapToGrid, setSnapToGrid, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, blocksSideSwipe, isFlatten, setFlatten, getTensileLength, setTensileLength, isGrabsPointerEvents, setGrabsPointerEvents, getScrollOpacityChangeSpeed, setScrollOpacityChangeSpeed, growShrink, isAlwaysTensile, setAlwaysTensile, isDraggable, setDraggable, isDropTarget, setDropTarget, isChildOf, isHideInPortrait, setHideInPortrait, getBindablePropertyNames, getBindablePropertyTypes, bindProperty, unbindProperty, getBoundPropertyValue, setBoundPropertyValue, getCloudBoundProperty, setCloudBoundProperty, getCloudDestinationProperty, setCloudDestinationProperty, getComponentState, setComponentState, setHidden, isHidden, setHidden, isHidden, announceForAccessibility, getAccessibilityText, setAccessibilityText, getSemantics, getAccessibilityNode, accessibilityChanged, accessibilityChanged, getTooltip, setTooltip

Constructor details

ZoomContainer

public ZoomContainer(Component content)
Wraps a component.

Parameters

content Component
the component to zoom

Method details

getContent

public Component getContent()
The component being zoomed.

Returns

the content

getScale

public float getScale()
The current zoom.

Returns

1 for the content at its laid out size, 2 for twice that

setScale

public void setScale(float scale)
Zooms around the center of the container.

Parameters

scale float
the zoom, clamped to the minimum and maximum

zoomAround

public void zoomAround(float newScale, float fx, float fy)
Zooms keeping one point of the container still.

Parameters

newScale float
the zoom, clamped to the minimum and maximum
fx float
the x of the still point, relative to the container
fy float
the y of the still point, relative to the container

getMinScale

public float getMinScale()
The smallest zoom.

Returns

the minimum scale

setMinScale

public void setMinScale(float minScale)
Sets the smallest zoom.

Parameters

minScale float
a positive scale, 1 by default

getMaxScale

public float getMaxScale()
The largest zoom.

Returns

the maximum scale

setMaxScale

public void setMaxScale(float maxScale)
Sets the largest zoom.

Parameters

maxScale float
the maximum scale, 3 by default

setDoubleTapScale

public void setDoubleTapScale(float doubleTapScale)
Sets the zoom a double tap goes to from the minimum. A double tap while zoomed goes back to the minimum.

Parameters

doubleTapScale float
the zoom, 2 by default

getPanX

public float getPanX()
How far the content is moved from the left edge.

Returns

the horizontal offset in pixels, zero or negative while zoomed in

getPanY

public float getPanY()
How far the content is moved from the top edge.

Returns

the vertical offset in pixels, zero or negative while zoomed in

getComponentAt

public Component getComponentAt(int x, int y)

Returns a Component at coordinate (x, y).

WARNING: This method may return components that are disabled, or invisible, or that do not respond to pointer events. If you are looking for the top-most component that responds to pointer events, you should use int) as it is guaranteed to return a component with Component#respondsToPointerEvents() true; or null if none is found at the coordinate.

Parameters

x int
absolute screen location
y int
absolute screen location

Returns

a Component if found, null otherwise

isStickyDrag

protected boolean isStickyDrag()
Returns true if the component is interested in receiving drag/pointer release events even after the gesture exceeded its boundaries. This is useful for spinners etc. where the motion might continue beyond the size of the component

Returns

false by default

pointerPressed

public void pointerPressed(int x, int y)
If this Component is focused, the pointer pressed event will call this method

Parameters

x int
the pointer x coordinate
y int
the pointer y coordinate

pointerDragged

public void pointerDragged(int x, int y)
If this Component is focused, the pointer dragged event will call this method

Parameters

x int
the pointer x coordinate
y int
the pointer y coordinate

pointerReleased

public void pointerReleased(int x, int y)
If this Component is focused, the pointer released event will call this method

Parameters

x int
the pointer x coordinate
y int
the pointer y coordinate

pinch

protected boolean pinch(int[] x, int[] y)
Invoked by subclasses interested in handling pinch to do their own actions based on the position of the two fingers, if true is returned other drag events will not be broadcast

Parameters

x int[]
the pointer x coordinate
y int[]
the pointer y coordinate

Returns

false by default, true if pinch is handled

pinch

protected boolean pinch(float s)
Invoked by subclasses interested in handling pinch to zoom events, if true is returned other drag events will not be broadcast

Parameters

s float
the scaling of the pinch operation a number larger than 1 means scaling up and smaller than 1 means scaling down. It is recommended that code would threshold the number (so a change between 1.0 and 1.02 shouldn’t necessarily trigger zoom). Notice that this number is relevant to current zoom levels and unaware of them so you should also enforce limits of maximum/minimum zoom levels.

Returns

false by default

pinchReleased

protected void pinchReleased(int x, int y)
To be implemented by subclasses interested in being notified when a pinch zoom has ended (i.e the user has removed one of their fingers, but is still dragging).

Parameters

x int
The x-coordinate of the remaining finger in the drag. (Absolute)
y int
The y-coordinate of the remaining finger in the drag. (Absolute)

layoutContainer

public void layoutContainer()
Performs the layout of the container if a layout is necessary

paint

public void paint(Graphics g)
This method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API’s to let the PLAF perform the rendering.

Parameters

g Graphics
the component graphics