Package org.apache.pivot.collections.Sequence.Tree

Examples of org.apache.pivot.collections.Sequence.Tree.Path


        }

        TreeBranch treeData = new TreeBranch();
        treeData.add(build(value));
        treeView.setTreeData(treeData);
        treeView.expandBranch(new Path(0));
    }
View Full Code Here


         * @param index
         * The index of the inserted item within its parent.
         */
        private void incrementPaths(ArrayList<Path> paths, Path basePath, int index) {
            // Calculate the child's path
            Path childPath = new Path(basePath);
            childPath.add(index);

            // Find the child path's place in our sorted paths sequence
            int i = ArrayList.binarySearch(paths, childPath, PATH_COMPARATOR);
            if (i < 0) {
                i = -(i + 1);
            }

            // Temporarily clear the comparator while we update the list
            paths.setComparator(null);
            try {
                // Update all affected paths by incrementing the appropriate path element
                for (int depth = basePath.getLength(), n = paths.getLength(); i < n; i++) {
                    Path affectedPath = paths.get(i);

                    if (!Sequence.Tree.isDescendant(basePath, affectedPath)) {
                        // All paths from here forward are guaranteed to be unaffected
                        break;
                    }

                    Integer[] elements = affectedPath.toArray();
                    elements[depth]++;
                    paths.update(i, new ImmutablePath(elements));
                }
            } finally {
                // Restore the comparator
View Full Code Here

        private void clearAndDecrementPaths(ArrayList<Path> paths, Path basePath, int index,
            int count) {
            int depth = basePath.getLength();

            // Find the index of the first path to clear (inclusive)
            Path testPath = new Path(basePath);
            testPath.add(index);

            int start = ArrayList.binarySearch(paths, testPath, PATH_COMPARATOR);
            if (start < 0) {
                start = -(start + 1);
            }

            // Find the index of the last path to clear (exclusive)
            testPath.update(depth, index + count);

            int end = ArrayList.binarySearch(paths, testPath, PATH_COMPARATOR);
            if (end < 0) {
                end = -(end + 1);
            }

            // Clear affected paths
            if (end > start) {
                paths.remove(start, end - start);
            }

            // Decrement paths as necessary
            for (int i = start, n = paths.getLength(); i < n; i++) {
                Path affectedPath = paths.get(i);

                if (!Sequence.Tree.isDescendant(basePath, affectedPath)) {
                    // All paths from here forward are guaranteed to be unaffected
                    break;
                }

                Integer[] elements = affectedPath.toArray();
                elements[depth] -= count;
                paths.update(i, new ImmutablePath(elements));
            }
        }
View Full Code Here

         * @param index
         * The index of the updated item within its parent.
         */
        private void clearPaths(ArrayList<Path> paths, Path basePath, int index) {
            // Calculate the child's path
            Path childPath = new Path(basePath);
            childPath.add(index);

            // Find the child path's place in our sorted paths sequence
            int clearIndex = ArrayList.binarySearch(paths, childPath, PATH_COMPARATOR);
            if (clearIndex < 0) {
                clearIndex = -(clearIndex + 1);
            }

            // Remove the child and all descendants from the paths list
            for (int i = clearIndex, n = paths.getLength(); i < n; i++) {
                Path affectedPath = paths.get(clearIndex);

                if (!Sequence.Tree.isDescendant(childPath, affectedPath)) {
                    break;
                }

View Full Code Here

            int index = ArrayList.binarySearch(paths, basePath, PATH_COMPARATOR);
            index = (index < 0 ? -(index + 1) : index + 1);

            // Remove all descendants from the paths list
            for (int i = index, n = paths.getLength(); i < n; i++) {
                Path affectedPath = paths.get(index);

                if (!Sequence.Tree.isDescendant(basePath, affectedPath)) {
                    break;
                }
View Full Code Here

            List<TreeNode> parentData;

            if (n == 1) {
                parentData = (List<TreeNode>)treeData;
            } else {
                Path parentPath = new Path(path, n - 1);
                parentData = (List<TreeNode>)Sequence.Tree.get(treeData, parentPath);
            }

            if (parentData.getComparator() == null) {
                int index = path.get(n - 1);
                parentData.remove(index, 1);
                parentData.insert(treeNode, index);
            } else {
                parentData.remove(path.get(n - 1), 1);
                parentData.add(treeNode);

                // Re-select the node, and make sure it's visible
                path = new Path(path, n - 1);
                path.add(parentData.indexOf(treeNode));
                treeView.setSelectedPath(path);
                treeView.scrollAreaToVisible(treeView.getNodeBounds(path));
            }
        }
View Full Code Here

                    || nodeInfo.isCheckmarkDisabled()
                    || x < nodeX + checkboxX
                    || x >= nodeX + checkboxX + checkboxWidth
                    || y < nodeY + checkboxY
                    || y >= nodeY + checkboxY + checkboxHeight) {
                    Path path = nodeInfo.getPath();

                    // See if the user clicked on an expand/collapse control of
                    // a branch. If so, expand/collapse the branch
                    if (showBranchControls
                        && nodeInfo instanceof BranchInfo
View Full Code Here

                    && !nodeInfo.isCheckmarkDisabled()
                    && x >= nodeX + checkboxX
                    && x < nodeX + checkboxX + checkboxWidth
                    && y >= nodeY + checkboxY
                    && y < nodeY + checkboxY + checkboxHeight) {
                    Path path = nodeInfo.getPath();
                    treeView.setNodeChecked(path, !nodeInfo.isChecked());
                } else {
                    if (selectPath != null
                        && count == 1
                        && button == Mouse.Button.LEFT) {
View Full Code Here

        TreeView.SelectMode selectMode = treeView.getSelectMode();

        switch (keyCode) {
        case Keyboard.KeyCode.UP: {
            if (selectMode != TreeView.SelectMode.NONE) {
                Path firstSelectedPath = treeView.getFirstSelectedPath();

                int index;
                if (firstSelectedPath != null) {
                    NodeInfo previousSelectedNode = getNodeInfoAt(firstSelectedPath);
                    index = visibleNodes.indexOf(previousSelectedNode);
                } else {
                    // Select the last visible node
                    index = visibleNodes.getLength();
                }

                NodeInfo newSelectedNode = null;
                do {
                    newSelectedNode = (--index >= 0) ? visibleNodes.get(index) : null;
                } while (newSelectedNode != null
                    && newSelectedNode.isDisabled());

                if (newSelectedNode != null) {
                    if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)
                        && treeView.getSelectMode() == TreeView.SelectMode.MULTI) {
                        treeView.addSelectedPath(newSelectedNode.getPath());
                    } else {
                        treeView.setSelectedPath(newSelectedNode.getPath());
                    }
                    treeView.scrollAreaToVisible(getNodeBounds(newSelectedNode));
                }
                consumed = true;
            }

            break;
        }

        case Keyboard.KeyCode.DOWN: {
            if (selectMode != TreeView.SelectMode.NONE) {
                Path lastSelectedPath = treeView.getLastSelectedPath();

                int index;
                if (lastSelectedPath != null) {
                    NodeInfo previousSelectedNode = getNodeInfoAt(lastSelectedPath);
                    index = visibleNodes.indexOf(previousSelectedNode);
                } else {
                    // Select the first visible node
                    index = -1;
                }

                NodeInfo newSelectedNode = null;
                int n = visibleNodes.getLength();
                do {
                    newSelectedNode = (++index <= n - 1) ? visibleNodes.get(index) : null;
                } while (newSelectedNode != null
                    && newSelectedNode.isDisabled());

                if (newSelectedNode != null) {
                    if (Keyboard.isPressed(Keyboard.Modifier.SHIFT)
                        && treeView.getSelectMode() == TreeView.SelectMode.MULTI) {
                        treeView.addSelectedPath(newSelectedNode.getPath());
                    } else {
                        treeView.setSelectedPath(newSelectedNode.getPath());
                    }
                    treeView.scrollAreaToVisible(getNodeBounds(newSelectedNode));
                }
                consumed = true;
            }

            break;
        }

        case Keyboard.KeyCode.LEFT: {
            if (showBranchControls) {
                Sequence<Path> paths = treeView.getSelectedPaths();

                if (paths != null
                    && paths.getLength() > 0) {
                    Path path = paths.get(paths.getLength() - 1);
                    NodeInfo nodeInfo = getNodeInfoAt(path);

                    if (nodeInfo instanceof BranchInfo) {
                        BranchInfo branchInfo = (BranchInfo)nodeInfo;

                        if (branchInfo.isExpanded()) {
                            treeView.collapseBranch(branchInfo.getPath());
                        }
                    }

                    consumed = true;
                }
            }

            break;
        }

        case Keyboard.KeyCode.RIGHT: {
            if (showBranchControls) {
                Sequence<Path> paths = treeView.getSelectedPaths();

                if (paths != null
                    && paths.getLength() > 0) {
                    Path path = paths.get(paths.getLength() - 1);
                    NodeInfo nodeInfo = getNodeInfoAt(path);

                    if (nodeInfo instanceof BranchInfo) {
                        BranchInfo branchInfo = (BranchInfo)nodeInfo;
View Full Code Here

        TreeView treeView = (TreeView)getComponent();

        if (keyCode == Keyboard.KeyCode.SPACE) {
            if (treeView.getCheckmarksEnabled()
                && treeView.getSelectMode() == TreeView.SelectMode.SINGLE) {
                Path selectedPath = treeView.getSelectedPath();

                if (selectedPath != null) {
                    NodeInfo nodeInfo = getNodeInfoAt(selectedPath);

                    if (!nodeInfo.isCheckmarkDisabled()) {
View Full Code Here

TOP

Related Classes of org.apache.pivot.collections.Sequence.Tree.Path

Copyright © 2018 www.massapicom. 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.