Search in sources :

Example 6 with TreeView

use of org.apache.pivot.wtk.TreeView in project pivot by apache.

the class TerraTreeViewSkin method getBaseline.

@Override
public int getBaseline(int width, int height) {
    int baseline = -1;
    if (visibleNodes.getLength() > 0) {
        TreeView treeView = (TreeView) getComponent();
        TreeView.NodeRenderer nodeRenderer = treeView.getNodeRenderer();
        NodeInfo nodeInfo = visibleNodes.get(0);
        int nodeWidth = width - (nodeInfo.depth - 1) * (indent + spacing);
        int nodeHeight = getNodeHeight();
        boolean expanded = false;
        boolean selected = nodeInfo.isSelected();
        boolean highlighted = nodeInfo.isHighlighted();
        boolean disabled = nodeInfo.isDisabled();
        if (showBranchControls) {
            if (nodeInfo instanceof BranchInfo) {
                BranchInfo branchInfo = (BranchInfo) nodeInfo;
                expanded = branchInfo.isExpanded();
            }
            nodeWidth -= (indent + spacing);
        }
        TreeView.NodeCheckState checkState = TreeView.NodeCheckState.UNCHECKED;
        if (treeView.getCheckmarksEnabled()) {
            checkState = nodeInfo.getCheckState();
            nodeWidth -= (Math.max(indent, CHECKBOX.getWidth()) + spacing);
        }
        nodeRenderer.render(nodeInfo.data, nodeInfo.getPath(), 0, treeView, expanded, selected, checkState, highlighted, disabled);
        baseline = nodeRenderer.getBaseline(nodeWidth, nodeHeight);
    }
    return baseline;
}
Also used : TreeView(org.apache.pivot.wtk.TreeView)

Example 7 with TreeView

use of org.apache.pivot.wtk.TreeView in project pivot by apache.

the class TerraTreeViewSkin method getPreferredWidth.

@Override
public int getPreferredWidth(int height) {
    TreeView treeView = (TreeView) getComponent();
    TreeView.NodeRenderer nodeRenderer = treeView.getNodeRenderer();
    int preferredWidth = 0;
    VisibleNodeIterator visibleNodeIterator = new VisibleNodeIterator();
    while (visibleNodeIterator.hasNext()) {
        NodeInfo nodeInfo = visibleNodeIterator.next();
        int nodeWidth = (nodeInfo.depth - 1) * (indent + spacing);
        nodeRenderer.render(nodeInfo.data, visibleNodeIterator.getPath(), visibleNodeIterator.getRowIndex(), 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;
}
Also used : TreeView(org.apache.pivot.wtk.TreeView)

Example 8 with TreeView

use of org.apache.pivot.wtk.TreeView in project pivot by apache.

the class TerraTreeViewSkin method keyReleased.

/**
 * {@link KeyCode#SPACE SPACE} toggles check mark selection when select mode
 * is {@link SelectMode#SINGLE}
 */
@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);
    }
    return consumed;
}
Also used : Path(org.apache.pivot.collections.Sequence.Tree.Path) GeneralPath(java.awt.geom.GeneralPath) TreeView(org.apache.pivot.wtk.TreeView)

Example 9 with TreeView

use of org.apache.pivot.wtk.TreeView in project pivot by apache.

the class TerraTreeViewSkin method mouseDown.

