Search in sources :

Example 11 with TreeView

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

the class TerraTreeViewSkin method mouseUp.

@Override
public boolean mouseUp(Component component, Mouse.Button button, int x, int y) {
    boolean consumed = super.mouseUp(component, button, x, y);
    TreeView treeView = (TreeView) getComponent();
    if (selectPath != null && !treeView.getFirstSelectedPath().equals(treeView.getLastSelectedPath())) {
        treeView.setSelectedPath(selectPath);
        selectPath = null;
    }
    return consumed;
}
Also used : TreeView(org.apache.pivot.wtk.TreeView)

Example 12 with TreeView

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

the class TerraTreeViewSkin method getNodeIndent.

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

Example 13 with TreeView

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

the class TerraTreeViewSkin method keyPressed.

/**
 * {@link KeyCode#UP UP} Selects the previous enabled node when select mode
 * is not {@link SelectMode#NONE}<br> {@link KeyCode#DOWN DOWN} Selects the
 * next enabled node when select mode is not {@link SelectMode#NONE}<p>
 * {@link Modifier#SHIFT SHIFT} + {@link KeyCode#UP UP} Increases the
 * selection size by including the previous enabled node when select mode is
 * {@link SelectMode#MULTI}<br> {@link Modifier#SHIFT SHIFT} +
 * {@link KeyCode#DOWN DOWN} Increases the selection size by including the
 * next enabled node when select mode is {@link SelectMode#MULTI}
 */
@Override
public boolean keyPressed(Component component, int keyCode, Keyboard.KeyLocation keyLocation) {
    boolean consumed = false;
    TreeView treeView = (TreeView) getComponent();
    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;
                            if (!branchInfo.isExpanded()) {
                                treeView.expandBranch(branchInfo.getPath());
                            }
                        }
                        consumed = true;
                    }
                }
                break;
            }
        default:
            consumed = super.keyPressed(component, keyCode, keyLocation);
            break;
    }
    if (consumed) {
        clearHighlightedNode();
    }
    return consumed;
}
Also used : Path(org.apache.pivot.collections.Sequence.Tree.Path) GeneralPath(java.awt.geom.GeneralPath) TreeView(org.apache.pivot.wtk.TreeView) Sequence(org.apache.pivot.collections.Sequence) SelectMode(org.apache.pivot.wtk.TreeView.SelectMode)

Example 14 with TreeView

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

the class TerraTreeViewSkin method mouseClick.

@Override
public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count) {
    boolean consumed = super.mouseClick(component, button, x, y, count);
    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;
            if (treeView.getCheckmarksEnabled() && !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) {
                    TreeView.NodeEditor nodeEditor = treeView.getNodeEditor();
                    if (nodeEditor != null) {
                        if (nodeEditor.isEditing()) {
                            nodeEditor.endEdit(true);
                        }
                        nodeEditor.beginEdit(treeView, selectPath);
                    }
                }
                selectPath = null;
            }
        }
    }
    return consumed;
}
Also used : Path(org.apache.pivot.collections.Sequence.Tree.Path) GeneralPath(java.awt.geom.GeneralPath) TreeView(org.apache.pivot.wtk.TreeView)

Example 15 with TreeView

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

the class TerraTreeViewSkin method getNodeHeight.

/**
 * @return The fixed node height of this skin.
 */
protected int getNodeHeight() {
    TreeView treeView = (TreeView) getComponent();
    TreeView.NodeRenderer nodeRenderer = treeView.getNodeRenderer();
    nodeRenderer.render(null, null, -1, treeView, false, false, TreeView.NodeCheckState.UNCHECKED, false, false);
    int nodeHeight = nodeRenderer.getPreferredHeight(-1);
    if (treeView.getCheckmarksEnabled()) {
        nodeHeight = Math.max(CHECKBOX.getHeight() + (2 * CHECKBOX_VERTICAL_PADDING), nodeHeight);
    }
    return nodeHeight;
}
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