Class ConstraintAnchor


  • public class ConstraintAnchor
    extends java.lang.Object
    Model a constraint relation. Widgets contains anchors, and a constraint relation between two widgets is made by connecting one anchor to another. The anchor will contains a pointer to the target anchor if it is connected.
    • Constructor Detail

      • ConstraintAnchor

        public ConstraintAnchor​(ConstraintWidget owner,
                                ConstraintAnchor.Type type)
        Constructor
        Parameters:
        owner - the widget owner of this anchor.
        type - the anchor type.
    • Method Detail

      • findDependents

        public void findDependents​(int orientation,
                                   java.util.ArrayList<WidgetGroup> list,
                                   WidgetGroup group)
      • hasDependents

        public boolean hasDependents()
      • hasCenteredDependents

        public boolean hasCenteredDependents()
      • setFinalValue

        public void setFinalValue​(int finalValue)
      • getFinalValue

        public int getFinalValue()
      • resetFinalResolution

        public void resetFinalResolution()
      • hasFinalValue

        public boolean hasFinalValue()
      • getSolverVariable

        public SolverVariable getSolverVariable()
        Return the solver variable for this anchor
      • resetSolverVariable

        public void resetSolverVariable​(Cache cache)
        Reset the solver variable
      • getOwner

        public ConstraintWidget getOwner()
        Return the anchor's owner
        Returns:
        the Widget owning the anchor
      • getType

        public ConstraintAnchor.Type getType()
        Return the type of the anchor
        Returns:
        type of the anchor.
      • getMargin

        public int getMargin()
        Return the connection's margin from this anchor to its target.
        Returns:
        the margin value. 0 if not connected.
      • getTarget

        public ConstraintAnchor getTarget()
        Return the connection's target (null if not connected)
        Returns:
        the ConstraintAnchor target
      • reset

        public void reset()
        Resets the anchor's connection.
      • connect

        public boolean connect​(ConstraintAnchor toAnchor,
                               int margin,
                               int goneMargin,
                               boolean forceConnection)
        Connects this anchor to another one.
        Returns:
        true if the connection succeeds.
      • connect

        public boolean connect​(ConstraintAnchor toAnchor,
                               int margin)
        Connects this anchor to another one.
        Returns:
        true if the connection succeeds.
      • isConnected

        public boolean isConnected()
        Returns the connection status of this anchor
        Returns:
        true if the anchor is connected to another one.
      • isValidConnection

        public boolean isValidConnection​(ConstraintAnchor anchor)
        Checks if the connection to a given anchor is valid.
        Parameters:
        anchor - the anchor we want to connect to
        Returns:
        true if it's a compatible anchor
      • isSideAnchor

        public boolean isSideAnchor()
        Return true if this anchor is a side anchor
        Returns:
        true if side anchor
      • isSimilarDimensionConnection

        public boolean isSimilarDimensionConnection​(ConstraintAnchor anchor)
        Return true if the connection to the given anchor is in the same dimension (horizontal or vertical)
        Parameters:
        anchor - the anchor we want to connect to
        Returns:
        true if it's an anchor on the same dimension
      • setMargin

        public void setMargin​(int margin)
        Set the margin of the connection (if there's one)
        Parameters:
        margin - the new margin of the connection
      • setGoneMargin

        public void setGoneMargin​(int margin)
        Set the gone margin of the connection (if there's one)
        Parameters:
        margin - the new margin of the connection
      • isVerticalAnchor

        public boolean isVerticalAnchor()
        Utility function returning true if this anchor is a vertical one.
        Returns:
        true if vertical anchor, false otherwise
      • toString

        public java.lang.String toString()
        Return a string representation of this anchor
        Overrides:
        toString in class java.lang.Object
        Returns:
        string representation of the anchor
      • isConnectionAllowed

        public boolean isConnectionAllowed​(ConstraintWidget target,
                                           ConstraintAnchor anchor)
        Return true if we can connect this anchor to this target. We recursively follow connections in order to detect eventual cycles; if we do we disallow the connection. We also only allow connections to direct parent, siblings, and descendants.
        Parameters:
        target - the ConstraintWidget we are trying to connect to
        anchor - Allow anchor if it loops back to me directly
        Returns:
        if the connection is allowed, false otherwise
      • isConnectionAllowed

        public boolean isConnectionAllowed​(ConstraintWidget target)
        Return true if we can connect this anchor to this target. We recursively follow connections in order to detect eventual cycles; if we do we disallow the connection. We also only allow connections to direct parent, siblings, and descendants.
        Parameters:
        target - the ConstraintWidget we are trying to connect to
        Returns:
        true if the connection is allowed, false otherwise
      • getOpposite

        public final ConstraintAnchor getOpposite()
        Returns the opposite anchor to this one
        Returns:
        opposite anchor