decouple IdeFrameImpl and JFrame (part 4): restore compatibility

GitOrigin-RevId: 2a469e5c5cece993414072afae4125c34f16f08d
This commit is contained in:
Vladimir Krivosheev
2019-09-03 18:33:10 +00:00
committed by intellij-monorepo-bot
parent 965ea8dd35
commit caedc28962
17 changed files with 198 additions and 74 deletions
@@ -32,7 +32,7 @@ import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vfs.VfsUtilCore;
import com.intellij.openapi.wm.*;
import com.intellij.openapi.wm.ex.IdeFrameEx;
import com.intellij.openapi.wm.impl.ProjectFrameHelper;
import com.intellij.openapi.wm.impl.IdeFrameImpl;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
@@ -165,7 +165,7 @@ public class NewProjectUtil {
if (lastFocusedFrame instanceof IdeFrameEx) {
boolean fullScreen = ((IdeFrameEx)lastFocusedFrame).isInFullScreen();
if (fullScreen) {
newProject.putUserData(ProjectFrameHelper.SHOULD_OPEN_IN_FULL_SCREEN, Boolean.TRUE);
newProject.putUserData(IdeFrameImpl.SHOULD_OPEN_IN_FULL_SCREEN, Boolean.TRUE);
}
}
}
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// 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.
package com.intellij.execution.actions;
import com.intellij.icons.AllIcons;
@@ -29,7 +15,6 @@ import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.ui.popup.ListItemDescriptorAdapter;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.wm.IdeFrame;
import com.intellij.openapi.wm.WindowManager;
import com.intellij.openapi.wm.ex.StatusBarEx;
import com.intellij.openapi.wm.ex.WindowManagerEx;
import com.intellij.ui.components.JBList;
@@ -111,7 +96,7 @@ public class StopBackgroundProcessesAction extends DumbAwareAction implements An
@NotNull
private static List<Pair<TaskInfo, ProgressIndicator>> getCancellableProcesses(@Nullable Project project) {
IdeFrame frame = ((WindowManagerEx)WindowManager.getInstance()).findFrameFor(project);
IdeFrame frame = WindowManagerEx.getInstanceEx().findFrameFor(project);
StatusBarEx statusBar = frame == null ? null : (StatusBarEx)frame.getStatusBar();
if (statusBar == null) return Collections.emptyList();
@@ -1,4 +1,4 @@
// Copyright 2000-2018 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-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.
package com.intellij.openapi.wm;
import com.intellij.openapi.actionSystem.DataKey;
@@ -13,6 +13,7 @@ import java.io.File;
public interface IdeFrame {
DataKey<IdeFrame> KEY = DataKey.create("IdeFrame");
@Nullable
StatusBar getStatusBar();
Rectangle suggestChildFrameBounds();
@@ -70,11 +70,10 @@ public abstract class WindowManager {
return null;
}
/**
* @return Frame, could be {@code null} in test environment.
*/
@Nullable
public abstract JFrame getFrame(@Nullable Project project);
@Nullable
public abstract IdeFrame getIdeFrame(@Nullable Project project);
/**
@@ -115,8 +115,10 @@ class AnalysisRunnable(val hprofPath: Path,
private var reportShown = false
override fun actionPerformed(e: AnActionEvent, notification: Notification) {
val parentComponent = WindowManager.getInstance().getFrame(e.project)
if (reportShown) return
val parentComponent = WindowManager.getInstance().getFrame(e.project) ?: return
if (reportShown) {
return
}
reportShown = true
UIUtil.invokeLaterIfNeeded {
@@ -550,7 +550,7 @@ private fun reportPluginError() {
val description = event.description
if (PluginManagerCore.EDIT == description) {
val ideFrame = WindowManagerEx.getInstanceEx().findFrameFor(null)
PluginManagerConfigurableProxy.showPluginConfigurable(ideFrame as JFrame, null)
PluginManagerConfigurableProxy.showPluginConfigurable(ideFrame?.component, null)
return@Notification
}
@@ -388,6 +388,7 @@ public class FrameWrapper implements Disposable, DataProvider {
return getRootPane();
}
@Nullable
@Override
public StatusBar getStatusBar() {
StatusBar ownerBar = myOwner != null ? myOwner.myStatusBar : null;
@@ -422,6 +423,7 @@ public class FrameWrapper implements Disposable, DataProvider {
return myOwner.getNorthExtension(key);
}
@Nullable
@Override
public BalloonLayout getBalloonLayout() {
return null;
@@ -478,6 +480,7 @@ public class FrameWrapper implements Disposable, DataProvider {
return getRootPane();
}
@Nullable
@Override
public StatusBar getStatusBar() {
return null;
@@ -27,6 +27,7 @@ public abstract class WindowManagerEx extends WindowManager {
return (WindowManagerEx)WindowManager.getInstance();
}
@Nullable
@Override
public abstract IdeFrameImpl getFrame(@Nullable Project project);
@@ -57,6 +58,7 @@ public abstract class WindowManagerEx extends WindowManager {
public abstract Window getMostRecentFocusedWindow();
@Nullable
public abstract IdeFrame findFrameFor(@Nullable Project project);
@NotNull
@@ -3,7 +3,13 @@ package com.intellij.openapi.wm.impl;
import com.intellij.diagnostic.LoadingPhase;
import com.intellij.ide.ui.UISettings;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.wm.IdeFrame;
import com.intellij.openapi.wm.IdeRootPaneNorthExtension;
import com.intellij.openapi.wm.StatusBar;
import com.intellij.ui.BalloonLayout;
import com.intellij.util.ui.GraphicsUtil;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.StartupUiUtil;
@@ -14,12 +20,18 @@ import org.jetbrains.annotations.Nullable;
import javax.accessibility.AccessibleContext;
import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.util.Objects;
@ApiStatus.Internal
public final class IdeFrameImpl extends JFrame {
public final class IdeFrameImpl extends JFrame implements IdeFrame {
public static final Key<Boolean> SHOULD_OPEN_IN_FULL_SCREEN = Key.create("should.open.in.full.screen");
static final String NORMAL_STATE_BOUNDS = "normalBounds";
@Nullable
private FrameHelper myFrameHelper;
@Nullable
private FrameDecorator myFrameDecorator;
interface FrameHelper {
@@ -30,6 +42,14 @@ public final class IdeFrameImpl extends JFrame {
void setTitle(String title);
void releaseFrame();
void updateView();
@Nullable
Project getProject();
@NotNull
IdeFrame getHelper();
}
interface FrameDecorator {
@@ -129,7 +149,9 @@ public final class IdeFrameImpl extends JFrame {
}
public void releaseFrame() {
myFrameHelper.releaseFrame();
if (myFrameHelper != null) {
myFrameHelper.releaseFrame();
}
}
protected final class AccessibleIdeFrameImpl extends AccessibleJFrame {
@@ -146,4 +168,67 @@ public final class IdeFrameImpl extends JFrame {
}
return null;
}
/**
* @deprecated Use {@link ProjectFrameHelper#updateView()} instead.
*/
@Deprecated
public void updateView() {
if (myFrameHelper != null) {
myFrameHelper.updateView();
}
}
/**
* @deprecated Use {@link ProjectFrameHelper#updateView()} instead.
*/
@Override
@Deprecated
@ApiStatus.ScheduledForRemoval(inVersion = "2020.1")
public Project getProject() {
return myFrameHelper == null ? null : myFrameHelper.getProject();
}
// deprecated stuff - as IdeFrame must be implemented (a lot of instanceof checks for JFrame)
@Nullable
@Override
public StatusBar getStatusBar() {
return myFrameHelper == null ? null : myFrameHelper.getHelper().getStatusBar();
}
@Override
public Rectangle suggestChildFrameBounds() {
return Objects.requireNonNull(myFrameHelper).getHelper().suggestChildFrameBounds();
}
@Override
public void setFrameTitle(String title) {
if (myFrameHelper != null) {
myFrameHelper.getHelper().setFrameTitle(title);
}
}
@Override
public void setFileTitle(String fileTitle, File ioFile) {
if (myFrameHelper != null) {
myFrameHelper.getHelper().setFileTitle(fileTitle, ioFile);
}
}
@Override
public IdeRootPaneNorthExtension getNorthExtension(String key) {
return myFrameHelper == null ? null : myFrameHelper.getHelper().getNorthExtension(key);
}
@Override
public JComponent getComponent() {
return getRootPane();
}
@Nullable
@Override
public BalloonLayout getBalloonLayout() {
return myFrameHelper == null ? null : myFrameHelper.getHelper().getBalloonLayout();
}
}
@@ -19,7 +19,6 @@ import com.intellij.openapi.project.DumbAwareRunnable;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.startup.StartupManager;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.Key;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.registry.Registry;
import com.intellij.openapi.util.text.StringUtil;
@@ -62,8 +61,6 @@ import java.util.Set;
public final class ProjectFrameHelper implements IdeFrameEx, AccessibleContextAccessor, DataProvider {
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.wm.impl.IdeFrameImpl");
public static final Key<Boolean> SHOULD_OPEN_IN_FULL_SCREEN = Key.create("should.open.in.full.screen");
private static boolean ourUpdatingTitle;
private String myTitle;
@@ -145,6 +142,23 @@ public final class ProjectFrameHelper implements IdeFrameEx, AccessibleContextAc
ProjectFrameHelper.this.dispose();
}
@Override
public void updateView() {
ProjectFrameHelper.this.updateView();
}
@Nullable
@Override
public Project getProject() {
return myProject;
}
@NotNull
@Override
public IdeFrame getHelper() {
return ProjectFrameHelper.this;
}
@Override
public void setTitle(String title) {
if (ourUpdatingTitle) {
@@ -286,6 +300,7 @@ public final class ProjectFrameHelper implements IdeFrameEx, AccessibleContextAc
});
}
@Nullable
@Override
public IdeStatusBarImpl getStatusBar() {
return myRootPane == null ? null : myRootPane.getStatusBar();
@@ -453,7 +468,7 @@ public final class ProjectFrameHelper implements IdeFrameEx, AccessibleContextAc
addWidget(statusBar, new ColumnSelectionModePanel(project), StatusBar.Anchors.after(encodingPanel.ID()));
addWidget(statusBar, new ToggleReadOnlyAttributePanel(), StatusBar.Anchors.after(StatusBar.StandardWidgets.COLUMN_SELECTION_MODE_PANEL));
for (StatusBarWidgetProvider widgetProvider: StatusBarWidgetProvider.EP_NAME.getExtensions()) {
for (StatusBarWidgetProvider widgetProvider: StatusBarWidgetProvider.EP_NAME.getExtensionList()) {
StatusBarWidget widget = widgetProvider.getWidget(project);
if (widget == null) {
continue;
@@ -542,6 +557,7 @@ public final class ProjectFrameHelper implements IdeFrameEx, AccessibleContextAc
return b;
}
@Nullable
@Override
public final BalloonLayout getBalloonLayout() {
return myBalloonLayout;
@@ -83,6 +83,7 @@ public final class TestWindowManager extends WindowManagerEx {
return null;
}
@Nullable
@Override
public final IdeFrameImpl getFrame(final Project project) {
return null;
@@ -389,13 +389,12 @@ public final class WindowManagerImpl extends WindowManagerEx implements Persiste
}
assert false : "Cannot find status bar for " + c;
return null;
}
@Override
public IdeFrame findFrameFor(@Nullable final Project project) {
IdeFrame frame = null;
public IdeFrame findFrameFor(@Nullable Project project) {
IdeFrame frame;
if (project != null) {
frame = project.isDefault() ? WelcomeFrame.getInstance() : getFrameHelper(project);
if (frame == null) {
@@ -403,69 +402,80 @@ public final class WindowManagerImpl extends WindowManagerEx implements Persiste
}
}
else {
Container eachParent = getMostRecentFocusedWindow();
while(eachParent != null) {
if (eachParent instanceof IdeFrame) {
frame = (IdeFrame)eachParent;
break;
}
eachParent = eachParent.getParent();
}
frame = ProjectFrameHelper.getFrameHelper(getMostRecentFocusedWindow());
if (frame == null) {
frame = tryToFindTheOnlyFrame();
}
}
return frame;
}
@Nullable
private static IdeFrame tryToFindTheOnlyFrame() {
IdeFrame candidate = null;
final Frame[] all = Frame.getFrames();
for (Frame each : all) {
if (each instanceof IdeFrame) {
IdeFrameImpl candidate = null;
for (Frame each : Frame.getFrames()) {
if (each instanceof IdeFrameImpl) {
if (candidate == null) {
candidate = (IdeFrame)each;
} else {
candidate = (IdeFrameImpl)each;
}
else {
candidate = null;
break;
}
}
}
return candidate;
return candidate == null ? null : ((IdeRootPane)candidate.getRootPane()).getFrameHelper();
}
@Override
public final IdeFrameImpl getFrame(@Nullable Project project) {
// no assert! otherwise WindowWatcher.suggestParentWindow fails for default project
//LOG.assertTrue(myProject2Frame.containsKey(project));
return getFrameHelper(project).getFrame();
ProjectFrameHelper helper = getFrameHelper(project);
return helper == null ? null : helper.getFrame();
}
@Nullable
public ProjectFrameHelper getFrameHelper(@Nullable Project project) {
return myProjectToFrame.get(project);
}
@Override
public IdeFrame getIdeFrame(@Nullable final Project project) {
@Nullable
public IdeFrame getIdeFrame(@Nullable Project project) {
if (project != null) {
return getFrameHelper(project);
}
final Window window = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
final Component parent = UIUtil.findUltimateParent(window);
if (parent instanceof IdeFrame) return (IdeFrame)parent;
final Frame[] frames = Frame.getFrames();
for (Frame each : frames) {
if (each instanceof IdeFrame) {
return (IdeFrame)each;
Window window = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
IdeFrame result = getIdeFrame(UIUtil.findUltimateParent(window));
if (result != null) {
return result;
}
for (Frame each : Frame.getFrames()) {
result = getIdeFrame(each);
if (result != null) {
return result;
}
}
return null;
}
@Nullable
private static IdeFrame getIdeFrame(@NotNull Component component) {
if (component instanceof IdeFrameImpl) {
return ((IdeRootPane)((IdeFrameImpl)component).getContentPane()).getFrameHelper();
}
else if (component instanceof IdeFrame) {
return (IdeFrame)component;
}
else {
return null;
}
}
@Nullable
@ApiStatus.Internal
public ProjectFrameHelper getAndRemoveRootFrame() {
@@ -553,7 +563,7 @@ public final class WindowManagerImpl extends WindowManagerEx implements Persiste
frame.getFrame().setVisible(true);
if (FrameInfoHelper.isFullScreenSupportedInCurrentOs() &&
((frameInfo != null && frameInfo.getFullScreen()) || ProjectFrameHelper.SHOULD_OPEN_IN_FULL_SCREEN.get(project) == Boolean.TRUE)) {
((frameInfo != null && frameInfo.getFullScreen()) || IdeFrameImpl.SHOULD_OPEN_IN_FULL_SCREEN.get(project) == Boolean.TRUE)) {
frame.toggleFullScreen(true);
}
}
@@ -8,6 +8,7 @@ import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.wm.FocusWatcher;
import com.intellij.openapi.wm.IdeFrame;
import com.intellij.openapi.wm.ex.WindowManagerEx;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.NonNls;
@@ -218,7 +219,21 @@ public final class WindowWatcher implements PropertyChangeListener{
synchronized (myLock) {
Window window = getFocusedWindowForProject(project);
if (window == null) {
return project == null ? null : (Window)windowManager.findFrameFor(project);
if (project == null) {
return null;
}
else {
IdeFrame frame = windowManager.findFrameFor(project);
if (frame == null) {
return null;
}
else if (frame instanceof Window) {
return (Window)frame;
}
else {
return ((ProjectFrameHelper)frame).getFrame();
}
}
}
LOG.assertTrue(window.isDisplayable());
@@ -183,6 +183,7 @@ public class FlatWelcomeFrame extends JFrame implements IdeFrame, Disposable, Ac
DimensionService.getInstance().setLocation(WelcomeFrame.DIMENSION_KEY, middle, null);
}
@Nullable
@Override
public StatusBar getStatusBar() {
return null;
@@ -852,6 +853,7 @@ public class FlatWelcomeFrame extends JFrame implements IdeFrame, Disposable, Ac
return arrow;
}
@Nullable
@Override
public BalloonLayout getBalloonLayout() {
return myBalloonLayout;
@@ -200,12 +200,14 @@ public final class WelcomeFrame extends JFrame implements IdeFrame, AccessibleCo
}, ModalityState.NON_MODAL);
}
@Nullable
@Override
public StatusBar getStatusBar() {
Container pane = getContentPane();
return pane instanceof JComponent ? UIUtil.findComponentOfType((JComponent)pane, IdeStatusBarImpl.class) : null;
}
@Nullable
@Override
public BalloonLayout getBalloonLayout() {
return myBalloonLayout;
@@ -127,4 +127,5 @@ com.jetbrains.edu 2.7-2019.2-2140
"Classic Icon" 1.3 1.2 1.1 1.0
com.intellij.flex.uiDesigner 183.3795.13
"Node.js Remote Interpreter" 192.6262.9
project_manager 1.0
project_manager 1.0
com.mabdurrahman.intellij.customtitle 0.0.3 0.0.2 0.0.1
@@ -1,4 +1,4 @@
// Copyright 2000-2018 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-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.
package org.jetbrains.idea.svn.auth
import com.intellij.concurrency.JobScheduler
@@ -109,15 +109,15 @@ class SvnAuthenticationNotifier(private val myVcs: SvnVcs) : GenericNotifierImpl
}
private fun showAlreadyChecking() {
val frameFor = WindowManagerEx.getInstanceEx().findFrameFor(myProject)
if (frameFor != null) {
val component = frameFor.component
val point = component.mousePosition ?: Point((component.width * 0.7).toInt(), 0)
val frameFor = WindowManagerEx.getInstanceEx().findFrameFor(myProject) ?: return
val component = frameFor.component
val point = component.mousePosition ?: Point((component.width * 0.7).toInt(), 0)
SwingUtilities.convertPointToScreen(point, component)
JBPopupFactory.getInstance().createHtmlTextBalloonBuilder("Already checking...", MessageType.WARNING, null).createBalloon().show(
RelativePoint(point), Balloon.Position.below)
}
SwingUtilities.convertPointToScreen(point, component)
JBPopupFactory.getInstance()
.createHtmlTextBalloonBuilder("Already checking...", MessageType.WARNING, null)
.createBalloon()
.show(RelativePoint(point), Balloon.Position.below)
}
private fun onStateChangedToSuccess(obj: AuthenticationRequest) {
@@ -233,7 +233,7 @@ class SvnAuthenticationNotifier(private val myVcs: SvnVcs) : GenericNotifierImpl
CommonProxy.getInstance().select(URI(url.toString()))
}
catch (e: URISyntaxException) {
LOG.info("wrong URL: " + url.toString())
LOG.info("wrong URL: $url")
return false
}