
package tmcm.xLogicCircuits;

import java.awt.*;


class Tack extends IONub {
   Tack() {
      kind = TACK;
   }
   void draw(Graphics g) {
      if (selected) {
         g.setColor(Color.blue);
         g.fillOval(Math.round(boundingBox.x)-2, Math.round(boundingBox.y)-2, 
                               Math.round(boundingBox.width)+4, Math.round(boundingBox.height)+4);
      }
      if (source == null)
         g.setColor(lineDestinationColor);
      else
         g.setColor(lineSourceColor);
      g.fillOval(Math.round(boundingBox.x),Math.round(boundingBox.y),Math.round(boundingBox.width),Math.round(boundingBox.height));
   }
   CircuitItem copy() {  // copied without source and destination
      Tack it = new Tack();
      it.selected = selected;
      it.on = on;
      it.reshape(boundingBox.x,boundingBox.y,boundingBox.width,boundingBox.height);
      it.kind = kind;
      it.connect_x = connect_x;
      it.connect_y = connect_y;
      return it;
   }
   void reshape(float x, float y, float width, float height) { 
      boundingBox.reshape(x,y,width,height); 
      connect_x = Math.round(x)+2;
      connect_y = Math.round(y)+2;
      if (source != null)
         source.setBoundingBox();
      for (int i = 0; i < destination.size(); i++)
         ((Line)destination.elementAt(i)).setBoundingBox();
   }
   void delete(Circuit owner) {
     owner.items.removeElement(this);
     for (int i = 0; i < destination.size(); i++) {
        Line line = (Line)destination.elementAt(i);
        owner.lines.removeElement(line);
        line.destination.source = null;           
     }
     if (source != null) {
        owner.lines.removeElement(source);
        source.source.destination.removeElement(source);
     }
   }
   void unDelete(Circuit owner) {
     owner.items.addElement(this);
     for (int i = 0; i < destination.size(); i++) {
        Line line = (Line)destination.elementAt(i);
        owner.lines.addElement(line);
        line.destination.source = line;           
     }
     if (source != null) {
        owner.lines.addElement(source);
        source.source.destination.addElement(source);
     }
   }
}


