]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.diagram/src/org/simantics/diagram/ui/SWTPopupMenuParticipantAwt.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.diagram / src / org / simantics / diagram / ui / SWTPopupMenuParticipantAwt.java
index a06e047274b3e0e23406e1d5c8080a0b4b2b7875..75aa8ec780fc2853ca4a48a1ac3bfdb0bd2ba360 100644 (file)
-/*******************************************************************************\r
- * Copyright (c) 2007, 2010 Association for Decentralized Information Management\r
- * in Industry THTH ry.\r
- * All rights reserved. This program and the accompanying materials\r
- * are made available under the terms of the Eclipse Public License v1.0\r
- * which accompanies this distribution, and is available at\r
- * http://www.eclipse.org/legal/epl-v10.html\r
- *\r
- * Contributors:\r
- *     VTT Technical Research Centre of Finland - initial API and implementation\r
- *******************************************************************************/\r
-package org.simantics.diagram.ui;\r
-\r
-import java.awt.geom.Point2D;\r
-\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.events.MenuEvent;\r
-import org.eclipse.swt.graphics.Point;\r
-import org.eclipse.swt.widgets.Control;\r
-import org.eclipse.swt.widgets.Display;\r
-import org.eclipse.swt.widgets.Menu;\r
-import org.eclipse.swt.widgets.Shell;\r
-import org.eclipse.ui.IWorkbenchPartSite;\r
-import org.simantics.g2d.diagram.DiagramHints;\r
-\r
-/**\r
- * This is a SWTPopupMenu implementation with workaround for SWT popup menus that do not work when overlaid top of AWT widgets in Linux/GTK \r
- * \r
- * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=392101\r
- * \r
- * \r
- * @author Marko Luukkainen\r
- *\r
- */\r
-public class SWTPopupMenuParticipantAwt extends SWTPopupMenuParticipant {\r
-\r
-       Shell shell;\r
-       Menu menu;\r
-       \r
-    public SWTPopupMenuParticipantAwt(IWorkbenchPartSite site, Control control, Display display, String menuId) {\r
-               super(site, control, display, menuId);\r
-       }\r
-    \r
-    @Override\r
-    protected void runDispose() {\r
-       if (shell != null) {\r
-               shell.dispose();\r
-               shell = null;\r
-       }\r
-               \r
-       super.runDispose();\r
-    }\r
-    \r
-\r
-    @Override\r
-    protected void createControl() {\r
-       if(shell == null) {\r
-           shell = new Shell(control.getShell(),SWT.NO_TRIM|SWT.NO_FOCUS|SWT.ON_TOP);\r
-           shell.setSize(4, 4);\r
-           shell.setVisible(false);\r
-       }\r
-       menuManager = createPopupMenu();\r
-        if (menuManager != null) {\r
-               menu = menuManager.createContextMenu(shell);\r
-            menu.addMenuListener(menuListener);\r
-            shell.setMenu(menu);\r
-            if (site != null) {\r
-                site.registerContextMenu(menuManager.getId(), menuManager, wbsp);\r
-            }\r
-        }\r
-    }\r
-    \r
-    @Override\r
-    protected void menuHidden(MenuEvent e) {\r
-       if (shell != null)\r
-               shell.setVisible(false);\r
-       super.menuHidden(e);\r
-    }\r
-    \r
-       /**\r
-     * @param newValue\r
-     * @thread canvas-thread (AWT)\r
-     */\r
-    protected void showPopup(Point2D newValue) {\r
-       final Point2D cp = (Point2D) newValue;\r
-        setHint(DiagramHints.POPUP_MENU_CONTROL_POSITION, cp);\r
-        setHint(DiagramHints.POPUP_MENU_CANVAS_POSITION, trUtil.controlToCanvas(cp, null));\r
-        display.asyncExec(new Runnable() {\r
-            @Override\r
-            public void run() {\r
-                \r
-               if (control == null || control.isDisposed())\r
-                    return;\r
-                final Point p = control.toDisplay((int) cp.getX(), (int) cp.getY());\r
-                                         \r
-                   shell.getDisplay().asyncExec(new Runnable() {\r
-                     public void run() {\r
-                               shell.setLocation(p.x-1, p.y-1);\r
-                               shell.setActive();\r
-                               shell.setVisible(true);\r
-                     }});\r
-                   shell.getDisplay().asyncExec(new Runnable() {\r
-                     public void run() {\r
-                       menuManager.getMenu().setLocation(p);\r
-                    menuManager.getMenu().setVisible(true);\r
-                     }});\r
-\r
-            }\r
-        });\r
-    }\r
-\r
-}\r
+/*******************************************************************************
+ * Copyright (c) 2007, 2010 Association for Decentralized Information Management
+ * in Industry THTH ry.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *     VTT Technical Research Centre of Finland - initial API and implementation
+ *******************************************************************************/
+package org.simantics.diagram.ui;
+
+import java.awt.geom.Point2D;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.MenuEvent;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Menu;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.IWorkbenchPartSite;
+import org.simantics.g2d.diagram.DiagramHints;
+
+/**
+ * This is a SWTPopupMenu implementation with workaround for SWT popup menus that do not work when overlaid top of AWT widgets in Linux/GTK 
+ * 
+ * @see https://bugs.eclipse.org/bugs/show_bug.cgi?id=392101
+ * 
+ * 
+ * @author Marko Luukkainen
+ *
+ */
+public class SWTPopupMenuParticipantAwt extends SWTPopupMenuParticipant {
+
+       Shell shell;
+       Menu menu;
+       
+    public SWTPopupMenuParticipantAwt(IWorkbenchPartSite site, Control control, Display display, String menuId) {
+               super(site, control, display, menuId);
+       }
+    
+    @Override
+    protected void runDispose() {
+       if (shell != null) {
+               shell.dispose();
+               shell = null;
+       }
+               
+       super.runDispose();
+    }
+    
+
+    @Override
+    protected void createControl() {
+       if(shell == null) {
+           shell = new Shell(control.getShell(),SWT.NO_TRIM|SWT.NO_FOCUS|SWT.ON_TOP);
+           shell.setSize(4, 4);
+           shell.setVisible(false);
+       }
+       menuManager = createPopupMenu();
+        if (menuManager != null) {
+               menu = menuManager.createContextMenu(shell);
+            menu.addMenuListener(menuListener);
+            shell.setMenu(menu);
+            if (site != null) {
+                site.registerContextMenu(menuManager.getId(), menuManager, wbsp);
+            }
+        }
+    }
+    
+    @Override
+    protected void menuHidden(MenuEvent e) {
+       if (shell != null)
+               shell.setVisible(false);
+       super.menuHidden(e);
+    }
+    
+       /**
+     * @param newValue
+     * @thread canvas-thread (AWT)
+     */
+    protected void showPopup(Point2D newValue) {
+       final Point2D cp = (Point2D) newValue;
+        setHint(DiagramHints.POPUP_MENU_CONTROL_POSITION, cp);
+        setHint(DiagramHints.POPUP_MENU_CANVAS_POSITION, trUtil.controlToCanvas(cp, null));
+        display.asyncExec(new Runnable() {
+            @Override
+            public void run() {
+                
+               if (control == null || control.isDisposed())
+                    return;
+                final Point p = control.toDisplay((int) cp.getX(), (int) cp.getY());
+                                         
+                   shell.getDisplay().asyncExec(new Runnable() {
+                     public void run() {
+                               shell.setLocation(p.x-1, p.y-1);
+                               shell.setActive();
+                               shell.setVisible(true);
+                     }});
+                   shell.getDisplay().asyncExec(new Runnable() {
+                     public void run() {
+                       menuManager.getMenu().setLocation(p);
+                    menuManager.getMenu().setVisible(true);
+                     }});
+
+            }
+        });
+    }
+
+}