Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[platform-swt-dev] Efficient eventHandlers in a subclass


Hi,

I create a lot of Composite or Canvas subclasses. To be able to handle their events,
the following code is used:

class X extends Canvas implements Listener {
   X() {
       ...
       addListener(SWT.Paint, this);
       addListener(SWT.MouseMove,this);
       ... lots more
   }
   public void handleEvent(Event e) {
       switch(e.type) {
case SWT.Paint: onPaint();
           break;
       ... etc


This is too 'heavy' in my opinion: each component has a big EventTable and must do a lookup for every event, only to send it to the same handleEvent() method where it is tested again
by the switch.

It would be better to override some public method, the eventTable would be empty that way (unless another component registers). The problem is that Widget.sendEvent() isn't public.

To make this possible, i propose one of the following changes:
- make Widget.sendEvent() public,
- let it call a new public method 'handleAllEvents()' before it does the EventTable lookup - create a special 'catch-all' event constant like SWT.AllEvents which is checked in EventTable.sendEvent() to that it sends all events to a handler that is registered with
that constant.

Regards,
Mauk



Back to the top