Class ArtView

java.lang.Object
com.codename1.ui.Component
com.codename1.art.ArtView
All Implemented Interfaces:
ArtListener, Animation, Editable, StyleListener

public class ArtView extends Component implements ArtListener

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.

  • Constructor Details

    • ArtView

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

      public ArtView(ArtModel model)

      Creates a view.

      Parameters
      • model: the model to show
  • Method Details

    • getModel

      public ArtModel getModel()
      The model.
    • setModel

      public final void setModel(ArtModel m)

      Shows another model.

      Parameters
      • m: the model
    • initComponent

      protected void initComponent()
      Description copied from class: Component
      Allows subclasses to bind functionality that relies on fully initialized and "ready for action" component state
      Overrides:
      initComponent in class Component
    • deinitialize

      protected void deinitialize()
      Description copied from class: Component
      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.
      Overrides:
      deinitialize in class Component
    • artChanged

      public void artChanged(ArtModel m, boolean contentChanged)
      Description copied from interface: ArtListener

      Called after the change, on the thread that made it.

      Parameters
      • model: the model
      • contentChanged: false when only the selection changed
      Specified by:
      artChanged in interface ArtListener
    • 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: 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: 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: device pixels per document unit
    • setPan

      public void setPan(double x, double y)

      Pans the view.

      Parameters
      • x: where the document's origin is, in pixels from the view's left
      • y: 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: absolute x
    • toDocumentY

      public double toDocumentY(int screenY)

      Converts a screen y to a document y.

      Parameters
      • screenY: 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: document x
      • y: 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: the node
    • calcPreferredSize

      protected Dimension calcPreferredSize()
      Description copied from class: Component

      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

      Overrides:
      calcPreferredSize in class Component
    • paint

      public void paint(Graphics g)
      Description copied from class: Component

      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: the component graphics
      Specified by:
      paint in interface Animation
      Overrides:
      paint in class Component
    • pointerPressed

      public void pointerPressed(int x, int y)
      Description copied from class: Component

      If this Component is focused, the pointer pressed event will call this method

      Parameters
      • x: the pointer x coordinate

      • y: the pointer y coordinate

      Overrides:
      pointerPressed in class Component
    • pointerDragged

      public void pointerDragged(int x, int y)
      Description copied from class: Component

      If this Component is focused, the pointer dragged event will call this method

      Parameters
      • x: the pointer x coordinate

      • y: the pointer y coordinate

      Overrides:
      pointerDragged in class Component
    • pointerReleased

      public void pointerReleased(int x, int y)
      Description copied from class: Component

      If this Component is focused, the pointer released event will call this method

      Parameters
      • x: the pointer x coordinate

      • y: the pointer y coordinate

      Overrides:
      pointerReleased in class Component
    • pinch

      protected boolean pinch(float scale)
      Description copied from class: Component

      Invoked by subclasses interested in handling pinch to zoom events, if true is returned other drag events will not be broadcast

      Parameters
      • scale: @param scale 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

      Overrides:
      pinch in class Component
    • pinchReleased

      protected void pinchReleased(int x, int y)
      Description copied from class: Component

      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: The x-coordinate of the remaining finger in the drag. (Absolute)

      • y: The y-coordinate of the remaining finger in the drag. (Absolute)

      Overrides:
      pinchReleased in class Component