software.common
Class BallotGeometry

java.lang.Object
  extended by software.common.BallotGeometry

public class BallotGeometry
extends java.lang.Object


Constructor Summary
BallotGeometry(float width, float height)
          Builds a new, blank geometry of size width,height
BallotGeometry(java.lang.String path)
          Reads in the geometry of a ballot from a file
 
Method Summary
 void addAlignment(Cluster alignment)
           
 void addContest(int qno, java.util.Vector<Cluster> top, java.util.Vector<Cluster> bottom)
          Adds a contest to the geometry
 void addHoleOnly(Cluster holeOnly)
           
 com.lowagie.text.Rectangle getBottom(java.lang.String race, java.lang.String rank, java.lang.String candidate)
           
 Cluster getBottomCluster(java.lang.String race, java.lang.String rank, java.lang.String candidate)
           
 org.w3c.dom.Node getBottomNode(java.lang.String race, java.lang.String rank, java.lang.String candidate)
           
 java.util.Vector<Cluster> getContestBottomHoles()
           
 org.gwu.voting.standardFormat.electionSpecification.ElectionSpecification getDefaultElectionSpec()
           
 double getDonutThicknessBottom()
           
 double getDonutThicknessTop()
           
 float getHeight()
           
 float getHoleDiameter()
           
 java.awt.geom.Point2D.Double getLowerAlignment()
           
 com.lowagie.text.Rectangle getLowerFinishButton()
           
static int getNoColumnsFormVectorSortedOnY(java.util.Vector<Cluster> q)
           
 int getNoDigitsInSerial()
           
 int getNoRaces()
           
static int getNoRowsFromVectorSortedOnX(java.util.Vector<Cluster> q)
           
 com.lowagie.text.Rectangle getSerialBarcode()
           
 org.w3c.dom.Node getSerialBarcodeNode()
           
 com.lowagie.text.Rectangle getSerialBottom(java.lang.String digitId)
           
 Cluster getSerialBottomCluster(java.lang.String digitId)
           
 java.util.Vector<Cluster> getSerialBottomHolles()
           
 org.w3c.dom.Node getSerialBottomNode(java.lang.String digitId)
           
 com.lowagie.text.Rectangle[][] getSerialBulleted()
          Equally divided the rectangle where the serial number should be
 org.w3c.dom.Node getSerialBulletedNode()
           
 com.lowagie.text.Rectangle getSerialTop(java.lang.String digitId)
           
 org.w3c.dom.Node getSerialTopNode(java.lang.String digitId)
           
 com.lowagie.text.Rectangle getTop(java.lang.String race, java.lang.String candidate)
           
 com.lowagie.text.Rectangle getTop(java.lang.String race, java.lang.String rank, java.lang.String candidate)
           
 org.w3c.dom.Node getTopNode(java.lang.String race, java.lang.String rank, java.lang.String candidate)
           
 java.awt.geom.Point2D.Double getUpperAlignment()
           
 com.lowagie.text.Rectangle getUpperFinishButton()
           
 float getWidth()
           
 com.lowagie.text.Rectangle makeRectangle(org.w3c.dom.Node node)
           
 com.lowagie.text.Rectangle makeRectangle(java.awt.geom.Point2D.Double p)
           
 void setSerial(java.util.Vector<Cluster> top, java.util.Vector<Cluster> bottom)
          Adds the where the serial number should be
 void setSerialBarcode(Cluster serialBarcode)
           
 void setSerialBulleted(Cluster serialBulleted)
           
static void sortOnX(java.util.Vector<Cluster> q, int start, int stop)
          Sorts a vector of clusters based on their X coordinates (horizontaly)
static int sortOnXThenOnY(java.util.Vector<Cluster> q)
          Sorts a vector on cluster on X (horizontally).
static void sortOnY(java.util.Vector<Cluster> q, int start, int stop)
          Sorts a vector of clusters based on their Y coordinates (vertically)
static int sortOnYThenOnX(java.util.Vector<Cluster> q)
          Sorts a vector on cluster on Y (vertically).
 void write(java.io.OutputStream fos)
          Writes the geometry
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

BallotGeometry

public BallotGeometry(float width,
                      float height)
Builds a new, blank geometry of size width,height

Parameters:
width - - the with of the ballot in inches
height - - the height of the ballot in inches

BallotGeometry

public BallotGeometry(java.lang.String path)
               throws org.xml.sax.SAXException,
                      java.io.IOException
Reads in the geometry of a ballot from a file

Parameters:
path - - the path to a xml file with the geometry
Throws:
java.lang.Exception - - no Exception is caugth and no Exception is Explicitly thrown
org.xml.sax.SAXException
java.io.IOException
Method Detail

