Class GridIterator
- java.lang.Object
-
- org.eclipse.nebula.paperclips.core.grid.internal.GridIterator
-
- All Implemented Interfaces:
PrintIterator
public class GridIterator extends java.lang.Object implements PrintIterator
Iterator for Grid
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static interface
GridIterator.Condition
-
Field Summary
Fields Modifier and Type Field Description (package private) GridCellIterator[][]
body
(package private) boolean
cellClippingEnabled
(package private) int[][]
columnGroups
(package private) GridColumn[]
columns
(package private) org.eclipse.swt.graphics.Device
device
(package private) org.eclipse.swt.graphics.Point
dpi
(package private) GridCellIterator[][]
footer
(package private) GridCellIterator[][]
header
(package private) GridLookPainter
look
(package private) int[]
minimumColSizes
(package private) org.eclipse.swt.graphics.Point
minimumSize
(package private) int[]
preferredColSizes
(package private) org.eclipse.swt.graphics.Point
preferredSize
private int
row
private boolean
rowStarted
-
Constructor Summary
Constructors Modifier Constructor Description GridIterator(GridPrint grid, org.eclipse.swt.graphics.Device device, org.eclipse.swt.graphics.GC gc)
private
GridIterator(GridIterator that)
Copy constructor (used by copy() only)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private GridCellIterator[][]
aggregateHeaderBodyAndFooterCells()
private void
applyCellAlignment(GridCellIterator[] cells, int[] cellWidths, PrintPiece[] pieces, int rowHeight, int[] xOffsets, int[] yOffsets)
private void
applyColumnGrouping(int[] columnSizes)
private int[]
calculateCellWidths(GridCellIterator[] cells, int[] columnWidths)
private void
calculateColumnWidthsForCellsSpanningMultipleColumns(int[] colSizes, GridCellIterator[][] rows, PrintSizeStrategy strategy)
private void
calculateColumnWidthsForCellsSpanningOneColumn(int[] colSizes, GridCellIterator[][] rows, PrintSizeStrategy strategy)
private void
calculateExplicitlySizedColumnWidths(int[] colSizes)
private static int
calculateRowHeight(PrintPiece[] cellPieces, GridCellIterator[] cells)
private static GridCellIterator[]
cloneRow(GridCellIterator[] row)
private static GridCellIterator[][]
cloneRows(GridCellIterator[][] rows, int firstRow)
private int
computeCellWidth(GridCellIterator entry, GridColumn col, PrintSizeStrategy strategy)
Compute the size of a column, respecting the constraints of the GridColumn.private int[]
computeColumnSizes(PrintSizeStrategy strategy)
private int[]
computeColumnWidths(int width)
private int
computeFooterHeight(PrintSizeStrategy strategy, GridMargins margins)
private int
computeHeaderHeight(GridMargins margins, PrintSizeStrategy strategy)
private int
computeMarginWidth()
private int
computeMaxBodyRowHeight(PrintSizeStrategy strategy)
private org.eclipse.swt.graphics.Point
computeSize(PrintSizeStrategy strategy, int[] colSizes)
PrintIterator
copy()
Returns a copy of this PrintIterator, with all relevant internal states.private static GridCellIterator[][]
createGridCellIterators(GridCell[][] gridCells, org.eclipse.swt.graphics.Device device, org.eclipse.swt.graphics.GC gc)
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)
private static GridCellIterator[]
createRowCellIterators(GridCell[] rowCells, org.eclipse.swt.graphics.Device device, org.eclipse.swt.graphics.GC gc)
private static PrintPiece
createRowResult(PrintPiece[] pieces, int[] xOffsets, int[] yOffsets)
private int[]
expandMinimumColumnWidths(int expansion)
private int[]
expandPreferredColumnWidthsByWeight(int extraWidth)
private int[]
findAllColumns()
private int[]
findColumns(int start, int count, GridIterator.Condition condition)
private int[]
findColumns(GridIterator.Condition condition)
private int[]
findShrinkableColumns(int extraWidth)
private GridIterator.Condition[]
getExpandableColumnConditions()
private int[]
getExpandableColumnIndices(int firstColumn, int colspan)
private static int
getHorzAlignmentOffset(int alignment, int pieceWidth, int totalWidth)
private GridIterator.Condition[]
getShrinkableColumnConditions()
private static int
getVertAlignmentOffset(int alignment, int pieceHeight, int cellHeight)
boolean
hasNext()
Identifies whether any PrintPieces remain.private static boolean
hasNext(GridCellIterator[] cells)
private boolean
isColumnGrouped(int col)
private static boolean
isDefaultVerticalAlignment(int vAlignment)
private static boolean
isExplicitSize(GridColumn col)
private static PrintPiece[]
layoutCellsWithFillVertAlignment(GridCellIterator[] cells, int height, int[] cellWidths, PrintPiece[] cellPieces)
private static PrintPiece[]
layoutCellsWithNonFillVertAlignment(GridCellIterator[] cells, int height, boolean bottomOpen, int[] cellWidths)
org.eclipse.swt.graphics.Point
minimumSize()
Returns the minimum size PrintPiece that this Print should be broken into.PrintPiece
next(int width, int height)
Returns the next PrintPiece for the Print.private PrintPiece
nextBodyPiece(int[] colSizes, int height, java.util.List<java.lang.Integer> rowHeights, java.util.List<int[]> colSpans, boolean footerPresent)
private PrintPiece
nextFooterPiece(int[] colSizes, int height, int[] rowHeights, int[][] colSpans)
private PrintPiece
nextHeaderOrFooterPiece(int[] colSizes, int height, int[] rowHeights, int[][] colSpans, int rowSpacing, GridCellIterator[][] headerOrFooter)
private PrintPiece
nextHeaderPiece(int[] colSizes, int height, int[] rowHeights, int[][] colSpans)
private PrintPiece
nextRow(GridCellIterator[] cells, int[] columnWidths, int height, boolean bottomOpen)
org.eclipse.swt.graphics.Point
preferredSize()
Returns the smallest size PrintPiece that this Print would be broken into if print space was unlimited.private int[]
reduceMinimumColumnWidths(int reduction)
private void
resizeColumnsEqually(int[] colSizes, int adjustment, int[] expandableColumns)
private void
resizeColumnsProportionateToCurrentSizes(int[] colSizes, int[] columnIndices, int adjustment, int totalWidth)
private static int
resolveHorzAlignment(int cellAlignment, int columnAlignment)
private static boolean
rowContainsNonDefaultVertAlignment(GridCellIterator[] cells)
-
-
-
Field Detail
-
device
final org.eclipse.swt.graphics.Device device
-
dpi
final org.eclipse.swt.graphics.Point dpi
-
columns
final GridColumn[] columns
-
columnGroups
final int[][] columnGroups
-
look
final GridLookPainter look
-
header
final GridCellIterator[][] header
-
body
final GridCellIterator[][] body
-
footer
final GridCellIterator[][] footer
-
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)
-
cloneRows
private static GridCellIterator[][] cloneRows(GridCellIterator[][] rows, int firstRow)
-
computeCellWidth
private int computeCellWidth(GridCellIterator entry, GridColumn col, PrintSizeStrategy strategy)
Compute the size of a column, respecting the constraints of the GridColumn.
-
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)
-
getExpandableColumnConditions
private GridIterator.Condition[] getExpandableColumnConditions()
-
findColumns
private int[] findColumns(GridIterator.Condition condition)
-
findColumns
private int[] findColumns(int start, int count, GridIterator.Condition condition)
-
computeSize
private org.eclipse.swt.graphics.Point computeSize(PrintSizeStrategy strategy, int[] colSizes)
-
computeHeaderHeight
private int computeHeaderHeight(GridMargins margins, PrintSizeStrategy strategy)
-
computeMaxBodyRowHeight
private int computeMaxBodyRowHeight(PrintSizeStrategy strategy)
-
computeFooterHeight
private int computeFooterHeight(PrintSizeStrategy strategy, GridMargins margins)
-
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 interfacePrintIterator
- 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 interfacePrintIterator
- Returns:
- a Point indicating the smallest size PrintPiece that this Print would be broken into if print space was unlimited.
-
getShrinkableColumnConditions
private GridIterator.Condition[] getShrinkableColumnConditions()
-
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 interfacePrintIterator
- Returns:
- whether any PrintPieces remain.
-
nextRow
private PrintPiece nextRow(GridCellIterator[] cells, int[] columnWidths, int height, boolean bottomOpen)
-
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)
-
calculateRowHeight
private static int calculateRowHeight(PrintPiece[] cellPieces, GridCellIterator[] cells)
-
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)
-
hasNext
private static boolean hasNext(GridCellIterator[] cells)
-
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 returnfalse
.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 returntrue
.If there is insufficient space for any of the remaining contents in the given space,
null
is returned, and subsequent calls toPrintIterator.hasNext()
will returntrue
.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 interfacePrintIterator
- 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)
-
cloneRow
private static GridCellIterator[] cloneRow(GridCellIterator[] row)
-
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 invokingnext(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 interfacePrintIterator
- Returns:
- a deep clone of the target with all relevant internal states.
-
-