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);
}
});
}
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);
}
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);
}
});
}
}
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;
}
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();
}
}
Aggregations