Search in sources :

Example 11 with BorderStyle

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

Example 12 with BorderStyle

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

Example 13 with BorderStyle

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

Example 14 with BorderStyle

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;
}
Also used : HorizontalAlignmentEnum(org.eclipse.nebula.widgets.nattable.style.HorizontalAlignmentEnum) BorderStyle(org.eclipse.nebula.widgets.nattable.style.BorderStyle) Color(org.eclipse.swt.graphics.Color) Style(org.eclipse.nebula.widgets.nattable.style.Style) BorderStyle(org.eclipse.nebula.widgets.nattable.style.BorderStyle) VerticalAlignmentEnum(org.eclipse.nebula.widgets.nattable.style.VerticalAlignmentEnum) Font(org.eclipse.swt.graphics.Font)

Example 15 with BorderStyle

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);
    }
}
Also used : BorderPainter(org.eclipse.nebula.widgets.nattable.painter.cell.BorderPainter) PaintModeEnum(org.eclipse.nebula.widgets.nattable.painter.cell.BorderPainter.PaintModeEnum) 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