Class GridIterator

  • All Implemented Interfaces:
    PrintIterator

    public class GridIterator
    extends java.lang.Object
    implements PrintIterator
    Iterator for Grid
    • Field Detail

      • device

        final org.eclipse.swt.graphics.Device device
      • dpi

        final org.eclipse.swt.graphics.Point dpi
      • columnGroups

        final int[][] columnGroups
      • cellClippingEnabled

        final boolean cellClippingEnabled
      • minimumColSizes

        final int[] minimumColSizes
      • preferredColSizes

        final int[] preferredColSizes
      • minimumSize

        final org.eclipse.swt.graphics.Point minimumSize
      • preferredSize

        final org.eclipse.swt.graphics.Point preferredSize
      • row

        private int row
      • rowStarted

        private boolean rowStarted
    • Constructor Detail

      • GridIterator

        public GridIterator​(GridPrint grid,
                            org.eclipse.swt.graphics.Device device,
                            org.eclipse.swt.graphics.GC gc)
        Parameters:
        grid -
        device -
        gc -
      • GridIterator

        private GridIterator​(GridIterator that)
        Copy constructor (used by copy() only)
    • Method Detail

      • createGridCellIterators

        private static GridCellIterator[][] createGridCellIterators​(GridCell[][] gridCells,
                                                                    org.eclipse.swt.graphics.Device device,
                                                                    org.eclipse.swt.graphics.GC gc)
      • createRowCellIterators

        private static GridCellIterator[] createRowCellIterators​(GridCell[] rowCells,
                                                                 org.eclipse.swt.graphics.Device device,
                                                                 org.eclipse.swt.graphics.GC gc)
      • isExplicitSize

        private static boolean isExplicitSize​(GridColumn col)
      • applyColumnGrouping

        private void applyColumnGrouping​(int[] columnSizes)
      • isColumnGrouped

        private boolean isColumnGrouped​(int col)
      • computeColumnSizes

        private int[] computeColumnSizes​(PrintSizeStrategy strategy)
      • aggregateHeaderBodyAndFooterCells

        private GridCellIterator[][] aggregateHeaderBodyAndFooterCells()
      • calculateColumnWidthsForCellsSpanningMultipleColumns

        private void calculateColumnWidthsForCellsSpanningMultipleColumns​(int[] colSizes,
                                                                          GridCellIterator[][] rows,
                                                                          PrintSizeStrategy strategy)
      • resizeColumnsProportionateToCurrentSizes

        private void resizeColumnsProportionateToCurrentSizes​(int[] colSizes,
                                                              int[] columnIndices,
                                                              int adjustment,
                                                              int totalWidth)
      • resizeColumnsEqually

        private void resizeColumnsEqually​(int[] colSizes,
                                          int adjustment,
                                          int[] expandableColumns)
      • calculateColumnWidthsForCellsSpanningOneColumn

        private void calculateColumnWidthsForCellsSpanningOneColumn​(int[] colSizes,
                                                                    GridCellIterator[][] rows,
                                                                    PrintSizeStrategy strategy)
      • calculateExplicitlySizedColumnWidths

        private void calculateExplicitlySizedColumnWidths​(int[] colSizes)
      • getExpandableColumnIndices

        private int[] getExpandableColumnIndices​(int firstColumn,
                                                 int colspan)
      • computeSize

        private org.eclipse.swt.graphics.Point computeSize​(PrintSizeStrategy strategy,
                                                           int[] colSizes)
      • computeMaxBodyRowHeight

        private int computeMaxBodyRowHeight​(PrintSizeStrategy strategy)
      • minimumSize

        public org.eclipse.swt.graphics.Point minimumSize()
        Description copied from interface: PrintIterator
        Returns the minimum size PrintPiece that this Print should be broken into.

        Note that the size calculated by this method is a "preferred minimum," or the smallest size that the Print should normally be broken into. For a TextPrint, this is the size of the widest individual word, in pixels.

        This is distinct from the "absolute minimum," which is the smallest size that a Print could possibly be broken into. For a TextPrint, this is the size of the widest individual letter, in pixels.

        Specified by:
        minimumSize in interface PrintIterator
        Returns:
        a Point indicating the minimum size PrintPiece this PrintIterator should be broken into.
      • preferredSize

        public org.eclipse.swt.graphics.Point preferredSize()
        Description copied from interface: PrintIterator
        Returns the smallest size PrintPiece that this Print would be broken into if print space was unlimited.

        For a TextPrint, this is the size of the widest line (or the whole TextPrint, if there are no line breaks), in pixels.

        Specified by:
        preferredSize in interface PrintIterator
        Returns:
        a Point indicating the smallest size PrintPiece that this Print would be broken into if print space was unlimited.
      • findShrinkableColumns

        private int[] findShrinkableColumns​(int extraWidth)
      • findAllColumns

        private int[] findAllColumns()
      • computeColumnWidths

        private int[] computeColumnWidths​(int width)
      • expandPreferredColumnWidthsByWeight

        private int[] expandPreferredColumnWidthsByWeight​(int extraWidth)
      • expandMinimumColumnWidths

        private int[] expandMinimumColumnWidths​(int expansion)
      • computeMarginWidth

        private int computeMarginWidth()
      • reduceMinimumColumnWidths

        private int[] reduceMinimumColumnWidths​(int reduction)
      • hasNext

        public boolean hasNext()
        Description copied from interface: PrintIterator
        Identifies whether any PrintPieces remain.
        Specified by:
        hasNext in interface PrintIterator
        Returns:
        whether any PrintPieces remain.
      • rowContainsNonDefaultVertAlignment

        private static boolean rowContainsNonDefaultVertAlignment​(GridCellIterator[] cells)
      • isDefaultVerticalAlignment

        private static boolean isDefaultVerticalAlignment​(int vAlignment)
      • calculateCellWidths

        private int[] calculateCellWidths​(GridCellIterator[] cells,
                                          int[] columnWidths)
      • layoutCellsWithNonFillVertAlignment

        private static PrintPiece[] layoutCellsWithNonFillVertAlignment​(GridCellIterator[] cells,
                                                                        int height,
                                                                        boolean bottomOpen,
                                                                        int[] cellWidths)
      • layoutCellsWithFillVertAlignment

        private static PrintPiece[] layoutCellsWithFillVertAlignment​(GridCellIterator[] cells,
                                                                     int height,
                                                                     int[] cellWidths,
                                                                     PrintPiece[] cellPieces)
      • applyCellAlignment

        private void applyCellAlignment​(GridCellIterator[] cells,
                                        int[] cellWidths,
                                        PrintPiece[] pieces,
                                        int rowHeight,
                                        int[] xOffsets,
                                        int[] yOffsets)
      • resolveHorzAlignment

        private static int resolveHorzAlignment​(int cellAlignment,
                                                int columnAlignment)
      • getHorzAlignmentOffset

        private static int getHorzAlignmentOffset​(int alignment,
                                                  int pieceWidth,
                                                  int totalWidth)
      • getVertAlignmentOffset

        private static int getVertAlignmentOffset​(int alignment,
                                                  int pieceHeight,
                                                  int cellHeight)
      • createRowResult

        private static PrintPiece createRowResult​(PrintPiece[] pieces,
                                                  int[] xOffsets,
                                                  int[] yOffsets)
      • next

        public PrintPiece next​(int width,
                               int height)
        Description copied from interface: PrintIterator
        Returns the next PrintPiece for the Print.

        If all of the remaining contents of the Print will fit in the given space, the returned PrintPiece will include all remaining contents, and subsequent calls to PrintIterator.hasNext() will return false.

        If some, but not all of the remaining contents will fit in the given space, the returned PrintPiece will contain as much of the contents as possible, and subsequent calls to PrintIterator.hasNext() will return true.

        If there is insufficient space for any of the remaining contents in the given space, null is returned, and subsequent calls to PrintIterator.hasNext() will return true.

        If subsequent calls to PrintIterator#hasNext() return true, this PrintIterator cannot fit any more in the given print area. Future calls to this method should provide a fresh print area. At the top level, each returned PrintPiece contains an entire page.

        Note: PrintIterator classes should call PaperClips.next(PrintIterator, int, int) instead of calling this method directly, to gain automatic results checking to ensure all Print classes are well-behaved.

        Specified by:
        next in interface PrintIterator
        Parameters:
        width - the width available on the graphics device for this iteration.
        height - the height available on the graphics device for this iteration.
        Returns:
        a PrintPiece that paints the next part of the Print, or null if the print area is too small. The size of the returned PrintPiece must NOT exceed the width and height indicated.
      • nextHeaderPiece

        private PrintPiece nextHeaderPiece​(int[] colSizes,
                                           int height,
                                           int[] rowHeights,
                                           int[][] colSpans)
      • nextFooterPiece

        private PrintPiece nextFooterPiece​(int[] colSizes,
                                           int height,
                                           int[] rowHeights,
                                           int[][] colSpans)
      • nextHeaderOrFooterPiece

        private PrintPiece nextHeaderOrFooterPiece​(int[] colSizes,
                                                   int height,
                                                   int[] rowHeights,
                                                   int[][] colSpans,
                                                   int rowSpacing,
                                                   GridCellIterator[][] headerOrFooter)
      • nextBodyPiece

        private PrintPiece nextBodyPiece​(int[] colSizes,
                                         int height,
                                         java.util.List<java.lang.Integer> rowHeights,
                                         java.util.List<int[]> colSpans,
                                         boolean footerPresent)
      • createResult

        private PrintPiece createResult​(int[] colSizes,
                                        PrintPiece headerPiece,
                                        int[] headerRows,
                                        int[][] headerColSpans,
                                        int firstRow,
                                        boolean topOpen,
                                        PrintPiece bodyPiece,
                                        int[] bodyRows,
                                        int[][] bodyColSpans,
                                        boolean bottomOpen,
                                        PrintPiece footerPiece,
                                        int[] footerRows,
                                        int[][] footerColSpans)
      • copy

        public PrintIterator copy()
        Description copied from interface: PrintIterator
        Returns a copy of this PrintIterator, with all relevant internal states. This method allows a containing iterator to "back up" the current state of its child iterators before invoking next(int, int) on them. The containing iterator can then safely attempt iterating its child(ren) in a variety of ways before selecting which way is the most appropriate.
        Specified by:
        copy in interface PrintIterator
        Returns:
        a deep clone of the target with all relevant internal states.