|
Re: right mouse click, mouse position [message #211407 is a reply to message #211385] |
Fri, 10 March 2006 11:40   |
Eclipse User |
|
|
|
One possible solution is adding a MouseListener to the corresponding
figure.
Following implementation might work:
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.MouseEvent;
import org.eclipse.draw2d.MouseListener;
public class RightClickableEditPart extends AbstractGraphicalEditPart
implements MouseListener
{
protected IFigure createFigure()
{
IFigure figure = FigureFactory.createRightClickableFigure();
figure.addMouseListener(new RightClickMouseListener());
return figure;
}
private class RightClickMouseListener implements MouseListener
{
public void mousePressed(MouseEvent me)
{
// '2' for mouse button 2
if(me.button==2)
{
// right-clicked!
}
}
public void mouseReleased(MouseEvent me) { }
public void mouseDoubleClicked(MouseEvent me) { }
}
}
Kind regards,
--
Andreas Schosser
Mind8 GmbH
> Hi,
>
> I am looking for a way to handle right clicks on an editpart. Important
> is that I need the mouse position for the corresponding action. I have
> found this post
> http://dev.eclipse.org/newslists/news.eclipse.tools.gef/msg0 1158.html
> but maybe it is out-of-date (three years old).
>
> Is there another, simpler way today?
>
> Regards,
> Jens
|
|
|
Re: right mouse click, mouse position [message #211520 is a reply to message #211407] |
Mon, 13 March 2006 20:33  |
Eclipse User |
|
|
|
Hi Andreas,
thanks for your help. It works, but the behavior is strange. After the
first mouse click the mousePressed method arise, but after a second
click the contextmenu appears. The next click ends in the mousePressed
method again ?!?
Further I would like to show a modified context menu, depending on the
mouse position. Do you have an idea?
Regards,
Jens
Andreas Schosser wrote:
> One possible solution is adding a MouseListener to the corresponding
> figure.
> Following implementation might work:
>
> import org.eclipse.draw2d.IFigure;
> import org.eclipse.draw2d.MouseEvent;
> import org.eclipse.draw2d.MouseListener;
>
>
> public class RightClickableEditPart extends
> AbstractGraphicalEditPart implements MouseListener
> {
> protected IFigure createFigure()
> {
> IFigure figure = FigureFactory.createRightClickableFigure();
> figure.addMouseListener(new RightClickMouseListener());
> return figure;
> }
>
> private class RightClickMouseListener implements MouseListener
> {
> public void mousePressed(MouseEvent me)
> {
> // '2' for mouse button 2
> if(me.button==2)
> {
> // right-clicked!
> }
> }
>
> public void mouseReleased(MouseEvent me) { }
>
> public void mouseDoubleClicked(MouseEvent me) { }
> }
> }
>
> Kind regards,
>
> --Andreas Schosser
> Mind8 GmbH
>
>
>> Hi,
>>
>> I am looking for a way to handle right clicks on an editpart.
>> Important is that I need the mouse position for the corresponding
>> action. I have found this post
>> http://dev.eclipse.org/newslists/news.eclipse.tools.gef/msg0 1158.html
>> but maybe it is out-of-date (three years old).
>>
>> Is there another, simpler way today?
>>
>> Regards,
>> Jens
|
|
|
Powered by
FUDForum. Page generated in 0.06923 seconds