| package org.eclipse.nebula.widgets.nattable.core.layer.impl |
| |
| import org.eclipse.nebula.widgets.nattable.core.geometry.PixelArea |
| import org.eclipse.nebula.widgets.nattable.core.geometry.PixelRectangle |
| import org.eclipse.nebula.widgets.nattable.core.graphics.GraphicsContext |
| import org.eclipse.nebula.widgets.nattable.core.layer.Layer |
| import org.eclipse.nebula.widgets.nattable.core.layer.LayerPainter |
| import org.eclipse.nebula.widgets.nattable.core.layer.cell.Cell |
| import org.eclipse.nebula.widgets.nattable.core.layer.cell.impl.TextCellPainter |
| |
| import static java.lang.Math.* |
| |
| import static extension org.eclipse.nebula.widgets.nattable.core.geometry.PixelRectangleInvariants.* |
| import static extension org.eclipse.nebula.widgets.nattable.core.layer.LayerInvariants.* |
| import static extension org.eclipse.nebula.widgets.nattable.core.layer.cell.CellInvariants.* |
| |
| class CellLayerPainter implements LayerPainter<Layer> { |
| |
| val cellPainter = new TextCellPainter |
| |
| // LayerPainter interface |
| |
| override paintLayer(Layer layer, PixelArea layerPaintArea, GraphicsContext gc) { |
| val layerPixelBounds = new PixelRectangle(0, 0, layerPaintArea.width, layerPaintArea.height) |
| val clipBounds = gc.clipBounds |
| |
| val fromColumnPosition = max(layer.getColumnPositionOfXPixel(clipBounds.x), 0) |
| val toColumnPosition = min(layer.getColumnPositionOfXPixel(clipBounds.x + clipBounds.width - 1), layer.columnCount - 1) |
| val fromRowPosition = max(layer.getRowPositionOfYPixel(clipBounds.y), 0) |
| val toRowPosition = min(layer.getRowPositionOfYPixel(clipBounds.y + clipBounds.height - 1), layer.rowCount - 1) |
| |
| if (fromColumnPosition <= toColumnPosition) |
| for (columnPosition : fromColumnPosition .. toColumnPosition) |
| if (fromRowPosition <= toRowPosition) |
| for (rowPosition : fromRowPosition .. toRowPosition) { |
| val cell = layer.getCell(columnPosition, rowPosition) |
| |
| gc.pushState |
| |
| val cellPixelBounds = cell.adjustedPixelBounds |
| gc.clipBounds = cellPixelBounds.intersect(layerPixelBounds) |
| gc.translate(cellPixelBounds.x, cellPixelBounds.y) |
| cellPainter.paintCell(cell, new PixelArea(cellPixelBounds.width, cellPixelBounds.height), gc) |
| |
| gc.popState |
| } |
| } |
| |
| // |
| |
| protected def getAdjustedPixelBounds(Cell cell) { |
| cell.pixelBounds |
| } |
| |
| } |