Hello i tried to copy some device wich is (or gate, and gate) and the wire between them, when I pasted this devices I could not connect between the new devices; each device has 3 ports( 2 input and 1 output),
public Vector CopyDevice = new Vector(); public Vector CopyConnectors = new Vector();
public void Copy() { CopyDevice.removeAllElements(); for(int i=0; i< canvas.devices.size();i++)
//Create new ANDGate ANDGate and = new ANDGate(canvas, p); // and.onePortSetAlready=((ANDGate)CopyDevice).onePortSetAlready; canvas.devices.addElement((Device)and); break; }
//********************* Connector Class has this important things
Point start; Point end;
protected Port[] ports;
public Connector(GateCanvas canvas, Point p){ start = p; this.canvas = canvas; ports = new Port[2]; }
/* Because at first the two ends of the connector are the same point, there is no need * to draw them, they are just set instead */ public void draw(Point p) { start = p; end = p; }
//Adds given port to its list of ports public void addPort(Port p){ if (ports[0] == null){ports[0] = p;} else if (ports[1] == null){ ports[1] = p;} }
/* Checks if it is possible to add a port. only true if there are no ports added yet, * or if there is only one port added and it is not of the same type of the given port. * (So it is not possible to connect two output ports for example) */ public boolean canAddPort(Port p){ if (ports[0] != null && ports[1] != null){return false;} else if (ports[0].getType() != p.getType()){return true;} else return false; }
}
//******************** the Port Class has this important things
//Type of port: either input or output. protected String type; protected Point upperLeft; protected Connector connector;
//Indicates wether this is the first port set by connector or not //Useful when moveing the connected with the port when it moves boolean firstPortSet;
//Device the port is attached to. protected Device device;
//Constructor public Port(GateCanvas canvas, String t){ this.canvas = canvas; type = t; }
//A port accepts connections if is not attached to a connector and the mouse pointer resides in it. public boolean canConnect(Point p){}
//Checks whether the given point is inside the port or not public boolean inPort(Point p){}
//Sets the connector to be the one given and adds itself to it. public void setConnector(Connector c, boolean firstPortSet){ connector = c; this.firstPortSet = firstPortSet; connector.addPort(this); }
//Sets the device attached to it public void setDevice(Device d){ device = d; }