Search in sources :

Example 1 with AutoResizeRowCommandFixture

use of org.eclipse.nebula.widgets.nattable.test.fixture.command.AutoResizeRowCommandFixture 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)

Aggregations

IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)1 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)1 TextPainter (org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter)1 AutoResizeRowCommandFixture (org.eclipse.nebula.widgets.nattable.test.fixture.command.AutoResizeRowCommandFixture)1 CellFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.CellFixture)1 DataLayerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture)1 GCFactory (org.eclipse.nebula.widgets.nattable.util.GCFactory)1 GC (org.eclipse.swt.graphics.GC)1 Rectangle (org.eclipse.swt.graphics.Rectangle)1 Test (org.junit.Test)1