Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » How do I make a rectangle clickable?
How do I make a rectangle clickable? [message #240818] Sat, 19 January 2008 03:21 Go to next message
Bryan Hunt is currently offline Bryan Hunt
Messages: 346
Registered: July 2009
Senior Member
I would like to display a rectangle on a canvas and have it respond to
a mouse click. I tried the following and it does not work - the
rectangle does not draw when used as the contents of the Clickable.
Could somone please explain what it means for a Clickable to have
contents. I assumed that the contents of a clickable would the the
figure shown and that the Clickable would simply be a wrapper on top of
the figure handling the mouse actions, but it seems that's not the case.

Canvas canvas = new Canvas(parent, SWT.NONE);
LightweightSystem lws = new LightweightSystem(canvas);
Figure root = new Figure();
RectangleFigure rect = new RectangleFigure();
Clickable click = new Clickable(rect);
click.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent arg0)
{
System.out.println("actionPerformed()");
}
});

rect.setBounds(new Rectangle(10, 10, 100, 100));
root.add(click);
lws.setContents(root);

Bryan
Re: How do I make a rectangle clickable? [message #240823 is a reply to message #240818] Sat, 19 January 2008 08:03 Go to previous messageGo to next message
Eclipse User
Originally posted by: shady_86.sify.com

there is a predefined org.eclipse.draw2d.Button.Button()
try to use it, i am not sure but it may work..,
Re: How do I make a rectangle clickable? [message #240894 is a reply to message #240818] Wed, 23 January 2008 08:05 Go to previous messageGo to next message
Manuel Selva is currently offline Manuel Selva
Messages: 189
Registered: July 2009
Location: Grenoble, France
Senior Member
Hi Bryan,

AN other way to achieve what you want is by adding a Draw2D MouseListener
to your rectangle.

The MouseListener interface allows you to respond to mouse up, mouse down
and mouse double click events.

Hope this help

Manu
http://manuelselva.wordpress.com/


Re: How do I make a rectangle clickable? [message #240949 is a reply to message #240894] Fri, 25 January 2008 06:55 Go to previous messageGo to next message
Neeraj Bhusare is currently offline Neeraj Bhusare
Messages: 93
Registered: July 2009
Location: India
Member
Manuel Selva wrote:

> Hi Bryan,

> AN other way to achieve what you want is by adding a Draw2D MouseListener
> to your rectangle.

> The MouseListener interface allows you to respond to mouse up, mouse down
> and mouse double click events.

> Hope this help

> Manu
> http://manuelselva.wordpress.com/

Hello Bryan,
You may like to have a look at
org.eclipse.draw2d.LightweightSystem class.

Neeraj.


Best regards, Neeraj
Re: How do I make a rectangle clickable? [message #241073 is a reply to message #240818] Tue, 29 January 2008 07:51 Go to previous message
Eclipse User
Originally posted by: Gerhard.Hinterndorfer.pedrics.at

Hallo Bryan,

use addMouseListener:

rect.addMouseListener(new MouseListener.Stub(){
public void mousePressed(MouseEvent me){
System.out.println("Mouse pressed on rect:" +"
x-Pos:"+me.x+" y-Pos:"+me.y);
});

Hope that helps.

cheers
Gerhard

Bryan Hunt schrieb:
> I would like to display a rectangle on a canvas and have it respond to a
> mouse click. I tried the following and it does not work - the rectangle
> does not draw when used as the contents of the Clickable. Could somone
> please explain what it means for a Clickable to have contents. I
> assumed that the contents of a clickable would the the figure shown and
> that the Clickable would simply be a wrapper on top of the figure
> handling the mouse actions, but it seems that's not the case.
>
> Canvas canvas = new Canvas(parent, SWT.NONE);
> LightweightSystem lws = new LightweightSystem(canvas);
> Figure root = new Figure();
> RectangleFigure rect = new RectangleFigure();
> Clickable click = new Clickable(rect);
> click.addActionListener(new ActionListener()
> {
> public void actionPerformed(ActionEvent arg0)
> {
> System.out.println("actionPerformed()");
> }
> });
>
> rect.setBounds(new Rectangle(10, 10, 100, 100));
> root.add(click);
> lws.setContents(root);
>
> Bryan
>
Previous Topic:problem with selection provider: domain object wanted instead of editpart
Next Topic:splines or bezier curves with Draw2D?
Goto Forum:
  


Current Time: Thu Oct 30 17:39:35 GMT 2014

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

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