Class PageFigure

All Implemented Interfaces:
Figure, FillableFigure, Grouping, HideableFigure, LockableFigure, Page, ResizableFigure, StrokableFigure, StyleableFigure, TransformableFigure, TransformCachingFigure, PropertyBean, StyleableBean, StyleablePropertyBean, TreeNode<Figure>

Defines a page layout for printing.
Author:
Werner Randelshofer
  • Field Details

  • Constructor Details

    • PageFigure

      public PageFigure()
  • Method Details

    • createNode

      public @NonNull javafx.scene.Node createNode(@NonNull RenderContext ctx)
      Description copied from interface: Figure
      This method is invoked by a RenderContext, when it needs a node to create a JavaFX scene graph for a figure.

      A typical implementation should look like this:

      
       public Node createNode(@NonNull RenderContext v) {
       return new ...desired subclass of Node...();
       }
       

      A figure may be rendered with multiple RenderContexts simultaneously. Each RenderContext uses this method to instantiate a JavaFX node for the figure and associate it to the figure.

      This method must create a new instance because returning an already existing instance may cause undesired side effects on other RenderContexts.

      Note that by convention this method may only be invoked by a RenderContext object.

      Specified by:
      createNode in interface Figure
      Parameters:
      ctx - the renderer which will use the node
      Returns:
      the newly created node
    • createPageNode

      public @NonNull javafx.scene.Node createPageNode(int internalPageNumber)
      Description copied from interface: Page
      Returns a node which will be placed on the paper.
      Specified by:
      createPageNode in interface Page
      Parameters:
      internalPageNumber - the internal page number
      Returns:
      a new node
    • getLayoutBounds

      public @NonNull javafx.geometry.Bounds getLayoutBounds()
      Description copied from interface: Figure
      The bounds that should be used for transformations of this figure.

      The bounds are given in the untransformed local coordinate space of the figure.

      This method may use caching and return incorrect results if the cache is stale. Invoke Figure.layout(org.jhotdraw8.draw.render.RenderContext) if you are not sure that the cache is valid.

      Specified by:
      getLayoutBounds in interface Figure
      Overrides:
      getLayoutBounds in class AbstractCompositeFigure
      Returns:
      the local bounds
    • getCssLayoutBounds

      public @NonNull CssRectangle2D getCssLayoutBounds()
      Specified by:
      getCssLayoutBounds in interface Figure
      Overrides:
      getCssLayoutBounds in class AbstractCompositeFigure
    • getNumberOfSubPages

      public int getNumberOfSubPages()
      Description copied from interface: Page
      Returns the number of sub-pages defined by this page.
      Specified by:
      getNumberOfSubPages in interface Page
      Returns:
      number of internal pages
    • getPageBounds

      public @NonNull javafx.geometry.Bounds getPageBounds(int internalPageNumber)
      Description copied from interface: Page
      Returns the bounds for the page content.
      Specified by:
      getPageBounds in interface Page
      Parameters:
      internalPageNumber - the internal page number
      Returns:
      the clipping region
    • getPageClip

      public @NonNull javafx.scene.shape.Shape getPageClip(int internalPageNumber)
      Description copied from interface: Page
      Returns the clip for the page content.
      Specified by:
      getPageClip in interface Page
      Parameters:
      internalPageNumber - the internal page number
      Returns:
      the clipping region
    • getPaperSize

      public CssDimension2D getPaperSize()
      Description copied from interface: Page
      Returns the paper size.
      Specified by:
      getPaperSize in interface Page
      Returns:
      the page size
    • getPageTransform

      public @NonNull javafx.scene.transform.Transform getPageTransform(int internalPageNumber)
      Description copied from interface: Page
      Returns a transform which will position the drawing contents inside the clip on the page.
      Specified by:
      getPageTransform in interface Page
      Parameters:
      internalPageNumber - the internal page number
      Returns:
      the transform
    • getTypeSelector

      public @NonNull String getTypeSelector()
      Specified by:
      getTypeSelector in interface StyleableBean
    • isLayoutable

      public boolean isLayoutable()
      Description copied from interface: Figure
      Whether the layout method of this figure does anything.

      The default implementation returns false.

      Specified by:
      isLayoutable in interface Figure
      Returns:
      true if the layout method is not empty.
    • isSuitableChild

      public boolean isSuitableChild(@NonNull Figure newChild)
      Description copied from interface: Figure
      This method returns whether the provided figure is a suitable child for this figure.
      Specified by:
      isSuitableChild in interface Figure
      Specified by:
      isSuitableChild in interface TreeNode<Figure>
      Parameters:
      newChild - The new child figure.
      Returns:
      true if newChild is an acceptable child
    • layout

      public void layout(@NonNull RenderContext ctx)
      Description copied from interface: Figure
      Updates the layout of this figure, based on the layout of its children and the layout of observed layout subjects.

      If the layout of this figure depends on the layout of other figures, then calling layout on this figure will only result in the correct result, if layout of the other figures has been performed first.

      A figure does not keep track of changes that require layout updates. Use DrawingModel to manage layout updates.

      The default implementation is empty.

      To layout a drawing use Drawing.layoutAll(RenderContext).

      Specified by:
      layout in interface Figure
      Parameters:
      ctx - the render context (optional)
    • reshapeInLocal

      public void reshapeInLocal(@NonNull CssSize x, @NonNull CssSize y, @NonNull CssSize width, @NonNull CssSize height)
      Description copied from interface: Figure
      Attempts to change the local bounds of the figure.

      See {#link #reshapeInLocal(Transform)} for a description of this method.

      This method takes parameters as CssSizes. This can be used to avoid rounding errors when the figure is reshaped in non-pixel units.

      This method can forward a call to Figure.reshapeInLocal(Transform) using the following code:

      
       void reshapeInLocal(@NonNull CssSize x, @NonNull CssSize y, @NonNull CssSize width, @NonNull CssSize height) {
         Transform tx = Transforms.createReshapeTransform(getCssBoundsInLocal(), x, y, width, height);
         reshapeInLocal(tx);
       }
       
      Specified by:
      reshapeInLocal in interface Figure
      Parameters:
      x - desired x-position in parent coordinates
      y - desired y-position in parent coordinates
      width - desired width in parent coordinates, may be negative
      height - desired height in parent coordinates, may be negative
    • reshapeInLocal

      public void reshapeInLocal(@NonNull javafx.scene.transform.Transform transform)
      Description copied from interface: Figure
      Attempts to change the local bounds of the figure.

      The figure may choose to only partially change its local bounds.

      Specified by:
      reshapeInLocal in interface Figure
      Specified by:
      reshapeInLocal in interface TransformableFigure
      Parameters:
      transform - the desired transformation in local coordinates
    • updateNode

      public void updateNode(@NonNull RenderContext ctx, @NonNull javafx.scene.Node node)
      Description copied from interface: Figure
      This method is invoked by a RenderContext, when it needs to update the node which represents the scene graph in the figure.

      A figure which is composed from child figures, must addChild the nodes of its getChildren to its node. This ensures that coordinate space transformations of the composed figure are properly propagated to its getChildren.

       public void updateNode(@NonNull RenderContext rc, Node n) {
           ObservableList<Node> group = ((Group) n).getChildren();
       group.clear();
       for (Figure child : children()) {
       group.addChild(rc.getNode(child));
       }
       

      A figure may be shown in multiple RenderContexts. Each RenderContext uses this method to update the a JavaFX node for the figure.

      Note that the figure must retrieve the JavaFX node from other figures from the render context by invoking rc.getNode(child) rather than creating new nodes using child.createNode(rc). This convention allows to implement a cache in the render context for the Java FX node. Also, render contexts like a drawing view need to associate input events on Java FX nodes to the corresponding figure.

      This figure does not keep track of changes that require node updates. DrawingModel to manage node updates.

      Specified by:
      updateNode in interface Figure
      Parameters:
      ctx - the render context
      node - the node which was created with Figure.createNode(org.jhotdraw8.draw.render.RenderContext)