Search in sources :

Example 1 with TreeViewSelectionListener

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

the class ComponentExplorerWindow method initialize.

@Override
public void initialize(Map<String, Object> namespace, URL location, Resources resources) {
    splitPane = (SplitPane) namespace.get("splitPane");
    treeView = (TreeView) namespace.get("treeView");
    contentScrollPane = (ScrollPane) namespace.get("contentScrollPane");
    contentPane = (Border) namespace.get("contentPane");
    sourceTextArea = (TextArea) namespace.get("sourceTextArea");
    componentPropertyInspector = (ComponentPropertyInspector) namespace.get("componentPropertyInspector");
    componentStyleInspector = (ComponentStyleInspector) namespace.get("componentStyleInspector");
    eventLogger = (EventLogger) namespace.get("eventLogger");
    horizontalScrollBarPolicyGroup = (ButtonGroup) namespace.get("horizontalScrollBarPolicyGroup");
    verticalScrollBarPolicyGroup = (ButtonGroup) namespace.get("verticalScrollBarPolicyGroup");
    horizontalAutoButton = (Button) namespace.get("horizontalAutoButton");
    horizontalFillButton = (Button) namespace.get("horizontalFillButton");
    horizontalFillToCapacityButton = (Button) namespace.get("horizontalFillToCapacityButton");
    horizontalNeverButton = (Button) namespace.get("horizontalNeverButton");
    horizontalAlwaysButton = (Button) namespace.get("horizontalAlwaysButton");
    verticalAutoButton = (Button) namespace.get("verticalAutoButton");
    verticalFillButton = (Button) namespace.get("verticalFillButton");
    verticalFillToCapacityButton = (Button) namespace.get("verticalFillToCapacityButton");
    verticalNeverButton = (Button) namespace.get("verticalNeverButton");
    verticalAlwaysButton = (Button) namespace.get("verticalAlwaysButton");
    treeView.getTreeViewSelectionListeners().add(new TreeViewSelectionListener() {

        @Override
        public void selectedPathsChanged(TreeView treeViewArgument, Sequence<Path> previousSelectedPaths) {
            Component component = null;
            Object node = treeViewArgument.getSelectedNode();
            if (node instanceof ComponentNode) {
                ComponentNode componentNode = (ComponentNode) node;
                URL url = componentNode.getSrc();
                try {
                    sourceTextArea.setText(url);
                } catch (IOException exception) {
                    throw new RuntimeException(exception);
                }
                BXMLSerializer bxmlSerializer = new BXMLSerializer();
                try {
                    component = (Component) bxmlSerializer.readObject(url);
                } catch (IOException exception) {
                    throw new RuntimeException(exception);
                } catch (SerializationException exception) {
                    throw new RuntimeException(exception);
                }
                switch(componentNode.getHorizontalScrollBarPolicy()) {
                    case AUTO:
                        horizontalScrollBarPolicyGroup.setSelection(horizontalAutoButton);
                        break;
                    case FILL:
                        horizontalScrollBarPolicyGroup.setSelection(horizontalFillButton);
                        break;
                    case FILL_TO_CAPACITY:
                        horizontalScrollBarPolicyGroup.setSelection(horizontalFillToCapacityButton);
                        break;
                    case NEVER:
                        horizontalScrollBarPolicyGroup.setSelection(horizontalNeverButton);
                        break;
                    case ALWAYS:
                        horizontalScrollBarPolicyGroup.setSelection(horizontalAlwaysButton);
                        break;
                    default:
                        break;
                }
                switch(componentNode.getVerticalScrollBarPolicy()) {
                    case AUTO:
                        verticalScrollBarPolicyGroup.setSelection(verticalAutoButton);
                        break;
                    case FILL:
                        verticalScrollBarPolicyGroup.setSelection(verticalFillButton);
                        break;
                    case FILL_TO_CAPACITY:
                        verticalScrollBarPolicyGroup.setSelection(verticalFillToCapacityButton);
                        break;
                    case NEVER:
                        verticalScrollBarPolicyGroup.setSelection(verticalNeverButton);
                        break;
                    case ALWAYS:
                        verticalScrollBarPolicyGroup.setSelection(verticalAlwaysButton);
                        break;
                    default:
                        break;
                }
            } else {
                sourceTextArea.setText("");
            }
            contentPane.setContent(component);
            componentPropertyInspector.setSource(component);
            componentStyleInspector.setSource(component);
            eventLogger.setSource(component);
            eventLogger.clearLog();
        }
    });
    treeView.getComponentMouseButtonListeners().add(new ComponentMouseButtonListener() {

        @Override
        public boolean mouseClick(Component component, Mouse.Button button, int x, int y, int count) {
            if (button == Mouse.Button.LEFT && count == 2) {
                Path path = treeView.getNodeAt(y);
                if (path != null) {
                    List<?> treeData = treeView.getTreeData();
                    Object node = Tree.get(treeData, path);
                    if (node instanceof List<?>) {
                        treeView.setBranchExpanded(path, !treeView.isBranchExpanded(path));
                    }
                }
            }
            return false;
        }
    });
    horizontalScrollBarPolicyGroup.getButtonGroupListeners().add(new ButtonGroupListener() {

        @Override
        public void selectionChanged(ButtonGroup buttonGroup, Button previousSelection) {
            Button button = buttonGroup.getSelection();
            ScrollBarPolicy horizontalScrollBarPolicy = null;
            if (button == horizontalAutoButton) {
                horizontalScrollBarPolicy = ScrollBarPolicy.AUTO;
            } else if (button == horizontalFillButton) {
                horizontalScrollBarPolicy = ScrollBarPolicy.FILL;
            } else if (button == horizontalFillToCapacityButton) {
                horizontalScrollBarPolicy = ScrollBarPolicy.FILL_TO_CAPACITY;
            } else if (button == horizontalNeverButton) {
                horizontalScrollBarPolicy = ScrollBarPolicy.NEVER;
            } else if (button == horizontalAlwaysButton) {
                horizontalScrollBarPolicy = ScrollBarPolicy.ALWAYS;
            }
            if (horizontalScrollBarPolicy != null) {
                contentScrollPane.setHorizontalScrollBarPolicy(horizontalScrollBarPolicy);
            }
        }
    });
    verticalScrollBarPolicyGroup.getButtonGroupListeners().add(new ButtonGroupListener() {

        @Override
        public void selectionChanged(ButtonGroup buttonGroup, Button previousSelection) {
            Button button = buttonGroup.getSelection();
            ScrollBarPolicy verticalScrollBarPolicy = null;
            if (button == verticalAutoButton) {
                verticalScrollBarPolicy = ScrollBarPolicy.AUTO;
            } else if (button == verticalFillButton) {
                verticalScrollBarPolicy = ScrollBarPolicy.FILL;
            } else if (button == verticalFillToCapacityButton) {
                verticalScrollBarPolicy = ScrollBarPolicy.FILL_TO_CAPACITY;
            } else if (button == verticalNeverButton) {
                verticalScrollBarPolicy = ScrollBarPolicy.NEVER;
            } else if (button == verticalAlwaysButton) {
                verticalScrollBarPolicy = ScrollBarPolicy.ALWAYS;
            }
            if (verticalScrollBarPolicy != null) {
                contentScrollPane.setVerticalScrollBarPolicy(verticalScrollBarPolicy);
            }
        }
    });
}
Also used : Path(org.apache.pivot.collections.Sequence.Tree.Path) SerializationException(org.apache.pivot.serialization.SerializationException) IOException(java.io.IOException) URL(java.net.URL) ButtonGroupListener(org.apache.pivot.wtk.ButtonGroupListener) Mouse(org.apache.pivot.wtk.Mouse) ButtonGroup(org.apache.pivot.wtk.ButtonGroup) Button(org.apache.pivot.wtk.Button) ScrollBarPolicy(org.apache.pivot.wtk.ScrollPane.ScrollBarPolicy) TreeViewSelectionListener(org.apache.pivot.wtk.TreeViewSelectionListener) TreeView(org.apache.pivot.wtk.TreeView) ComponentMouseButtonListener(org.apache.pivot.wtk.ComponentMouseButtonListener) List(org.apache.pivot.collections.List) Component(org.apache.pivot.wtk.Component) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer)

