]> gerrit.simantics Code Review - simantics/3d.git/blob - org.simantics.g3d.vtk/src/org/simantics/g3d/vtk/swt/ContextMenuListener.java
Remove dependencies on log4j
[simantics/3d.git] / org.simantics.g3d.vtk / src / org / simantics / g3d / vtk / swt / ContextMenuListener.java
1 package org.simantics.g3d.vtk.swt;
2
3 import org.eclipse.swt.events.MouseEvent;
4 import org.eclipse.swt.events.MouseListener;
5 import org.eclipse.swt.graphics.Point;
6 import org.eclipse.swt.widgets.Menu;
7
8 public class ContextMenuListener implements MouseListener{
9         
10         InteractiveVtkComposite panel;
11         Menu contextMenu;
12         
13         public ContextMenuListener(InteractiveVtkComposite panel, Menu contextMenu) {
14                 this.panel = panel;
15                 this.contextMenu = contextMenu;
16                 this.panel.getComponent().addMouseListener(this);
17         }
18         
19         int x = 0;
20         int y = 0;
21         int d = 4;
22         int time = 0;
23         
24         @Override
25         public void mouseUp(MouseEvent e) {
26                 if (e.button == 3) {
27                         if (Math.abs(x-e.x) < d && Math.abs(y-e.y) < d && (e.time - time) < 500) {
28                                 Point point = panel.getComponent().getParent().toDisplay(new Point(e.x, e.y));
29                                 contextMenu.setLocation(point.x, point.y);
30                                 contextMenu.setVisible(true);
31                         }
32                 }
33         }
34         
35         @Override
36         public void mouseDown(MouseEvent e) {
37                 if (e.button == 3) {
38                         x = e.x;
39                         y = e.y;
40                         time = e.time;
41                 }
42         }
43         
44         @Override
45         public void mouseDoubleClick(MouseEvent e) {
46                         
47         }
48
49 }