--- /dev/null
+/*******************************************************************************\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