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);
}
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);
}
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);
}
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);
}
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;
}
Aggregations