]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.g2d/src/org/simantics/g2d/tooltip/TerminalTooltipParticipant.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / tooltip / TerminalTooltipParticipant.java
diff --git a/bundles/org.simantics.g2d/src/org/simantics/g2d/tooltip/TerminalTooltipParticipant.java b/bundles/org.simantics.g2d/src/org/simantics/g2d/tooltip/TerminalTooltipParticipant.java
new file mode 100644 (file)
index 0000000..a5b8447
--- /dev/null
@@ -0,0 +1,64 @@
+/*******************************************************************************\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
+import java.awt.geom.Point2D;\r
+\r
+import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency;\r
+import org.simantics.g2d.diagram.participant.pointertool.PointerInteractor;\r
+import org.simantics.g2d.diagram.participant.pointertool.TerminalUtil.TerminalInfo;\r
+import org.simantics.g2d.element.ElementHints;\r
+import org.simantics.g2d.element.handler.TerminalData;\r
+import org.simantics.scenegraph.g2d.events.EventHandlerReflection.EventHandler;\r
+import org.simantics.scenegraph.g2d.events.MouseEvent.MouseMovedEvent;\r
+import org.simantics.utils.datastructures.hints.IHintContext.Key;\r
+import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;\r
+\r
+\r
+/**\r
+ * TooltipParticipan that is able to show terminal tooltips\r
+ * \r
+ * Note: this participant does not co-operate with TooltipParticipant.\r
+ * \r
+ * \r
+ * @author Marko Luukkainen <marko.luukkainen@vtt.fi>\r
+ *\r
+ */\r
+public class TerminalTooltipParticipant extends BaseTooltipParticipant {\r
+\r
+    public static final Key KEY_TOOLTIP_TEXT = new KeyOf(String.class, "TERMINAL_TOOLTIP_TEXT");\r
+\r
+    @Dependency PointerInteractor interactor;\r
+\r
+    @EventHandler(priority = 0)\r
+    public boolean handleMove(MouseMovedEvent me) {\r
+        update(me.controlPosition);\r
+        return false;\r
+    }\r
+\r
+    private void update(Point2D controlPos) {\r
+        TerminalInfo info = interactor.pickTerminal(controlPos);\r
+\r
+        if (info != null) {\r
+            TerminalData data = info.e.getElementClass().getAtMostOneItemOfClass(TerminalData.class);\r
+            if (data == null)\r
+                return;\r
+\r
+            String text = data.getHint(info.e, info.t, ElementHints.KEY_TEXT);\r
+            // this is not a really good way to provide terminal name\r
+            info.e.setHint(KEY_TOOLTIP_TEXT, text);\r
+            showTooltipFor(info.e);\r
+        } else\r
+            hideTooltip();\r
+    }\r
+\r
+}\r