Search in sources :

Example 6 with TreeBranch

use of org.apache.pivot.wtk.content.TreeBranch in project pivot by apache.

the class JSONViewer method build.

@SuppressWarnings("unchecked")
private static TreeNode build(Object value) {
    TreeNode treeNode;
    if (value instanceof Map<?, ?>) {
        TreeBranch treeBranch = new TreeBranch("{}");
        treeBranch.setComparator(new Comparator<TreeNode>() {

            @Override
            public int compare(TreeNode treeNode1, TreeNode treeNode2) {
                return treeNode1.getText().compareTo(treeNode2.getText());
            }
        });
        Map<String, Object> map = (Map<String, Object>) value;
        for (String key : map) {
            TreeNode valueNode = build(map.get(key));
            String text = valueNode.getText();
            if (text == null) {
                valueNode.setText(key);
            } else {
                valueNode.setText(key + " : " + text);
            }
            treeBranch.add(valueNode);
        }
        treeNode = treeBranch;
    } else if (value instanceof List<?>) {
        TreeBranch treeBranch = new TreeBranch("[]");
        List<Object> list = (List<Object>) value;
        for (int i = 0, n = list.getLength(); i < n; i++) {
            TreeNode itemNode = build(list.get(i));
            String text = itemNode.getText();
            if (text == null) {
                itemNode.setText("[" + i + "]");
            } else {
                itemNode.setText("[" + i + "] " + text);
            }
            treeBranch.add(itemNode);
        }
        treeNode = treeBranch;
    } else if (value instanceof String) {
        treeNode = new TreeNode("\"" + value.toString() + "\"");
    } else if (value instanceof Number) {
        treeNode = new TreeNode(value.toString());
    } else if (value instanceof Boolean) {
        treeNode = new TreeNode(value.toString());
    } else {
        treeNode = new TreeNode("null");
    }
    return treeNode;
}
Also used : TreeBranch(org.apache.pivot.wtk.content.TreeBranch) TreeNode(org.apache.pivot.wtk.content.TreeNode) List(org.apache.pivot.collections.List) FileList(org.apache.pivot.io.FileList) Map(org.apache.pivot.collections.Map)

Example 7 with TreeBranch

use of org.apache.pivot.wtk.content.TreeBranch in project pivot by apache.

the class BXMLExplorerDocument method load.

public void load(File f) throws IOException, SerializationException, ParserConfigurationException, SAXException {
    BXMLSerializer serializer = new BXMLSerializer();
    serializer.setLocation(f.toURI().toURL());
    try (FileInputStream in = new FileInputStream(f)) {
        Object obj = serializer.readObject(in);
        if (!(obj instanceof Component)) {
            throw new IllegalStateException("obj " + obj + " is of class " + obj.getClass() + " which is not a subtype of Component");
        }
        // create an inverse map so we can IDs for widgets
        widgetToID = new HashMap<>();
        for (String key : serializer.getNamespace()) {
            widgetToID.put(serializer.getNamespace().get(key), key);
        }
        // we can't add a Window into the component hierarchy, so fake it
        if (obj instanceof Window) {
            obj = new FakeWindow((Window) obj);
        }
        // create the explorer tree
        componentToTreeNode = new HashMap<>();
        // the root node is not visible
        final TreeBranch rootbranch = new TreeBranch("");
        rootbranch.add(analyseObjectTree(obj));
        treeView.setTreeData(rootbranch);
        treeView.expandAll();
        // add the loaded widget to the display
        this.loadedComponent = (Component) obj;
        playgroundCardPane.add((Component) obj);
    }
    try (FileInputStream in2 = new FileInputStream(f)) {
        CreateHighlightedXML xml = new CreateHighlightedXML();
        bxmlSourceTextPane.setDocument(xml.prettyPrint(in2));
    }
    this.file = f;
}
Also used : Window(org.apache.pivot.wtk.Window) TreeBranch(org.apache.pivot.wtk.content.TreeBranch) Component(org.apache.pivot.wtk.Component) BXMLSerializer(org.apache.pivot.beans.BXMLSerializer) FileInputStream(java.io.FileInputStream)

Example 8 with TreeBranch

use of org.apache.pivot.wtk.content.TreeBranch in project pivot by apache.

the class EventLoggerSkin method sourceChanged.

// EventLoggerListener methods
@Override
public void sourceChanged(EventLogger eventLogger, Component previousSource) {
    // Component source = eventLogger.getSource();
    HashMap<Class<?>, ArrayList<Method>> buckets = new HashMap<>();
    for (Method event : eventLogger.getDeclaredEvents()) {
        Class<?> listenerInterface = event.getDeclaringClass();
        ArrayList<Method> bucket = buckets.get(listenerInterface);
        if (bucket == null) {
            bucket = new ArrayList<>();
            buckets.put(listenerInterface, bucket);
        }
        bucket.add(event);
    }
    ArrayList<TreeNode> treeData = new ArrayList<>(treeNodeComparator);
    declaredEventsTreeView.setTreeData(treeData);
    updating = true;
    try {
        for (Class<?> listenerInterface : buckets) {
            TreeBranch treeBranch = new TreeBranch(listenerInterface.getSimpleName());
            treeBranch.setComparator(treeNodeComparator);
            treeData.add(treeBranch);
            for (Method event : buckets.get(listenerInterface)) {
                treeBranch.add(new EventNode(event));
                eventLogger.getIncludeEvents().add(event);
            }
        }
        Sequence.Tree.ItemIterator<TreeNode> iter = Sequence.Tree.depthFirstIterator(treeData);
        while (iter.hasNext()) {
            iter.next();
            declaredEventsTreeView.setNodeChecked(iter.getPath(), true);
        }
    } finally {
        updating = false;
    }
}
Also used : HashMap(org.apache.pivot.collections.HashMap) ArrayList(org.apache.pivot.collections.ArrayList) Method(java.lang.reflect.Method) TreeBranch(org.apache.pivot.wtk.content.TreeBranch) TreeNode(org.apache.pivot.wtk.content.TreeNode)

Aggregations

TreeBranch (org.apache.pivot.wtk.content.TreeBranch)8 Path (org.apache.pivot.collections.Sequence.Tree.Path)4 TreeNode (org.apache.pivot.wtk.content.TreeNode)4 Button (org.apache.pivot.wtk.Button)3 ButtonPressListener (org.apache.pivot.wtk.ButtonPressListener)3 PushButton (org.apache.pivot.wtk.PushButton)3 TreeView (org.apache.pivot.wtk.TreeView)3 TreeViewSelectionListener (org.apache.pivot.wtk.TreeViewSelectionListener)3 List (org.apache.pivot.collections.List)2 Map (org.apache.pivot.collections.Map)2 FileList (org.apache.pivot.io.FileList)2 Component (org.apache.pivot.wtk.Component)2 FileInputStream (java.io.FileInputStream)1 Method (java.lang.reflect.Method)1 BXMLSerializer (org.apache.pivot.beans.BXMLSerializer)1 BeanAdapter (org.apache.pivot.beans.BeanAdapter)1 DefaultProperty (org.apache.pivot.beans.DefaultProperty)1 ArrayList (org.apache.pivot.collections.ArrayList)1 HashMap (org.apache.pivot.collections.HashMap)1 Sequence (org.apache.pivot.collections.Sequence)1