Tool Tip while Link being positioned


#1

My users are trying to link two nodes together by their ports. They hover over the ports in the first node to see the tool tip. Once they find the port that they want, they click and drag to the other node. The trouble is the other node has more than one port and now the tool tip doesn’t come up.
There doesn’t seem to be any event that fires when the link snaps to a port, so I’ve been focusing on trying to add some flags to the MouseDown and MouseMove events to try and figure out A) if the user is creating a link and B) if that link has a ToPort that is different than the last Mouse Move. Needless to say, since the link isn’t created yet, getting this info is tough. Any suggestions?


#2

You need to modify the behavior of the linking tool. Look at the modified/derived linking tool in the Demo1 sample. Instead of modifying the appearance of the proposed port, you can do something else, such as display a Tooltip.
[Serializable]
public class GraphViewLinkingNewTool : GoToolLinkingNew {
public GraphViewLinkingNewTool(GoView v) : base(v) {}
public override IGoPort PickNearestPort(PointF dc) {
IGoPort iport = base.PickNearestPort(dc);
if (this.EndPort != null && this.EndPort.GoObject is GoPort) {
if (iport != null) {
myLastNearestPort = (GoPort)this.EndPort.GoObject;
myLastNearestPort.Style = GoPortStyle.Rectangle;
myLastNearestPort.Pen = ((GraphView)this.View).PortHighlightPen;
myLastNearestPort.Brush = ((GraphView)this.View).PortHighlightBrush;
} else if (myLastNearestPort != null) {
myLastNearestPort.Style = GoPortStyle.None;
myLastNearestPort = null;
}
}
return iport;
}
public override void Stop() {
base.Stop();
if (myLastNearestPort != null) {
myLastNearestPort.Style = GoPortStyle.None;
myLastNearestPort = null;
}
}
private GoPort myLastNearestPort = null;
}
Remember to replace the standard linking too with your customized one by doing:
goView1.ReplaceMouseTool(typeof(GoToolLinkingNew), new GraphViewLinkingNewTool(goView1));


#3

That’s great stuff, Walter. Thanks!
I’m trying to get the caption into a tool tip now and I’ve noticed something interesting. The line:
(GoPort)this.EndPort.GoObject
when viewed in the Watch shows as a GoTemporaryPort class which has a member called Target. This target is pointing to an instance of my class: ProPort (inherits from GoGeneralNodePort) and it contains the text that I want in the caption. The trouble now is that GoTemporaryPort is a protected class and I am unable to cast it as such. GoPort has no such member Target.
The brute force way is search the document for a ProPort with a matching position, but with the reference so close, I’m hoping that there is a more elegant way. Any suggestions?


#4

In the above code “iport” has the port in the document that is being proposed to be connected to, and is probably the ProPort you care about.
.StartPort, .EndPort, and .Link are the temporary ports and temporary link created when the GoToolLinkingNew tool starts, initialized by the StartNewLink method.
.OriginalStartPort refers to the document port that the link started at. The new link (if completed) will connect this port with the port found by PickNearestPort.