use of org.eclipse.nebula.widgets.nattable.layer.ILayer in project nebula.widgets.nattable by eclipse.
the class TextPainter method paintCell.
@Override
public void paintCell(ILayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
if (this.paintBg) {
super.paintCell(cell, gc, rectangle, configRegistry);
}
if (this.paintFg) {
Rectangle originalClipping = gc.getClipping();
gc.setClipping(rectangle.intersection(originalClipping));
IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
setupGCFromConfig(gc, cellStyle);
int fontHeight = gc.getFontMetrics().getHeight();
String text = convertDataType(cell, configRegistry);
// Draw Text
text = getTextToDisplay(cell, gc, rectangle.width, text);
int numberOfNewLines = getNumberOfNewLines(text);
// if the content height is bigger than the available row height
// we're extending the row height (only if word wrapping is enabled)
int contentHeight = (fontHeight * numberOfNewLines) + (this.lineSpacing * (numberOfNewLines - 1)) + (this.spacing * 2);
int contentToCellDiff = (cell.getBounds().height - rectangle.height);
if (performRowResize(contentHeight, rectangle)) {
ILayer layer = cell.getLayer();
layer.doCommand(new RowResizeCommand(layer, cell.getRowPosition(), contentHeight + contentToCellDiff, true));
}
if (numberOfNewLines == 1) {
int contentWidth = Math.min(getLengthFromCache(gc, text), rectangle.width);
gc.drawText(text, rectangle.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentWidth) + this.spacing, rectangle.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, contentHeight) + this.spacing, SWT.DRAW_TRANSPARENT | SWT.DRAW_DELIMITER);
// start x of line = start x of text
int x = rectangle.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentWidth) + this.spacing;
// y = start y of text
int y = rectangle.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, contentHeight) + this.spacing;
int length = gc.textExtent(text).x;
paintDecoration(cellStyle, gc, x, y, length, fontHeight);
} else {
// draw every line by itself because of the alignment, otherwise
// the whole text is always aligned right
int yStartPos = rectangle.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, contentHeight);
// $NON-NLS-1$
String[] lines = text.split("\n");
for (String line : lines) {
int lineContentWidth = Math.min(getLengthFromCache(gc, line), rectangle.width);
gc.drawText(line, rectangle.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, lineContentWidth) + this.spacing, yStartPos + this.spacing, SWT.DRAW_TRANSPARENT | SWT.DRAW_DELIMITER);
// start x of line = start x of text
int x = rectangle.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, lineContentWidth) + this.spacing;
// y = start y of text
int y = yStartPos + this.spacing;
int length = gc.textExtent(line).x;
paintDecoration(cellStyle, gc, x, y, length, fontHeight);
// after every line calculate the y start pos new
yStartPos += fontHeight;
yStartPos += this.lineSpacing;
}
}
gc.setClipping(originalClipping);
resetGC(gc);
}
}
use of org.eclipse.nebula.widgets.nattable.layer.ILayer in project nebula.widgets.nattable by eclipse.
the class VerticalTextPainter 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 VerticalTextPainter method paintCell.
@Override
public void paintCell(ILayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
if (this.paintBg) {
super.paintCell(cell, gc, rectangle, configRegistry);
}
if (this.paintFg) {
Rectangle originalClipping = gc.getClipping();
gc.setClipping(rectangle.intersection(originalClipping));
IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
setupGCFromConfig(gc, cellStyle);
int fontHeight = gc.getFontMetrics().getHeight();
String text = convertDataType(cell, configRegistry);
// Draw Text
text = getTextToDisplay(cell, gc, rectangle.height, text);
int numberOfNewLines = getNumberOfNewLines(text);
// if the content height is bigger than the available column width
// we're extending the column width (only if word wrapping is
// enabled)
int contentHeight = (fontHeight * numberOfNewLines) + (this.lineSpacing * (numberOfNewLines - 1)) + (this.spacing * 2);
int contentToCellDiff = (cell.getBounds().width - rectangle.width);
if ((contentHeight > rectangle.width) && this.calculateByTextHeight) {
ILayer layer = cell.getLayer();
layer.doCommand(new ColumnResizeCommand(layer, cell.getColumnPosition(), contentHeight + contentToCellDiff, true));
}
if (text != null && text.length() > 0) {
Transform originalTransform = new Transform(gc.getDevice());
gc.getTransform(originalTransform);
Transform transform = new Transform(gc.getDevice());
gc.getTransform(transform);
if (numberOfNewLines == 1) {
int contentWidth = Math.min(getLengthFromCache(gc, text), rectangle.height);
if (!isRotateClockwise()) {
transform.rotate(-90f);
int xOffset = -rectangle.x + (-contentWidth - rectangle.y) - CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, contentWidth);
int yOffset = rectangle.x + -rectangle.y + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentHeight) + this.spacing;
transform.translate(xOffset, yOffset);
} else {
transform.rotate(90f);
int horizontalPadding = CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentHeight);
if (horizontalPadding != 0) {
horizontalPadding += gc.getFontMetrics().getLeading();
}
int xOffset = rectangle.y - rectangle.x + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, contentWidth);
int yOffset = -contentHeight - rectangle.y - rectangle.x - horizontalPadding + this.spacing;
transform.translate(xOffset, yOffset);
}
gc.setTransform(transform);
gc.drawText(text, rectangle.x, rectangle.y, SWT.DRAW_TRANSPARENT | SWT.DRAW_DELIMITER);
int length = gc.textExtent(text).x;
paintDecoration(cellStyle, gc, rectangle.x, rectangle.y, length, fontHeight);
} else {
// draw every line by itself because of the alignment,
// otherwise the whole text is always aligned right
// $NON-NLS-1$
String[] lines = text.split("\n");
boolean firstline = true;
int previousXOffset = 0;
for (String line : lines) {
int lineContentWidth = Math.min(getLengthFromCache(gc, line), rectangle.height);
if (!isRotateClockwise()) {
int xOffset = -rectangle.x + (-lineContentWidth - rectangle.y) - CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, lineContentWidth);
if (firstline) {
transform.rotate(-90f);
int yOffset = rectangle.x + -rectangle.y + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentHeight) + this.spacing;
transform.translate(xOffset, yOffset);
firstline = false;
} else {
transform.translate(xOffset - previousXOffset, fontHeight + this.lineSpacing);
}
previousXOffset = xOffset;
} else {
int xOffset = rectangle.y - rectangle.x + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, rectangle, lineContentWidth);
if (firstline) {
transform.rotate(90f);
int horizontalPadding = CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, rectangle, contentHeight);
if (horizontalPadding != 0) {
horizontalPadding += gc.getFontMetrics().getLeading();
}
int yOffset = -contentHeight - rectangle.y - rectangle.x - horizontalPadding + this.spacing + (fontHeight * (numberOfNewLines - 1)) + (this.lineSpacing * (numberOfNewLines - 1));
transform.translate(xOffset, yOffset);
firstline = false;
} else {
transform.translate(xOffset - previousXOffset, -fontHeight - this.lineSpacing);
}
previousXOffset = xOffset;
}
gc.setTransform(transform);
gc.drawText(line, rectangle.x, rectangle.y, SWT.DRAW_TRANSPARENT | SWT.DRAW_DELIMITER);
int length = gc.textExtent(line).x;
paintDecoration(cellStyle, gc, rectangle.x, rectangle.y, length, fontHeight);
}
}
gc.setTransform(originalTransform);
if (originalTransform != null) {
originalTransform.dispose();
}
if (transform != null) {
transform.dispose();
}
}
gc.setClipping(originalClipping);
resetGC(gc);
}
}
use of org.eclipse.nebula.widgets.nattable.layer.ILayer in project nebula.widgets.nattable by eclipse.
the class ColumnReorderLayer method populateIndexOrder.
/**
* Initialize the internal column index ordering from a clean state, which
* means it reflects the ordering from the underlying layer.
*/
private void populateIndexOrder() {
this.columnIndexOrder.clear();
ILayer underlyingLayer = getUnderlyingLayer();
for (int columnPosition = 0; columnPosition < underlyingLayer.getColumnCount(); columnPosition++) {
int index = underlyingLayer.getColumnIndexByPosition(columnPosition);
this.columnIndexOrder.add(index);
this.indexPositionMapping.put(index, columnPosition);
}
}
use of org.eclipse.nebula.widgets.nattable.layer.ILayer in project nebula.widgets.nattable by eclipse.
the class RowReorderLayer method populateIndexOrder.
/**
* Initially populate the index order to the local cache.
*/
private void populateIndexOrder() {
this.rowIndexOrder.clear();
ILayer underlyingLayer = getUnderlyingLayer();
for (int rowPosition = 0; rowPosition < underlyingLayer.getRowCount(); rowPosition++) {
int index = underlyingLayer.getRowIndexByPosition(rowPosition);
this.rowIndexOrder.add(index);
this.indexPositionMapping.put(index, rowPosition);
}
}
Aggregations