Search in sources :

Example 1 with TextPainter

use of org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter in project nebula.widgets.nattable by eclipse.

the class MaxCellBoundsHelperTest method getPreferedRowHeights.

@Test
public void getPreferedRowHeights() throws Exception {
    DataLayerFixture dataLayer = new DataLayerFixture(3, 2, 10, 10);
    IDataProvider dataProvider = dataLayer.getDataProvider();
    // Row 0
    dataProvider.setDataValue(0, 0, "..");
    dataProvider.setDataValue(1, 0, "...");
    dataProvider.setDataValue(2, 0, "...");
    // Row 1
    dataProvider.setDataValue(0, 1, "Elephant");
    dataProvider.setDataValue(1, 1, "Cat");
    dataProvider.setDataValue(2, 1, "Rat");
    AutoResizeRowCommandFixture command = new AutoResizeRowCommandFixture();
    GCFactory gcFactory = command.getGCFactory();
    IConfigRegistry registry = command.getConfigRegistry();
    GC gc = gcFactory.createGC();
    int row0MaxTextHeight = new TextPainter().getPreferredHeight(new CellFixture(".."), gc, registry);
    int row1MaxTextHeight = new TextPainter().getPreferredHeight(new CellFixture("Elephant"), gc, registry);
    gc.dispose();
    int[] maxRowHeights = MaxCellBoundsHelper.getPreferredRowHeights(registry, gcFactory, dataLayer, new int[] { 0, 1 });
    // Adjust heights
    int row0AdjustedMaxHeight = dataLayer.getLayerPainter().adjustCellBounds(0, 0, new Rectangle(0, 0, 10, maxRowHeights[0])).height;
    int row1AdjustedMaxHeight = dataLayer.getLayerPainter().adjustCellBounds(0, 1, new Rectangle(0, 0, 10, maxRowHeights[1])).height;
    Assert.assertEquals(row0MaxTextHeight, row0AdjustedMaxHeight);
    Assert.assertEquals(row1MaxTextHeight, row1AdjustedMaxHeight);
}
Also used : GCFactory(org.eclipse.nebula.widgets.nattable.util.GCFactory) CellFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.CellFixture) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DataLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture) Rectangle(org.eclipse.swt.graphics.Rectangle) AutoResizeRowCommandFixture(org.eclipse.nebula.widgets.nattable.test.fixture.command.AutoResizeRowCommandFixture) TextPainter(org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) GC(org.eclipse.swt.graphics.GC) Test(org.junit.Test)

Example 2 with TextPainter

use of org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter in project nebula.widgets.nattable by eclipse.

the class MaxCellBoundsHelperTest method getPreferedColumnWidths.

@Test
public void getPreferedColumnWidths() throws Exception {
    DataLayerFixture dataLayer = new DataLayerFixture(2, 3, 10, 10);
    IDataProvider dataProvider = dataLayer.getDataProvider();
    // Col 0
    dataProvider.setDataValue(0, 0, "Long");
    dataProvider.setDataValue(0, 1, "Longer");
    dataProvider.setDataValue(0, 2, "Longest Text");
    // Col 1
    dataProvider.setDataValue(1, 0, "Elephant");
    dataProvider.setDataValue(1, 1, "Cat");
    dataProvider.setDataValue(1, 2, "Rat");
    AutoResizeColumnCommandFixture command = new AutoResizeColumnCommandFixture();
    GCFactory gcFactory = command.getGCFactory();
    IConfigRegistry registry = command.getConfigRegistry();
    GC gc = gcFactory.createGC();
    int col0MaxTextWidth = new TextPainter().getPreferredWidth(new CellFixture("Longest Text"), gc, registry);
    int col1MaxTextWidth = new TextPainter().getPreferredWidth(new CellFixture("Elephant"), gc, registry);
    gc.dispose();
    int[] maxColumnWidths = MaxCellBoundsHelper.getPreferredColumnWidths(registry, gcFactory, dataLayer, new int[] { 0, 1 });
    // Adjust widths
    int col0AdjustedMaxWidth = dataLayer.getLayerPainter().adjustCellBounds(0, 0, new Rectangle(0, 0, maxColumnWidths[0], 10)).width;
    int col1AdjustedMaxWidth = dataLayer.getLayerPainter().adjustCellBounds(1, 0, new Rectangle(0, 0, maxColumnWidths[1], 10)).width;
    Assert.assertEquals(col0MaxTextWidth, col0AdjustedMaxWidth);
    Assert.assertEquals(col1MaxTextWidth, col1AdjustedMaxWidth);
}
Also used : GCFactory(org.eclipse.nebula.widgets.nattable.util.GCFactory) CellFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.CellFixture) AutoResizeColumnCommandFixture(org.eclipse.nebula.widgets.nattable.test.fixture.command.AutoResizeColumnCommandFixture) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DataLayerFixture(org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture) Rectangle(org.eclipse.swt.graphics.Rectangle) TextPainter(org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) GC(org.eclipse.swt.graphics.GC) Test(org.junit.Test)

