Package org.apache.pivot.wtk

Examples of org.apache.pivot.wtk.TreeView$NodeEditorListener


    @Override
    public boolean keyReleased(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
        boolean consumed = false;

        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()) {
                        treeView.setNodeChecked(selectedPath,
                            !treeView.isNodeChecked(selectedPath));
                    }
                }
            }
        } else {
            consumed = super.keyReleased(component, keyCode, keyLocation);
View Full Code Here


        return consumed;
    }

    @Override
    public boolean isFocusable() {
        TreeView treeView = (TreeView)getComponent();
        return (treeView.getSelectMode() != TreeView.SelectMode.NONE);
    }
View Full Code Here

        return nodeBounds;
    }

    @Override
    public int getNodeIndent(int depth) {
        TreeView treeView = (TreeView)getComponent();

        int nodeIndent = (depth - 1) * (indent + spacing);

        if (showBranchControls) {
            nodeIndent += indent + spacing;
        }

        if (treeView.getCheckmarksEnabled()) {
            nodeIndent += Math.max(CHECKBOX.getWidth(), indent) + spacing;
        }

        return nodeIndent;
    }
View Full Code Here

        if (!isEditing()) {
            throw new IllegalStateException();
        }

        // Save local reference to members variables before they get cleared
        TreeView treeView = this.treeView;
        Path path = this.path;

        // Preview the changes
        String text = textInput.getText();
        Vote vote = nodeEditorListeners.previewSaveChanges(this, treeView, path, text);

        if (vote == Vote.APPROVE) {
            // Update the node data
            List<?> treeData = treeView.getTreeData();
            TreeNode treeNode = (TreeNode)Sequence.Tree.get(treeData, path);
            treeNode.setText(text);

            // Get a reference to the parent of the node data
            int n = path.getLength();
            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);
            }

            // Notifying the parent will close the popup
            if (parentData.getComparator() == null) {
                parentData.update(path.get(n - 1), treeNode);
            } 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));
            }

            nodeEditorListeners.changesSaved(this, treeView, path);
        } else if (vote == Vote.DENY) {
            nodeEditorListeners.saveChangesVetoed(this, vote);
View Full Code Here

        if (!isEditing()) {
            throw new IllegalStateException();
        }

        // Save local reference to members variables before they get cleared
        TreeView treeView = this.treeView;
        Path path = this.path;

        popup.close();

        nodeEditorListeners.editCancelled(this, treeView, path);
View Full Code Here

        // Notifying the parent will close the popup
        if (parentData.getComparator() == null) {
            parentData.update(path.get(n - 1), treeNode);
        } else {
            // Save local reference to members variables before they get cleared
            TreeView treeView = this.treeView;
            Path path = this.path;

            parentData.remove(path.get(n - 1), 1);
            parentData.add(treeNode);

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

    @Override
    public void install(Component component) {
        super.install(component);

        TreeView treeView = (TreeView)component;
        treeView.getTreeViewListeners().add(this);
        treeView.getTreeViewBranchListeners().add(this);
        treeView.getTreeViewNodeListeners().add(this);
        treeView.getTreeViewNodeStateListeners().add(this);
        treeView.getTreeViewSelectionListeners().add(this);

        treeDataChanged(treeView, null);
    }
View Full Code Here

        treeDataChanged(treeView, null);
    }

    @Override
    public void uninstall() {
        TreeView treeView = (TreeView)getComponent();
        treeView.getTreeViewListeners().remove(this);
        treeView.getTreeViewBranchListeners().remove(this);
        treeView.getTreeViewNodeListeners().remove(this);
        treeView.getTreeViewNodeStateListeners().remove(this);
        treeView.getTreeViewSelectionListeners().remove(this);

        super.uninstall();
    }
View Full Code Here

        super.uninstall();
    }

    @Override
    public int getPreferredWidth(int height) {
        TreeView treeView = (TreeView)getComponent();
        TreeView.NodeRenderer nodeRenderer = treeView.getNodeRenderer();

        int preferredWidth = 0;

        for (int i = 0, n = visibleNodes.getLength(); i < n; i++) {
            NodeInfo nodeInfo = visibleNodes.get(i);

            int nodeWidth = (nodeInfo.depth - 1) * (indent + spacing);

            nodeRenderer.render(nodeInfo.data, treeView, false, false,
                TreeView.NodeCheckState.UNCHECKED, false, false);
            nodeWidth += nodeRenderer.getPreferredWidth(-1);

            preferredWidth = Math.max(preferredWidth, nodeWidth);
        }

        if (showBranchControls) {
            preferredWidth += indent + spacing;
        }

        if (treeView.getCheckmarksEnabled()) {
            preferredWidth += Math.max(CHECKBOX.getWidth(), indent) + spacing;
        }

        return preferredWidth;
    }
