Index: trunk/src/org/expeditee/core/Anchoring.java
===================================================================
--- trunk/src/org/expeditee/core/Anchoring.java	(revision 1097)
+++ trunk/src/org/expeditee/core/Anchoring.java	(revision 1513)
@@ -4,154 +4,174 @@
 
 /**
- * Class for anchoring the position of items within the frame.
- * Anchoring is when the position of the item is defined relative
- * to the edge of the frame instead of being defined in absolute
- * coordinates. Can't be anchored to the left and right edge at
- * the same time, nor the top and bottom edge at the same time.
+ * Class for anchoring the position of items within the frame. Anchoring is when
+ * the position of the item is defined relative to the edge of the frame instead
+ * of being defined in absolute coordinates. Can't be anchored to the left and
+ * right edge at the same time, nor the top and bottom edge at the same time.
  * 
  * @author cts16
  */
 public class Anchoring {
+	
+	private enum VerticalDirection { left, center, right }
+	private enum HorizontalDirection { top, center, bottom }
 
-	/** The relative distance from the left or right edge (null means unanchored). */
+	/**
+	 * The relative distance from the left, center or right edge (null means unanchored).
+	 */
 	private Integer _xAnchor = null;
-	/** The relative distance from the top or bottom edge (null means unanchored). */
+	/**
+	 * The relative distance from the top, center or bottom edge (null means unanchored).
+	 */
 	private Integer _yAnchor = null;
+
 	/** Whether the x-anchor is relative to the left or right edge. */
-	private boolean _left = true;
+	private VerticalDirection verticalDirection = VerticalDirection.left;
 	/** Whether the y-anchor is relative to the top or bottom edge. */
-	private boolean _top = true;
-	
-	public Anchoring()
-	{
+	private HorizontalDirection horizonalDirection = HorizontalDirection.top;
+
+	public Anchoring() {
 	}
 	
-	public void setXAnchor(Integer offset, boolean left)
-	{
-		_xAnchor = offset;
-		_left = left;
+	public void setXAnchor(Anchoring other) {
+		if (other == null) {
+			return;
+		}
+		
+		setXAnchor(other._xAnchor, other.verticalDirection);
+	}
+
+	public void setYAnchor(Anchoring other) {
+		if (other == null)
+			return;
+
+		setYAnchor(other._yAnchor, other.horizonalDirection);
+	}
+
+	public void setLeftAnchor(Integer offset) {
+		setXAnchor(offset, VerticalDirection.left);
 	}
 	
-	public void setYAnchor(Integer offset, boolean top)
-	{
-		_yAnchor = offset;
-		_top = top;
+	public void setCenterXAnchor(Integer offset) {
+		setXAnchor(offset, VerticalDirection.center);
+	}
+
+	public void setRightAnchor(Integer offset) {
+		setXAnchor(offset, VerticalDirection.right);
+	}
+
+	public void setTopAnchor(Integer offset) {
+		setYAnchor(offset, HorizontalDirection.top);
 	}
 	
-	public void setXAnchor(Anchoring other)
-	{
-		if (other == null) return;
-		
-		setXAnchor(other._xAnchor, other._left);
+	public void setCenterYAnchor(Integer offset) {
+		setYAnchor(offset, HorizontalDirection.center);
 	}
 
-	public void setYAnchor(Anchoring other)
-	{
-		if (other == null) return;
-		
-		setYAnchor(other._yAnchor, other._top);
+	public void setBottomAnchor(Integer offset) {
+		setYAnchor(offset, HorizontalDirection.bottom);
 	}
 	
-	public void setLeftAnchor(Integer offset)
-	{
-		setXAnchor(offset, true);
+	public void removeXAnchor() {
+		setXAnchor(null, verticalDirection);
 	}
-	
-	public void setRightAnchor(Integer offset)
-	{
-		setXAnchor(offset, false);
+
+	public void removeYAnchor() {
+		setYAnchor(null, horizonalDirection);
 	}
-	
-	public void setTopAnchor(Integer offset)
-	{
-		setYAnchor(offset, true);
-	}
-	
-	public void setBottomAnchor(Integer offset)
-	{
-		setYAnchor(offset, false);
-	}
-	
-	public void removeXAnchor()
-	{
-		setXAnchor(null, _left);
-	}
-	
-	public void removeYAnchor()
-	{
-		setYAnchor(null, _top);
-	}
-	
-	public void removeAllAnchors()
-	{
+
+	public void removeAllAnchors() {
 		removeXAnchor();
 		removeYAnchor();
 	}
+
+	public Point getPositionInBox(AxisAlignedBoxBounds box) {
+		Integer x = getXPositionInBox(box);
+		Integer y = getYPositionInBox(box);
+
+		if (x == null || y == null)
+			return null;
+
+		return new Point(x, y);
+	}
+
+	public boolean isXAnchored() {
+		return _xAnchor != null;
+	}
+
+	public boolean isYAnchored() {
+		return _yAnchor != null;
+	}
+
+	public boolean isAnchored() {
+		return isXAnchored() || isYAnchored();
+	}
 	
-	public Integer getXPositionInBox(AxisAlignedBoxBounds box)
-	{
-		if (box == null || _xAnchor == null) return null;
+	public Integer getLeftAnchor() {
+		return verticalDirection.equals(VerticalDirection.left) ? _xAnchor : null;
+	}
+	
+	public Integer getCenterXAnchor() {
+		return verticalDirection.equals(VerticalDirection.center) ? _xAnchor : null;
+	}
+
+	public Integer getRightAnchor() {
+		return verticalDirection.equals(VerticalDirection.right) ? _xAnchor : null;
+	}
+
+	public Integer getTopAnchor() {
+		return horizonalDirection.equals(HorizontalDirection.top) ? _yAnchor : null;
+	}
+	
+	public Integer getCenterYAnchor() {
+		return horizonalDirection.equals(HorizontalDirection.center) ? _yAnchor : null;
+	}
+	
+	public Integer getBottomAnchor() {
+		return horizonalDirection.equals(HorizontalDirection.bottom) ? _yAnchor : null;
+	}
+			
+	private void setXAnchor(Integer offset, VerticalDirection left) {
+		_xAnchor = offset;
+		verticalDirection = left;
+	}
+
+	private void setYAnchor(Integer offset, HorizontalDirection top) {
+		_yAnchor = offset;
+		horizonalDirection = top;
+	}
+	
+	private Integer getXPositionInBox(AxisAlignedBoxBounds box) {
+		if (box == null || _xAnchor == null)
+			return null;
 		
-		if (_left) {
+		switch (verticalDirection) {
+		case left:
 			return box.getMinX() + _xAnchor;
-		} else {
+		case center:
+			return box.getCentreX() + _xAnchor;
+		case right:
 			return box.getMaxX() - _xAnchor;
+		default:
+			System.err.println("Anchoring::getXPositionInBox::VerticalDirection does not match available options.  Has the enum been updated without this function being updated?");
+			return null;
 		}
 	}
 	
-	public Integer getYPositionInBox(AxisAlignedBoxBounds box)
-	{
-		if (box == null || _yAnchor == null) return null;
+	private Integer getYPositionInBox(AxisAlignedBoxBounds box) {
+		if (box == null || _yAnchor == null) {
+			return null;
+		}
 		
-		if (_top) {
+		switch (horizonalDirection) {
+		case top:
 			return box.getMinY() + _yAnchor;
-		} else {
+		case center:
+			return box.getCentreY() + _yAnchor;
+		case bottom:
 			return box.getMaxY() - _yAnchor;
+		default:
+			System.err.println("Anchoring::getYPositionInBox::HorizonalDirection does not match available options.  Has the enum been updated without this function being updated?");
+			return null;
 		}
 	}
-	
-	public Point getPositionInBox(AxisAlignedBoxBounds box)
-	{
-		Integer x = getXPositionInBox(box);
-		Integer y = getYPositionInBox(box);
-		
-		if (x == null || y == null) return null;
-		
-		return new Point(x, y);
-	}
-	
-	public boolean isXAnchored()
-	{
-		return _xAnchor != null;
-	}
-	
-	public boolean isYAnchored()
-	{
-		return _yAnchor != null;
-	}
-	
-	public boolean isAnchored()
-	{
-		return isXAnchored() || isYAnchored();
-	}
-	
-	public Integer getLeftAnchor()
-	{
-		return _left ? _xAnchor : null;
-	}
-	
-	public Integer getRightAnchor()
-	{
-		return !_left ? _xAnchor : null;
-	}
-	
-	public Integer getTopAnchor()
-	{
-		return _top ? _yAnchor : null;
-	}
-	
-	public Integer getBottomAnchor()
-	{
-		return !_top ? _yAnchor : null;
-	}
 }
