Search in sources :

Example 1 with GCFactory

use of org.eclipse.nebula.widgets.nattable.util.GCFactory in project nebula.widgets.nattable by eclipse.

the class AutoResizeColumnsTest method setUp.

@Before
public void setUp() {
    this.configRegistry = new ConfigRegistry();
    new DefaultNatTableStyleConfiguration().configureRegistry(this.configRegistry);
    this.img = new Image(Display.getDefault(), new Rectangle(0, 0, 200, 150));
    this.gcFactory = new GCFactory(this.img);
    // Use a common, foxed width font to avoid failing the test on a
    // different platform
    Font normalFont = GUIHelper.getFont(new FontData("Courier", 8, SWT.NORMAL));
    Style cellStyle = new Style();
    cellStyle.setAttributeValue(CellStyleAttributes.FONT, normalFont);
    this.configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, DisplayMode.NORMAL);
}
Also used : ConfigRegistry(org.eclipse.nebula.widgets.nattable.config.ConfigRegistry) GCFactory(org.eclipse.nebula.widgets.nattable.util.GCFactory) DefaultNatTableStyleConfiguration(org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration) FontData(org.eclipse.swt.graphics.FontData) Rectangle(org.eclipse.swt.graphics.Rectangle) Style(org.eclipse.nebula.widgets.nattable.style.Style) Image(org.eclipse.swt.graphics.Image) Font(org.eclipse.swt.graphics.Font) Before(org.junit.Before)

Example 2 with GCFactory

use of org.eclipse.nebula.widgets.nattable.util.GCFactory 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 3 with GCFactory

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

use of org.eclipse.nebula.widgets.nattable.util.GCFactory in project nebula.widgets.nattable by eclipse.

the class AutoResizeRowAction method run.

@Override
public void run(NatTable natTable, MouseEvent event) {
    Point clickPoint = new Point(event.x, event.y);
    int row = CellEdgeDetectUtil.getRowPositionToResize(natTable, clickPoint);
    InitializeAutoResizeRowsCommand command = new InitializeAutoResizeRowsCommand(natTable, row, natTable.getConfigRegistry(), new GCFactory(natTable));
    natTable.doCommand(command);
}
Also used : GCFactory(org.eclipse.nebula.widgets.nattable.util.GCFactory) InitializeAutoResizeRowsCommand(org.eclipse.nebula.widgets.nattable.resize.command.InitializeAutoResizeRowsCommand) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point)

Example 5 with GCFactory

use of org.eclipse.nebula.widgets.nattable.util.GCFactory in project nebula.widgets.nattable by eclipse.

the class MenuItemProviders method autoResizeAllSelectedColumnMenuItemProvider.

public static IMenuItemProvider autoResizeAllSelectedColumnMenuItemProvider(final String menuLabel) {
    return new IMenuItemProvider() {

        @Override
        public void addMenuItem(final NatTable natTable, final Menu popupMenu) {
            MenuItem autoResizeColumns = new MenuItem(popupMenu, SWT.PUSH);
            autoResizeColumns.setText(Messages.getLocalizedMessage(menuLabel));
            autoResizeColumns.setEnabled(true);
            autoResizeColumns.addSelectionListener(new SelectionAdapter() {

                @Override
                public void widgetSelected(SelectionEvent event) {
                    int columnPosition = getNatEventData(event).getColumnPosition();
                    natTable.doCommand(new InitializeAutoResizeColumnsCommand(natTable, columnPosition, natTable.getConfigRegistry(), new GCFactory(natTable)));
                }
            });
        }
    };
}
Also used : GCFactory(org.eclipse.nebula.widgets.nattable.util.GCFactory) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) InitializeAutoResizeColumnsCommand(org.eclipse.nebula.widgets.nattable.resize.command.InitializeAutoResizeColumnsCommand) SelectionEvent(org.eclipse.swt.events.SelectionEvent) NatTable(org.eclipse.nebula.widgets.nattable.NatTable) MenuItem(org.eclipse.swt.widgets.MenuItem) Menu(org.eclipse.swt.widgets.Menu)

Aggregations

GCFactory (org.eclipse.nebula.widgets.nattable.util.GCFactory)8 NatTable (org.eclipse.nebula.widgets.nattable.NatTable)3 InitializeAutoResizeColumnsCommand (org.eclipse.nebula.widgets.nattable.resize.command.InitializeAutoResizeColumnsCommand)3 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)3 SelectionEvent (org.eclipse.swt.events.SelectionEvent)3 Rectangle (org.eclipse.swt.graphics.Rectangle)3 Menu (org.eclipse.swt.widgets.Menu)3 MenuItem (org.eclipse.swt.widgets.MenuItem)3 IConfigRegistry (org.eclipse.nebula.widgets.nattable.config.IConfigRegistry)2 IDataProvider (org.eclipse.nebula.widgets.nattable.data.IDataProvider)2 TextPainter (org.eclipse.nebula.widgets.nattable.painter.cell.TextPainter)2 InitializeAutoResizeRowsCommand (org.eclipse.nebula.widgets.nattable.resize.command.InitializeAutoResizeRowsCommand)2 CellFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.CellFixture)2 DataLayerFixture (org.eclipse.nebula.widgets.nattable.test.fixture.layer.DataLayerFixture)2 GC (org.eclipse.swt.graphics.GC)2 Point (org.eclipse.swt.graphics.Point)2 Test (org.junit.Test)2 ConfigRegistry (org.eclipse.nebula.widgets.nattable.config.ConfigRegistry)1 DefaultNatTableStyleConfiguration (org.eclipse.nebula.widgets.nattable.config.DefaultNatTableStyleConfiguration)1 Style (org.eclipse.nebula.widgets.nattable.style.Style)1