Example 3 with TextPainter

use of org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter in project nebula.widgets.nattable by eclipse.

the class ComboBoxFilterRowConfiguration method configureRegistry.

@Override
public void configureRegistry(IConfigRegistry configRegistry) {
    configRegistry.registerConfigAttribute(EditConfigAttributes.CELL_EDITOR, this.cellEditor, DisplayMode.NORMAL, GridRegion.FILTER_ROW);
    configRegistry.registerConfigAttribute(FilterRowConfigAttributes.TEXT_MATCHING_MODE, TextMatchingMode.REGULAR_EXPRESSION);
    ICellPainter cellPainter = new CellPainterDecorator(new TextPainter() {

        {
            this.paintFg = false;
        }

        // override the preferred width and height to be 0, as otherwise
        // the String that is generated in the background for multiple
        // selection will be taken into account for auto resizing
        @Override
        public int getPreferredWidth(ILayerCell cell, GC gc, IConfigRegistry configRegistry) {
            return 0;
        }

        @Override
        public int getPreferredHeight(ILayerCell cell, GC gc, IConfigRegistry configRegistry) {
            return 0;
        }
    }, CellEdgeEnum.RIGHT, this.filterIconPainter);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, cellPainter, DisplayMode.NORMAL, GridRegion.FILTER_ROW);
}
Also used : IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) TextPainter(org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter) CellPainterDecorator(org.eclipse.nebula.widgets.nattable.painter.cell.decorator.CellPainterDecorator) ILayerCell(org.eclipse.nebula.widgets.nattable.layer.cell.ILayerCell) GC(org.eclipse.swt.graphics.GC) ICellPainter(org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter)

Example 4 with TextPainter

use of org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter in project nebula.widgets.nattable by eclipse.

the class DefaultHierarchicalTreeLayerConfiguration method configureRegistry.

@Override
public void configureRegistry(IConfigRegistry configRegistry) {
    // configure the tree structure painter
    ICellPainter treeImagePainter = new PaddingDecorator(new TreeImagePainter(), 5, 2, 5, 2);
    IndentedTreeImagePainter treePainter = new IndentedTreeImagePainter(0, CellEdgeEnum.TOP_LEFT, treeImagePainter);
    treePainter.getInternalPainter().setPaintDecorationDependent(false);
    ICellPainter treeStructurePainter = new BackgroundPainter(treePainter);
    configRegistry.registerConfigAttribute(TreeConfigAttributes.TREE_STRUCTURE_PAINTER, treeStructurePainter, DisplayMode.NORMAL);
    // configure the style and the cell painter for the tree/node columns
    // necessary because the IndentedTreeImagePainter is inspecting and
    // using the underlying painter
    ICellPainter basePainter = new PaddingDecorator(new TextPainter(), 2, 2, 2, 15);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, basePainter, DisplayMode.NORMAL, TreeLayer.TREE_COLUMN_CELL);
    Style treeStyle = new Style();
    treeStyle.setAttributeValue(CellStyleAttributes.VERTICAL_ALIGNMENT, VerticalAlignmentEnum.TOP);
    treeStyle.setAttributeValue(CellStyleAttributes.HORIZONTAL_ALIGNMENT, HorizontalAlignmentEnum.LEFT);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, treeStyle, DisplayMode.NORMAL, TreeLayer.TREE_COLUMN_CELL);
    // configure styling for tree level header
    Style levelHeaderStyle = new Style();
    levelHeaderStyle.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, this.levelHeaderColor);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, levelHeaderStyle, DisplayMode.NORMAL, HierarchicalTreeLayer.LEVEL_HEADER_CELL);
    Style levelHeaderSelectedStyle = new Style();
    levelHeaderSelectedStyle.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, this.levelHeaderSelectedColor);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, levelHeaderSelectedStyle, DisplayMode.SELECT, HierarchicalTreeLayer.LEVEL_HEADER_CELL);
    // register special empty painter to not render content in collapsed
    // childs
    // this also allows for example some different styling of collapsed
    // childs
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, new BackgroundPainter(), DisplayMode.NORMAL, HierarchicalTreeLayer.COLLAPSED_CHILD);
    // configure alternate row style
    Style evenRowCellStyle = new Style();
    evenRowCellStyle.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, this.evenRowBgColor);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, evenRowCellStyle, DisplayMode.NORMAL, AlternatingRowConfigLabelAccumulator.EVEN_ROW_CONFIG_TYPE);
    Style oddRowCellStyle = new Style();
    oddRowCellStyle.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, this.oddRowBgColor);
    configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, oddRowCellStyle, DisplayMode.NORMAL, AlternatingRowConfigLabelAccumulator.ODD_ROW_CONFIG_TYPE);
    configureEditableRules(configRegistry);
}
Also used : BackgroundPainter(org.eclipse.nebula.widgets.nattable.painter.cell.BackgroundPainter) PaddingDecorator(org.eclipse.nebula.widgets.nattable.painter.cell.decorator.PaddingDecorator) Style(org.eclipse.nebula.widgets.nattable.style.Style) TextPainter(org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter) IndentedTreeImagePainter(org.eclipse.nebula.widgets.nattable.tree.painter.IndentedTreeImagePainter) IndentedTreeImagePainter(org.eclipse.nebula.widgets.nattable.tree.painter.IndentedTreeImagePainter) TreeImagePainter(org.eclipse.nebula.widgets.nattable.tree.painter.TreeImagePainter) ICellPainter(org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter)

