use of com.android.tools.adtui.common.ColumnTreeBuilder in project android by JetBrains.
the class AppTrace method generateTopdownTree.
// Convert a HNode tree into an AppStat tree (better suited for rendition in a ColumnTree).
private JComponent generateTopdownTree(HNode<MethodUsage> graph) {
AppStatTreeNode top = new AppStatTreeNode();
// Intentionally discard first child
graph = graph.getFirstChild();
convertGraphToTree(graph, top);
JTree tree = new JTree(top);
JComponent topdownColumnTree = new ColumnTreeBuilder(tree).addColumn(new ColumnTreeBuilder.ColumnBuilder().setName("Method").setRenderer(new ColoredTreeCellRenderer() {
@Override
public void customizeCellRenderer(@NotNull JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
AppStatTreeNode node = (AppStatTreeNode) value;
append(generateNameForColumn(node.getMethodNamespace(), node.getMethodName(), getSeparator()));
}
})).addColumn(new ColumnTreeBuilder.ColumnBuilder().setName("Inclusive stats").setRenderer(new ColoredTreeCellRenderer() {
@Override
public void customizeCellRenderer(@NotNull JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
AppStatTreeNode node = (AppStatTreeNode) value;
append(String.format("%2.1f%%", node.getPercentageInclusive() * 100));
}
})).addColumn(new ColumnTreeBuilder.ColumnBuilder().setName("Exclusive stats").setRenderer(new ColoredTreeCellRenderer() {
@Override
public void customizeCellRenderer(@NotNull JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) {
AppStatTreeNode node = (AppStatTreeNode) value;
append(String.format("%2.1f%%", node.getPercentageExclusive() * 100));
}
})).build();
return topdownColumnTree;
}
use of com.android.tools.adtui.common.ColumnTreeBuilder in project android by JetBrains.
the class MemoryClassView method ensureTreeInitialized.
private void ensureTreeInitialized(@NotNull JPanel parentPanel, @NotNull HeapObject heapObject) {
if (myClassesTree != null) {
assert myClassesTreeModel != null && myClassesTreeRoot != null;
return;
}
myClassesTreeRoot = new MemoryObjectTreeNode<>(new ClassObject() {
@NotNull
@Override
public List<InstanceAttribute> getInstanceAttributes() {
return Collections.emptyList();
}
});
myClassesTreeModel = new DefaultTreeModel(myClassesTreeRoot);
JTree tree = new Tree(myClassesTreeModel);
tree.setRootVisible(false);
tree.setShowsRootHandles(true);
tree.addTreeSelectionListener(e -> {
TreePath path = e.getPath();
if (!e.isAddedPath()) {
return;
}
assert path.getLastPathComponent() instanceof MemoryObjectTreeNode;
MemoryObjectTreeNode classObject = (MemoryObjectTreeNode) path.getLastPathComponent();
assert classObject.getAdapter() instanceof ClassObject;
myStage.selectClass((ClassObject) classObject.getAdapter());
});
List<HeapObject.ClassAttribute> attributes = heapObject.getClassAttributes();
ColumnTreeBuilder builder = new ColumnTreeBuilder(tree);
for (ClassAttribute attribute : attributes) {
builder.addColumn(myAttributeColumns.get(attribute).getBuilder());
}
builder.setTreeSorter((Comparator<MemoryObjectTreeNode<ClassObject>> comparator, SortOrder sortOrder) -> {
myClassesTreeRoot.sort(comparator);
myClassesTreeModel.nodeStructureChanged(myClassesTreeRoot);
});
builder.setBackground(ProfilerColors.MONITOR_BACKGROUND);
myClassesTree = builder.build();
parentPanel.add(myClassesTree, BorderLayout.CENTER);
}
use of com.android.tools.adtui.common.ColumnTreeBuilder in project android by JetBrains.
the class MemoryInstanceView method ensureTreeInitialized.
private void ensureTreeInitialized(@NotNull JPanel parentPanel) {
if (myTree != null) {
assert myTreeModel != null && myTreeRoot != null;
return;
}
myTreeRoot = new MemoryObjectTreeNode<>(new InstanceObject() {
@NotNull
@Override
public String getName() {
return "";
}
});
myTreeModel = new DefaultTreeModel(myTreeRoot);
JTree tree = new Tree(myTreeModel);
tree.setRootVisible(false);
tree.setShowsRootHandles(true);
tree.addTreeSelectionListener(e -> {
TreePath path = e.getPath();
if (!e.isAddedPath()) {
return;
}
assert path.getLastPathComponent() instanceof MemoryObjectTreeNode;
MemoryObjectTreeNode instanceObject = (MemoryObjectTreeNode) path.getLastPathComponent();
assert instanceObject.getAdapter() instanceof InstanceObject;
InstanceObject selectedInstanceObject = (InstanceObject) instanceObject.getAdapter();
myStage.selectInstance(selectedInstanceObject);
});
// Not all nodes have been populated during buildTree. Here we capture the TreeExpansionEvent to check whether any children
// under the expanded node need to be populated.
tree.addTreeExpansionListener(new TreeExpansionListener() {
@Override
public void treeExpanded(TreeExpansionEvent event) {
TreePath path = event.getPath();
assert path.getLastPathComponent() instanceof MemoryObjectTreeNode;
MemoryObjectTreeNode treeNode = (MemoryObjectTreeNode) path.getLastPathComponent();
for (int i = 0; i < treeNode.getChildCount(); i++) {
assert treeNode.getChildAt(i) instanceof MemoryObjectTreeNode;
MemoryObjectTreeNode childNode = (MemoryObjectTreeNode) treeNode.getChildAt(i);
// Anything below the top level should be FieldObjects
assert childNode.getAdapter() instanceof FieldObject;
FieldObject childObject = (FieldObject) childNode.getAdapter();
if (childObject.getValueType() == ValueType.OBJECT && childNode.getChildCount() == 0) {
populateFields(childNode);
myTreeModel.nodeStructureChanged(childNode);
}
}
}
@Override
public void treeCollapsed(TreeExpansionEvent event) {
// No-op. TODO remove unseen children?
}
});
assert myClassObject != null;
List<InstanceAttribute> attributes = myClassObject.getInstanceAttributes();
ColumnTreeBuilder builder = new ColumnTreeBuilder(tree);
for (InstanceAttribute attribute : attributes) {
builder.addColumn(myAttributeColumns.get(attribute).getBuilder());
}
builder.setTreeSorter((Comparator<MemoryObjectTreeNode<InstanceObject>> comparator, SortOrder sortOrder) -> {
myTreeRoot.sort(comparator);
myTreeModel.nodeStructureChanged(myTreeRoot);
});
builder.setBackground(ProfilerColors.MONITOR_BACKGROUND);
myTree = builder.build();
parentPanel.add(myTree, BorderLayout.CENTER);
}
Aggregations