Class AbstractLabelFigure

All Implemented Interfaces:
ConnectableFigure, Figure, FillableFigure, PaddableFigure, PathIterableFigure, ShapeableFigure, StrokableFigure, TextFillableFigure, TextFontableFigure, TextLayoutableFigure, TransformCachingFigure, PropertyBean, StyleableBean, StyleablePropertyBean, TreeNode<Figure>
Direct Known Subclasses:
AbstractLabelConnectionFigure, LabelFigure, PageLabelFigure

A Label that can be placed anywhere on a drawing.

Label: The layout bounds of the label are controlled by FillableFigure, StrokableFigure, ShapeableFigure. Other figures can get its path with PathIterableFigure. The label box is connectable by means of ConnectableFigure.

 +---------------+
 | layout bounds |
 +---------------+
 
Layout bounds: The layout bounds consist of a content box with padding around it.
 +-------------------+
 | padding           |
 | +---------------+ |
 | | content box   | |
 | +---------------+ |
 +-------------------+
 
Content box: The content is controlled by ICON_POSITION, ICON_SIZE, ICON_TEXT_GAP.
 +------+  +---------------+  +---------------+
 | text |  | icon gap text |  | text gap icon |
 +------+  +---------------+  +---------------+
 

The placement of the label is controlled by ORIGIN, TextLayoutableFigure.TEXT_VPOS, TEXT_HPOS. Note that the placement affects the content box.

 text-hpos: left;  ┆ center;            ┆ right;
                   ┆                    ┆
 x                 ┆       x            ┆               x
 +-------------+   ┆ +-------------+    ┆ +-------------+
 | content box |   ┆ | content box |    ┆ | content box |
 +-------------+   ┆ +-------------+    ┆ +-------------+
 
 text-vpos: top; ┆ center;        ┆ baseline;     ┆ bottom;
                 ┆                ┆               ┆
 y +---------+   ┆   +---------+  ┆   +---------+ ┆   +---------+
   | content |   ┆ y | content |  ┆ y_| content | ┆   | content |
   | box     |   ┆   | box     |  ┆   | box     | ┆   | box     |
   +---------+   ┆   +---------+  ┆   +---------+ ┆ y +---------+
 
