Examples of DockableLeaf


Examples of org.noos.xing.mydoggy.plaf.ui.cmp.multisplit.DockableLeaf

        if (!checkModel())
            System.out.println("Check model fail. addDockable before");

        if (entries.size() == 0) {
            // Just one leaf
            DockableLeaf leaf = new DockableLeaf(getNextLeanName(),
                    dockable.getId());
            leaf.setWeight(1.0d);
            multiSplitPaneModelRoot = leaf;

            multiSplitPane.setModel(leaf);
            multiSplitPane.add(getWrapperForComponent(dockable, content, Action.ADD_DOCK), "1");
            setRootComponent(multiSplitPane);
            SwingUtil.repaint(this);
        } else {
            boolean resetB = true;

            byte[] oldModel = null;
            if (dockable.equals(removedDockable)) {
                oldModel = lastLayout;
                removedDockable = null;
                lastLayout = null;
            }

            boolean invalidAggregationPosition = false;
            if (aggregationPosition == AggregationPosition.DEFAULT || aggregationPosition == null) {
                invalidAggregationPosition = true;
                aggregationPosition = defaultAggregationPosition;
            }

            if (multiSplitPaneModelRoot instanceof DockableLeaf) {
                // The root is a leaf...
                DockableLeaf rootLeaf = (DockableLeaf) multiSplitPaneModelRoot;

                if (aggregationOnDockable != null && (aggregationPosition == null || invalidAggregationPosition)) {
                    // Aggregate to an already registered leaf
                    Component componentWrapper;

                    if (rootLeaf.getDockables().size() > 1) {
                        componentWrapper = multiSplitPane.getComponent(0);
                    } else {
                        Component rootLeafCmp = getComponentFromWrapper(multiSplitPane.getComponent(0));
                        multiSplitPane.removeAll();
                        componentWrapper = forceWrapperForComponent(entries.values().iterator().next().dockable, rootLeafCmp);
                        multiSplitPane.add(componentWrapper, rootLeaf.getName());
                    }

                    // The requeste is to add more than one dockable on the same leaf... no need to request a new leaf name
                    addToWrapper(componentWrapper, dockable, aggregationIndexLocation, content);

                    repaintMultiSplit(toolWindowManager.getClientProperty(MyDoggyKeySpace.PERSISTENCE_DELEGATE_PARSING) != null,
                            multiSplitPaneModelRoot);

                    rootLeaf.addDockable(dockable.getId());
                } else {
                    // Create a new leaf...

                    DockableLeaf firstLeaf = rootLeaf;
                    DockableLeaf secondLeaf;

                    // Init two leafs
                    firstLeaf.setWeight(0.5);

                    secondLeaf = new DockableLeaf(getNextLeanName());
                    secondLeaf.setWeight(0.5);
                    secondLeaf.addDockable(dockable.getId());

                    List<Node> children = null;
                    switch (aggregationPosition) {
                        case LEFT:
                        case TOP:
                            children = Arrays.asList(secondLeaf,
                                    new Divider(),
                                    firstLeaf);
                            break;
                        case RIGHT:
                        case BOTTOM:
                            children = Arrays.asList(firstLeaf,
                                    new Divider(),
                                    secondLeaf);
                            break;
                    }

                    boolean rowLayout = (aggregationPosition == AggregationPosition.LEFT || aggregationPosition == AggregationPosition.RIGHT);

                    Split split = new Split();
                    split.setRowLayout(rowLayout);
                    split.setBounds(split.getBounds());
                    split.setChildren(children);

                    // update the model
                    multiSplitPaneModelRoot = split;

                    if (!multiSplitPane.getMultiSplitLayout().getFloatingDividers())
                        multiSplitPane.getMultiSplitLayout().setFloatingDividers(true);

                    validateModel(multiSplitPaneModelRoot);
                    multiSplitPane.setModel(multiSplitPaneModelRoot);

                    // update the components in the container
                    Component wrapper;
                    if (rootLeaf.getDockables().size() > 1) {
                        wrapper = multiSplitPane.getComponent(0);
                    } else {
                        Dockable delegator = entries.values().iterator().next().dockable;
                        wrapper = getWrapperForComponent(delegator, getComponentFromWrapper(multiSplitPane.getComponent(0)), Action.ADD_DOCK);
                    }
                    multiSplitPane.removeAll();

                    multiSplitPane.add(wrapper, firstLeaf.getName());
                    multiSplitPane.add(getWrapperForComponent(dockable, content, Action.ADD_DOCK), secondLeaf.getName());
                }
            } else {
                // Take the root, it's a split
                Split splitRoot = (Split) multiSplitPaneModelRoot;

                // Build content to add
                boolean addCmp = true;
                String leafName = null;

                // Modify model
                if (aggregationOnDockable != null) {

                    // Search for aggregationOnDockable leaf
                    Stack<Split> stack = new Stack<Split>();
                    stack.push(splitRoot);

                    while (!stack.isEmpty()) {
                        Split split = stack.pop();

                        for (Node child : split.getChildren()) {
                            if (child instanceof DockableLeaf) {
                                DockableLeaf leaf = (DockableLeaf) child;

                                if (leaf.getDockables().contains(aggregationOnDockable.getId())) {
                                    if (invalidAggregationPosition) {
                                        // The requeste is to add more than one dockable on the same leaf...
                                        addToWrapper(multiSplitPane.getMultiSplitLayout().getChildMap().get(leaf.getName()),
                                                dockable,
                                                aggregationIndexLocation,
                                                content);

                                        leaf.addDockable(dockable.getId());

                                        addCmp = false;
                                        resetB = false;
                                    } else {
                                        leafName = getNextLeanName();
                                        boolean step1Failed = false;

                                        // Check for concordance to leaf.getParent().isRowLayout and aggregationPosition
                                        Split parent = leaf.getParent();
                                        boolean rowLayout = parent.isRowLayout();

                                        List<Node> parentChildren = parent.getChildren();
                                        int startIndex = parentChildren.indexOf(leaf);
                                        if (rowLayout) {
                                            boolean finalize = false;
                                            switch (aggregationPosition) {
                                                case LEFT:
                                                    parentChildren.add(startIndex, new DockableLeaf(leafName, dockable.getId()));
                                                    parentChildren.add(startIndex + 1, new Divider());
                                                    finalize = true;
                                                    break;
                                                case RIGHT:
                                                    parentChildren.add(startIndex + 1, new Divider());
                                                    parentChildren.add(startIndex + 2, new DockableLeaf(leafName, dockable.getId()));
                                                    finalize = true;
                                                    break;
                                                default:
                                                    step1Failed = true;
                                            }

                                            if (finalize) {
                                                // Set new children
                                                forceWeight(parentChildren);
                                                parent.setChildren(parentChildren);
                                            }
                                        } else {
                                            boolean finalize = false;
                                            switch (aggregationPosition) {
                                                case TOP:
                                                    parentChildren.add(startIndex, new DockableLeaf(leafName, dockable.getId()));
                                                    parentChildren.add(startIndex + 1, new Divider());
                                                    finalize = true;
                                                    break;
                                                case BOTTOM:
                                                    parentChildren.add(startIndex + 1, new Divider());
                                                    parentChildren.add(startIndex + 2, new DockableLeaf(leafName, dockable.getId()));
                                                    finalize = true;
                                                    break;
                                                default:
                                                    step1Failed = true;
                                            }

                                            if (finalize) {
                                                // Set new children
                                                forceWeight(parentChildren);
                                                parent.setChildren(parentChildren);
                                            }
                                        }


                                        if (step1Failed) {
                                            // Create two leafs

                                            Leaf newleaf = new DockableLeaf(leafName, dockable.getId());
                                            newleaf.setWeight(0.5);

                                            // Creat the split
                                            Split newSplit = new Split();
                                            newSplit.setBounds(leaf.getBounds());
                                            newSplit.setRowLayout((aggregationPosition == AggregationPosition.LEFT || aggregationPosition == AggregationPosition.RIGHT));
                                            newSplit.setWeight(leaf.getWeight());
                                            leaf.getParent().removeNode(leaf);
                                            switch (aggregationPosition) {
                                                case LEFT:
                                                case TOP:
                                                    newSplit.setChildren(Arrays.asList(newleaf,
                                                            new Divider(),
                                                            leaf));
                                                    break;
                                                default:
                                                    newSplit.setChildren(Arrays.asList(leaf,
                                                            new Divider(),
                                                            newleaf));
                                                    break;
                                            }

                                            leaf.setWeight(0.5);

                                            // Switch the leaf with the new split
                                            parentChildren.set(startIndex, newSplit);
                                            parent.setChildren(parentChildren);
                                        }
                                    }

                                    stack.clear();
                                    break;
                                }
                            } else if (child instanceof Split) {
                                stack.push((Split) child);
                            }
                        }
                    }

                    if (!multiSplitPane.getMultiSplitLayout().getFloatingDividers())
                        multiSplitPane.getMultiSplitLayout().setFloatingDividers(true);
                } else {
                    leafName = getNextLeanName();
                    boolean rowLayout = (aggregationPosition == AggregationPosition.LEFT || aggregationPosition == AggregationPosition.RIGHT);

                    if (splitRoot.isRowLayout() == rowLayout) {
                        List<Node> children = splitRoot.getChildren();

                        switch (aggregationPosition) {
                            case LEFT:
                            case TOP:
                                children.add(0, new DockableLeaf(leafName, dockable.getId()));
                                children.add(1, new Divider());
                                break;
                            case RIGHT:
                            case BOTTOM:
                                children.add(new Divider());
                                children.add(new DockableLeaf(leafName, dockable.getId()));
                                break;
                        }

                        forceWeight(children);

                        splitRoot.setChildren(children);
                    } else {
                        Split newRoot = new Split();
                        newRoot.setRowLayout(rowLayout);
                        newRoot.setBounds(multiSplitPaneModelRoot.getBounds());

                        Leaf leaf = new DockableLeaf(leafName, dockable.getId());
                        leaf.setWeight(0.5);
                        multiSplitPaneModelRoot.setWeight(0.5);

                        List<Node> children = null;
                        switch (aggregationPosition) {
                            case LEFT:
View Full Code Here

Examples of org.noos.xing.mydoggy.plaf.ui.cmp.multisplit.DockableLeaf

        else {
            if (dockableConstraint.getNode() == null)
                addDockable(dockable, component, null, dockableConstraint.getIndex(), dockableConstraint.getAggregationPosition());
            else {
                if (dockableConstraint.getNode() instanceof DockableLeaf) {
                    DockableLeaf leaf = (DockableLeaf) dockableConstraint.getNode();

                    for (String leafDockableId : leaf.getDockables()) {
                        Dockable leafDockable = toolWindowManager.lookupDockable(leafDockableId);
                        if (leafDockable != null && !leafDockable.isDetached()) {
                            addDockable(dockable, component, leafDockable, dockableConstraint.getIndex(), dockableConstraint.getAggregationPosition());
                            return;
                        }
                    }

                    addDockable(dockable, component, null, dockableConstraint.getIndex(), dockableConstraint.getAggregationPosition());
                } else if (dockableConstraint.getNode() instanceof Split) {
                    Split split = (Split) dockableConstraint.getNode();

                    if (multiSplitPaneModelRoot == split)
                        addDockable(dockable, component, null, dockableConstraint.getIndex(), dockableConstraint.getAggregationPosition());
                    else {
                        Split parent = split.getParent();
                        if (!isNodeAttached(split) || parent == null) {
                            addDockable(dockable, component, null, dockableConstraint.getIndex(), dockableConstraint.getAggregationPosition());
                        } else {
                            AggregationPosition aggregationPosition = dockableConstraint.getAggregationPosition();
                            switch (aggregationPosition) {
                                case TOP:
                                case LEFT:
                                    List<Node> nodes = parent.getChildren();
                                    DockableLeaf dockableLeaf = new DockableLeaf(getNextLeanName(), dockable.getId());
                                    dockableLeaf.setWeight(0.5d);

                                    int index = nodes.indexOf(split);
                                    nodes.add(index, dockableLeaf);
                                    nodes.add(index + 1, new Divider());

                                    parent.setChildren(nodes);

                                    multiSplitPane.add(getWrapperForComponent(dockable, component, Action.ADD_DOCK),
                                            dockableLeaf.getName());
                                    break;
                                case BOTTOM:
                                case RIGHT:
                                    nodes = parent.getChildren();
                                    dockableLeaf = new DockableLeaf(getNextLeanName(), dockable.getId());
                                    dockableLeaf.setWeight(0.5d);

                                    index = nodes.indexOf(split);
                                    nodes.add(index, dockableLeaf);
                                    nodes.add(index - 1, new Divider());

                                    parent.setChildren(nodes);

                                    multiSplitPane.add(getWrapperForComponent(dockable, component, Action.ADD_DOCK),
                                            dockableLeaf.getName());
                                    break;
                            }
                            entries.put(dockable, new DockableEntry(dockable, component));

                            validateModel(multiSplitPaneModelRoot);
View Full Code Here

Examples of org.noos.xing.mydoggy.plaf.ui.cmp.multisplit.DockableLeaf

        // Remove the dockable
        entries.remove(dockable);

        // Adjust the layout...
        if (entries.size() == 0) {
            DockableLeaf dockableLeaf = getLeaf(dockable);
            Component cmp = multiSplitPane.getMultiSplitLayout().getChildMap().get(dockableLeaf.getName());

            if (isWrapper(cmp))
                removeFromWrapper(cmp, dockable);

            multiSplitPaneModelRoot = null;
            multiSplitPane.removeAll();

            resetRootComponent();
            leafNameCounter = 0;
            SwingUtil.repaint(this);

            // No constraint for the content because it was alone on the container
            return null;
        }

        if (entries.size() == 1) {
            if (multiSplitPaneModelRoot instanceof DockableLeaf) {
                DockableLeaf leaf = (DockableLeaf) multiSplitPaneModelRoot;
                int index = removeFromWrapper(multiSplitPane.getComponent(0), dockable);
                leaf.getDockables().remove(dockable.getId());

                if (!useAlwaysContentWrapper) {
                    Component root = multiSplitPane.getComponent(0);
                    multiSplitPane.removeAll();
                    multiSplitPane.add(getComponentFromWrapper(root), "1");
                }

                return new DockableConstraint(leaf,
                        AggregationPosition.DEFAULT,
                        index);
            } else {
                // the root is a split

                // remove the component related to dockable
                Component component = multiSplitPane.getMultiSplitLayout().getChildMap().get(getLeafName(dockable));
                if (isWrapper(component))
                    removeFromWrapper(component, dockable);
                multiSplitPane.remove(component);

                // retrieve the component related to sole entry in entries
                Dockable leftDockable = entries.keySet().iterator().next();
                DockableLeaf leftLeaf = getLeaf(leftDockable);

                Component masterLeftLeafCmp = multiSplitPane.getMultiSplitLayout().getChildMap().get(leftLeaf.getName());
                Component leftLeafCmp = getComponentFromWrapper(masterLeftLeafCmp);
                leftLeaf.setName("1");

                if (isWrapper(masterLeftLeafCmp))
                    removeFromWrapper(masterLeftLeafCmp, leftDockable);

                // Update the model
                AggregationPosition constraintAggPosition = AggregationPosition.DEFAULT;
                Split rootSplit = (Split) multiSplitPaneModelRoot;
                List<Node> children = rootSplit.getChildren();
                for (int i = 0, size = children.size(); i < size; i++) {
                    Node node = children.get(i);
                    if (node == leftLeaf) {
                        if (i == 0) {
                            if (rootSplit.isRowLayout())
                                constraintAggPosition = AggregationPosition.RIGHT;
                            else
                                constraintAggPosition = AggregationPosition.BOTTOM;
                        } else if (rootSplit.isRowLayout())
                            constraintAggPosition = AggregationPosition.LEFT;
                        else
                            constraintAggPosition = AggregationPosition.TOP;
                        break;
                    }
                }


                multiSplitPaneModelRoot = leftLeaf;
                multiSplitPaneModelRoot.setParent(null);

                // Update the pane
                multiSplitPane.setModel(multiSplitPaneModelRoot);
                multiSplitPane.removeAll();
                multiSplitPane.add(getWrapperForComponent(leftDockable, leftLeafCmp, Action.REMOVE_DOCK), "1");

                // Finalize
                leafNameCounter = 1;
                SwingUtil.repaint(this);

                // Prepare constraint
                return new DockableConstraint(leftLeaf,
                        constraintAggPosition,
                        -1);
            }
        } else {
            DockableConstraint dockableConstraint = null;

            DockableLeaf dockableLeaf = getLeaf(dockable);
            if (dockableLeaf == null)
                throw new IllegalArgumentException("Cannot remove the dockable. Cannot find leaf. [id : " + dockable.getId() + "]");

            if (dockableLeaf.getDockables().size() > 1) {
                // There are more than one dockable on the same leaf
                // Remove the dockable from leaf and from aggregating component...
                dockableLeaf.getDockables().remove(dockable.getId());

                int index = removeFromWrapper(multiSplitPane.getMultiSplitLayout().getChildMap().get(dockableLeaf.getName()),
                        dockable);

                // Prepare dockableConstraint
                return new DockableConstraint(dockableLeaf,
                        AggregationPosition.DEFAULT,
                        index);
            } else {
                leafNameCounter--;

                // There is one dockable on the leaf. We have to rearrange the layout...
                String leafKey = dockableLeaf.getName();
                int leafValue = Integer.parseInt(leafKey);
                Component component = multiSplitPane.getMultiSplitLayout().getChildMap().get(leafKey);

                // Remove content
                if (component != null) {
View Full Code Here

Examples of org.noos.xing.mydoggy.plaf.ui.cmp.multisplit.DockableLeaf

            return;

        // Check for contents root

        if (root instanceof DockableLeaf) {
            DockableLeaf dockableLeaf = (DockableLeaf) root;
            if (!containsDockable(dockableLeaf) || dockableLeaf.getDockables().size() != entries.size())
                return;
        } else if (root instanceof Split) {
            Stack<Split> stack = new Stack<Split>();
            stack.push((Split) root);
            int dockCounter = 0;

            while (!stack.isEmpty()) {
                Split split = stack.pop();

                for (Node child : split.getChildren()) {

                    if (child instanceof Split) {
                        stack.push((Split) child);
                    } else if (child instanceof DockableLeaf) {
                        DockableLeaf dockableLeaf = (DockableLeaf) child;
                        if (!containsDockable(dockableLeaf))
                            return;
                        dockCounter += dockableLeaf.getDockables().size();
                    }
                }
            }

            if (dockCounter != entries.size())
                return;
        } else
            throw new RuntimeException("Invalid model. [model : " + root + "]");

        // Mount new root
        Map<String, Component> currentChildMap = multiSplitPane.getMultiSplitLayout().getChildMap();

        // First Step: disaggregate...
        if (multiSplitPaneModelRoot instanceof DockableLeaf) {
            DockableLeaf leaf = (DockableLeaf) multiSplitPaneModelRoot;

            String[] dockIds = leaf.getDockables().toArray(new String[leaf.getDockables().size()]);
            for (String dockId : dockIds) {

                if (leaf.getDockables().size() == 1)
                    break;

                Component component = currentChildMap.get(leaf.getName());

                Dockable dockable = toolWindowManager.lookupDockable(dockId);
                setConstraints(dockable,
                        getComponentFromWrapper(component, dockable),
                        null,
                        -1,
                        AggregationPosition.DEFAULT
                );
            }
        } else {
            Stack<Split> stack = new Stack<Split>();
            stack.push((Split) multiSplitPaneModelRoot);
            while (!stack.isEmpty()) {
                Split split = stack.pop();

                for (Node child : split.getChildren()) {
                    if (child instanceof DockableLeaf) {
                        DockableLeaf leaf = (DockableLeaf) child;

                        String[] dockIds = leaf.getDockables().toArray(new String[leaf.getDockables().size()]);
                        for (String dockId : dockIds) {

                            if (leaf.getDockables().size() == 1)
                                break;

                            Component component = currentChildMap.get(leaf.getName());

                            Dockable dockable = toolWindowManager.lookupDockable(dockId);
                            setConstraints(dockable,
                                    getComponentFromWrapper(component, dockable),
                                    null,
                                    -1,
                                    AggregationPosition.DEFAULT
                            );
                        }
                    } else if (child instanceof Split) {
                        stack.push((Split) child);
                    }
                }
            }
        }


        if (root instanceof Split) {
            // Step Two: apply model 1...Aggregate
            Stack<Split> stack = new Stack<Split>();
            stack.push((Split) root);
            while (!stack.isEmpty()) {
                Split split = stack.pop();

                for (Node child : split.getChildren()) {
                    if (child instanceof DockableLeaf) {
                        DockableLeaf leaf = (DockableLeaf) child;

                        List<String> ids = leaf.getDockables();
                        Dockable master = toolWindowManager.lookupDockable(leaf.getDockable());

                        for (int i = 1; i < ids.size(); i++) {
                            Dockable dockable = toolWindowManager.lookupDockable(ids.get(i));
                            setConstraints(dockable,
                                    getComponentFromWrapper(currentChildMap.get(getLeaf(dockable).getName()), dockable),
                                    master,
                                    -1,
                                    AggregationPosition.DEFAULT
                            );
                        }
                    } else if (child instanceof Split) {
                        stack.push((Split) child);
                    }
                }
            }

            // Step Two: apply model 2...Isomorphing
            Map<String, Component> newChildMap = new LinkedHashMap<String, Component>();
            stack = new Stack<Split>();
            stack.push((Split) root);
            while (!stack.isEmpty()) {
                Split split = stack.pop();

                for (Node child : split.getChildren()) {
                    if (child instanceof DockableLeaf) {
                        DockableLeaf leaf = (DockableLeaf) child;

                        DockableLeaf currentLeaf = getLeaf(multiSplitPaneModelRoot, leaf.getDockable());

                        newChildMap.put(
                                leaf.getName(),
                                currentChildMap.get(currentLeaf.getName())
                        );
                    } else if (child instanceof Split) {
                        stack.push((Split) child);
                    }
                }
            }

            multiSplitPane.getMultiSplitLayout().setChildMap(newChildMap);
        } else {
            DockableLeaf leaf = (DockableLeaf) root;

            List<String> dockIds = leaf.getDockables();
            Dockable masterDockable = toolWindowManager.lookupDockable(leaf.getDockable());
            for (int i = 1; i < dockIds.size(); i++) {
                String dockId = dockIds.get(i);

                Dockable dockable = toolWindowManager.lookupDockable(dockId);
                setConstraints(dockable,
View Full Code Here

Examples of org.noos.xing.mydoggy.plaf.ui.cmp.multisplit.DockableLeaf

            }
        }
    }

    public Rectangle getBoundsRelativeToScreen(Dockable dockable) {
        DockableLeaf leaf = getLeaf(dockable);
        if (leaf != null) {
            Rectangle bounds = leaf.getBounds();
            Point location = bounds.getLocation();
            SwingUtilities.convertPointToScreen(location, this);
            bounds.setLocation(location);
            bounds.y += toolWindowManager.getJMenuBarExtraHeight();
View Full Code Here

Examples of org.noos.xing.mydoggy.plaf.ui.cmp.multisplit.DockableLeaf

        }
        return null;
    }

    protected String getLeafName(Dockable dockable) {
        DockableLeaf leaf = getLeaf(multiSplitPaneModelRoot, dockable.getId());
        return (leaf != null) ? leaf.getName() : null;
    }
View Full Code Here

Examples of org.noos.xing.mydoggy.plaf.ui.cmp.multisplit.DockableLeaf

    }

    protected DockableLeaf getLeaf(Node root, String dockableId) {
        if (root == null || !(root instanceof Split)) {
            if (root instanceof Leaf) {
                DockableLeaf leaf = (DockableLeaf) root;
                if (leaf.getDockables().contains(dockableId))
                    return leaf;
            }
            return null;
        }

        Stack<Split> stack = new Stack<Split>();
        stack.push((Split) root);

        while (!stack.isEmpty()) {
            Split split = stack.pop();

            for (Node child : split.getChildren()) {
                if (child instanceof DockableLeaf) {
                    DockableLeaf leaf = (DockableLeaf) child;

                    if (leaf.getDockables().contains(dockableId))
                        return leaf;
                } else if (child instanceof Split) {
                    stack.push((Split) child);
                }
            }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.