Example 2 with TreeViewSelectionListener

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

the class Pivot718 method controlTree.

private void controlTree(BXMLSerializer bxmlSerializer) {
    treeDelButton = (PushButton) bxmlSerializer.getNamespace().get("treeDelButton");
    tree = (TreeView) bxmlSerializer.getNamespace().get("tree");
    tree.getTreeViewSelectionListeners().add(new TreeViewSelectionListener() {

        @Override
        public void selectedPathAdded(TreeView treeView, Path path) {
            System.out.println("selectedPathAdded");
        }

        @Override
        public void selectedPathRemoved(TreeView treeView, Path path) {
            System.out.println("selectedPathRemoved");
        }

        @Override
        public void selectedPathsChanged(TreeView treeView, Sequence<Path> previousSelectedPaths) {
            System.out.println("selectedPathsChanged");
        }

        @Override
        public void selectedNodeChanged(TreeView treeView, Object previousSelectedNode) {
            System.out.println("selectedNodeChanged");
        }
    });
    treeDelButton.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            TreeNode selectedNode = (TreeNode) tree.getSelectedNode();
            System.out.println("delete :: " + selectedNode);
            if (selectedNode != null) {
                TreeBranch parent = selectedNode.getParent();
                if (parent != null) {
                    parent.remove(selectedNode);
                }
            }
        }
    });
}
Also used : Path(org.apache.pivot.collections.Sequence.Tree.Path) ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) TreeBranch(org.apache.pivot.wtk.content.TreeBranch) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) TreeNode(org.apache.pivot.wtk.content.TreeNode) TreeViewSelectionListener(org.apache.pivot.wtk.TreeViewSelectionListener) TreeView(org.apache.pivot.wtk.TreeView)

