Java Code Examples for com.intellij.util.Alarm#addRequest()
The following examples show how to use
com.intellij.util.Alarm#addRequest() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AsyncPopupImpl.java From consulo with Apache License 2.0 | 6 votes |
public AsyncPopupImpl(@Nullable Project project, @Nullable WizardPopup parent, @Nonnull AsyncPopupStep<Object> step, @Nullable Object parentValue) { super(project, parent, step); if (!(parent instanceof NextStepHandler)) throw new IllegalArgumentException("parent must be NextStepHandler"); myCallBackParent = (NextStepHandler)parent; myParentValue = parentValue; myFuture = ApplicationManager.getApplication().executeOnPooledThread(step); myAlarm = new Alarm(this); myAlarm.addRequest(this, 200); Disposer.register(this, new Disposable() { @Override public void dispose() { if (!myFuture.isCancelled() && !myFuture.isDone()) { myFuture.cancel(false); } } }); }
Example 2
Source File: ControlledCycle.java From consulo with Apache License 2.0 | 6 votes |
public ControlledCycle(final Project project, final Getter<Boolean> callback, @Nonnull final String name, final int refreshInterval) { myRefreshInterval = (refreshInterval <= 0) ? ourRefreshInterval : refreshInterval; myActive = new AtomicBoolean(false); myRunnable = new Runnable() { boolean shouldBeContinued = true; @Override public void run() { if (! myActive.get() || project.isDisposed()) return; try { shouldBeContinued = callback.get(); } catch (ProcessCanceledException e) { return; } catch (RuntimeException e) { LOG.info(e); } if (! shouldBeContinued) { myActive.set(false); } else { mySimpleAlarm.addRequest(myRunnable, myRefreshInterval); } } }; mySimpleAlarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, project); }
Example 3
Source File: TodoPanel.java From consulo with Apache License 2.0 | 6 votes |
protected void rebuildWithAlarm(final Alarm alarm) { alarm.cancelAllRequests(); alarm.addRequest(() -> { final Set<VirtualFile> files = new HashSet<>(); DumbService.getInstance(myProject).runReadActionInSmartMode(() -> { if (myTodoTreeBuilder.isDisposed()) return; myTodoTreeBuilder.collectFiles(virtualFile -> { files.add(virtualFile); return true; }); final Runnable runnable = () -> { if (myTodoTreeBuilder.isDisposed()) return; myTodoTreeBuilder.rebuildCache(files); updateTree(); }; ApplicationManager.getApplication().invokeLater(runnable); }); }, 300); }
Example 4
Source File: AddFilterRuleDialog.java From AndroidStringsOneTabTranslation with Apache License 2.0 | 5 votes |
private void animate() { final int height = getPreferredSize().height; final int frameCount = 10; final boolean toClose = isShowing(); final AtomicInteger i = new AtomicInteger(-1); final Alarm animator = new Alarm(myDisposable); final Runnable runnable = new Runnable() { @Override public void run() { int state = i.addAndGet(1); double linearProgress = (double) state / frameCount; if (toClose) { linearProgress = 1 - linearProgress; } myLayout.myPhase = (1 - Math.cos(Math.PI * linearProgress)) / 2; Window window = getPeer().getWindow(); Rectangle bounds = window.getBounds(); bounds.height = (int) (height * myLayout.myPhase); window.setBounds(bounds); if (state == 0 && !toClose && window.getOwner() instanceof IdeFrame) { WindowManager.getInstance().requestUserAttention((IdeFrame) window.getOwner(), true); } if (state < frameCount) { animator.addRequest(this, 10); } else if (toClose) { AddFilterRuleDialog.super.dispose(); } } }; animator.addRequest(runnable, 10, ModalityState.stateForComponent(getRootPane())); }
Example 5
Source File: MultiSelectDialog.java From AndroidStringsOneTabTranslation with Apache License 2.0 | 5 votes |
private void animate() { final int height = getPreferredSize().height; final int frameCount = 10; final boolean toClose = isShowing(); final AtomicInteger i = new AtomicInteger(-1); final Alarm animator = new Alarm(myDisposable); final Runnable runnable = new Runnable() { @Override public void run() { int state = i.addAndGet(1); double linearProgress = (double) state / frameCount; if (toClose) { linearProgress = 1 - linearProgress; } myLayout.myPhase = (1 - Math.cos(Math.PI * linearProgress)) / 2; Window window = getPeer().getWindow(); Rectangle bounds = window.getBounds(); bounds.height = (int) (height * myLayout.myPhase); window.setBounds(bounds); if (state == 0 && !toClose && window.getOwner() instanceof IdeFrame) { WindowManager.getInstance().requestUserAttention((IdeFrame) window.getOwner(), true); } if (state < frameCount) { animator.addRequest(this, 10); } else if (toClose) { MultiSelectDialog.super.dispose(); } } }; animator.addRequest(runnable, 10, ModalityState.stateForComponent(getRootPane())); }
Example 6
Source File: Notifications.java From consulo with Apache License 2.0 | 5 votes |
public static void notifyAndHide(@Nonnull final Notification notification, @Nullable Project project) { notify(notification); Alarm alarm = new Alarm(project == null ? Application.get() : project); alarm.addRequest(() -> { notification.expire(); Disposer.dispose(alarm); }, 5000); }
Example 7
Source File: DesktopRequestFocusInToolWindowCmd.java From consulo with Apache License 2.0 | 5 votes |
private void requestFocus() { final Alarm checkerAlarm = new Alarm(); Runnable checker = new Runnable() { final long startTime = System.currentTimeMillis(); @Override public void run() { if (System.currentTimeMillis() - startTime > 10000) { LOG.debug(myToolWindow.getId(), " tool window - cannot wait for showing component"); return; } Component c = getShowingComponentToRequestFocus(); if (c != null) { final Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner(); if (owner != c) { getManager().getFocusManager().requestFocusInProject(c, myProject); bringOwnerToFront(); } getManager().getFocusManager().doWhenFocusSettlesDown(() -> updateToolWindow(c)); } else { checkerAlarm.addRequest(this, 100); } } }; checkerAlarm.addRequest(checker, 0); }
Example 8
Source File: Messages.java From consulo with Apache License 2.0 | 4 votes |
private void animate() { final int height = getPreferredSize().height; final int frameCount = 10; final boolean toClose = isShowing(); final AtomicInteger i = new AtomicInteger(-1); final Alarm animator = new Alarm(myDisposable); final Runnable runnable = new Runnable() { @Override public void run() { int state = i.addAndGet(1); double linearProgress = (double)state / frameCount; if (toClose) { linearProgress = 1 - linearProgress; } myLayout.myPhase = (1 - Math.cos(Math.PI * linearProgress)) / 2; Window window = getPeer().getWindow(); Rectangle bounds = window.getBounds(); bounds.height = (int)(height * myLayout.myPhase); window.setBounds(bounds); if (state == 0 && !toClose && window.getOwner() != null) { consulo.ui.Window uiWindow = TargetAWT.from(window.getOwner()); IdeFrame ideFrame = uiWindow.getUserData(IdeFrame.KEY); if(ideFrame != null) { WindowManager.getInstance().requestUserAttention(ideFrame, true); } } if (state < frameCount) { animator.addRequest(this, 10); } else if (toClose) { MessageDialog.super.dispose(); } } }; animator.addRequest(runnable, 10, ModalityState.stateForComponent(getRootPane())); }
Example 9
Source File: DesktopIdeFrameImpl.java From consulo with Apache License 2.0 | 4 votes |
public DesktopIdeFrameImpl(ActionManager actionManager, DataManager dataManager, Application application) { myJFrame = new MyFrame(); myJFrame.toUIWindow().putUserData(IdeFrame.KEY, this); myJFrame.toUIWindow().addUserDataProvider(key -> getData(key)); myJFrame.setTitle(FrameTitleUtil.buildTitle()); myRootPane = createRootPane(actionManager, dataManager, application); myJFrame.setRootPane(myRootPane); myJFrame.setBackground(UIUtil.getPanelBackground()); AppUIUtil.updateWindowIcon(myJFrame); final Dimension size = ScreenUtil.getMainScreenBounds().getSize(); size.width = Math.min(1400, size.width - 20); size.height = Math.min(1000, size.height - 40); myJFrame.setSize(size); myJFrame.setLocationRelativeTo(null); LayoutFocusTraversalPolicyExt layoutFocusTraversalPolicy = new LayoutFocusTraversalPolicyExt(); myJFrame.setFocusTraversalPolicy(layoutFocusTraversalPolicy); setupCloseAction(); MnemonicHelper.init(myJFrame); myBalloonLayout = new DesktopBalloonLayoutImpl(myRootPane, new Insets(8, 8, 8, 8)); // to show window thumbnail under Macs // http://lists.apple.com/archives/java-dev/2009/Dec/msg00240.html if (SystemInfo.isMac) myJFrame.setIconImage(null); MouseGestureManager.getInstance().add(this); myFrameDecorator = IdeFrameDecorator.decorate(this); myJFrame.addWindowStateListener(new WindowAdapter() { @Override public void windowStateChanged(WindowEvent e) { updateBorder(); } }); if (SystemInfo.isWindows) { myWindowsBorderUpdater = __ -> updateBorder(); Toolkit.getDefaultToolkit().addPropertyChangeListener("win.xpstyle.themeActive", myWindowsBorderUpdater); if (!SystemInfo.isJavaVersionAtLeast(8, 0, 0)) { final Ref<Dimension> myDimensionRef = new Ref<>(new Dimension()); final Alarm alarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD); final Runnable runnable = new Runnable() { @Override public void run() { if (myJFrame.isDisplayable() && !myJFrame.getSize().equals(myDimensionRef.get())) { Rectangle bounds = myJFrame.getBounds(); bounds.width--; myJFrame.setBounds(bounds); bounds.width++; myJFrame.setBounds(bounds); myDimensionRef.set(myJFrame.getSize()); } alarm.addRequest(this, 50); } }; alarm.addRequest(runnable, 50); } } // UIUtil.suppressFocusStealing(); }