Search in sources :

Example 41 with Disposable

use of com.intellij.openapi.Disposable in project intellij-community by JetBrains.

the class UIUtil method addAwtListener.

public static void addAwtListener(final AWTEventListener listener, long mask, Disposable parent) {
    Toolkit.getDefaultToolkit().addAWTEventListener(listener, mask);
    Disposer.register(parent, new Disposable() {

        @Override
        public void dispose() {
            Toolkit.getDefaultToolkit().removeAWTEventListener(listener);
        }
    });
}
Also used : Disposable(com.intellij.openapi.Disposable)

Example 42 with Disposable

use of com.intellij.openapi.Disposable in project intellij-community by JetBrains.

the class AboutPopup method show.

public static void show(@Nullable Window window, boolean showDebugInfo) {
    ApplicationInfoEx appInfo = (ApplicationInfoEx) ApplicationInfo.getInstance();
    final PopupPanel panel = new PopupPanel(new BorderLayout());
    Icon image = IconLoader.getIcon(appInfo.getAboutImageUrl());
    if (appInfo.showLicenseeInfo()) {
        final InfoSurface infoSurface = new InfoSurface(image, showDebugInfo);
        infoSurface.setPreferredSize(new Dimension(image.getIconWidth(), image.getIconHeight()));
        panel.setInfoSurface(infoSurface);
    } else {
        panel.add(new JLabel(image), BorderLayout.NORTH);
    }
    RelativePoint location;
    if (window != null) {
        Rectangle r = window.getBounds();
        location = new RelativePoint(window, new Point((r.width - image.getIconWidth()) / 2, (r.height - image.getIconHeight()) / 2));
    } else {
        Rectangle r = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getBounds();
        location = new RelativePoint(new Point((r.width - image.getIconWidth()) / 2, (r.height - image.getIconHeight()) / 2));
    }
    ourPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(panel, panel).setRequestFocus(true).setFocusable(true).setResizable(false).setMovable(false).setModalContext(false).setShowShadow(true).setShowBorder(false).setCancelKeyEnabled(true).setCancelOnClickOutside(true).setCancelOnOtherWindowOpen(true).createPopup();
    Disposer.register(ourPopup, new Disposable() {

        @Override
        public void dispose() {
            ourPopup = null;
        }
    });
    ourPopup.show(location);
}
Also used : Disposable(com.intellij.openapi.Disposable) ApplicationInfoEx(com.intellij.openapi.application.ex.ApplicationInfoEx) RelativePoint(com.intellij.ui.awt.RelativePoint) RelativePoint(com.intellij.ui.awt.RelativePoint)

Example 43 with Disposable

use of com.intellij.openapi.Disposable in project intellij-community by JetBrains.

the class LafManagerImpl method initComponent.

@Override
public void initComponent() {
    if (myCurrentLaf != null) {
        final UIManager.LookAndFeelInfo laf = findLaf(myCurrentLaf.getClassName());
        if (laf != null) {
            boolean needUninstall = UIUtil.isUnderDarcula();
            // setup default LAF or one specified by readExternal.
            setCurrentLookAndFeel(laf);
            updateWizardLAF(needUninstall);
        }
    }
    updateUI();
    if (SystemInfo.isXWindow) {
        PropertyChangeListener themeChangeListener = new PropertyChangeListener() {

            @Override
            public void propertyChange(final PropertyChangeEvent evt) {
                //noinspection SSBasedInspection
                SwingUtilities.invokeLater(() -> {
                    fixGtkPopupStyle();
                    patchGtkDefaults(UIManager.getLookAndFeelDefaults());
                });
            }
        };
        Toolkit.getDefaultToolkit().addPropertyChangeListener(GNOME_THEME_PROPERTY_NAME, themeChangeListener);
        Disposer.register(this, new Disposable() {

            @Override
            public void dispose() {
                Toolkit.getDefaultToolkit().removePropertyChangeListener(GNOME_THEME_PROPERTY_NAME, themeChangeListener);
            }
        });
    }
}
Also used : Disposable(com.intellij.openapi.Disposable) PropertyChangeEvent(java.beans.PropertyChangeEvent) PropertyChangeListener(java.beans.PropertyChangeListener)

Example 44 with Disposable

use of com.intellij.openapi.Disposable in project intellij-community by JetBrains.

the class BackgroundTaskUtil method executeOnPooledThread.

@NotNull
@CalledInAny
public static ProgressIndicator executeOnPooledThread(@NotNull Consumer<ProgressIndicator> task, @NotNull Disposable parent, @NotNull ModalityState modalityState) {
    ProgressIndicator indicator = new EmptyProgressIndicator(modalityState);
    Disposable disposable = new Disposable() {

        @Override
        public void dispose() {
            if (indicator.isRunning())
                indicator.cancel();
        }
    };
    Disposer.register(parent, disposable);
    indicator.start();
    ApplicationManager.getApplication().executeOnPooledThread(() -> {
        ProgressManager.getInstance().executeProcessUnderProgress(() -> {
            try {
                task.consume(indicator);
            } finally {
                indicator.stop();
                Disposer.dispose(disposable);
            }
        }, indicator);
    });
    return indicator;
}
Also used : Disposable(com.intellij.openapi.Disposable) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) CalledInAny(org.jetbrains.annotations.CalledInAny) NotNull(org.jetbrains.annotations.NotNull)

Example 45 with Disposable

use of com.intellij.openapi.Disposable in project intellij-community by JetBrains.

the class SmoothProgressAdapter method stop.

@Override
public synchronized void stop() {
    if (myOriginal.isRunning()) {
        myOriginal.stop();
    } else {
        myStartupAlarm.cancel(false);
        if (!myOriginalStarted && myOriginal instanceof Disposable) {
            // dispose original because start & stop were not called so original progress might not have released its resources 
            Disposer.dispose(((Disposable) myOriginal));
        }
    }
    // needed only for correct assertion of !progress.isRunning() in ApplicationImpl.runProcessWithProgressSynchroniously
    final Semaphore semaphore = new Semaphore();
    semaphore.down();
    SwingUtilities.invokeLater(() -> {
        semaphore.waitFor();
        if (myDialog != null) {
            //System.out.println("myDialog.destroyProcess()");
            myDialog.close(DialogWrapper.OK_EXIT_CODE);
            myDialog = null;
        }
    });
    try {
        // should be last to not leaveModal before closing the dialog
        super.stop();
    } finally {
        semaphore.up();
    }
}
Also used : Disposable(com.intellij.openapi.Disposable) Semaphore(com.intellij.util.concurrency.Semaphore)

Aggregations

Disposable (com.intellij.openapi.Disposable)282 NotNull (org.jetbrains.annotations.NotNull)52 Test (org.junit.Test)25 Project (com.intellij.openapi.project.Project)18 TestOnly (org.jetbrains.annotations.TestOnly)17 ArrayList (java.util.ArrayList)13 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 RelativePoint (com.intellij.ui.awt.RelativePoint)11 Nullable (org.jetbrains.annotations.Nullable)10 Document (com.intellij.openapi.editor.Document)9 File (java.io.File)9 ProcessHandler (com.intellij.execution.process.ProcessHandler)6 Editor (com.intellij.openapi.editor.Editor)6 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)6 VirtualFilePointer (com.intellij.openapi.vfs.pointers.VirtualFilePointer)6 Content (com.intellij.ui.content.Content)6 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)5 Alarm (com.intellij.util.Alarm)5 ActionEvent (java.awt.event.ActionEvent)5 ListSelectionEvent (javax.swing.event.ListSelectionEvent)5