Subclasing TextPainter - chanigng colors is impossible [message #988524] |
Fri, 30 November 2012 11:07 |
Alex Kipling Messages: 260 Registered: July 2012 |
Senior Member |
|
|
Is it intended, that TextPainter ALLWAYS gets the colors from the Cell's IStyle?
When subclassing TextPainter - it seems impossible to change the colors, without chaning the IStyle.
Changing the IStyle seems to be problematic too, since it is unknow, which Label it was attached to.
MyPainter extends TextPainter
...
@Override
public void paintCell(ILayerCell cell, GC gc, Rectangle rectangle, IConfigRegistry configRegistry) {
// override the colors
IStyle style = CellStyleUtil.getCellStyle(cell, configRegistry);
cellStyle.setAttributeValue(CellStyleAttributes.FOREGROUND_COLOR, TEXT_COLOR);
cellStyle.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, BG_COLOR);
LabelStack labelsStack = cell.getConfigLabels();
List<String> labels = labelsStack.getLabels(); //which Label do i have to use to chenge the Style, responsible for the Bg colors?
Style style = new Style();
style.setAttributeValue(CellStyleAttributes.FOREGROUND_COLOR, GUIHelper.COLOR_BLUE);
style.setAttributeValue(CellStyleAttributes.BACKGROUND_COLOR, GUIHelper.COLOR_WHITE);
configRegistry.registerConfigAttribute(CellConfigAttributes.CELL_STYLE, style, DisplayMode.NORMAL,?WHICHLABEL?);
Wouldn't it be easier to provide some king of methods a la "setTextColor, setBgColor" ?
|
|
|
|
|
Re: Subclasing TextPainter - chanigng colors is impossible [message #988538 is a reply to message #988535] |
Fri, 30 November 2012 12:03 |
Alex Kipling Messages: 260 Registered: July 2012 |
Senior Member |
|
|
Dirk Fauth wrote on Fri, 30 November 2012 06:45
It is not unknown which labels are applied, this information is stored within the cell. That's how the CellStyleUtil is retrieving the Style to use for rendering.
And what happens, if there are multiple Labels? E.g. one, registerd t oa column, and one to the cell itselfe.
Which Label t use, to change the style?
Dirk Fauth wrote on Fri, 30 November 2012 06:45
If you want to change the styling, than you should use the mechanism provided by NatTable to be flexible. Your mechanism would need to change the painter everytime instead of simply changing the style attached to a cell.
I am aware of this. But why is a Renderer (here it is TextPainter) forced to use the styling?
It is just about the concrete case, where TextPainter has to use colors, provided by Cellstyle.
But now I found a workaround, by using setupGCFromConfig()
|
|
|
Re: Subclasing TextPainter - chanigng colors is impossible [message #988543 is a reply to message #988538] |
Fri, 30 November 2012 12:17 |
Dirk Fauth Messages: 2903 Registered: July 2012 |
Senior Member |
|
|
Alex Kipling wrote on Fri, 30 November 2012 13:03
And what happens, if there are multiple Labels? E.g. one, registerd t oa column, and one to the cell itselfe.
Which Label t use, to change the style?
It checks the LabelStack top down. So it uses the topmost label and will check further down the LabelStack if the attribute you are requesting is not found for that label.
Alex Kipling wrote on Fri, 30 November 2012 13:03
But why is a Renderer (here it is TextPainter) forced to use the styling?
As I said, your mechanism breaks the flexibility. If you want to use one style everytime, than define just one. And if you want a fixed style dependent on some conditions, add the label on top of the LabelStack.
You can simply achieve what you are trying to do by using existing funtionality without subclassing our painters. Unless of course you are trying to render differently. But just because of styles it isn't necessary. And IMHO not suggested.
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.05015 seconds