Class FigureSpecificConstrainer

All Implemented Interfaces:
javafx.beans.Observable, Constrainer, ObservableMixin

public class FigureSpecificConstrainer extends AbstractConstrainer implements Constrainer
Allows to use different constrainers for different figure types.

XXX This could be an abstract class with abstract method getConstrainer. The constrainerMap and the defaultConstrainer could be moved into a concrete subclass.

Author:
Werner Randelshofer
  • Property Details

  • Field Details

    • CONSTRAINER_MAP_PROPERTY

      public final String CONSTRAINER_MAP_PROPERTY
      The name of the "constrainerMap" property.
      See Also:
    • DEFAULT_CONSTRAINER_PROPERTY

      public final String DEFAULT_CONSTRAINER_PROPERTY
      The name of the "defaultConstrainer" property.
      See Also:
  • Constructor Details

    • FigureSpecificConstrainer

      public FigureSpecificConstrainer()
  • Method Details

    • constrainerMapProperty

      public javafx.collections.ObservableMap<Class<?>,Constrainer> constrainerMapProperty()
      Maps figure classes to constrainers.
      Returns:
      the constrainerMap property
      See Also:
    • defaultConstrainerProperty

      public NonNullObjectProperty<Constrainer> defaultConstrainerProperty()
      All figures which are not in the map use the default constrainer.
      Returns:
      the defaultConstrainer property
      See Also:
    • getConstrainerMap

      public Map<Class<?>,Constrainer> getConstrainerMap()
      Gets the value of the constrainerMap property.
      Property description:
      Maps figure classes to constrainers.
      Returns:
      the value of the constrainerMap property
      See Also:
    • getDefaultConstrainer

      public Constrainer getDefaultConstrainer()
      Gets the value of the defaultConstrainer property.
      Property description:
      All figures which are not in the map use the default constrainer.
      Returns:
      the value of the defaultConstrainer property
      See Also:
    • setDefaultConstrainer

      public void setDefaultConstrainer(Constrainer newValue)
      Sets the value of the defaultConstrainer property.
      Property description:
      All figures which are not in the map use the default constrainer.
      Parameters:
      newValue - the value for the defaultConstrainer property
      See Also:
    • translatePoint

      public CssPoint2D translatePoint(Figure f, CssPoint2D p, CssPoint2D dir)
      Description copied from interface: Constrainer
      Snaps a point to the next constrained location in the specified direction.

      This method changes the point which is passed as a parameter.

      Specified by:
      translatePoint in interface Constrainer
      Parameters:
      f - The figure for which the point is to be constrained.
      p - A point on the drawing.
      dir - A direction vector. If the vector length is zero, then the nearest constrained location is used.
      Returns:
      Returns the constrained point.
    • translateRectangle

      public CssRectangle2D translateRectangle(Figure f, CssRectangle2D r, CssPoint2D dir)
      Description copied from interface: Constrainer
      Snaps a rectangle into the the closest constraint position in the given direction.

      This method changes the location of the rectangle which is passed as a parameter. This method does not change the size of the rectangle.

      Specified by:
      translateRectangle in interface Constrainer
      Parameters:
      f - The figure for which points are to be constrained.
      r - A rectangle on the drawing.
      dir - A direction vector. If the vector length is zero, then the nearest constrained location is used.
      Returns:
      Returns the constrained rectangle.
    • translateAngle

      public double translateAngle(Figure f, double angle, double dir)
      Description copied from interface: Constrainer
      Snaps an angle (in degrees) to the closest constrained orientation in the specified direction.
      Specified by:
      translateAngle in interface Constrainer
      Parameters:
      f - The figure for which the angle is to be constrained.
      angle - The angle (in degrees).
      dir - A direction. If the direction is zero, then the nearest constrained location is used.
      Returns:
      The closest constrained angle (in radians) in the specified direction.
    • constrainPoint

      public CssPoint2D constrainPoint(Figure f, CssPoint2D p)
      Description copied from interface: Constrainer
      Constrains the placement of a point towards the closest constraint in any direction.

      This method changes the point which is passed as a parameter.

      Specified by:
      constrainPoint in interface Constrainer
      Parameters:
      f - The figure for which the point is to be constrained.
      p - A point on the drawing.
      Returns:
      Returns the constrained point.
    • constrainRectangle

      public CssRectangle2D constrainRectangle(Figure f, CssRectangle2D r)
      Description copied from interface: Constrainer
      Constrains the placement of a rectangle towards the closest constraint in any direction.

      This method changes the location of the rectangle which is passed as a parameter. This method does not change the size of the rectangle.

      Specified by:
      constrainRectangle in interface Constrainer
      Parameters:
      f - The figure for which the rectangle is to be constrained.
      r - A rectangle on the drawing.
      Returns:
      Returns the constrained rectangle.
    • constrainAngle

      public double constrainAngle(Figure f, double angle)
      Description copied from interface: Constrainer
      Constrains the given angle (in degrees). This method changes the angle which is passed as a parameter.
      Specified by:
      constrainAngle in interface Constrainer
      Parameters:
      f - The figure for which the angle is to be constrained.
      angle - The angle (in degrees).
      Returns:
      The closest constrained angle (in radians).
    • getNode

      public javafx.scene.Node getNode()
      Description copied from interface: Constrainer
      Returns a node that renders the grid in view coordinates.
      Specified by:
      getNode in interface Constrainer
      Returns:
      the node
    • updateNode

      public void updateNode(DrawingView drawingView)
      Description copied from interface: Constrainer
      Updates the node.
      Specified by:
      updateNode in interface Constrainer
      Parameters:
      drawingView - the drawing view