Class OverlapLayout

java.lang.Object
org.bidib.wizard.mvc.common.view.layout.OverlapLayout
All Implemented Interfaces:
LayoutManager, LayoutManager2, Serializable

public class OverlapLayout extends Object implements LayoutManager2, Serializable
The OverlapLayout class is a layout manager that lays out a container's components in an overlapping fashion. A component can be painted "above" or "below" the previous component in the container. Like the GridLayout, each component is sized to the largest width and height of any component in the container. The amount of overlap is controlled by specifying the overlap postion of each component. You can simulate, left-to-right, right-to-left, top-to-bottom, bottom-to-top and diagonal layouts. As well you can "stack" components completely on top of one another. In this case the components are sized to the space available in the container. A main usage for this layout might be in the creation of "card games". A few features have been added that might be handy in these cases: a) a "popup" feature - when a component is selected in can "popup" from its regular location so it visibly stands out. To accomplish this some extra space must be reserved in the container for the popup. This is done by using the setPopupInsets method which allow you to control the popup direction. In addition you can add/remove a simple constraint to the component. POP_UP will popup the component. POP_DOWN or null will paint the component in its regular location. b) when a component is made "invisible" you can reserve its location in the container so all the other components don't shift. Note: this layout is achieved by changing the ZOrder of components in the container. It will not work for all components as some compnents will always paint themselves on the top of others. This seems to happen with components like JButton as rollover effects are painted when a mouse moves over the components.
See Also:
  • Field Details

    • POP_UP

      public static Boolean POP_UP
    • POP_DOWN

      public static Boolean POP_DOWN
  • Constructor Details

    • OverlapLayout

      public OverlapLayout()
      Convenience constructor to provide for "stacking" of components. Each component will be stacked above the previous component and sized to fill the space of the parent container.
    • OverlapLayout

      public OverlapLayout(Point overlapPosition)
      Convenience constructor. Each component will overlap above the previous component.
      Parameters:
      overlapPosition - a Point defining the relative amount of overlap
    • OverlapLayout

      public OverlapLayout(Point overlapPosition, boolean overlapAbove)
      Create an overlapping layout.
      Parameters:
      overlapPosition - a Point defining the relative amount of overlap
      overlapAbove - when true components are painted above the previous component, otherwise they are painted below.
  • Method Details

    • convertIndex

      public int convertIndex(int index)
      When components are overlapped above the ZOrder of each component is changed resulting in the components position in the container being changed. For example when you add a component to the end of the container it will be moved to the beginning. If you then try to access the component using Component.componentAt(), you will get the first component, not the last. This method will convert the index to you access the proper component.
      Parameters:
      index - the index to convert
    • isIncludeInvisible

      public boolean isIncludeInvisible()
      Get the include invisible property
      Returns:
      returns the include invisible property
    • setIncludeInvisible

      public void setIncludeInvisible(boolean includeInvisible)
      Controls whether spaces should reserved for invisible components in the container
      Parameters:
      includeInvisible - when true, space is reserved otherwise the component is not included in the layout sizing
    • getOverlapPosition

      public Point getOverlapPosition()
      Get the overlapping position of each component
      Returns:
      returns the Point representing the overlapped position
    • setOverlapPosition

      public void setOverlapPosition(Point overlapPosition)
      Specify the position where the overlapped component should be painted.
      Parameters:
      overlapPosition - the position where the next component is painted
    • getPopupInsets

      public Insets getPopupInsets()
      Get the popup insets
      Returns:
      returns the popup insets
    • setPopupInsets

      public void setPopupInsets(Insets popupInsets)
      Define extra space to be reserved by the container. This will allow components to be "popped up" if required. Generally space would only be reserved on one side of the container.
      Parameters:
      popupInsets - Insets defining extra space for a particular side of the container.
    • getConstraints

      public Boolean getConstraints(Component component)
      Gets the constraints for the specified component.
      Parameters:
      component - the component to be queried
      Returns:
      the constraint for the specified component, or null if component is null or is not present in this layout
    • addLayoutComponent

      public void addLayoutComponent(String name, Component comp)
      Adds the specified component with the specified name to the layout.
      Specified by:
      addLayoutComponent in interface LayoutManager
      Parameters:
      name - the name of the component
      comp - the component to be added
    • addLayoutComponent

      public void addLayoutComponent(Component component, Object constraint)
      Specified by:
      addLayoutComponent in interface LayoutManager2
    • removeLayoutComponent

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

      public Dimension minimumLayoutSize(Container parent)
      Determine the minimum size on the Container
      Specified by:
      minimumLayoutSize in interface LayoutManager
      Parameters:
      parent - the container in which to do the layout
      Returns:
      the minimum dimensions needed to lay out the subcomponents of the specified container
    • preferredLayoutSize

      public Dimension preferredLayoutSize(Container parent)
      Determine the preferred size on the Container
      Specified by:
      preferredLayoutSize in interface LayoutManager
      Parameters:
      parent - the container in which to do the layout
      Returns:
      the preferred dimensions to lay out the subcomponents of the specified container
    • layoutContainer

      public void layoutContainer(Container parent)
      Lays out the specified container using this layout.

      Specified by:
      layoutContainer in interface LayoutManager
      Parameters:
      parent - the container in which to do the layout
    • maximumLayoutSize

      public Dimension maximumLayoutSize(Container target)
      There is no maximum.
      Specified by:
      maximumLayoutSize in interface LayoutManager2
    • getLayoutAlignmentX

      public float getLayoutAlignmentX(Container parent)
      Returns the alignment along the x axis. Use center alignment.
      Specified by:
      getLayoutAlignmentX in interface LayoutManager2
    • getLayoutAlignmentY

      public float getLayoutAlignmentY(Container parent)
      Returns the alignment along the y axis. Use center alignment.
      Specified by:
      getLayoutAlignmentY in interface LayoutManager2
    • invalidateLayout

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

      public String toString()
      Returns the string representation of this column layout's values.
      Overrides:
      toString in class Object
      Returns:
      a string representation of this grid layout