More on Listener Output

Ty Tower tytower at hotmail.com.au
Mon Apr 28 01:10:07 PDT 2008


Barry Denton Wrote:

>  Here is a simpler table to compile and test event returns.
>  The "set data" listener should return details of each item set in the table. It returns 9 empty events rather than 10 with details.
>  
>  The ""Selection " listener should also return an event containing info but does not.
>  
> What is the cause? It seems to be in Event?
> 
> -----------------------------------------------
> module tabletester;
> import dwt.DWT;
> import dwt.widgets.Display;
> import dwt.widgets.Shell;
> import dwt.layout.GridLayout;
> import dwt.widgets.Button;
> import dwt.widgets.Table;
> import dwt.widgets.TableItem;
> import dwt.widgets.Listener;
> import dwt.widgets.Event;
> import dwt.widgets.Shell;
> import tango.time.WallClock;
> import tango.io.Stdout;
> import tango.text.locale.Locale;
> import tango.util.Convert;
> 
> void main () {
>   Display display = new Display ();
>   Shell shell = new Shell (display);
>   shell.setText("Tester");
>   GridLayout gridLayout = new GridLayout();
>   shell.setLayout(gridLayout);
>   auto clock = new WallClock;
>   auto layout = new Locale;
> 
>   Table table= new Table(shell, DWT.VIRTUAL | DWT.MULTI | DWT.HORIZONTAL | DWT.BORDER |DWT.H_SCROLL|DWT.V_SCROLL| DWT.FULL_SELECTION );
>   const int COUNT = 10;
>   char [][COUNT] itemFields ;
>   for (int i = 0; i < COUNT; i++) {
>       itemFields [i] = ( "item " ~ to!(char[]) (i)) ~ "  ";      }
>   table.addListener(DWT.SetData, new class Listener {
>     void handleEvent(Event event) {
>       TableItem tableitem = cast (TableItem)event.item;
>       int index = event.index;
>       tableitem.setText(itemFields [index]);
> }   }  );
>   table.setItemCount(COUNT);
>   table.setEnabled=true;
>   table.setVisible(true);
>   table.setSize(200, 200);
>   
>   Button button = new Button(shell, DWT.PUSH | DWT.BORDER);
>   button.setText("Change item at index 5");
>   button.setEnabled(true);    
>   button.setVisible(true);    
>   button.setBounds(400, 120, 50, 70); 
>   button.addListener(DWT.Selection, new class Listener {
>     void handleEvent(Event event) {
>       itemFields [5] = ("item has changed ");
>       Stdout.formatln("{}",event);
>       Stdout.print(itemFields).newline;
>       table.clear(5);   }  }); 
>   table.addListener(DWT.SetData, new class Listener {
>     void handleEvent(Event event) {
>        Stdout.formatln("{}" , event);
>        TableItem t = cast (TableItem)event.item;
>        t.setText(itemFields [event.index]);  }   }  );
>   table.addListener(DWT.Selection, new class Listener {
>     void handleEvent(Event event) {
>       Stdout.print(event).newline;
>       Stdout.print(itemFields).newline;
> }  }); 
> 
>    shell.pack();
> 
>   shell.open();	
>   while (!shell.isDisposed ()) {
>   if (!display.readAndDispatch ()) display.sleep ();
> }
> display.dispose ();
> }
>  
> -----------------------------------------
> Out..
> Event {missing or misplaced '}'}Event {type=36 Table {} time=0 data={null} x=0 y=0 width=0 height=0 detail=0}
> Event {missing or misplaced '}'}Event {type=36 Table {} time=0 data={null} x=0 y=0 width=0 height=0 detail=0}
> Event {missing or misplaced '}'}Event {type=36 Table {} time=0 data={null} x=0 y=0 width=0 height=0 detail=0}
> Event {missing or misplaced '}'}Event {type=36 Table {} time=0 data={null} x=0 y=0 width=0 height=0 detail=0}
> Event {missing or misplaced '}'}Event {type=36 Table {} time=0 data={null} x=0 y=0 width=0 height=0 detail=0}
> Event {missing or misplaced '}'}Event {type=36 Table {} time=0 data={null} x=0 y=0 width=0 height=0 detail=0}
> Event {missing or misplaced '}'}Event {type=36 Table {} time=0 data={null} x=0 y=0 width=0 height=0 detail=0}
> Event {missing or misplaced '}'}Event {type=36 Table {} time=0 data={null} x=0 y=0 width=0 height=0 detail=0}
> Event {missing or misplaced '}'}Event {type=36 Table {} time=0 data={null} x=0 y=0 width=0 height=0 detail=0}
>                                                                                                                 
Indeed the event should have the item no in it's returned data
http://www.eclipse.org/articles/Article-SWT-Virtual/Virtual-in-SWT.html
which says
"Gets the index of the item and sets its text accordingly. The index of this item can be found in the event's index field (@since 3.2). Alternatively, this index can be computed with Table.indexOf(TableItem)." Assuming that Frank is converting a version of 3.2 or over?


More information about the Digitalmars-d-learn mailing list