Class GridPrint

java.lang.Object
org.eclipse.nebula.paperclips.core.grid.GridPrint
All Implemented Interfaces:
Print

public final class GridPrint
extends java.lang.Object
implements Print
A Print which arranges child prints into a grid. A grid is initialized with a series of GridColumns, and child prints are laid out into those columns by invoking the add(...) methods.

GridPrint uses a column sizing algorithm based on the W3C recommendation for automatic layout of tables. GridPrint deviates from the recommendation on one important point: if there is less width available on the print device than the calculated "minimum" size of the grid, the columns will be scaled down to less than their calculated minimum widths. Only when one of the columns goes below its "absolute minimum" will the grid fail to print ( PrintIterator.next(int, int) returns null).

GridPrint offers three basic methods of specifying column size.

  1. Default size. The column will be somewhere between it's minimum and preferred width. GridPrint will determine the optimum widths for all default size columns, using the modified W3C recommendation described above. This is the recommended option for most cases.
  2. Preferred size. The column will be sized to it's preferred width. This option is sometimes appropriate, for example when certain portions of text should not be allowed to line-wrap. In cases where only a few cells in a column need to be prevented from line wrapping, consider wrapping them in a NoBreakPrint instead.
  3. Explicit size. The column will be the size you specify, expressed in points. 72 points = 1".
Example: GridPrint grid = new GridPrint("d, p, 72pts");

In addition, any column can be given a grow attribute. In the event a grid is not as wide as the page, those columns with the grow attribute set will be widened to fill the extra space.

Because GridPrint scales columns according to their minimum sizes in the worst-case scenario, the absolute minimum size of a GridPrint is dependant on its child prints and is not clearly defined.

If a grid has one of more columns with the grow attribute set, the grid is horizontally greedy. Greedy prints take up all the available space on the page.

