// Copyright (c) 1995, 1996 Regents of the University of California. // All rights reserved. // // This software was developed by the Arcadia project // at the University of California, Irvine. // // Redistribution and use in source and binary forms are permitted // provided that the above copyright notice and this paragraph are // duplicated in all such forms and that any documentation, // advertising materials, and other materials related to such // distribution and use acknowledge that the software was developed // by the University of California, Irvine. The name of the // University may not be used to endorse or promote products derived // from this software without specific prior written permission. // THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR // IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED // WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. // File: ArcPerspective.java // Classes: ArcPerspective // Original Author: Jason Robbins Modification : Kedar Patankar + Alberto Medina // $Id: ArcPerspective.java,v 1.1.1.1 1997/02/27 20:52:27 chandra Exp $ package uci.graphedit; import java.awt.Rectangle; import java.awt.Color; import java.awt.Graphics; import java.awt.Point; /** A DiagramElement that draws arcs between two vertices.*/ public class ArcPerspective extends DiagramElement { private Perspective _sourcePerspective; private Perspective _destPerspective; private Fig _edge; private NetArc parentArc; public ArcPerspective(NetArc a) { _sourcePerspective = a.destNode().get_Perspective(); _destPerspective = a.sourceNode().get_Perspective(); _edge=new FigAltEdge(1,1,1,1,Color.black); owner(a); a.set_perspective(this); } public ArcPerspective(NetArc a,String edgeLabel,String cardinality) { _sourcePerspective = a.sourceNode().get_Perspective(); _destPerspective = a.destNode().get_Perspective(); _edge = new FigConstEdge(1,1,1,1,Color.black,edgeLabel,cardinality); owner(a); a.set_perspective(this); } public void owner(NetArc n){parentArc=n;} public Object owner(){return parentArc;} /** Return the figure held by this perspective */ public Fig get_figure(){ return _edge;} /** Draw this object. * @see DiagramElement#drawSelected */ public void draw(Graphics g) { g.setColor(Color.black); drawArc(g); } /** Draw this object when the user has selected it. * @see DiagramElement#drawSelected */ public void drawSelected(Graphics g) { drawSelectedArc(g,Globals.prefs().handleColor()); } /** reply the bounding box for this arc. * @see DiagramElement#getBoundingBox */ public Rectangle getBoundingBox() { Rectangle bbox = null; bbox=_edge.getBoundingBox(); return bbox; } public boolean inside(int x, int y) { if(_edge.inside(x,y)) return true; return false; } /** reply true iff this arc intersects the given rectangle. * @see DiagramElement#intersects */ public boolean intersects(Rectangle rect) { if (_edge.intersects(rect)) return true; return false; } public void dispose(Document ed) { ((NetArc)owner()).dispose(); super.dispose(ed); } /** find the route that the arc should follow. Basically case * analysis to route around source and destination nodes.

* needs-more-work: a better algorithm would really be useful. */ protected void computeRoute() { Point srcPt = _sourcePerspective.center(); Point dstPt = _destPerspective.center(); _edge.set_position(srcPt,dstPt); } /* end computeRoute */ void drawSelectedArc(Graphics g, Color l_color) { computeRoute(); Point destDimension=_destPerspective.get_dimensions(); Point sourceDimension=_sourcePerspective.get_dimensions(); _edge.draw(g,l_color,sourceDimension,destDimension); } /** Draw the arc */ void drawArc(Graphics g) { computeRoute(); Point destDimension=_destPerspective.get_dimensions(); Point sourceDimension=_sourcePerspective.get_dimensions(); _edge.draw(g,sourceDimension,destDimension); } /** 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 setGraphicAttribute(String k, Object v) { } } /* end class ArcPerspective */