Class AbstractBlock

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.awt.geom.Rectangle2D bounds
      The current bounds for the block (position of the block in Java2D space).
      private BlockFrame frame
      The frame (or border) for the block.
      private double height
      The natural height of the block (may be overridden if there are constraints in sizing).
      private java.lang.String id
      The id for the block.
      private RectangleInsets margin
      The margin around the outside of the block.
      private RectangleInsets padding
      The padding between the block content and the border.
      private static long serialVersionUID
      For serialization.
      private double width
      The natural width of the block (may be overridden if there are constraints in sizing).
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected AbstractBlock()
      Creates a new block.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      Size2D arrange​(java.awt.Graphics2D g2)
      Arranges the contents of the block, with no constraints, and returns the block size.
      Size2D arrange​(java.awt.Graphics2D g2, RectangleConstraint constraint)
      Arranges the contents of the block, within the given constraints, and returns the block size.
      protected double calculateTotalHeight​(double contentHeight)
      Adds the margin, border and padding to the specified content height.
      protected double calculateTotalWidth​(double contentWidth)
      Adds the margin, border and padding to the specified content width.
      boolean canEqual​(java.lang.Object other)
      Ensures symmetry between super/subclass implementations of equals.
      java.lang.Object clone()
      Returns a clone of this block.
      protected void drawBorder​(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D area)
      Draws the border around the perimeter of the specified area.
      boolean equals​(java.lang.Object obj)
      Tests this block for equality with an arbitrary object.
      java.awt.geom.Rectangle2D getBounds()
      Returns the current bounds of the block.
      double getContentXOffset()
      Returns the x-offset for the content within the block.
      double getContentYOffset()
      Returns the y-offset for the content within the block.
      BlockFrame getFrame()
      Returns the current frame (border).
      double getHeight()
      Returns the natural height of the block, if this is known in advance.
      java.lang.String getID()
      Returns the id.
      RectangleInsets getMargin()
      Returns the margin.
      RectangleInsets getPadding()
      Returns the padding.
      double getWidth()
      Returns the natural width of the block, if this is known in advance.
      int hashCode()  
      private void readObject​(java.io.ObjectInputStream stream)
      Provides serialization support.
      void setBorder​(double top, double left, double bottom, double right)
      Sets a black border with the specified line widths.
      void setBounds​(java.awt.geom.Rectangle2D bounds)
      Sets the bounds of the block.
      void setFrame​(BlockFrame frame)
      Sets the frame (or border).
      void setHeight​(double height)
      Sets the natural width of the block, if this is known in advance.
      void setID​(java.lang.String id)
      Sets the id for the block.
      void setMargin​(double top, double left, double bottom, double right)
      Sets the margin.
      void setMargin​(RectangleInsets margin)
      Sets the margin (use RectangleInsets.ZERO_INSETS for no padding).
      void setPadding​(double top, double left, double bottom, double right)
      Sets the padding.
      void setPadding​(RectangleInsets padding)
      Sets the padding (use RectangleInsets.ZERO_INSETS for no padding).
      void setWidth​(double width)
      Sets the natural width of the block, if this is known in advance.
      protected RectangleConstraint toContentConstraint​(RectangleConstraint c)
      Returns a constraint for the content of this block that will result in the bounds of the block matching the specified constraint.
      protected java.awt.geom.Rectangle2D trimBorder​(java.awt.geom.Rectangle2D area)
      Reduces the specified area by the amount of space consumed by the border.
      protected java.awt.geom.Rectangle2D trimMargin​(java.awt.geom.Rectangle2D area)
      Reduces the specified area by the amount of space consumed by the margin.
      protected java.awt.geom.Rectangle2D trimPadding​(java.awt.geom.Rectangle2D area)
      Reduces the specified area by the amount of space consumed by the padding.
      protected double trimToContentHeight​(double fixedHeight)
      Calculate the height available for content after subtracting the margin, border and padding space from the specified fixed height.
      private Range trimToContentHeight​(Range r)  
      protected double trimToContentWidth​(double fixedWidth)
      Calculate the width available for content after subtracting the margin, border and padding space from the specified fixed width.
      private Range trimToContentWidth​(Range r)  
      private void writeObject​(java.io.ObjectOutputStream stream)
      Provides serialization support.
      • Methods inherited from class java.lang.Object

        finalize, getClass, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • serialVersionUID

        private static final long serialVersionUID
        For serialization.
        See Also:
        Constant Field Values
      • id

        private java.lang.String id
        The id for the block.
      • margin

        private RectangleInsets margin
        The margin around the outside of the block.
      • frame

        private BlockFrame frame
        The frame (or border) for the block.
      • padding

        private RectangleInsets padding
        The padding between the block content and the border.
      • width

        private double width
        The natural width of the block (may be overridden if there are constraints in sizing).
      • height

        private double height
        The natural height of the block (may be overridden if there are constraints in sizing).
      • bounds

        private transient java.awt.geom.Rectangle2D bounds
        The current bounds for the block (position of the block in Java2D space).
    • Constructor Detail

      • AbstractBlock

        protected AbstractBlock()
        Creates a new block.
    • Method Detail

      • getID

        public java.lang.String getID()
        Returns the id.
        Returns:
        The id (possibly null).
        See Also:
        setID(String)
      • setID

        public void setID​(java.lang.String id)
        Sets the id for the block.
        Parameters:
        id - the id (null permitted).
        See Also:
        getID()
      • getWidth

        public double getWidth()
        Returns the natural width of the block, if this is known in advance. The actual width of the block may be overridden if layout constraints make this necessary.
        Returns:
        The width.
        See Also:
        setWidth(double)
      • setWidth

        public void setWidth​(double width)
        Sets the natural width of the block, if this is known in advance.
        Parameters:
        width - the width (in Java2D units)
        See Also:
        getWidth()
      • getHeight

        public double getHeight()
        Returns the natural height of the block, if this is known in advance. The actual height of the block may be overridden if layout constraints make this necessary.
        Returns:
        The height.
        See Also:
        setHeight(double)
      • setHeight

        public void setHeight​(double height)
        Sets the natural width of the block, if this is known in advance.
        Parameters:
        height - the width (in Java2D units)
        See Also:
        getHeight()
      • setMargin

        public void setMargin​(double top,
                              double left,
                              double bottom,
                              double right)
        Sets the margin.
        Parameters:
        top - the top margin.
        left - the left margin.
        bottom - the bottom margin.
        right - the right margin.
        See Also:
        getMargin()
      • setBorder

        public void setBorder​(double top,
                              double left,
                              double bottom,
                              double right)
        Sets a black border with the specified line widths.
        Parameters:
        top - the top border line width.
        left - the left border line width.
        bottom - the bottom border line width.
        right - the right border line width.
      • setFrame

        public void setFrame​(BlockFrame frame)
        Sets the frame (or border).
        Parameters:
        frame - the frame (null not permitted).
        See Also:
        getFrame()
      • setPadding

        public void setPadding​(double top,
                               double left,
                               double bottom,
                               double right)
        Sets the padding.
        Parameters:
        top - the top padding.
        left - the left padding.
        bottom - the bottom padding.
        right - the right padding.
      • getContentXOffset

        public double getContentXOffset()
        Returns the x-offset for the content within the block.
        Returns:
        The x-offset.
        See Also:
        getContentYOffset()
      • getContentYOffset

        public double getContentYOffset()
        Returns the y-offset for the content within the block.
        Returns:
        The y-offset.
        See Also:
        getContentXOffset()
      • arrange

        public Size2D arrange​(java.awt.Graphics2D g2)
        Arranges the contents of the block, with no constraints, and returns the block size.
        Parameters:
        g2 - the graphics device.
        Returns:
        The block size (in Java2D units, never null).
      • arrange

        public Size2D arrange​(java.awt.Graphics2D g2,
                              RectangleConstraint constraint)
        Arranges the contents of the block, within the given constraints, and returns the block size.
        Parameters:
        g2 - the graphics device.
        constraint - the constraint (null not permitted).
        Returns:
        The block size (in Java2D units, never null).
      • getBounds

        public java.awt.geom.Rectangle2D getBounds()
        Returns the current bounds of the block.
        Returns:
        The bounds.
        See Also:
        setBounds(Rectangle2D)
      • setBounds

        public void setBounds​(java.awt.geom.Rectangle2D bounds)
        Sets the bounds of the block.
        Parameters:
        bounds - the bounds (null not permitted).
        See Also:
        getBounds()
      • trimToContentWidth

        protected double trimToContentWidth​(double fixedWidth)
        Calculate the width available for content after subtracting the margin, border and padding space from the specified fixed width.
        Parameters:
        fixedWidth - the fixed width.
        Returns:
        The available space.
        See Also:
        trimToContentHeight(double)
      • trimToContentHeight

        protected double trimToContentHeight​(double fixedHeight)
        Calculate the height available for content after subtracting the margin, border and padding space from the specified fixed height.
        Parameters:
        fixedHeight - the fixed height.
        Returns:
        The available space.
        See Also:
        trimToContentWidth(double)
      • toContentConstraint

        protected RectangleConstraint toContentConstraint​(RectangleConstraint c)
        Returns a constraint for the content of this block that will result in the bounds of the block matching the specified constraint.
        Parameters:
        c - the outer constraint (null not permitted).
        Returns:
        The content constraint.
      • trimToContentWidth

        private Range trimToContentWidth​(Range r)
      • trimToContentHeight

        private Range trimToContentHeight​(Range r)
      • calculateTotalWidth

        protected double calculateTotalWidth​(double contentWidth)
        Adds the margin, border and padding to the specified content width.
        Parameters:
        contentWidth - the content width.
        Returns:
        The adjusted width.
      • calculateTotalHeight

        protected double calculateTotalHeight​(double contentHeight)
        Adds the margin, border and padding to the specified content height.
        Parameters:
        contentHeight - the content height.
        Returns:
        The adjusted height.
      • trimMargin

        protected java.awt.geom.Rectangle2D trimMargin​(java.awt.geom.Rectangle2D area)
        Reduces the specified area by the amount of space consumed by the margin.
        Parameters:
        area - the area (null not permitted).
        Returns:
        The trimmed area.
      • trimBorder

        protected java.awt.geom.Rectangle2D trimBorder​(java.awt.geom.Rectangle2D area)
        Reduces the specified area by the amount of space consumed by the border.
        Parameters:
        area - the area (null not permitted).
        Returns:
        The trimmed area.
      • trimPadding

        protected java.awt.geom.Rectangle2D trimPadding​(java.awt.geom.Rectangle2D area)
        Reduces the specified area by the amount of space consumed by the padding.
        Parameters:
        area - the area (null not permitted).
        Returns:
        The trimmed area.
      • drawBorder

        protected void drawBorder​(java.awt.Graphics2D g2,
                                  java.awt.geom.Rectangle2D area)
        Draws the border around the perimeter of the specified area.
        Parameters:
        g2 - the graphics device.
        area - the area.
      • equals

        public boolean equals​(java.lang.Object obj)
        Tests this block for equality with an arbitrary object.
        Overrides:
        equals in class java.lang.Object
        Parameters:
        obj - the object (null permitted).
        Returns:
        A boolean.
      • canEqual

        public boolean canEqual​(java.lang.Object other)
        Ensures symmetry between super/subclass implementations of equals. For more detail, see http://jqno.nl/equalsverifier/manual/inheritance.
        Parameters:
        other - Object
        Returns:
        true ONLY if the parameter is THIS class type
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • clone

        public java.lang.Object clone()
                               throws java.lang.CloneNotSupportedException
        Returns a clone of this block.
        Overrides:
        clone in class java.lang.Object
        Returns:
        A clone.
        Throws:
        java.lang.CloneNotSupportedException - if there is a problem creating the clone.
      • writeObject

        private void writeObject​(java.io.ObjectOutputStream stream)
                          throws java.io.IOException
        Provides serialization support.
        Parameters:
        stream - the output stream.
        Throws:
        java.io.IOException - if there is an I/O error.
      • readObject

        private void readObject​(java.io.ObjectInputStream stream)
                         throws java.io.IOException,
                                java.lang.ClassNotFoundException
        Provides serialization support.
        Parameters:
        stream - the input stream.
        Throws:
        java.io.IOException - if there is an I/O error.
        java.lang.ClassNotFoundException - if there is a classpath problem.