getNoDigitsInSerial

public int getNoDigitsInSerial()
Returns:
the size of the serial

getSerialTop

public com.lowagie.text.Rectangle getSerialTop(java.lang.String digitId)
Parameters:
digitId - the number of the digit in the top serial
Returns:
a bounding rectangle for digit number "digit" in the serial number on the top page

getSerialTopNode

public org.w3c.dom.Node getSerialTopNode(java.lang.String digitId)
Parameters:
digitId - the number of the digit in the top serial
Returns:
the xml node for the top digit in the serial number having id=digitId

getSerialBottom

public com.lowagie.text.Rectangle getSerialBottom(java.lang.String digitId)
Parameters:
digitId - the number of the digit in the bottom serial
Returns:
a bounding rectangle for digit number "digit" in the serial number on the bottom page

getSerialBottomCluster

public Cluster getSerialBottomCluster(java.lang.String digitId)
Parameters:
digitId - the number of the digit in the bottom serial
Returns:
the cluster for the bottom digit in the serial number having id=digitId

getSerialBottomHolles

public java.util.Vector<Cluster> getSerialBottomHolles()
Returns:
the possitions of the serial digits on the bottom page

getSerialBottomNode

public org.w3c.dom.Node getSerialBottomNode(java.lang.String digitId)
Parameters:
digitId - the number of the digit in the bottom serial
Returns:
the xml node for the bottom digit in the serial number having id=digitId

getTop

public com.lowagie.text.Rectangle getTop(java.lang.String race,
                                         java.lang.String candidate)
Parameters:
race - the race id
candidate - - the candidate id
Returns:
a bounding rectangle for the letter on the top page (rank 0)

getTop

public com.lowagie.text.Rectangle getTop(java.lang.String race,
                                         java.lang.String rank,
                                         java.lang.String candidate)
Parameters:
race - the race id
rank - the rank (if a scantegrity ballot)
candidate - - the candidate id
Returns:
a bounding rectangle for the letter on the top page

getBottom

public com.lowagie.text.Rectangle getBottom(java.lang.String race,
                                            java.lang.String rank,
                                            java.lang.String candidate)
Parameters:
race - the race number
rank -
candidate -
Returns:
a bounding rectangle for where the letter of the bottom page should appear

getBottomCluster

public Cluster getBottomCluster(java.lang.String race,
                                java.lang.String rank,
                                java.lang.String candidate)
Parameters:
race -
rank -
candidate -
Returns:
a cluster representing where the letter on bottom should apear

getBottomNode

public org.w3c.dom.Node getBottomNode(java.lang.String race,
                                      java.lang.String rank,
                                      java.lang.String candidate)
Parameters:
race -
rank -
candidate -
Returns:
an xml node from the geometry coresponding to the where the bottom letter should appear (null if no such thing is found for the particular race, rank and candidate)

getTopNode

public org.w3c.dom.Node getTopNode(java.lang.String race,
                                   java.lang.String rank,
                                   java.lang.String candidate)
Parameters:
race -
rank -
candidate -
Returns:
an xml node from the geometry coresponding to the where the top letter should appear (null if no such thing is found for the particular race, rank and candidate)

getContestBottomHoles

public java.util.Vector<Cluster> getContestBottomHoles()
Returns:
a vector of Clusters containing one element for every letter on the bottom page

addContest

public void addContest(int qno,
                       java.util.Vector<Cluster> top,
                       java.util.Vector<Cluster> bottom)
                throws java.lang.Exception
Adds a contest to the geometry

Parameters:
qno - - the question number
top - - where the top letter shold be
bottom - - where the bottom letters should be
Throws:
java.lang.Exception - if bottom is not null (Scantegrity) then the number of letter on the bottom must be a multiple of the number of letters on the top. Otherwise an exception is thrown

setSerial

public void setSerial(java.util.Vector<Cluster> top,
                      java.util.Vector<Cluster> bottom)
Adds the where the serial number should be

Parameters:
top - - the serial number on the top page
bottom - - the serial number on the bottom page

addAlignment

public void addAlignment(Cluster alignment)
Parameters:
alignment - the alignment mark to be added

addHoleOnly

public void addHoleOnly(Cluster holeOnly)
Parameters:
holeOnly - the place where a hole shoold be drilled (in addition to letters and serial number)

sortOnX

public static void sortOnX(java.util.Vector<Cluster> q,
                           int start,
                           int stop)
Sorts a vector of clusters based on their X coordinates (horizontaly)

Parameters:
q - - the vecotr to be sorted (it is modified by this method)
start - - the start possition (including)
stop - - the stop possition (exclusive)

sortOnY

public static void sortOnY(java.util.Vector<Cluster> q,
                           int start,
                           int stop)
