Interface DrawingView

All Superinterfaces:
ReadOnlyPropertyBean, RenderContext, WritableRenderContext
All Known Implementing Classes:
AbstractDrawingView, SimpleDrawingView

public interface DrawingView extends WritableRenderContext
A DrawingView can display a Drawing in a JavaFX scene graph.

A DrawingView consists of the following layers:

  • Background. Displays a background behind the drawing.
  • Drawing. Displays the figures of the drawing.
  • Grid. Displays a grid.
  • Tools. Displays the handles used for editing figures.

DrawingView uses a DrawingModel to listen for changes on a Drawing. Once a drawing is showing in a drawing view, all changes to the drawing must be performed on the drawing model.

DrawingView invokes validate() on its DrawingModel each time before it renders the drawing to ensure that the figures are laid out and that CSS styles are applied before rendering the drawing.

Author:
Werner Randelshofer Responsibility, Handler.
  • Property Details

  • Field Details

  • Method Details

    • modelProperty

      The drawing model.
      Returns:
      the drawing model property, with getBean() returning this drawing view, and getName() returning DRAWING_PROPERTY.
      See Also:
    • drawingProperty

      javafx.beans.property.ReadOnlyObjectProperty<Drawing> drawingProperty()
      The drawing model.
      Returns:
      the drawing model property
      See Also:
    • editorProperty

      javafx.beans.property.ObjectProperty<DrawingEditor> editorProperty()
      The drawing editor.
      Returns:
      the editor property
      See Also:
    • activeParentProperty

      javafx.beans.property.ObjectProperty<Figure> activeParentProperty()
      The active layer of the drawing.
      Returns:
      the active layer of the drawing. Returns null if the drawing has no layers or no layer has been activated.
      See Also:
    • scrollSelectedFiguresToVisible

      default void scrollSelectedFiguresToVisible()
    • toolProperty

      javafx.beans.property.ObjectProperty<Tool> toolProperty()
      The tool which currently edits this DrawingView.

      When a tool is set on the drawing view, then drawing view adds the Node of the tool to its tool panel which is stacked on top of the drawing panel. It then invokes toolsetDrawingView(this).

      Setting a tool will removeChild the previous tool. The drawing view invokes tool.setDrawingView(null) and then removes its Node from its tool panel.

      Returns:
      the tool property, with getBean() returning this drawing view, and getName() returning TOOL_PROPERTY.
      See Also:
    • zoomFactorProperty

      javafx.beans.property.DoubleProperty zoomFactorProperty()
      The scale factor of the drawing view.
      Returns:
      The zoom factor. The value is always greater than 0. Values larger than 1 cause a magnification. Values between 0 and 1 causes a minification.
      See Also:
    • constrainerProperty

      NonNullObjectProperty<Constrainer> constrainerProperty()
      The constrainer.
      Returns:
      the constrainer property, with getBean() returning this drawing view, and getName() returning CONSTRAINER_PROPERTY.
      See Also:
    • focusedProperty

      javafx.beans.property.ReadOnlyBooleanProperty focusedProperty()
      The focused property is set to true, when the DrawingView has input focus.
      Returns:
      the focused property, with getBean() returning this drawing view, and getName() returning FOCUSED_PROPERTY.
    • selectedFiguresProperty

      javafx.beans.property.ReadOnlySetProperty<Figure> selectedFiguresProperty()
      The selected figures.

      Note: The selection is represented by a SequencedSet because the sequence of the selection is important.

      The first figure in the selection is the 'anchor' of the selection.

      The last figure in the selection is the 'lead' of the selection.

      Operations that act on multiple selected figures, typically use the 'lead' figure as the reference figure.

      Returns:
      the currently selected figures
      See Also:
    • handlesProperty

      javafx.beans.property.ReadOnlySetProperty<Handle> handlesProperty()
      The handles.

      Note: The handles are represented by a SequencedSet because the sequence of the handles is important.

      Returns:
      the handles that are currently being displayed on this drawing view.
      See Also:
    • activeHandleProperty

      javafx.beans.property.ObjectProperty<Handle> activeHandleProperty()
      The active handle.

      This is the handle, on which the user has clicked the last time.

      Tools that support keyboard input on handles, typically forward keyboard input to the active handle.

      Returns:
      the active handle if present
      See Also:
    • clipboardOutputFormatProperty

      javafx.beans.property.ObjectProperty<ClipboardOutputFormat> clipboardOutputFormatProperty()
      The clipboard output format.
      Returns:
      the clipboard output format handle if present
      See Also:
    • clipboardInputFormatProperty

      javafx.beans.property.ObjectProperty<ClipboardInputFormat> clipboardInputFormatProperty()
      The clipboard input format.
      Returns:
      the clipboard output format handle if present
      See Also:
    • getNode

      javafx.scene.Node getNode()
      Returns the javafx.scene.Node of the DrawingView.
      Returns:
      a node
    • getNode

      @Nullable javafx.scene.Node getNode(Figure f)
      Gets the node which is used to render the specified figure by the drawing view.
      Specified by:
      getNode in interface RenderContext
      Parameters:
      f - The figure
      Returns:
      The node associated to the figure
    • findHandle

      @Nullable Handle findHandle(double vx, double vy)
      Finds the handle at the given view coordinates. Handles are searched in Z-order from front to back. Skips handles which are not selectable.
      Parameters:
      vx - x in view coordinates
      vy - y in view coordinates
      Returns:
      A handle or null
    • findFigure

      default @Nullable Figure findFigure(double vx, double vy, Set<Figure> figures)
      Finds the figure at the given view coordinates. Figures are searched in Z-order from front to back. Skips disabled figures.
      Parameters:
      vx - x in view coordinates
      vy - y in view coordinates
      figures - Only searches in the provided list of figures
      Returns:
      A figure or null
    • getClosestFigure

      default Figure getClosestFigure(List<Map.Entry<Figure,Double>> result)
    • findFigure

      default @Nullable Figure findFigure(double vx, double vy)
      Finds the figure at the given view coordinates. Figures are searched in Z-order from front to back. Only returns selectable figures.
      Parameters:
      vx - x in view coordinates
      vy - y in view coordinates
      Returns:
      A figure or null
    • findFigure

      default @Nullable Figure findFigure(double vx, double vy, Predicate<Figure> predicate)
      Finds the figure at the given view coordinates. Figures are searched in Z-order from front to back.
      Parameters:
      vx - x in view coordinates
      vy - y in view coordinates
      Returns:
      A figure or null
    • findFigureNode

      @Nullable javafx.scene.Node findFigureNode(Figure figure, double vx, double vy)
      Finds the front-most node of the specified figure that contains the specified view coordinates.
      Parameters:
      figure - the figure
      vx - x in view coordinates
      vy - y in view coordinates
      Returns:
      A node or null
    • findFigures

      default List<Map.Entry<Figure,Double>> findFigures(double vx, double vy, boolean decompose)
      Finds the figure at the given view coordinates behind the given figure. Figures are searched in Z-order from front to back. Only returns figures that are selectable.
      Parameters:
      vx - x in view coordinates
      vy - y in view coordinates
      decompose - whether to decompose the figures
      Returns:
      A list of figures from front to back. Each entry contains the figure and the distance of the figure to vx,vy. Distance 0 means that vx,vy is inside the figure.
    • findFigures

      List<Map.Entry<Figure,Double>> findFigures(double vx, double vy, boolean decompose, Predicate<Figure> predicate)
      Finds the figure at the given view coordinates behind the given figure. Figures are searched in Z-order from front to back.
      Parameters:
      vx - x in view coordinates
      vy - y in view coordinates
      decompose - whether to decompose the figures
      Returns:
      A list of figures from front to back. Each entry contains the figure and the distance of the figure to vx,vy. Distance 0 means that vx,vy is inside the figure.
    • findFiguresInside

      List<Map.Entry<Figure,Double>> findFiguresInside(double vx, double vy, double vwidth, double vheight, boolean decompose)
      Returns all figures that lie within the specified bounds given in view coordinates. The figures are returned in Z-order from back to front. Skips disabled figures.
      Parameters:
      vx - x in view coordinates
      vy - y in view coordinates
      vwidth - width in view coordinates
      vheight - height in view coordinates
      decompose - whether to decompose the figures
      Returns:
      A list of figures from front to back. Each entry contains the figure and the distance of the figure to vx,vy. Distance 0 means that vx,vy is inside the figure.
    • findFiguresIntersecting

      default List<Map.Entry<Figure,Double>> findFiguresIntersecting(double vx, double vy, double vwidth, double vheight, boolean decompose)
      Returns all figures that intersect the specified bounds given in view coordinates. The figures are returned in Z-order from front to back. Skips disabled figures.
      Parameters:
      vx - x in view coordinates
      vy - y in view coordinates
      vwidth - width in view coordinates
      vheight - height in view coordinates
      decompose - whether to decompose the figures
      Returns:
      A list of figures from front to back
    • findFiguresIntersecting

      List<Map.Entry<Figure,Double>> findFiguresIntersecting(double vx, double vy, double vwidth, double vheight, boolean decompose, Predicate<Figure> predicate)
      Returns all figures that intersect the specified bounds given in view coordinates. The figures are returned in Z-order from front to back. Skips disabled figures.
      Parameters:
      vx - x in view coordinates
      vy - y in view coordinates
      vwidth - width in view coordinates
      vheight - height in view coordinates
      decompose - whether to decompose the figures
      predicate - predicate for filtering figures
      Returns:
      A list of figures from front to back
    • getFiguresWithCompatibleHandle

      Set<Figure> getFiguresWithCompatibleHandle(Collection<Figure> figures, Handle handle)
      Gets selected figures with the same handle.
      Parameters:
      figures - selected figures
      handle - a handle
      Returns:
      A collection containing the figures with compatible handles.
    • getWorldToView

      javafx.scene.transform.Transform getWorldToView()
      Returns the world to view transformation.
      Returns:
      the transformation
    • getViewToWorld

      javafx.scene.transform.Transform getViewToWorld()
      Returns the view to world transformation.
      Returns:
      the transformation;
    • findFigure

      default @Nullable Figure findFigure(javafx.geometry.Point2D pointInView)
      Finds the figure at the given view coordinates. Figures are searched in Z-order from front to back. Skips disabled figures and non-selectable figures.
      Parameters:
      pointInView - point in view coordinates
      Returns:
      A figure or empty
    • findFigures

      default List<Map.Entry<Figure,Double>> findFigures(javafx.geometry.Point2D pointInView, boolean decompose)
      Finds the figures at the given view coordinates. Figures are searched in Z-order from front to back. Skips disabled figures and non-selectable figures.
      Parameters:
      pointInView - point in view coordinates
      decompose - whether to decompose the figures
      Returns:
      A list of figures from front to back. Each entry contains the figure and the distance of the figure to vx,vy. Distance 0 means that pointInView is inside the figure.
    • findFiguresInside

      default List<Map.Entry<Figure,Double>> findFiguresInside(javafx.geometry.Rectangle2D rectangleInView, boolean decompose)
      Returns all figures that are inside the specified bounds given in view coordinates. The figures are returned in Z-order from front to back. Skips disabled figures and non-selectable figures.
      Parameters:
      rectangleInView - rectangle in view coordinates
      decompose - whether to decompose the figures
      Returns:
      A list of figures from front to back. Each entry contains the figure and the distance of the figure to vx,vy. Distance 0 means that pointInView is inside the figure.
    • findFiguresIntersecting

      default List<Map.Entry<Figure,Double>> findFiguresIntersecting(javafx.geometry.Rectangle2D rectangleInView, boolean decompose)
      Returns all figures that intersect the specified bounds given in view coordinates. The figures are returned in Z-order from back to front. Skips disabled figures and non-selectable figures.
      Parameters:
      rectangleInView - rectangle in view coordinates
      decompose - whether to decompose the figures
      Returns:
      A list of figures from front to back
    • setDrawing

      default void setDrawing(@Nullable Drawing newValue)
      Sets the value of the drawing property.
      Property description:
      The drawing model.
      Parameters:
      newValue - the value for the drawing property
      See Also:
    • getDrawing

      default @Nullable Drawing getDrawing()
      Gets the value of the drawing property.
      Property description:
      The drawing model.
      Returns:
      the value of the drawing property
      See Also:
    • setEditor

      default void setEditor(@Nullable DrawingEditor newValue)
      Sets the value of the editor property.
      Property description:
      The drawing editor.
      Parameters:
      newValue - the value for the editor property
      See Also:
    • getEditor

      default @Nullable DrawingEditor getEditor()
      Gets the value of the editor property.
      Property description:
      The drawing editor.
      Returns:
      the value of the editor property
      See Also:
    • setConstrainer

      default void setConstrainer(Constrainer newValue)
      Sets the value of the constrainer property.
      Property description:
      The constrainer.
      Parameters:
      newValue - the value for the constrainer property
      See Also:
    • getConstrainer

      default Constrainer getConstrainer()
      Gets the value of the constrainer property.
      Property description:
      The constrainer.
      Returns:
      the value of the constrainer property
      See Also:
    • setTool

      default void setTool(@Nullable Tool newValue)
      Sets the value of the tool property.
      Property description:
      The tool which currently edits this DrawingView.

      When a tool is set on the drawing view, then drawing view adds the Node of the tool to its tool panel which is stacked on top of the drawing panel. It then invokes toolsetDrawingView(this).

      Setting a tool will removeChild the previous tool. The drawing view invokes tool.setDrawingView(null) and then removes its Node from its tool panel.

      Parameters:
      newValue - the value for the tool property
      See Also:
    • getTool

      default @Nullable Tool getTool()
      Gets the value of the tool property.
      Property description:
      The tool which currently edits this DrawingView.

      When a tool is set on the drawing view, then drawing view adds the Node of the tool to its tool panel which is stacked on top of the drawing panel. It then invokes toolsetDrawingView(this).

      Setting a tool will removeChild the previous tool. The drawing view invokes tool.setDrawingView(null) and then removes its Node from its tool panel.

      Returns:
      the value of the tool property
      See Also:
    • setActiveHandle

      default void setActiveHandle(@Nullable Handle newValue)
      Sets the value of the activeHandle property.
      Property description:
      The active handle.

      This is the handle, on which the user has clicked the last time.

      Tools that support keyboard input on handles, typically forward keyboard input to the active handle.

      Parameters:
      newValue - the value for the activeHandle property
      See Also:
    • getActiveHandle

      default @Nullable Handle getActiveHandle()
      Gets the value of the activeHandle property.
      Property description:
      The active handle.

      This is the handle, on which the user has clicked the last time.

      Tools that support keyboard input on handles, typically forward keyboard input to the active handle.

      Returns:
      the value of the activeHandle property
      See Also:
    • getSelectionLead

      default @Nullable Figure getSelectionLead()
    • getSelectionAnchor

      default @Nullable Figure getSelectionAnchor()
    • setActiveParent

      default void setActiveParent(@Nullable Figure newValue)
      Sets the value of the activeParent property.
      Property description:
      The active layer of the drawing.
      Parameters:
      newValue - the value for the activeParent property
      See Also:
    • getActiveParent

      default @Nullable Figure getActiveParent()
      Gets the value of the activeParent property.
      Property description:
      The active layer of the drawing.
      Returns:
      the value of the activeParent property
      See Also:
    • setZoomFactor

      default void setZoomFactor(double newValue)
      Sets the value of the zoomFactor property.
      Property description:
      The scale factor of the drawing view.
      Parameters:
      newValue - the value for the zoomFactor property
      See Also:
    • getZoomFactor

      default double getZoomFactor()
      Gets the value of the zoomFactor property.
      Property description:
      The scale factor of the drawing view.
      Returns:
      the value of the zoomFactor property
      See Also:
    • getSelectedFigures

      default javafx.collections.ObservableSet<Figure> getSelectedFigures()
      Gets the value of the selectedFigures property.
      Property description:
      The selected figures.

      Note: The selection is represented by a SequencedSet because the sequence of the selection is important.

      The first figure in the selection is the 'anchor' of the selection.

      The last figure in the selection is the 'lead' of the selection.

      Operations that act on multiple selected figures, typically use the 'lead' figure as the reference figure.

      Returns:
      the value of the selectedFigures property
      See Also:
    • getHandles

      default javafx.collections.ObservableSet<Handle> getHandles()
      Gets the value of the handles property.
      Property description:
      The handles.

      Note: The handles are represented by a SequencedSet because the sequence of the handles is important.

      Returns:
      the value of the handles property
      See Also:
    • viewToWorld

      default javafx.geometry.Point2D viewToWorld(javafx.geometry.Point2D view)
      Converts view coordinates into world coordinates.
      Parameters:
      view - a point in view coordinates
      Returns:
      the corresponding point in world coordinates
    • viewToWorld

      default javafx.geometry.Bounds viewToWorld(javafx.geometry.Bounds view)
      Converts view coordinates into world coordinates.
      Parameters:
      view - a rectangle in view coordinates
      Returns:
      the corresponding point in world coordinates
    • worldToView

      default javafx.geometry.Point2D worldToView(javafx.geometry.Point2D world)
      Converts world coordinates into view coordinates.
      Parameters:
      world - a point in world coordinates
      Returns:
      the corresponding point in view coordinates
    • worldToView

      default javafx.geometry.Bounds worldToView(javafx.geometry.Bounds world)
      Converts world coordinates into view coordinates.
      Parameters:
      world - a box in world coordinates
      Returns:
      the corresponding box in view coordinates
    • viewToWorld

      default javafx.geometry.Point2D viewToWorld(double vx, double vy)
      Converts view coordinates into world coordinates.
      Parameters:
      vx - the x coordinate of a point in view coordinates
      vy - the y coordinate of a point in view coordinates
      Returns:
      the corresponding point in world coordinates
    • worldToView

      default javafx.geometry.Point2D worldToView(double dx, double dy)
      Converts world coordinates into view coordinates.
      Parameters:
      dx - the x coordinate of a point in world coordinates
      dy - the y coordinate of a point in world coordinates
      Returns:
      the corresponding point in view coordinates
    • getModel

      default DrawingModel getModel()
      Returns the underlying drawing model.
      Returns:
      a drawing model
    • setModel

      default void setModel(DrawingModel newValue)
      Sets a new underlying drawing model.
      Parameters:
      newValue - a drawing model
    • setClipboardOutputFormat

      default void setClipboardOutputFormat(@Nullable ClipboardOutputFormat newValue)
      Sets the value of the clipboardOutputFormat property.
      Property description:
      The clipboard output format.
      Parameters:
      newValue - the value for the clipboardOutputFormat property
      See Also:
    • setClipboardInputFormat

      default void setClipboardInputFormat(@Nullable ClipboardInputFormat newValue)
      Sets the value of the clipboardInputFormat property.
      Property description:
      The clipboard input format.
      Parameters:
      newValue - the value for the clipboardInputFormat property
      See Also:
    • getClipboardOutputFormat

      default @Nullable ClipboardOutputFormat getClipboardOutputFormat()
      Gets the value of the clipboardOutputFormat property.
      Property description:
      The clipboard output format.
      Returns:
      the value of the clipboardOutputFormat property
      See Also:
    • getClipboardInputFormat

      default @Nullable ClipboardInputFormat getClipboardInputFormat()
      Gets the value of the clipboardInputFormat property.
      Property description:
      The clipboard input format.
      Returns:
      the value of the clipboardInputFormat property
      See Also:
    • recreateHandles

      void recreateHandles()
    • jiggleHandles

      void jiggleHandles()
      Plays a short animation on the handles to make them easier discoverable.
    • scrollFigureToVisible

      default void scrollFigureToVisible(Figure f)
      Scrolls the specified figure to visible.
      Parameters:
      f - A figure in the drawing of this DrawingView.
    • scrollRectToVisible

      void scrollRectToVisible(javafx.geometry.Bounds boundsInView)
      Scrolls the specified rectangle to visible.
      Parameters:
      boundsInView - A rectangle in view coordinates.
    • getVisibleRect

      javafx.geometry.Bounds getVisibleRect()
      Returns the visible rectangle of the drawing view in view coordinates.
      Returns:
      the portion of the DrawingView that is visible on screen.