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;
}
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;
}
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;
}
}
Aggregations