Home » Eclipse Projects » GEF » Simple Examples and a Mouse Listener
Simple Examples and a Mouse Listener [message #57178] |
Wed, 22 January 2003 19:38 |
Eclipse User |
|
|
|
Originally posted by: ian.ianbull.com
Hi,
I am very new to Eclipse, SWT and GEF so I may just be missing something
obvious.
I am trying to extend the basic examples found at
(http://eclipsewiki.swiki.net/50). In particular I am trying to add a mouse
listener to the rectangles. When I did this (using the rectangles
addMouseListener method) I found I could receive mouse pressed but not mouse
released or double click events. I tried the same with Keyboard events and
found I could not receive any. I couldn't find any way of saying
"EnableDoubleClick" or "EnableKeyboardEvents". Am I missing something
obvious? Is this even the desired way to implement keyboard / mouse
handlers.
As I mentioned I am extremely new to this platform so if this isn't the
right newsgroup for questions of this nature, I'm sorry. (If someone could
point me to the right newsgroup that would be great). Also, If anyone has
any information on "Getting Started with GEF / SWT" it would be greatly
appreciated. (I have been using these HelloGef examples and the javadocs).
Thanks,
Ian
|
|
|
Re: Simple Examples and a Mouse Listener [message #57310 is a reply to message #57178] |
Wed, 22 January 2003 21:03 |
Eclipse User |
|
|
|
Originally posted by: noone.ibm.com
What you have explained sounds valid. Try this example:
import org.eclipse.draw2d.Figure;
import org.eclipse.draw2d.KeyEvent;
import org.eclipse.draw2d.KeyListener;
import org.eclipse.draw2d.LightweightSystem;
import org.eclipse.draw2d.MouseEvent;
import org.eclipse.draw2d.MouseListener;
import org.eclipse.draw2d.RectangleFigure;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
/**
* @author danlee
*/
public class MouseListenerTest {
public static void main(String[] args) {
Display d = new Display();
final Shell shell = new Shell(d);
shell.setSize(200, 200);
LightweightSystem lws = new LightweightSystem(shell);
Figure fig = new Figure();
lws.setContents(fig);
Figure rect1 = new RectangleFigure();
rect1.setBounds(new Rectangle(0,0,50,50));
fig.add(rect1);
rect1.addMouseListener(new MouseListener() {
/**
* @see org.eclipse.draw2d.MouseListener#mousePressed(MouseEvent)
*/
public void mousePressed(MouseEvent me) {
System.out.println("Mouse pressed");
}
/**
* @see org.eclipse.draw2d.MouseListener#mouseReleased(MouseEvent)
*/
public void mouseReleased(MouseEvent me) {
System.out.println("Mouse released");
}
/**
* @see org.eclipse.draw2d.MouseListener#mouseDoubleClicked(MouseEve nt)
*/
public void mouseDoubleClicked(MouseEvent me) {
System.out.println("Mouse double clicked");
}
});
shell.open();
while (!shell.isDisposed())
while (!d.readAndDispatch())
d.sleep();
}
}
"ian" <ian@ianbull.com> wrote in message news:b0mqtf$r5n$1@rogue.oti.com...
> Hi,
> I am very new to Eclipse, SWT and GEF so I may just be missing something
> obvious.
>
> I am trying to extend the basic examples found at
> (http://eclipsewiki.swiki.net/50). In particular I am trying to add a
mouse
> listener to the rectangles. When I did this (using the rectangles
> addMouseListener method) I found I could receive mouse pressed but not
mouse
> released or double click events. I tried the same with Keyboard events
and
> found I could not receive any. I couldn't find any way of saying
> "EnableDoubleClick" or "EnableKeyboardEvents". Am I missing something
> obvious? Is this even the desired way to implement keyboard / mouse
> handlers.
>
> As I mentioned I am extremely new to this platform so if this isn't the
> right newsgroup for questions of this nature, I'm sorry. (If someone
could
> point me to the right newsgroup that would be great). Also, If anyone has
> any information on "Getting Started with GEF / SWT" it would be greatly
> appreciated. (I have been using these HelloGef examples and the
javadocs).
>
> Thanks,
> Ian
>
>
|
|
|
Re: Simple Examples and a Mouse Listener [message #57360 is a reply to message #57310] |
Wed, 22 January 2003 21:54 |
Eric Bordeau Messages: 259 Registered: July 2009 |
Senior Member |
|
|
It's not always that simple when you use GEF (as opposed to pure Draw2d like Dan's example). With
GEF, most mouse/keyboard events are handled through the tools. For instance, SelectEditPartTracker
overrides handleDoubleClick() to invoke direct edit. The reason you're not getting a double click
event is because GEF's DomainEventDispatcher routes all mouse events (except mouse pressed) to the
editor unless a figure has consumed the mouse event (which can be done during the mouse pressed
event). If, for instance, you put a mouse listener on a figure and in mousePressed() you say
event.consume(), that figure will then get subsequent mouse events (until the mouse is released).
If you don't call event.consume(), the events will be sent directly to the active tool until (and
including) the next mouse release event.
If you're going to use GEF, you shouldn't rely on listening to mouse events on figures. However, if
you're application just displays information and you don't need to edit a model, using pure Draw2d
is better suited and much less complex. In that case, you wouldn't have a DomainEventDispatcher at
all and your mouse events should arrive as expected (like in Dan's example).
I currently see a problem with the way GEF handles double click in particular. Right now, a double
click will invoke direct edit. But I can think of situations when a double click should perform
some other action, like in a file explorer. It should be easier for GEF users to customize what a
double click will do. Subclassing a tool seems too extreme. But it is a possibility.
Anyway, I hope this helps.
Eric
Dan Lee wrote:
> What you have explained sounds valid. Try this example:
>
> import org.eclipse.draw2d.Figure;
>
> import org.eclipse.draw2d.KeyEvent;
>
> import org.eclipse.draw2d.KeyListener;
>
> import org.eclipse.draw2d.LightweightSystem;
>
> import org.eclipse.draw2d.MouseEvent;
>
> import org.eclipse.draw2d.MouseListener;
>
> import org.eclipse.draw2d.RectangleFigure;
>
> import org.eclipse.draw2d.geometry.Rectangle;
>
> import org.eclipse.swt.widgets.Display;
>
> import org.eclipse.swt.widgets.Shell;
>
> /**
>
> * @author danlee
>
> */
>
> public class MouseListenerTest {
>
> public static void main(String[] args) {
>
>
> Display d = new Display();
>
> final Shell shell = new Shell(d);
>
> shell.setSize(200, 200);
>
> LightweightSystem lws = new LightweightSystem(shell);
>
> Figure fig = new Figure();
>
> lws.setContents(fig);
>
>
> Figure rect1 = new RectangleFigure();
>
> rect1.setBounds(new Rectangle(0,0,50,50));
>
> fig.add(rect1);
>
>
> rect1.addMouseListener(new MouseListener() {
>
> /**
>
> * @see org.eclipse.draw2d.MouseListener#mousePressed(MouseEvent)
>
> */
>
> public void mousePressed(MouseEvent me) {
>
> System.out.println("Mouse pressed");
>
> }
>
> /**
>
> * @see org.eclipse.draw2d.MouseListener#mouseReleased(MouseEvent)
>
> */
>
> public void mouseReleased(MouseEvent me) {
>
> System.out.println("Mouse released");
>
> }
>
> /**
>
> * @see org.eclipse.draw2d.MouseListener#mouseDoubleClicked(MouseEve nt)
>
> */
>
> public void mouseDoubleClicked(MouseEvent me) {
>
> System.out.println("Mouse double clicked");
>
> }
>
> });
>
> shell.open();
>
> while (!shell.isDisposed())
>
> while (!d.readAndDispatch())
>
> d.sleep();
>
> }
>
> }
>
> "ian" <ian@ianbull.com> wrote in message news:b0mqtf$r5n$1@rogue.oti.com...
>
>>Hi,
>>I am very new to Eclipse, SWT and GEF so I may just be missing something
>>obvious.
>>
>>I am trying to extend the basic examples found at
>>(http://eclipsewiki.swiki.net/50). In particular I am trying to add a
>
> mouse
>
>>listener to the rectangles. When I did this (using the rectangles
>>addMouseListener method) I found I could receive mouse pressed but not
>
> mouse
>
>>released or double click events. I tried the same with Keyboard events
>
> and
>
>>found I could not receive any. I couldn't find any way of saying
>>"EnableDoubleClick" or "EnableKeyboardEvents". Am I missing something
>>obvious? Is this even the desired way to implement keyboard / mouse
>>handlers.
>>
>>As I mentioned I am extremely new to this platform so if this isn't the
>>right newsgroup for questions of this nature, I'm sorry. (If someone
>
> could
>
>>point me to the right newsgroup that would be great). Also, If anyone has
>>any information on "Getting Started with GEF / SWT" it would be greatly
>>appreciated. (I have been using these HelloGef examples and the
>
> javadocs).
>
>>Thanks,
>>Ian
>>
>>
>
>
>
|
|
|
Re: Simple Examples and a Mouse Listener [message #57384 is a reply to message #57310] |
Wed, 22 January 2003 22:27 |
Eclipse User |
|
|
|
Originally posted by: ian.ianbull.com
Thanks Dan,
I'm starting to get a better idea of the difference between GEF and simple
draw2d.
I understand what your example does, but I can't get it to work. I am
getting an UnsatisfiedLinkError for swt-win32-2049. I added both the
org.eclipse.swt and org.eclipse.swt32 to my buildpath, and to the classpath
you can edit when pressing run... from the tool bar (I assume this is the
runtime path?). Although I'm not sure if either of these jar files provides
me with the swt-win32-2049 library (2049?).
Sorry for the inconvenience obvious simple question, but I come from a unix
background so I'm not used to these fancy editors :).
Also, I have only used eclipse for plugins. I have never written a
stand-alone application yet.
cheers,
Ian
--
Ian Bull - IBM Centre for Advanced Studies
University of Victoria
"Dan Lee" <noone@ibm.com> wrote in message
news:b0mvs2$va2$1@rogue.oti.com...
> What you have explained sounds valid. Try this example:
>
> import org.eclipse.draw2d.Figure;
>
> import org.eclipse.draw2d.KeyEvent;
>
> import org.eclipse.draw2d.KeyListener;
>
> import org.eclipse.draw2d.LightweightSystem;
>
> import org.eclipse.draw2d.MouseEvent;
>
> import org.eclipse.draw2d.MouseListener;
>
> import org.eclipse.draw2d.RectangleFigure;
>
> import org.eclipse.draw2d.geometry.Rectangle;
>
> import org.eclipse.swt.widgets.Display;
>
> import org.eclipse.swt.widgets.Shell;
>
> /**
>
> * @author danlee
>
> */
>
> public class MouseListenerTest {
>
> public static void main(String[] args) {
>
>
> Display d = new Display();
>
> final Shell shell = new Shell(d);
>
> shell.setSize(200, 200);
>
> LightweightSystem lws = new LightweightSystem(shell);
>
> Figure fig = new Figure();
>
> lws.setContents(fig);
>
>
> Figure rect1 = new RectangleFigure();
>
> rect1.setBounds(new Rectangle(0,0,50,50));
>
> fig.add(rect1);
>
>
> rect1.addMouseListener(new MouseListener() {
>
> /**
>
> * @see org.eclipse.draw2d.MouseListener#mousePressed(MouseEvent)
>
> */
>
> public void mousePressed(MouseEvent me) {
>
> System.out.println("Mouse pressed");
>
> }
>
> /**
>
> * @see org.eclipse.draw2d.MouseListener#mouseReleased(MouseEvent)
>
> */
>
> public void mouseReleased(MouseEvent me) {
>
> System.out.println("Mouse released");
>
> }
>
> /**
>
> * @see org.eclipse.draw2d.MouseListener#mouseDoubleClicked(MouseEve nt)
>
> */
>
> public void mouseDoubleClicked(MouseEvent me) {
>
> System.out.println("Mouse double clicked");
>
> }
>
> });
>
> shell.open();
>
> while (!shell.isDisposed())
>
> while (!d.readAndDispatch())
>
> d.sleep();
>
> }
>
> }
>
> "ian" <ian@ianbull.com> wrote in message
news:b0mqtf$r5n$1@rogue.oti.com...
> > Hi,
> > I am very new to Eclipse, SWT and GEF so I may just be missing something
> > obvious.
> >
> > I am trying to extend the basic examples found at
> > (http://eclipsewiki.swiki.net/50). In particular I am trying to add a
> mouse
> > listener to the rectangles. When I did this (using the rectangles
> > addMouseListener method) I found I could receive mouse pressed but not
> mouse
> > released or double click events. I tried the same with Keyboard events
> and
> > found I could not receive any. I couldn't find any way of saying
> > "EnableDoubleClick" or "EnableKeyboardEvents". Am I missing something
> > obvious? Is this even the desired way to implement keyboard / mouse
> > handlers.
> >
> > As I mentioned I am extremely new to this platform so if this isn't the
> > right newsgroup for questions of this nature, I'm sorry. (If someone
> could
> > point me to the right newsgroup that would be great). Also, If anyone
has
> > any information on "Getting Started with GEF / SWT" it would be greatly
> > appreciated. (I have been using these HelloGef examples and the
> javadocs).
> >
> > Thanks,
> > Ian
> >
> >
>
>
|
|
|
Re: Simple Examples and a Mouse Listener [message #57410 is a reply to message #57360] |
Wed, 22 January 2003 22:33 |
Eclipse User |
|
|
|
Originally posted by: ian.ianbull.com
Thanks Eric,
Your post cleared a lot up as well. I am hoping to create a widget that
will be editable (hence the desire to use GEF) but allows me to open up
containers (such as file explores do) on double click, (or single click and
a key stroke). I still have a lot to learn before I get to this point
though :).
Cheers,
ian
--
Ian Bull - IBM Centre for Advanced Studies
University of Victoria
"Eric Bordeau" <ebordeau@us.ibm.com> wrote in message
news:b0n2r4$vda$1@rogue.oti.com...
> It's not always that simple when you use GEF (as opposed to pure Draw2d
like Dan's example). With
> GEF, most mouse/keyboard events are handled through the tools. For
instance, SelectEditPartTracker
> overrides handleDoubleClick() to invoke direct edit. The reason you're
not getting a double click
> event is because GEF's DomainEventDispatcher routes all mouse events
(except mouse pressed) to the
> editor unless a figure has consumed the mouse event (which can be done
during the mouse pressed
> event). If, for instance, you put a mouse listener on a figure and in
mousePressed() you say
> event.consume(), that figure will then get subsequent mouse events (until
the mouse is released).
> If you don't call event.consume(), the events will be sent directly to the
active tool until (and
> including) the next mouse release event.
>
> If you're going to use GEF, you shouldn't rely on listening to mouse
events on figures. However, if
> you're application just displays information and you don't need to edit a
model, using pure Draw2d
> is better suited and much less complex. In that case, you wouldn't have a
DomainEventDispatcher at
> all and your mouse events should arrive as expected (like in Dan's
example).
>
> I currently see a problem with the way GEF handles double click in
particular. Right now, a double
> click will invoke direct edit. But I can think of situations when a
double click should perform
> some other action, like in a file explorer. It should be easier for GEF
users to customize what a
> double click will do. Subclassing a tool seems too extreme. But it is a
possibility.
>
> Anyway, I hope this helps.
>
> Eric
>
>
>
>
> Dan Lee wrote:
> > What you have explained sounds valid. Try this example:
> >
> > import org.eclipse.draw2d.Figure;
> >
> > import org.eclipse.draw2d.KeyEvent;
> >
> > import org.eclipse.draw2d.KeyListener;
> >
> > import org.eclipse.draw2d.LightweightSystem;
> >
> > import org.eclipse.draw2d.MouseEvent;
> >
> > import org.eclipse.draw2d.MouseListener;
> >
> > import org.eclipse.draw2d.RectangleFigure;
> >
> > import org.eclipse.draw2d.geometry.Rectangle;
> >
> > import org.eclipse.swt.widgets.Display;
> >
> > import org.eclipse.swt.widgets.Shell;
> >
> > /**
> >
> > * @author danlee
> >
> > */
> >
> > public class MouseListenerTest {
> >
> > public static void main(String[] args) {
> >
> >
> > Display d = new Display();
> >
> > final Shell shell = new Shell(d);
> >
> > shell.setSize(200, 200);
> >
> > LightweightSystem lws = new LightweightSystem(shell);
> >
> > Figure fig = new Figure();
> >
> > lws.setContents(fig);
> >
> >
> > Figure rect1 = new RectangleFigure();
> >
> > rect1.setBounds(new Rectangle(0,0,50,50));
> >
> > fig.add(rect1);
> >
> >
> > rect1.addMouseListener(new MouseListener() {
> >
> > /**
> >
> > * @see org.eclipse.draw2d.MouseListener#mousePressed(MouseEvent)
> >
> > */
> >
> > public void mousePressed(MouseEvent me) {
> >
> > System.out.println("Mouse pressed");
> >
> > }
> >
> > /**
> >
> > * @see org.eclipse.draw2d.MouseListener#mouseReleased(MouseEvent)
> >
> > */
> >
> > public void mouseReleased(MouseEvent me) {
> >
> > System.out.println("Mouse released");
> >
> > }
> >
> > /**
> >
> > * @see org.eclipse.draw2d.MouseListener#mouseDoubleClicked(MouseEve nt)
> >
> > */
> >
> > public void mouseDoubleClicked(MouseEvent me) {
> >
> > System.out.println("Mouse double clicked");
> >
> > }
> >
> > });
> >
> > shell.open();
> >
> > while (!shell.isDisposed())
> >
> > while (!d.readAndDispatch())
> >
> > d.sleep();
> >
> > }
> >
> > }
> >
> > "ian" <ian@ianbull.com> wrote in message
news:b0mqtf$r5n$1@rogue.oti.com...
> >
> >>Hi,
> >>I am very new to Eclipse, SWT and GEF so I may just be missing something
> >>obvious.
> >>
> >>I am trying to extend the basic examples found at
> >>(http://eclipsewiki.swiki.net/50). In particular I am trying to add a
> >
> > mouse
> >
> >>listener to the rectangles. When I did this (using the rectangles
> >>addMouseListener method) I found I could receive mouse pressed but not
> >
> > mouse
> >
> >>released or double click events. I tried the same with Keyboard events
> >
> > and
> >
> >>found I could not receive any. I couldn't find any way of saying
> >>"EnableDoubleClick" or "EnableKeyboardEvents". Am I missing something
> >>obvious? Is this even the desired way to implement keyboard / mouse
> >>handlers.
> >>
> >>As I mentioned I am extremely new to this platform so if this isn't the
> >>right newsgroup for questions of this nature, I'm sorry. (If someone
> >
> > could
> >
> >>point me to the right newsgroup that would be great). Also, If anyone
has
> >>any information on "Getting Started with GEF / SWT" it would be greatly
> >>appreciated. (I have been using these HelloGef examples and the
> >
> > javadocs).
> >
> >>Thanks,
> >>Ian
> >>
> >>
> >
> >
> >
>
|
|
|
Re: Simple Examples and a Mouse Listener [message #57436 is a reply to message #57384] |
Wed, 22 January 2003 23:18 |
Eric Bordeau Messages: 259 Registered: July 2009 |
Senior Member |
|
|
That library is in plugins\org.eclipse.swt.win32_<some version number>\os\win32\x86. I usually just
put the library file in my windows directory.
Eric
ian wrote:
> Thanks Dan,
> I'm starting to get a better idea of the difference between GEF and simple
> draw2d.
> I understand what your example does, but I can't get it to work. I am
> getting an UnsatisfiedLinkError for swt-win32-2049. I added both the
> org.eclipse.swt and org.eclipse.swt32 to my buildpath, and to the classpath
> you can edit when pressing run... from the tool bar (I assume this is the
> runtime path?). Although I'm not sure if either of these jar files provides
> me with the swt-win32-2049 library (2049?).
>
> Sorry for the inconvenience obvious simple question, but I come from a unix
> background so I'm not used to these fancy editors :).
> Also, I have only used eclipse for plugins. I have never written a
> stand-alone application yet.
>
> cheers,
> Ian
>
> --
> Ian Bull - IBM Centre for Advanced Studies
> University of Victoria
>
> "Dan Lee" <noone@ibm.com> wrote in message
> news:b0mvs2$va2$1@rogue.oti.com...
>
>>What you have explained sounds valid. Try this example:
>>
>>import org.eclipse.draw2d.Figure;
>>
>>import org.eclipse.draw2d.KeyEvent;
>>
>>import org.eclipse.draw2d.KeyListener;
>>
>>import org.eclipse.draw2d.LightweightSystem;
>>
>>import org.eclipse.draw2d.MouseEvent;
>>
>>import org.eclipse.draw2d.MouseListener;
>>
>>import org.eclipse.draw2d.RectangleFigure;
>>
>>import org.eclipse.draw2d.geometry.Rectangle;
>>
>>import org.eclipse.swt.widgets.Display;
>>
>>import org.eclipse.swt.widgets.Shell;
>>
>>/**
>>
>>* @author danlee
>>
>>*/
>>
>>public class MouseListenerTest {
>>
>>public static void main(String[] args) {
>>
>>
>>Display d = new Display();
>>
>>final Shell shell = new Shell(d);
>>
>>shell.setSize(200, 200);
>>
>>LightweightSystem lws = new LightweightSystem(shell);
>>
>>Figure fig = new Figure();
>>
>>lws.setContents(fig);
>>
>>
>>Figure rect1 = new RectangleFigure();
>>
>>rect1.setBounds(new Rectangle(0,0,50,50));
>>
>>fig.add(rect1);
>>
>>
>>rect1.addMouseListener(new MouseListener() {
>>
>>/**
>>
>>* @see org.eclipse.draw2d.MouseListener#mousePressed(MouseEvent)
>>
>>*/
>>
>>public void mousePressed(MouseEvent me) {
>>
>>System.out.println("Mouse pressed");
>>
>>}
>>
>>/**
>>
>>* @see org.eclipse.draw2d.MouseListener#mouseReleased(MouseEvent)
>>
>>*/
>>
>>public void mouseReleased(MouseEvent me) {
>>
>>System.out.println("Mouse released");
>>
>>}
>>
>>/**
>>
>>* @see org.eclipse.draw2d.MouseListener#mouseDoubleClicked(MouseEve nt)
>>
>>*/
>>
>>public void mouseDoubleClicked(MouseEvent me) {
>>
>>System.out.println("Mouse double clicked");
>>
>>}
>>
>>});
>>
>>shell.open();
>>
>>while (!shell.isDisposed())
>>
>>while (!d.readAndDispatch())
>>
>>d.sleep();
>>
>>}
>>
>>}
>>
>>"ian" <ian@ianbull.com> wrote in message
>
> news:b0mqtf$r5n$1@rogue.oti.com...
>
>>>Hi,
>>>I am very new to Eclipse, SWT and GEF so I may just be missing something
>>>obvious.
>>>
>>>I am trying to extend the basic examples found at
>>>(http://eclipsewiki.swiki.net/50). In particular I am trying to add a
>>
>>mouse
>>
>>>listener to the rectangles. When I did this (using the rectangles
>>>addMouseListener method) I found I could receive mouse pressed but not
>>
>>mouse
>>
>>>released or double click events. I tried the same with Keyboard events
>>
>>and
>>
>>>found I could not receive any. I couldn't find any way of saying
>>>"EnableDoubleClick" or "EnableKeyboardEvents". Am I missing something
>>>obvious? Is this even the desired way to implement keyboard / mouse
>>>handlers.
>>>
>>>As I mentioned I am extremely new to this platform so if this isn't the
>>>right newsgroup for questions of this nature, I'm sorry. (If someone
>>
>>could
>>
>>>point me to the right newsgroup that would be great). Also, If anyone
>
> has
>
>>>any information on "Getting Started with GEF / SWT" it would be greatly
>>>appreciated. (I have been using these HelloGef examples and the
>>
>>javadocs).
>>
>>>Thanks,
>>>Ian
>>>
>>>
>>
>>
>
>
|
|
|
Re: Simple Examples and a Mouse Listener [message #58290 is a reply to message #57360] |
Mon, 27 January 2003 16:05 |
Eclipse User |
|
|
|
Originally posted by: hudsonr.us.i_b_m.com
"Eric Bordeau" <ebordeau@us.ibm.com> wrote in message
news:b0n2r4$vda$1@rogue.oti.com...
> It's not always that simple when you use GEF (as opposed to pure Draw2d
like Dan's example). With
> GEF, most mouse/keyboard events are handled through the tools. For
instance, SelectEditPartTracker
> overrides handleDoubleClick() to invoke direct edit. The reason you're
not getting a double click
> event is because GEF's DomainEventDispatcher routes all mouse events
(except mouse pressed) to the
> editor unless a figure has consumed the mouse event (which can be done
during the mouse pressed
> event). If, for instance, you put a mouse listener on a figure and in
mousePressed() you say
> event.consume(), that figure will then get subsequent mouse events (until
the mouse is released).
> If you don't call event.consume(), the events will be sent directly to the
active tool until (and
> including) the next mouse release event.
>
> If you're going to use GEF, you shouldn't rely on listening to mouse
events on figures. However, if
> you're application just displays information and you don't need to edit a
model, using pure Draw2d
> is better suited and much less complex. In that case, you wouldn't have a
DomainEventDispatcher at
> all and your mouse events should arrive as expected (like in Dan's
example).
>
> I currently see a problem with the way GEF handles double click in
particular. Right now, a double
> click will invoke direct edit. But I can think of situations when a
double click should perform
> some other action, like in a file explorer. It should be easier for GEF
users to customize what a
> double click will do. Subclassing a tool seems too extreme. But it is a
possibility.
double-click is processed by the SelectEditPartTracker, which is provided by
the editpart. DirectEdit is just a Request sent to the EditPart, and Ian's
EditPart could interpret this to mean "open folder" or whatever.
Perhaps we could make the Request and its constant a more generic names, sim
ply indicating that a double click occurred, which would be a breaking
change. Also, we might change the direct edit "gesture" to be a single
click on an already selected part, ala Windows Explorer.
>
> Anyway, I hope this helps.
>
> Eric
>
>
>
>
> Dan Lee wrote:
> > What you have explained sounds valid. Try this example:
> >
> > import org.eclipse.draw2d.Figure;
> >
> > import org.eclipse.draw2d.KeyEvent;
> >
> > import org.eclipse.draw2d.KeyListener;
> >
> > import org.eclipse.draw2d.LightweightSystem;
> >
> > import org.eclipse.draw2d.MouseEvent;
> >
> > import org.eclipse.draw2d.MouseListener;
> >
> > import org.eclipse.draw2d.RectangleFigure;
> >
> > import org.eclipse.draw2d.geometry.Rectangle;
> >
> > import org.eclipse.swt.widgets.Display;
> >
> > import org.eclipse.swt.widgets.Shell;
> >
> > /**
> >
> > * @author danlee
> >
> > */
> >
> > public class MouseListenerTest {
> >
> > public static void main(String[] args) {
> >
> >
> > Display d = new Display();
> >
> > final Shell shell = new Shell(d);
> >
> > shell.setSize(200, 200);
> >
> > LightweightSystem lws = new LightweightSystem(shell);
> >
> > Figure fig = new Figure();
> >
> > lws.setContents(fig);
> >
> >
> > Figure rect1 = new RectangleFigure();
> >
> > rect1.setBounds(new Rectangle(0,0,50,50));
> >
> > fig.add(rect1);
> >
> >
> > rect1.addMouseListener(new MouseListener() {
> >
> > /**
> >
> > * @see org.eclipse.draw2d.MouseListener#mousePressed(MouseEvent)
> >
> > */
> >
> > public void mousePressed(MouseEvent me) {
> >
> > System.out.println("Mouse pressed");
> >
> > }
> >
> > /**
> >
> > * @see org.eclipse.draw2d.MouseListener#mouseReleased(MouseEvent)
> >
> > */
> >
> > public void mouseReleased(MouseEvent me) {
> >
> > System.out.println("Mouse released");
> >
> > }
> >
> > /**
> >
> > * @see org.eclipse.draw2d.MouseListener#mouseDoubleClicked(MouseEve nt)
> >
> > */
> >
> > public void mouseDoubleClicked(MouseEvent me) {
> >
> > System.out.println("Mouse double clicked");
> >
> > }
> >
> > });
> >
> > shell.open();
> >
> > while (!shell.isDisposed())
> >
> > while (!d.readAndDispatch())
> >
> > d.sleep();
> >
> > }
> >
> > }
> >
> > "ian" <ian@ianbull.com> wrote in message
news:b0mqtf$r5n$1@rogue.oti.com...
> >
> >>Hi,
> >>I am very new to Eclipse, SWT and GEF so I may just be missing something
> >>obvious.
> >>
> >>I am trying to extend the basic examples found at
> >>(http://eclipsewiki.swiki.net/50). In particular I am trying to add a
> >
> > mouse
> >
> >>listener to the rectangles. When I did this (using the rectangles
> >>addMouseListener method) I found I could receive mouse pressed but not
> >
> > mouse
> >
> >>released or double click events. I tried the same with Keyboard events
> >
> > and
> >
> >>found I could not receive any. I couldn't find any way of saying
> >>"EnableDoubleClick" or "EnableKeyboardEvents". Am I missing something
> >>obvious? Is this even the desired way to implement keyboard / mouse
> >>handlers.
> >>
> >>As I mentioned I am extremely new to this platform so if this isn't the
> >>right newsgroup for questions of this nature, I'm sorry. (If someone
> >
> > could
> >
> >>point me to the right newsgroup that would be great). Also, If anyone
has
> >>any information on "Getting Started with GEF / SWT" it would be greatly
> >>appreciated. (I have been using these HelloGef examples and the
> >
> > javadocs).
> >
> >>Thanks,
> >>Ian
> >>
> >>
> >
> >
> >
>
|
|
|
Goto Forum:
Current Time: Thu Dec 26 20:06:30 GMT 2024
Powered by FUDForum. Page generated in 0.04306 seconds
|