From e69b3e2eb0e98a250d1af915ed74ea6db2d433b6 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Wed, 1 Apr 2015 12:32:43 +0300 Subject: [PATCH] use our own getVisibleRowCount() because the standard one returns 20 --- .../configuration/ContentEntryTreeEditor.java | 18 +++--------------- .../com/intellij/util/ui/tree/TreeUtil.java | 17 ++++++++++++++--- .../intellij/ui/popup/tree/TreePopupImpl.java | 4 ++-- .../intellij/usages/impl/UsageViewImpl.java | 4 +--- 4 files changed, 20 insertions(+), 23 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/ContentEntryTreeEditor.java b/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/ContentEntryTreeEditor.java index cddd83dfb5ec..908d695798e5 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/ContentEntryTreeEditor.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/ContentEntryTreeEditor.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -70,7 +70,7 @@ public class ContentEntryTreeEditor { protected final Tree myTree; private FileSystemTreeImpl myFileSystemTree; private final JPanel myTreePanel; - private final DefaultMutableTreeNode EMPTY_TREE_ROOT = new DefaultMutableTreeNode(ProjectBundle.message("module.paths.empty.node")); + private final TreeNode EMPTY_TREE_ROOT = new DefaultMutableTreeNode(ProjectBundle.message("module.paths.empty.node")); protected final DefaultActionGroup myEditingActionsGroup; private ContentEntryEditor myContentEntryEditor; private final MyContentEntryEditorListener myContentEntryEditorListener = new MyContentEntryEditorListener(); @@ -205,7 +205,7 @@ public class ContentEntryTreeEditor { if (myFileSystemTree != null) { myFileSystemTree.updateTree(); final DefaultTreeModel model = (DefaultTreeModel)myTree.getModel(); - final int visibleRowCount = myTree.getVisibleRowCount(); + final int visibleRowCount = TreeUtil.getVisibleRowCount(myTree); for (int row = 0; row < visibleRowCount; row++) { final TreePath pathForRow = myTree.getPathForRow(row); if (pathForRow != null) { @@ -218,18 +218,6 @@ public class ContentEntryTreeEditor { } } - private static class MarkSourceToggleActionsGroup extends DefaultActionGroup { - public MarkSourceToggleActionsGroup(String groupName, final Icon rootIcon) { - super(groupName, true); - getTemplatePresentation().setIcon(rootIcon); - } - - @Override - public boolean displayTextInToolbar() { - return true; - } - } - private class MyContentEntryEditorListener extends ContentEntryEditorListenerAdapter { @Override public void sourceFolderAdded(@NotNull ContentEntryEditor editor, SourceFolder folder) { diff --git a/platform/platform-api/src/com/intellij/util/ui/tree/TreeUtil.java b/platform/platform-api/src/com/intellij/util/ui/tree/TreeUtil.java index 6b56e1111eff..23c6ac3ad471 100644 --- a/platform/platform-api/src/com/intellij/util/ui/tree/TreeUtil.java +++ b/platform/platform-api/src/com/intellij/util/ui/tree/TreeUtil.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -297,7 +297,7 @@ public final class TreeUtil { private static IndexTreePathState removeLastPathComponent(@NotNull final DefaultTreeModel model, @NotNull final TreePath pathToBeRemoved) { final IndexTreePathState selectionState = new IndexTreePathState(pathToBeRemoved); if (((MutableTreeNode) pathToBeRemoved.getLastPathComponent()).getParent() == null) return selectionState; - model.removeNodeFromParent((MutableTreeNode) pathToBeRemoved.getLastPathComponent()); + model.removeNodeFromParent((MutableTreeNode)pathToBeRemoved.getLastPathComponent()); return selectionState; } @@ -661,7 +661,7 @@ public final class TreeUtil { return row; } - private static int getVisibleRowCount(@NotNull final JTree tree) { + public static int getVisibleRowCount(@NotNull final JTree tree) { final Rectangle visible = tree.getVisibleRect(); if (visible == null) return 0; @@ -677,6 +677,17 @@ public final class TreeUtil { return count; } + /** + * works correctly for trees with fixed row height only. + * For variable height trees (e.g. trees with custom tree node renderer) use the {@link #getVisibleRowCount(JTree)} which is slower + */ + public static int getVisibleRowCountForFixedRowHeight(@NotNull final JTree tree) { + // myTree.getVisibleRowCount returns 20 + Rectangle bounds = tree.getRowBounds(0); + int rowHeight = bounds == null ? 0 : bounds.height; + return rowHeight == 0 ? tree.getVisibleRowCount() : tree.getVisibleRect().height / rowHeight; + } + @SuppressWarnings({"HardCodedStringLiteral"}) public static void installActions(@NotNull final JTree tree) { tree.getActionMap().put("scrollUpChangeSelection", new AbstractAction() { diff --git a/platform/platform-impl/src/com/intellij/ui/popup/tree/TreePopupImpl.java b/platform/platform-impl/src/com/intellij/ui/popup/tree/TreePopupImpl.java index de4119791ad4..c48c39b27a8c 100644 --- a/platform/platform-impl/src/com/intellij/ui/popup/tree/TreePopupImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/popup/tree/TreePopupImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * Copyright 2000-2015 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -408,7 +408,7 @@ public class TreePopupImpl extends WizardPopup implements TreePopup { Rectangle visibleRect = getVisibleRect(); int rowForLocation = getClosestRowForLocation(0, visibleRect.y); - for (int i = rowForLocation; i < rowForLocation + getVisibleRowCount() + 1; i++) { + for (int i = rowForLocation; i < rowForLocation + TreeUtil.getVisibleRowCount(this) + 1; i++) { final TreePath eachPath = getPathForRow(i); if (eachPath == null) continue; diff --git a/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java b/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java index 5dda1f7b6e65..140ef311c67b 100644 --- a/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java +++ b/platform/usageView/src/com/intellij/usages/impl/UsageViewImpl.java @@ -310,9 +310,7 @@ public class UsageViewImpl implements UsageView, UsageModelTracker.UsageModelTra private int getVisibleRowCount() { // myTree.getVisibleRowCount returns 20 - Rectangle bounds = myTree.getRowBounds(0); - int rowHeight = bounds == null ? 0 : bounds.height; - return rowHeight == 0 ? myTree.getVisibleRowCount() : myTree.getVisibleRect().height / rowHeight; + return TreeUtil.getVisibleRowCountForFixedRowHeight(myTree); } private void setupCentralPanel() {