designtools
Class Wire

java.lang.Object
  extended bydesigntools.Wire

public class Wire
extends java.lang.Object

Class to represent a wire which is internally represented as a set of points


Constructor Summary
Wire(java.awt.Point startPoint, java.awt.Color colour, Workspace workspace)
          Wire constructor
 
Method Summary
 void connect(java.awt.Point point)
          If wire starts / ends at an input/output connection of a circuit component update the variables sourceComponent or targetComponent
 boolean disconnect(CircuitComponent comp)
          If this wire connects to comp, update the other end and return true, else false.
 void draw(java.awt.Graphics2D g)
          Draw the wire.
 ConnectedWires getConnectedWires()
           
 int getPointCount()
           
 boolean isWirePoint(java.awt.Point point)
           
 void lineTo(java.awt.Point bendPoint)
          Add a significant point to the wire.
 void removeLastPoint()
          If the wire consists of more that one point calling this procedure removed the last point recorded
 void removePoint(java.awt.Point bendPoint)
          Remove a point from the wire
 void removeWire()
          Removes wire from workspace and updates connected components accordingly.
 void setSelected(boolean selected)
          Indicate if the wire is selected by the user
 void sketchLineTo(java.awt.Point mousePoint)
          This sketches a line from the last wire bend / start to the current mouse position It is needed to show the user the wire section they are drawing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Wire

public Wire(java.awt.Point startPoint,
            java.awt.Color colour,
            Workspace workspace)
Wire constructor

Parameters:
startPoint - Wire start point
colour - Colour of wire
workspace - Workspace onto which the wire will be placed. Required for checking Circuit Components being connected
Method Detail

connect

public void connect(java.awt.Point point)
If wire starts / ends at an input/output connection of a circuit component update the variables sourceComponent or targetComponent

Parameters:
point - The wire point

getConnectedWires

public ConnectedWires getConnectedWires()
Returns:
a list of wires connected (directly or indirectly to this)

lineTo

public void lineTo(java.awt.Point bendPoint)
Add a significant point to the wire.

Parameters:
bendPoint - The point to add

sketchLineTo

public void sketchLineTo(java.awt.Point mousePoint)
This sketches a line from the last wire bend / start to the current mouse position It is needed to show the user the wire section they are drawing. The pointList isn't updated until the user clicks the mouse.

Parameters:
mousePoint - Current point of mouse to which a line should be sketched

removePoint

public void removePoint(java.awt.Point bendPoint)
Remove a point from the wire

Parameters:
bendPoint - The point to remove

removeLastPoint

public void removeLastPoint()
If the wire consists of more that one point calling this procedure removed the last point recorded


setSelected

public void setSelected(boolean selected)
Indicate if the wire is selected by the user

Parameters:
selected - true if wire is selected

getPointCount

public int getPointCount()
Returns:
Number of points that make up wire

isWirePoint

public boolean isWirePoint(java.awt.Point point)
Parameters:
point - The point to test
Returns:
True if point is on wire

draw

public void draw(java.awt.Graphics2D g)
Draw the wire.

Parameters:
g - Graphics Object

removeWire

public void removeWire()
Removes wire from workspace and updates connected components accordingly. If the wire is connected to others all connected wires are removed


disconnect

public boolean disconnect(CircuitComponent comp)
If this wire connects to comp, update the other end and return true, else false.

Parameters:
comp - The circuit component to disconnect from the wire
Returns:
true If the wire was connected to the component