public void constrainToBounds(Rectangle aBounds)
    {
        if (aBounds == null)
            return;
        
        Rectangle r = this.getRect();

        if (r.width < 1)
            r.width = 1;
        else if (r.width > aBounds.width)
            r.width = aBounds.width;

        if (r.height < 1)
            r.height = 1;
        else if (r.height > aBounds.height)
            r.height = aBounds.height;

        if (r.x < 0)
            r.x = 0;
        else if (r.x + r.width > aBounds.width)
            r.x = aBounds.width - r.width;

        if (r.y < 0)
            r.y = 0;
        else if (r.y + r.height > aBounds.height)
            r.y = aBounds.height - r.height;
    }