Rectangle area = new Rectangle(new Point(x, y)); Stack stack = new Stack(); MapLayer before = new MapLayer(layer); MapLayer after;
Rectangle area = null; MapLayer before = new MapLayer(layer); MapLayer after;
    private void pour(MapLayer layer, int x, int y,            Tile newTile, Tile oldTile) {        if (newTile == oldTile) return;        Rectangle area = new Rectangle(new Point(x, y));        Stack stack = new Stack();        MapLayer before = new MapLayer(layer);        MapLayer after;        stack.push(new Point(x, y));        while (!stack.empty()) {            // Remove the next tile from the stack            Point p = (Point)stack.pop();            // If the tile it meets the requirements, set it and push its            // neighbouring tiles on the stack.            if (currentMap.inBounds(p.x, p.y) &&                    layer.getTileAt(p.x, p.y) == oldTile)            {                layer.setTileAt(p.x, p.y, newTile);                area.add(p);                stack.push(new Point(p.x, p.y - 1));                stack.push(new Point(p.x, p.y + 1));                stack.push(new Point(p.x + 1, p.y));                stack.push(new Point(p.x - 1, p.y));            }        }        Rectangle bounds = new Rectangle(                area.x, area.y, area.width + 1, area.height + 1);        after = new MapLayer(bounds);        after.copyFrom(layer);        MapLayerEdit mle = new MapLayerEdit(layer, before, after);        mle.setPresentationName("Fill");        undoSupport.postEdit(mle);    }