| 
| A simple mouse listener [message #39140] | Tue, 17 July 2007 12:06 |  | 
| Eclipse User  |  |  |  |  | Originally posted by: nindl_go.hotmail.com 
 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
 Sternberg)
 +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)
 
 break;
 
 }
 
 //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;
 
 
 
 |  |  |  | 
Powered by 
FUDForum. Page generated in 0.04573 seconds