]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.g2d/src/org/simantics/g2d/tooltip/TerminalTooltipParticipant.java
G2DParentNode handles "undefined" child bounds separately
[simantics/platform.git] / bundles / org.simantics.g2d / src / org / simantics / g2d / tooltip / TerminalTooltipParticipant.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2010 Association for Decentralized Information Management
3  * in Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.g2d.tooltip;
13
14 import java.awt.geom.Point2D;
15
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;
25
26
27 /**
28  * TooltipParticipan that is able to show terminal tooltips
29  * 
30  * Note: this participant does not co-operate with TooltipParticipant.
31  * 
32  * 
33  * @author Marko Luukkainen <marko.luukkainen@vtt.fi>
34  *
35  */
36 public class TerminalTooltipParticipant extends BaseTooltipParticipant {
37
38     public static final Key KEY_TOOLTIP_TEXT = new KeyOf(String.class, "TERMINAL_TOOLTIP_TEXT");
39
40     @Dependency PointerInteractor interactor;
41
42     @EventHandler(priority = 0)
43     public boolean handleMove(MouseMovedEvent me) {
44         update(me.controlPosition);
45         return false;
46     }
47
48     private void update(Point2D controlPos) {
49         TerminalInfo info = interactor.pickTerminal(controlPos);
50
51         if (info != null) {
52             TerminalData data = info.e.getElementClass().getAtMostOneItemOfClass(TerminalData.class);
53             if (data == null)
54                 return;
55
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);
60         } else
61             hideTooltip();
62     }
63
64 }