I am working on an application with a node subclass of GoIconicNode that has multiple ports subclassed from GoPort (the resulting node is a GoGroup). I have two different screen modes where the nodes need to be displayed - view and edit. In view mode I need to display only ports with links while in edit mode I need to display all ports that can accept links. As such, I would like to be able to maintain all ports from all nodes in a single ArrayList and then loop through the array to change visibility (or color) when switching between view and edit modes. I have seen the Go documentation that states that an object’s Pen should not be manipulated once assigned and so have been trying to loop through a port ArrayList and assign a new pen with a different color (LightGray in edit mode and Empty in view mode) to each port when switching modes. This, however, has not worked as expected since assigning a new pen to the ports in the ArrayList is not consistently changing their colors.
I am wondering if you have a suggestion for the best way to achieve my goal or know why looping through the ArrayList is not working.
Hmmm. Are you saying that it sometimes works for some ports but not others? Are you sure that your ArrayList of ports is correct?
I would do something like:
foreach (GoObject obj in myDocument) {
IGoNode node = obj as IGoNode;
if (node != null) {
foreach (IGoPort port in node) {
AppPort p = port.GoObject as AppPort;
if (p != null) {
if (VIEWMODE) {
p.Visible = (p.LinksCount > 0);
} else {
p.Visible = p.CanAcceptLinks();
}
}
}
}
}
The Processor example does something similar, except looking for links instead of ports, in ProcessDocument.SetLinkPen.