Skip to main content

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


Or you could use the typed event mechanism.
Then you have your choice of implementing the typed listener interfaces or just using inner classes.
i.e. here's implementing the listeners:

class X extends Canvas implements PaintListener, etc {
   X() {
       ...
       addPaintListener(this);
       ... lots more
   }
   public void paintControl (PaintEvent e) {
       ... do your paint code right here...

    }

And here's using anonymous inner classes...

class X extends Canvas implements PaintListener, etc {
   X() {

        ...
       addPaintListener (new PaintListener () {

                public void paintControl (PaintEvent e) {
                        e.gc.drawImage (image, 0, 0); // or whatever your paint code is
                }
        });
        ... lots more
}

Carolyn




Mauk van der Laan <mauk@xxxxxxxxxxxx>
Sent by: platform-swt-dev-bounces@xxxxxxxxxxx

09/28/2006 03:49 AM

Please respond to
"Eclipse Platform SWT component developers list." <platform-swt-dev@xxxxxxxxxxx>

To
platform-swt-dev@xxxxxxxxxxx
cc
Subject
[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

_______________________________________________
platform-swt-dev mailing list
platform-swt-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/platform-swt-dev


Back to the top