use of javax.swing.tree.DefaultTreeModel in project android by JetBrains.
the class ApkDiffPanel method setRootNode.
private void setRootNode(@NotNull DefaultMutableTreeNode root) {
myTreeModel = new DefaultTreeModel(root);
ApkEntry entry = ApkEntry.fromNode(root);
assert entry != null;
myTree.setPaintBusy(false);
myTree.setRootVisible(false);
myTree.setModel(myTreeModel);
}
use of javax.swing.tree.DefaultTreeModel in project android by JetBrains.
the class ApkViewPanel method createUIComponents.
private void createUIComponents() {
myNameAsyncIcon = new AsyncProcessIcon("aapt xmltree manifest");
mySizeAsyncIcon = new AsyncProcessIcon("estimating apk size");
myTreeModel = new DefaultTreeModel(new LoadingNode());
myTree = new Tree(myTreeModel);
myTree.setShowsRootHandles(true);
// show root node only when showing LoadingNode
myTree.setRootVisible(true);
myTree.setPaintBusy(true);
TreeSpeedSearch treeSpeedSearch = new TreeSpeedSearch(myTree, path -> {
ApkEntry e = ApkEntry.fromNode(path.getLastPathComponent());
if (e == null) {
return null;
}
return e.getPath();
}, true);
// Provides the percentage of the node size to the total size of the APK
PercentRenderer.PercentProvider percentProvider = (jTree, value, row) -> {
ApkEntry entry = ApkEntry.fromNode(value);
ApkEntry rootEntry = ApkEntry.fromNode(jTree.getModel().getRoot());
if (entry == null || rootEntry == null) {
return 0;
} else if (!entry.isCompressedSizeKnown() || !rootEntry.isCompressedSizeKnown()) {
return 0;
} else {
return (double) entry.getCompressedSize() / rootEntry.getCompressedSize();
}
};
ColumnTreeBuilder builder = new ColumnTreeBuilder(myTree).addColumn(new ColumnTreeBuilder.ColumnBuilder().setName("File").setPreferredWidth(600).setHeaderAlignment(SwingConstants.LEADING).setRenderer(new NameRenderer(treeSpeedSearch))).addColumn(new ColumnTreeBuilder.ColumnBuilder().setName("Raw File Size").setPreferredWidth(150).setHeaderAlignment(SwingConstants.TRAILING).setRenderer(new SizeRenderer(false))).addColumn(new ColumnTreeBuilder.ColumnBuilder().setName("Download Size").setPreferredWidth(150).setHeaderAlignment(SwingConstants.TRAILING).setRenderer(new SizeRenderer(true))).addColumn(new ColumnTreeBuilder.ColumnBuilder().setName("% of Total Download size").setPreferredWidth(150).setHeaderAlignment(SwingConstants.LEADING).setRenderer(new PercentRenderer(percentProvider)));
myColumnTreePane = (JScrollPane) builder.build();
myTree.addTreeSelectionListener(this);
}
use of javax.swing.tree.DefaultTreeModel in project android by JetBrains.
the class MemoryDetailSegment method createComponentsList.
@Override
public void createComponentsList(@NotNull List<Animatable> animatables) {
mTreeModel = new DefaultTreeModel(mRoot);
mTree = new Tree(mTreeModel);
mTree.setRootVisible(false);
mTree.setShowsRootHandles(true);
ColumnTreeBuilder builder = new ColumnTreeBuilder(mTree).addColumn(new ColumnTreeBuilder.ColumnBuilder().setName("Class").setHeaderAlignment(SwingConstants.LEFT).setRenderer(new MemoryInfoColumnRenderer(0, mRoot))).addColumn(new ColumnTreeBuilder.ColumnBuilder().setName("Count").setHeaderAlignment(SwingConstants.LEFT).setRenderer(new MemoryInfoColumnRenderer(1, mRoot)).setInitialOrder(SortOrder.DESCENDING).setComparator((MemoryInfoTreeNode a, MemoryInfoTreeNode b) -> a.getCount() - b.getCount()));
builder.setTreeSorter((Comparator<MemoryInfoTreeNode> comparator, SortOrder sortOrder) -> {
mRoot.sort(comparator);
mTreeModel.nodeStructureChanged(mRoot);
});
mColumnTree = builder.build();
}
use of javax.swing.tree.DefaultTreeModel in project android by JetBrains.
the class LicenseAgreementStep method setChanges.
private void setChanges(List<Change> changes) {
Map<String, DefaultMutableTreeNode> licenseNodeMap = Maps.newHashMap();
myVisibleLicenses.clear();
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
DefaultMutableTreeNode firstChild = null;
for (Change change : changes) {
String licenseRef = change.license.getId();
myVisibleLicenses.add(licenseRef);
if (!licenseNodeMap.containsKey(licenseRef)) {
DefaultMutableTreeNode n = new DefaultMutableTreeNode(change.license);
if (firstChild == null) {
firstChild = n;
}
licenseNodeMap.put(licenseRef, n);
myAcceptances.put(licenseRef, Boolean.FALSE);
root.add(n);
}
licenseNodeMap.get(licenseRef).add(new DefaultMutableTreeNode(change));
}
myTreeModel = new DefaultTreeModel(root);
myChangeTree.setModel(myTreeModel);
expandTree();
if (firstChild != null) {
myChangeTree.setSelectionPath(new TreePath(firstChild.getPath()));
}
}
use of javax.swing.tree.DefaultTreeModel in project jdk8u_jdk by JetBrains.
the class bug6505523 method createAndShowGUI.
private static void createAndShowGUI() {
final DefaultMutableTreeNode root = new DefaultMutableTreeNode("Problem with NPE under JDK 1.6");
final DefaultMutableTreeNode problematic = new DefaultMutableTreeNode("Expand me and behold a NPE in stderr");
problematic.add(new DefaultMutableTreeNode("some content"));
root.add(new DefaultMutableTreeNode("irrelevant..."));
root.add(problematic);
final DefaultTreeModel model = new DefaultTreeModel(root);
tree = new JTree(model);
tree.setRootVisible(true);
tree.setShowsRootHandles(true);
tree.expandRow(0);
tree.collapseRow(2);
// this is critical - without dragEnabled everything works
tree.setDragEnabled(true);
tree.addTreeExpansionListener(new TreeExpansionListener() {
@Override
public void treeExpanded(TreeExpansionEvent event) {
TreeNode parent = problematic.getParent();
if (parent instanceof DefaultMutableTreeNode) {
model.removeNodeFromParent(problematic);
}
}
@Override
public void treeCollapsed(TreeExpansionEvent event) {
}
});
JFrame frame = new JFrame("JTree Problem");
frame.add(new JScrollPane(tree));
frame.setSize(500, 300);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
Aggregations