public function replaceWithContainer(SwatContainer $container = null)
    {
        if ($this->parent === null) {
            throw new SwatException(
                'Widget does not have a parent, unable ' .
                    'to replace this widget with a container.'
            );
        }

        if ($container === null) {
            $container = new SwatContainer();
        }

        $parent = $this->parent;
        $parent->replace($this, $container);
        $container->add($this);

        return $container;
    }