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

public class ArtView

  1. Object
  2. Component
  3. ArtView

ImplementsAnimation, ArtListener, Editable, StyleListener

Shows an ArtModel’s document, with panning, pinch zoom, hit testing and the selection drawn over it.

Dragging pans the document unless a PointerHandler is set; ArtEditor sets one per tool. The rendered document is cached and rendered again only when the model, the zoom, the pan or the size changes.

Nested types

interface ArtView.PointerHandlerReceives pointer events in document coordinates.

Constructors

public ArtView()Creates a view of an empty document.
public ArtView(ArtModel model)Creates a view.

Methods

public ArtModel getModel()The model.
public final void setModel(ArtModel m)Shows another model.
protected void initComponent()Allows subclasses to bind functionality that relies on fully initialized and “ready for action” component state
protected void deinitialize()Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy.
public void artChanged(ArtModel m, boolean contentChanged)Called after the change, on the thread that made it.
public void invalidateCache()Renders the document again on the next paint.
public ArtView.PointerHandler getPointerHandler()The pointer handler, or null when dragging pans.
public void setPointerHandler(ArtView.PointerHandler h)Sets the pointer handler.
public void setShowSelection(boolean show)True draws an outline and handles around the selected nodes.
public double getZoom()The zoom: device pixels per document unit.
public void setZoom(double z)Sets the zoom, keeping the middle of the view where it is.
public void setPan(double x, double y)Pans the view.
public void fit()Zooms and centers so the whole document is visible.
public Matrix getViewTransform()The transform from document coordinates to the view’s pixels.
public double toDocumentX(int screenX)Converts a screen x (as pointer events report it) to a document x.
public double toDocumentY(int screenY)Converts a screen y to a document y.
public ArtNode nodeAt(double x, double y)The topmost visible, unlocked node under a document point, searching into groups; null when there is none.
public double[] viewBounds(ArtNode n)The bounds of a node in view pixels, as x, y, w, h, or null.
protected Dimension calcPreferredSize()Calculates the preferred size based on component content.
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.
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(float scale)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).

Inherited fields

Inherited methods

From Component

setSameSize, isSetCursorSupported, parsePreferredSize, getDefaultDragTransparency, setDefaultDragTransparency, getEditingDelegate, setEditingDelegate, getCursor, setCursor, showNativeOverlay, hideNativeOverlay, updateNativeOverlay, getNativeOverlay, getAllStyles, getSameWidth, setSameWidth, getSameHeight, setSameHeight, initLaf, getUIManager, getX, setX, getOuterX, getInnerX, getY, setY, getOuterY, getInnerY, isVisible, setVisible, getClientProperty, stripMarginAndPadding, clearClientProperties, 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, fireClicked, isSelectableInteraction, getSelectCommandText, setSelectCommandText, getLabelForComponent, setLabelForComponent, focusGained, focusLost, paintBackgrounds, paintShadows, getAbsoluteX, getAbsoluteY, isInClippingRegion, paintIntersectingComponentsAbove, paintScrollbars, paintScrollbarX, getScrollOpacity, getSelectedRect, paintScrollbarY, paintComponent, paintComponent, getBorder, getScrollable, paintBackground, isScrollable, isScrollableX, isScrollableY, getScrollX, setScrollX, getScrollY, setScrollY, onScrollX, onScrollY, getDraggedx, getDraggedy, getBottomGap, getSideGap, contains, visibleBoundsContains, hasFixedPreferredSize, getBounds, getBounds, getVisibleBounds, getVisibleBounds, isFocusable, setFocusable, onSetFocusable, resetFocusable, getTabIndex, setTabIndex, getPreferredTabIndex, setPreferredTabIndex, isTraversable, setTraversable, setShouldCalcPreferredSize, handlesInput, setHandlesInput, consumesRawTextInput, hasFocus, setFocus, getComponentForm, getTopLevelContainer, repaint, repaint, longKeyPress, keyPressed, keyReleased, keyRepeated, registerForAnimation, deregisterFromAnimation, getAnimationManager, getScrollAnimationSpeed, setScrollAnimationSpeed, isBlockLead, setBlockLead, isIgnorePointerEvents, setIgnorePointerEvents, isRippleEffect, setRippleEffect, getInlineStylesTheme, setInlineStylesTheme, shouldRenderComponentSelection, isHideInLandscape, setHideInLandscape, createStyleAnimation, isSmoothScrolling, setSmoothScrolling, pointerHover, stopScrollMomentum, pointerHoverReleased, pointerHoverPressed, pinch, rotation, isPinchBlocksDragAndDrop, setPinchBlocksDragAndDrop, pointerDragged, getDragImage, getDragTransparency, setDragTransparency, toImage, dragInitiated, drawDraggedImage, draggingOver, dragEnter, dragExit, drop, addPullToRefresh, setPullToRefresh, respondsToPointerEvents, isStickyDrag, 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, paramString, refreshTheme, refreshTheme, refreshTheme, isDragActivated, getGridPosY, getGridPosX, animate, scrollRectToVisible, scrollRectToVisible, paintBorder, paintBorderBackground, isCellRenderer, setCellRenderer, isScrollVisible, setScrollVisible, setIsScrollVisible, startEditingAsync, stopEditing, isEditing, isEditable, laidOut, isInitialized, setInitialized, styleChanged, getNextFocusDown, setNextFocusDown, getNextFocusUp, setNextFocusUp, getNextFocusLeft, setNextFocusLeft, getNextFocusRight, setNextFocusRight, isEnabled, setEnabled, 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, cancelRepaints, 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

