Class CellGroup

  • All Implemented Interfaces:
    Serializable

    public class CellGroup
    extends Object
    implements Serializable

    A simple helper class to define columns and rows with identical size in PercentLayout.

    In GUI design it is often desirable that certain columns and rows have exactly the same size, independent from the components they contain. An example would be columns with labels that have a different width. With this class it is possible to define the indices of columns and rows that should have the same size.

    This class defines some convenience constructors for dealing with a limited number of cells. There is also a generic constructor which expects an array with cell indices. The numeric values passed to the constructors are interpreted as 0-based indices of columns and rows that have already been defined in PercentLayout. It is also possible to set the indices of the affected cells using a string format. Valid strings simply contain the numeric indices separated by one or more of the following characters: " ,;/". Examples for valid strings would be:

     "1 3 4"
     "1, 3,4"
     "1;3/4"  etc.
     

    CellGroup objects are immutable. There are no setter methods for manipulating instances once they have been created.

    Version:
    $Id: CellGroup.java 205 2012-01-29 18:29:57Z oheger $
    Author:
    Oliver Heger
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      CellGroup​(int idx1, int idx2)
      Creates a new instance of CellGroup.
      CellGroup​(int idx1, int idx2, int idx3)
      Creates a new instance of CellGroup.
      CellGroup​(int idx1, int idx2, int idx3, int idx4)
      Creates a new instance of CellGroup.
    • Constructor Detail

      • CellGroup

        public CellGroup​(int idx1,
                         int idx2)
        Creates a new instance of CellGroup. The group contains the two passed in cells.
        Parameters:
        idx1 - the index of the first cell
        idx2 - the index of the second cell
      • CellGroup

        public CellGroup​(int idx1,
                         int idx2,
                         int idx3)
        Creates a new instance of CellGroup. The group contains the three passed in cells.
        Parameters:
        idx1 - the index of the first cell
        idx2 - the index of the second cell
        idx3 - the index of the third cell
      • CellGroup

        public CellGroup​(int idx1,
                         int idx2,
                         int idx3,
                         int idx4)
        Creates a new instance of CellGroup. The group contains the four passed in cells.
        Parameters:
        idx1 - the index of the first cell
        idx2 - the index of the second cell
        idx3 - the index of the third cell
        idx4 - the index of the fourth cell
    • Method Detail

      • fromArray

        public static CellGroup fromArray​(int... idx)
        Creates a new instance of CellGroup and initializes it with the indices of the affected cells.
        Parameters:
        idx - an array with the cell indices
        Returns:
        the newly created CellGroup object
      • fromString

        public static CellGroup fromString​(String s)
        Creates a new instance of CellGroup and initializes it from the passed in string.
        Parameters:
        s - a string defining the cell indices
        Returns:
        the newly created CellGroup object
      • groupSize

        public int groupSize()
        Returns the number of elements contained in this group.
        Returns:
        the number of elements
      • apply

        public void apply​(int[] sizes)
        Applies this group object to the given cell sizes. This method checks the sizes of all cells that belong to this group and sets them to the maximum.
        Parameters:
        sizes - an array with the cell sizes (must not be null)
        Throws:
        IllegalArgumentException - if the array with sizes is null
        ArrayIndexOutOfBoundsException - if indices in this group are too big
      • buildString

        public void buildString​(StringBuilder buf)
        Appends a string representation of this object to the given string buffer. This string contains only the indices of this group separated by ",".
        Parameters:
        buf - the target buffer (must not be null)
        Throws:
        IllegalArgumentException - if the target buffer is null
      • toString

        public String toString()
        Creates a string representation of this object.
        Overrides:
        toString in class Object
        Returns:
        a string representation of this object
      • equals

        public boolean equals​(Object obj)
        Compares this object with another one. Two instances of CellGroup are equal if they contain the same indices (the order does not matter).
        Overrides:
        equals in class Object
        Parameters:
        obj - the object to compare to
        Returns:
        a flag whether these objects are equal
      • hashCode

        public int hashCode()
        Returns a hash code for this object.
        Overrides:
        hashCode in class Object
        Returns:
        a hash code