Example 3 with TreeViewSelectionListener

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

the class Pivot734 method controlTree.

private void controlTree(BXMLSerializer bxmlSerializer) {
    treeButtonAdd = (PushButton) bxmlSerializer.getNamespace().get("treeButtonAdd");
    treeButtonRemove = (PushButton) bxmlSerializer.getNamespace().get("treeButtonRemove");
    tree = (TreeView) bxmlSerializer.getNamespace().get("tree");
    boolean treeStyleForShowEmptyBranchControls = tree.getStyles().getBoolean(Style.showEmptyBranchControls);
    System.out.println("tree style for showEmptyBranchControls is " + treeStyleForShowEmptyBranchControls);
    tree.getTreeViewSelectionListeners().add(new TreeViewSelectionListener() {

        @Override
        public void selectedPathAdded(TreeView treeView, Path path) {
            System.out.println("selectedPathAdded");
        }

        @Override
        public void selectedPathRemoved(TreeView treeView, Path path) {
            System.out.println("selectedPathRemoved");
        }

        @Override
        public void selectedPathsChanged(TreeView treeView, Sequence<Path> previousSelectedPaths) {
            System.out.println("selectedPathsChanged");
        }

        @Override
        public void selectedNodeChanged(TreeView treeView, Object previousSelectedNode) {
            System.out.println("selectedNodeChanged");
        }
    });
    treeButtonAdd.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            Object x = tree.getSelectedNode();
            System.out.println("add a 'new branch' element to the selected element :: " + x);
            if (x != null && x instanceof TreeBranch) {
                ((TreeBranch) x).add(newBranch);
            }
        }
    });
    treeButtonRemove.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            Object x = tree.getSelectedNode();
            System.out.println("remove a 'new branch' element under the selected element :: " + x);
            if (x != null && x instanceof TreeBranch) {
                ((TreeBranch) x).remove(newBranch);
            }
        }
    });
}
Also used : Path(org.apache.pivot.collections.Sequence.Tree.Path) ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) TreeBranch(org.apache.pivot.wtk.content.TreeBranch) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) TreeViewSelectionListener(org.apache.pivot.wtk.TreeViewSelectionListener) TreeView(org.apache.pivot.wtk.TreeView)

