]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.g2d/src/org/simantics/g2d/tooltip/EditableTextTooltipProvider2.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / tooltip / EditableTextTooltipProvider2.java
index 3b68fac08c396dde588f0353c048411cb94af739..d81f0085568a3378bdeb1ffe544c2a51977a7fa0 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.g2d.tooltip;\r
-\r
-\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.events.KeyAdapter;\r
-import org.eclipse.swt.events.KeyEvent;\r
-import org.eclipse.swt.layout.FillLayout;\r
-import org.eclipse.swt.widgets.Composite;\r
-import org.eclipse.swt.widgets.Display;\r
-import org.eclipse.swt.widgets.Label;\r
-import org.eclipse.swt.widgets.Shell;\r
-import org.eclipse.swt.widgets.Text;\r
-import org.simantics.g2d.element.IElement;\r
-\r
-public abstract class EditableTextTooltipProvider2 implements FocusableTooltipProvider {\r
-       \r
-       private Shell shell;\r
-       private Text text;\r
-       \r
-       @Override\r
-       public void showTooltip(final IElement element, final int x, final int y) {\r
-               Display.getDefault().asyncExec(new Runnable() {\r
-                       @Override\r
-                       public void run() {\r
-                               if (shell != null) {\r
-                                       shell.dispose();\r
-                                       shell = null;\r
-                               }\r
-                               shell = new Shell(Display.getCurrent().getActiveShell(),SWT.NO_TRIM);\r
-                               shell.setLayout(new FillLayout());\r
-                               Composite composite = new Composite(shell, SWT.BORDER);\r
-                               composite.setLayout(new FillLayout(SWT.VERTICAL));\r
-                               Label label = new Label(composite,SWT.NONE);\r
-                               label.setText("Press 'F9' to focus");\r
-                               text = new Text(composite, SWT.SINGLE);\r
-                               text.setText(getTooltipText(element));\r
-                               text.addKeyListener(new KeyAdapter() {\r
-                                       @Override\r
-                                       public void keyReleased(KeyEvent e) {\r
-                                               if (e.keyCode == SWT.CR) {\r
-                                                       setText(element, text.getText());\r
-                                                       shell.dispose();\r
-                                                       shell = null;\r
-                                               }\r
-                                       }\r
-                               });\r
-                               shell.pack();\r
-                               shell.setVisible(true);\r
-                               shell.setLocation(x, y-32);\r
-                               \r
-                       }\r
-               });\r
-               \r
-       }\r
-       \r
-       @Override\r
-       public void hideTooltip(IElement element) {\r
-               if (shell == null)\r
-                       return;\r
-               Display.getDefault().asyncExec(new Runnable() {\r
-                       @Override\r
-                       public void run() {\r
-                               shell.dispose();\r
-                               shell = null;\r
-\r
-                       }\r
-               });\r
-       }\r
-       \r
-       public void focus() {\r
-               Display.getDefault().asyncExec(new Runnable() {\r
-                       @Override\r
-                       public void run() {\r
-                               if (!shell.isDisposed())\r
-                                       shell.forceFocus();\r
-                       }\r
-               });\r
-       }\r
-       boolean has_focus = false;\r
-       \r
-       @Override\r
-       public boolean hasFocus() {\r
-               \r
-               Display.getDefault().syncExec(new Runnable() {\r
-                       \r
-                       @Override\r
-                       public void run() {\r
-                               if(shell != null && !shell.isDisposed())\r
-                                       has_focus = shell.isFocusControl() || text.isFocusControl();\r
-                               \r
-                               else\r
-                                       has_focus = false;\r
-                               \r
-                       }\r
-               });\r
-               return has_focus;\r
-       }\r
-       \r
-       public abstract String getTooltipText(IElement element);\r
-       \r
-       public abstract void setText(IElement element, String text);\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.g2d.tooltip;
+
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.simantics.g2d.element.IElement;
+
+public abstract class EditableTextTooltipProvider2 implements FocusableTooltipProvider {
+       
+       private Shell shell;
+       private Text text;
+       
+       @Override
+       public void showTooltip(final IElement element, final int x, final int y) {
+               Display.getDefault().asyncExec(new Runnable() {
+                       @Override
+                       public void run() {
+                               if (shell != null) {
+                                       shell.dispose();
+                                       shell = null;
+                               }
+                               shell = new Shell(Display.getCurrent().getActiveShell(),SWT.NO_TRIM);
+                               shell.setLayout(new FillLayout());
+                               Composite composite = new Composite(shell, SWT.BORDER);
+                               composite.setLayout(new FillLayout(SWT.VERTICAL));
+                               Label label = new Label(composite,SWT.NONE);
+                               label.setText("Press 'F9' to focus");
+                               text = new Text(composite, SWT.SINGLE);
+                               text.setText(getTooltipText(element));
+                               text.addKeyListener(new KeyAdapter() {
+                                       @Override
+                                       public void keyReleased(KeyEvent e) {
+                                               if (e.keyCode == SWT.CR) {
+                                                       setText(element, text.getText());
+                                                       shell.dispose();
+                                                       shell = null;
+                                               }
+                                       }
+                               });
+                               shell.pack();
+                               shell.setVisible(true);
+                               shell.setLocation(x, y-32);
+                               
+                       }
+               });
+               
+       }
+       
+       @Override
+       public void hideTooltip(IElement element) {
+               if (shell == null)
+                       return;
+               Display.getDefault().asyncExec(new Runnable() {
+                       @Override
+                       public void run() {
+                               shell.dispose();
+                               shell = null;
+
+                       }
+               });
+       }
+       
+       public void focus() {
+               Display.getDefault().asyncExec(new Runnable() {
+                       @Override
+                       public void run() {
+                               if (!shell.isDisposed())
+                                       shell.forceFocus();
+                       }
+               });
+       }
+       boolean has_focus = false;
+       
+       @Override
+       public boolean hasFocus() {
+               
+               Display.getDefault().syncExec(new Runnable() {
+                       
+                       @Override
+                       public void run() {
+                               if(shell != null && !shell.isDisposed())
+                                       has_focus = shell.isFocusControl() || text.isFocusControl();
+                               
+                               else
+                                       has_focus = false;
+                               
+                       }
+               });
+               return has_focus;
+       }
+       
+       public abstract String getTooltipText(IElement element);
+       
+       public abstract void setText(IElement element, String text);
+
+}