// 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: ArcPerspective.java // Classes: ArcPerspective // Original Author: jrobbins@ics.uci.edu // $Id: ArcPerspective.java,v 1.12 1997/06/10 23:42:31 jrobbins Exp $ package uci.graphedit; import java.util.*; import java.awt.*; import java.io.*; import uci.ui.IProps; import uci.util.*; /** A DiagramElement that draws arcs between ports. * * FEATURE: graph_visualization_arcs * * BUG: arc_translate */ public abstract class ArcPerspective extends DiagramElement { //////////////////////////////////////////////////////////////// // instance variables /** Fig presenting the NetArc's from NetPort . */ protected Fig _sourcePortFig; /** Fig presenting the NetArc's to NetPort. */ protected Fig _destPortFig; /** Perspective presenting the NetArc's from NetPort's parent NetNode. */ protected Perspective _sourcePerspective; /** Perspective presenting the NetArc's to NetPort's parent NetNode. */ protected Perspective _destPerspective; /** Fig that presents the NetArc. */ protected Fig _arcFig; //////////////////////////////////////////////////////////////// // constructors public ArcPerspective(Fig s, Fig d, Perspective sp, Perspective dp, NetArc a) { _sourcePortFig = s; _destPortFig = d; _sourcePerspective = sp; _destPerspective = dp; Rectangle bbox = getBoundingBox(); owner(a); _arcFig = makeArcFig(); } public ArcPerspective() { _arcFig = makeArcFig(); } protected abstract Fig makeArcFig(); //////////////////////////////////////////////////////////////// // accessors public void sourcePortFig(Fig fig) { _sourcePortFig = fig; } public void destPortFig(Fig fig) { _destPortFig = fig; } public void sourcePerspective(Perspective pers) {_sourcePerspective = pers; } public void destPerspective(Perspective pers) { _destPerspective = pers; } public void owner(Object own) { Object oldOwner = owner(); if (oldOwner != null && oldOwner instanceof Observable) { ((Observable)oldOwner).deleteObserver(this); } if (own instanceof Observable) { ((NetArc)own).addPersistantObserver(this); } super.owner(own); } public Object get(String key) { if (owner() instanceof IProps) { IProps node = (IProps) owner(); Object res = node.get(key); if (res != null) return res; } return super.get(key); } public boolean put(String key, Object value) { boolean res = false; if (owner() instanceof IProps) { IProps node = (IProps) owner(); if (node != null) res = node.put(key, value); } return res || super.put(key, value); } public Enumeration keysIn(String cat) { if (owner() instanceof IProps) { IProps node = (IProps) owner(); if (node != null) return new EnumerationComposite(node.keysIn(cat), super.keysIn(cat)); } return super.keysIn(cat); } public boolean canPut(String key) { if (owner() instanceof IProps) { IProps node = (IProps) owner(); if (node != null) return node.canPut(key); } return super.canPut(key); } //////////////////////////////////////////////////////////////// // Routing related methods protected void computeRoute() { } //////////////////////////////////////////////////////////////// // DiagramElement API /** Draw this object when the user has selected it. */ public void drawSelected(Graphics g) { _arcFig.drawSelected(g); } /** Reply the bounding box for this arc. */ public Rectangle getBoundingBox() { return _arcFig.getBoundingBox(); } /** Reply true iff this arc contains the given point. * @see DiagramElement#inside */ public boolean inside(int x, int y) { return _arcFig.inside(x, y); } /** Reply true iff this arc intersects the given rectangle. */ public boolean intersects(Rectangle r) { return _arcFig.intersects(r); } public void dispose(Editor ed) { System.out.println("disposing: " + toString()); ((NetArc)owner()).dispose(); super.dispose(ed); } public void removeFrom(Editor ed) { super.removeFrom(ed); owner(null); } //////////////////////////////////////////////////////////////// // drawing methods /** Draw this object. */ public void draw(Graphics g) { computeRoute(); g.setColor(Color.black); drawArc(g); } /** Draw the arc. */ protected void drawArc(Graphics g) { _arcFig.draw(g); } //////////////////////////////////////////////////////////////// // notifications and updates /** Reply a new selection object that can be used to manipulate this * object. For now, use SelectionHandles. Needs-More-Work: Users * should be able to adjust arcs by dragging on handles. */ public Selection selectionObject() { return new SelectionHandles(this); } public void update(Observable o, Object arg) { if (arg instanceof Vector) { Vector v = (Vector) arg; String s = (String) v.elementAt(0); Object obj = v.elementAt(1); if (s.equals(Globals.REMOVE) && obj == owner()) { removeFrom(null); } } } } /* end class ArcPerspective */