Sorts a vector of clusters based on their Y coordinates (vertically)

Parameters:
q - - the vecotr to be sorted (it is modified by this method)
start - - the start possition (including)
stop - - the stop possition (exclusive)

sortOnXThenOnY

public static int sortOnXThenOnY(java.util.Vector<Cluster> q)
Sorts a vector on cluster on X (horizontally). It then finds the ones that have a very close X and for evry such grup, it sorts them on Y

Parameters:
q - - the vector to be sorted (it is modified by this method)
Returns:
- the number of groups with simmilar X coordinates

sortOnYThenOnX

public static int sortOnYThenOnX(java.util.Vector<Cluster> q)
Sorts a vector on cluster on Y (vertically). It then finds the ones that have a very close Y and for evry such grup, it sorts them on X

Parameters:
q - - the vector to be sorted (it is modified by this method)
Returns:
- the number of groups with simmilar Y coordinates

getNoRowsFromVectorSortedOnX

public static int getNoRowsFromVectorSortedOnX(java.util.Vector<Cluster> q)
Parameters:
q - - a vector of Clusters already sorted on X (does not get modified by this method)
Returns:
- the number of groups with similar X coordinates

getNoColumnsFormVectorSortedOnY

public static int getNoColumnsFormVectorSortedOnY(java.util.Vector<Cluster> q)
Parameters:
q - - a vector of Clusters already sorted on Y (does not get modified by this method)
Returns:
- the number of groups with similar Y coordinates

write

public void write(java.io.OutputStream fos)
           throws java.io.IOException
Writes the geometry

Parameters:
fos - - the output stream to write to
Throws:
java.lang.Exception - - no Exception is caugth and no Exception is Explicitly thrown
java.io.IOException

getUpperFinishButton

public com.lowagie.text.Rectangle getUpperFinishButton()
Returns:
a bouding rectangle where the "Finish voting" button should be on the top part of the form form. It is places horizontally in the middle of the page, 0.5 inches to the top. It has a height of 0.4 inches

getLowerFinishButton

public com.lowagie.text.Rectangle getLowerFinishButton()
Returns:
a bouding rectangle where the "Finish voting" button should be on the bottom part of the form. It is places horizontally in the middle of the page, 0.5 inches to the bottom. It has a height of 0.4 inches

makeRectangle

public com.lowagie.text.Rectangle makeRectangle(org.w3c.dom.Node node)
Parameters:
node -
Returns:
a Rectangle surounding the cluster in pdf coordinates

makeRectangle

public com.lowagie.text.Rectangle makeRectangle(java.awt.geom.Point2D.Double p)
Parameters:
p -
Returns:
a Rectangle surounding the point in pdf coordinates. The width and the height of the rectangle are 0.25inches each

getHeight

public float getHeight()

getWidth

public float getWidth()

getHoleDiameter

public float getHoleDiameter()

getUpperAlignment

public java.awt.geom.Point2D.Double getUpperAlignment()
Returns:
the alignment mark with the smallest Y

getLowerAlignment

public java.awt.geom.Point2D.Double getLowerAlignment()
Returns:
the alignment mark with the greatest Y

getDefaultElectionSpec

public org.gwu.voting.standardFormat.electionSpecification.ElectionSpecification getDefaultElectionSpec()
Returns:
a default election speficicartion. The questions are of rank type if the number of letters on the top is different to the number of letters on the bottom. All candidates can be ranked by default. Otherwise, the question is a choose one out of n.

getNoRaces

public int getNoRaces()
Returns:
the number of contests present on the ballot

setSerialBarcode

public void setSerialBarcode(Cluster serialBarcode)
Parameters:
serialBarcode - where the serial number in barcode is placed

setSerialBulleted

public void setSerialBulleted(Cluster serialBulleted)
Parameters:
serialBulleted - where the serial number in bullets readable by a mark sense machine is placed

getSerialBarcode

public com.lowagie.text.Rectangle getSerialBarcode()
Returns:
where the serial number in barcode is placed

getSerialBarcodeNode

public org.w3c.dom.Node getSerialBarcodeNode()
Returns:
where the serial number in bullets readable by a mark sense machine is placed

getSerialBulleted

public com.lowagie.text.Rectangle[][] getSerialBulleted()
Equally divided the rectangle where the serial number should be

Returns:
an array of rectables, with 10 columns and as many rows as in the serial number

getSerialBulletedNode

public org.w3c.dom.Node getSerialBulletedNode()
Returns:
the xml node coresponding to where the serial number bulleted should be

getDonutThicknessBottom

public double getDonutThicknessBottom()

getDonutThicknessTop

public double getDonutThicknessTop()