Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » SWT equivalent to AWT EventQueue replace?
SWT equivalent to AWT EventQueue replace? [message #534460] Wed, 19 May 2010 09:34 Go to next message
carles is currently offline carlesFriend
Messages: 7
Registered: May 2010
Junior Member
Hi,

Is there any way to manage events as we like in SWT?
In AWT we can do this replacing the event queue by a new one with push(myEventQueue) method. With this I can do anything I want with events of an application (even stopping them).
Is there anything similar in SWT?

Thanks.
Sorry if there are any mistakes in the text. My English isn't very good.
Re: SWT equivalent to AWT EventQueue replace? [message #534491 is a reply to message #534460] Wed, 19 May 2010 10:53 Go to previous messageGo to next message
Thomas Schindl is currently offline Thomas SchindlFriend
Messages: 6512
Registered: July 2009
Senior Member
You can register a filter on the Display in SWT.

Tom

Am 19.05.10 11:34, schrieb carles:
> Hi,
>
> Is there any way to manage events as we like in SWT? In AWT we can do
> this replacing the event queue by a new one with push(myEventQueue)
> method. With this I can do anything I want with events of an application
> (even stopping them).
> Is there anything similar in SWT?
>
> Thanks.
> Sorry if there are any mistakes in the text. My English isn't very good.
>
Re: SWT equivalent to AWT EventQueue replace? [message #534501 is a reply to message #534460] Wed, 19 May 2010 11:32 Go to previous messageGo to next message
carles is currently offline carlesFriend
Messages: 7
Registered: May 2010
Junior Member
Yes, but this way I can't control which events are going to be dispatched. I need for example that certain MouseDown events with certain paramenters don't affect the components of an application, while the rest of MouseDown events must affect it (I tried with doit to false but doesn't work).

In addition I want to do this events treatment for all events of an application, not for only one display. Doing it like in AWT EventQueue system it's more clean and totally transparent, so you don't have to worry if the application below changes.

Thanks for you reply.
Carles.
Re: SWT equivalent to AWT EventQueue replace? [message #534505 is a reply to message #534501] Wed, 19 May 2010 11:39 Go to previous messageGo to next message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
Just in handle event method set e.type=SWT.NONE;
it effects all the controls

This way you can stop any event or modify paramaters of any event.

Even log them...

In my case we built a automated recording playback tool based on this!!!


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay

[Updated on: Wed, 19 May 2010 11:45]

Report message to a moderator

Re: SWT equivalent to AWT EventQueue replace? [message #534760 is a reply to message #534460] Thu, 20 May 2010 09:21 Go to previous messageGo to next message
carles is currently offline carlesFriend
Messages: 7
Registered: May 2010
Junior Member
You mean this:

class SimpleListener implements Listener{

public SimpleListener(String name) {
}

public void handleEvent(Event e) {
System.out.println("Event: [" + e.type + "]");
e.type = SWT.NONE;
}
}

Then in the display
display.addFilter(SWT.MouseDown | SWT.MouseUp | SWT.MouseDoubleClick, new SimpleListener());

This must stop all mouse clicks, but it doesn't work. I still can press buttons, activate check boxes, etc. Am I doing something wrong?

I'm working in a program which can replay the progress of an application by saving the events. During the replay I post the saved events but the user of replayer can not interfere with the application.

In AWT I only have to replace the event queue and override the dispatchevent() method (then I can dispatch the events I want and ignore the rest). Now I'm trying in SWT, that's why am I asking if there is something similar to AWT Event queue replacing in SWT.

Thanks again.
Carles.
Re: SWT equivalent to AWT EventQueue replace? [message #534773 is a reply to message #534760] Thu, 20 May 2010 09:53 Go to previous messageGo to next message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
You will be able to see the button press,

but the associated listeners where the code had been written for what to do with button press will not be fired.

button.addSelectionListener(new SelectionListener(){
public void selectionChanged()
{
System.out.println("Button Pressed");
}
}}


if you add a filter for selection(and do event type none) then "Button Pressed" will not be printed.

Now questions..
Is your playback happening properly??
Is user not able to interact in playback or do you not want user interaction to happeni in playback??


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay

[Updated on: Thu, 20 May 2010 11:29]

Report message to a moderator

Re: SWT equivalent to AWT EventQueue replace? [message #535086 is a reply to message #534460] Fri, 21 May 2010 09:25 Go to previous messageGo to next message
carles is currently offline carlesFriend
Messages: 7
Registered: May 2010
Junior Member
The problem is I have two sources of events during the playback:
- A thread posting events previously saved.
- Events generated by user who is watching the replay

The playback works fine until the user generates a mouse/key event. Then the playback lost its consistency and arrives to a final state different from the original.

So I don't want user interaction happen in playback (f.e. if he tries to generate an event, the playback doesn't have to notice it). The playback only has to play attention to the events posted by the thread mentioned above.

I already had this problem when I did a playback in AWT, and listeners didn't work. The only solution back then was to intercept events before they arrive to the application. But AWT has ways to intercept events in the event queue like AWTEventListener or replacing the eventqueue.

But in SWT...

Thanks.
Carles.
Re: SWT equivalent to AWT EventQueue replace? [message #535093 is a reply to message #535086] Fri, 21 May 2010 09:44 Go to previous messageGo to next message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
May be use display thread to post u r events..
use display.syncexec if u r not already in display thread(the whole loop not just display.post)....

That way display will not be responsive,but u have to do display.readanddispatch in u r post loop,so that refresh and all other events are taken care of(u r post events)...

but all this may make the UI unresponsive for u r posts also...

other way can be put a marker in u r events(which r posted) and in display filter allow those events only to be processed....

was wondering how did u save u r events...
(specificaly how are u grabbing the same control on which u have to post the event)


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Re: SWT equivalent to AWT EventQueue replace? [message #535129 is a reply to message #534460] Fri, 21 May 2010 11:56 Go to previous messageGo to next message
carles is currently offline carlesFriend
Messages: 7
Registered: May 2010
Junior Member
Grabbing the same controls is another problem to solve in SWT. For now I only can do it for AWT applications. But for SWT I think I'll try with shell getChildren() method.
My idea is search the event.widget on getChildren returning list and save the index. When I replay I call again getChildren and I get the getChildern()[index] control and put it on the event. The list returning getChildren may have the same controls in the same position because it's a replay and the two times we are in the same execution point.
But it is just an idea... I deal with that when I solve the stopping events problem.

Thanks.
Carles.
Re: SWT equivalent to AWT EventQueue replace? [message #535131 is a reply to message #535129] Fri, 21 May 2010 12:01 Go to previous messageGo to next message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
its not as simple as that!!!
u control may be on a composite which is on a composite......n times
then that composite may be on the shell. Twisted Evil

how did u handle it in AWT???

(I am happy that finally i got some one who is going thru same things which i went thru(good ones n bad ones))
Razz


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Re: SWT equivalent to AWT EventQueue replace? [message #535522 is a reply to message #534460] Mon, 24 May 2010 09:11 Go to previous messageGo to next message
carles is currently offline carlesFriend
Messages: 7
Registered: May 2010
Junior Member
For AWT I used Window.getWindows() and Container.getComponents recursively to build a list (the list must be redone every time you save an event because it may change). From that list I save the index of the component. When I need to recover the event source I rebuild the list and I get the component on the saved index. It is not very elegant but it worked.
Re: SWT equivalent to AWT EventQueue replace? [message #535529 is a reply to message #535522] Mon, 24 May 2010 09:33 Go to previous messageGo to next message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
Quote:
For AWT I used Window.getWindows() and Container.getComponents recursively to build a list (the list must be redone every time you save an event because it may change). From that list I save the index of the component. When I need to recover the event source I rebuild the list and I get the component on the saved index. It is not very elegant but it worked.


exactly the same thing i did for SWT....

i also agree its not elegant but i searched every where, there is no other way,
identifing controls by name(text) or control class is inconsistant..


---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Re: SWT equivalent to AWT EventQueue replace? [message #535535 is a reply to message #534460] Mon, 24 May 2010 09:52 Go to previous messageGo to next message
carles is currently offline carlesFriend
Messages: 7
Registered: May 2010
Junior Member
So it also works in SWT?
But you use the same methods or they have their equivalents in SWT.
getWindows and getComponents are java.awt
Re: SWT equivalent to AWT EventQueue replace? [message #535536 is a reply to message #535535] Mon, 24 May 2010 09:57 Go to previous message
Vijay RajFriend
Messages: 608
Registered: July 2009
Senior Member
in swt its getChildren for composite(component equavalent)
getwindow is display.getShells here...



---------------------
why, mr. Anderson, why, why do you persist?
Because I Choose To.
Regards,
Vijay
Previous Topic:SWT OLE and PowerPoint- Control Order Matters?
Next Topic:Auto-complete functionality
Goto Forum:
  


Current Time: Fri Dec 13 00:55:39 GMT 2019

Powered by FUDForum. Page generated in 0.02734 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top