Example 4 with TreeViewSelectionListener

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

the class Pivot734WithWorkaround method controlTree.

private void controlTree(BXMLSerializer bxmlSerializer) {
    treeButtonAdd = (PushButton) bxmlSerializer.getNamespace().get("treeButtonAdd");
    treeButtonRemove = (PushButton) bxmlSerializer.getNamespace().get("treeButtonRemove");
    tree = (TreeView) bxmlSerializer.getNamespace().get("tree");
    boolean treeStyleForShowEmptyBranchControls = tree.getStyles().getBoolean(Style.showEmptyBranchControls);
    System.out.println("tree style for showEmptyBranchControls is " + treeStyleForShowEmptyBranchControls);
    tree.getTreeViewSelectionListeners().add(new TreeViewSelectionListener() {

        @Override
        public void selectedPathAdded(TreeView treeView, Path path) {
            System.out.println("selectedPathAdded");
        }

        @Override
        public void selectedPathRemoved(TreeView treeView, Path path) {
            System.out.println("selectedPathRemoved");
        }

        @Override
        public void selectedPathsChanged(TreeView treeView, Sequence<Path> previousSelectedPaths) {
            System.out.println("selectedPathsChanged");
        }

        @Override
        public void selectedNodeChanged(TreeView treeView, Object previousSelectedNode) {
            System.out.println("selectedNodeChanged");
        }
    });
    treeButtonAdd.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            Object x = tree.getSelectedNode();
            System.out.println("add a 'new branch' element to the selected element :: " + x);
            if (x != null && x instanceof TreeBranch) {
                // workaround for PIVOT-734
                Path path = tree.getSelectedPath();
                tree.setBranchExpanded(path, true);
                // end of workaround for PIVOT-734
                ((TreeBranch) x).add(newBranch);
            }
        }
    });
    treeButtonRemove.getButtonPressListeners().add(new ButtonPressListener() {

        @Override
        public void buttonPressed(Button button) {
            Object x = tree.getSelectedNode();
            System.out.println("remove a 'new branch' element under the selected element :: " + x);
            if (x != null && x instanceof TreeBranch) {
                ((TreeBranch) x).remove(newBranch);
            }
        }
    });
}
Also used : Path(org.apache.pivot.collections.Sequence.Tree.Path) ButtonPressListener(org.apache.pivot.wtk.ButtonPressListener) TreeBranch(org.apache.pivot.wtk.content.TreeBranch) PushButton(org.apache.pivot.wtk.PushButton) Button(org.apache.pivot.wtk.Button) TreeViewSelectionListener(org.apache.pivot.wtk.TreeViewSelectionListener) TreeView(org.apache.pivot.wtk.TreeView)

Example 5 with TreeViewSelectionListener

use of org.apache.pivot.wtk.TreeViewSelectionListener 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)5 TreeView (org.apache.pivot.wtk.TreeView)5 TreeViewSelectionListener (org.apache.pivot.wtk.TreeViewSelectionListener)5 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)3 IOException (java.io.IOException)2 SerializationException (org.apache.pivot.serialization.SerializationException)2 Component (org.apache.pivot.wtk.Component)2 ComponentMouseButtonListener (org.apache.pivot.wtk.ComponentMouseButtonListener)2 TreeNode (org.apache.pivot.wtk.content.TreeNode)2 URL (java.net.URL)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)1 List (org.apache.pivot.collections.List)1 ButtonGroup (org.apache.pivot.wtk.ButtonGroup)1 ButtonGroupListener (org.apache.pivot.wtk.ButtonGroupListener)1 LinkButton (org.apache.pivot.wtk.LinkButton)1 Mouse (org.apache.pivot.wtk.Mouse)1