Search in sources :

Example 1 with ShadeDecorator

use of org.apache.pivot.wtk.effects.ShadeDecorator 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

IOException (java.io.IOException)1 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)1 Path (org.apache.pivot.collections.Sequence.Tree.Path)1 SerializationException (org.apache.pivot.serialization.SerializationException)1 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)1 Component (org.apache.pivot.wtk.Component)1 ComponentMouseButtonListener (org.apache.pivot.wtk.ComponentMouseButtonListener)1 LinkButton (org.apache.pivot.wtk.LinkButton)1 Button (org.apache.pivot.wtk.Mouse.Button)1 PushButton (org.apache.pivot.wtk.PushButton)1 RadioButton (org.apache.pivot.wtk.RadioButton)1 TreeView (org.apache.pivot.wtk.TreeView)1 TreeViewSelectionListener (org.apache.pivot.wtk.TreeViewSelectionListener)1 TreeNode (org.apache.pivot.wtk.content.TreeNode)1 Decorator (org.apache.pivot.wtk.effects.Decorator)1 ShadeDecorator (org.apache.pivot.wtk.effects.ShadeDecorator)1 SAXException (org.xml.sax.SAXException)1