See Also:
GridColumn, PrintIterator.minimumSize(), PrintIterator.preferredSize()
  • Field Summary

    Fields 
    Modifier and Type Field Description
    (package private) java.util.List<java.util.List<GridCell>> body
    Two-dimensional list of all body cells.
    static int BORDER_OVERLAP
    Constant cell spacing value indicating that the borders of adjacent cells should overlap.
    (package private) boolean cellClippingEnabled  
    (package private) int[][] columnGroups
    Array of column groups.
    (package private) java.util.List<GridColumn> columns
    The columns for this grid.
    (package private) java.util.List<java.util.List<GridCell>> footer
    Two-dimension list of all footer cells.
    (package private) java.util.List<java.util.List<GridCell>> header
    Two-dimension list of all header cells.
    static int PREFERRED
    Constant column size value indicating that the column should be given its preferred size.
    static int REMAINDER
    Constant colspan value indicating that all remaining columns in the row should be used.
  • Constructor Summary

    Constructors 
    Constructor Description
    GridPrint()
    Constructs a GridPrint with no columns and a default look.
    GridPrint​(java.lang.String columns)
    Constructs a GridPrint with the given columns and a default look.
    GridPrint​(java.lang.String columns, GridLook look)
    Constructs a GridPrint with the given columns and look.
    GridPrint​(GridColumn[] columns)
    Constructs a GridPrint with the given columns and a default look.
    GridPrint​(GridColumn[] columns, GridLook look)
    Constructs a GridPrint with the given columns and look.
    GridPrint​(GridLook look)
    Constructs a GridPrint with no columns and the given look.
  • Method Summary

    Modifier and Type Method Description
    void add​(int hAlignment, int vAlignment, Print cell)
    Adds the Print to the grid body, using the given colspan and alignment.
    void add​(int hAlignment, int vAlignment, Print cell, int colspan)
    Adds the Print to the grid body, using the given colspan and alignment.
    void add​(int hAlignment, Print cell)
    Adds the Print to the grid body, using the given colspan and alignment.
    void add​(int hAlignment, Print cell, int colspan)
    Adds the Print to the grid body, using the given colspan and alignment.
    void add​(Print cell)
    Adds the Print to the grid body, with the default alignment and a colspan of 1.
    void add​(Print cell, int colspan)
    Adds the Print to the grid body, with the given colspan and the default alignment.
    void addColumn​(int index, java.lang.String column)
    Inserts the column at the specified position in the grid.
    void addColumn​(int index, GridColumn column)
    Inserts the column at the specified position in the grid.
    void addColumn​(java.lang.String column)
    Adds the column on the right edge of the grid.
    void addColumn​(GridColumn column)
    Adds the column on the right edge of the grid.
    void addColumns​(int index, java.lang.String columns)
    Inserts the columns at the specified position in the grid.
    void addColumns​(int index, GridColumn[] columns)
    Inserts the columns at the specified position in the grid.
    void addColumns​(java.lang.String columns)
    Adds the columns on the right edge of the grid.
    void addColumns​(GridColumn[] columns)
    Adds the columns on the right edge of the grid.
    void addFooter​(int hAlignment, int vAlignment, Print cell)
    Adds the Print to the grid footer, using the given colspan and alignment.
    void addFooter​(int hAlignment, int vAlignment, Print cell, int colspan)
    Adds the Print to the grid footer, using the given colspan and alignment.
    void addFooter​(int hAlignment, Print cell)
    Adds the Print to the grid footer, using the given colspan and alignment.
    void addFooter​(int hAlignment, Print cell, int colspan)
    Adds the Print to the grid footer, using the given colspan and alignment.
    void addFooter​(Print cell)
    Adds the Print to the grid footer, with the default alignment and a colspan of 1.
    void addFooter​(Print cell, int colspan)
    Adds the Print to the grid footer, with the given colspan and the default alignment.
    void addHeader​(int hAlignment, int vAlignment, Print cell)
    Adds the Print to the grid header, using the given alignment.
    void addHeader​(int hAlignment, int vAlignment, Print cell, int colspan)
    Adds the Print to the grid header, using the given colspan and alignment.
    void addHeader​(int hAlignment, Print cell)
    Adds the Print to the grid header, using the given alignment.
    void addHeader​(int hAlignment, Print cell, int colspan)
    Adds the Print to the grid header, using the given colspan and alignment.
    void addHeader​(Print cell)
    Adds the Print to the grid header, with default alignment and a colspan of 1.
    void addHeader​(Print cell, int colspan)
    Adds the Print to the grid header, with the given colspan and the default alignment.
    boolean equals​(java.lang.Object obj)  
    GridCell[][] getBodyCells()
    Returns an array containing the body cells in the grid.
    int[][] getColumnGroups()
    Returns current column groups.
    GridColumn[] getColumns()
    Returns an array of GridColumns which are the columns in the receiver.
    GridCell[][] getFooterCells()
    Returns an array containing the footer cells in the grid.
    GridCell[][] getHeaderCells()
    Returns an array containing the header cells in this grid.
    GridLook getLook()
    Returns the grid's look.
    int hashCode()  
    boolean isCellClippingEnabled()
    Returns whether individual body cells in the grid may be broken across pages.
    PrintIterator iterator​(org.eclipse.swt.graphics.Device device, org.eclipse.swt.graphics.GC gc)
    Returns a PrintIterator for laying out the contents of this Print.
    void setCellClippingEnabled​(boolean cellClippingEnabled)
    Sets whether individual body cells in the grid may be broken across pages.
    void setColumnGroups​(int[][] columnGroups)
    Sets the column groups to the given two-dimension array.
    void setLook​(GridLook look)
    Sets the grid's look.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • REMAINDER

      public static final int REMAINDER
      Constant colspan value indicating that all remaining columns in the row should be used.
      See Also:
      Constant Field Values
    • PREFERRED

      public static final int PREFERRED
      Constant column size value indicating that the column should be given its preferred size. (In the context of W3C's autolayout recommendation, this has the effect of setting the columns minimum width to its preferred width. This value is used in the GridColumn constructor.
      See Also:
      Constant Field Values
    • BORDER_OVERLAP

      public static final int BORDER_OVERLAP
      Constant cell spacing value indicating that the borders of adjacent cells should overlap.
      See Also:
      Constant Field Values
    • columns

      final java.util.List<GridColumn> columns
      The columns for this grid.
    • columnGroups

      int[][] columnGroups
      Array of column groups.
    • header

      final java.util.List<java.util.List<GridCell>> header
      Two-dimension list of all header cells. Each element of this list represents a row in the header. Each element of a row represents a cellspan in that row.
    • body

      final java.util.List<java.util.List<GridCell>> body
      Two-dimensional list of all body cells. Each element of this list represents a row in the body. Each element of a row represents a cellspan in that row.
    • cellClippingEnabled

      boolean cellClippingEnabled
    • footer

      final java.util.List<java.util.List<GridCell>> footer
      Two-dimension list of all footer cells. Each element of this list represents a row in the footer. Each element of a row represents a cellspan in that row.
  • Constructor Details

    • GridPrint

      public GridPrint()
      Constructs a GridPrint with no columns and a default look.
    • GridPrint

      public GridPrint​(GridLook look)
      Constructs a GridPrint with no columns and the given look.
      Parameters:
      look - the look to apply to the constructed grid.
    • GridPrint

      public GridPrint​(java.lang.String columns)
      Constructs a GridPrint with the given columns and a default look.
      Parameters:
      columns - a comma-separated list of parseable column specs.
      See Also:
      GridColumn.parse(String)
    • GridPrint

      public GridPrint​(java.lang.String columns, GridLook look)
      Constructs a GridPrint with the given columns and look.
      Parameters:
      columns - a comma-separated list of parseable column specs.
      look - the look to apply to the constructed grid.
      See Also:
      GridColumn.parse(String)
    • GridPrint

      public GridPrint​(GridColumn[] columns)
      Constructs a GridPrint with the given columns and a default look.
      Parameters:
      columns - the columns for the new grid.
    • GridPrint

      public GridPrint​(GridColumn[] columns, GridLook look)
      Constructs a GridPrint with the given columns and look.
      Parameters:
      columns - the columns for the new grid.
      look - the look to apply to the constructed grid.
  • Method Details

    • hashCode

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

      public boolean equals​(java.lang.Object obj)
      Overrides:
      equals in class java.lang.Object
    • addColumn

      public void addColumn​(java.lang.String column)
      Adds the column on the right edge of the grid. Any cells which have been added to the grid prior to adding the column will be adjusted as follows: the right-hand cell of each completed row will have it's colspan expanded to fill the added column.
      Parameters:
      column - the column to add to the grid.
      See Also:
      GridColumn.parse(String)
    • addColumn

      public void addColumn​(GridColumn column)
      Adds the column on the right edge of the grid. Any cells which have been added to the grid prior to adding the column will be adjusted as follows: the right-hand cell of each completed row will have it's colspan expanded to fill the added column.
      Parameters:
      column - the column to add to the grid.
    • addColumn

      public void addColumn​(int index, java.lang.String column)
      Inserts the column at the specified position in the grid. Any cells which have been added to the grid prior to adding the column will be adjusted as follows: on each row, the cell which overlaps or whose right edge touches the insert position will be expanded to fill the added column.
      Parameters:
      index - the insert position.
      column - the column to be inserted.
      See Also:
      GridColumn.parse(String)
    • addColumn

      public void addColumn​(int index, GridColumn column)
      Inserts the column at the specified position in the grid. Any cells which have been added to the grid prior to adding the column will be adjusted as follows: on each row, the cell which overlaps or whose right edge touches the insert position will be expanded to fill the added column.
      Parameters:
      index - the insert position.
      column - the column to be inserted.
    • addColumns

      public void addColumns​(java.lang.String columns)
      Adds the columns on the right edge of the grid. Any cells which have been added to the grid prior to adding the columns will be adjusted as follows: the right-hand cell of each completed row will have it's colspan expanded to fill the added columns.
      Parameters:
      columns - the columns to add to the grid.
      See Also:
      GridColumn.parse(String)
    • addColumns

      public void addColumns​(GridColumn[] columns)
      Adds the columns on the right edge of the grid. Any cells which have been added to the grid prior to adding the columns will be adjusted as follows: the right-hand cell of each completed row will have it's colspan expanded to fill the added columns.
      Parameters:
      columns - the columns to add to the grid.
    • addColumns

      public void addColumns​(int index, java.lang.String columns)
      Inserts the columns at the specified position in the grid. Any cells which have been added to the grid prior to adding the columns will be adjusted as follows: on each row, the cell which overlaps or whose right edge touches the insert position will be expanded to fill the added columns.
      Parameters:
      index - the insert position.
      columns - the columns to be inserted.
      See Also:
      GridColumn.parse(String)
    • addColumns

      public void addColumns​(int index, GridColumn[] columns)
      Inserts the columns at the specified position in the grid. Any cells which have been added to the grid prior to adding the columns will be adjusted as follows: on each row, the cell which overlaps or whose right edge touches the insert position will be expanded to fill the added columns.
      Parameters:
      index - the insert position.
      columns - the columns to be inserted.
      See Also:
      GridColumn.parse(String)
    • getColumns

      public GridColumn[] getColumns()
      Returns an array of GridColumns which are the columns in the receiver.
      Returns:
      an array of GridColumns which are the columns in the receiver.
    • addHeader

      public void addHeader​(Print cell)
      Adds the Print to the grid header, with default alignment and a colspan of 1.
      Parameters:
      cell - the print to add.
    • addHeader

      public void addHeader​(int hAlignment, Print cell)
      Adds the Print to the grid header, using the given alignment.
      Parameters:
      hAlignment - the horizontal alignment of the print within the grid cell. One of SWT.DEFAULT , SWT.LEFT, SWT.CENTER or SWT.RIGHT.
      cell - the print to add.
    • addHeader

      public void addHeader​(int hAlignment, int vAlignment, Print cell)
      Adds the Print to the grid header, using the given alignment.
      Parameters:
      hAlignment - the horizontal alignment of the print within the grid cell. One of SWT.DEFAULT , SWT.LEFT, SWT.CENTER or SWT.RIGHT.
      vAlignment - the vertical alignment of the print within the grid cell. One of SWT.DEFAULT, SWT.TOP, SWT.CENTER, SWT.BOTTOM, or SWT.FILL. A value of FILL indicates that the cell is vertically greedy, so GridPrint will limit the cell's height to the tallest non-FILL cell in the row.
      cell - the print to add.
    • addHeader

      public void addHeader​(Print cell, int colspan)
      Adds the Print to the grid header, with the given colspan and the default alignment.
      Parameters:
      cell - the print to add.
      colspan - the number of columns to span, or REMAINDER to span the rest of the row.
    • addHeader

      public void addHeader​(int hAlignment, Print cell, int colspan)
      Adds the Print to the grid header, using the given colspan and alignment.
      Parameters:
      cell - the print to add.
      colspan - the number of columns to span, or REMAINDER to span the rest of the row.
      hAlignment - the horizontal alignment of the print within the grid cell. One of SWT.DEFAULT , SWT.LEFT, SWT.CENTER or SWT.RIGHT.
    • addHeader

      public void addHeader​(int hAlignment, int vAlignment, Print cell, int colspan)
      Adds the Print to the grid header, using the given colspan and alignment.
      Parameters:
      hAlignment - the horizontal alignment of the print within the grid cell. One of SWT.DEFAULT , SWT.LEFT, SWT.CENTER or SWT.RIGHT.
      vAlignment - the vertical alignment of the print within the grid cell. One of SWT.DEFAULT, SWT.TOP, SWT.CENTER, SWT.BOTTOM, or SWT.FILL. A value of FILL indicates that the cell is vertically greedy, so GridPrint will limit the cell's height to the tallest non-FILL cell in the row.
      cell - the print to add.
      colspan - the number of columns to span, or REMAINDER to span the rest of the row.
    • getHeaderCells

      public GridCell[][] getHeaderCells()
      Returns an array containing the header cells in this grid. Each inner array represents one row in the header.
      Returns:
      an array containing the header cells in this grid.
    • getBodyCells

      public GridCell[][] getBodyCells()
      Returns an array containing the body cells in the grid. Each inner array represents one row in the body.
      Returns:
      an array containing the body cells in the grid.
    • getFooterCells

      public GridCell[][] getFooterCells()
      Returns an array containing the footer cells in the grid. Each inner array represents one row in the footer.
      Returns:
      an array containing the footer cells in the grid.
    • add

      public void add​(Print cell)
      Adds the Print to the grid body, with the default alignment and a colspan of 1.
      Parameters:
      cell - the print to add.
    • add

      public void add​(int hAlignment, Print cell)
      Adds the Print to the grid body, using the given colspan and alignment.
      Parameters:
      hAlignment - the horizontal alignment of the print within the grid cell. One of SWT.DEFAULT , SWT.LEFT, SWT.CENTER or SWT.RIGHT.
      cell - the print to add.
    • add

      public void add​(int hAlignment, int vAlignment, Print cell)
      Adds the Print to the grid body, using the given colspan and alignment.
      Parameters:
      hAlignment - the horizontal alignment of the print within the grid cell. One of SWT.DEFAULT , SWT.LEFT, SWT.CENTER or SWT.RIGHT.
      vAlignment - the vertical alignment of the print within the grid cell. One of SWT.DEFAULT, SWT.TOP, SWT.CENTER, SWT.BOTTOM, or SWT.FILL. A value of FILL indicates that the cell is vertically greedy, so GridPrint will limit the cell's height to the tallest non-FILL cell in the row.
      cell - the print to add.
    • add

      public void add​(Print cell, int colspan)
      Adds the Print to the grid body, with the given colspan and the default alignment.
      Parameters:
      cell - the print to add.
      colspan - the number of columns to span, or REMAINDER to span the rest of the row.
    • add

      public void add​(int hAlignment, Print cell, int colspan)
      Adds the Print to the grid body, using the given colspan and alignment.
      Parameters:
      hAlignment - the horizontal alignment of the print within the grid cell. One of SWT.DEFAULT , SWT.LEFT, SWT.CENTER or SWT.RIGHT.
      cell - the print to add.
      colspan - the number of columns to span, or REMAINDER to span the rest of the row.
    • add

      public void add​(int hAlignment, int vAlignment, Print cell, int colspan)
      Adds the Print to the grid body, using the given colspan and alignment.
      Parameters:
      hAlignment - the horizontal alignment of the print within the grid cell. One of SWT.DEFAULT , SWT.LEFT, SWT.CENTER or SWT.RIGHT.
      vAlignment - the vertical alignment of the print within the grid cell. One of SWT.DEFAULT, SWT.TOP, SWT.CENTER, SWT.BOTTOM, or SWT.FILL. A value of FILL indicates that the cell is vertically greedy, so GridPrint will limit the cell's height to the tallest non-FILL cell in the row.
      cell - the print to add.
      colspan - the number of columns to span, or REMAINDER to span the rest of the row.
    • isCellClippingEnabled

      public boolean isCellClippingEnabled()
      Returns whether individual body cells in the grid may be broken across pages. Defaults to true.
      Returns:
      whether individual body cells in the grid may be broken across pages.
    • setCellClippingEnabled

      public void setCellClippingEnabled​(boolean cellClippingEnabled)
      Sets whether individual body cells in the grid may be broken across pages.
      Parameters:
      cellClippingEnabled - whether to enabled cell clipping.
    • addFooter

      public void addFooter​(Print cell)
      Adds the Print to the grid footer, with the default alignment and a colspan of 1.
      Parameters:
      cell - the print to add.
    • addFooter

      public void addFooter​(int hAlignment, Print cell)
      Adds the Print to the grid footer, using the given colspan and alignment.
      Parameters:
      hAlignment - the horizontal alignment of the print within the grid cell. One of SWT.DEFAULT , SWT.LEFT, SWT.CENTER or SWT.RIGHT.
      cell - the print to add.
    • addFooter

      public void addFooter​(int hAlignment, int vAlignment, Print cell)
      Adds the Print to the grid footer, using the given colspan and alignment.
      Parameters:
      hAlignment - the horizontal alignment of the print within the grid cell. One of SWT.DEFAULT , SWT.LEFT, SWT.CENTER or SWT.RIGHT.
      vAlignment - the vertical alignment of the print within the grid cell. One of SWT.DEFAULT, SWT.TOP, SWT.CENTER, SWT.BOTTOM, or SWT.FILL. A value of FILL indicates that the cell is vertically greedy, so GridPrint will limit the cell's height to the tallest non-FILL cell in the row.
      cell - the print to add.
    • addFooter

      public void addFooter​(Print cell, int colspan)
      Adds the Print to the grid footer, with the given colspan and the default alignment.
      Parameters:
      cell - the print to add.
      colspan - the number of columns to span, or REMAINDER to span the rest of the row.
    • addFooter

      public void addFooter​(int hAlignment, Print cell, int colspan)
      Adds the Print to the grid footer, using the given colspan and alignment.
      Parameters:
      hAlignment - the horizontal alignment of the print within the grid cell. One of SWT.DEFAULT , SWT.LEFT, SWT.CENTER or SWT.RIGHT.
      cell - the print to add.
      colspan - the number of columns to span, or REMAINDER to span the rest of the row.
    • addFooter

      public void addFooter​(int hAlignment, int vAlignment, Print cell, int colspan)
      Adds the Print to the grid footer, using the given colspan and alignment.
      Parameters:
      hAlignment - the horizontal alignment of the print within the grid cell. One of SWT.DEFAULT , SWT.LEFT, SWT.CENTER or SWT.RIGHT.
      vAlignment - the vertical alignment of the print within the grid cell. One of SWT.DEFAULT, SWT.TOP, SWT.CENTER, SWT.BOTTOM, or SWT.FILL. A value of FILL indicates that the cell is vertically greedy, so GridPrint will limit the cell's height to the tallest non-FILL cell in the row.
      cell - the print to add.
      colspan - the number of columns to span, or REMAINDER to span the rest of the row.
    • getColumnGroups

      public int[][] getColumnGroups()
      Returns current column groups. The returned array may be modified without affecting this GridPrint.
      Returns:
      the column groups.
    • setColumnGroups

      public void setColumnGroups​(int[][] columnGroups)
      Sets the column groups to the given two-dimension array. Each int[] array is a group. Columns in a group will be the same size when laid out on the print device.

      The following statement causes columns 0 and 2 to be the same size, and columns 1 and 3 to be the same size.

       grid.setColumnGroups(new int[][] { { 0, 2 }, { 1, 3 } });
       

      The behavior of this property is undefined when a column belongs to more than one group.

      Note: Column grouping is enforced before column weights. Therefore, columns in the same group should be given the same weight to ensure they are laid out at the same width.

      Parameters:
      columnGroups - the new column groups.
    • getLook

      public GridLook getLook()
      Returns the grid's look. A GridLook determines what decorations will appear around the grid's contents. Default is a DefaultGridLook with no cell spacing, no cell borders, and no background colors.
      Returns:
      the look of this grid.
    • setLook

      public void setLook​(GridLook look)
      Sets the grid's look.
      Parameters:
      look - the new look.
    • iterator

      public PrintIterator iterator​(org.eclipse.swt.graphics.Device device, org.eclipse.swt.graphics.GC gc)
      Description copied from interface: Print
      Returns a PrintIterator for laying out the contents of this Print. The iterator uses a snapshot of the print at the time this method is invoked, so subsequent changes to the Print will not affect the output of the iterator.
      Specified by:
      iterator in interface Print
      Parameters:
      device - the graphics device this Print will be drawn onto.
      gc - the graphics context to be used for calculating layout and drawing the Print's contents.
      Returns:
      a PrintIterator for laying out the contents of this Print.