package MaxFlowApplet.graphic; import MaxFlowApplet.graph.*; import java.awt.*; /* The class extends the FlowVretex class with functions for drawing * * the vertex. A vertex is represented as a 3D rectangular, that * * seems as a button, and may be drawn as pushed or released in diff-* * erent locations, colors and sizes (not all the options are used * * as present). */ public class GraphicVertex extends FlowVertex { public GraphicVertex(int x, int y) { base = new Point(x - sideLength/2, y - sideLength/2); center = new Point(x, y); pressed = false; color = DEFAULTCOLOR; } public void setColor(Color newColor) { color = newColor; }; public Color getColor() { return color; }; public Point getPosition() { return center; }; public int getSideLength() { return sideLength; }; public void setSideLength(int n) { sideLength = n; }; public boolean isPressed() { return pressed; }; public void release() { pressed = false; } public void press() { pressed = true; }; public boolean inside(int x, int y) { return (base.x <= x && base.x+sideLength >= x && base.y <= y && base.y+sideLength >= y); } public void moveTo(int x, int y) { center = new Point(x,y); base.x = center.x - (sideLength / 2); base.y = center.y - (sideLength / 2); }; protected void updateEdges() { Edge e; int n; n = fanOut(); for(int i = 0; i < n; i++) ((GraphicEdge) getEdgeOut(i)).updateArrowLocation(); n = fanIn(); for(int i = 0; i < n; i++) ((GraphicEdge) getEdgeIn(i)).updateArrowLocation(); } /* In some situations, a vertex have to remember some position, * * in order to go back to it later. The next two methods does that */ public void storeOriginalPosition() { originalPosition = new Point(center.x, center.y); } public void moveToOriginalPosition() { moveTo(originalPosition.x, originalPosition.y); } public void draw(Graphics g) { g.setColor(color); g.fill3DRect( base.x, base.y, sideLength, sideLength, !pressed); } protected Point base; protected Color color; protected Point center; protected Point originalPosition; protected int sideLength = 15; protected boolean pressed = false; protected static final Color DEFAULTCOLOR = Color.gray; };