Home » Eclipse Projects » NatTable » GAP between the custom image and base content with background image(There is a gap between custom image and base content if have background image)
GAP between the custom image and base content with background image [message #1785750] |
Thu, 19 April 2018 10:47 |
chun liang Wen Messages: 10 Registered: December 2017 |
Junior Member |
|
|
Hi,
Experts.
I'm try to add an image to a cell which has background image. But there is a gap between the custom image and the cell's original content. (see my attachment)
my configuration code is :
public class ColumnHeaderStyleWithRedStarConfigurations extends DefaultColumnHeaderStyleConfiguration {
private String columnWithRedStarLabel;
public static final Image RED_STAR_ICON_IMAGE = GUIHelper.getImageByURL(Images.getURL(Images.COLUMN_HEADER_BACKGROUND_IMAGE_WITH_RED_STAR));
public static final Image COLUMN_HEADER_BACKGROUND_ICON_IMAGE = GUIHelper.getImageByURL(Images.getURL(Images.COLUMN_HEADER_BACKGROUND_IMAGE));
public ColumnHeaderStyleWithRedStarConfigurations(String columnWithRedStarLabel) {
this.columnWithRedStarLabel = columnWithRedStarLabel;
}
@Override
public void configureRegistry(IConfigRegistry configRegistry) {
Style cellStyle = new Style();
cellStyle.setAttributeValue(CellStyleAttributes.HORIZONTAL_ALIGNMENT, HorizontalAlignmentEnum.LEFT);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, DisplayMode.NORMAL, columnWithRedStarLabel);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, cellStyle, DisplayMode.SELECT, columnWithRedStarLabel);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, getCellPainterDecorator(), DisplayMode.NORMAL, columnWithRedStarLabel);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_PAINTER, getCellPainterDecorator(), DisplayMode.SELECT, columnWithRedStarLabel);
}
private CellPainterDecorator getCellPainterDecorator() {
/* try 1 */
return new CellPainterDecorator(new BackgroundImagePainter(new TextPainter(true, false, false), COLUMN_HEADER_BACKGROUND_ICON_IMAGE), CellEdgeEnum.LEFT, new ImagePainter(RED_STAR_ICON_IMAGE));
/* try 2 */
// return new CellPainterDecorator(new ScalingBackgroundImagePainter(new TextPainter(true, false, false), COLUMN_HEADER_BACKGROUND_ICON_IMAGE,
// ISSPTheme.COLOMN_HEADER_BACKGROUND_IMAGE), CellEdgeEnum.LEFT, new ImagePainter(RED_STAR_ICON_IMAGE));
/* try 3 */
// return new CellPainterDecorator(new TextPainter(true, false, false), CellEdgeEnum.LEFT, new ImagePainter(RED_STAR_ICON_IMAGE));
}
}
I added the configuration to my NatTable instance:
natTable.addConfiguration(new ColumnHeaderStyleWithRedStarConfigurations(COLUMN_WITH_RED_STAR_LABEL));
I've added the label COLUMN_WITH_RED_STAR_LABEL for the columns I want,
see code :
private void updateColumnNames() {
Set<Integer> filterIndexes = selectedFilterValues.keySet();
ColumnOverrideLabelAccumulator labelAccumulator = new ColumnOverrideLabelAccumulator(costTable.getColumnHeaderLayer());
for (int i = 0; i < costTable.getColumns().size(); i++) {
String colname = costTable.getColumns().get(i).getColumnName();
if (NAME_OF_TOTAL_COLUMN.equals(colname)) {
break;
}
Column col = costTable.getColumns().get(i);
boolean hasStar = col.getColumnName().startsWith(StringUtils.SPACE); // placeholder "space" with the column means that the column is filtered
boolean filteredCol = filterIndexes.contains(i);
if (hasStar && !filteredCol) {
costTable.getColumns().get(i).setColumnName(colname.substring(1)); // remove the "space"
} else if (!hasStar && filteredCol) {
col.setColumnName(StringUtils.SPACE + colname); // add the "space"
labelAccumulator.registerColumnOverridesOnTop(i, COLUMN_WITH_RED_STAR_LABEL);
}
}
costTable.getColumnHeaderLayer().setConfigLabelAccumulator(labelAccumulator);
costTable.refreshColumnLabels();
costTable.refreshData();
}
Is there a way to solve this problem? Or would you please give some advice?
Thanks in advance.
|
|
| |
Re: GAP between the custom image and base content with background image [message #1785792 is a reply to message #1785753] |
Fri, 20 April 2018 02:50 |
chun liang Wen Messages: 10 Registered: December 2017 |
Junior Member |
|
|
It worked after I change my code like this:
return new CellPainterDecorator(new ScalingBackgroundImagePainter(new TextPainter(true, false, false), COLUMN_HEADER_BACKGROUND_ICON_IMAGE,
ISSPTheme.COLOMN_HEADER_BACKGROUND_IMAGE), CellEdgeEnum.LEFT, 0, new ImagePainter(RED_STAR_ICON_IMAGE), true, false);
The root cause is that for the constructor I used before there are 2 pixels as spacing between base and decoration painter. So, for my scenario, it should be 0.
Dirk, Thank you very much for your help.
|
|
|
Re: GAP between the custom image and base content with background image [message #1785793 is a reply to message #1785792] |
Fri, 20 April 2018 03:20 |
chun liang Wen Messages: 10 Registered: December 2017 |
Junior Member |
|
|
And I've tried another solution using RichTextCellPainter . At first glance feeling no problem, but because it has a SortHeaderLayer above ColumnGroupHeaderLayer, if I click the column header, it will do sort action, and the column name will show the original html code I assigned to the column. Is there a way to resolve this issue?
If it can be fixed, which solution is better? the ImagePainter one OR this RichTextCellPainter one? Thanks very much for you help in advance.
my code snippet:
// build the column header layer
columnHeaderDataProvider = new IsspColumnHeaderDataProvider(columns);
columnHeaderDataLayer = new DefaultColumnHeaderDataLayer(columnHeaderDataProvider);
columnHeaderHoverLayer = new HoverLayer(columnHeaderDataLayer, false);
columnHeaderLayer = new ColumnHeaderLayer(columnHeaderHoverLayer, bodyLayerStack, bodyLayerStack.getSelectionLayer(), false);
columnHeaderLayer.addConfiguration(new ColumnHeaderHoverLayerConfiguration(columnHeaderHoverLayer));
// create column groups
columnGroupHeaderLayer = new IsspColumnGroupHeaderLayer(columnHeaderLayer, bodyLayerStack.getSelectionLayer(), bodyLayerStack.getColumnGroupModel());
columnGroupHeaderLayer.setDisplayHeaderLabel(displayColumnGroupLabels);
createColumnGroups(columnGroupHeaderLayer);
// calculate the height of the column header area dependent if column groups exist or not
columnGroupHeaderLayer.setCalculateHeight(true);
if (hasSortedHeader) {
configRegistry.registerConfigAttribute(SortConfigAttributes.SORT_COMPARATOR, IsspTableGenerator.this.getCustomComparator(), DisplayMode.NORMAL,
CUSTOM_NUMBER_COMPARATOR_LABEL);
sortHeaderLayer = new SortHeaderLayer<>(columnGroupHeaderLayer,
new GlazedListsSortModel<>(bodyLayerStack.getSortedList(), columnPropertyAccessor, configRegistry, columnHeaderHoverLayer), false);
sortHeaderLayer.addConfiguration(new SingleClickSortConfiguration(new BeveledBorderDecorator(new SortableHeaderTextPainter(new RichTextCellPainter()))));
}
// as the auto configuration of the NatTable is turned off, we have to
// add the DefaultNatTableStyleConfiguration and the ConfigRegistry manually
ColumnOverrideLabelAccumulator columnLabelHeaderAccumulator = new ColumnOverrideLabelAccumulator(columnHeaderHoverLayer);
columnHeaderHoverLayer.setConfigLabelAccumulator(columnLabelHeaderAccumulator);
for (int i = 0; i < columns.size(); i++) {
if (columns.get(i).hasNumericData()) {
columnLabelHeaderAccumulator.registerColumnOverrides(i, CUSTOM_NUMBER_COMPARATOR_LABEL);
}
}
add the label code snippet is :
private void updateColumnNames() {
Set<Integer> filterIndexes = selectedFilterValues.keySet();
ColumnOverrideLabelAccumulator labelAccumulator = new ColumnOverrideLabelAccumulator(costTable.getColumnHeaderLayer());
for (int i = 0; i < costTable.getColumns().size(); i++) {
String colname = costTable.getColumns().get(i).getColumnName();
if ("Total".equals(colname)) {
break;
}
Column col = costTable.getColumns().get(i);
boolean hasStar = col.getColumnName().startsWith("<span style=\"color:rgb(255,0,0)\">*</span>"); // placeholder a red *
boolean filteredCol = filterIndexes.contains(i);
if (hasStar && !filteredCol) {
costTable.getColumns().get(i).setColumnName(colname.substring(41));
} else if (!hasStar && filteredCol) {
col.setColumnName("<span style=\"color:rgb(255,0,0)\">*</span>" + colname);
labelAccumulator.registerColumnOverridesOnTop(i, COLUMN_WITH_RED_STAR_LABEL);
}
}
costTable.getColumnHeaderLayer().setConfigLabelAccumulator(labelAccumulator);
costTable.refreshColumnLabels();
costTable.refreshData();
}
|
|
| | | | |
Goto Forum:
Current Time: Thu Apr 18 16:33:37 GMT 2024
Powered by FUDForum. Page generated in 0.02216 seconds
|