Search in sources :

Example 16 with Path

use of org.apache.pivot.collections.Sequence.Tree.Path 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 17 with Path

use of org.apache.pivot.collections.Sequence.Tree.Path in project pivot by apache.

the class TerraTreeViewSkin method scrollSelectionToVisible.

/**
 * Scrolls the last visible (expanded) selected node into viewport
 * visibility. If no such node exists, nothing happens. <p> This should only
 * be called when the tree view is valid.
 */
private void scrollSelectionToVisible() {
    TreeView treeView = (TreeView) getComponent();
    Sequence<Path> selectedPaths = treeView.getSelectedPaths();
    int n = selectedPaths.getLength();
    if (n > 0) {
        Bounds nodeBounds = null;
        for (int i = n - 1; i >= 0 && nodeBounds == null; i--) {
            NodeInfo nodeInfo = getNodeInfoAt(selectedPaths.get(i));
            nodeBounds = getNodeBounds(nodeInfo);
        }
        if (nodeBounds != null) {
            Bounds visibleSelectionBounds = treeView.getVisibleArea(nodeBounds);
            if (visibleSelectionBounds != null && visibleSelectionBounds.height < nodeBounds.height) {
                treeView.scrollAreaToVisible(nodeBounds);
            }
        }
    }
}
Also used : Path(org.apache.pivot.collections.Sequence.Tree.Path) GeneralPath(java.awt.geom.GeneralPath) Bounds(org.apache.pivot.wtk.Bounds) TreeView(org.apache.pivot.wtk.TreeView)

Example 18 with Path

use of org.apache.pivot.collections.Sequence.Tree.Path in project pivot by apache.

the class TreeView method getSelectedNode.

/**
 * @return The selected object, or <tt>null</tt> if nothing is selected.
 * Note that technically, the selected path could be backed by a
 * <tt>null</tt> data value. If the caller wishes to distinguish between
 * these cases, they can use <tt>getSelectedPath()</tt> instead.
 */
public Object getSelectedNode() {
    Path path = getSelectedPath();
    Object node = null;
    if (path != null) {
        node = Sequence.Tree.get(treeData, path);
    }
    return node;
}
Also used : Path(org.apache.pivot.collections.Sequence.Tree.Path) ImmutablePath(org.apache.pivot.collections.Sequence.Tree.ImmutablePath)

Example 19 with Path

use of org.apache.pivot.collections.Sequence.Tree.Path in project pivot by apache.

the class TreeViewNodeEditor method endEdit.

@Override
@SuppressWarnings("unchecked")
public void endEdit(boolean result) {
    if (result) {
        // Update the node data
        String text = textInput.getText();
        List<?> treeData = treeView.getTreeData();
        TreeNode treeNode = (TreeNode) Sequence.Tree.get(treeData, path);
        treeNode.setText(text);
        // Get a reference to node's parent
        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);
        }
        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));
        }
    }
    getOwner().moveToFront();
    treeView.requestFocus();
    treeView = null;
    path = null;
    close();
}
Also used : Path(org.apache.pivot.collections.Sequence.Tree.Path) Point(org.apache.pivot.wtk.Point)

Example 20 with Path

use of org.apache.pivot.collections.Sequence.Tree.Path in project pivot by apache.

