Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » Change Label Image when pressed(How to change a Label's Image while pressed)
Change Label Image when pressed [message #1494353] Mon, 01 December 2014 11:51 Go to next message
John Gymer is currently offline John GymerFriend
Messages: 263
Registered: November 2012
Location: UK
Senior Member
This could be a general question for SWT too, and maybe I've missed something in the event API, but I cannot see it...

I have a Label that acts like a Button - when pressed I capture it and perform some event logic. This is done with a MouseDown event, since Label does not support a Selection event.

OK, but now I want to give my Label an image, and change the image for a 'pressed' alternative image just while pressed, then revert to the original image when unpressed.

I can use the MouseDown event, and inside here change the image to my pressed image, but how do I reliably change it back when the press is released? MouseUp doesn't work reliably because the user might MouseDown on the control, then drag outside the Label and let go, in which case I never get the MouseUp.

I cannot use MouseEnter/MouseExit because these are not supported by RAP (and rightly so).

Is there an alternative where I can achieve this 'different image while pressed' effect?

I'm thinking JavaScript might be the only option, but I'd really rather not, as it seems that there should be an inbuilt way to do this in Java. Perhaps a 'setPressedImage(Image img) method would be good?

Thanks, John


---
Just because you can doesn't mean you should
Re: Change Label Image when pressed [message #1494363 is a reply to message #1494353] Mon, 01 December 2014 12:04 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2339
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
Hi John,
did you try display mouseUp filter to reset the image?
Best,
Ivan

--
Ivan Furnadjiev

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: Change Label Image when pressed [message #1494384 is a reply to message #1494363] Mon, 01 December 2014 12:28 Go to previous messageGo to next message
John Gymer is currently offline John GymerFriend
Messages: 263
Registered: November 2012
Location: UK
Senior Member
Good idea, but unfortunately the MouseUp on the display is not getting triggered.

...
display.addFilter(SWT.MouseUp, ...
...

Also tried display.addListener(SWT.MouseUp, ... but that didn't fire either.

Is there something special that I have to do to get this to fire?


---
Just because you can doesn't mean you should
Re: Change Label Image when pressed [message #1494386 is a reply to message #1494384] Mon, 01 December 2014 12:30 Go to previous messageGo to next message
John Gymer is currently offline John GymerFriend
Messages: 263
Registered: November 2012
Location: UK
Senior Member
just noticed in the JavaDoc for AddFilter: "NOTE: In RAP, only events that have a matching listener registered on the event's source widget are processed on the server"
is this my problem? I have a MouseDown listener on the Label, but not a MouseUp...?


---
Just because you can doesn't mean you should
Re: Change Label Image when pressed [message #1494391 is a reply to message #1494386] Mon, 01 December 2014 12:32 Go to previous messageGo to next message
John Gymer is currently offline John GymerFriend
Messages: 263
Registered: November 2012
Location: UK
Senior Member
actually that didn't work properly either - I only get the MouseUp on the display if it is released within the Label still


---
Just because you can doesn't mean you should
Re: Change Label Image when pressed [message #1494400 is a reply to message #1494353] Mon, 01 December 2014 12:44 Go to previous messageGo to next message
Ivan Furnadjiev is currently offline Ivan FurnadjievFriend
Messages: 2339
Registered: July 2009
Location: Sofia, Bulgaria
Senior Member
.... than I have another idea. Why not using a standard RWT Button with
custom styling (customVariant). Button has a "pressed" state and you can
configure the background image (and other) property. You can make Button
to look like a Label with CSS too.
HTH,
Ivan

--
Ivan Furnadjiev

Twitter: @EclipseRAP
Blog: http://eclipsesource.com/blogs/

Professional services for RAP and RCP?
http://eclipsesource.com/services/rap/
Re: Change Label Image when pressed [message #1494422 is a reply to message #1494400] Mon, 01 December 2014 13:06 Go to previous messageGo to next message
John Gymer is currently offline John GymerFriend
Messages: 263
Registered: November 2012
Location: UK
Senior Member
Thanks Ivan, I'll have a play around with that idea. I'm not sure that it gives me exactly what I want, but it may be sufficient. I was hoping for a generic solution for SWT and RAP but I don't see that happening.
The CSS theme approach will enable me to at least cause the button to change appearance when pressed, but I don't think I can really use the image attributes because the image needs to be configurable at runtime - the developer may wish to change the image on the fly. However, the primary concern was that the control didn't change appearance at all when pressed, so there was no visual feedback, so using an offset and playing with the border might be an acceptable solution...
time to play...


---
Just because you can doesn't mean you should
Re: Change Label Image when pressed [message #1495525 is a reply to message #1494422] Tue, 02 December 2014 09:28 Go to previous message
John Gymer is currently offline John GymerFriend
Messages: 263
Registered: November 2012
Location: UK
Senior Member
Yes, that works reasonably well for RAP.
I'll have to come up with different branches of code for SWT and Tabris, but it is OK for RAP.
For SWT I can rely on MouseEnter/MouseExit/MouseUp/MouseDown, and physically change the bitmap, and for Tabris it probably doesn't make much sense anyway.
Thanks for your suggestions!



---
Just because you can doesn't mean you should
Previous Topic:Sharing data between background thread and clients
Next Topic:Generating test id for components not created programmatically
Goto Forum:
  


Current Time: Thu May 28 05:34:57 GMT 2020

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

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

Back to the top