/** Begins listening on changes in the background. */ public synchronized void startBackgroundListening() { if (watchTimer == null) { watchTimer = new Timer("cloud debug watcher", true /* isDaemon */); watchTimer.schedule(new CloudDebugGlobalPollerTimerTask(this), DELAY_MS, DELAY_MS); ApplicationManager.getApplication() .addApplicationListener( new ApplicationAdapter() { @Override public void applicationExiting() { if (watchTimer != null) { watchTimer.cancel(); } } }); } }
static void watchForEvents(Application application) { AtomicBoolean reported = new AtomicBoolean(); IdeEventQueue.getInstance().addPostprocessor(e -> { if (application.isWriteAccessAllowed() && reported.compareAndSet(false, true)) { LOG.error("AWT events are not allowed inside write action: " + e); } return true; }, application); application.addApplicationListener(new ApplicationAdapter() { @Override public void afterWriteActionFinished(@Nonnull Object action) { reported.set(false); } }); }
@NotNull public static ProgressIndicator forceWriteActionPriority(@NotNull final ProgressIndicator progress, @NotNull final Disposable builder) { ApplicationManager.getApplication().addApplicationListener(new ApplicationAdapter() { @Override public void beforeWriteActionStart(Object action) { if (progress.isRunning()) { progress.cancel(); } } }, builder); return progress; }
@Nonnull public static ProgressIndicator forceWriteActionPriority(@Nonnull ProgressIndicator progress, @Nonnull Disposable parentDisposable) { ApplicationManager.getApplication().addApplicationListener(new ApplicationAdapter() { @Override public void beforeWriteActionStart(@Nonnull Object action) { if (progress.isRunning()) { progress.cancel(); } } }, parentDisposable); return progress; }
protected void showTextFieldPanel() { final JLayeredPane layeredPane = getLayeredPane(); final Dimension preferredTextFieldPanelSize = myTextFieldPanel.getPreferredSize(); final int x = (layeredPane.getWidth() - preferredTextFieldPanelSize.width) / 2; final int paneHeight = layeredPane.getHeight(); final int y = paneHeight / 3 - preferredTextFieldPanelSize.height / 2; VISIBLE_LIST_SIZE_LIMIT = Math.max (10, (paneHeight - (y + preferredTextFieldPanelSize.height)) / (preferredTextFieldPanelSize.height / 2) - 1); ComponentPopupBuilder builder = JBPopupFactory.getInstance().createComponentPopupBuilder(myTextFieldPanel, myTextField); builder.setCancelCallback(new Computable<Boolean>() { @Override public Boolean compute() { myTextPopup = null; close(false); return Boolean.TRUE; } }).setFocusable(true).setRequestFocus(true).setModalContext(false).setCancelOnClickOutside(false); Point point = new Point(x, y); SwingUtilities.convertPointToScreen(point, layeredPane); Rectangle bounds = new Rectangle(point, new Dimension(preferredTextFieldPanelSize.width + 20, preferredTextFieldPanelSize.height)); myTextPopup = builder.createPopup(); myTextPopup.setSize(bounds.getSize()); myTextPopup.setLocation(bounds.getLocation()); new MnemonicHelper().register(myTextFieldPanel); if (myProject != null && !myProject.isDefault()) { DaemonCodeAnalyzer.getInstance(myProject).disableUpdateByTimer(myTextPopup); } Disposer.register(myTextPopup, new Disposable() { @Override public void dispose() { cancelCalcElementsThread(); } }); ApplicationManager.getApplication().addApplicationListener(new ApplicationAdapter() { @Override public void beforeWriteActionStart(Object action) { CalcElementsThread prevThread = cancelCalcElementsThread(); if (prevThread != null) { prevThread.scheduleRestart(); } } }, myTextPopup); myTextPopup.show(layeredPane); }