ArtView

public ArtView()
Creates a view of an empty document.

ArtView

public ArtView(ArtModel model)
Creates a view.

Parameters

model ArtModel
the model to show

Method details

getModel

public ArtModel getModel()
The model.

setModel

public final void setModel(ArtModel m)
Shows another model.

Parameters

m ArtModel
the model

initComponent

protected void initComponent()
Allows subclasses to bind functionality that relies on fully initialized and “ready for action” component state

deinitialize

protected void deinitialize()
Invoked to indicate that the component initialization is being reversed since the component was detached from the container hierarchy. This allows the component to deregister animators and cleanup after itself. This method is the opposite of the initComponent() method.

artChanged

public void artChanged(ArtModel m, boolean contentChanged)
Called after the change, on the thread that made it.

Parameters

m ArtModel
the model
contentChanged boolean
false when only the selection changed

invalidateCache

public void invalidateCache()
Renders the document again on the next paint.

getPointerHandler

public ArtView.PointerHandler getPointerHandler()
The pointer handler, or null when dragging pans.

setPointerHandler

public void setPointerHandler(ArtView.PointerHandler h)
Sets the pointer handler.

Parameters

h ArtView.PointerHandler
the handler, or null to pan on drag

setShowSelection

public void setShowSelection(boolean show)
True draws an outline and handles around the selected nodes.

Parameters

show boolean
true to draw the selection

getZoom

public double getZoom()
The zoom: device pixels per document unit.

setZoom

public void setZoom(double z)
Sets the zoom, keeping the middle of the view where it is.

Parameters

z double
device pixels per document unit

setPan

public void setPan(double x, double y)
Pans the view.

Parameters

x double
where the document’s origin is, in pixels from the view’s left
y double
in pixels from the view’s top

fit

public void fit()
Zooms and centers so the whole document is visible.

getViewTransform

public Matrix getViewTransform()
The transform from document coordinates to the view’s pixels.

toDocumentX

public double toDocumentX(int screenX)
Converts a screen x (as pointer events report it) to a document x.

Parameters

screenX int
absolute x

toDocumentY

public double toDocumentY(int screenY)
Converts a screen y to a document y.

Parameters

screenY int
absolute y

nodeAt

public ArtNode nodeAt(double x, double y)
The topmost visible, unlocked node under a document point, searching into groups; null when there is none.

Parameters

x double
document x
y double
document y

viewBounds

public double[] viewBounds(ArtNode n)
The bounds of a node in view pixels, as x, y, w, h, or null.

Parameters

n ArtNode
the node

calcPreferredSize

protected Dimension calcPreferredSize()
Calculates the preferred size based on component content. This method is invoked lazily by getPreferred size.

Returns

the calculated preferred size based on component content

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

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(float scale)
Invoked by subclasses interested in handling pinch to zoom events, if true is returned other drag events will not be broadcast

Parameters

scale 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)