diff --git a/platform/platform-impl/src/com/intellij/ui/AppIcon.java b/platform/platform-impl/src/com/intellij/ui/AppIcon.java index cee5e62025e8..c0cb18181832 100644 --- a/platform/platform-impl/src/com/intellij/ui/AppIcon.java +++ b/platform/platform-impl/src/com/intellij/ui/AppIcon.java @@ -8,6 +8,7 @@ import com.intellij.openapi.application.ApplicationActivationListener; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.project.Project; +import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.wm.AppIconScheme; @@ -38,6 +39,8 @@ import java.nio.ByteOrder; import java.util.HashMap; import java.util.Map; +import static com.intellij.openapi.util.Pair.pair; + public abstract class AppIcon { private static final Logger LOG = Logger.getInstance(AppIcon.class); @@ -190,7 +193,7 @@ public abstract class AppIcon { @SuppressWarnings("UseJBColor") static final class MacAppIcon extends BaseIcon { private BufferedImage myAppImage; - private final Map myProgressImagesCache = new HashMap<>(); + private final Map> myProgressImagesCache = new HashMap<>(); private BufferedImage getAppImage() { EDT.assertIsEdt(); @@ -198,9 +201,7 @@ public abstract class AppIcon { try { if (myAppImage != null) return myAppImage; - Object app = getApp(); - Image appImage = (Image)getAppMethod("getDockIconImage").invoke(app); - + Image appImage = (Image)getAppMethod("getDockIconImage").invoke(getApp()); if (appImage == null) return null; // [tav] expecting two resolution variants for the dock icon: 128x128, 256x256 @@ -237,8 +238,7 @@ public abstract class AppIcon { try { getAppMethod("requestForeground", boolean.class).invoke(getApp(), true); } - catch (NoSuchMethodException ignored) { - } + catch (NoSuchMethodException ignored) { } catch (Exception e) { LOG.error(e); } @@ -251,8 +251,7 @@ public abstract class AppIcon { try { getAppMethod("requestUserAttention", boolean.class).invoke(getApp(), critical); } - catch (NoSuchMethodException ignored) { - } + catch (NoSuchMethodException ignored) { } catch (Exception e) { LOG.error(e); } @@ -262,14 +261,15 @@ public abstract class AppIcon { public boolean _hideProgress(@Nullable JFrame frame, Object processId) { EDT.assertIsEdt(); - if (getAppImage() == null) return false; if (myCurrentProcessId != null && !myCurrentProcessId.equals(processId)) return false; - setDockIcon(getAppImage()); + BufferedImage appImage = getAppImage(); + if (appImage == null) return false; + + setDockIcon(appImage); myProgressImagesCache.remove(myCurrentProcessId); myCurrentProcessId = null; myLastValue = 0; - return true; } @@ -277,14 +277,14 @@ public abstract class AppIcon { public void _setOkBadge(@Nullable JFrame frame, boolean visible) { EDT.assertIsEdt(); - if (getAppImage() == null) { - return; - } + BufferedImage appImage = getAppImage(); + if (appImage == null) return; + + Pair img = createAppImage(appImage); - AppImage img = createAppImage(); if (visible) { Icon okIcon = AllIcons.Mac.AppIconOk512; - int w = img.myImg.getWidth(); + int w = img.first.getWidth(); if (w != 128) { okIcon = IconUtil.scale(okIcon, frame != null ? frame.getRootPane() : null, w / 128f); } @@ -292,10 +292,10 @@ public abstract class AppIcon { int x = w - okIcon.getIconWidth(); int y = 0; - okIcon.paintIcon(JOptionPane.getRootFrame(), img.myG2d, x, y); + okIcon.paintIcon(JOptionPane.getRootFrame(), img.second, x, y); } - setDockIcon(img.myImg); + setDockIcon(img.first); } // white 80% transparent @@ -306,7 +306,8 @@ public abstract class AppIcon { public boolean _setProgress(@Nullable JFrame frame, Object processId, AppIconScheme.Progress scheme, double value, boolean isOk) { EDT.assertIsEdt(); - if (getAppImage() == null) return false; + BufferedImage appImage = getAppImage(); + if (appImage == null) return false; myCurrentProcessId = processId; @@ -335,19 +336,19 @@ public abstract class AppIcon { progressArea.intersect(borderArea); - AppImage appImg = myProgressImagesCache.get(myCurrentProcessId); - if (appImg == null) myProgressImagesCache.put(myCurrentProcessId, appImg = createAppImage()); + Pair appImg = myProgressImagesCache.get(myCurrentProcessId); + if (appImg == null) myProgressImagesCache.put(myCurrentProcessId, appImg = createAppImage(appImage)); - appImg.myG2d.setColor(PROGRESS_BACKGROUND_COLOR); - appImg.myG2d.fill(backgroundArea); - final Color color = isOk ? scheme.getOkColor() : scheme.getErrorColor(); - appImg.myG2d.setColor(color); - appImg.myG2d.fill(progressArea); - appImg.myG2d.setColor(PROGRESS_OUTLINE_COLOR); - appImg.myG2d.draw(backgroundArea); - appImg.myG2d.draw(borderArea); + Graphics2D g2d = appImg.second; + g2d.setColor(PROGRESS_BACKGROUND_COLOR); + g2d.fill(backgroundArea); + g2d.setColor(isOk ? scheme.getOkColor() : scheme.getErrorColor()); + g2d.fill(progressArea); + g2d.setColor(PROGRESS_OUTLINE_COLOR); + g2d.draw(backgroundArea); + g2d.draw(borderArea); - setDockIcon(appImg.myImg); + setDockIcon(appImg.first); myLastValue = value; } @@ -361,25 +362,12 @@ public abstract class AppIcon { return true; } - private AppImage createAppImage() { - BufferedImage appImage = getAppImage(); - assert appImage != null; - @SuppressWarnings("UndesirableClassUsage") - BufferedImage current = new BufferedImage(appImage.getWidth(), appImage.getHeight(), BufferedImage.TYPE_INT_ARGB); + private static Pair createAppImage(BufferedImage appImage) { + @SuppressWarnings("UndesirableClassUsage") BufferedImage current = new BufferedImage(appImage.getWidth(), appImage.getHeight(), BufferedImage.TYPE_INT_ARGB); Graphics2D g = current.createGraphics(); g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); StartupUiUtil.drawImage(g, appImage, 0, 0, null); - return new AppImage(current, g); - } - - private static final class AppImage { - BufferedImage myImg; - Graphics2D myG2d; - - AppImage(BufferedImage img, Graphics2D g2d) { - myImg = img; - myG2d = g2d; - } + return pair(current, g); } static void setDockIcon(BufferedImage image) { @@ -391,7 +379,7 @@ public abstract class AppIcon { } } - private static Method getAppMethod(@NonNls final String name, Class... args) throws NoSuchMethodException, ClassNotFoundException { + private static Method getAppMethod(String name, Class... args) throws NoSuchMethodException, ClassNotFoundException { return getAppClass().getMethod(name, args); } @@ -582,7 +570,7 @@ public abstract class AppIcon { int textHeight = UIUtil.getHighestGlyphHeight(text, font, g); g.setPaint(errorBadgeTextBackgroundColor); - g.fillOval( size / 2 - textWidth / 2, size / 2 - textHeight / 2, textWidth, textHeight); + g.fillOval(size / 2 - textWidth / 2, size / 2 - textHeight / 2, textWidth, textHeight); g.setColor(Color.white); g.drawString(text, size / 2 - textWidth / 2, size / 2 - fontMetrics.getHeight() / 2 + fontMetrics.getAscent()); @@ -655,7 +643,7 @@ public abstract class AppIcon { public void requestFocus() { try { // This is required for the focus stealing mechanism to work reliably, - // see WinFocusStealer.setFocusStealingEnabled's javadoc for details + // see WinFocusStealer.setFocusStealingEnabled javadoc for details Thread.sleep(Registry.intValue("win.request.focus.delay.ms")); } catch (InterruptedException e) { @@ -716,4 +704,4 @@ public abstract class AppIcon { @Override public void requestAttention(@Nullable Project project, boolean critical) { } } -} \ No newline at end of file +} diff --git a/platform/platform-impl/src/com/intellij/ui/mac/MacDockDelegate.java b/platform/platform-impl/src/com/intellij/ui/mac/MacDockDelegate.java index ae14a1265ec1..4b05d781e7fe 100644 --- a/platform/platform-impl/src/com/intellij/ui/mac/MacDockDelegate.java +++ b/platform/platform-impl/src/com/intellij/ui/mac/MacDockDelegate.java @@ -15,8 +15,6 @@ import com.intellij.openapi.wm.impl.SystemDock; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.util.List; /** @@ -31,13 +29,15 @@ public final class MacDockDelegate implements SystemDock.Delegate { private static final PopupMenu dockMenu = new PopupMenu("DockMenu"); private static final Menu recentProjectsMenu = new Menu("Recent Projects"); - private MacDockDelegate() {} + private MacDockDelegate() { } private static void initDockMenu() { dockMenu.add(recentProjectsMenu); try { - getAppMethod("setDockMenu", PopupMenu.class).invoke(getApp(), dockMenu); + Class appClass = Class.forName("com.apple.eawt.Application"); + Object application = appClass.getMethod("getApplication").invoke(null); + appClass.getMethod("setDockMenu", PopupMenu.class).invoke(application, dockMenu); } catch (Exception e) { LOG.error(e); @@ -51,7 +51,7 @@ public final class MacDockDelegate implements SystemDock.Delegate { List recentProjectActions = RecentProjectListActionProvider.getInstance().getActions(false); recentProjectsMenu.removeAll(); - for (final AnAction action : recentProjectActions) { + for (AnAction action : recentProjectActions) { MenuItem menuItem = new MenuItem(((ReopenProjectAction)action).getProjectName()); menuItem.addActionListener(new ActionListener() { @Override @@ -63,18 +63,6 @@ public final class MacDockDelegate implements SystemDock.Delegate { } } - private static Object getApp() throws NoSuchMethodException, ClassNotFoundException, InvocationTargetException, IllegalAccessException { - return getAppClass().getMethod("getApplication").invoke(null); - } - - private static Method getAppMethod(final String name, Class... args) throws NoSuchMethodException, ClassNotFoundException { - return getAppClass().getMethod(name, args); - } - - private static Class getAppClass() throws ClassNotFoundException { - return Class.forName("com.apple.eawt.Application"); - } - synchronized public static SystemDock.Delegate getInstance() { if (!initialized) { initDockMenu(); diff --git a/platform/platform-impl/src/com/intellij/ui/mac/MacMainFrameDecorator.java b/platform/platform-impl/src/com/intellij/ui/mac/MacMainFrameDecorator.java index 70343fc8a034..7c50354e2506 100644 --- a/platform/platform-impl/src/com/intellij/ui/mac/MacMainFrameDecorator.java +++ b/platform/platform-impl/src/com/intellij/ui/mac/MacMainFrameDecorator.java @@ -1,4 +1,4 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.ui.mac; import com.apple.eawt.*; @@ -22,13 +22,14 @@ import java.awt.*; import java.lang.reflect.Method; import java.util.EventListener; import java.util.LinkedList; +import java.util.Queue; public final class MacMainFrameDecorator extends IdeFrameDecorator { private interface FSListener extends FullScreenListener, EventListener {} private static class FSAdapter extends FullScreenAdapter implements FSListener {} private static class FullScreenQueue { - private final LinkedList myQueue = new LinkedList<>(); + private final Queue myQueue = new LinkedList<>(); private boolean myWaitingForAppKit = false; synchronized void runOrEnqueue(Runnable runnable) { @@ -74,7 +75,7 @@ public final class MacMainFrameDecorator extends IdeFrameDecorator { public static final String FULL_SCREEN = "Idea.Is.In.FullScreen.Mode.Now"; - private static Method requestToggleFullScreenMethod; + private static Method toggleFullScreenMethod; private static Method enterFullScreenMethod; private static Method leaveFullScreenMethod; @@ -91,7 +92,7 @@ public final class MacMainFrameDecorator extends IdeFrameDecorator { catch (NoSuchMethodException e) { // temporary solution for the old runtime //noinspection JavaReflectionMemberAccess - requestToggleFullScreenMethod = Application.class.getMethod("requestToggleFullScreen", Window.class); + toggleFullScreenMethod = Application.class.getMethod("requestToggleFullScreen", Window.class); } } catch (Exception e) { @@ -106,7 +107,7 @@ public final class MacMainFrameDecorator extends IdeFrameDecorator { public MacMainFrameDecorator(@NotNull JFrame frame, @NotNull Disposable parentDisposable) { super(frame); - if (leaveFullScreenMethod != null || requestToggleFullScreenMethod != null) { + if (leaveFullScreenMethod != null || toggleFullScreenMethod != null) { FullScreenUtilities.setWindowCanFullScreen(frame, true); // Native full screen listener can be set only once @@ -173,9 +174,8 @@ public final class MacMainFrameDecorator extends IdeFrameDecorator { return myInFullScreen; } - @NotNull @Override - public Promise toggleFullScreen(boolean state) { + public @NotNull Promise toggleFullScreen(boolean state) { if (myInFullScreen == state) { return Promises.resolvedPromise(state); } @@ -196,8 +196,8 @@ public final class MacMainFrameDecorator extends IdeFrameDecorator { }); // temporary solution for the old runtime - if (requestToggleFullScreenMethod != null) { - myFullScreenQueue.runOrEnqueue(() -> invokeAppMethod(requestToggleFullScreenMethod)); + if (toggleFullScreenMethod != null) { + myFullScreenQueue.runOrEnqueue(() -> invokeAppMethod(toggleFullScreenMethod)); } else if (state) { myFullScreenQueue.runOrEnqueue(() -> invokeAppMethod(enterFullScreenMethod)); @@ -217,4 +217,4 @@ public final class MacMainFrameDecorator extends IdeFrameDecorator { Logger.getInstance(MacMainFrameDecorator.class).warn(e); } } -} \ No newline at end of file +} diff --git a/platform/platform-impl/src/com/intellij/ui/mac/MacOSApplicationProvider.java b/platform/platform-impl/src/com/intellij/ui/mac/MacOSApplicationProvider.java index fae9a93da912..8cce2184ade2 100644 --- a/platform/platform-impl/src/com/intellij/ui/mac/MacOSApplicationProvider.java +++ b/platform/platform-impl/src/com/intellij/ui/mac/MacOSApplicationProvider.java @@ -119,7 +119,6 @@ public final class MacOSApplicationProvider { Callback impl = new Callback() { @SuppressWarnings("unused") public void callback(ID self, String selector) { - //noinspection SSBasedInspection SwingUtilities.invokeLater(() -> { ActionManager actionManager = ActionManager.getInstance(); MouseEvent mouseEvent = new MouseEvent(JOptionPane.getRootFrame(), MouseEvent.MOUSE_CLICKED, System.currentTimeMillis(), 0, 0, 0, 1, false); @@ -188,7 +187,7 @@ public final class MacOSApplicationProvider { ID urlTypes = Foundation.invoke(mainBundle, "objectForInfoDictionaryKey:", Foundation.nsString("CFBundleURLTypes")); if (urlTypes.equals(ID.NIL)) { BuildNumber build = ApplicationInfoImpl.getShadowInstance().getBuild(); - if (!(build == null || build.isSnapshot())) { + if (!build.isSnapshot()) { LOG.warn("No URL bundle (CFBundleURLTypes) is defined in the main bundle.\n" + "To be able to open external links, specify protocols in the app layout section of the build file.\n" + "Example: args.urlSchemes = [\"your-protocol\"] will handle following links: your-protocol://open?file=file&line=line"); @@ -230,4 +229,4 @@ public final class MacOSApplicationProvider { }); } } -} \ No newline at end of file +}