Example 5 with TextPainter

use of org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter in project nebula.widgets.nattable by eclipse.

the class _5062_CompositeHoverStylingExample method createExampleControl.

@Override
public Control createExampleControl(Composite parent) {
    // property names of the Person class
    String[] propertyNames = { "firstName", "lastName", "gender", "married", "birthday" };
    // mapping from property to label, needed for column header labels
    Map<String, String> propertyToLabelMap = new HashMap<>();
    propertyToLabelMap.put("firstName", "Firstname");
    propertyToLabelMap.put("lastName", "Lastname");
    propertyToLabelMap.put("gender", "Gender");
    propertyToLabelMap.put("married", "Married");
    propertyToLabelMap.put("birthday", "Birthday");
    // build the body layer stack
    // Usually you would create a new layer stack by extending
    // AbstractIndexLayerTransform and setting the ViewportLayer
    // as underlying layer. But in this case using the ViewportLayer
    // directly as body layer is also working.
    IDataProvider bodyDataProvider = new DefaultBodyDataProvider<>(PersonService.getPersons(10), propertyNames);
    DataLayer bodyDataLayer = new DataLayer(bodyDataProvider);
    HoverLayer hoverLayer = new HoverLayer(bodyDataLayer);
    SelectionLayer selectionLayer = new SelectionLayer(hoverLayer);
    ViewportLayer viewportLayer = new ViewportLayer(selectionLayer);
    // build the column header layer
    IDataProvider columnHeaderDataProvider = new DefaultColumnHeaderDataProvider(propertyNames, propertyToLabelMap);
    DataLayer columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
    HoverLayer columnHoverLayer = new HoverLayer(columnHeaderDataLayer, false);
    ColumnHeaderLayer columnHeaderLayer = new ColumnHeaderLayer(columnHoverLayer, viewportLayer, selectionLayer, false);
    // add ColumnHeaderHoverLayerConfiguration to ensure that hover styling
    // and resizing is working together
    columnHeaderLayer.addConfiguration(new ColumnHeaderHoverLayerConfiguration(columnHoverLayer));
    CompositeLayer compLayer = new CompositeLayer(1, 2);
    compLayer.setChildLayer(GridRegion.COLUMN_HEADER, columnHeaderLayer, 0, 0);
    compLayer.setChildLayer(GridRegion.BODY, viewportLayer, 0, 1);
    // turn the auto configuration off as we want to add our hover styling
    // configuration
    NatTable natTable = new NatTable(parent, compLayer, false);
    // as the autoconfiguration of the NatTable is turned off, we have to
    // add the DefaultNatTableStyleConfiguration manually
    natTable.addConfiguration(new DefaultNatTableStyleConfiguration());
    // add the style configuration for hover
    natTable.addConfiguration(new AbstractRegistryConfiguration() {

        @Override
        public void configureRegistry(IConfigRegistry configRegistry) {
            Style style = new Style();
            style.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, GUIHelper.getColor(217, 232, 251));
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.HOVER);
            Image bgImage = GUIHelper.getImageByURL("columnHeaderBg", getClass().getResource("/org/eclipse/nebula/widgets/nattable/examples/resources/column_header_bg.png"));
            Image hoverBgImage = GUIHelper.getImageByURL("hoverColumnHeaderBg", getClass().getResource("/org/eclipse/nebula/widgets/nattable/examples/resources/hovered_column_header_bg.png"));
            TextPainter txtPainter = new TextPainter(false, false);
            ICellPainter bgImagePainter = new BackgroundImagePainter(txtPainter, bgImage, GUIHelper.getColor(192, 192, 192));
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, bgImagePainter, DisplayMode.NORMAL, GridRegion.COLUMN_HEADER);
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, bgImagePainter, DisplayMode.NORMAL, GridRegion.CORNER);
            ICellPainter hoveredHeaderPainter = new BackgroundImagePainter(txtPainter, hoverBgImage, GUIHelper.getColor(192, 192, 192));
            configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, hoveredHeaderPainter, DisplayMode.HOVER, GridRegion.COLUMN_HEADER);
        }
    });
    natTable.configure();
    return natTable;
}
Also used : ColumnHeaderHoverLayerConfiguration(org.eclipse.nebula.widgets.nattable.hover.config.ColumnHeaderHoverLayerConfiguration) HashMap(java.util.HashMap) ColumnHeaderLayer(org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer) AbstractRegistryConfiguration(org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration) IDataProvider(org.eclipse.nebula.widgets.nattable.data.IDataProvider) HoverLayer(org.eclipse.nebula.widgets.nattable.hover.HoverLayer) ViewportLayer(org.eclipse.nebula.widgets.nattable.viewport.ViewportLayer) Image(org.eclipse.swt.graphics.Image) DefaultBodyDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultBodyDataProvider) ICellPainter(org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter) DataLayer(org.eclipse.nebula.widgets.nattable.layer.DataLayer) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) Style(org.eclipse.nebula.widgets.nattable.style.Style) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) BackgroundImagePainter(org.eclipse.nebula.widgets.nattable.painter.cell.BackgroundImagePainter) TextPainter(org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter) DefaultColumnHeaderDataLayer(org.eclipse.nebula.widgets.nattable.grid.layer.DefaultColumnHeaderDataLayer) CompositeLayer(org.eclipse.nebula.widgets.nattable.layer.CompositeLayer) SelectionLayer(org.eclipse.nebula.widgets.nattable.selection.SelectionLayer) IConfigRegistry(org.eclipse.nebula.widgets.nattable.config.IConfigRegistry) DefaultColumnHeaderDataProvider(org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)

