Class MigLayout

  • All Implemented Interfaces:
    java.io.Externalizable, java.io.Serializable

    public final class MigLayout
    extends org.eclipse.swt.widgets.Layout
    implements java.io.Externalizable
    A very flexible layout manager.

    Read the documentation that came with this layout manager for information on usage.

    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      MigLayout()
      Constructor with no constraints.
      MigLayout​(java.lang.String layoutConstraints)
      Constructor.
      MigLayout​(java.lang.String layoutConstraints, java.lang.String colConstraints)
      Constructor.
      MigLayout​(java.lang.String layoutConstraints, java.lang.String colConstraints, java.lang.String rowConstraints)
      Constructor.
      MigLayout​(LC layoutConstraints)
      Constructor.
      MigLayout​(LC layoutConstraints, AC colConstraints)
      Constructor.
      MigLayout​(LC layoutConstraints, AC colConstraints, AC rowConstraints)
      Constructor.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void addLayoutCallback​(LayoutCallback callback)
      Adds the callback function that will be called at different stages of the layout cycle.
      private void checkCache​(org.eclipse.swt.widgets.Composite parent)
      Check if something has changed and if so recreate it to the cached objects.
      private void checkConstrMap​(org.eclipse.swt.widgets.Composite parent)
      Checks so all components in ccMap actually exist in the parent's collection.
      private ContainerWrapper checkParent​(org.eclipse.swt.widgets.Composite parent)  
      protected org.eclipse.swt.graphics.Point computeSize​(org.eclipse.swt.widgets.Composite parent, int wHint, int hHint, boolean flushCache)  
      protected boolean flushCache​(org.eclipse.swt.widgets.Control control)  
      java.lang.Object getColumnConstraints()
      Returns the column layout constraints either as a String or AC.
      java.util.Map<org.eclipse.swt.widgets.Control,​java.lang.Object> getConstraintMap()
      Returns a shallow copy of the constraints map.
      private boolean getDebug()
      Returns the current debugging state.
      private int getDebugMillis()
      Returns the debug millis.
      float getLayoutAlignmentX​(org.eclipse.swt.widgets.Composite parent)  
      float getLayoutAlignmentY​(org.eclipse.swt.widgets.Composite parent)  
      java.lang.Object getLayoutConstraints()
      Returns layout constraints either as a String or LC depending what was sent in to the constructor or set with setLayoutConstraints(Object).
      java.lang.Object getRowConstraints()
      Returns the row layout constraints as a String representation.
      boolean isManagingComponent​(org.eclipse.swt.widgets.Control c)
      Returns if this layout manager is currently managing this component.
      protected void layout​(org.eclipse.swt.widgets.Composite parent, boolean flushCache)  
      void readExternal​(java.io.ObjectInput in)  
      private java.lang.Object readResolve()  
      void removeLayoutCallback​(LayoutCallback callback)
      Removes the callback if it exists.
      void setColumnConstraints​(java.lang.Object constr)
      Sets the column layout constraints for the layout manager instance as a String.
      private void setComponentConstraintsImpl​(org.eclipse.swt.widgets.Control comp, java.lang.Object constr, boolean noCheck)
      Sets the component constraint for the component that already must be handled by this layout manager.
      void setConstraintMap​(java.util.Map<org.eclipse.swt.widgets.Control,​java.lang.Object> map)
      Sets the constraints map.
      private void setDebug​(ComponentWrapper parentW, boolean b)
      Sets the debugging state for this layout manager instance.
      void setLayoutConstraints​(java.lang.Object s)
      Sets the layout constraints for the layout manager instance as a String.
      void setRowConstraints​(java.lang.Object constr)
      Sets the row layout constraints for the layout manager instance as a String.
      void writeExternal​(java.io.ObjectOutput out)  
      • Methods inherited from class java.lang.Object

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

      • scrConstrMap

        private final java.util.Map<org.eclipse.swt.widgets.Control,​java.lang.Object> scrConstrMap
        The component to String or CC constraints mappings.
      • layoutConstraints

        private java.lang.Object layoutConstraints
        Hold the serializable text representation of the constraints.
      • colConstraints

        private java.lang.Object colConstraints
        Hold the serializable text representation of the constraints.
      • rowConstraints

        private java.lang.Object rowConstraints
        Hold the serializable text representation of the constraints.
      • lc

        private transient LC lc
      • colSpecs

        private transient AC colSpecs
      • rowSpecs

        private transient AC rowSpecs
      • grid

        private transient Grid grid
      • debugTimer

        private transient java.util.Timer debugTimer
      • curDelay

        private transient long curDelay
      • lastModCount

        private transient int lastModCount
      • lastHash

        private transient int lastHash
      • callbackList

        private transient java.util.ArrayList<LayoutCallback> callbackList
    • Constructor Detail

      • MigLayout

        public MigLayout()
        Constructor with no constraints.
      • MigLayout

        public MigLayout​(java.lang.String layoutConstraints)
        Constructor.
        Parameters:
        layoutConstraints - The constraints that concern the whole layout. null will be treated as "".
      • MigLayout

        public MigLayout​(java.lang.String layoutConstraints,
                         java.lang.String colConstraints)
        Constructor.
        Parameters:
        layoutConstraints - The constraints that concern the whole layout. null will be treated as "".
        colConstraints - The constraints for the columns in the grid. null will be treated as "".
      • MigLayout

        public MigLayout​(java.lang.String layoutConstraints,
                         java.lang.String colConstraints,
                         java.lang.String rowConstraints)
        Constructor.
        Parameters:
        layoutConstraints - The constraints that concern the whole layout. null will be treated as "".
        colConstraints - The constraints for the columns in the grid. null will be treated as "".
        rowConstraints - The constraints for the rows in the grid. null will be treated as "".
      • MigLayout

        public MigLayout​(LC layoutConstraints)
        Constructor.
        Parameters:
        layoutConstraints - The constraints that concern the whole layout. null will be treated as an empty constraint.
      • MigLayout

        public MigLayout​(LC layoutConstraints,
                         AC colConstraints)
        Constructor.
        Parameters:
        layoutConstraints - The constraints that concern the whole layout. null will be treated as an empty constraint.
        colConstraints - The constraints for the columns in the grid. null will be treated as an empty constraint.
      • MigLayout

        public MigLayout​(LC layoutConstraints,
                         AC colConstraints,
                         AC rowConstraints)
        Constructor.
        Parameters:
        layoutConstraints - The constraints that concern the whole layout. null will be treated as an empty constraint.
        colConstraints - The constraints for the columns in the grid. null will be treated as an empty constraint.
        rowConstraints - The constraints for the rows in the grid. null will be treated as an empty constraint.
    • Method Detail

      • getLayoutConstraints

        public java.lang.Object getLayoutConstraints()
        Returns layout constraints either as a String or LC depending what was sent in to the constructor or set with setLayoutConstraints(Object).
        Returns:
        The layout constraints either as a String or LC depending what was sent in to the constructor or set with setLayoutConstraints(Object). Never null.
      • setLayoutConstraints

        public void setLayoutConstraints​(java.lang.Object s)
        Sets the layout constraints for the layout manager instance as a String.

        See the class JavaDocs for information on how this string is formatted.

        Parameters:
        s - The layout constraints as a String representation. null is converted to "" for storage.
        Throws:
        java.lang.RuntimeException - if the constraint was not valid.
      • getColumnConstraints

        public java.lang.Object getColumnConstraints()
        Returns the column layout constraints either as a String or AC.
        Returns:
        The column constraints either as a String or LC depending what was sent in to the constructor or set with setLayoutConstraints(Object). Never null.
      • setColumnConstraints

        public void setColumnConstraints​(java.lang.Object constr)
        Sets the column layout constraints for the layout manager instance as a String.

        See the class JavaDocs for information on how this string is formatted.

        Parameters:
        constr - The column layout constraints as a String representation. null is converted to "" for storage.
        Throws:
        java.lang.RuntimeException - if the constraint was not valid.
      • getRowConstraints

        public java.lang.Object getRowConstraints()
        Returns the row layout constraints as a String representation. This string is the exact string as set with setRowConstraints(Object) or sent into the constructor.

        See the class JavaDocs for information on how this string is formatted.

        Returns:
        The row layout constraints as a String representation. Never null.
      • setRowConstraints

        public void setRowConstraints​(java.lang.Object constr)
        Sets the row layout constraints for the layout manager instance as a String.

        See the class JavaDocs for information on how this string is formatted.

        Parameters:
        constr - The row layout constraints as a String representation. null is converted to "" for storage.
        Throws:
        java.lang.RuntimeException - if the constraint was not valid.
      • getConstraintMap

        public java.util.Map<org.eclipse.swt.widgets.Control,​java.lang.Object> getConstraintMap()
        Returns a shallow copy of the constraints map.
        Returns:
        A shallow copy of the constraints map. Never null.
      • setConstraintMap

        public void setConstraintMap​(java.util.Map<org.eclipse.swt.widgets.Control,​java.lang.Object> map)
        Sets the constraints map.
        Parameters:
        map - The map. Will be copied.
      • setComponentConstraintsImpl

        private void setComponentConstraintsImpl​(org.eclipse.swt.widgets.Control comp,
                                                 java.lang.Object constr,
                                                 boolean noCheck)
        Sets the component constraint for the component that already must be handled by this layout manager.

        See the class JavaDocs for information on how this string is formatted.

        Parameters:
        constr - The component constraints as a String or CC. null is ok.
        comp - The component to set the constraints for.
        noCheck - Doesn't check if control already is managed.
        Throws:
        java.lang.RuntimeException - if the constraint was not valid.
        java.lang.IllegalArgumentException - If the component is not handling the component.
      • isManagingComponent

        public boolean isManagingComponent​(org.eclipse.swt.widgets.Control c)
        Returns if this layout manager is currently managing this component.
        Parameters:
        c - The component to check. If null then false will be returned.
        Returns:
        If this layout manager is currently managing this component.
      • addLayoutCallback

        public void addLayoutCallback​(LayoutCallback callback)
        Adds the callback function that will be called at different stages of the layout cycle.
        Parameters:
        callback - The callback. Not null.
      • removeLayoutCallback

        public void removeLayoutCallback​(LayoutCallback callback)
        Removes the callback if it exists.
        Parameters:
        callback - The callback. May be null.
      • setDebug

        private void setDebug​(ComponentWrapper parentW,
                              boolean b)
        Sets the debugging state for this layout manager instance. If debug is turned on a timer will repaint the last laid out parent with debug information on top.

        Red fill and dashed dark red outline is used to indicate occupied cells in the grid. Blue dashed outline indicate component bounds set.

        Note that debug can also be set on the layout constraints. There it will be persisted. The value set here will not. See the class JavaDocs for information.

        Parameters:
        parentW - The parent. Never null.
        b - true means debug is turned on.
      • getDebug

        private boolean getDebug()
        Returns the current debugging state.
        Returns:
        The current debugging state.
      • checkCache

        private void checkCache​(org.eclipse.swt.widgets.Composite parent)
        Check if something has changed and if so recreate it to the cached objects.
        Parameters:
        parent - The parent that is the target for this layout manager.
      • checkConstrMap

        private void checkConstrMap​(org.eclipse.swt.widgets.Composite parent)
        Checks so all components in ccMap actually exist in the parent's collection. Removes any references that don't.
        Parameters:
        parent - The parent to compare ccMap against. Never null.
      • checkParent

        private ContainerWrapper checkParent​(org.eclipse.swt.widgets.Composite parent)
      • getLayoutAlignmentX

        public float getLayoutAlignmentX​(org.eclipse.swt.widgets.Composite parent)
      • getLayoutAlignmentY

        public float getLayoutAlignmentY​(org.eclipse.swt.widgets.Composite parent)
      • computeSize

        protected org.eclipse.swt.graphics.Point computeSize​(org.eclipse.swt.widgets.Composite parent,
                                                             int wHint,
                                                             int hHint,
                                                             boolean flushCache)
        Specified by:
        computeSize in class org.eclipse.swt.widgets.Layout
      • layout

        protected void layout​(org.eclipse.swt.widgets.Composite parent,
                              boolean flushCache)
        Specified by:
        layout in class org.eclipse.swt.widgets.Layout
      • flushCache

        protected boolean flushCache​(org.eclipse.swt.widgets.Control control)
        Overrides:
        flushCache in class org.eclipse.swt.widgets.Layout
      • readResolve

        private java.lang.Object readResolve()
                                      throws java.io.ObjectStreamException
        Throws:
        java.io.ObjectStreamException
      • readExternal

        public void readExternal​(java.io.ObjectInput in)
                          throws java.io.IOException,
                                 java.lang.ClassNotFoundException
        Specified by:
        readExternal in interface java.io.Externalizable
        Throws:
        java.io.IOException
        java.lang.ClassNotFoundException
      • writeExternal

        public void writeExternal​(java.io.ObjectOutput out)
                           throws java.io.IOException
        Specified by:
        writeExternal in interface java.io.Externalizable
        Throws:
        java.io.IOException