Search in sources :

Example 86 with DefaultTreeModel

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);
}
Also used : ApkEntry(com.android.tools.idea.apk.viewer.ApkEntry) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Example 87 with DefaultTreeModel

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);
}
Also used : AllIcons(com.intellij.icons.AllIcons) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) SdkConstants(com.android.SdkConstants) VirtualFile(com.intellij.openapi.vfs.VirtualFile) AnimatedIcon(com.intellij.util.ui.AnimatedIcon) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) EdtExecutor(com.android.tools.idea.ddms.EdtExecutor) TreeSelectionListener(javax.swing.event.TreeSelectionListener) AsyncProcessIcon(com.intellij.util.ui.AsyncProcessIcon) Disposer(com.intellij.openapi.util.Disposer) Tree(com.intellij.ui.treeStructure.Tree) ColumnTreeBuilder(com.android.tools.adtui.common.ColumnTreeBuilder) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) AndroidBundle(org.jetbrains.android.util.AndroidBundle) DecimalFormat(java.text.DecimalFormat) com.intellij.ui(com.intellij.ui) FutureCallback(com.google.common.util.concurrent.FutureCallback) SearchUtil(com.intellij.ide.ui.search.SearchUtil) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Nullable(org.jetbrains.annotations.Nullable) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) AndroidIcons(icons.AndroidIcons) Function(com.intellij.util.Function) NotNull(org.jetbrains.annotations.NotNull) javax.swing(javax.swing) AsyncProcessIcon(com.intellij.util.ui.AsyncProcessIcon) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) ColumnTreeBuilder(com.android.tools.adtui.common.ColumnTreeBuilder) Tree(com.intellij.ui.treeStructure.Tree)

Example 88 with DefaultTreeModel

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();
}
Also used : ColumnTreeBuilder(com.android.tools.adtui.common.ColumnTreeBuilder) MemoryInfoTreeNode(com.android.tools.idea.monitor.ui.memory.model.MemoryInfoTreeNode) Tree(com.intellij.ui.treeStructure.Tree) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) Comparator(java.util.Comparator)

Example 89 with DefaultTreeModel

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()));
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Example 90 with DefaultTreeModel

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);
}
Also used : JScrollPane(javax.swing.JScrollPane) JTree(javax.swing.JTree) TreeExpansionListener(javax.swing.event.TreeExpansionListener) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) JFrame(javax.swing.JFrame) TreeNode(javax.swing.tree.TreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) TreeExpansionEvent(javax.swing.event.TreeExpansionEvent)

Aggregations

DefaultTreeModel (javax.swing.tree.DefaultTreeModel)196 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)99 TreePath (javax.swing.tree.TreePath)50 Tree (com.intellij.ui.treeStructure.Tree)22 Test (org.junit.Test)21 JTree (javax.swing.JTree)17 MockTreeModelListener (com.facebook.buck.intellij.ideabuck.test.util.MockTreeModelListener)16 JScrollPane (javax.swing.JScrollPane)16 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)15 TreeSelectionListener (javax.swing.event.TreeSelectionListener)14 ArrayList (java.util.ArrayList)10 TreeNode (javax.swing.tree.TreeNode)10 NotNull (org.jetbrains.annotations.NotNull)10 Module (com.intellij.openapi.module.Module)9 MouseEvent (java.awt.event.MouseEvent)9 DefaultTreeCellRenderer (javax.swing.tree.DefaultTreeCellRenderer)9 Project (com.intellij.openapi.project.Project)7 javax.swing (javax.swing)7 JPanel (javax.swing.JPanel)7 ColumnTreeBuilder (com.android.tools.adtui.common.ColumnTreeBuilder)6