Aggregations

TextPainter (org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter)21 ICellPainter (org.eclipse.nebula.widgets.nattable.painter.cell.ICellPainter)11 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)10 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)9 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)9 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)8 AbstractRegistryConfiguration (org.eclipse.nebula.widgets.nattable.config.AbstractRegistryConfiguration)7 DataLayer (org.eclipse.nebula.widgets.nattable.layer.DataLayer)7 BackgroundImagePainter (org.eclipse.nebula.widgets.nattable.painter.cell.BackgroundImagePainter)7 Style (org.eclipse.nebula.widgets.nattable.style.Style)7 Image (org.eclipse.swt.graphics.Image)7 DefaultColumnHeaderDataProvider (org.eclipse.nebula.widgets.nattable.grid.data.DefaultColumnHeaderDataProvider)6 HashMap (java.util.HashMap)5 CellPainterDecorator (org.eclipse.nebula.widgets.nattable.painter.cell.decorator.CellPainterDecorator)5 PaddingDecorator (org.eclipse.nebula.widgets.nattable.painter.cell.decorator.PaddingDecorator)5 SortableHeaderTextPainter (org.eclipse.nebula.widgets.nattable.sort.painter.SortableHeaderTextPainter)5 ColumnHeaderLayer (org.eclipse.nebula.widgets.nattable.grid.layer.ColumnHeaderLayer)4 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)3 ILayer (org.eclipse.nebula.widgets.nattable.layer.ILayer)3 BeveledBorderDecorator (org.eclipse.nebula.widgets.nattable.painter.cell.decorator.BeveledBorderDecorator)3