// File: FigBentLine.java // Classes: FigBentLine // Original Author: Kedar Patankar package edu.neu.ccs.demeter.tools.apstudio.graphedit; import java.awt.Color; import java.awt.Rectangle; import java.awt.Point; import java.awt.Graphics; import java.util.Hashtable; /** Class to implement bent lines when drawing the edges. */ public class FigBentLine extends DiagramElement { public static final int FUDGE_FACTOR = 4; private Point firstEnd,bendPoint,secondEnd; /** Construct a new FigLine with the given coordinates and color. */ public FigBentLine(int x1,int y1) { firstEnd = new Point(x1,y1); bendPoint=null; secondEnd=new Point (x1,y1); } public void setBendPoint(int x,int y) { bendPoint = new Point(x,y); } public Point getBendPoint() { return bendPoint; } public void createDrag(int x, int y) { secondEnd.x = x; secondEnd.y = y; } /** draw this line object */ public void draw(Graphics g) { g.setColor(Color.black); if(bendPoint==null) g.drawLine(firstEnd.x, firstEnd.y, secondEnd.x,secondEnd.y); else { g.drawLine(firstEnd.x, firstEnd.y, bendPoint.x,bendPoint.y); g.drawLine(bendPoint.x,bendPoint.y, secondEnd.x,secondEnd.y); } } /** Reply a rect that encloses this line. I add a few pixels on * either side so that the rect will have non-zero area. */ public Rectangle getBoundingBox() { Point p = secondEnd; Point b = bendPoint; Point q = firstEnd; if(b!=null) { int x1 = Math.min(p.x,b.x); x1=Math.min(x1,q.x); int y1 = Math.min(p.y,b.y); y1=Math.min(y1,q.y); int x2 = Math.max(p.x,b.x); x2=Math.max(x2,q.x); int y2 = Math.max(p.y,b.y); y2=Math.max(y2,q.y); return new Rectangle(x1 - 1 , y1 -1 , x2 - x1 +2 , y2 - y1 +2); } else { return new Rectangle(Math.min(p.x, q.x) - 1, Math.min(p.y, q.y) - 1, Math.max(p.x, q.x) - Math.min(p.x, q.y) + 2, Math.max(p.y, q.x) - Math.min(p.y, q.y) + 2); } } // Following methods are meaningless but required since DiagramElement defines them as abstract methods public void drawSelected(Graphics g) {} public Selection selectionObject() { return null; } public void setGraphicAttribute(String k, Object v) {} } /* end class FigBentLine */