use of org.eclipse.nebula.widgets.nattable.style.BorderStyle in project nebula.widgets.nattable by eclipse.
the class BorderStylePersistenceTest method canRecreateInstanceFromAPersistedString.
@Test
public void canRecreateInstanceFromAPersistedString() throws Exception {
BorderStyle borderStyle = new BorderStyle("2|100,110,120|DOTTED|INTERNAL");
assertEquals(2, borderStyle.getThickness());
assertEquals(100, borderStyle.getColor().getRed());
assertEquals(110, borderStyle.getColor().getGreen());
assertEquals(120, borderStyle.getColor().getBlue());
assertEquals(LineStyleEnum.DOTTED, borderStyle.getLineStyle());
assertEquals(BorderModeEnum.INTERNAL, borderStyle.getBorderMode());
}
use of org.eclipse.nebula.widgets.nattable.style.BorderStyle in project nebula.widgets.nattable by eclipse.
the class BorderStylePersistenceTest method canRecreateInstanceFromAPersistedStringWithoutBorderMode.
@Test
public void canRecreateInstanceFromAPersistedStringWithoutBorderMode() throws Exception {
BorderStyle borderStyle = new BorderStyle("2|100,110,120|DOTTED");
assertEquals(2, borderStyle.getThickness());
assertEquals(100, borderStyle.getColor().getRed());
assertEquals(110, borderStyle.getColor().getGreen());
assertEquals(120, borderStyle.getColor().getBlue());
assertEquals(LineStyleEnum.DOTTED, borderStyle.getLineStyle());
assertEquals(BorderModeEnum.CENTERED, borderStyle.getBorderMode());
}
use of org.eclipse.nebula.widgets.nattable.style.BorderStyle in project nebula.widgets.nattable by eclipse.
the class BorderStylePersistenceTest method toStringCreatesAPersistableString.
@Test
public void toStringCreatesAPersistableString() throws Exception {
BorderStyle borderStyle = new BorderStyle();
assertEquals("1|0,0,0|SOLID|CENTERED", borderStyle.toString());
}
use of org.eclipse.nebula.widgets.nattable.style.BorderStyle in project nebula.widgets.nattable by eclipse.
the class FillHandleLayerPainter 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 IConfigRegistry} 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 IConfigRegistry} 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 FillHandleLayerPainter method paintLayer.
@Override
public void paintLayer(ILayer natLayer, GC gc, int xOffset, int yOffset, Rectangle pixelRectangle, IConfigRegistry configRegistry) {
Rectangle positionRectangle = getPositionRectangleFromPixelRectangle(natLayer, pixelRectangle);
int columnPositionOffset = positionRectangle.x;
int rowPositionOffset = positionRectangle.y;
super.paintLayer(natLayer, gc, xOffset, yOffset, pixelRectangle, configRegistry);
ILayerCell fillHandleCell = null;
BorderCell[][] borderCells = new BorderCell[positionRectangle.height][positionRectangle.width];
boolean atLeastOne = false;
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) {
cellBounds = currentCell.getBounds();
if (isFillHandleRegion(currentCell)) {
insideBorder = true;
atLeastOne = true;
}
if (fillHandleCell == null && isFillHandleCell(currentCell)) {
fillHandleCell = currentCell;
}
}
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 fillHandleRegionBorderStyle = getHandleRegionBorderStyle(configRegistry);
BorderPainter borderPainter = new BorderPainter(borderCells, fillHandleRegionBorderStyle);
borderPainter.paintBorder(gc);
// Restore original gc settings
gc.setLineStyle(originalLineStyle);
gc.setLineWidth(originalLineWidth);
gc.setForeground(originalForeground);
}
// paint the border around the copied cells if a clipboard is set
if (this.clipboard != null && this.clipboard.getCopiedCells() != null) {
paintCopyBorder(natLayer, gc, xOffset, yOffset, pixelRectangle, configRegistry);
}
// to find it and eventually repaint it
if (fillHandleCell == null && positionRectangle.width <= 2 && positionRectangle.height <= 2) {
for (int columnPosition = columnPositionOffset - 1; columnPosition < columnPositionOffset + positionRectangle.width + 1 && fillHandleCell == null; columnPosition++) {
for (int rowPosition = rowPositionOffset - 1; rowPosition < rowPositionOffset + positionRectangle.height + 1 && fillHandleCell == null; rowPosition++) {
ILayerCell currentCell = natLayer.getCellByPosition(columnPosition, rowPosition);
if (currentCell != null) {
if (isFillHandleCell(currentCell)) {
fillHandleCell = currentCell;
}
}
}
}
}
if (fillHandleCell != null) {
paintFillHandle(fillHandleCell, gc, xOffset, yOffset, configRegistry);
} else {
// set the local stored bounds to null as no handle is rendered and
// therefore event matchers shouldn't react anymore
this.handleBounds = null;
}
}
Aggregations