private int createGraphFromTree(ListenableGraph<Tree, DefaultEdge> graph, Tree tree,
                                    Tree parent, int parentXOffset, int parentYOffset) {

        graph.addVertex(tree);
        if (parent != null) {
            graph.addEdge(parent, tree);
        }

        if (tree.getLeft() == null
                && tree.getRight() == null
                && tree.getOperator() == null) {
            positionVertexAt(tree, (1 + parentXOffset) * X_OFFSET, parentYOffset * Y_OFFSET);
            return 1;
        }

        if (tree.getRight() == null
                && tree.getLeft() == null
                && tree.getOperator() != null) {
            int offset = createGraphFromTree(graph,
                    tree.getOperator(), tree, parentXOffset, parentYOffset + 1);
            positionVertexAt(tree, (1 + parentXOffset + offset) * X_OFFSET, parentYOffset * Y_OFFSET);
            return offset + 1;
        }

        Tree l = tree.getLeft();
        Tree r = tree.getRight();

        int offsetOperator = createGraphFromTree(graph,
                tree.getOperator(), tree, parentXOffset, parentYOffset + 1);
        int offsetLeft = createGraphFromTree(graph,
                l, tree, offsetOperator + parentXOffset + 1, parentYOffset + 1);
        int offsetRight = createGraphFromTree(graph,
                r, tree, offsetOperator + offsetLeft + parentXOffset + 2, parentYOffset + 1);

        positionVertexAt(tree, (offsetLeft + parentXOffset + 1) * X_OFFSET, parentYOffset * Y_OFFSET);

        return offsetLeft + offsetRight + 1;
    }