Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Remote Application Platform (RAP) » A simple mouse listener
A simple mouse listener [message #39140] Tue, 17 July 2007 16:06
Eclipse UserFriend
Originally posted by:

Everyone, who desperately searched for a low-level mouse listener support in
RAP will be happy to read this.

We implemented the following listeners for M5:
- Mouse listeners on ClickLabels (inital contribution from Ralf Sternberg)
+mouseDown (button is pressed)
+mouseUp (button is released)
+mouseDoubleClick (left button double click)
- Selection listeners on ClickLabels (inital contribution from Ralf
+widgetDefaultSelected (left button double click)
+widgetSelected (left button single click)

The x, y variables of the event Object (MouseEvent and SelectionEvent)
return the widget relative position of the mouse click, that is computed
server-side (see below for code). Other data, for example, which button was
pressed or the screen position of the mouse click, is provided too. Add this
classes to your project and you should be able to create a ClickLabel with a
mouse listener (addMouseListener). Additionally you have to add a resource
entry in your plugin.xml in order to register the MouseEventResource class
for the MouseEventUtil.js.

If you want to register a mouse listener to your own widgets, you have to
write a corresponding LCA class, which does the rendering and data reading
(see ClickLabel and ClickLabelLCA)

Thanks Ralf for your excellent input!

Contribution by
BOC Asset Management GmbH, Vienna

Relative from absolute mouse position (far from being perfect, but serves
our needs):
private Point computeRelativeMousePosition(Point absolute) {

Point relative = new Point(absolute.x, absolute.y);

Control currentControl = this.control;

do {

Rectangle bounds = currentControl.getBounds();

relative.x -= bounds.x;

relative.y -= bounds.y;

//When Scrollbars, the value of the scrollbars have to added

if (currentControl instanceof ScrolledComposite) {

ScrolledComposite sc = (ScrolledComposite)currentControl;

ScrollBar hb = sc.getHorizontalBar();

ScrollBar vb = sc.getVerticalBar();

relative.x += hb.getSelection();

relative.y += vb.getSelection();


else {

//Shell is last Control to be calculated

if (currentControl instanceof Shell)



//Otherwise the next parent is processed

currentControl = currentControl.getParent();

} while( currentControl != null );

//Unprecise calculation due to the script or getBounds()-Methods

//What the hell ever...

relative.x -= 3;

relative.y -= 3;

return relative;

Previous Topic:JS Libraries in RAP
Next Topic:ScrollBar and SelectionListener + a general question
Goto Forum:

Current Time: Sat Jun 10 03:39:45 GMT 2023

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

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

Back to the top