Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Subclasing TextPainter - chanigng colors is impossible
Subclasing TextPainter - chanigng colors is impossible [message #988524] Fri, 30 November 2012 11:07 Go to next message
Alex Kipling is currently offline Alex Kipling
Messages: 253
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 #988529 is a reply to message #988524] Fri, 30 November 2012 11:26 Go to previous messageGo to next message
Alex Kipling is currently offline Alex Kipling
Messages: 253
Registered: July 2012
Senior Member
Found a way to hook into the color setting by overriding setupGCFromConfig inside the Textpainter
    @Override
    public void setupGCFromConfig(GC gc, IStyle cellStyle) {
        super.setupGCFromConfig(gc, cellStyle);
        // override own colors
        if (textColor != null) {
            gc.setForeground(textColor);
        }
        if (bgColor != null) {
            gc.setBackground(bgColor);
        }
    }
Re: Subclasing TextPainter - chanigng colors is impossible [message #988535 is a reply to message #988529] Fri, 30 November 2012 11:45 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk Fauth
Messages: 1289
Registered: July 2012
Senior Member
No, this violates our concepts of separating rendering and styling.

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.

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.

You find more information on styling in NatTable here:
http://eclipse.org/nattable/documentation.php?page=styling
Re: Subclasing TextPainter - chanigng colors is impossible [message #988538 is a reply to message #988535] Fri, 30 November 2012 12:03 Go to previous messageGo to next message
Alex Kipling is currently offline Alex Kipling
Messages: 253
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 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk Fauth
Messages: 1289
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.
Re: Subclasing TextPainter - chanigng colors is impossible [message #988544 is a reply to message #988543] Fri, 30 November 2012 12:35 Go to previous messageGo to next message
Alex Kipling is currently offline Alex Kipling
Messages: 253
Registered: July 2012
Senior Member
So you mean, that Painter can be replaced, but should still be bound to the cell style?

I defer, than! Smile

Re: Subclasing TextPainter - chanigng colors is impossible [message #988547 is a reply to message #988544] Fri, 30 November 2012 12:42 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk Fauth
Messages: 1289
Registered: July 2012
Senior Member
Alex Kipling wrote on Fri, 30 November 2012 13:35
So you mean, that Painter can be replaced, but should still be bound to the cell style?


I don't understand the question. Are you doing different rendering additional to the different styles? Than yes! Are you just doing the same stuff the TextPainter already does, and just subclassed because of the styling, then get rid of your implementation and use the TextPainter. Smile
Re: Subclasing TextPainter - chanigng colors is impossible [message #988548 is a reply to message #988547] Fri, 30 November 2012 12:43 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk Fauth
Messages: 1289
Registered: July 2012
Senior Member
No Message Body
Re: Subclasing TextPainter - chanigng colors is impossible [message #988571 is a reply to message #988548] Fri, 30 November 2012 14:48 Go to previous message
Alex Kipling is currently offline Alex Kipling
Messages: 253
Registered: July 2012
Senior Member
My rendere does teh same thing, like TextPainter.
It just whants to use cellStyle independant colors.

Since Renderers seem to be independant objects, it seems to fit into the NatTable concepts.
Previous Topic:How can I set the summary row on a fixed position (below the body)?
Next Topic:p2-Repository for NatTable
Goto Forum:
  


Current Time: Sat Sep 20 08:07:55 GMT 2014

Powered by FUDForum. Page generated in 0.03917 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software