// 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: Perspective.java // Classes: Perspective // Original Author: ics125b spring 1996 // Modifications By : Kedar Patankar // Date 23 Jan 1997 package uci.graphedit; import java.awt.Rectangle; import java.awt.Point; import java.awt.Graphics; import java.util.Observable; import java.util.Vector; import java.util.Enumeration; /** Class to display graphics for NetNode's */ public class Perspective extends DiagramElement { /** when the Perspective is selected, how close should the selection * box be to the Perspective's bbox. Needs-More-Work: this shuold be * in SelectionBox. */ private static final int BORDER_WIDTH = 10; /** The NetNode that is being displayed */ public NetNode parentNode; /** The Fig's that make up the look of this Perspective */ private Fig _fig; /** True when we want to draw the user's attention to this * Perspective */ boolean _highlight = false; /** Constructs a new Perspective on the given NetNode with the * given Fig's. */ public Perspective(NetNode parent_node, Fig fig) { _fig=fig; parentNode = parent_node; parentNode.addObserver(this); } /** Replys a rectangle that bounds all the Fig's in this perspective*/ public Rectangle getBoundingBox() { return _fig.getBoundingBox(); } /** Move the Perspective to the given position. */ /* public void position(int x,int y) { int dx = x - position().x; int dy = y - position().y; translate(dx, dy); }*/ /** Move the Perspective by the given amount */ void translate(int dx,int dy) { position().x += dx; position().y += dy; _fig.translate(dx,dy); } protected Vector arcPerspectives(Document ed) { Vector arcPerspectives = new Vector(); Enumeration arcs = parentNode.inArcList.elements(); while (arcs.hasMoreElements()) { DiagramElement de = ((NetArc) arcs.nextElement()).get_perspective(); arcPerspectives.addElement(de); } arcs = parentNode.outArcList.elements(); while (arcs.hasMoreElements()) { DiagramElement de = ((NetArc) arcs.nextElement()).get_perspective(); arcPerspectives.addElement(de); } return arcPerspectives; } /** When a Perspective is damaged, all of its arcs may need * redrawing. */ public void damagedIn(Document ed) { Enumeration arcPers = arcPerspectives(ed).elements(); while (arcPers.hasMoreElements()) { DiagramElement de = (DiagramElement) arcPers.nextElement(); de.damagedIn(ed); } super.damagedIn(ed); } /** When a Perspective is removed, dispose all of the NetArcs and * the underlying NetNode. Needs-More-Work: is this right? Doesn't * ActionDelete call this method also? How is deletion of a * Perspective handled without disposing the underlying model? */ public void removeFrom(Document ed) { Enumeration arcPers = arcPerspectives(ed).elements(); while (arcPers.hasMoreElements()) { DiagramElement de = (DiagramElement) arcPers.nextElement(); de.dispose(ed); } if (parentNode != null) parentNode.dispose(); super.removeFrom(ed); parentNode = null; } /** The owner of a Perspective is an underlying NetNode */ public Object owner() { return parentNode; } /** Reply the dimensions of the FigRect which is the first figure added to FigList*/ // public Object get_first(){ return _fig;} public Fig get_first(){ return _fig;} public Point get_dimensions(){ return _fig.get_dimensions();} /** Reply true iff the point lies within any of the Fig's in the * perspective. */ public boolean inside(int x, int y) { return (_fig.inside(x, y)); } public boolean hasId(int id) { if( ((NetNode)owner()).getId()==id) return true; return false; } /** Reply true iff this Perspective intersects the given Rectangle */ public boolean intersects(Rectangle rct) { return getBoundingBox().intersects(rct); } /** Reply the NetNode associated with the Fig under the mouse, or * null if there is none. */ public final NetNode pickNode(Point p) { return pickNode(p.x, p.y); } public NetNode pickNode(int x, int y) { boolean ret=_fig.inside(x,y); if(ret) return (NetNode)owner(); else return null; } /** Draws the perspective to the given Graphics */ public void draw(Graphics g) { Rectangle clip = g.getClipRect(); Rectangle bbox = getBoundingBox(); if (clip == null || bbox.intersects(clip)) { _fig.draw(g); } if (_highlight) { g.setColor(Globals.prefs().highlightColor()); /* needs-more-work */ g.drawRect(bbox.x-3, bbox.y-3, bbox.width+6, bbox.height+6); g.drawRect(bbox.x-4, bbox.y-4, bbox.width+8, bbox.height+8); } } /** Needs-More-Work: remove this, its logic has been moved to * SelectionBox. */ public void drawSelected(Graphics g) { } /** When a Perspective is selected the Editor should record that * fact in an instance of SelectionBox. */ public Selection selectionObject() { return new SelectionBox(this); } /** If I get a notification that I shuold be Highlighted or * Unhighlight, set a flag and mark my area as damaged. */ public void update(Observable o, Object arg) { if (arg.equals("Highlight")) { startTrans(); _highlight = true; endTrans(); } else if (arg.equals("Unhighlight")) { startTrans(); _highlight = false; endTrans(); } } // Pratima R Kayiti**** PRK **** public void setGraphicAttribute(String k, Object v){ } } /* end class Perspective */