Skip to main content



      Home
Home » Eclipse Projects » GEF » draw2d: findMouseEventTarget
draw2d: findMouseEventTarget [message #25525] Tue, 08 October 2002 09:59 Go to next message
Eclipse UserFriend
Good day,

Problem occured when I tried to implement simple editor using draw2d.
The drawing below contains the root figure A, which is parent of the
figure B and figure L (PolyLine, but it does not matter).

+---------------------------+
| A |
| +----------------+ |
| L | <p> B | |
| *---+----*----* | |
| | | |
| +----------------+ |
+---------------------------+

A and B have mouse listeners, while L has not. When I click at the
point <p>, mouse event comes to A, which searches for child,
containing <p>, _then A found L, L has no mouse listener, and A
decides to processes event mouse event itself_. I expected that
figure B should receive this event, but it doesn't.

I think, it's bug (see code below), but if I wrong, it would be
nice to know, how can I avoid this situation.

--- Figure.java ---
IFigure findMouseEventTargetInDescendantsAt(int x, int y){
if(useLocalCoordinates()){
x -= (getBounds().x + getInsets().left);
y -= (getBounds().y + getInsets().top);
}
FigureIterator iter = new FigureIterator(this);
IFigure fig;
while (iter.hasNext()){
fig = iter.nextFigure();
if (fig.isVisible() && fig.isEnabled()){
if (fig.containsPoint(x, y)){
fig = fig.findMouseEventTargetAt(x, y);

// return fig; << bug?
// changed:
if (fig!=null) return fig;
}
}
}
return null;
}
---

/Sergey
Re: draw2d: findMouseEventTarget [message #25764 is a reply to message #25525] Tue, 08 October 2002 15:01 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: hudsonr.us.eye-bee-em.com

This is a multi-part message in MIME format.

------=_NextPart_000_002D_01C26EDB.95420420
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Your proposed change in hit-testing seems consistent with Windows. Does =
anyone know if this is how other platforms work? I thought we were =
being like Swing, but maybe not. In the following SWT test, mouse =
events "fall through" the inactive sibling. Open a bugzilla for this.

public static void main(String[] args) {
Display d =3D new Display();
final Shell shell =3D new Shell(d);
shell.setText("Hittest demonstration");

Button b1, b2;
b1 =3D new Button(shell, 0);
b2 =3D new Button(shell, 0);
=20
b1.setBounds(20,20,200,100);
b2.setBounds(30,30,200,100);
b1.setEnabled(false);
=20
shell.addMouseListener(new MouseAdapter() {
public void mouseDown(MouseEvent e) {
shell.setBackground(new Color(null, 0,0,0)); //Bad code
}
public void mouseUp(MouseEvent e) {
shell.setBackground(null);
}
});

shell.setSize(300,260);
shell.open();
while (!shell.isDisposed())
while (!d.readAndDispatch())
d.sleep();
}


"Sergey Bushkov" <bush@ispras.ru> wrote in message =
news:anujbj$2s6$1@rogue.oti.com...
> Good day,
>=20
> Problem occured when I tried to implement simple editor using draw2d.
> The drawing below contains the root figure A, which is parent of the
> figure B and figure L (PolyLine, but it does not matter).
>=20
> +---------------------------+
> | A |
> | +----------------+ |
> | L | <p> B | |
> | *---+----*----* | |
> | | | |
> | +----------------+ |
> +---------------------------+
>=20
> A and B have mouse listeners, while L has not. When I click at the
> point <p>, mouse event comes to A, which searches for child,
> containing <p>, _then A found L, L has no mouse listener, and A
> decides to processes event mouse event itself_. I expected that
> figure B should receive this event, but it doesn't.
>=20
> I think, it's bug (see code below), but if I wrong, it would be
> nice to know, how can I avoid this situation.
>=20
> --- Figure.java ---
> IFigure findMouseEventTargetInDescendantsAt(int x, int y){
> if(useLocalCoordinates()){
> x -=3D (getBounds().x + getInsets().left);
> y -=3D (getBounds().y + getInsets().top);
> }
> FigureIterator iter =3D new FigureIterator(this);
> IFigure fig;
> while (iter.hasNext()){
> fig =3D iter.nextFigure();
> if (fig.isVisible() && fig.isEnabled()){
> if (fig.containsPoint(x, y)){
> fig =3D fig.findMouseEventTargetAt(x, y);
> =20
> // return fig; << bug?
> // changed:
> if (fig!=3Dnull) return fig;
> }
> }
> }
> return null;
> }
> ---
>=20
> /Sergey
>=20

------=_NextPart_000_002D_01C26EDB.95420420
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2716.2200" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY>
<DIV><FONT face=3DArial size=3D2>Your proposed change in hit-testing =
seems=20
consistent with Windows.&nbsp; Does anyone know if this is how other =
platforms=20
work?&nbsp; I thought we were being&nbsp;like Swing, but maybe =
not.&nbsp; In the=20
following SWT test, mouse events "fall through" the inactive =
sibling.&nbsp; Open=20
a bugzilla for this.</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT><FONT face=3DArial =
size=3D2>public static void=20
main(String[] args) {<BR>&nbsp;Display d =3D new =
Display();<BR>&nbsp;final Shell=20
shell =3D new Shell(d);<BR>&nbsp;shell.setText("Hittest=20
demonstration");</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;Button b1, b2;<BR>&nbsp;b1 =3D =
new=20
Button(shell, 0);<BR>&nbsp;b2 =3D new Button(shell,=20
0);<BR>&nbsp;<BR>&nbsp;b1.setBounds(20,20,200,100); <BR>&nbsp;b2.setBounds=
(30,30,200,100);<BR>&nbsp;b1.setEnabled(false);<BR>&nbsp; <BR>&nbsp;shell.=
addMouseListener(new=20
MouseAdapter() {<BR>&nbsp;&nbsp;public void mouseDown(MouseEvent e)=20
{<BR>&nbsp;&nbsp;&nbsp;shell.setBackground(new Color(null, 0,0,0)); =
//Bad=20
code<BR>&nbsp;&nbsp;}<BR>&nbsp;&nbsp;public void mouseUp(MouseEvent e)=20
{<BR>&nbsp;&nbsp;&nbsp;shell.setBackground(null); <BR>&nbsp;&nbsp;}<BR>&nb=
sp;});</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial=20
size=3D2>&nbsp;shell.setSize(300,260);<BR>&nbsp;shell.open(); <BR>&nbsp;wh=
ile=20
(!shell.isDisposed())<BR>&nbsp;&nbsp;while=20
(!d.readAndDispatch())<BR>&nbsp;&nbsp;&nbsp;d.sleep(); <BR>}<BR></FONT></D=
IV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>"Sergey Bushkov" &lt;</FONT><A=20
href=3D"mailto:bush@ispras.ru"><FONT face=3DArial=20
size=3D2>bush@ispras.ru</FONT></A><FONT face=3DArial size=3D2>&gt; wrote =
in message=20
</FONT><A href=3D"news:anujbj$2s6$1@rogue.oti.com"><FONT face=3DArial=20
size=3D2>news:anujbj$2s6$1@rogue.oti.com</FONT></A><FONT face=3DArial=20
size=3D2>...</FONT></DIV><FONT face=3DArial size=3D2>&gt; Good =
day,<BR>&gt; <BR>&gt;=20
Problem occured when I tried to implement simple editor using =
draw2d.<BR>&gt;=20
The drawing below contains the root figure A, which is parent of =
the<BR>&gt;=20
figure B and figure L (PolyLine, but it does not matter).<BR>&gt; =
<BR><FONT=20
face=3DCourier>&gt; &nbsp;+---------------------------+<BR>&gt;=20
&nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;=
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &=
nbsp;=20
A |<BR>&gt; &nbsp;|&nbsp;&nbsp;&nbsp;&nbsp; =
+----------------+&nbsp;&nbsp;&nbsp;=20
|<BR>&gt; &nbsp;| L&nbsp;&nbsp; |&nbsp;&nbsp;=20
&lt;p&gt;&nbsp;&nbsp;&nbsp;&nbsp;&am p;nbsp;&nbsp;&nbsp; B =
|&nbsp;&nbsp;&nbsp;=20
|<BR>&gt; &nbsp;| *---+----*----*&nbsp;&nbsp;&nbsp;&nbsp;& nbsp;=20
|&nbsp;&nbsp;&nbsp; |<BR>&gt; &nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;=20
|&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp ;=
&nbsp;&nbsp;&nbsp;=20
|&nbsp;&nbsp;&nbsp; |<BR>&gt; &nbsp;|&nbsp;&nbsp;&nbsp;&nbsp;=20
+----------------+&nbsp;&nbsp;&nbsp; |<BR>&gt;=20
&nbsp;+---------------------------+<BR>&gt; </FONT><BR>&gt; A and B have =
mouse=20
listeners, while L has not. When I click at the<BR>&gt; point &lt;p&gt;, =
mouse=20
event comes to A, which searches for child,<BR>&gt; containing =
&lt;p&gt;, _then=20
A found L, L has no mouse listener, and A<BR>&gt; decides to processes =
event=20
mouse event itself_. I expected that<BR>&gt; figure B should receive =
this event,=20
but it doesn't.<BR>&gt; <BR>&gt; I think, it's bug (see code below), but =
if I=20
wrong, it would be<BR>&gt; nice to know, how can I avoid this =
situation.<BR>&gt;=20
<BR>&gt; --- Figure.java ---<BR>&gt; IFigure=20
findMouseEventTargetInDescendantsAt(int x, int y){<BR>&gt; =
&nbsp;&nbsp;&nbsp;=20
if(useLocalCoordinates()){<BR>&gt; =
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; x=20
-=3D (getBounds().x + getInsets().left);<BR>&gt;=20
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; y -=3D (getBounds().y +=20
getInsets().top);<BR>&gt; &nbsp;&nbsp;&nbsp; }<BR>&gt; =
&nbsp;&nbsp;&nbsp;=20
FigureIterator iter =3D new FigureIterator(this);<BR>&gt; =
&nbsp;&nbsp;&nbsp;=20
IFigure fig;<BR>&gt; &nbsp;&nbsp;&nbsp; while (iter.hasNext()){<BR>&gt;=20
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; fig =3D =
iter.nextFigure();<BR>&gt;=20
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; if (fig.isVisible() =
&amp;&amp;=20
fig.isEnabled()){<BR>&gt;=20
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if=20
(fig.containsPoint(x, y)){<BR>&gt;=20
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &=
nbsp;&nbsp;&nbsp;=20
fig =3D fig.findMouseEventTargetAt(x, y);<BR>&gt;=20
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &=
nbsp;&nbsp;=20
<BR>&gt;=20
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &=
nbsp;&nbsp;&nbsp;=20
// return fig; &lt;&lt; bug?<BR>&gt;=20
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &=
nbsp;&nbsp;&nbsp;=20
// changed:<BR>&gt;=20
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &=
nbsp;&nbsp;&nbsp;=20
if (fig!=3Dnull) return fig;<BR>&gt;=20
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; =
}<BR>&gt;=20
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; }<BR>&gt; &nbsp;&nbsp;&nbsp;=20
}<BR>&gt; &nbsp;&nbsp;&nbsp; return null;<BR>&gt; }<BR>&gt; ---<BR>&gt; =
<BR>&gt;=20
/Sergey<BR>&gt; </FONT></BODY></HTML>

------=_NextPart_000_002D_01C26EDB.95420420--
Re: draw2d: findMouseEventTarget [message #25863 is a reply to message #25764] Wed, 09 October 2002 07:06 Go to previous messageGo to next message
Eclipse UserFriend
> Your proposed change in hit-testing seems consistent with Windows.
Does anyone know
> if this is how other platforms work? I thought we were being like
Swing, but maybe not.
> In the following SWT test, mouse events "fall through" the inactive
sibling.

:) nice example.
But it does not "fall" through second button at least.. When using
draw2d, such events
"fall" down to the root Figure.

> Open a bugzilla for this.

ok.
Re: draw2d: findMouseEventTarget [message #26065 is a reply to message #25863] Wed, 09 October 2002 10:14 Go to previous message
Eclipse UserFriend
Originally posted by: hudsonr.us.eye-bee-em.com

"Sergey Bushkov" <bush@ispras.ru> wrote in message
news:ao0ti6$gis$1@rogue.oti.com...
> > Your proposed change in hit-testing seems consistent with Windows.
> Does anyone know
> > if this is how other platforms work? I thought we were being like
> Swing, but maybe not.
> > In the following SWT test, mouse events "fall through" the inactive
> sibling.
>
> :) nice example.
> But it does not "fall" through second button at least.. When using
> draw2d, such events
> "fall" down to the root Figure.

I know, my point was that the example shows what you would like to happen,
not what currently happens.

>
> > Open a bugzilla for this.
>
> ok.
>
Previous Topic:Create a Diamond Class using Polygon Class in GEF
Next Topic:How to add serval connection creation tools?
Goto Forum:
  


Current Time: Fri Apr 18 20:14:51 EDT 2025

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

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

Back to the top