Interface DrawingModel

All Superinterfaces:
javafx.beans.Observable, ObservableMixin, TreeModel<Figure>
All Known Implementing Classes:
AbstractDrawingModel, SimpleDrawingModel

public interface DrawingModel extends javafx.beans.Observable, TreeModel<Figure>
DrawingModel provides DrawingModelEvents about a Drawing.

DrawingModel is used by DrawingView to get change events from a drawing without having to register listeners on all figures.

The DrawingModelEvents that a DrawingModel fires are based on assumptions that it makes about the figures contained in the drawing. If the assumptions are wrong, then the drawing view will not properly update its view!

DrawingModel invokes addNotify() and removeNotify() methods on a Figure when it detects that the figure has been added or removed from a Drawing.

A DrawingView will only be updated properly, if all Tools, Handles and inspectors update the drawing using the DrawingModel.

Author:
Werner Randelshofer
  • Property Details

  • Field Details

  • Method Details

    • getDrawingModelListeners

      @NonNull CopyOnWriteArrayList<org.jhotdraw8.base.event.Listener<DrawingModelEvent>> getDrawingModelListeners()
      List of drawing model listeners.
      Returns:
      a list of drawing model listeners
    • getInvalidationListeners

      @NonNull CopyOnWriteArrayList<javafx.beans.InvalidationListener> getInvalidationListeners()
      List of invalidation listeners.
      Specified by:
      getInvalidationListeners in interface ObservableMixin
      Specified by:
      getInvalidationListeners in interface TreeModel<Figure>
      Returns:
      a list of drawing model listeners
    • drawingProperty

      @NonNull javafx.beans.property.ObjectProperty<Drawing> drawingProperty()
      The root of the drawing model.
      Returns:
      the root
      See Also:
    • addDrawingModelListener

      default void addDrawingModelListener(org.jhotdraw8.base.event.Listener<DrawingModelEvent> l)
      Adds a listener for DrawingModelEvents.
      Parameters:
      l - the listener
    • removeDrawingModelListener

      default void removeDrawingModelListener(org.jhotdraw8.base.event.Listener<DrawingModelEvent> l)
      Removes a listener for DrawingModelEvents.
      Parameters:
      l - the listener
    • addListener

      default void addListener(javafx.beans.InvalidationListener l)
      Specified by:
      addListener in interface javafx.beans.Observable
      Specified by:
      addListener in interface ObservableMixin
    • removeListener

      default void removeListener(javafx.beans.InvalidationListener l)
      Specified by:
      removeListener in interface javafx.beans.Observable
      Specified by:
      removeListener in interface ObservableMixin
    • getDrawing

      default Drawing getDrawing()
      Gets the root of the tree.
      Returns:
      the drawing
    • setDrawing

      default void setDrawing(Drawing root)
      Sets the root of the tree and fires appropriate DrawingModelEvents.
      Parameters:
      root - the new root
    • getChildren

      default @NonNull List<Figure> getChildren(@NonNull Figure figure)
      Gets the getChildren of the specified figure.
      Specified by:
      getChildren in interface TreeModel<Figure>
      Parameters:
      figure - the figure.
      Returns:
      the getChildren.
    • getChildCount

      default int getChildCount(@NonNull Figure figure)
      Gets the child count of the specified figure.
      Specified by:
      getChildCount in interface TreeModel<Figure>
      Parameters:
      figure - the parent.
      Returns:
      the number of getChildren
    • getChild

      default @NonNull Figure getChild(@NonNull Figure parent, int index)
      Gets the child at the given index from the parent.
      Specified by:
      getChild in interface TreeModel<Figure>
      Parameters:
      parent - the parent.
      index - the index.
      Returns:
      the child
    • removeFromParent

      void removeFromParent(@NonNull Figure child)
      Removes the specified child from its parent and fires appropriate DrawingModelEvents.
      Specified by:
      removeFromParent in interface TreeModel<Figure>
      Parameters:
      child - the figure
    • removeFromParent

      Figure removeFromParent(Figure parent, int index)
      Removes the specified child from its parent and fires appropriate DrawingModelEvents.
      Parameters:
      parent - the parent figure
      index - the index
    • insertChildAt

      void insertChildAt(@NonNull Figure child, @NonNull Figure parent, int index)
      Adds the specified child to a parent and fires appropriate DrawingModelEvents.
      Specified by:
      insertChildAt in interface TreeModel<Figure>
      Parameters:
      child - the new child
      parent - the parent.
      index - the index
    • addChildTo

      default void addChildTo(@NonNull Figure child, @NonNull Figure parent)
      Adds the specified child to a parent and fires appropriate DrawingModelEvents.
      Specified by:
      addChildTo in interface TreeModel<Figure>
      Parameters:
      child - the new child
      parent - the parent.
    • set

      <T> @Nullable T set(@NonNull Figure figure, MapAccessor<T> key, @Nullable T newValue)
      Sets the specified property on the figure and fires appropriate DrawingModelEvents.
      Type Parameters:
      T - the value type
      Parameters:
      figure - the figure
      key - the key
      newValue - the new value
      Returns:
      the old value
    • remove

      <T> @Nullable T remove(@NonNull Figure figure, MapAccessor<T> key)
    • setNonNull

      <T> @NonNull T setNonNull(@NonNull Figure figure, @NonNull NonNullMapAccessor<T> key, @NonNull T newValue)
      Sets the specified property on the figure and fires appropriate DrawingModelEvents.
      Type Parameters:
      T - the value type
      Parameters:
      figure - the figure
      key - the key
      newValue - the new value
      Returns:
      the old value
    • get

      default <T> @Nullable T get(@NonNull Figure figure, @NonNull MapAccessor<T> key)
      Gets the specified property from the figure.
      Type Parameters:
      T - the value type
      Parameters:
      figure - the figure
      key - the key
      Returns:
      the value
    • getNonNull

      default <T> @NonNull T getNonNull(@NonNull Figure figure, @NonNull NonNullMapAccessor<T> key)
      Gets the specified property from the figure.
      Type Parameters:
      T - the value type
      Parameters:
      figure - the figure
      key - the key
      Returns:
      the value
    • reshapeInLocal

      void reshapeInLocal(Figure f, javafx.scene.transform.Transform transform)
      Attempts to change the local bounds of the figure and fires appropriate DrawingModelEvents.
      Parameters:
      f - the figure
      transform - the desired transformation in the local coordinate system
    • reshapeInParent

      void reshapeInParent(Figure f, javafx.scene.transform.Transform transform)
      Attempts to change the parent bounds of the figure and fires appropriate DrawingModelEvents.
      Parameters:
      f - the figure
      transform - the desired transformation in the parent coordinate system
    • translateInParent

      void translateInParent(Figure f, CssPoint2D tx)
    • reshapeInLocal

      void reshapeInLocal(Figure f, double x, double y, double width, double height)
      Attempts to change the local bounds of the figure and fires appropriate DrawingModelEvents.
      Parameters:
      f - the figure
      x - desired x-position in the local coordinate system
      y - desired y-position in the local coordinate system
      width - desired width in the local coordinate system, may be negative
      height - desired height in the local coordinat system, may be negative
    • reshapeInLocal

      void reshapeInLocal(Figure f, CssSize x, CssSize y, CssSize width, CssSize height)
    • layout

      void layout(Figure f, RenderContext ctx)
      Invokes the layout method of the figure and fires appropriate / DrawingModelEvents.
      Parameters:
      f - the figure
      ctx - the render context (optional)
    • disconnect

      void disconnect(Figure f)
      Invokes the disconnect method of the figure and fires appropriate DrawingModelEvents.
      Parameters:
      f - the figure
    • isValidating

      boolean isValidating()
      Returns true if the drawing model is currently validating its figures.
      Returns:
      true if validation is in progress
    • validatingProperty

      javafx.beans.property.ReadOnlyBooleanProperty validatingProperty()
      This property returns true if the drawing model is validating its figures.
      Returns:
      property that returns true if validation is in progress
      See Also:
    • updateCss

      void updateCss(Figure f)
      Invokes the updateCss method of the figure and fires appropriate DrawingModelEvents.
      Parameters:
      f - the figure
    • fireDrawingModelEvent

      default void fireDrawingModelEvent(DrawingModelEvent event)
      Fires the specified event.
      Parameters:
      event - the event
    • validate

      void validate(RenderContext ctx)
      Validates the model. This method is invoked by DrawingView each time before it renders the model.
      Parameters:
      ctx - the render context (optional)
    • fireNodeInvalidated

      default void fireNodeInvalidated(@NonNull Figure f)
      Fires "node invalidated" event for the specified figure.
      Specified by:
      fireNodeInvalidated in interface TreeModel<Figure>
      Parameters:
      f - the figure
    • firePropertyValueChanged

      default <T> void firePropertyValueChanged(Figure f, Key<T> key, @Nullable T oldValue, @Nullable T newValue, boolean wasAdded, boolean wasRemoved)
      Fires "node invalidated" event for the specified figure.
      Type Parameters:
      T - the value type
      Parameters:
      f - the figure
      key - the property key
      oldValue - the old value
      newValue - the new value
      wasAdded -
      wasRemoved -
    • fireTransformInvalidated

      default void fireTransformInvalidated(Figure f)
      Fires "node invalidated" event for the specified figure.
      Parameters:
      f - the figure
    • fireLayoutInvalidated

      default void fireLayoutInvalidated(Figure f)
      Fires "node invalidated" event for the specified figure.
      Parameters:
      f - the figure
    • fireStyleInvalidated

      default void fireStyleInvalidated(Figure f)
      Fires "style invalidated" event for the specified figure.
      Parameters:
      f - the figure
    • fireDrawingModelInvalidated

      default void fireDrawingModelInvalidated()
      Fires an "invalidated" event.
    • transformInParent

      void transformInParent(Figure figure, javafx.scene.transform.Transform transform)
      Invokes "transformInParent" on the specified figure.
      Parameters:
      figure - a figure
      transform - the desired transformation
    • transformInLocal

      void transformInLocal(Figure figure, javafx.scene.transform.Transform transform)
      Invokes "transformInLocal" on the specified figure.
      Parameters:
      figure - a figure
      transform - the desired transformation
    • remove

      <T> @Nullable T remove(Figure f, Key<T> remove)
      Removes the specified key from the figure.
      Type Parameters:
      T - the value type
      Parameters:
      f - a figure
      remove - a key
      Returns:
      the old value
    • propertyAt

      <T> @NonNull javafx.beans.property.Property<T> propertyAt(Figure f, Key<T> key)
      Creates a property for the specified figure and property key.
      Type Parameters:
      T - the property type
      Parameters:
      f - a figure
      key - a property key
      Returns:
      a property