Search in sources :

Example 1 with IStyle

use of org.eclipse.nebula.widgets.nattable.style.IStyle in project nebula.widgets.nattable by eclipse.

the class BoxingStyleTest method retrievedCellShouldHaveConfiguredForegroundColor.

// Foreground color
@Test
public void retrievedCellShouldHaveConfiguredForegroundColor() {
    // Register foreground color for body cells in normal mode
    final Color foregroundColor = Display.getDefault().getSystemColor(SWT.COLOR_BLACK);
    this.cellStyle.setAttributeValue(CellStyleAttributes.FOREGROUND_COLOR, foregroundColor);
    this.configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, this.cellStyle, DisplayMode.NORMAL, AlternatingRowConfigLabelAccumulator.ODD_ROW_CONFIG_TYPE);
    // Check cell foreground color
    ILayerCell cell = this.natTable.getCellByPosition(2, 2);
    IStyle cellStyle = this.configRegistry.getConfigAttribute(CellConfigAttributes.CELL_STYLE, cell.getDisplayMode(), cell.getConfigLabels().getLabels());
    Assert.assertEquals(foregroundColor, cellStyle.getAttributeValue(CellStyleAttributes.FOREGROUND_COLOR));
    // set up painter
    this.cellPainter.setupGCFromConfig(this.gc, cellStyle);
    Assert.assertEquals(foregroundColor, this.gc.getForeground());
}
Also used : IStyle(org.eclipse.nebula.widgets.nattable.style.IStyle) Color(org.eclipse.swt.graphics.Color) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) Test(org.junit.Test)

Example 2 with IStyle

use of org.eclipse.nebula.widgets.nattable.style.IStyle in project nebula.widgets.nattable by eclipse.

the class TextRenderingTest method verifyFontAttributes.

private void verifyFontAttributes() {
    // Check cell font attributes
    ILayerCell cell = this.natTable.getCellByPosition(2, 2);
    final FontData expectedFontData = this.defaultFont.getFontData()[0];
    IStyle cellStyle = this.configRegistry.getConfigAttribute(CellConfigAttributes.CELL_STYLE, cell.getDisplayMode(), cell.getConfigLabels().getLabels());
    final FontData actualFontData = cellStyle.getAttributeValue(CellStyleAttributes.FONT).getFontData()[0];
    Assert.assertEquals(actualFontData.getName(), expectedFontData.getName());
    Assert.assertEquals(actualFontData.getHeight(), expectedFontData.getHeight());
    Assert.assertEquals(actualFontData.getStyle(), expectedFontData.getStyle());
    // Draw font
    this.cellPainter.setupGCFromConfig(this.gc, cellStyle);
    final FontData exepectedDrawnFontData = this.gc.getFont().getFontData()[0];
    Assert.assertEquals(actualFontData.getName(), exepectedDrawnFontData.getName());
    Assert.assertEquals(actualFontData.getHeight(), exepectedDrawnFontData.getHeight());
    Assert.assertEquals(actualFontData.getStyle(), exepectedDrawnFontData.getStyle());
}
Also used : IStyle(org.eclipse.nebula.widgets.nattable.style.IStyle) FontData(org.eclipse.swt.graphics.FontData) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell)

Example 3 with IStyle

use of org.eclipse.nebula.widgets.nattable.style.IStyle 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 4 with IStyle

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

Example 5 with IStyle

use of org.eclipse.nebula.widgets.nattable.style.IStyle 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);
}
Also used : IStyle(org.eclipse.nebula.widgets.nattable.style.IStyle) FormulaResultDisplayConverter(org.eclipse.nebula.widgets.nattable.formula.FormulaResultDisplayConverter) BorderStyle(org.eclipse.nebula.widgets.nattable.style.BorderStyle) IStyle(org.eclipse.nebula.widgets.nattable.style.IStyle) Style(org.eclipse.nebula.widgets.nattable.style.Style) BorderStyle(org.eclipse.nebula.widgets.nattable.style.BorderStyle) TextCellEditor(org.eclipse.nebula.widgets.nattable.edit.editor.TextCellEditor) FormulaEditDisplayConverter(org.eclipse.nebula.widgets.nattable.formula.FormulaEditDisplayConverter)

Aggregations

IStyle (org.eclipse.nebula.widgets.nattable.style.IStyle)97 BorderStyle (org.eclipse.nebula.widgets.nattable.style.BorderStyle)50 Style (org.eclipse.nebula.widgets.nattable.style.Style)49 ICellPainter (org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter)24 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)8 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)7 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)6 HashMap (java.util.HashMap)5 AbstractRegistryConfiguration (org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration)5 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)5 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)5 ExtendedPersonWithAddress (org.eclipse.nebula.widgets.nattable.dataset.person.ExtendedPersonWithAddress)5 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)5 VisualRefreshCommand (org.eclipse.nebula.widgets.nattable.command.VisualRefreshCommand)4 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)4 ExtendedReflectiveColumnPropertyAccessor (org.eclipse.nebula.widgets.nattable.data.ExtendedReflectiveColumnPropertyAccessor)4 ListDataProvider (org.eclipse.nebula.widgets.nattable.data.ListDataProvider)4 DefaultDoubleDisplayConverter (org.eclipse.nebula.widgets.nattable.data.convert.DefaultDoubleDisplayConverter)4 GroupByDataLayer (org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByDataLayer)4 GroupByHeaderLayer (org.eclipse.nebula.widgets.nattable.extension.glazedlists.groupBy.GroupByHeaderLayer)4