www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - More on Listener Output

reply Barry Denton <basse42 yahoo.com> writes:
I think there is more behind this than just escaping the brackets
The event does not return any item number or other stuff it should return It
does get the type and the time, but no item,x,y,or data.

If you compile and run the program below you will see that the output when
selecting a point on either table is nothing for any point on the table?
--------------------------------------------------------------------------------------
Item is  TableItem {item 0  }
Event {missing or misplaced '}'}Event {type=13 Table {} time=1857596828
data={null} x=0 >>>y=0 width=0 height=0 detail=0}
This is where item details should be
point is Point {0, 0}



module readMyData; import dwt.DWT; import dwt.widgets.Display; import dwt.widgets.Shell; import dwt.widgets.Table; import dwt.widgets.TableItem; import dwt.widgets.TableColumn; import dwt.widgets.Composite; import dwt.widgets.Text; import dwt.widgets.Listener; import dwt.events.ModifyListener; import dwt.widgets.Button; import dwt.widgets.Event; import dwt.events.ModifyEvent; import dwt.layout.GridLayout; import dwt.graphics.Point; import dwt.graphics.Rectangle; import tango.io.Stdout; import tango.io.File; import tango.io.stream.TextFileStream; import tango.text.stream.LineIterator; import tango.util.Convert; import tango.time.WallClock; import tango.text.locale.Locale; import TextUtil = tango.text.Util; import Float = tango.text.convert.Float; void main () { Display display = new Display (); Shell shell = new Shell (display); shell.setText("Cheque Entry"); GridLayout gridLayout = new GridLayout(); shell.setLayout(gridLayout); auto clock = new WallClock; Stdout.print ("{:ddd, dd MMMM yyyy HH':'mm':'ss z}", WallClock.now).newline; Stdout.print(clock.mangleof, clock.stringof).newline; const int COUNT = 10; char[][] word; char[][] copy; char [][COUNT] itemWords ; for (int i = 0; i < COUNT; i++) { itemWords [i] = ( "item " ~ to!(char[]) (i)) ~ " "; } Table minitable = new Table(shell, DWT.VIRTUAL | DWT.MULTI | DWT.HORIZONTAL | DWT.BORDER |DWT.H_SCROLL|DWT.V_SCROLL| DWT.FULL_SELECTION ); minitable.addListener(DWT.SetData, new class Listener { void handleEvent(Event event) { Stdout.formatln("{}" , event); TableItem t = cast (TableItem)event.item; t.setText(itemWords [event.index]); } } ); minitable.setItemCount(COUNT); minitable.setEnabled=true; minitable.setVisible(true); minitable.setSize(minitable.computeSize (150, 100)); 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) { itemWords [5] = ("item has changed " ~ clock.stringof~" "~ cast(char)clock); Stdout.formatln("{}""{}" ,event.mangleof, event.stringof).newline; Stdout.formatln("{}""{}" ,clock.mangleof, clock.stringof).newline; Stdout.formatln("{}",event); Stdout.print(itemWords).newline; minitable.clear(5); } }); minitable.addListener(DWT.Selection, new class Listener{ void handleEvent(Event event){ Point pt = new Point(event.x, event.y); TableItem item = minitable.getItem(pt); Stdout.formatln("Item is {}", item); Stdout.print(event).newline; Stdout.print("This is where item details should be").newline; Stdout.formatln("point is {}",pt).newline; if (item == null) return; for (int i = 0; i < 8; i++){ Rectangle rect = item.getBounds(i); if (rect.contains(pt)) { int index = minitable.indexOf(item); char cindex = cast (char) index; Stdout.print("Item "~ cindex ~ "-" ~ cast (char)i).newline; Stdout.print("This is where second bit should be"); } } } }); Table table = new Table (shell, DWT.MULTI | DWT.HORIZONTAL | DWT.BORDER |DWT.H_SCROLL|DWT.V_SCROLL| DWT.FULL_SELECTION ); table.setEnabled(true); table.setLinesVisible (true); table.setHeaderVisible (true); char[][] titles = ["Number", "Date ","ChequeNo ", "Description ", "Code", "Debit", "Credit","Balance " ]; for (int i=0; i<4; i++) { TableColumn column = new TableColumn (table, DWT.LEFT); //NONE,LEFT,RIGHT.CENTER,LEAD.TRAIL column.setText (titles [i]); } for (int i=4; i<8; i++) { TableColumn column = new TableColumn (table, DWT.NONE); column.setText (titles [i]); } double balance=0; foreach (line; new LineIterator!(char) (new FileConduit ("data.db"))){ TableItem item = new TableItem (table, DWT.RIGHT); //NONE,LEFT,RIGHT.CENTER,LEAD.TRAIL word = TextUtil.delimit(line,","); for (int a=0 ;a<5;a++) {item.setText (a,word[a]); } auto debit = Float.parse(word[5]); auto credit = Float.parse(word[6]); balance = balance - debit + credit; if (word[5]!="0.00")item.setText (5,word[5]); if (word[6]!="0.00")item.setText (6,word[6]); item.setText (7, to!(char[]) (balance) ); copy = word.dup; } for (int i=0; i<titles.length; i++) { table.getColumn (i).pack (); } Button button2 = new Button(shell, DWT.PUSH | DWT.BORDER); button2.setText("Change item"); button2.setEnabled(true); button2.setVisible(true); button2.setBounds(400, 120, 50, 70); button2.addListener(DWT.Selection, new class Listener { void handleEvent(Event event) { Stdout.print(event).newline; TableItem item1 = cast (TableItem)event.item;//.item Stdout.print(event.index).newline; auto layout = new Locale; word[event.index] = "item has changed "~ (layout ("{:ddd, dd MMMM yyyy HH':'mm':'ss z}", WallClock.now)); Stdout.print(word[event.index]).newline; table.clear(event.index);//(event.index) Clears line 1 , Item 0 I suppose ? //word.setText(event.index,word[event.index]); //item1.setText(event.index,word[event.index][]);//causes seg fault } }); table.addListener(DWT.Selection, new class Listener{ void handleEvent(Event event){ Point pt = new Point(event.x, event.y); TableItem item = table.getItem(pt); Stdout.formatln("Item is {}", item); Stdout.print(event).newline; Stdout.print("This is where item details should be").newline; Stdout.formatln("point is {}",pt).newline; if (item == null) return; for (int i = 0; i < 8; i++){ Rectangle rect = item.getBounds(i); if (rect.contains(pt)) { int index = table.indexOf(item); char cindex = cast (char) index; Stdout.print("Item "~ cindex ~ "-" ~ cast (char)i).newline; Stdout.print("This is where second bit should be"); } } } }); table.setSize (table.computeSize (700, 500)); Composite panel = new Composite(shell,DWT.EMBEDDED); auto line = new Text(panel, DWT.LEFT); line.setBounds( 600, 0, 100, 150); line.setText ="Test Text Box"; line.setEditable(true); line.setVisible(true); panel.setEnabled(true); panel.setVisible(true); shell.pack(); shell.open(); while (!shell.isDisposed ()) { if (!display.readAndDispatch ()) display.sleep (); } display.dispose (); } -------------------------------------------------------------------------------------------------
Apr 20 2008
parent reply Barry Denton <basse42 yahoo.com> writes:
 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}
                                                                               
                                
Apr 21 2008
parent Ty Tower <tytower hotmail.com.au> writes:
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}
                                                                               
                                 

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?
Apr 28 2008