package implementation.source.java.nodes; import java.awt.BasicStroke; import java.awt.Color; import java.awt.Shape; import java.awt.Stroke; import java.awt.geom.Ellipse2D; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import edu.umd.cs.piccolo.PNode; /** * @author Timothy Ober */ public class DFNode extends DFEndpoint { public static final int DEFAULT_SIZE = 50; static final Shape DEFAULT_SHAPE = new Ellipse2D.Double(100, 100, DEFAULT_SIZE, DEFAULT_SIZE); static final Stroke DEFAULT_STROKE = new BasicStroke(); ArrayList edgesIn; ArrayList edgesOut; ArrayList portsIn; ArrayList portsOut; DFLabel label; /** * */ public DFNode(double x, double y) { this(x, y, DEFAULT_SHAPE, DEFAULT_STROKE); } /** * @param arg0 */ public DFNode(double x, double y, Shape arg0) { this(x, y, arg0, DEFAULT_STROKE); } /** * @param arg0 * @param arg1 */ public DFNode(double x, double y, Shape arg0, Stroke arg1) { super(arg0, arg1); setX(x - getWidth() / 2); setY(y - getHeight() / 2); edgesIn = new ArrayList(); edgesOut = new ArrayList(); portsIn = new ArrayList(); portsOut = new ArrayList(); label = new DFLabel("New Node"); setPaint(Color.WHITE); centerLabel(); addChild(label); } public DFNode(DFNode n) { super(n.getPathReference(), n.getStroke()); setX(n.getX() - n.getWidth() / 2); setY(n.getY() - n.getHeight() / 2); edgesIn = (ArrayList)n.getEdgesIn().clone(); edgesOut = (ArrayList)n.getEdgesOut().clone(); portsIn = (ArrayList)n.getPortsIn().clone(); portsOut = (ArrayList)n.getPortsOut().clone(); label = new DFLabel(n.getLabel()); setPaint(Color.WHITE); centerLabel(); addChild(label); } public void showLabel(boolean show) { if (show) { if (!getChildrenReference().contains(label)) { addChild(label); } } else { if (getChildrenReference().contains(label)) { removeChild(label); } } } public String getLabel() { return label.getText(); } public void updateChildren(double x, double y) { Collection c = getAllNodes(); Iterator i; PNode n; c.remove(this); c.remove(label); for (i = c.iterator(); i.hasNext(); ) { n = (PNode)i.next(); n.setX(n.getX() + x); n.setY(n.getY() + y); } label.setX(label.getX() + x); label.setY(label.getY() + y); } public ArrayList getEdgesIn() {return edgesIn;} public ArrayList getEdgesOut() {return edgesOut;} public ArrayList getPortsIn() {return portsIn;} public ArrayList getPortsOut() {return portsOut;} public void addInputPort() { portsIn.add(new DFInputPort(this)); } public void addOutputPort() { portsOut.add(new DFOutputPort(this)); } private void centerLabel() { label.setX(getX() - (label.getWidth() / 2) + (getWidth() / 2)); label.setY(getY() - (label.getHeight() / 2) + (getHeight() / 2)); } }