/*
 * Created on Feb 3, 2004
 */
package org.lucci.madhoc.network.net;

import org.lucci.madhoc.bining.Cel;
import org.lucci.madhoc.network.Station;
import org.lucci.up.data.Point;

public class Location extends Point
{
    private Station computer;
    private Cel cel;

    
    public Cel getCel()
    {
        return cel;
    }

    public void setCel(Cel newCel)
    {
        if (newCel == null)
            throw new IllegalArgumentException("null cell");

        if ( cel != newCel )
        {
            if (cel != null) cel.getStations().remove(getComputer());
            cel = newCel;
            cel.getStations().add(getComputer());
        }
    }

    
    public Location(double x, double y)
    {
        super(x, y);
    }

    public Station getComputer()
    {
        return computer;
    }

    public void setXY(double x, double y)
    {
        super.setX(x);
        super.setY(y);
        setCel(computer.getNetwork().getNetworkEnvironment().getGrid().getCelAt(computer.getLocation()));
    }

    public void setX(double x)
    {
        throw new IllegalStateException("Please use setXY(x, y)");
    }
    public void setY(double y)
    {
        throw new IllegalStateException("Please use setXY(x, y)");
    }

    public void setComputer(Station device)
    {
        if (device == null)
            throw new IllegalArgumentException();

        this.computer = device;
    }
}