]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/common/ContextMenuListener.java
Refactoring small features to common classes
[simantics/3d.git] / org.simantics.g3d.vtk / src / org / simantics / g3d / vtk / common / ContextMenuListener.java
1 package org.simantics.g3d.vtk.common;
2
3 import java.awt.event.MouseEvent;
4
5 import org.eclipse.swt.widgets.Display;
6 import org.eclipse.swt.widgets.Menu;
7
8 import vtk.vtkPanel;
9
10 public class ContextMenuListener extends java.awt.event.MouseAdapter{
11         
12         vtkPanel panel;
13         Menu contextMenu;
14         
15         public ContextMenuListener(vtkPanel panel, Menu contextMenu) {
16                 this.panel = panel;
17                 this.contextMenu = contextMenu;
18                 this.panel.addMouseListener(this);
19         }
20         @Override
21         public void mouseClicked(final MouseEvent e) {
22                 if (e.getButton() == java.awt.event.MouseEvent.BUTTON3) {
23                         Display.getDefault().asyncExec(new Runnable() {
24                                 public void run() {
25                                         contextMenu.setLocation(e.getXOnScreen(), e.getYOnScreen());
26                                         contextMenu.setVisible(true);
27                                 }
28                         });
29                 }
30         }
31
32 }