com.intellij.util.Alarm Java Examples
The following examples show how to use
com.intellij.util.Alarm.
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: SearchUtil.java From consulo with Apache License 2.0 | 6 votes |
public static void showHintPopup(final ConfigurableSearchTextField searchField, final JBPopup[] activePopup, final Alarm showHintAlarm, final Consumer<String> selectConfigurable, final Project project) { for (JBPopup aPopup : activePopup) { if (aPopup != null) { aPopup.cancel(); } } final JBPopup popup = createPopup(searchField, activePopup, showHintAlarm, selectConfigurable, project, 0); //no selection if (popup != null) { popup.showUnderneathOf(searchField); searchField.requestFocusInWindow(); } activePopup[0] = popup; activePopup[1] = null; }
Example #2
Source File: VcsAnnotationLocalChangesListenerImpl.java From consulo with Apache License 2.0 | 6 votes |
public VcsAnnotationLocalChangesListenerImpl(Project project, final ProjectLevelVcsManager vcsManager) { myLock = new Object(); myUpdateStuff = createUpdateStuff(); myUpdater = new ZipperUpdater(ApplicationManager.getApplication().isUnitTestMode() ? 10 : 300, Alarm.ThreadToUse.POOLED_THREAD, project); myConnection = project.getMessageBus().connect(); myLocalFileSystem = LocalFileSystem.getInstance(); VcsAnnotationRefresher handler = createHandler(); myDirtyPaths = new HashSet<>(); myDirtyChanges = new HashMap<>(); myDirtyFiles = new HashSet<>(); myFileAnnotationMap = MultiMap.createSet(); myVcsManager = vcsManager; myVcsKeySet = new HashSet<>(); myConnection.subscribe(VcsAnnotationRefresher.LOCAL_CHANGES_CHANGED, handler); }
Example #3
Source File: DialogWrapper.java From consulo with Apache License 2.0 | 6 votes |
protected final void initValidation() { myValidationAlarm.cancelAllRequests(); final Runnable validateRequest = () -> { if (myDisposed) return; List<ValidationInfo> result = doValidateAll(); if (!result.isEmpty()) { installErrorPainter(); } myErrorPainter.setValidationInfo(result); updateErrorInfo(result); if (!myDisposed) { initValidation(); } }; if (getValidationThreadToUse() == Alarm.ThreadToUse.SWING_THREAD) { // null if headless JRootPane rootPane = getRootPane(); myValidationAlarm.addRequest(validateRequest, myValidationDelay, ApplicationManager.getApplication() == null ? null : rootPane == null ? ModalityState.current() : ModalityState.stateForComponent(rootPane)); } else { myValidationAlarm.addRequest(validateRequest, myValidationDelay); } }
Example #4
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 #5
Source File: BraceHighlightingHandler.java From consulo with Apache License 2.0 | 6 votes |
@Nonnull private static PsiFile getInjectedFileIfAny(@Nonnull final Editor editor, @Nonnull final Project project, int offset, @Nonnull PsiFile psiFile, @Nonnull final Alarm alarm) { Document document = editor.getDocument(); // when document is committed, try to highlight braces in injected lang - it's fast if (PsiDocumentManager.getInstance(project).isCommitted(document)) { final PsiElement injectedElement = InjectedLanguageManager.getInstance(psiFile.getProject()).findInjectedElementAt(psiFile, offset); if (injectedElement != null /*&& !(injectedElement instanceof PsiWhiteSpace)*/) { final PsiFile injected = injectedElement.getContainingFile(); if (injected != null) { return injected; } } } else { PsiDocumentManager.getInstance(project).performForCommittedDocument(document, () -> { if (!project.isDisposed() && !editor.isDisposed()) { BraceHighlighter.updateBraces(editor, alarm); } }); } return psiFile; }
Example #6
Source File: LookupUi.java From consulo with Apache License 2.0 | 6 votes |
void setCalculating(boolean calculating) { Runnable iconUpdater = () -> { if (calculating && myHintButton.isVisible()) { myHintButton.setVisible(false); } myProcessIcon.setVisible(calculating); ApplicationManager.getApplication().invokeLater(() -> { if (!calculating && !myLookup.isLookupDisposed()) { updateHint(); } }, myModalityState); }; if (calculating) { myProcessIcon.resume(); } else { myProcessIcon.suspend(); } new Alarm(myLookup).addRequest(iconUpdater, 100, myModalityState); }
Example #7
Source File: EvalOnDartLibrary.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
public EvalOnDartLibrary(Set<String> libraryNames, VmService vmService, VMServiceManager vmServiceManager) { this.libraryNames = libraryNames; this.vmService = vmService; this.vmServiceManager = vmServiceManager; this.myRequestsScheduler = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, this); libraryRef = new CompletableFuture<>(); subscription = vmServiceManager.getCurrentFlutterIsolate((isolate) -> { if (libraryRef.isDone()) { libraryRef = new CompletableFuture<>(); } if (isolate != null) { initialize(isolate.getId()); } }, true); delayer = new ScheduledThreadPoolExecutor(1); }
Example #8
Source File: ProjectListBuilder.java From consulo with Apache License 2.0 | 6 votes |
public ProjectListBuilder(final Project project, final CommanderPanel panel, final AbstractTreeStructure treeStructure, final Comparator comparator, final boolean showRoot) { super(project, panel.getList(), panel.getModel(), treeStructure, comparator, showRoot); myList.setCellRenderer(new ColoredCommanderRenderer(panel)); myUpdateAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD, myProject); myPsiTreeChangeListener = new MyPsiTreeChangeListener(); PsiManager.getInstance(myProject).addPsiTreeChangeListener(myPsiTreeChangeListener); myFileStatusListener = new MyFileStatusListener(); FileStatusManager.getInstance(myProject).addFileStatusListener(myFileStatusListener); myCopyPasteListener = new MyCopyPasteListener(); CopyPasteManager.getInstance().addContentChangedListener(myCopyPasteListener); buildRoot(); }
Example #9
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 #10
Source File: EvalOnDartLibrary.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 6 votes |
public EvalOnDartLibrary(Set<String> libraryNames, VmService vmService, VMServiceManager vmServiceManager) { this.libraryNames = libraryNames; this.vmService = vmService; this.vmServiceManager = vmServiceManager; this.myRequestsScheduler = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, this); libraryRef = new CompletableFuture<>(); subscription = vmServiceManager.getCurrentFlutterIsolate((isolate) -> { if (libraryRef.isDone()) { libraryRef = new CompletableFuture<>(); } if (isolate != null) { initialize(isolate.getId()); } }, true); delayer = new ScheduledThreadPoolExecutor(1); }
Example #11
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 #12
Source File: EditorBasedStatusBarPopup.java From consulo with Apache License 2.0 | 6 votes |
public EditorBasedStatusBarPopup(@Nonnull Project project, boolean writeableFileRequired) { super(project); myWriteableFileRequired = writeableFileRequired; update = new Alarm(this); myComponent = new TextPanel.WithIconAndArrows(); myComponent.setVisible(false); new ClickListener() { @Override public boolean onClick(@Nonnull MouseEvent e, int clickCount) { update(); showPopup(e); return true; } }.installOn(myComponent); myComponent.setBorder(WidgetBorder.WIDE); }
Example #13
Source File: BraceHighlightingHandler.java From consulo with Apache License 2.0 | 5 votes |
private BraceHighlightingHandler(@Nonnull Project project, @Nonnull Editor editor, @Nonnull Alarm alarm, PsiFile psiFile) { myProject = project; myEditor = editor; myAlarm = alarm; myDocument = (DocumentEx)myEditor.getDocument(); myPsiFile = psiFile; myCodeInsightSettings = CodeInsightSettings.getInstance(); }
Example #14
Source File: VcsRootScanner.java From consulo with Apache License 2.0 | 5 votes |
private VcsRootScanner(@Nonnull Project project, @Nonnull List<VcsRootChecker> checkers) { myRootProblemNotifier = VcsRootProblemNotifier.getInstance(project); myCheckers = checkers; final MessageBus messageBus = project.getMessageBus(); messageBus.connect().subscribe(ProjectLevelVcsManager.VCS_CONFIGURATION_CHANGED, this); messageBus.connect().subscribe(VirtualFileManager.VFS_CHANGES, this); messageBus.connect().subscribe(ProjectTopics.PROJECT_ROOTS, this); myAlarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, project); }
Example #15
Source File: ContentChooser.java From consulo with Apache License 2.0 | 5 votes |
public ContentChooser(Project project, String title, boolean useIdeaEditor, boolean allowMultipleSelections) { super(project, true); myProject = project; myUseIdeaEditor = useIdeaEditor; myAllowMultipleSelections = allowMultipleSelections; myUpdateAlarm = new Alarm(getDisposable()); mySplitter = new JBSplitter(true, 0.3f); mySplitter.setSplitterProportionKey(getDimensionServiceKey() + ".splitter"); myList = new JBList(new CollectionListModel<Item>()); setOKButtonText(CommonBundle.getOkButtonText()); setTitle(title); init(); }
Example #16
Source File: VcsDirtyScopeVfsListener.java From consulo with Apache License 2.0 | 5 votes |
@Inject public VcsDirtyScopeVfsListener(@Nonnull Project project) { myVcsManager = ProjectLevelVcsManager.getInstance(project); VcsDirtyScopeManager dirtyScopeManager = VcsDirtyScopeManager.getInstance(project); myLock = new Object(); myQueue = new ArrayList<>(); myDirtReporter = () -> { ArrayList<FilesAndDirs> list; synchronized (myLock) { list = new ArrayList<>(myQueue); myQueue.clear(); } HashSet<FilePath> dirtyFiles = new HashSet<>(); HashSet<FilePath> dirtyDirs = new HashSet<>(); for (FilesAndDirs filesAndDirs : list) { dirtyFiles.addAll(filesAndDirs.forcedNonRecursive); for (FilePath path : filesAndDirs.regular) { if (path.isDirectory()) { dirtyDirs.add(path); } else { dirtyFiles.add(path); } } } if (!dirtyFiles.isEmpty() || !dirtyDirs.isEmpty()) { dirtyScopeManager.filePathsDirty(dirtyFiles, dirtyDirs); } }; myZipperUpdater = new ZipperUpdater(300, Alarm.ThreadToUse.POOLED_THREAD, this); Disposer.register(project, this); VirtualFileManager.getInstance().addAsyncFileListener(this, project); }
Example #17
Source File: PositionPanel.java From consulo with Apache License 2.0 | 5 votes |
@Override public void install(@Nonnull StatusBar statusBar) { super.install(statusBar); myAlarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, this); EditorEventMulticaster multicaster = EditorFactory.getInstance().getEventMulticaster(); multicaster.addCaretListener(this, this); multicaster.addSelectionListener(this, this); multicaster.addDocumentListener(this, this); KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener(SWING_FOCUS_OWNER_PROPERTY, this); Disposer.register(this, () -> KeyboardFocusManager.getCurrentKeyboardFocusManager().removePropertyChangeListener(SWING_FOCUS_OWNER_PROPERTY, this)); }
Example #18
Source File: ChangesViewManager.java From consulo with Apache License 2.0 | 5 votes |
@Inject public ChangesViewManager(@Nonnull Project project, @Nonnull ChangesViewContentI contentManager) { myProject = project; myContentManager = contentManager; myView = new ChangesListView(project); myRepaintAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD, project); myTsl = new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { if (LOG.isDebugEnabled()) { TreePath[] paths = myView.getSelectionPaths(); String joinedPaths = paths != null ? StringUtil.join(paths, FunctionUtil.string(), ", ") : null; String message = "selection changed. selected: " + joinedPaths; if (LOG.isTraceEnabled()) { LOG.trace(message + " from: " + DebugUtil.currentStackTrace()); } else { LOG.debug(message); } } SwingUtilities.invokeLater(new Runnable() { @Override public void run() { changeDetails(); } }); } }; }
Example #19
Source File: BraceHighlighter.java From consulo with Apache License 2.0 | 5 votes |
static void updateBraces(@Nonnull final Editor editor, @Nonnull final Alarm alarm) { if (editor.getDocument().isInBulkUpdate()) return; BraceHighlightingHandler.lookForInjectedAndMatchBracesInOtherThread(editor, alarm, handler -> { handler.updateBraces(); return false; }); }
Example #20
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 #21
Source File: InspectionsConfigTreeTable.java From consulo with Apache License 2.0 | 5 votes |
public InspectionsConfigTreeTableModel(final InspectionsConfigTreeTableSettings settings, Disposable parentDisposable) { super(settings.getRoot()); mySettings = settings; myUpdateRunnable = new Runnable() { public void run() { settings.updateRightPanel(); ((AbstractTableModel)myTreeTable.getModel()).fireTableDataChanged(); } }; myUpdateAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD, parentDisposable); }
Example #22
Source File: ChangeListTodosPanel.java From consulo with Apache License 2.0 | 5 votes |
public ChangeListTodosPanel(Project project,TodoPanelSettings settings, Content content){ super(project,settings,false,content); ChangeListManager changeListManager = ChangeListManager.getInstance(project); final MyChangeListManagerListener myChangeListManagerListener = new MyChangeListManagerListener(); changeListManager.addChangeListListener(myChangeListManagerListener); Disposer.register(this, new Disposable() { @Override public void dispose() { ChangeListManager.getInstance(myProject).removeChangeListListener(myChangeListManagerListener); } }); myAlarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, this); }
Example #23
Source File: ScopeBasedTodosPanel.java From consulo with Apache License 2.0 | 5 votes |
public ScopeBasedTodosPanel(final Project project, TodoPanelSettings settings, Content content){ super(project,settings,false,content); myAlarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, this); myScopes.getChildComponent().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { rebuildWithAlarm(ScopeBasedTodosPanel.this.myAlarm); PropertiesComponent.getInstance(myProject).setValue(SELECTED_SCOPE, myScopes.getSelectedScopeName(), null); } }); rebuildWithAlarm(myAlarm); }
Example #24
Source File: ScopeViewPane.java From consulo with Apache License 2.0 | 5 votes |
@Inject public ScopeViewPane(final Project project, ProjectView projectView, DependencyValidationManager dependencyValidationManager, NamedScopeManager namedScopeManager) { super(project); myProjectView = projectView; myDependencyValidationManager = dependencyValidationManager; myNamedScopeManager = namedScopeManager; myScopeListener = new NamedScopesHolder.ScopeListener() { Alarm refreshProjectViewAlarm = new Alarm(); @Override public void scopesChanged() { // amortize batch scope changes refreshProjectViewAlarm.cancelAllRequests(); refreshProjectViewAlarm.addRequest(new Runnable() { @Override public void run() { if (myProject.isDisposed()) return; final String subId = getSubId(); final String id = myProjectView.getCurrentViewId(); myProjectView.removeProjectPane(ScopeViewPane.this); myProjectView.addProjectPane(ScopeViewPane.this); if (id != null) { if (Comparing.strEqual(id, getId())) { myProjectView.changeView(id, subId); } else { myProjectView.changeView(id); } } } }, 10); } }; myDependencyValidationManager.addScopeListener(myScopeListener, this); myNamedScopeManager.addScopeListener(myScopeListener, this); }
Example #25
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 #26
Source File: FlutterLogTree.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
private TreeModel(@NotNull ColumnModel columns, @NotNull Disposable parent, @NotNull FlutterLogPreferences logPreferences) { super(new LogRootTreeNode(), columns.getInfos()); this.logPreferences = logPreferences; this.log = columns.app.getFlutterLog(); this.columns = columns; // Scroll to end by default. autoScrollToEnd = true; setShowSequenceNumbers(false); uiThreadAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD, parent); updateTimer = new Timer(100, e -> uiExec(this::update, 0)); }
Example #27
Source File: DelayedDocumentWatcher.java From consulo with Apache License 2.0 | 5 votes |
public DelayedDocumentWatcher(@Nonnull Project project, int delayMillis, @Nonnull Consumer<Integer> modificationStampConsumer, @javax.annotation.Nullable Condition<VirtualFile> changedFileFilter) { myProject = project; myAlarm = new Alarm(Alarm.ThreadToUse.SWING_THREAD, project); myDelayMillis = delayMillis; myModificationStampConsumer = modificationStampConsumer; myChangedFileFilter = changedFileFilter; myListener = new MyDocumentAdapter(); myAlarmRunnable = new MyRunnable(); }
Example #28
Source File: LoadingDecorator.java From consulo with Apache License 2.0 | 5 votes |
public LoadingDecorator(JComponent content, @Nonnull Disposable parent, int startDelayMs, boolean useMinimumSize, @Nonnull AsyncProcessIcon icon) { myPane = new MyLayeredPane(useMinimumSize ? content : null); myLoadingLayer = new LoadingLayer(icon); myDelay = startDelayMs; myStartAlarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, parent); setLoadingText("Loading..."); myFadeOutAnimator = new Animator("Loading", 10, 500, false) { public void paintNow(final int frame, final int totalFrames, final int cycle) { myLoadingLayer.setAlpha(1f - ((float)frame) / ((float)totalFrames)); } @Override protected void paintCycleEnd() { myLoadingLayer.setVisible(false); myLoadingLayer.setAlpha(-1); } }; Disposer.register(parent, myFadeOutAnimator); myPane.add(content, JLayeredPane.DEFAULT_LAYER, 0); myPane.add(myLoadingLayer, JLayeredPane.DRAG_LAYER, 1); Disposer.register(parent, myLoadingLayer.myProgress); }
Example #29
Source File: VmServiceWrapper.java From flutter-intellij with BSD 3-Clause "New" or "Revised" License | 5 votes |
public VmServiceWrapper(@NotNull final DartVmServiceDebugProcess debugProcess, @NotNull final VmService vmService, @NotNull final DartVmServiceListener vmServiceListener, @NotNull final IsolatesInfo isolatesInfo, @NotNull final DartVmServiceBreakpointHandler breakpointHandler) { myDebugProcess = debugProcess; myVmService = vmService; myVmServiceListener = vmServiceListener; myIsolatesInfo = isolatesInfo; myBreakpointHandler = breakpointHandler; myRequestsScheduler = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, this); }
Example #30
Source File: AutoScrollFromSourceHandler.java From consulo with Apache License 2.0 | 5 votes |
public AutoScrollFromSourceHandler(@Nonnull Project project, @Nonnull JComponent view, @Nullable Disposable parentDisposable) { myProject = project; if (parentDisposable != null) { Disposer.register(parentDisposable, this); } myComponent = view; myAlarm = new Alarm(this); }