use of org.eclipse.nebula.widgets.nattable.style.BorderStyle in project nebula.widgets.nattable by eclipse.
the class CustomLineBorderDecorator method getPreferredHeight.
@Override
public int getPreferredHeight(ILayerCell cell, GC gc, IConfigRegistry configRegistry) {
BorderStyle borderStyle = getBorderStyle(cell, configRegistry);
int borderThickness = borderStyle != null ? borderStyle.getThickness() : 0;
int borderLineCount = 0;
// check how many border lines are configured for that cell
List<String> labels = cell.getConfigLabels().getLabels();
if (labels.contains(TOP_LINE_BORDER_LABEL))
borderLineCount++;
if (labels.contains(BOTTOM_LINE_BORDER_LABEL))
borderLineCount++;
return super.getPreferredHeight(cell, gc, configRegistry) + (borderThickness * borderLineCount);
}
use of org.eclipse.nebula.widgets.nattable.style.BorderStyle in project nebula.widgets.nattable by eclipse.
the class LineBorderDecorator method getPreferredWidth.
@Override
public int getPreferredWidth(ILayerCell cell, GC gc, IConfigRegistry configRegistry) {
BorderStyle borderStyle = getBorderStyle(cell, configRegistry);
int borderThickness = borderStyle != null ? borderStyle.getThickness() : 0;
return super.getPreferredWidth(cell, gc, configRegistry) + (borderThickness * 2);
}
use of org.eclipse.nebula.widgets.nattable.style.BorderStyle in project nebula.widgets.nattable by eclipse.
the class LineBorderDecorator method paintCell.
@Override
public void paintCell(ILayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
BorderStyle borderStyle = getBorderStyle(cell, configRegistry);
int borderThickness = borderStyle != null ? borderStyle.getThickness() : 0;
Rectangle interiorBounds = new Rectangle(rectangle.x + borderThickness, rectangle.y + borderThickness, rectangle.width - (borderThickness * 2), rectangle.height - (borderThickness * 2));
super.paintCell(cell, gc, interiorBounds, configRegistry);
if (borderStyle == null || borderThickness <= 0) {
return;
}
// Save GC settings
Color originalForeground = gc.getForeground();
int originalLineWidth = gc.getLineWidth();
int originalLineStyle = gc.getLineStyle();
Integer gridLineWidth = configRegistry.getConfigAttribute(CellConfigAttributes.GRID_LINE_WIDTH, DisplayMode.NORMAL, cell.getConfigLabels().getLabels());
int adjustment = (gridLineWidth == null || gridLineWidth == 1) ? 0 : Math.round(gridLineWidth.floatValue() / 2);
gc.setLineWidth(borderThickness);
Rectangle borderArea = new Rectangle(rectangle.x, rectangle.y, rectangle.width, rectangle.height);
if (borderThickness >= 1) {
int shift = 0;
int areaShift = 0;
if ((borderThickness % 2) == 0) {
shift = borderThickness / 2;
areaShift = (shift * 2);
} else {
shift = borderThickness / 2;
areaShift = (shift * 2) + 1;
}
borderArea.x += (shift + adjustment);
borderArea.y += (shift + adjustment);
borderArea.width -= (areaShift + adjustment);
borderArea.height -= (areaShift + adjustment);
}
gc.setLineStyle(LineStyleEnum.toSWT(borderStyle.getLineStyle()));
gc.setForeground(borderStyle.getColor());
gc.drawRectangle(borderArea);
// Restore GC settings
gc.setForeground(originalForeground);
gc.setLineWidth(originalLineWidth);
gc.setLineStyle(originalLineStyle);
}
use of org.eclipse.nebula.widgets.nattable.style.BorderStyle in project nebula.widgets.nattable by eclipse.
the class StylePersistor method loadStyle.
// Load
public static Style loadStyle(String prefix, Properties properties) {
Style style = new Style();
prefix = prefix + DOT + STYLE_PERSISTENCE_PREFIX;
// BG Color
String bgColorPrefix = prefix + DOT + BG_COLOR_PREFIX;
Color bgColor = loadColor(bgColorPrefix, properties);
if (bgColor != null) {
style.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, bgColor);
}
// FG Color
String fgColorPrefix = prefix + DOT + FG_COLOR_PREFIX;
Color fgColor = loadColor(fgColorPrefix, properties);
if (fgColor != null) {
style.setAttributeValue(CellStyleAttributes.FOREGROUND_COLOR, fgColor);
}
// Alignment
String hAlignPrefix = prefix + DOT + H_ALIGNMENT_PREFIX;
HorizontalAlignmentEnum hAlign = loadHAlignment(hAlignPrefix, properties);
if (hAlign != null) {
style.setAttributeValue(CellStyleAttributes.HORIZONTAL_ALIGNMENT, hAlign);
}
String vAlignPrefix = prefix + DOT + V_ALIGNMENT_PREFIX;
VerticalAlignmentEnum vAlign = loadVAlignment(vAlignPrefix, properties);
if (vAlign != null) {
style.setAttributeValue(CellStyleAttributes.VERTICAL_ALIGNMENT, vAlign);
}
// Font
String fontPrefix = prefix + DOT + FONT_PREFIX;
Font font = loadFont(fontPrefix, properties);
if (font != null) {
style.setAttributeValue(CellStyleAttributes.FONT, font);
}
// Border Style
String borderPrefix = prefix + DOT + BORDER_PREFIX;
BorderStyle borderStyle = loadBorderStyle(borderPrefix, properties);
if (borderStyle != null) {
style.setAttributeValue(CellStyleAttributes.BORDER_STYLE, borderStyle);
}
return style;
}
use of org.eclipse.nebula.widgets.nattable.style.BorderStyle in project nebula.widgets.nattable by eclipse.
the class SelectionLayerPainter method paintLayer.
@Override
public void paintLayer(ILayer natLayer, GC gc, int xOffset, int yOffset, Rectangle pixelRectangle, IConfigRegistry configRegistry) {
super.paintLayer(natLayer, gc, xOffset, yOffset, pixelRectangle, configRegistry);
Rectangle positionRectangle = getPositionRectangleFromPixelRectangle(natLayer, pixelRectangle);
int columnPositionOffset = positionRectangle.x;
int rowPositionOffset = positionRectangle.y;
// nothing to draw, we exit
if (positionRectangle.width <= 0 || positionRectangle.height <= 0) {
return;
}
BorderCell[][] borderCells;
boolean atLeastOne = false;
PaintModeEnum paintMode;
// tentative way to know that this is a single cell update
if (positionRectangle.width <= 2 && positionRectangle.height <= 2) {
// In order to correctly paint the selection borders in case of
// single cell updates we need to consider also the adjacent cells.
// Therefore we try to retrieve also cells that are outside the
// pixelRectangle but still inside our layer.
// +2 because we are going to read also adjacent cells in the
// extremities
borderCells = new BorderCell[positionRectangle.height + 2][positionRectangle.width + 2];
// we need to repaint only the internal borders of the external
// cells
paintMode = PaintModeEnum.NO_EXTERNAL_BORDERS;
// extremities
for (int columnPosition = columnPositionOffset - 1, ix = 0; columnPosition < columnPositionOffset + positionRectangle.width + 1; columnPosition++, ix++) {
for (int rowPosition = rowPositionOffset - 1, iy = 0; rowPosition < rowPositionOffset + positionRectangle.height + 1; rowPosition++, iy++) {
boolean insideBorder = false;
Rectangle cellBounds = null;
ILayerCell currentCell = natLayer.getCellByPosition(columnPosition, rowPosition);
if (currentCell != null) {
cellBounds = currentCell.getBounds();
// the cell should be considered only if it is in our
// layer
boolean toBeConsidered = isInCurrentLayer(ix, iy, xOffset, yOffset, cellBounds, borderCells);
if (toBeConsidered && isSelected(currentCell)) {
insideBorder = true;
atLeastOne = true;
}
}
Rectangle fixedBounds = fixBoundsInGridLines(cellBounds, xOffset, yOffset);
BorderCell borderCell = new BorderCell(fixedBounds, insideBorder);
borderCells[iy][ix] = borderCell;
}
}
} else {
borderCells = new BorderCell[positionRectangle.height][positionRectangle.width];
paintMode = PaintModeEnum.ALL;
for (int columnPosition = columnPositionOffset, ix = 0; columnPosition < columnPositionOffset + positionRectangle.width; columnPosition++, ix++) {
for (int rowPosition = rowPositionOffset, iy = 0; rowPosition < rowPositionOffset + positionRectangle.height; rowPosition++, iy++) {
boolean insideBorder = false;
Rectangle cellBounds = null;
ILayerCell currentCell = natLayer.getCellByPosition(columnPosition, rowPosition);
if (currentCell != null) {
// In case of spanned cells the border painter needs to
// know the bounds of adjacent cells even if they are
// not selected. This is the reason why we get the
// bounds also for non selected cells.
cellBounds = currentCell.getBounds();
if (isSelected(currentCell)) {
insideBorder = true;
atLeastOne = true;
}
}
Rectangle fixedBounds = fixBoundsInGridLines(cellBounds, xOffset, yOffset);
BorderCell borderCell = new BorderCell(fixedBounds, insideBorder);
borderCells[iy][ix] = borderCell;
}
}
}
if (atLeastOne) {
// Save gc settings
int originalLineStyle = gc.getLineStyle();
int originalLineWidth = gc.getLineWidth();
Color originalForeground = gc.getForeground();
BorderStyle borderStyle = getBorderStyle(configRegistry);
BorderPainter borderPainter = new BorderPainter(borderCells, borderStyle, paintMode);
borderPainter.paintBorder(gc);
// Restore original gc settings
gc.setLineStyle(originalLineStyle);
gc.setLineWidth(originalLineWidth);
gc.setForeground(originalForeground);
}
}
Aggregations