Class JideBoxLayout

  • All Implemented Interfaces:
    java.awt.LayoutManager, java.awt.LayoutManager2, java.io.Serializable
    Direct Known Subclasses:
    JideSplitPaneLayout

    public class JideBoxLayout
    extends java.lang.Object
    implements java.awt.LayoutManager2, java.io.Serializable
    JideBoxLayout is very similar to BoxLayout in the way that all components are arranged either from left to right or from top to bottom. Different \ from BoxLayout, there are three possible constraints when adding component to this layout - FIX, FLEXIBLE and VARY.
    • FIX: use the preferred size of the component and size is fixed
    • FLEXIBLE: respect the preferred size of the component but size can be changed.
    • VARY: ignore preferred size. Its size is calculated based how much area left.
    This is the default layout manager for JideSplitPane.
    See Also:
    Serialized Form
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected int _axis
      Axis, 0 for horizontal, or 1 for vertical.
      protected int[] _componentSizes  
      protected java.awt.Container _target  
      static java.lang.String FIX
      For FIX component, the width (or height if vertical) is and will always be the preferred width.
      static java.lang.String FLEXIBLE
      FLEXIBLE components try to keep the preferred width.
      static int LINE_AXIS
      Specifies that components should be laid out in the direction of a line of text as determined by the target container's ComponentOrientation property.
      static int PAGE_AXIS
      Specifies that components should be laid out in the direction that lines flow across a page as determined by the target container's ComponentOrientation property.
      static java.lang.String VARY
      For VARY component, the width will always be whatever width left.
      static int X_AXIS
      Specifies that components should be laid out left to right.
      static int Y_AXIS
      Specifies that components should be laid out top to bottom.
    • Constructor Summary

      Constructors 
      Constructor Description
      JideBoxLayout​(java.awt.Container target)
      Creates a layout manager that will lay out components along the given axis.
      JideBoxLayout​(java.awt.Container target, int axis)  
      JideBoxLayout​(java.awt.Container target, int axis, int gap)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addLayoutComponent​(java.awt.Component comp, java.lang.Object constraints)
      Adds the specified component to the layout, using the specified constraint object.
      void addLayoutComponent​(java.lang.String name, java.awt.Component component)
      If the layout manager uses a per-component string, adds the component comp to the layout, associating it with the string specified by name.
      protected boolean calculateComponentSizes​(int availableSize, int startIndex, int endIndex)  
      protected boolean componentCountChanged​(java.awt.Container c)  
      protected int getAvailableSize​(java.awt.Dimension containerSize, java.awt.Insets insets)
      Returns the available width based on the container size and Insets.
      int getAxis()
      Gets the axis.
      java.util.Map<java.awt.Component,​java.lang.Object> getConstraintMap()
      Gets the map of constraints.
      int getGap()
      Gets the gap between each component.
      protected int getInitialLocation​(java.awt.Insets insets)
      Returns the left inset, unless the Insets are null in which case 0 is returned.
      float getLayoutAlignmentX​(java.awt.Container target)
      Returns the alignment along the x axis.
      float getLayoutAlignmentY​(java.awt.Container target)
      Returns the alignment along the y axis.
      protected java.awt.Dimension getPreferredSizeOf​(java.awt.Component comp, int atIndex)  
      protected int getPreferredSizeOfComponent​(java.awt.Component c)
      Returns the width of the passed in Components preferred size.
      protected int getSizeOfComponent​(java.awt.Component c)
      Returns the width of the passed in component.
      void invalidateLayout​(java.awt.Container c)
      Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.
      boolean isAlwaysLayout()
      Checks if the alwaysLayout flag is true.
      boolean isResetWhenInvalidate()
      Checks of the layout should be reset when invalidateLayout(java.awt.Container) is called.
      void layoutContainer​(java.awt.Container container)
      Lays out the specified container.
      java.awt.Dimension maximumLayoutSize​(java.awt.Container target)
      Returns the maximum layout size, which is Integer.MAX_VALUE in both directions.
      java.awt.Dimension minimumLayoutSize​(java.awt.Container container)
      Returns the minimum size needed to contain the children.
      java.awt.Dimension preferredLayoutSize​(java.awt.Container container)
      Returns the preferred size needed to contain the children.
      void removeLayoutComponent​(java.awt.Component comp)
      Removes the specified component from the layout.
      protected static int resolveAxis​(int axis, java.awt.ComponentOrientation o)
      Given one of the 4 axis values, resolve it to an absolute axis.
      void setAlwaysLayout​(boolean alwaysLayout)
      Sets the alwaysLayout flag.
      void setAxis​(int axis)
      Sets the axis.
      protected void setComponentToSize​(java.awt.Component c, int size, int location, java.awt.Insets insets, java.awt.Dimension containerSize)
      Sets the width of the component c to be size, placing its x location at location, y to the insets.top and height to the containersize.height less the top and bottom insets.
      void setGap​(int gap)
      Sets the gap between each component.
      void setResetWhenInvalidate​(boolean resetWhenInvalidate)
      Sets the flag if the layout should be reset when invalidateLayout(java.awt.Container) is called.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • _axis

        protected int _axis
        Axis, 0 for horizontal, or 1 for vertical.
      • _target

        protected java.awt.Container _target
      • _componentSizes

        protected int[] _componentSizes
      • FIX

        public static final java.lang.String FIX
        For FIX component, the width (or height if vertical) is and will always be the preferred width.
        See Also:
        Constant Field Values
      • FLEXIBLE

        public static final java.lang.String FLEXIBLE
        FLEXIBLE components try to keep the preferred width. If there isn't enough space, all FLEXIBLE components will shrink proportionally.
        See Also:
        Constant Field Values
      • VARY

        public static final java.lang.String VARY
        For VARY component, the width will always be whatever width left. You can allow add multiple FIX or FLEXIBLE components but only one VARY component is allowed.
        See Also:
        Constant Field Values
      • X_AXIS

        public static final int X_AXIS
        Specifies that components should be laid out left to right.
        See Also:
        Constant Field Values
      • Y_AXIS

        public static final int Y_AXIS
        Specifies that components should be laid out top to bottom.
        See Also:
        Constant Field Values
      • LINE_AXIS

        public static final int LINE_AXIS
        Specifies that components should be laid out in the direction of a line of text as determined by the target container's ComponentOrientation property.
        See Also:
        Constant Field Values
      • PAGE_AXIS

        public static final int PAGE_AXIS
        Specifies that components should be laid out in the direction that lines flow across a page as determined by the target container's ComponentOrientation property.
        See Also:
        Constant Field Values
    • Constructor Detail

      • JideBoxLayout

        public JideBoxLayout​(java.awt.Container target)
        Creates a layout manager that will lay out components along the given axis.
        Parameters:
        target - the container that needs to be laid out
        Throws:
        java.awt.AWTError - if the value of axis is invalid
      • JideBoxLayout

        public JideBoxLayout​(java.awt.Container target,
                             int axis)
        Parameters:
        target - the container that needs to be laid out
        axis - the axis to lay out components along. Can be one of: JideBoxLayout.X_AXIS, JideBoxLayout.Y_AXIS, JideBoxLayout.LINE_AXIS or JideBoxLayout.PAGE_AXIS
      • JideBoxLayout

        public JideBoxLayout​(java.awt.Container target,
                             int axis,
                             int gap)
        Parameters:
        target - the container that needs to be laid out
        axis - the axis to lay out components along. Can be one of: JideBoxLayout.X_AXIS, JideBoxLayout.Y_AXIS, JideBoxLayout.LINE_AXIS or JideBoxLayout.PAGE_AXIS
        gap - the gap
    • Method Detail

      • layoutContainer

        public void layoutContainer​(java.awt.Container container)
        Lays out the specified container.
        Specified by:
        layoutContainer in interface java.awt.LayoutManager
        Parameters:
        container - the container to be laid out
      • calculateComponentSizes

        protected boolean calculateComponentSizes​(int availableSize,
                                                  int startIndex,
                                                  int endIndex)
      • addLayoutComponent

        public void addLayoutComponent​(java.lang.String name,
                                       java.awt.Component component)
        If the layout manager uses a per-component string, adds the component comp to the layout, associating it with the string specified by name.
        Specified by:
        addLayoutComponent in interface java.awt.LayoutManager
        Parameters:
        name - the string to be associated with the component
        component - the component to be added
      • minimumLayoutSize

        public java.awt.Dimension minimumLayoutSize​(java.awt.Container container)
        Returns the minimum size needed to contain the children. The width is the sum of all the children min widths and the height is the largest of the children minimum heights.
        Specified by:
        minimumLayoutSize in interface java.awt.LayoutManager
      • preferredLayoutSize

        public java.awt.Dimension preferredLayoutSize​(java.awt.Container container)
        Returns the preferred size needed to contain the children. The width is the sum of all the children preferred widths and the height is the largest of the children preferred heights.
        Specified by:
        preferredLayoutSize in interface java.awt.LayoutManager
      • removeLayoutComponent

        public void removeLayoutComponent​(java.awt.Component comp)
        Removes the specified component from the layout.
        Specified by:
        removeLayoutComponent in interface java.awt.LayoutManager
        Parameters:
        comp - the component to be removed
      • addLayoutComponent

        public void addLayoutComponent​(java.awt.Component comp,
                                       java.lang.Object constraints)
        Adds the specified component to the layout, using the specified constraint object.
        Specified by:
        addLayoutComponent in interface java.awt.LayoutManager2
        Parameters:
        comp - the component to be added
        constraints - where/how the component is added to the layout.
      • getLayoutAlignmentX

        public float getLayoutAlignmentX​(java.awt.Container target)
        Returns the alignment along the x axis. This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc.
        Specified by:
        getLayoutAlignmentX in interface java.awt.LayoutManager2
      • getLayoutAlignmentY

        public float getLayoutAlignmentY​(java.awt.Container target)
        Returns the alignment along the y axis. This specifies how the component would like to be aligned relative to other components. The value should be a number between 0 and 1 where 0 represents alignment along the origin, 1 is aligned the furthest away from the origin, 0.5 is centered, etc.
        Specified by:
        getLayoutAlignmentY in interface java.awt.LayoutManager2
      • invalidateLayout

        public void invalidateLayout​(java.awt.Container c)
        Invalidates the layout, indicating that if the layout manager has cached information it should be discarded.
        Specified by:
        invalidateLayout in interface java.awt.LayoutManager2
      • componentCountChanged

        protected boolean componentCountChanged​(java.awt.Container c)
      • maximumLayoutSize

        public java.awt.Dimension maximumLayoutSize​(java.awt.Container target)
        Returns the maximum layout size, which is Integer.MAX_VALUE in both directions.
        Specified by:
        maximumLayoutSize in interface java.awt.LayoutManager2
      • getPreferredSizeOfComponent

        protected int getPreferredSizeOfComponent​(java.awt.Component c)
        Returns the width of the passed in Components preferred size.
        Parameters:
        c - the component
        Returns:
        the preferred size of the component.
      • getSizeOfComponent

        protected int getSizeOfComponent​(java.awt.Component c)
        Returns the width of the passed in component.
        Parameters:
        c - the component
        Returns:
        the size of the component.
      • getAvailableSize

        protected int getAvailableSize​(java.awt.Dimension containerSize,
                                       java.awt.Insets insets)
        Returns the available width based on the container size and Insets.
        Parameters:
        containerSize - the size of the container
        insets - the insets
        Returns:
        the available size.
      • getInitialLocation

        protected int getInitialLocation​(java.awt.Insets insets)
        Returns the left inset, unless the Insets are null in which case 0 is returned.
        Parameters:
        insets - the insets
        Returns:
        the initial location.
      • setComponentToSize

        protected void setComponentToSize​(java.awt.Component c,
                                          int size,
                                          int location,
                                          java.awt.Insets insets,
                                          java.awt.Dimension containerSize)
        Sets the width of the component c to be size, placing its x location at location, y to the insets.top and height to the containersize.height less the top and bottom insets.
        Parameters:
        c - the component
        size - the size of the component
        location - the location of the component
        insets - the insets of the component
        containerSize - the size of the container
      • getConstraintMap

        public java.util.Map<java.awt.Component,​java.lang.Object> getConstraintMap()
        Gets the map of constraints.
        Returns:
        the map of constraints
      • resolveAxis

        protected static int resolveAxis​(int axis,
                                         java.awt.ComponentOrientation o)
        Given one of the 4 axis values, resolve it to an absolute axis. The relative axis values, PAGE_AXIS and LINE_AXIS are converted to their absolute counterpart given the target's ComponentOrientation value. The absolute axes, X_AXIS and Y_AXIS are returned unmodified.
        Parameters:
        axis - the axis to resolve
        o - the ComponentOrientation to resolve against
        Returns:
        the resolved axis
      • getGap

        public int getGap()
        Gets the gap between each component.
        Returns:
        the gap between each component.
      • setGap

        public void setGap​(int gap)
        Sets the gap between each component. Make sure you cal doLayout() after you change the gap.
        Parameters:
        gap - the gap
      • getPreferredSizeOf

        protected java.awt.Dimension getPreferredSizeOf​(java.awt.Component comp,
                                                        int atIndex)
      • setResetWhenInvalidate

        public void setResetWhenInvalidate​(boolean resetWhenInvalidate)
        Sets the flag if the layout should be reset when invalidateLayout(java.awt.Container) is called.
        Parameters:
        resetWhenInvalidate - the flag
      • getAxis

        public int getAxis()
        Gets the axis.
        Returns:
        the axis.
      • setAxis

        public void setAxis​(int axis)
        Sets the axis. After changing the axis, you need to call doLayout method on the container which has this layout.
        Parameters:
        axis - the new axis.
      • isAlwaysLayout

        public boolean isAlwaysLayout()
        Checks if the alwaysLayout flag is true. If true, the layout manager will layout the components even there is no way to satisfy the minimum size requirements from all FIXED components. By default, it is true.
        Returns:
        true or false.
      • setAlwaysLayout

        public void setAlwaysLayout​(boolean alwaysLayout)
        Sets the alwaysLayout flag.
        Parameters:
        alwaysLayout - true to always layout components even there is no way to satisfy the minimum size requirements from all FIXED components.