// Copyright (c) 1996-98 The Regents of the University of California. All // Rights Reserved. Permission to use, copy, modify, and distribute this // software and its documentation for educational, research and non-profit // purposes, without fee, and without a written agreement is hereby granted, // provided that the above copyright notice and this paragraph appear in all // copies. Permission to incorporate this software into commercial products may // be obtained by contacting the University of California. David F. Redmiles // Department of Information and Computer Science (ICS) University of // California Irvine, California 92697-3425 Phone: 714-824-3823. This software // program and documentation are copyrighted by The Regents of the University // of California. The software program and documentation are supplied "as is", // without any accompanying services from The Regents. The Regents do not // warrant that the operation of the program will be uninterrupted or // error-free. The end-user understands that the program was developed for // research purposes and is advised not to rely exclusively on the program for // any reason. IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY // PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, // INCLUDING LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS // DOCUMENTATION, EVEN IF THE UNIVERSITY OF CALIFORNIA HAS BEEN ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. THE UNIVERSITY OF CALIFORNIA SPECIFICALLY // DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE // SOFTWARE PROVIDED HEREUNDER IS ON AN "AS IS" BASIS, AND THE UNIVERSITY OF // CALIFORNIA HAS NO OBLIGATIONS TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, // ENHANCEMENTS, OR MODIFICATIONS. // File: NetArc.java // Classes: NetArc // Original Author: ics125b spring 1996 // $Id: NetArc.java,v 1.14 1997/06/10 23:43:15 jrobbins Exp $ package uci.graphedit; import java.awt.*; import java.io.*; import java.util.*; /** This class models an arc in our underlying connected graph model. * * FEATURE: graph_representation_arcs */ public abstract class NetArc extends NetPrimitive { //////////////////////////////////////////////////////////////// // instance variables /** The start and end ports of this arc. */ private NetPort _sourcePort; private NetPort _destPort; //////////////////////////////////////////////////////////////// // constructors /** Construct a new NetArc */ public NetArc() { } //////////////////////////////////////////////////////////////// // accessors public void sourcePort(NetPort s) { _sourcePort = s; } public NetPort sourcePort() { return _sourcePort; } public void destPort(NetPort d) { _destPort = d; } public NetPort destPort() { return _destPort; } public NetPort otherEnd(NetPort oneEnd) { NetPort sp = sourcePort(); if (sp == oneEnd) { return destPort(); } else { return sp; } } //////////////////////////////////////////////////////////////// // net-level hooks /** Connect the source and destination ports, iff they agree to * being connected (i.e., canConnectTo() returns true). Reply true * on success. This method is noramlly called after a new arc * instance is made. Maybe this behavior should be in a constructor, * but I want to use Class#newInstancel so constructors do not get * any arguments. */ public boolean connect(NetPort s, NetPort d) { if (s.canConnectTo(d) && d.canConnectTo(s)) { sourcePort(s); destPort(d); s.addArc(this); d.addArc(this); s.postConnect(d); d.postConnect(s); return true; } return false; } //////////////////////////////////////////////////////////////// // Editor API /** Remove this NetArc from the underlying connected graph model. */ public void dispose() { System.out.println("disposing: " + toString()); if (sourcePort() != null && destPort() != null) { _sourcePort.removeArc(this); _destPort.removeArc(this); // needs-more-work: assumes no parallel arcs! _sourcePort.postDisconnect(destPort()); _destPort.postDisconnect(sourcePort()); Vector v = new Vector(2); v.addElement(Globals.REMOVE); v.addElement(this); setChanged(); System.out.println("NetArc notifying:" + toString()); notifyObservers(v); } } //////////////////////////////////////////////////////////////// // diagram-level operations /** The perspective to use in views of a given type */ public ArcPerspective perspectiveFor(Layer lay) { NetNode sourceNode = _sourcePort.parentNode(); NetNode destNode = _destPort.parentNode(); Perspective sourcePerspective = sourceNode.perspectiveFor(lay); Perspective destPerspective = destNode.perspectiveFor(lay); Fig sourcePortFig = sourcePerspective.getPortFig(_sourcePort); Fig destPortFig = destPerspective.getPortFig(_destPort); ArcPerspective ap = makePerspective(lay); ap.sourcePortFig(sourcePortFig); ap.destPortFig(destPortFig); ap.sourcePerspective(sourcePerspective); ap.destPerspective(destPerspective); ap.owner(this); return ap; } /** Override this method if you want your Arc subclasses to have a * different look. */ public abstract ArcPerspective makePerspective(Layer lay); } /* end class NetArc */