use of org.eclipse.nebula.widgets.nattable.style.BorderStyle in project nebula.widgets.nattable by eclipse.
the class FillHandleLayerPainter method paintFillHandle.
protected void paintFillHandle(ILayerCell fillHandleCell, GC gc, int xOffset, int yOffset, IConfigRegistry configRegistry) {
// Save gc settings
Color originalBackground = gc.getBackground();
Rectangle originalClipping = gc.getClipping();
Rectangle bounds = fillHandleCell.getBounds();
int fillHandleSize = GUIHelper.convertHorizontalPixelToDpi(7);
// positions offset starting from the lower right corner of the fill
// handle cell
int fillHandleOffsetX = -GUIHelper.convertHorizontalPixelToDpi(4);
int fillHandleOffsetY = -GUIHelper.convertHorizontalPixelToDpi(4);
Rectangle handleInterior = new Rectangle(bounds.x + bounds.width + fillHandleOffsetX, bounds.y + bounds.height + fillHandleOffsetY, fillHandleSize, fillHandleSize);
BorderStyle borderStyle = getHandleBorderStyle(configRegistry);
this.handleBounds = GraphicsUtils.getResultingExternalBounds(handleInterior, borderStyle);
// how much we need to increment the gc clipping to paint the whole
// fill handle
int clippingWidthIncrement = Math.max(0, (this.handleBounds.x + this.handleBounds.width) - (originalClipping.x + originalClipping.width));
int clippingHeightIncrement = Math.max(0, (this.handleBounds.y + this.handleBounds.height) - (originalClipping.y + originalClipping.height));
if (clippingWidthIncrement > 0 || clippingHeightIncrement > 0) {
gc.setClipping(originalClipping.x, originalClipping.y, originalClipping.width + clippingWidthIncrement, originalClipping.height + clippingHeightIncrement);
}
Color color = getHandleColor(configRegistry);
gc.setBackground(color);
GraphicsUtils.fillRectangle(gc, handleInterior);
GraphicsUtils.drawRectangle(gc, handleInterior, borderStyle);
// Restore original gc settings
gc.setBackground(originalBackground);
gc.setClipping(originalClipping);
}
use of org.eclipse.nebula.widgets.nattable.style.BorderStyle in project nebula.widgets.nattable by eclipse.
the class CopySelectionLayerPainter method applyCopyBorderStyle.
/**
* Apply the border style that should be used to render the border for cells
* that are currently copied to the {@link InternalCellClipboard}. Checks
* the {@link ConfigRegistry} for a registered {@link IStyle} for the
* {@link SelectionStyleLabels#COPY_BORDER_STYLE} label. If none is
* registered, a default line style will be used to render the border.
*
* @param gc
* The current {@link GC} that is used for rendering.
* @param configRegistry
* The {@link ConfigRegistry} to retrieve the style information
* from.
*/
protected void applyCopyBorderStyle(GC gc, IConfigRegistry configRegistry) {
IStyle cellStyle = configRegistry.getConfigAttribute(CellConfigAttributes.CELL_STYLE, DisplayMode.NORMAL, SelectionStyleLabels.COPY_BORDER_STYLE);
BorderStyle borderStyle = cellStyle != null ? cellStyle.getAttributeValue(CellStyleAttributes.BORDER_STYLE) : null;
// if there is no border style configured, use the default
if (borderStyle == null) {
gc.setLineStyle(SWT.LINE_DASH);
gc.setLineDash(new int[] { 2, 2 });
gc.setForeground(GUIHelper.COLOR_BLACK);
} else {
gc.setLineStyle(LineStyleEnum.toSWT(borderStyle.getLineStyle()));
gc.setLineWidth(borderStyle.getThickness());
gc.setForeground(borderStyle.getColor());
}
}
use of org.eclipse.nebula.widgets.nattable.style.BorderStyle in project nebula.widgets.nattable by eclipse.
the class DefaultFormulaConfiguration method configureRegistry.
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITABLE_RULE, IEditableRule.ALWAYS_EDITABLE);
// register converter to make editing of functions work
configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new FormulaEditDisplayConverter(this.dataProvider), DisplayMode.EDIT);
// register converter to show decimal values localized
configRegistry.registerConfigAttribute(CellConfigAttributes.DISPLAY_CONVERTER, new FormulaResultDisplayConverter(this.dataProvider), DisplayMode.NORMAL, GridRegion.BODY);
// register TextCellEditor that moves on arrow keys and enter
configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, new TextCellEditor(true, true, true));
// register the border style to use for copy border
IStyle copyBorderStyle = new Style();
copyBorderStyle.setAttributeValue(CellStyleAttributes.BORDER_STYLE, new BorderStyle(1, GUIHelper.COLOR_BLACK, LineStyleEnum.DASHED));
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, copyBorderStyle, DisplayMode.NORMAL, SelectionStyleLabels.COPY_BORDER_STYLE);
}
use of org.eclipse.nebula.widgets.nattable.style.BorderStyle 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;
}
use of org.eclipse.nebula.widgets.nattable.style.BorderStyle in project nebula.widgets.nattable by eclipse.
the class CustomLineBorderDecorator 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;
// check how many border lines are configured for that cell
List<String> labels = cell.getConfigLabels().getLabels();
int leftBorderThickness = 0;
int rightBorderThickness = 0;
int topBorderThickness = 0;
int bottomBorderThickness = 0;
if (labels.contains(LEFT_LINE_BORDER_LABEL))
leftBorderThickness = borderThickness;
if (labels.contains(RIGHT_LINE_BORDER_LABEL))
rightBorderThickness = borderThickness;
if (labels.contains(TOP_LINE_BORDER_LABEL))
topBorderThickness = borderThickness;
if (labels.contains(BOTTOM_LINE_BORDER_LABEL))
bottomBorderThickness = borderThickness;
Rectangle interiorBounds = new Rectangle(rectangle.x + leftBorderThickness, rectangle.y + topBorderThickness, (rectangle.width - leftBorderThickness - rightBorderThickness), (rectangle.height - topBorderThickness - bottomBorderThickness));
super.paintCell(cell, gc, interiorBounds, configRegistry);
if (borderStyle == null || borderThickness <= 0 || (leftBorderThickness == 0 && rightBorderThickness == 0 && topBorderThickness == 0 && bottomBorderThickness == 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 correction = 0;
if ((borderThickness % 2) == 0) {
shift = borderThickness / 2;
} else {
shift = borderThickness / 2;
correction = 1;
}
if (leftBorderThickness >= 1) {
borderArea.x += (shift + adjustment);
borderArea.width -= (shift + adjustment);
}
if (rightBorderThickness >= 1) {
borderArea.width -= shift + correction;
}
if (topBorderThickness >= 1) {
borderArea.y += (shift + adjustment);
borderArea.height -= (shift + adjustment);
}
if (bottomBorderThickness >= 1) {
borderArea.height -= shift + correction;
}
}
gc.setLineStyle(LineStyleEnum.toSWT(borderStyle.getLineStyle()));
gc.setForeground(borderStyle.getColor());
// if all borders are set draw a rectangle
if (leftBorderThickness > 0 && rightBorderThickness > 0 && topBorderThickness > 0 && bottomBorderThickness > 0) {
gc.drawRectangle(borderArea);
} else // else draw a line for every set border
{
Point topLeftPos = new Point(borderArea.x, borderArea.y);
Point topRightPos = new Point(borderArea.x + borderArea.width, borderArea.y);
Point bottomLeftPos = new Point(borderArea.x, borderArea.y + borderArea.height);
Point bottomRightPos = new Point(borderArea.x + borderArea.width, borderArea.y + borderArea.height);
if (leftBorderThickness > 0) {
gc.drawLine(topLeftPos.x, topLeftPos.y, bottomLeftPos.x, bottomLeftPos.y);
}
if (rightBorderThickness > 0) {
gc.drawLine(topRightPos.x, topRightPos.y, bottomRightPos.x, bottomRightPos.y);
}
if (topBorderThickness > 0) {
gc.drawLine(topLeftPos.x, topLeftPos.y, topRightPos.x, topRightPos.y);
}
if (bottomBorderThickness > 0) {
gc.drawLine(bottomLeftPos.x, bottomLeftPos.y, bottomRightPos.x, bottomRightPos.y);
}
}
// Restore GC settings
gc.setForeground(originalForeground);
gc.setLineWidth(originalLineWidth);
gc.setLineStyle(originalLineStyle);
}
Aggregations