Search in sources :

Example 1 with BorderStyle

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());
}
Also used : BorderStyle(org.eclipse.nebula.widgets.nattable.style.BorderStyle) Test(org.junit.Test)

Example 2 with BorderStyle

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());
}
Also used : BorderStyle(org.eclipse.nebula.widgets.nattable.style.BorderStyle) Test(org.junit.Test)

Example 3 with BorderStyle

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());
}
Also used : BorderStyle(org.eclipse.nebula.widgets.nattable.style.BorderStyle) Test(org.junit.Test)

Example 4 with BorderStyle

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());
    }
}
Also used : IStyle(org.eclipse.nebula.widgets.nattable.style.IStyle) BorderStyle(org.eclipse.nebula.widgets.nattable.style.BorderStyle)

Example 5 with BorderStyle

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;
    }
}
Also used : BorderPainter(org.eclipse.nebula.widgets.nattable.painter.cell.BorderPainter) BorderStyle(org.eclipse.nebula.widgets.nattable.style.BorderStyle) Color(org.eclipse.swt.graphics.Color) Rectangle(org.eclipse.swt.graphics.Rectangle) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) BorderCell(org.eclipse.nebula.widgets.nattable.painter.cell.BorderPainter.BorderCell)

Aggregations

BorderStyle (org.eclipse.nebula.widgets.nattable.style.BorderStyle)33 Color (org.eclipse.swt.graphics.Color)11 IStyle (org.eclipse.nebula.widgets.nattable.style.IStyle)9 Style (org.eclipse.nebula.widgets.nattable.style.Style)6 Rectangle (org.eclipse.swt.graphics.Rectangle)5 Test (org.junit.Test)5 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)4 ILayerCell (org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)3 ICellPainter (org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter)3 HorizontalAlignmentEnum (org.eclipse.nebula.widgets.nattable.style.HorizontalAlignmentEnum)3 VerticalAlignmentEnum (org.eclipse.nebula.widgets.nattable.style.VerticalAlignmentEnum)3 Font (org.eclipse.swt.graphics.Font)3 Point (org.eclipse.swt.graphics.Point)3 List (java.util.List)2 CSSStylableElement (org.eclipse.e4.ui.css.core.dom.CSSStylableElement)2 CSS2FontProperties (org.eclipse.e4.ui.css.core.dom.properties.css2.CSS2FontProperties)2 CSSElementContext (org.eclipse.e4.ui.css.core.engine.CSSElementContext)2 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)2 IOverlayPainter (org.eclipse.nebula.widgets.nattable.painter.IOverlayPainter)2 BorderPainter (org.eclipse.nebula.widgets.nattable.painter.cell.BorderPainter)2