use of org.eclipse.nebula.widgets.nattable.style.IStyle in project nebula.widgets.nattable by eclipse.
the class ImagePainter method paintCell.
@Override
public void paintCell(ILayerCell cell, GC gc, Rectangle bounds, IConfigRegistry configRegistry) {
if (this.paintBg) {
super.paintCell(cell, gc, bounds, configRegistry);
}
Image image = getImage(cell, configRegistry);
if (image != null) {
Rectangle imageBounds = image.getBounds();
IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
int contentHeight = imageBounds.height;
if (this.calculateByHeight && (contentHeight > bounds.height)) {
int contentToCellDiff = (cell.getBounds().height - bounds.height);
ILayer layer = cell.getLayer();
layer.doCommand(new RowResizeCommand(layer, cell.getRowPosition(), contentHeight + contentToCellDiff, true));
}
int contentWidth = imageBounds.width;
if (this.calculateByWidth && (contentWidth > bounds.width)) {
int contentToCellDiff = (cell.getBounds().width - bounds.width);
ILayer layer = cell.getLayer();
layer.doCommand(new ColumnResizeCommand(layer, cell.getColumnPosition(), contentWidth + contentToCellDiff, true));
}
gc.drawImage(image, bounds.x + CellStyleUtil.getHorizontalAlignmentPadding(cellStyle, bounds, imageBounds.width), bounds.y + CellStyleUtil.getVerticalAlignmentPadding(cellStyle, bounds, imageBounds.height));
}
}
use of org.eclipse.nebula.widgets.nattable.style.IStyle in project nebula.widgets.nattable by eclipse.
the class BlendedBackgroundPainter method blendBackgroundColour.
/**
* Returns a background colour for the specified cell. If multiple colours
* have been registered, they are all blended together.
*
* @param cell
* the
* {@link org.eclipse.nebula.widgets.nattable.layer.cell.LayerCell}
* to get a background colour for.
* @param configRegistry
* an
* {@link org.eclipse.nebula.widgets.nattable.config.IConfigRegistry}
* .
* @param baseColor
* Colours are not blended with this colour.
* @return A blended background colour.
*/
public static Color blendBackgroundColour(final ILayerCell cell, final IConfigRegistry configRegistry, final RGB baseColor) {
// Get all of the background colours registered for the cell in normal
// mode.
final List<Color> colours = CellStyleUtil.getAllBackgroundColors(cell, configRegistry, DisplayMode.NORMAL);
// to the blending mix.
if (cell.getDisplayMode().equals(DisplayMode.SELECT)) {
final IStyle cellStyle = new CellStyleProxy(configRegistry, DisplayMode.SELECT, cell.getConfigLabels().getLabels());
colours.add(cellStyle.getAttributeValue(CellStyleAttributes.BACKGROUND_COLOR));
}
if (colours.size() == 0) {
return null;
} else if (colours.size() == 1) {
return colours.get(0);
} else {
RGB rgb = colours.get(0).getRGB();
for (int i = 1; i < colours.size(); i++) {
// Don't blend with the grid background colour.
if (rgb.equals(baseColor)) {
rgb = colours.get(i).getRGB();
} else if (!colours.get(i).getRGB().equals(baseColor)) {
rgb = GUIHelper.blend(rgb, colours.get(i).getRGB());
}
}
return GUIHelper.getColor(rgb);
}
}
use of org.eclipse.nebula.widgets.nattable.style.IStyle 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.style.IStyle 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.style.IStyle in project nebula.widgets.nattable by eclipse.
the class CustomLineBorderDecorator method getBorderStyle.
private BorderStyle getBorderStyle(ILayerCell cell, IConfigRegistry configRegistry) {
IStyle cellStyle = CellStyleUtil.getCellStyle(cell, configRegistry);
BorderStyle borderStyle = cellStyle.getAttributeValue(CellStyleAttributes.BORDER_STYLE);
if (borderStyle == null) {
borderStyle = this.defaultBorderStyle;
}
return borderStyle;
}
Aggregations