package cnp.ew.diagram;

import java.awt.*;

import cnp.ew.lightweight.*;

public class CpBasicLocator implements CpLocator
{
    public static final int LEFT_TOP = 0;
    public static final int RIGHT_TOP = 1;
    public static final int LEFT_BOTTOM = 2;
    public static final int RIGHT_BOTTOM = 3;
    public static final int RIGHT_MIDDLE = 4;

    // cache of common locators
    public static CpBasicLocator leftTopLocator = new CpBasicLocator(LEFT_TOP);
    public static CpBasicLocator rightTopLocator = new CpBasicLocator(RIGHT_TOP);
    public static CpBasicLocator leftBottomLocator = new CpBasicLocator(LEFT_BOTTOM);
    public static CpBasicLocator rightBottomLocator = new CpBasicLocator(RIGHT_BOTTOM);
    public static CpBasicLocator rightMiddleLocator = new CpBasicLocator(RIGHT_MIDDLE);

    int stockLocation;

    public CpBasicLocator(int newStockLocation)
    {
        stockLocation = newStockLocation;
    }

    public Point getPoint(CpDiagrammableLc g)
    {
        Rectangle bounds = g.boundsDiagram();

        switch (stockLocation) {
            case LEFT_TOP : return new Point(bounds.x, bounds.y);
            case RIGHT_TOP : return new Point(bounds.x + bounds.width, bounds.y);
            case LEFT_BOTTOM : return new Point(bounds.x, bounds.y + bounds.height);
            case RIGHT_BOTTOM : return new Point(bounds.x + bounds.width, bounds.y + bounds.height);
            case RIGHT_MIDDLE : return new Point(bounds.x + bounds.width, bounds.y + bounds.height / 2);
        }
        return null;
    }
}