Unnamed: 0
int64
0
305k
body
stringlengths
7
52.9k
name
stringlengths
1
185
278,400
void (final @NotNull JTree tree, final TreeNode node) { selectPath(tree, getPathFromRoot(node)); }
selectNode
278,401
void (final @NotNull JTree tree, final int direction) { final TreePath selectionPath = tree.getSelectionPath(); final DefaultMutableTreeNode treeNode = (DefaultMutableTreeNode)selectionPath.getLastPathComponent(); final DefaultMutableTreeNode parent = (DefaultMutableTreeNode)treeNode.getParent(); final int idx = parent.getIndex(treeNode); ((DefaultTreeModel)tree.getModel()).removeNodeFromParent(treeNode); ((DefaultTreeModel)tree.getModel()).insertNodeInto(treeNode, parent, idx + direction); selectNode(tree, treeNode); }
moveSelectedRow
278,402
List<TreeNode> (final @NotNull TreeNode node) { //ThreadingAssertions.assertEventDispatchThread(); int size = node.getChildCount(); ArrayList<TreeNode> result = new ArrayList<>(size); for(int i = 0; i < size; i++){ TreeNode child = node.getChildAt(i); LOG.assertTrue(child != null); result.add(child); } return result; }
listChildren
278,403
void (final @Nullable JTree tree) { if (tree == null) return; Runnable runnable = () -> { TreeModel model = tree.getModel(); Object root = model.getRoot(); if (root == null) return; TreePath rootPath = new TreePath(root); tree.expandPath(rootPath); if (model.getChildCount(root) == 1) { Object firstChild = model.getChild(root, 0); tree.expandPath(rootPath.pathByAddingChild(firstChild)); } }; EdtInvocationManager.invokeLaterIfNeeded(runnable); }
expandRootChildIfOnlyOne
278,404
void (@NotNull JTree tree) { promiseExpandAll(tree); }
expandAll
278,405
void (@NotNull JTree tree, @NotNull Runnable onDone) { promiseExpandAll(tree).onSuccess(result -> EdtInvocationManager.invokeLaterIfNeeded(onDone)); }
expandAll
278,406
void (@NotNull JTree tree, int levels) { promiseExpand(tree, levels); }
expand
278,407
void (@NotNull JTree tree, int depth, @NotNull Runnable onDone) { promiseExpand(tree, depth).onSuccess(result -> EdtInvocationManager.invokeLaterIfNeeded(onDone)); }
expand
278,408
ActionCallback (DefaultMutableTreeNode node, boolean requestFocus, @NotNull JTree tree) { return selectInTree(node, requestFocus, tree, true); }
selectInTree
278,409
ActionCallback (@Nullable DefaultMutableTreeNode node, boolean requestFocus, @NotNull JTree tree, boolean center) { if (node == null) return ActionCallback.DONE; final TreePath treePath = new TreePath(node.getPath()); tree.expandPath(treePath); if (requestFocus) { IdeFocusManager.getGlobalInstance().doWhenFocusSettlesDown(() -> IdeFocusManager.getGlobalInstance().requestFocus(tree, true)); } return selectPath(tree, treePath, center); }
selectInTree
278,410
ActionCallback (Project project, @Nullable DefaultMutableTreeNode node, boolean requestFocus, @NotNull JTree tree, boolean center) { if (node == null) return ActionCallback.DONE; final TreePath treePath = new TreePath(node.getPath()); tree.expandPath(treePath); if (requestFocus) { ActionCallback result = new ActionCallback(2); IdeFocusManager.getInstance(project).requestFocus(tree, true).notifyWhenDone(result); selectPath(tree, treePath, center).notifyWhenDone(result); return result; } return selectPath(tree, treePath, center); }
selectInTree
278,411
boolean (@NotNull JTree tree, @NotNull TreePath path) { TreePath parent = path.getParentPath(); return parent != null ? tree.isExpanded(parent) : tree.isRootVisible(); }
isViewable
278,412
List<TreePath> (@NotNull JTree tree) { return collectSelectedObjects(tree, Function.identity()); }
collectSelectedPaths
278,413
List<Object> (@NotNull JTree tree) { return collectSelectedObjects(tree, TreeUtil::getLastUserObject); }
collectSelectedUserObjects
278,414
List<TreePath> (@NotNull JTree tree, @NotNull TreePath root) { return collectSelectedObjects(tree, root, Function.identity()); }
collectSelectedPaths
278,415
List<Object> (@NotNull JTree tree, @NotNull TreePath root) { return collectSelectedObjects(tree, root, TreeUtil::getLastUserObject); }
collectSelectedUserObjects
278,416
void (@NotNull JTree tree, @Nullable TreePath path) { if (path == null) return; TreePath[] selectionPaths = tree.getSelectionPaths(); if (selectionPaths == null) return; for (TreePath selectionPath : selectionPaths) { if (selectionPath.getPathCount() > path.getPathCount() && path.isDescendant(selectionPath)) { tree.removeSelectionPath(selectionPath); } } }
unselectPath
278,417
int (@NotNull JTree aTree) { if (aTree.isRootVisible()) { return aTree.getShowsRootHandles() ? 1 : 0; } else { return aTree.getShowsRootHandles() ? 0 : -1; } }
getDepthOffset
278,418
int (@NotNull JTree tree, @NotNull TreePath path) { int depth = path.getPathCount(); if (!tree.isRootVisible()) depth--; if (!tree.getShowsRootHandles()) depth--; return depth; }
getNodeDepth
278,419
int (@NotNull JTree tree, int row) { if (LazyRowX.METHOD == null) return -1; // system error TreePath path = tree.getPathForRow(row); if (path == null) return -1; // path does not exist int depth = getNodeDepth(tree, path); if (depth < 0) return -1; // root is not visible try { return (Integer)LazyRowX.METHOD.invoke(tree.getUI(), row, depth); } catch (Exception exception) { LOG.error(exception); return -1; // unexpected } }
getNodeRowX
278,420
boolean (@NotNull JTree tree, int x, int y) { if (LazyLocationInExpandControl.METHOD == null) return false; // system error return isLocationInExpandControl(tree, tree.getClosestPathForLocation(x, y), x, y); }
isLocationInExpandControl
278,421
boolean (@NotNull JTree tree, @Nullable TreePath path, int x, int y) { if (LazyLocationInExpandControl.METHOD == null || path == null) return false; // system error or undefined path try { return (Boolean)LazyLocationInExpandControl.METHOD.invoke(tree.getUI(), path, x, y); } catch (Exception exception) { LOG.error(exception); return false; // unexpected } }
isLocationInExpandControl
278,422
void (@Nullable TreeUI ui) { if (ui instanceof BasicTreeUI basic) { if (null == getField(BasicTreeUI.class, ui, JTree.class, "tree")) { LOG.warn(new IllegalStateException("tree is not properly initialized yet")); return; } EdtInvocationManager.invokeLaterIfNeeded(() -> basic.setLeftChildIndent(basic.getLeftChildIndent())); } }
invalidateCacheAndRepaint
278,423
RelativePoint (@NotNull JTree aTree) { final int[] rows = aTree.getSelectionRows(); if (rows == null || rows.length == 0) { return RelativePoint.getCenterOf(aTree); } return getPointForRow(aTree, rows[rows.length - 1]); }
getPointForSelection
278,424
RelativePoint (@NotNull JTree aTree, int aRow) { return getPointForPath(aTree, aTree.getPathForRow(aRow)); }
getPointForRow
278,425
RelativePoint (@NotNull JTree aTree, TreePath path) { final Rectangle rowBounds = aTree.getPathBounds(path); rowBounds.x += 20; return getPointForBounds(aTree, rowBounds); }
getPointForPath
278,426
RelativePoint (JComponent aComponent, final @NotNull Rectangle aBounds) { return new RelativePoint(aComponent, new Point(aBounds.x, (int)aBounds.getMaxY())); }
getPointForBounds
278,427
boolean (final @NotNull JTree tree, final @NotNull Point point) { TreePath path = tree.getPathForLocation(point.x, point.y); return path != null && tree.getSelectionModel().isPathSelected(path); }
isOverSelection
278,428
void (@NotNull JTree tree, @NotNull Point treePoint) { final TreePath toRetain = tree.getPathForLocation(treePoint.x, treePoint.y); if (toRetain == null) return; TreePath[] selection = tree.getSelectionModel().getSelectionPaths(); selection = selection == null ? EMPTY_TREE_PATH : selection; for (TreePath each : selection) { if (toRetain.equals(each)) continue; tree.getSelectionModel().removeSelectionPath(each); } }
dropSelectionButUnderPoint
278,429
boolean (@Nullable TreePath path) { return path != null && isLoadingNode(path.getLastPathComponent()); }
isLoadingPath
278,430
boolean (@Nullable Object node) { while (node != null) { if (node instanceof LoadingNode) return true; if (!(node instanceof DefaultMutableTreeNode)) return false; node = ((DefaultMutableTreeNode)node).getUserObject(); } return false; }
isLoadingNode
278,431
void (@NotNull JTree tree) { final TreePath[] paths = tree.getSelectionPaths(); if (paths != null) { for (TreePath each : paths) { if (tree.getRowForPath(each) >= 0 && tree.isVisible(each)) { return; } } } for (int eachRow = 0; eachRow < tree.getRowCount(); eachRow++) { TreePath eachPath = tree.getPathForRow(eachRow); if (eachPath != null && tree.isVisible(eachPath)) { tree.setSelectionPath(eachPath); break; } } }
ensureSelection
278,432
Comparator<TreePath> (final @NotNull JTree tree) { return Comparator.comparingInt(tree::getRowForPath); }
getDisplayOrderComparator
278,433
void (@NotNull JTree tree, @NotNull TreePath path) { if (LOG.isTraceEnabled()) LOG.debug("tree expand path: ", path); tree.expandPath(path); }
expandPathWithDebug
278,434
void (@NotNull JTree tree, @NotNull TreeVisitor visitor, @NotNull Consumer<? super TreePath> consumer) { promiseMakeVisibleOne(tree, visitor, path -> { expandPathWithDebug(tree, path); consumer.accept(path); }); }
expand
278,435
Promise<TreePath> (@NotNull JTree tree, @NotNull TreePath path) { return promiseExpand(tree, new TreeVisitor.ByTreePath<>(path, node -> node)); }
promiseExpand
278,436
Promise<TreePath> (@NotNull JTree tree, @NotNull TreeVisitor visitor) { return promiseMakeVisibleOne(tree, visitor, path -> expandPathWithDebug(tree, path)); }
promiseExpand
278,437
Promise<List<TreePath>> (@NotNull JTree tree, @NotNull Stream<? extends TreeVisitor> visitors) { return promiseMakeVisibleAll(tree, visitors, paths -> paths.forEach(path -> expandPathWithDebug(tree, path))); }
promiseExpand
278,438
void (@NotNull JTree tree, @NotNull TreeVisitor visitor, @NotNull Consumer<? super TreePath> consumer) { promiseMakeVisibleOne(tree, visitor, consumer); }
makeVisible
278,439
Promise<TreePath> (@NotNull JTree tree, @NotNull TreePath path) { return promiseMakeVisible(tree, new TreeVisitor.ByTreePath<>(path, node -> node)); }
promiseMakeVisible
278,440
Promise<TreePath> (@NotNull JTree tree, @NotNull TreeVisitor visitor) { return promiseMakeVisibleOne(tree, visitor, null); }
promiseMakeVisible
278,441
Promise<TreePath> (@NotNull JTree tree, @NotNull TreeVisitor visitor, @Nullable Consumer<? super TreePath> consumer) { AsyncPromise<TreePath> promise = new AsyncPromise<>(); promiseMakeVisible(tree, visitor, promise) .onError(promise::setError) .onSuccess(path -> { if (promise.isCancelled()) { return; } EdtInvocationManager.invokeLaterIfNeeded(() -> { if (promise.isCancelled()) return; if (tree.isVisible(path)) { if (consumer != null) consumer.accept(path); promise.setResult(path); } else { promise.cancel(); } }); }); return promise; }
promiseMakeVisibleOne
278,442
Promise<List<TreePath>> (@NotNull JTree tree, @NotNull Stream<? extends TreeVisitor> visitors) { return promiseMakeVisibleAll(tree, visitors, null); }
promiseMakeVisible
278,443
Promise<List<TreePath>> (@NotNull JTree tree, @NotNull Stream<? extends TreeVisitor> visitors, @Nullable Consumer<? super List<TreePath>> consumer) { AsyncPromise<List<TreePath>> promise = new AsyncPromise<>(); List<Promise<TreePath>> promises = visitors .filter(Objects::nonNull) .map(visitor -> promiseMakeVisible(tree, visitor, promise)) .collect(toList()); Promises.collectResults(promises, true) .onError(promise::setError) .onSuccess(paths -> { if (promise.isCancelled()) return; if (!ContainerUtil.isEmpty(paths)) { EdtInvocationManager.invokeLaterIfNeeded(() -> { if (promise.isCancelled()) return; List<TreePath> visible = ContainerUtil.filter(paths, tree::isVisible); if (!ContainerUtil.isEmpty(visible)) { if (consumer != null) consumer.accept(visible); promise.setResult(visible); } else { promise.cancel(); } }); } else { promise.cancel(); } }); return promise; }
promiseMakeVisibleAll
278,444
Promise<TreePath> (@NotNull JTree tree, @NotNull TreeVisitor visitor, @NotNull AsyncPromise<?> promise) { return promiseVisit(tree, new MakeVisibleVisitor(tree, visitor, promise)); }
promiseMakeVisible
278,445
Action (@NotNull TreePath path, @NotNull TreeVisitor.Action action) { if (action == TreeVisitor.Action.CONTINUE || action == TreeVisitor.Action.INTERRUPT) { // do not expand children if parent path is collapsed if (!tree.isVisible(path)) { if (!promise.isCancelled()) { if (LOG.isTraceEnabled()) LOG.debug("tree expand canceled"); promise.cancel(); } return TreeVisitor.Action.SKIP_SIBLINGS; } if (action == TreeVisitor.Action.CONTINUE) expandPathWithDebug(tree, path); } return action; }
postVisitEDT
278,446
Promise<TreePath> (@NotNull JTree tree, @NotNull TreePath path) { return promiseSelect(tree, new TreeVisitor.ByTreePath<>(path, node -> node)); }
promiseSelect
278,447
Promise<TreePath> (@NotNull JTree tree, @NotNull TreeVisitor visitor) { return promiseMakeVisibleOne(tree, visitor, path -> internalSelect(tree, path)); }
promiseSelect
278,448
Promise<List<TreePath>> (@NotNull JTree tree, @NotNull Stream<? extends TreeVisitor> visitors) { return promiseMakeVisibleAll(tree, visitors, paths -> internalSelect(tree, paths.toArray(EMPTY_TREE_PATH))); }
promiseSelect
278,449
void (@NotNull JTree tree, @NotNull TreePath @NotNull ... paths) { assert EventQueue.isDispatchThread(); if (paths.length == 0) return; tree.setSelectionPaths(paths); for (TreePath path : paths) { if (scrollToVisible(tree, path, Registry.is("ide.tree.autoscrollToVCenter", false))) { break; } } }
internalSelect
278,450
boolean (@NotNull JTree tree, @NotNull TreePath path, boolean centered) { assert EventQueue.isDispatchThread(); Rectangle bounds = tree.getPathBounds(path); if (bounds == null) { if (LOG.isTraceEnabled()) LOG.debug("cannot scroll to: ", path); return false; } internalScroll(tree, bounds, centered); // notify screen readers that they should notify the user that the visual appearance of the component has changed AccessibleContext context = tree.getAccessibleContext(); if (context != null) context.firePropertyChange(AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY, false, true); // try to scroll later when the tree is ready long stamp = 1L + getScrollTimeStamp(tree); tree.putClientProperty(TREE_UTIL_SCROLL_TIME_STAMP, stamp); EdtScheduledExecutorService.getInstance().schedule(() -> { Rectangle boundsLater = stamp != getScrollTimeStamp(tree) ? null : tree.getPathBounds(path); if (boundsLater != null) internalScroll(tree, boundsLater, centered); }, 5, MILLISECONDS); return true; }
scrollToVisible
278,451
void (@NotNull JTree tree, @NotNull Rectangle bounds, boolean centered) { JViewport viewport = ComponentUtil.getViewport(tree); if (viewport != null) { int width = viewport.getWidth(); if (!centered && tree instanceof Tree && !((Tree)tree).isHorizontalAutoScrollingEnabled()) { bounds.x = -tree.getX(); bounds.width = width; } else { int control = JBUIScale.scale(20); // calculate a control width bounds.x = Math.max(0, bounds.x - control); bounds.width = bounds.x > 0 ? Math.min(bounds.width + control, centered ? width : width / 2) : width; } int height = viewport.getHeight(); if (height > bounds.height && height < tree.getHeight()) { if (centered || height < bounds.height * 5) { bounds.y -= (height - bounds.height) / 2; bounds.height = height; } else { bounds.y -= bounds.height * 2; bounds.height *= 5; } if (bounds.y < 0) { bounds.height += bounds.y; bounds.y = 0; } int y = bounds.y + bounds.height - tree.getHeight(); if (y > 0) bounds.height -= y; } } tree.scrollRectToVisible(bounds); }
internalScroll
278,452
long (@NotNull JTree tree) { Object property = tree.getClientProperty(TREE_UTIL_SCROLL_TIME_STAMP); return property instanceof Long ? (Long)property : Long.MIN_VALUE; }
getScrollTimeStamp
278,453
Promise<TreePath> (@NotNull JTree tree) { return promiseSelect(tree, path -> isHiddenRoot(tree, path) ? TreeVisitor.Action.CONTINUE : TreeVisitor.Action.INTERRUPT); }
promiseSelectFirst
278,454
boolean (@NotNull JTree tree, @NotNull TreePath path) { return !tree.isRootVisible() && path.getParentPath() == null; }
isHiddenRoot
278,455
Promise<TreePath> (@NotNull JTree tree) { AtomicReference<TreePath> reference = new AtomicReference<>(); AsyncPromise<TreePath> promise = new AsyncPromise<>(); promiseMakeVisible(tree, path -> { TreePath parent = reference.getAndSet(path); if (getPathCount(parent) == getPathCount(path.getParentPath())) return TreeVisitor.Action.CONTINUE; internalSelect(tree, parent); promise.setResult(parent); return TreeVisitor.Action.INTERRUPT; }, promise) .onError(promise::setError) .onSuccess(path -> { if (!promise.isDone()) { TreePath tail = reference.get(); if (tail == null || isHiddenRoot(tree, tail)) { promise.cancel(); } else { internalSelect(tree, tail); promise.setResult(tail); } } }); return promise; }
promiseSelectFirstLeaf
278,456
int (@Nullable TreePath path) { return path == null ? 0 : path.getPathCount(); }
getPathCount
278,457
void (@NotNull JTree tree, @NotNull TreeVisitor visitor, @NotNull Consumer<? super TreePath> consumer) { promiseVisit(tree, visitor).onSuccess(path -> EdtInvocationManager.invokeLaterIfNeeded(() -> consumer.accept(path))); }
visit
278,458
Promise<TreePath> (@NotNull JTree tree, @NotNull TreeVisitor visitor) { TreeModel model = tree.getModel(); if (model instanceof TreeVisitor.Acceptor acceptor) { return acceptor.accept(visitor); } if (model == null) return Promises.rejectedPromise("tree model is not set"); AsyncPromise<TreePath> promise = new AsyncPromise<>(); EdtInvocationManager.invokeLaterIfNeeded(() -> promise.setResult(visitModel(model, visitor))); return promise; }
promiseVisit
278,459
TreePath (@NotNull TreeModel model, @NotNull TreeVisitor visitor) { Object root = model.getRoot(); if (root == null) return null; TreePath path = new TreePath(root); switch (visitor.visit(path)) { case INTERRUPT -> { return path; // root path is found } case CONTINUE -> { // visit children } default -> { return null; // skip children } } Deque<Deque<TreePath>> stack = new ArrayDeque<>(); stack.push(children(model, path)); while (path != null) { Deque<TreePath> siblings = stack.peek(); if (siblings == null) return null; // nothing to process TreePath next = siblings.poll(); if (next == null) { LOG.assertTrue(siblings == stack.poll()); path = path.getParentPath(); } else { switch (visitor.visit(next)) { case INTERRUPT -> { return next; // path is found } case CONTINUE -> { path = next; stack.push(children(model, path)); } case SKIP_SIBLINGS -> siblings.clear(); case SKIP_CHILDREN -> {} } } } LOG.assertTrue(stack.isEmpty()); return null; }
visitModel
278,460
Deque<TreePath> (@NotNull TreeModel model, @NotNull TreePath path) { Object object = path.getLastPathComponent(); int count = model.getChildCount(object); Deque<TreePath> deque = new ArrayDeque<>(count); for (int i = 0; i < count; i++) { deque.add(path.pathByAddingChild(model.getChild(object, i))); } return deque; }
children
278,461
TreePath (@NotNull JTree tree, @NotNull TreeVisitor visitor) { TreePath parent = null; int count = tree.getRowCount(); for (int row = 0; row < count; row++) { TreePath path = getVisiblePathWithValidation(tree, row, count); if (parent == null || !parent.isDescendant(path)) { switch (visitor.visit(path)) { case INTERRUPT -> { return path; // path is found } case CONTINUE -> parent = null; case SKIP_CHILDREN -> parent = path; case SKIP_SIBLINGS -> { parent = path.getParentPath(); if (parent == null) return null; } } } } return null; }
visitVisibleRows
278,462
boolean () { if (ScreenReader.isActive()) return false; if (!Registry.is("ide.tree.ui.cyclic.scrolling.allowed")) return false; UISettings settings = UISettings.getInstanceOrNull(); return settings != null && settings.getCycleScrolling(); }
isCyclicScrollingAllowed
278,463
TreePath (@NotNull JTree tree, int row, int count) { if (count != tree.getRowCount()) throw new ConcurrentModificationException("tree is modified"); TreePath path = tree.getPathForRow(row); if (path == null) throw new NullPointerException("path is not found at row " + row); return path; }
getVisiblePathWithValidation
278,464
boolean (@NotNull TreeNode node, int threshold) { return hasManyNodes(node, threshold); }
hasManyChildren
278,465
TreePath () { int aliveIndex = findLowestAliveNodeIndex(mySelectionPath); if (aliveIndex == mySelectionPath.getPathCount() - 1) return mySelectionPath; TreeNode aliveAncestor = (TreeNode) mySelectionPath.getPathComponent(aliveIndex); TreePath newSelection = TreeUtil.getPathFromRoot(aliveAncestor); int childrenLeft = aliveAncestor.getChildCount(); if (childrenLeft != 0) { int newSelectedChildIndex = Math.min(myIndicies[aliveIndex + 1], childrenLeft - 1); newSelection = newSelection.pathByAddingChild(aliveAncestor.getChildAt(newSelectedChildIndex)); } return newSelection; }
getRestoredPath
278,466
void (JTree tree) { TreeUtil.selectPath(tree, getRestoredPath()); }
restoreSelection
278,467
int (TreePath path) { Object[] nodes = path.getPath(); for (int i = 1; i < nodes.length; i++) { TreeNode node = (TreeNode) nodes[i]; if (node.getParent() == null) return i - 1; } return nodes.length - 1; }
findLowestAliveNodeIndex
278,468
int[] (TreePath path) { int[] result = new int[path.getPathCount()]; for (int i = 0; i < path.getPathCount(); i++) { TreeNode node = (TreeNode) path.getPathComponent(i); TreeNode parent = node.getParent(); result[i] = parent != null ? parent.getIndex(node) : 0; } return result; }
pathToChildIndecies
278,469
Easing (double c1x, double c1y, double c2x, double c2y) { return new CubicBezierEasing(c1x, c1y, c2x, c2y); }
bezier
278,470
double (double x) { value = x; return delegate.calc(value); }
calc
278,471
JBAnimatorHelper () { return JBAnimatorHelperHolder.INSTANCE; }
getInstance
278,472
void (@NotNull JBAnimator requestor) { if (isAvailable()) { var helper = getInstance(); if (helper.requestors.add(requestor)) { helper.lib.timeBeginPeriod(PERIOD); } } }
requestHighPrecisionTimer
278,473
void (@NotNull JBAnimator requestor) { if (isAvailable()) { var helper = getInstance(); if (helper.requestors.remove(requestor)) { helper.lib.timeEndPeriod(PERIOD); } } }
cancelHighPrecisionTimer
278,474
boolean () { if (!SystemInfoRt.isWindows || exceptionInInitialization != null) { return false; } return PropertiesComponent.getInstance().getBoolean(PROPERTY_NAME, DEFAULT_VALUE); }
isAvailable
278,475
void (boolean value) { if (exceptionInInitialization != null) { Logger.getInstance(JBAnimatorHelper.class).error(exceptionInInitialization); } if (!SystemInfoRt.isWindows) { throw new IllegalArgumentException("This option can be set only on Windows"); } PropertiesComponent.getInstance().setValue(PROPERTY_NAME, value, DEFAULT_VALUE); var helper = getInstance(); if (!helper.requestors.isEmpty()) { helper.requestors.clear(); helper.lib.timeEndPeriod(PERIOD); } }
setAvailable
278,476
int (int period) { return 0; }
timeBeginPeriod
278,477
int (int period) { return 0; }
timeEndPeriod
278,478
void (double c1x, double c1y, double c2x, double c2y) { for (int i = 0; i < xs.length; i++) { xs[i] = bezier(i * 1. / (xs.length - 1), c1x, c2x); ys[i] = bezier(i * 1. / (ys.length - 1), c1y, c2y); } }
update
278,479
int () { assert xs.length == ys.length; return xs.length; }
getSize
278,480
double (double x) { int res = Arrays.binarySearch(xs, x); if (res < 0) { res = -res - 1; } return ys[min(res, ys.length - 1)]; }
calc
278,481
double (double t, double u1, double u2) { double v = 1 - t; return 3 * u1 * v * v * t + 3 * u2 * v * t * t + t * t * t; }
bezier
278,482
void (T t) { this.value = t; }
accept
278,483
long (Animation @NotNull... animations) { return animate(Arrays.asList(animations)); }
animate
278,484
long (@NotNull Collection<@NotNull Animation> animations) { if (myDisposed.get()) { LOG.warn("Animator is already disposed"); return Long.MAX_VALUE; } var from = Integer.MAX_VALUE; var to = 0; for (Animation animation : animations) { from = Math.min(animation.getDelay(), from); to = Math.max(animation.getDelay() + animation.getDuration(), to); } final var delay = animations.isEmpty() ? 0 : from; final var duration = animations.isEmpty() ? 0 : to - from; final var taskId = myRunning.incrementAndGet(); if (!myIgnorePowerSaveMode && PowerSaveMode.isEnabled() || Registry.is("ui.no.bangs.and.whistles", false) || RemoteDesktopService.isRemoteSession() || duration == 0) { myCurrentAnimatorFuture = myService.schedule(() -> { if (taskId < myRunning.get()) { for (Animation animation : animations) { animation.fireEvent(Animation.Phase.CANCELLED); } return; } for (Animation animation : animations) { try { animation.fireEvent(Animation.Phase.SCHEDULED); animation.update(1.0); animation.fireEvent(Animation.Phase.UPDATED); animation.fireEvent(Animation.Phase.EXPIRED); } catch (Throwable t) { LOG.error(t); } } myRunning.compareAndSet(taskId, taskId + 1); }, delay, TimeUnit.MILLISECONDS); return taskId; } final var stat = new Statistic(myName, taskId); stat.start = System.nanoTime(); if (myPeriod < 16) { // do not enable this until it's really necessary JBAnimatorHelper.requestHighPrecisionTimer(this); } myCurrentAnimatorFuture = myService.schedule(new Runnable() { final Type type = myType; final int period = myPeriod; final boolean cycle = myCyclic; @Nullable FrameCounter frameCounter; @NotNull LinkedHashSet<Animation> scheduledAnimations = new LinkedHashSet<>(); //private final long animationStarted = System.nanoTime(); private long nextScheduleTime = System.nanoTime() + TimeUnit.MILLISECONDS.toNanos(delay); // ns private void prepareAnimations() { frameCounter = create(type, period, duration); scheduledAnimations = new LinkedHashSet<>(animations); for (Animation animation : scheduledAnimations) { animation.fireEvent(Animation.Phase.SCHEDULED); } } private void finalizeRunning() { JBAnimatorHelper.cancelHighPrecisionTimer(JBAnimator.this); stat.end = System.nanoTime(); myStatistic = stat; } @Override public void run() { stat.count.incrementAndGet(); // There's a penalty for run a task. // To decrease cumulative penalty difference between real start // and expected is subtracted from the next delay long wasLate = System.nanoTime() - nextScheduleTime; if (wasLate < 0) { LOG.warn("Negative animation late value"); wasLate = 0; } if (taskId < myRunning.get()) { finalizeRunning(); for (Animation animation : scheduledAnimations) { animation.fireEvent(Animation.Phase.CANCELLED); } return; } if (frameCounter == null) { prepareAnimations(); } long totalFrames = frameCounter.getTotalFrames(); long currentFrame = Math.min(frameCounter.getNextFrame(cycle), totalFrames); long currentDelay = frameCounter.getDelay(currentFrame); double timeline = (double) currentFrame / totalFrames; if (currentFrame >= totalFrames && cycle) { frameCounter = null; } final var expired = new LinkedList<Animation>(); for (Animation animation : scheduledAnimations) { double start = (double) (animation.getDelay() - delay) / duration; double end = start + (double) animation.getDuration() / duration; if (start <= timeline) try { double current = (timeline - start) / (end - start); animation.update(MathUtil.clamp(current, 0.0, 1.0)); animation.fireEvent(Animation.Phase.UPDATED); } catch (Throwable t) { LOG.error(t); } if (timeline > end) { expired.add(animation); } } expired.forEach(scheduledAnimations::remove); boolean isProceed = currentFrame < totalFrames || cycle; if (isProceed) { long nextDelay = Math.max(TimeUnit.MILLISECONDS.toNanos(currentDelay) - wasLate, TimeUnit.MILLISECONDS.toNanos(1)); nextScheduleTime = System.nanoTime() + nextDelay; myCurrentAnimatorFuture = myService.schedule(this, nextDelay, TimeUnit.NANOSECONDS); } else { // There's a situation when a new task is submitted but current is already in progress. // For example, the task can be submitted with Animation#runWhenExpired, // but this code synchronously can fire animate, therefore myRunning increases. // If this situation happens the current one ID is abandoned, // because the value is increased somewhere else. myRunning.compareAndSet(taskId, taskId + 1); //var debugInfo = "Animation total time is " + // TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - animationStarted) + // " ms; requested time is " + // (delay + duration); //LOG.info(debugInfo); finalizeRunning(); } // we should fire events after taskId is updated // and some final activity is done by calling finalizeRunning for (Animation animation : isProceed ? expired : scheduledAnimations) { animation.fireEvent(Animation.Phase.EXPIRED); } } }, delay, TimeUnit.MILLISECONDS); return taskId; }
animate
278,485
void () { frameCounter = create(type, period, duration); scheduledAnimations = new LinkedHashSet<>(animations); for (Animation animation : scheduledAnimations) { animation.fireEvent(Animation.Phase.SCHEDULED); } }
prepareAnimations
278,486
void () { JBAnimatorHelper.cancelHighPrecisionTimer(JBAnimator.this); stat.end = System.nanoTime(); myStatistic = stat; }
finalizeRunning
278,487
void () { stat.count.incrementAndGet(); // There's a penalty for run a task. // To decrease cumulative penalty difference between real start // and expected is subtracted from the next delay long wasLate = System.nanoTime() - nextScheduleTime; if (wasLate < 0) { LOG.warn("Negative animation late value"); wasLate = 0; } if (taskId < myRunning.get()) { finalizeRunning(); for (Animation animation : scheduledAnimations) { animation.fireEvent(Animation.Phase.CANCELLED); } return; } if (frameCounter == null) { prepareAnimations(); } long totalFrames = frameCounter.getTotalFrames(); long currentFrame = Math.min(frameCounter.getNextFrame(cycle), totalFrames); long currentDelay = frameCounter.getDelay(currentFrame); double timeline = (double) currentFrame / totalFrames; if (currentFrame >= totalFrames && cycle) { frameCounter = null; } final var expired = new LinkedList<Animation>(); for (Animation animation : scheduledAnimations) { double start = (double) (animation.getDelay() - delay) / duration; double end = start + (double) animation.getDuration() / duration; if (start <= timeline) try { double current = (timeline - start) / (end - start); animation.update(MathUtil.clamp(current, 0.0, 1.0)); animation.fireEvent(Animation.Phase.UPDATED); } catch (Throwable t) { LOG.error(t); } if (timeline > end) { expired.add(animation); } } expired.forEach(scheduledAnimations::remove); boolean isProceed = currentFrame < totalFrames || cycle; if (isProceed) { long nextDelay = Math.max(TimeUnit.MILLISECONDS.toNanos(currentDelay) - wasLate, TimeUnit.MILLISECONDS.toNanos(1)); nextScheduleTime = System.nanoTime() + nextDelay; myCurrentAnimatorFuture = myService.schedule(this, nextDelay, TimeUnit.NANOSECONDS); } else { // There's a situation when a new task is submitted but current is already in progress. // For example, the task can be submitted with Animation#runWhenExpired, // but this code synchronously can fire animate, therefore myRunning increases. // If this situation happens the current one ID is abandoned, // because the value is increased somewhere else. myRunning.compareAndSet(taskId, taskId + 1); //var debugInfo = "Animation total time is " + // TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - animationStarted) + // " ms; requested time is " + // (delay + duration); //LOG.info(debugInfo); finalizeRunning(); } // we should fire events after taskId is updated // and some final activity is done by calling finalizeRunning for (Animation animation : isProceed ? expired : scheduledAnimations) { animation.fireEvent(Animation.Phase.EXPIRED); } }
run
278,488
boolean (long taskId) { return myRunning.get() == taskId; }
isRunning
278,489
void () { myRunning.incrementAndGet(); }
stop
278,490
int () { return myPeriod; }
getPeriod
278,491
JBAnimator (int period) { myPeriod = Math.max(period, 1); return this; }
setPeriod
278,492
boolean () { return myCyclic; }
isCyclic
278,493
JBAnimator (boolean cyclic) { myCyclic = cyclic; return this; }
setCyclic
278,494
JBAnimator () { myIgnorePowerSaveMode = true; return this; }
ignorePowerSaveMode
278,495
Type () { return myType; }
getType
278,496
JBAnimator (Type type) { myType = type; return this; }
setType
278,497
JBAnimator (@Nullable String name) { myName = name; return this; }
setName
278,498
void () { stop(); myCurrentAnimatorFuture.cancel(false); if (!myDisposed.getAndSet(true) && myService != EdtExecutorService.getScheduledExecutorInstance()) { myService.shutdownNow(); JBAnimatorHelper.cancelHighPrecisionTimer(this); } }
dispose
278,499
FrameCounter (@NotNull Type type, int period, int duration) { return switch (type) { case EACH_FRAME -> new FrameCounter() { final long frames = duration / period + ((duration % period == 0) ? 0 : 1); long frame; @Override public long getNextFrame(boolean isCyclic) { var f = frame; frame++; if (isCyclic) { frame %= frames; } return f; } @Override public long getTotalFrames() { // at least one frame should be played return Math.max(frames, 1); } @Override public long getDelay(long currentFrame) { return period; } }; case IN_TIME -> new FrameCounter() { final long startTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); @Override public long getNextFrame(boolean isCyclic) { return TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - startTime; } @Override public long getTotalFrames() { return duration; } @Override public long getDelay(long currentFrame) { return Math.min(duration - currentFrame, period); } }; }; }
create