Search in sources :

Example 1 with AutoResizeColumnCommandFixture

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

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 AutoResizeColumnCommandFixture (org.eclipse.nebula.widgets.nattable.test.fixture.command.AutoResizeColumnCommandFixture)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