use of org.eclipse.nebula.widgets.nattable.layer.ILayer in project nebula.widgets.nattable by eclipse.
the class TableCellPainter method paintCell.
@Override
public void paintCell(ILayerCell cell, GC gc, Rectangle bounds, IConfigRegistry configRegistry) {
if (this.paintBg) {
super.paintCell(cell, gc, bounds, configRegistry);
}
Object[] cellDataArray = getDataAsArray(cell);
if (cellDataArray != null) {
// iterate over all values in the collection and render them
// separately by creating temporary sub cells
// and adding grid lines for the sub cells
int subGridY = bounds.y;
if (cellDataArray != null) {
Color originalColor = gc.getForeground();
for (int i = 0; i < cellDataArray.length; i++) {
ILayerCell subCell = createSubLayerCell(cell, cellDataArray[i]);
int subCellHeight = getSubCellHeight(subCell, gc, configRegistry);
Rectangle subCellBounds = new Rectangle(bounds.x, subGridY, bounds.width, subCellHeight);
this.getInternalPainter().paintCell(subCell, gc, subCellBounds, configRegistry);
// render sub grid line
// update subGridY for calculated height
subGridY += subCellHeight + 1;
gc.setForeground(cell.getDisplayMode().equals(DisplayMode.SELECT) ? getSelectedGridColor() : getGridColor());
gc.drawLine(bounds.x, subGridY, bounds.x + bounds.width, subGridY);
gc.setForeground(originalColor);
// increase subGridY by 1 so the next sub cell renders below
subGridY += 1;
}
// perform resize if necessary
int neededHeight = subGridY - bounds.y;
if (isCalculateParentCellHeight() && (neededHeight > cell.getBounds().height)) {
ILayer layer = cell.getLayer();
layer.doCommand(new RowResizeCommand(layer, cell.getRowPosition(), neededHeight, true));
}
}
} else {
this.getInternalPainter().paintCell(cell, gc, bounds, configRegistry);
}
}
use of org.eclipse.nebula.widgets.nattable.layer.ILayer in project nebula.widgets.nattable by eclipse.
the class TextPainter method setNewMinLength.
@Override
protected void setNewMinLength(ILayerCell cell, int contentWidth) {
int cellLength = cell.getBounds().width;
if (cellLength < contentWidth) {
// execute ColumnResizeCommand
ILayer layer = cell.getLayer();
layer.doCommand(new ColumnResizeCommand(layer, cell.getColumnPosition(), contentWidth, true));
}
}
use of org.eclipse.nebula.widgets.nattable.layer.ILayer in project nebula.widgets.nattable by eclipse.
the class VerticalTextImagePainter method setNewMinLength.
@Override
protected void setNewMinLength(ILayerCell cell, int contentHeight) {
int cellLength = cell.getBounds().height;
if (cellLength < contentHeight) {
ILayer layer = cell.getLayer();
layer.doCommand(new RowResizeCommand(layer, cell.getRowPosition(), contentHeight, true));
}
}
use of org.eclipse.nebula.widgets.nattable.layer.ILayer in project nebula.widgets.nattable by eclipse.
the class VerticalTextImagePainter method paintCell.
@Override
public void paintCell(ILayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
if (this.paintBg) {
super.paintCell(cell, gc, rectangle, configRegistry);
}
Rectangle originalClipping = gc.getClipping();
gc.setClipping(rectangle.intersection(originalClipping));
IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
setupGCFromConfig(gc, cellStyle);
boolean underline = renderUnderlined(cellStyle);
boolean strikethrough = renderStrikethrough(cellStyle);
String text = convertDataType(cell, configRegistry);
// calculate the text to display, adds dots if the text is longer than
// the available row height and adds new lines instead of spaces if word
// wrapping is enabled
text = getTextToDisplay(cell, gc, rectangle.height, text);
int numberOfNewLines = getNumberOfNewLines(text);
// if the content width is bigger than the available column width
// we're extending the column width (only if word wrapping is enabled)
int fontHeight = gc.getFontMetrics().getHeight();
int contentWidth = (fontHeight * numberOfNewLines) + (this.lineSpacing * (numberOfNewLines - 1)) + (this.spacing * 2);
int contentToCellDiff = (cell.getBounds().width - rectangle.width);
if ((contentWidth > rectangle.width) && this.calculateByTextHeight) {
ILayer layer = cell.getLayer();
layer.doCommand(new ColumnResizeCommand(layer, cell.getColumnPosition(), contentWidth + contentToCellDiff, true));
}
if (text != null && text.length() > 0) {
if (numberOfNewLines == 1) {
int contentHeight = Math.min(getLengthFromCache(gc, text), rectangle.height);
GraphicsUtils.drawVerticalText(text, rectangle.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentWidth) + this.spacing, rectangle.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, contentHeight + this.spacing), underline, strikethrough, this.paintBg, gc, SWT.UP);
} else {
// draw every line by itself because of the alignment, otherwise
// the whole text is always aligned right
int xStartPos = rectangle.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentWidth);
// $NON-NLS-1$
String[] lines = text.split("\n");
for (String line : lines) {
int lineContentWidth = Math.min(getLengthFromCache(gc, line), rectangle.height);
GraphicsUtils.drawVerticalText(line, xStartPos + this.spacing, rectangle.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, lineContentWidth + this.spacing), underline, strikethrough, this.paintBg, gc, SWT.UP);
// after every line calculate the x start pos new
xStartPos += fontHeight;
xStartPos += this.lineSpacing;
}
}
}
gc.setClipping(originalClipping);
}
use of org.eclipse.nebula.widgets.nattable.layer.ILayer in project nebula.widgets.nattable by eclipse.
the class CellLayerPainter method paintCell.
protected void paintCell(ILayerCell cell, GC gc, IConfigRegistry configRegistry) {
ILayer layer = cell.getLayer();
int columnPosition = cell.getColumnPosition();
int rowPosition = cell.getRowPosition();
ICellPainter cellPainter = layer.getCellPainter(columnPosition, rowPosition, cell, configRegistry);
Rectangle adjustedCellBounds = layer.getLayerPainter().adjustCellBounds(columnPosition, rowPosition, cell.getBounds());
if (cellPainter != null) {
Rectangle originalClipping = gc.getClipping();
int startX = getStartXOfColumnPosition(columnPosition);
int startY = getStartYOfRowPosition(rowPosition);
int endX = getStartXOfColumnPosition(cell.getOriginColumnPosition() + cell.getColumnSpan());
int endY = getStartYOfRowPosition(cell.getOriginRowPosition() + cell.getRowSpan());
Rectangle cellClipBounds = originalClipping.intersection(new Rectangle(startX, startY, endX - startX, endY - startY));
gc.setClipping(cellClipBounds.intersection(adjustedCellBounds));
cellPainter.paintCell(cell, gc, adjustedCellBounds, configRegistry);
gc.setClipping(originalClipping);
}
}
Aggregations