Author:
Werner Randelshofer
  • Field Details

  • Constructor Details

    • AbstractLabelFigure

      public AbstractLabelFigure()
    • AbstractLabelFigure

      public AbstractLabelFigure(@NonNull javafx.geometry.Point2D position)
    • AbstractLabelFigure

      public AbstractLabelFigure(double x, double y)
  • Method Details

    • createNode

      public @NonNull javafx.scene.Node createNode(@NonNull RenderContext ctx)
      Creates the node for this label. The node has the following structure:
       Group   holds all other elements of the label
       . Path  the path draws the background and border of the label
       . Text  draws the text of the label
       . Group draws the icon of the label
       
      Specified by:
      createNode in interface Figure
      Parameters:
      ctx - the render context
      Returns:
      the node
    • findConnector

      public @Nullable Connector findConnector(@NonNull javafx.geometry.Point2D p, @Nullable Figure prototype, double tolerance)
      Description copied from interface: ConnectableFigure
      Gets a connector for this figure at the given location.
      Specified by:
      findConnector in interface ConnectableFigure
      Parameters:
      p - the location of the connector in local coordinates.
      prototype - The connecting figure or null if unknown. This allows for specific connectors for different connection figures.
      tolerance - tolerance in world coordinates
      Returns:
      Returns the connector. Returns null if there is no connector at the given location.
    • getCachedLayoutBounds

      protected @Nullable javafx.geometry.Bounds getCachedLayoutBounds()
    • setCachedLayoutBounds

      protected void setCachedLayoutBounds(@NonNull javafx.geometry.Bounds newValue)
    • 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
      Returns:
      the local bounds
    • getCssLayoutBounds

      public @NonNull CssRectangle2D getCssLayoutBounds()
      Specified by:
      getCssLayoutBounds in interface Figure
    • hasIcon

      protected boolean hasIcon()
      Returns true if this figure has an icon. This method returns true if it has a non-null ICON_SHAPE.

      Subclasses can override this and

      Returns:
    • getPathIterator

      Specified by:
      getPathIterator in interface PathIterableFigure
    • getText

      protected abstract @Nullable String getText(@NonNull RenderContext ctx)
    • layout

      public void layout(@NonNull RenderContext ctx)
      Computes the layout bounds of this figure.
      Specified by:
      layout in interface Figure
      Parameters:
      ctx - the render context
    • 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
    • translateInLocal

      public void translateInLocal(@NonNull CssPoint2D delta)
      Description copied from interface: Figure
      Attempts to translate the local bounds of the figure.
      Specified by:
      translateInLocal in interface Figure
      Parameters:
      delta - the translation in x and in y direction
    • updateGroupNode

      protected void updateGroupNode(@NonNull RenderContext ctx, @NonNull javafx.scene.Group node)
      Updates the group node that holds all other nodes of the label.

      This method is empty. Subclasses may apply properties to the group node.

      Parameters:
      ctx - the render context
      node - the group node
    • updateNode

      public void updateNode(@NonNull RenderContext ctx, @NonNull javafx.scene.Node node)
      Updates the node of the label.
      Specified by:
      updateNode in interface Figure
      Parameters:
      ctx - the render context
      node - the node
    • updateIconNode

      protected void updateIconNode(@NonNull RenderContext ctx, @NonNull javafx.scene.Group iconGroupNode)
      Updates the icon node for rendering.
      Parameters:
      ctx - the render context
      iconGroupNode - the group node that holds the icon image
    • updateIconNodeImage

      protected void updateIconNodeImage(@NonNull RenderContext ctx, @NonNull javafx.scene.Group iconGroupNode)
      Updates the image of the icon node.
      Parameters:
      ctx - the render context
      iconGroupNode - the group node that holds the icon image
    • updateIconNodeTransform

      protected void updateIconNodeTransform(@NonNull RenderContext ctx, @NonNull javafx.scene.Group iconGroupNode)
      Updates the transforms (translate, rotate, ...) of the provided icon group node.

      The icon is placed next to the text plus the icon gap. The path for the icon is taken from ICON_SHAPE.

      Parameters:
      ctx - the render context
      iconGroupNode - the group node that holds the icon image
    • updatePathNode

      protected void updatePathNode(@NonNull RenderContext ctx, @NonNull javafx.scene.shape.Path node)
      Updates the path that fills or strokes the visual bounds of the label.
      Parameters:
      ctx - the render context
      node - the path node
    • updateTextNode

      protected void updateTextNode(@NonNull RenderContext ctx, @NonNull javafx.scene.text.Text tn)
      Updates the given text node with properties from this figure, so that it can be rendered.

      This method calls updateTextNodeFontAndText(RenderContext, Text), updateTextNodeLayout(RenderContext, Text), updateTextNodePaint(RenderContext, Text).

      If hasIcon() returns true, the text is placed next to the icon plus the icon gap.

      Parameters:
      ctx - the render context
      tn - the text node
    • updateTextNodePaint

      protected void updateTextNodePaint(@NonNull RenderContext ctx, @NonNull javafx.scene.text.Text tn)
      Updates paint properties of the given text node with properties from this figure.
      Parameters:
      ctx - the render context
      tn - the text node
    • updateTextNodeLayout

      protected void updateTextNodeLayout(@NonNull RenderContext ctx, @NonNull javafx.scene.text.Text tn)
      Updates properties that are relevant for the layout of the given text node with properties from this figure.
      Parameters:
      ctx - the render context
      tn - the text node
    • updateTextNodeFontAndText

      protected void updateTextNodeFontAndText(@NonNull RenderContext ctx, @NonNull javafx.scene.text.Text tn)
      Updates the given text node with properties from this figure that affects the layout of the text node. This includes the text, the font properties, and the text alignment properties.
      Parameters:
      ctx - the render context
      tn - the text node