Unnamed: 0
int64
0
305k
body
stringlengths
7
52.9k
name
stringlengths
1
185
278,300
boolean () { return OptionsDialog.this.canBeHidden(); }
canBeHidden
278,301
boolean () { return OptionsDialog.this.shouldSaveOptionsOnCancel(); }
shouldSaveOptionsOnCancel
278,302
String () { return OptionsDialog.this.getDoNotShowMessage(); }
getDoNotShowMessage
278,303
boolean (int inputEventModifiers) { return (inputEventModifiers & Event.SHIFT_MASK) != 0; }
shiftIsPressed
278,304
boolean () { return true; }
canBeHidden
278,305
String () { return myValue; }
getValue
278,306
TextAttributes () { return myTextAttributes; }
getAttributes
278,307
Editor () { return myEditor; }
getEditor
278,308
void (String string, TextAttributes attrs) { synchronized (myLines) { myLines.add(new Line(string, attrs)); } if (myFlushAlarm.isEmpty()) { myFlushAlarm.addRequest(this::flushStoredLines, 200, ModalityState.nonModal()); } }
appendString
278,309
Runnable (@NotNull Collection<? extends Line> lines) { final Runnable command = () -> { Document document = myEditor.getDocument(); StringBuilder buffer = new StringBuilder(); for (Line line : lines) { buffer.append(line.getValue()); } int endBefore = document.getTextLength(); document.insertString(endBefore, buffer.toString()); int endBeforeLine = endBefore; for (Line line : lines) { myEditor.getMarkupModel() .addRangeHighlighter(endBeforeLine, Math.min(document.getTextLength(), endBeforeLine + line.getValue().length()), HighlighterLayer.ADDITIONAL_SYNTAX, line.getAttributes(), HighlighterTargetArea.EXACT_RANGE); endBeforeLine += line.getValue().length(); if (endBeforeLine > document.getTextLength()) break; } shiftCursorToTheEndOfDocument(); }; return () -> CommandProcessor.getInstance().executeCommand(myProject, command, "", null, UndoConfirmationPolicy.DEFAULT, myEditor.getDocument()); }
writingCommand
278,310
void () { if (myScrollToTheEndOnAppend) { myEditor.getCaretModel().moveToOffset(myEditor.getDocument().getTextLength()); myEditor.getSelectionModel().removeSelection(); myEditor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE); } }
shiftCursorToTheEndOfDocument
278,311
void (boolean showIcon) { myShowIcon = showIcon; }
setShowIcon
278,312
String (File file) { return file.getPath(); }
getFilePath
278,313
void (File ioFile) { myFile = ioFile; if (myShowIcon) { setIcon(FileTypeManager.getInstance().getFileTypeByFileName(myFile.getName()).getIcon()); } else { setIcon(null); } }
setFile
278,314
String () { if (myFile == null) return ""; int width = getWidth(); if (getIcon() != null) width -= getIconWidth(); return myPolicy.getOptimalTextForComponent(myFile, this, width); }
getText
278,315
void () { setPreferredSize(new Dimension(getPreferredWidth(), getPreferredSize().height)); }
pack
278,316
int () { return getIconWidth() + getFontMetrics(getFont()).stringWidth(myPolicy.getPresentableName(myFile, PREFERRED_TEXT_LENGTH)); }
getPreferredWidth
278,317
int () { Icon icon = getIcon(); if (icon == null) return 0; return icon.getIconWidth() + getIconTextGap(); }
getIconWidth
278,318
void (ID self, Pointer selector, ID event) { UIUtil.invokeLaterIfNeeded(() -> fireStyleChanged()); }
callback
278,319
void (ID self, Pointer selector, ID event) { UIUtil.invokeLaterIfNeeded(() -> updateBehaviorPreferences()); }
callback
278,320
boolean () { return SystemInfoRt.isMac; }
isOverlayScrollbarSupported
278,321
void () { Foundation.NSAutoreleasePool pool = new Foundation.NSAutoreleasePool(); ID delegateClass = Foundation.allocateObjcClassPair(Foundation.getObjcClass("NSObject"), "NSScrollerChangesObserver"); if (!ID.NIL.equals(delegateClass)) { // This static initializer might be called more than once (with different class loaders). In that case NSScrollerChangesObserver // already exists. if (!Foundation.addMethod(delegateClass, Foundation.createSelector("handleScrollerStyleChanged:"), APPEARANCE_CALLBACK, "v@")) { throw new RuntimeException("Cannot add observer method"); } if (!Foundation.addMethod(delegateClass, Foundation.createSelector("handleBehaviorChanged:"), BEHAVIOR_CALLBACK, "v@")) { throw new RuntimeException("Cannot add observer method"); } Foundation.registerObjcClassPair(delegateClass); } ID delegate = Foundation.invoke("NSScrollerChangesObserver", "new"); try { ID center; center = Foundation.invoke("NSNotificationCenter", "defaultCenter"); Foundation.invoke(center, "addObserver:selector:name:object:", delegate, Foundation.createSelector("handleScrollerStyleChanged:"), Foundation.nsString("NSPreferredScrollerStyleDidChangeNotification"), ID.NIL ); center = Foundation.invoke("NSDistributedNotificationCenter", "defaultCenter"); Foundation.invoke(center, "addObserver:selector:name:object:", delegate, Foundation.createSelector("handleBehaviorChanged:"), Foundation.nsString("AppleNoRedisplayAppearancePreferenceChanged"), ID.NIL, 2 // NSNotificationSuspensionBehaviorCoalesce ); } finally { pool.drain(); } }
initNotificationObserver
278,322
void () { if (!SystemInfoRt.isMac) return; Foundation.NSAutoreleasePool pool = new Foundation.NSAutoreleasePool(); try { ID defaults = Foundation.invoke("NSUserDefaults", "standardUserDefaults"); Foundation.invoke(defaults, "synchronize"); ourClickBehavior = Foundation.invoke(defaults, "boolForKey:", Foundation.nsString("AppleScrollerPagingBehavior")).booleanValue() ? ClickBehavior.JumpToSpot : ClickBehavior.NextPage; } finally { pool.drain(); } }
updateBehaviorPreferences
278,323
void (@NotNull ScrollbarStyleListener listener) { processReferences(listener, null, null); }
addScrollbarStyleListener
278,324
void (@NotNull ScrollbarStyleListener listener) { processReferences(null, listener, null); }
removeScrollbarStyleListener
278,325
void (ScrollbarStyleListener toAdd, ScrollbarStyleListener toRemove, List<? super ScrollbarStyleListener> list) { synchronized (ourStyleListeners) { Iterator<Reference<ScrollbarStyleListener>> iterator = ourStyleListeners.iterator(); while (iterator.hasNext()) { Reference<ScrollbarStyleListener> reference = iterator.next(); ScrollbarStyleListener ui = reference.get(); if (ui == null || ui == toRemove) { iterator.remove(); } else if (list != null) { list.add(ui); } } if (toAdd != null) { ourStyleListeners.add(new WeakReference<>(toAdd)); } } }
processReferences
278,326
void () { List<ScrollbarStyleListener> list = new ArrayList<>(); processReferences(null, null, list); for (ScrollbarStyleListener listener : list) { listener.styleChanged(); } }
fireStyleChanged
278,327
void (@ActionText String option, Action action) { action.putValue(Action.NAME, option); int mnemoPos = option.indexOf("&"); if (mnemoPos >= 0 && mnemoPos < option.length() - 2) { String mnemoChar = option.substring(mnemoPos + 1, mnemoPos + 2).trim(); if (mnemoChar.length() == 1) { action.putValue(Action.MNEMONIC_KEY, Integer.valueOf(mnemoChar.charAt(0))); } } }
assignMnemonic
278,328
JComponent () { JPanel panel = new JPanel(new BorderLayout(15, 0)); if (myIcon != null) { JLabel iconLabel = new JLabel(myIcon); Container container = new Container(); container.setLayout(new BorderLayout()); container.add(iconLabel, BorderLayout.NORTH); panel.add(container, BorderLayout.WEST); } if (myMessage != null) { JLabel textLabel = new JLabel(myMessage); textLabel.setUI(new MultiLineLabelUI()); panel.add(textLabel, BorderLayout.CENTER); } return panel; }
createNorthPanel
278,329
JComponent () { return null; }
createCenterPanel
278,330
int (int i) { return JBUIScale.scale(i); }
scale
278,331
ComponentPanelBuilder (JComponent component) { return new ComponentPanelBuilder(component); }
panel
278,332
ProgressPanelBuilder (JProgressBar progressBar) { return new ProgressPanelBuilder(progressBar); }
panel
278,333
PanelGridBuilder () { return new PanelGridBuilder(); }
grid
278,334
TreePath () { return null; }
getRestoredPath
278,335
void (@NotNull JTree tree) { tree.putClientProperty(KEY, this); }
installOn
278,336
ExpandOnDoubleClick (@NotNull JTree tree) { Object property = tree.getClientProperty(KEY); if (property instanceof ExpandOnDoubleClick) return (ExpandOnDoubleClick)property; String option = Registry.get(KEY).getSelectedOption(); if (NEVER.name().equalsIgnoreCase(option)) return NEVER; if (ALWAYS.name().equalsIgnoreCase(option)) return ALWAYS; if (NAVIGATABLE.name().equalsIgnoreCase(option)) return NAVIGATABLE; return DEFAULT; }
getBehavior
278,337
void (@NotNull JTree tree, @NotNull Function<? super TreePath, ? extends Navigatable> provider) { tree.putClientProperty(NAVIGATABLE_PROVIDER, provider); }
setNavigatableProvider
278,338
JBTreeTraverser<Object> (@NotNull JTree tree) { TreeModel model = tree.getModel(); Object root = model.getRoot(); return JBTreeTraverser.from(node -> nodeChildren(node, model)).withRoot(root); }
treeTraverser
278,339
JBTreeTraverser<TreePath> (@NotNull JTree tree) { TreeModel model = tree.getModel(); Object root = model.getRoot(); TreePath rootPath = root == null ? null : new TreePath(root); return JBTreeTraverser.<TreePath>from(path -> nodeChildren(path.getLastPathComponent(), model) .map(o -> path.pathByAddingChild(o))) .withRoot(rootPath); }
treePathTraverser
278,340
JBIterable<Object> (@Nullable Object node, @NotNull TreeModel model) { int count = model.getChildCount(node); return count == 0 ? JBIterable.empty() : NUMBERS.take(count).map(index -> model.getChild(node, index)); }
nodeChildren
278,341
JBTreeTraverser<TreeNode> (@Nullable TreeNode treeNode) { return JBTreeTraverser.<TreeNode>from(node -> nodeChildren(node)).withRoot(treeNode); }
treeNodeTraverser
278,342
JBIterable<TreeNode> (@Nullable TreeNode treeNode) { int count = treeNode == null ? 0 : treeNode.getChildCount(); return count == 0 ? JBIterable.empty() : NUMBERS.take(count).map(index -> treeNode.getChildAt(index)); }
nodeChildren
278,343
boolean (@NotNull Tree tree, int threshold) { return hasManyNodes(treeTraverser(tree), threshold); }
hasManyNodes
278,344
boolean (@NotNull TreeNode node, int threshold) { return hasManyNodes(treeNodeTraverser(node), threshold); }
hasManyNodes
278,345
int (@NotNull JTree tree, int x, int y) { return Math.max(-1, tree.getRowForPath(getPathForLocation(tree, x, y))); }
getRowForLocation
278,346
void (@NotNull JTree tree, @Nullable TreePath path) { assert EventQueue.isDispatchThread(); Rectangle bounds = tree.getPathBounds(path); if (bounds != null) tree.repaint(0, bounds.y, tree.getWidth(), bounds.height); }
repaintPath
278,347
void (@NotNull JTree tree, int row) { assert EventQueue.isDispatchThread(); Rectangle bounds = tree.getRowBounds(row); if (bounds != null) tree.repaint(0, bounds.y, tree.getWidth(), bounds.height); }
repaintRow
278,348
List<TreePath> (@NotNull JTree tree) { return collectExpandedObjects(tree, Function.identity()); }
collectExpandedPaths
278,349
List<Object> (@NotNull JTree tree) { return collectExpandedObjects(tree, TreeUtil::getLastUserObject); }
collectExpandedUserObjects
278,350
List<TreePath> (@NotNull JTree tree, @NotNull TreePath root) { return collectExpandedObjects(tree, root, Function.identity()); }
collectExpandedPaths
278,351
List<Object> (@NotNull JTree tree, @NotNull TreePath root) { return collectExpandedObjects(tree, root, TreeUtil::getLastUserObject); }
collectExpandedUserObjects
278,352
void (final @NotNull JTree tree, final @NotNull List<? extends TreePath> paths) { for(int i = paths.size() - 1; i >= 0; i--){ tree.expandPath(paths.get(i)); } }
restoreExpandedPaths
278,353
TreePath (@NotNull TreeNode aRootNode, @NotNull TreeNode aNode) { TreeNode[] nodes = getPathFromRootTo(aRootNode, aNode, true); return new TreePath(nodes); }
getPath
278,354
boolean (@NotNull TreeNode ancestor, @NotNull TreeNode node) { TreeNode parent = node; while (parent != null) { if (parent == ancestor) return true; parent = parent.getParent(); } return false; }
isAncestor
278,355
TreePath (@NotNull TreeNode node) { TreeNode[] path = getPathFromRootTo(null, node, false); return new TreePath(path); }
getPathFromRoot
278,356
void (final @NotNull JTree tree) { TreePath[] paths = tree.getSelectionPaths(); if (paths == null) { return; } for (TreePath path : paths) { removeLastPathComponent((DefaultTreeModel) tree.getModel(), path).restoreSelection(tree); } }
removeSelected
278,357
void (final @NotNull JTree tree, final @NotNull TreePath pathToBeRemoved) { removeLastPathComponent((DefaultTreeModel)tree.getModel(), pathToBeRemoved).restoreSelection(tree); }
removeLastPathComponent
278,358
ActionCallback (@NotNull JTree tree) { return Promises.toActionCallback(promiseSelectFirst(tree)); }
selectFirstNode
278,359
TreePath (@NotNull JTree tree) { TreeModel model = tree.getModel(); Object root = model.getRoot(); TreePath selectionPath = new TreePath(root); if (!tree.isRootVisible() && model.getChildCount(root) > 0) { selectionPath = selectionPath.pathByAddingChild(model.getChild(root, 0)); } return selectionPath; }
getFirstNodePath
278,360
int (@NotNull JTree tree, @NotNull DefaultMutableTreeNode targetNode) { TreeNode[] path = targetNode.getPath(); return tree.getRowForPath(new TreePath(path)); }
getRowForNode
278,361
TreePath (@NotNull JTree tree) { final TreeModel model = tree.getModel(); Object root = model.getRoot(); TreePath selectionPath = new TreePath(root); while (model.getChildCount(root) > 0) { final Object child = model.getChild(root, 0); selectionPath = selectionPath.pathByAddingChild(child); root = child; } return selectionPath; }
getFirstLeafNodePath
278,362
IndexTreePathState (final @NotNull DefaultTreeModel model, final @NotNull TreePath pathToBeRemoved) { final IndexTreePathState selectionState = new IndexTreePathState(pathToBeRemoved); if (((MutableTreeNode) pathToBeRemoved.getLastPathComponent()).getParent() == null) return selectionState; model.removeNodeFromParent((MutableTreeNode)pathToBeRemoved.getLastPathComponent()); return selectionState; }
removeLastPathComponent
278,363
void (final @NotNull DefaultTreeModel model, @Nullable Comparator comparator) { sort((DefaultMutableTreeNode) model.getRoot(), comparator); }
sort
278,364
void (final @NotNull DefaultMutableTreeNode node, @Nullable Comparator comparator) { sortRecursively(node, comparator); }
sort
278,365
void (final @NotNull MutableTreeNode node, final @NotNull List<? extends TreeNode> children) { for (final Object aChildren : children) { final MutableTreeNode child = (MutableTreeNode)aChildren; node.insert(child, node.getChildCount()); } }
addChildrenTo
278,366
boolean (@NotNull TreeNode node, @NotNull Traverse traverse) { return treeNodeTraverser(node).traverse(TreeTraversal.POST_ORDER_DFS).processEach(traverse::accept); }
traverse
278,367
boolean (@NotNull TreeNode node, @NotNull Traverse traverse) { return treeNodeTraverser(node).traverse(TreeTraversal.PRE_ORDER_DFS).processEach(traverse::accept); }
traverseDepth
278,368
void (@NotNull JTree tree, int index) { TreePath path = tree.getPathForRow(index); if (path != null) internalSelect(tree, path); }
selectRow
278,369
void (@NotNull JTree tree, @NotNull Collection<? extends TreePath> paths) { if (!paths.isEmpty()) selectPaths(tree, paths.toArray(EMPTY_TREE_PATH)); }
selectPaths
278,370
void (@NotNull JTree tree, @NotNull TreePath @NotNull ... paths) { if (paths.length == 0) return; for (TreePath path : paths) tree.makeVisible(path); internalSelect(tree, paths); }
selectPaths
278,371
ActionCallback (final @NotNull JTree tree, final TreePath path) { return selectPath(tree, path, true); }
selectPath
278,372
ActionCallback (final @NotNull JTree tree, final TreePath path, boolean center) { tree.makeVisible(path); Rectangle bounds = tree.getPathBounds(path); if (bounds == null) return ActionCallback.REJECTED; if (center) { Rectangle visible = tree.getVisibleRect(); if (visible.y < bounds.y + bounds.height && bounds.y < visible.y + visible.height) { center = false; // disable centering if the given path is already visible } } if (center) { return showRowCentred(tree, tree.getRowForPath(path)); } else { final int row = tree.getRowForPath(path); return showAndSelect(tree, row - ScrollingUtil.ROW_PADDING, row + ScrollingUtil.ROW_PADDING, row, -1); } }
selectPath
278,373
ActionCallback (final @NotNull JTree tree) { final int size = tree.getRowCount(); int row = tree.getLeadSelectionRow(); if (row < size - 1) { row++; return showAndSelect(tree, row, row + 2, row, getSelectedRow(tree), false, true, true); } else { return ActionCallback.DONE; } }
moveDown
278,374
ActionCallback (final @NotNull JTree tree) { int row = tree.getLeadSelectionRow(); if (row > 0) { row--; return showAndSelect(tree, row - 2, row, row, getSelectedRow(tree), false, true, true); } else { return ActionCallback.DONE; } }
moveUp
278,375
ActionCallback (final @NotNull JTree tree) { final int visible = getVisibleRowCount(tree); if (visible <= 0){ return moveHome(tree); } final int decrement = visible - 1; final int row = Math.max(getSelectedRow(tree) - decrement, 0); final int top = getFirstVisibleRow(tree) - decrement; final int bottom = top + visible - 1; return showAndSelect(tree, top, bottom, row, getSelectedRow(tree)); }
movePageUp
278,376
ActionCallback (final @NotNull JTree tree) { final int visible = getVisibleRowCount(tree); if (visible <= 0){ return moveEnd(tree); } final int size = tree.getRowCount(); final int increment = visible - 1; final int index = Math.min(getSelectedRow(tree) + increment, size - 1); final int top = getFirstVisibleRow(tree) + increment; final int bottom = top + visible - 1; return showAndSelect(tree, top, bottom, index, getSelectedRow(tree)); }
movePageDown
278,377
ActionCallback (final @NotNull JTree tree) { return showRowCentred(tree, 0); }
moveHome
278,378
ActionCallback (final @NotNull JTree tree) { return showRowCentred(tree, tree.getRowCount() - 1); }
moveEnd
278,379
ActionCallback (final @NotNull JTree tree, final int row) { return showRowCentered(tree, row, true); }
showRowCentred
278,380
ActionCallback (final @NotNull JTree tree, final int row, final boolean centerHorizontally) { return showRowCentered(tree, row, centerHorizontally, true); }
showRowCentered
278,381
ActionCallback (final @NotNull JTree tree, final int row, final boolean centerHorizontally, boolean scroll) { final int visible = getVisibleRowCount(tree); final int top = visible > 0 ? row - (visible - 1)/ 2 : row; final int bottom = visible > 0 ? top + visible - 1 : row; return showAndSelect(tree, top, bottom, row, -1, false, scroll, false); }
showRowCentered
278,382
ActionCallback (final @NotNull JTree tree, int top, int bottom, final int row, final int previous) { return showAndSelect(tree, top, bottom, row, previous, false); }
showAndSelect
278,383
ActionCallback (final @NotNull JTree tree, int top, int bottom, final int row, final int previous, boolean addToSelection) { return showAndSelect(tree, top, bottom, row, previous, addToSelection, true, false); }
showAndSelect
278,384
ActionCallback (final @NotNull JTree tree, int top, int bottom, final int row, final int previous, final boolean addToSelection, final boolean scroll) { return showAndSelect(tree, top, bottom, row, previous, addToSelection, scroll, false); }
showAndSelect
278,385
ActionCallback (final @NotNull JTree tree, int top, int bottom, final int row, final int previous, final boolean addToSelection, final boolean scroll, final boolean resetSelection) { final TreePath path = tree.getPathForRow(row); if (path == null) return ActionCallback.DONE; final int size = tree.getRowCount(); if (size == 0) { tree.clearSelection(); return ActionCallback.DONE; } if (top < 0){ top = 0; } if (bottom >= size){ bottom = size - 1; } if (row >= tree.getRowCount()) return ActionCallback.DONE; boolean okToScroll = true; if (tree.isShowing()) { if (!tree.isValid()) { tree.validate(); } } else { Application app = ApplicationManager.getApplication(); if (app != null && app.isUnitTestMode()) { okToScroll = false; } } Runnable selectRunnable = () -> { if (!tree.isRowSelected(row)) { if (addToSelection) { tree.getSelectionModel().addSelectionPath(tree.getPathForRow(row)); } else { tree.setSelectionRow(row); } } else if (resetSelection) { if (!addToSelection) { tree.setSelectionRow(row); } } }; if (!okToScroll || !scroll) { selectRunnable.run(); return ActionCallback.DONE; } final Rectangle rowBounds = tree.getRowBounds(row); if (rowBounds == null) return ActionCallback.DONE; Rectangle topBounds = tree.getRowBounds(top); if (topBounds == null) { topBounds = rowBounds; } Rectangle bottomBounds = tree.getRowBounds(bottom); if (bottomBounds == null) { bottomBounds = rowBounds; } Rectangle bounds = topBounds.union(bottomBounds); bounds.x = rowBounds.x; bounds.width = rowBounds.width; final Rectangle visible = tree.getVisibleRect(); if (visible.contains(bounds)) { selectRunnable.run(); return ActionCallback.DONE; } final Component comp = tree.getCellRenderer().getTreeCellRendererComponent(tree, path.getLastPathComponent(), true, true, false, row, false); if (comp instanceof SimpleColoredComponent renderer) { final Dimension scrollableSize = renderer.computePreferredSize(true); bounds.width = scrollableSize.width; } final ActionCallback callback = new ActionCallback(); selectRunnable.run(); final Range<Integer> range = getExpandControlRange(tree, path); if (range != null) { int delta = bounds.x - range.getFrom().intValue(); bounds.x -= delta; bounds.width -= delta; } if (visible.width < bounds.width) { bounds.width = visible.width; } if (tree instanceof Tree && !((Tree)tree).isHorizontalAutoScrollingEnabled()) { bounds.x = tree.getVisibleRect().x; } if (LOG.isTraceEnabled()) LOG.debug("tree scroll: ", path); tree.scrollRectToVisible(bounds); // try to scroll later when the tree is ready Object property = tree.getClientProperty(TREE_UTIL_SCROLL_TIME_STAMP); long stamp = property instanceof Long ? (Long)property + 1L : Long.MIN_VALUE; tree.putClientProperty(TREE_UTIL_SCROLL_TIME_STAMP, stamp); // store relative offset because the row can be moved during the tree updating int offset = rowBounds.y - bounds.y; AbstractTreeBuilder builder = AbstractTreeBuilder.getBuilderFor(tree); scrollToVisible(tree, path, bounds, offset, stamp, callback::setDone, builder, 3); return callback; }
showAndSelect
278,386
void (JTree tree, TreePath path, Rectangle bounds, int offset, long expected, Runnable done, AbstractTreeBuilder builder, int attempt) { Runnable scroll = () -> { Rectangle pathBounds = attempt <= 0 ? null : tree.getPathBounds(path); if (pathBounds != null) { Object property = tree.getClientProperty(TREE_UTIL_SCROLL_TIME_STAMP); long stamp = property instanceof Long ? (Long)property : Long.MAX_VALUE; if (LOG.isTraceEnabled()) LOG.debug("tree scroll ", attempt, stamp == expected ? ": try again: " : ": ignore: ", path); if (stamp == expected) { bounds.y = pathBounds.y - offset; // restore bounds according to the current row Rectangle visible = tree.getVisibleRect(); if (bounds.y < visible.y || bounds.y > visible.y + Math.max(0, visible.height - bounds.height)) { tree.scrollRectToVisible(bounds); scrollToVisible(tree, path, bounds, offset, expected, done, builder, attempt - 1); return; // try to scroll again } } } done.run(); }; SwingUtilities.invokeLater(builder == null ? scroll : () -> builder.getReady(TreeUtil.class).doWhenDone(scroll)); }
scrollToVisible
278,387
int (final @NotNull JTree tree) { return tree.getRowForPath(tree.getSelectionPath()); }
getSelectedRow
278,388
int (final @NotNull JTree tree) { final Rectangle visible = tree.getVisibleRect(); int row = -1; for (int i=0; i < tree.getRowCount(); i++) { final Rectangle bounds = tree.getRowBounds(i); if (visible.y <= bounds.y && visible.y + visible.height >= bounds.y + bounds.height) { row = i; break; } } return row; }
getFirstVisibleRow
278,389
int (final @NotNull JTree tree) { final Rectangle visible = tree.getVisibleRect(); if (visible == null) return 0; int rowCount = tree.getRowCount(); if (rowCount <= 0) return 0; int firstRow; int lastRow; int rowHeight = tree.getRowHeight(); if (rowHeight > 0) { Insets insets = tree.getInsets(); int top = visible.y - insets.top; int bottom = visible.y + visible.height - insets.top; firstRow = Math.max(0, Math.min(top / rowHeight, rowCount - 1)); lastRow = Math.max(0, Math.min(bottom / rowHeight, rowCount - 1)); } else { firstRow = tree.getClosestRowForLocation(visible.x, visible.y); lastRow = tree.getClosestRowForLocation(visible.x, visible.y + visible.height); } return lastRow - firstRow + 1; }
getVisibleRowCount
278,390
void (final @NotNull JTree tree) { TreeUI ui = tree.getUI(); if (ui != null && ui.getClass().getName().equals("com.intellij.ui.tree.ui.DefaultTreeUI")) return; tree.getActionMap().put("scrollUpChangeSelection", new AbstractAction() { @Override public void actionPerformed(final ActionEvent e) { movePageUp(tree); } }); tree.getActionMap().put("scrollDownChangeSelection", new AbstractAction() { @Override public void actionPerformed(final ActionEvent e) { movePageDown(tree); } }); tree.getActionMap().put("selectPrevious", new AbstractAction() { @Override public void actionPerformed(final ActionEvent e) { moveUp(tree); } }); tree.getActionMap().put("selectNext", new AbstractAction() { @Override public void actionPerformed(final ActionEvent e) { moveDown(tree); } }); copyAction(tree, "selectLast", "selectLastChangeLead"); copyAction(tree, "selectFirst", "selectFirstChangeLead"); InputMap inputMap = tree.getInputMap(JComponent.WHEN_FOCUSED); UIUtil.maybeInstall(inputMap, "scrollUpChangeSelection", KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0)); UIUtil.maybeInstall(inputMap, "scrollDownChangeSelection", KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0)); UIUtil.maybeInstall(inputMap, "selectNext", KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0)); UIUtil.maybeInstall(inputMap, "selectPrevious", KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0)); UIUtil.maybeInstall(inputMap, "selectLast", KeyStroke.getKeyStroke(KeyEvent.VK_END, 0)); UIUtil.maybeInstall(inputMap, "selectFirst", KeyStroke.getKeyStroke(KeyEvent.VK_HOME, 0)); }
installActions
278,391
void (final ActionEvent e) { movePageUp(tree); }
actionPerformed
278,392
void (final ActionEvent e) { movePageDown(tree); }
actionPerformed
278,393
void (final ActionEvent e) { moveUp(tree); }
actionPerformed
278,394
void (final ActionEvent e) { moveDown(tree); }
actionPerformed
278,395
void (final @NotNull JTree tree, String original, String copyTo) { final Action action = tree.getActionMap().get(original); if (action != null) { tree.getActionMap().put(copyTo, action); } }
copyAction
278,396
void (@NotNull JTree tree, final int keepSelectionLevel) { collapseAll(tree, false, keepSelectionLevel); }
collapseAll
278,397
void (@NotNull JTree tree, boolean strict, int keepSelectionLevel) { assert EventQueue.isDispatchThread(); int row = tree.getRowCount(); if (row <= 1) return; // nothing to collapse final TreePath leadSelectionPath = tree.getLeadSelectionPath(); int minCount = 1; // allowed path count to collapse if (!tree.isRootVisible()) minCount++; if (!tree.getShowsRootHandles()) { minCount++; strict = true; } // use the parent path of the normalized selection path to prohibit its collapsing TreePath prohibited = leadSelectionPath == null ? null : normalize(leadSelectionPath, minCount, keepSelectionLevel).getParentPath(); // Collapse all while (0 < row--) { if (!strict && row == 0) break; TreePath path = tree.getPathForRow(row); assert path != null : "path is not found at row " + row; int pathCount = path.getPathCount(); if (pathCount < minCount) continue; if (pathCount == minCount && row > 0) strict = true; if (!isAlwaysExpand(path) && !path.isDescendant(prohibited)) tree.collapsePath(path); } if (leadSelectionPath == null) return; // no selection to restore if (!strict) minCount++; // top level node is not collapsed internalSelect(tree, normalize(leadSelectionPath, minCount, keepSelectionLevel)); }
collapseAll
278,398
TreePath (@NotNull TreePath path, int minCount, int keepSelectionLevel) { if (keepSelectionLevel < 0) return path; if (keepSelectionLevel > minCount) minCount = keepSelectionLevel; int pathCount = path.getPathCount(); while (minCount < pathCount--) path = path.getParentPath(); assert path != null : "unexpected minCount: " + minCount; return path; }
normalize
278,399
boolean (@NotNull TreePath path) { AbstractTreeNode<?> node = getAbstractTreeNode(path); return node != null && node.isAlwaysExpand(); }
isAlwaysExpand