@Override
public boolean mouseDown(Component component, Mouse.Button button, int x, int y) {
    boolean consumed = super.mouseDown(component, button, x, y);
    if (!consumed) {
        TreeView treeView = (TreeView) getComponent();
        NodeInfo nodeInfo = getNodeInfoAt(y);
        if (nodeInfo != null && !nodeInfo.isDisabled()) {
            int nodeHeight = getNodeHeight();
            int baseNodeX = (nodeInfo.depth - 1) * (indent + spacing);
            int nodeX = baseNodeX + (showBranchControls ? indent + spacing : 0);
            int nodeY = (y / (nodeHeight + VERTICAL_SPACING)) * (nodeHeight + VERTICAL_SPACING);
            int checkboxWidth = CHECKBOX.getWidth();
            int checkboxHeight = CHECKBOX.getHeight();
            int checkboxX = Math.max(indent - checkboxWidth, 0) / 2;
            int checkboxY = (nodeHeight - checkboxHeight) / 2;
            // Only proceed if the user DIDN'T click on a checkbox
            if (!treeView.getCheckmarksEnabled() || nodeInfo.isCheckmarkDisabled() || x < nodeX + checkboxX || x >= nodeX + checkboxX + checkboxWidth || y < nodeY + checkboxY || y >= nodeY + checkboxY + checkboxHeight) {
                Path path = nodeInfo.getPath();
                // a branch. If so, expand/collapse the branch
                if (showBranchControls && nodeInfo instanceof BranchInfo && x >= baseNodeX && x < baseNodeX + indent) {
                    BranchInfo branchInfo = (BranchInfo) nodeInfo;
                    treeView.setBranchExpanded(path, !branchInfo.isExpanded());
                    consumed = true;
                }
                // the selection state of the node
                if (!consumed) {
                    TreeView.SelectMode selectMode = treeView.getSelectMode();
                    if (button == Mouse.Button.LEFT) {
                        Keyboard.Modifier commandModifier = Platform.getCommandModifier();
                        if (Keyboard.isPressed(commandModifier) && selectMode == TreeView.SelectMode.MULTI) {
                            // Toggle the item's selection state
                            if (nodeInfo.isSelected()) {
                                treeView.removeSelectedPath(path);
                            } else {
                                treeView.addSelectedPath(path);
                            }
                        } else if (Keyboard.isPressed(commandModifier) && selectMode == TreeView.SelectMode.SINGLE) {
                            // Toggle the item's selection state
                            if (nodeInfo.isSelected()) {
                                treeView.clearSelection();
                            } else {
                                treeView.setSelectedPath(path);
                            }
                        } else {
                            if (selectMode != TreeView.SelectMode.NONE) {
                                if (nodeInfo.isSelected()) {
                                    selectPath = path;
                                } else {
                                    treeView.setSelectedPath(path);
                                }
                            }
                        }
                    }
                }
            }
        }
        treeView.requestFocus();
    }
    return consumed;
}
Also used : Path(org.apache.pivot.collections.Sequence.Tree.Path) GeneralPath(java.awt.geom.GeneralPath) Modifier(org.apache.pivot.wtk.Keyboard.Modifier) Keyboard(org.apache.pivot.wtk.Keyboard) TreeView(org.apache.pivot.wtk.TreeView) SelectMode(org.apache.pivot.wtk.TreeView.SelectMode)

Example 10 with TreeView

use of org.apache.pivot.wtk.TreeView in project pivot by apache.

the class TerraTreeViewSkin method install.

@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);
}
Also used : TreeView(org.apache.pivot.wtk.TreeView)

Aggregations

TreeView (org.apache.pivot.wtk.TreeView)19 Path (org.apache.pivot.collections.Sequence.Tree.Path)11 GeneralPath (java.awt.geom.GeneralPath)6 Button (org.apache.pivot.wtk.Button)5 TreeViewSelectionListener (org.apache.pivot.wtk.TreeViewSelectionListener)5 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)4 PushButton (org.apache.pivot.wtk.PushButton)4 IOException (java.io.IOException)3 SerializationException (org.apache.pivot.serialization.SerializationException)3 TreeBranch (org.apache.pivot.wtk.content.TreeBranch)3 TreeNode (org.apache.pivot.wtk.content.TreeNode)3 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)2 List (org.apache.pivot.collections.List)2 Component (org.apache.pivot.wtk.Component)2 ComponentMouseButtonListener (org.apache.pivot.wtk.ComponentMouseButtonListener)2 SelectMode (org.apache.pivot.wtk.TreeView.SelectMode)2 Color (java.awt.Color)1 Graphics2D (java.awt.Graphics2D)1 Rectangle (java.awt.Rectangle)1 Method (java.lang.reflect.Method)1