To sub-class or not to sub-class [message #436897] |
Tue, 25 May 2004 23:04 |
Mark Freiheit Messages: 30 Registered: July 2009 |
Member |
|
|
I wish to create a Table (or a TableTree) that has alternating rows
colored.
The code to do this is fairly straight forward...
private static final Color oddRowBkgnd =
new Color(Display.getCurrent(), 187, 221, 238);
private static final Color evenRowBkgnd =
new Color(Display.getCurrent(), 255, 255, 255);
private static Color[] rowBkgnd = new Color[] { evenRowBkgnd,
oddRowBkgnd };
public static void colorTable (Table table) {
TableItem[] items = table.getItems();
for (int i = 0; i < items.length; i++) {
items[i].setBackground(rowBkgnd[i % rowBkgnd.length]);
}
}
But if I implement this in a TableTree, then I have to call this code from
each
event handler that alters the input to the table, including Filters and
expand/contract
events.
Is there a "pre-draw" event that I can listen for and call this code in
one place?
Am I better served sub-classing a TableTree (as say a StripedTableTree)?
If so,
what methods would I overload to accomplish the drawing?
Thanks in advance for any advice you can give me -- Mark
|
|
|
Re: To sub-class or not to sub-class [message #436898 is a reply to message #436897] |
Wed, 26 May 2004 00:11 |
Phil Williams Messages: 22 Registered: July 2009 |
Junior Member |
|
|
Why not just use a ColorProvider for your Table?
Mark wrote:
>I wish to create a Table (or a TableTree) that has alternating rows
>colored.
>The code to do this is fairly straight forward...
>
> private static final Color oddRowBkgnd =
> new Color(Display.getCurrent(), 187, 221, 238);
> private static final Color evenRowBkgnd =
> new Color(Display.getCurrent(), 255, 255, 255);
>
> private static Color[] rowBkgnd = new Color[] { evenRowBkgnd,
>oddRowBkgnd };
>
> public static void colorTable (Table table) {
>
> TableItem[] items = table.getItems();
> for (int i = 0; i < items.length; i++) {
> items[i].setBackground(rowBkgnd[i % rowBkgnd.length]);
> }
> }
>
>But if I implement this in a TableTree, then I have to call this code from
>each
>event handler that alters the input to the table, including Filters and
>expand/contract
>events.
>
>Is there a "pre-draw" event that I can listen for and call this code in
>one place?
>
>Am I better served sub-classing a TableTree (as say a StripedTableTree)?
>If so,
>what methods would I overload to accomplish the drawing?
>
>Thanks in advance for any advice you can give me -- Mark
>
>
>
|
|
|
Re: To sub-class or not to sub-class [message #436998 is a reply to message #436898] |
Thu, 27 May 2004 19:47 |
Mark Freiheit Messages: 30 Registered: July 2009 |
Member |
|
|
Sorry... I cannot find any references to ColorProvider in SWT APIs (or
Java).
Could you please elaborate a little, or provide me a link to more info?
Thanks -- Mark
Phil Williams wrote:
> Why not just use a ColorProvider for your Table?
> Mark wrote:
> >I wish to create a Table (or a TableTree) that has alternating rows
> >colored.
> >The code to do this is fairly straight forward...
> >
> > private static final Color oddRowBkgnd =
> > new Color(Display.getCurrent(), 187, 221, 238);
> > private static final Color evenRowBkgnd =
> > new Color(Display.getCurrent(), 255, 255, 255);
> >
> > private static Color[] rowBkgnd = new Color[] { evenRowBkgnd,
> >oddRowBkgnd };
> >
> > public static void colorTable (Table table) {
> >
> > TableItem[] items = table.getItems();
> > for (int i = 0; i < items.length; i++) {
> > items[i].setBackground(rowBkgnd[i % rowBkgnd.length]);
> > }
> > }
> >
> >But if I implement this in a TableTree, then I have to call this code from
> >each
> >event handler that alters the input to the table, including Filters and
> >expand/contract
> >events.
> >
> >Is there a "pre-draw" event that I can listen for and call this code in
> >one place?
> >
> >Am I better served sub-classing a TableTree (as say a StripedTableTree)?
> >If so,
> >what methods would I overload to accomplish the drawing?
> >
> >Thanks in advance for any advice you can give me -- Mark
> >
> >
> >
|
|
|
|
Powered by
FUDForum. Page generated in 0.02752 seconds