1 /*******************************************************************************
2 * Copyright (c) 2007, 2010 Association for Decentralized Information Management
4 * All rights reserved. This program and the accompanying materials
5 * are made available under the terms of the Eclipse Public License v1.0
6 * which accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.g2d.tooltip;
14 import java.awt.geom.Point2D;
16 import org.simantics.g2d.canvas.impl.DependencyReflection.Dependency;
17 import org.simantics.g2d.diagram.participant.pointertool.PointerInteractor;
18 import org.simantics.g2d.diagram.participant.pointertool.TerminalUtil.TerminalInfo;
19 import org.simantics.g2d.element.ElementHints;
20 import org.simantics.g2d.element.handler.TerminalData;
21 import org.simantics.scenegraph.g2d.events.EventHandlerReflection.EventHandler;
22 import org.simantics.scenegraph.g2d.events.MouseEvent.MouseMovedEvent;
23 import org.simantics.utils.datastructures.hints.IHintContext.Key;
24 import org.simantics.utils.datastructures.hints.IHintContext.KeyOf;
28 * TooltipParticipan that is able to show terminal tooltips
30 * Note: this participant does not co-operate with TooltipParticipant.
33 * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
36 public class TerminalTooltipParticipant extends BaseTooltipParticipant {
38 public static final Key KEY_TOOLTIP_TEXT = new KeyOf(String.class, "TERMINAL_TOOLTIP_TEXT");
40 @Dependency PointerInteractor interactor;
42 @EventHandler(priority = 0)
43 public boolean handleMove(MouseMovedEvent me) {
44 update(me.controlPosition);
48 private void update(Point2D controlPos) {
49 TerminalInfo info = interactor.pickTerminal(controlPos);
52 TerminalData data = info.e.getElementClass().getAtMostOneItemOfClass(TerminalData.class);
56 String text = data.getHint(info.e, info.t, ElementHints.KEY_TEXT);
57 // this is not a really good way to provide terminal name
58 info.e.setHint(KEY_TOOLTIP_TEXT, text);
59 showTooltipFor(info.e);