View Full Code Here

        // No-op
    }

    @Override
    public void paint(Graphics2D graphics) {
        TreeView treeView = (TreeView)getComponent();
        TreeView.NodeRenderer nodeRenderer = treeView.getNodeRenderer();

        int width = getWidth();
        int height = getHeight();

        int nodeHeight = getNodeHeight();

        // Paint the background
        graphics.setPaint(backgroundColor);
        graphics.fillRect(0, 0, width, height);

        // nodeStart and nodeEnd are both inclusive
        int nodeStart = 0;
        int nodeEnd = visibleNodes.getLength() - 1;

        // Ensure that we only paint items that are visible
        Rectangle clipBounds = graphics.getClipBounds();
        if (clipBounds != null) {
            nodeStart = Math.max(nodeStart, (int)(clipBounds.y
                / (double)(nodeHeight + VERTICAL_SPACING)));
            nodeEnd = Math.min(nodeEnd, (int)((clipBounds.y +
                clipBounds.height) / (double)(nodeHeight + VERTICAL_SPACING)));
        }

        int nodeY = nodeStart * (nodeHeight + VERTICAL_SPACING);

        for (int i = nodeStart; i <= nodeEnd; i++) {
            NodeInfo nodeInfo = visibleNodes.get(i);

            boolean expanded = false;
            boolean highlighted = nodeInfo.isHighlighted();
            boolean selected = nodeInfo.isSelected();
            boolean disabled = nodeInfo.isDisabled();

            int nodeX = (nodeInfo.depth - 1) * (indent + spacing);

            if (treeView.isEnabled()) {
                if (selected) {
                    // Paint the selection state
                    Color selectionBackgroundColor = treeView.isFocused() ?
                        this.selectionBackgroundColor : inactiveSelectionBackgroundColor;
                    graphics.setPaint(selectionBackgroundColor);
                    graphics.fillRect(0, nodeY, width, nodeHeight);
                } else if (highlighted && !disabled) {
                    // Paint the highlight state
                    graphics.setPaint(highlightBackgroundColor);
                    graphics.fillRect(0, nodeY, width, nodeHeight);
                }
            }

            // Paint the expand/collapse control
            if (showBranchControls) {
                if (nodeInfo instanceof BranchInfo) {
                    BranchInfo branchInfo = (BranchInfo)nodeInfo;
                    expanded = branchInfo.isExpanded();

                    Color branchControlColor;

                    if (treeView.isEnabled()
                        && !disabled) {
                        if (selected) {
                            if (treeView.isFocused()) {
                                branchControlColor = branchControlSelectionColor;
                            } else {
                                branchControlColor = branchControlInactiveSelectionColor;
                            }
                        } else {
                            branchControlColor = this.branchControlColor;
                        }
                    } else {
                        branchControlColor = branchControlDisabledColor;
                    }

                    GeneralPath shape = new GeneralPath();

                    int imageX = nodeX + (indent - BRANCH_CONTROL_IMAGE_WIDTH) / 2;
                    int imageY = nodeY + (nodeHeight - BRANCH_CONTROL_IMAGE_HEIGHT) / 2;

                    if (expanded) {
                        shape.moveTo(imageX, imageY + 1);
                        shape.lineTo(imageX + 8, imageY + 1);
                        shape.lineTo(imageX + 4, imageY + 7);
                    } else {
                        shape.moveTo(imageX + 1, imageY);
                        shape.lineTo(imageX + 7, imageY + 4);
                        shape.lineTo(imageX + 1, imageY + 8);
                    }

                    shape.closePath();

                    graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
                        RenderingHints.VALUE_ANTIALIAS_ON);
                    graphics.setPaint(branchControlColor);

                    graphics.fill(shape);
                }

                nodeX += indent + spacing;
            }

            // Paint the checkbox
            TreeView.NodeCheckState checkState = TreeView.NodeCheckState.UNCHECKED;
            if (treeView.getCheckmarksEnabled()) {
                checkState = nodeInfo.getCheckState();

                int checkboxWidth = CHECKBOX.getWidth();
                int checkboxHeight = CHECKBOX.getHeight();

View Full Code Here

TOP

Related Classes of org.apache.pivot.wtk.TreeView$NodeEditorListener

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.