the class BXMLExplorerDocument method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
    treeView.setSelectMode(SelectMode.SINGLE);
    treeView.setNodeRenderer(new MyTreeViewNodeRenderer());
    treeView.getTreeViewSelectionListeners().add(new TreeViewSelectionListener() {

        private final Decorator focusDecorator = new ShadeDecorator(0.2f, Color.RED);

        private Component previousSelectedComponent = null;

        @Override
        public void selectedNodeChanged(TreeView treeViewArgument, Object previousSelectedNode) {
            TreeNode node = (TreeNode) treeViewArgument.getSelectedNode();
            if (previousSelectedComponent != null && previousSelectedComponent.getDecorators().indexOf(focusDecorator) > -1) {
                previousSelectedComponent.getDecorators().remove(focusDecorator);
                previousSelectedComponent = null;
            }
            if (node == null || !(node.getUserData() instanceof Component)) {
                // TODO make the inspectors able to deal with things like
                // TablePane.Row
                componentPropertyInspector.setSource(null);
                componentStyleInspector.setSource(null);
                return;
            }
            Component selectedComp = (Component) node.getUserData();
            if (selectedComp != null && selectedComp.getDecorators().indexOf(focusDecorator) == -1) {
                selectedComp.getDecorators().add(focusDecorator);
                previousSelectedComponent = selectedComp;
            }
            if (selectedComp instanceof FakeWindow) {
                selectedComp = ((FakeWindow) selectedComp).window;
            }
            componentPropertyInspector.setSource(selectedComp);
            componentStyleInspector.setSource(selectedComp);
        }

        @Override
        public void selectedPathsChanged(TreeView treeViewArgument, Sequence<Path> previousSelectedPaths) {
            // if the selection becomes empty, remove the decorator
            if (treeViewArgument.getSelectedNode() == null && previousSelectedComponent != null && previousSelectedComponent.getDecorators().indexOf(focusDecorator) > -1) {
                previousSelectedComponent.getDecorators().remove(focusDecorator);
            }
        }
    });
    playgroundCardPane.getComponentMouseButtonListeners().add(new ComponentMouseButtonListener() {

        @Override
        public boolean mouseClick(Component component, Button button, int x, int y, int count) {
            if (count == 1) {
                Component comp = playgroundCardPane.getDescendantAt(x, y);
                if (comp != null) {
                    TreeNode treeNode = componentToTreeNode.get(comp);
                    Path path = getPathForNode(treeView, treeNode);
                    if (path != null) {
                        treeView.setSelectedPath(path);
                        return true;
                    }
                }
            }
            return false;
        }
    });
    reloadButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(org.apache.pivot.wtk.Button button) {
            playgroundCardPane.remove(loadedComponent);
            widgetToID = null;
            componentToTreeNode = null;
            loadedComponent = null;
            try {
                load(file);
            } catch (RuntimeException exception) {
                exception.printStackTrace();
                BXMLExplorer.displayLoadException(exception, BXMLExplorerDocument.this.getWindow());
            } catch (IOException exception) {
                exception.printStackTrace();
                BXMLExplorer.displayLoadException(exception, BXMLExplorerDocument.this.getWindow());
            } catch (SerializationException exception) {
                exception.printStackTrace();
                BXMLExplorer.displayLoadException(exception, BXMLExplorerDocument.this.getWindow());
            } catch (ParserConfigurationException exception) {
                exception.printStackTrace();
                BXMLExplorer.displayLoadException(exception, BXMLExplorerDocument.this.getWindow());
            } catch (SAXException exception) {
                exception.printStackTrace();
                BXMLExplorer.displayLoadException(exception, BXMLExplorerDocument.this.getWindow());
            }
        }
    });
}
Also used : Path(org.apache.pivot.collections.Sequence.Tree.Path) ShadeDecorator(org.apache.pivot.wtk.effects.ShadeDecorator) SerializationException(org.apache.pivot.serialization.SerializationException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) Decorator(org.apache.pivot.wtk.effects.Decorator) ShadeDecorator(org.apache.pivot.wtk.effects.ShadeDecorator) ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) LinkButton(org.apache.pivot.wtk.LinkButton) Button(org.apache.pivot.wtk.Mouse.Button) RadioButton(org.apache.pivot.wtk.RadioButton) PushButton(org.apache.pivot.wtk.PushButton) TreeNode(org.apache.pivot.wtk.content.TreeNode) TreeViewSelectionListener(org.apache.pivot.wtk.TreeViewSelectionListener) TreeView(org.apache.pivot.wtk.TreeView) ComponentMouseButtonListener(org.apache.pivot.wtk.ComponentMouseButtonListener) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) Component(org.apache.pivot.wtk.Component)

Aggregations

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