User-Controlled Tree Edges
I've devised a custom tree user interface using Swing and I'm at the point where I want to implement the connection lines or "edges" between nodes.
As a test, I hard coded the tree's structure, defining the relationships of the nodes, and then on the parent JPanel that houses the nodes I drew the
lines between the nodes in paintComponent(). This works as I expected but obviously doesn't allow the user to define the tree structure.
So what I think I need to do is define a class called Connector that subclasses JPanel. This class will draw a line from its top-left corner to its
bottom-right corner. Each node will need to have a collection of these Connector objects, and then update each Connector's bounds when the Node
is moved or when the node's child is moved. This Connector class will implement MouseListener and MouseMotionListener so its "loose" end can be
dragged and then the Connector's bounds will be updated.
The black arrows would be the Connectors. If the tail/nose of the Connector is dragged and released on top of a node then that end of the Connector
should be forever "parented" to the new node, even when the new node is moved/resized.
When a node is clicked it is brought to the "front", meaning all other nodes are now below it in Z order. The Connectors of a selected node should
also be brought to the front.
This approach seems awfully complicated and I'm very eager to hear a different approach and/or
suggestions for my approach. Thanks.