import java.awt.*; import java.awt.geom.*; /** * An edge type representing a link in a network. * * This class adds a new edge approval method that is used to * check network constraints before adding edges. * * @author Eric Lemar */ public class NetworkEdge extends LineEdge { public NetworkEdge() { super(); } /** * Try to add this edge between nodes aStart and aEnd * * To add a connection, both nodes must be of type NetworkNode, and the * Node.isConnectOk(Edge,otherNode) method must return * true for each side. * * @param aStart The starting node * @param anEnd The ending node * @return true if the edge was added, false * otherwise. */ public boolean approvedConnect(Node aStart, Node anEnd) { if (aStart instanceof NetworkNode && anEnd instanceof NetworkNode) { NetworkNode n1,n2; n1 = (NetworkNode)aStart; n2 = (NetworkNode)anEnd; if (n1.isOkConnect(this,n2) && n2.isOkConnect(this,n1)) { connect(aStart,anEnd); n1.addedEdge(this,n2); n2.addedEdge(this,n1); return true; } } return false; } /** * Tell the edge that it is being removed. * * This gives the edge the chance to tell the nodes that the edge is being * removed. It does so by calling signalRemove(this) on each end end. */ public void signalRemove() { NetworkNode n1,n2; n1 = (NetworkNode)getStart(); n2 = (NetworkNode)getEnd(); n1.signalRemove(this); n2.signalRemove(this); } }