简体   繁体   中英

How to convert SWT events? Why does SWT notifyListeners method expects event type argument?

Why does org.eclipse.swt.widgets.Widget#notifyListeners(int, Event) method expects separate event type argument? Isn't it contained inside Event argument already? What if they do not coincide?

May I resend the same event with another id?

Suppose I wish to send SWT.OpenDocument in response to SWT.MouseDoubleClick

public void handleEvent(Event event) {
    if (event.type == SWT.MouseDoubleClick) {

        notifyListeners(SWT.OpenDocument, event);

    }
}

If you look at the source of Widget#notifyListeners(int, Event) and follow the method calls to Widget#sendEvent(int, Event, boolean) You can see the following:

void sendEvent (int eventType, Event event, boolean send) {
    if (eventTable == null && !display.filters (eventType)) {
        return;
    }
    if (event == null) event = new Event ();
    event.type = eventType;
    event.display = display;
    event.widget = this;
    if (event.time == 0) {
        event.time = display.getLastEventTime ();
    }
    if (send) {
        sendEvent (event);
    } else {
        display.postEvent (event);
    }
}

As you can see, the Event is "filled" for you, so it's impossible to have interfering/contradictory event types.

The event you specify in the method call of notifyListeners will be used in any case.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM