don't use expensive, unsafe and bloated UIUtil

GitOrigin-RevId: 412a15c002e13773f263c75d25014620534e1771
This commit is contained in:
Vladimir Krivosheev
2022-08-24 20:05:18 +00:00
committed by intellij-monorepo-bot
parent c57882ca1d
commit c0044f5718
11 changed files with 72 additions and 69 deletions
@@ -1,4 +1,4 @@
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.ui.table;
import com.intellij.openapi.application.ApplicationManager;
@@ -64,7 +64,7 @@ public class JBTable extends JTable implements ComponentWithEmptyText, Component
private int myRowHeight = -1;
private boolean myRowHeightIsExplicitlySet;
private boolean myRowHeightIsComputing;
private boolean myUiUpdating = true;
private boolean myUiUpdating;
private Integer myMinRowHeight;
private boolean myStriped;
@@ -830,7 +830,7 @@ public class JBTable extends JTable implements ComponentWithEmptyText, Component
@Override
public void run() {
Component c = focusManager.getFocusOwner();
if (UIUtil.isMeaninglessFocusOwner(c)) {
if (ComponentUtil.isMeaninglessFocusOwner(c)) {
// this allows using popup menus and menu bar without stopping cell editing
return;
}
@@ -884,7 +884,7 @@ public class JBTable extends JTable implements ComponentWithEmptyText, Component
}
}
@SuppressWarnings({"unchecked"})
@SuppressWarnings("unchecked")
protected TableRowSorter<TableModel> createRowSorter(final TableModel model) {
return new DefaultColumnInfoBasedRowSorter(model);
}
@@ -390,10 +390,10 @@ public class JBTabsImpl extends JComponent
gp.addMouseMotionPreprocessor(myTabActionsAutoHideListener, myTabActionsAutoHideListenerDisposable);
myGlassPane = gp;
UIUtil.addAwtListener(__ -> {
if (!JBPopupFactory.getInstance().getChildPopups(JBTabsImpl.this).isEmpty()) return;
processFocusChange();
}, AWTEvent.FOCUS_EVENT_MASK, parentDisposable);
StartupUiUtil.addAwtListener(__ -> {
if (!JBPopupFactory.getInstance().getChildPopups(JBTabsImpl.this).isEmpty()) return;
processFocusChange();
}, AWTEvent.FOCUS_EVENT_MASK, parentDisposable);
myDragHelper = createDragHelper(child, parentDisposable);
myDragHelper.start();
@@ -57,7 +57,7 @@ import com.intellij.util.containers.CollectionFactory;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.containers.MultiMap;
import com.intellij.util.messages.MessageBusConnection;
import com.intellij.util.ui.UIUtil;
import com.intellij.util.ui.StartupUiUtil;
import com.intellij.util.xml.dom.XmlElement;
import it.unimi.dsi.fastutil.objects.Object2IntMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
@@ -1682,15 +1682,15 @@ public class ActionManagerImpl extends ActionManagerEx implements Disposable {
result.setRejected();
return;
}
UIUtil.addAwtListener(event1 -> {
if (event1.getID() == WindowEvent.WINDOW_OPENED || event1.getID() == WindowEvent.WINDOW_ACTIVATED) {
if (!result.isProcessed()) {
final WindowEvent we = (WindowEvent)event1;
IdeFocusManager.findInstanceByComponent(we.getWindow()).doWhenFocusSettlesDown(
result.createSetDoneRunnable(), ModalityState.defaultModalityState());
}
}
}, AWTEvent.WINDOW_EVENT_MASK, result);
StartupUiUtil.addAwtListener(event1 -> {
if (event1.getID() == WindowEvent.WINDOW_OPENED || event1.getID() == WindowEvent.WINDOW_ACTIVATED) {
if (!result.isProcessed()) {
final WindowEvent we = (WindowEvent)event1;
IdeFocusManager.findInstanceByComponent(we.getWindow()).doWhenFocusSettlesDown(
result.createSetDoneRunnable(), ModalityState.defaultModalityState());
}
}
}, AWTEvent.WINDOW_EVENT_MASK, result);
try {
ActionUtil.performActionDumbAwareWithCallbacks(action, event);
}
@@ -23,6 +23,7 @@ import com.intellij.ui.components.JBLayeredPane;
import com.intellij.util.Alarm;
import com.intellij.util.ObjectUtils;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.StartupUiUtil;
import com.intellij.util.ui.UIUtil;
import com.intellij.util.ui.components.BorderLayoutPanel;
import org.jetbrains.annotations.Nls;
@@ -170,7 +171,7 @@ public class TextEditorWithPreview extends UserDataHolderBase implements TextEdi
}
private void registerToolbarListeners(JComponent actualComponent, LayoutActionsFloatingToolbar toolbar) {
UIUtil.addAwtListener(new MyMouseListener(toolbar), AWTEvent.MOUSE_MOTION_EVENT_MASK, toolbar);
StartupUiUtil.addAwtListener(new MyMouseListener(toolbar), AWTEvent.MOUSE_MOTION_EVENT_MASK, toolbar);
final var actualEditor = UIUtil.findComponentOfType(actualComponent, EditorComponentImpl.class);
if (actualEditor != null) {
final var editorKeyListener = new KeyAdapter() {
@@ -50,10 +50,7 @@ import com.intellij.ui.tabs.impl.*;
import com.intellij.util.ObjectUtils;
import com.intellij.util.concurrency.EdtScheduledExecutorService;
import com.intellij.util.concurrency.NonUrgentExecutor;
import com.intellij.util.ui.GraphicsUtil;
import com.intellij.util.ui.JBUI;
import com.intellij.util.ui.TimedDeadzone;
import com.intellij.util.ui.UIUtil;
import com.intellij.util.ui.*;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -682,7 +679,7 @@ public final class EditorTabbedContainer implements CloseAction.CloseTarget {
super(project, parentDisposable);
myWindow = window;
UIUtil.addAwtListener(e -> updateActive(), AWTEvent.FOCUS_EVENT_MASK, parentDisposable);
StartupUiUtil.addAwtListener(e -> updateActive(), AWTEvent.FOCUS_EVENT_MASK, parentDisposable);
setUiDecorator(() -> new UiDecorator.UiDecoration(null, JBUI.CurrentTheme.EditorTabs.tabInsets()));
project.getMessageBus().connect(parentDisposable).subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerListener() {
@@ -262,8 +262,7 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer {
}
@Override
@Nullable
public Container getContentPane() {
public @Nullable Container getContentPane() {
return getRootPane() != null ? myDialog.getContentPane() : null;
}
@@ -366,9 +365,8 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer {
myDialog.setResizable(resizable);
}
@NotNull
@Override
public Point getLocation() {
public @NotNull Point getLocation() {
return myDialog.getLocation();
}
@@ -559,8 +557,7 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer {
setFocusTraversalPolicy(new LayoutFocusTraversalPolicy() {
@Override
public boolean accept(Component aComponent) {
if (UIUtil.isFocusProxy(aComponent)) return false;
return super.accept(aComponent);
return !ComponentUtil.isFocusProxy(aComponent) && super.accept(aComponent);
}
});
@@ -637,9 +634,8 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer {
super.setBounds(r);
}
@NotNull
@Override
protected JRootPane createRootPane() {
protected @NotNull JRootPane createRootPane() {
return new DialogRootPane();
}
@@ -749,14 +745,12 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer {
return size;
}
@Nullable
private Project getProject() {
private @Nullable Project getProject() {
return SoftReference.dereference(myProject);
}
@NotNull
@Override
public IdeFocusManager getFocusManager() {
public @NotNull IdeFocusManager getFocusManager() {
Project project = getProject();
if (project != null && !project.isDisposed()) {
return IdeFocusManager.getInstance(project);
@@ -938,9 +932,8 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer {
setBorder(UIManager.getBorder("Window.border"));
}
@NotNull
@Override
protected JLayeredPane createLayeredPane() {
protected @NotNull JLayeredPane createLayeredPane() {
JLayeredPane p = new JBLayeredPane();
p.setName(this.getName()+".layeredPane");
return p;
@@ -1007,8 +1000,7 @@ public class DialogWrapperPeerImpl extends DialogWrapperPeer {
}
}
@NotNull
private static WindowStateService getWindowStateService(@Nullable Project project) {
private static @NotNull WindowStateService getWindowStateService(@Nullable Project project) {
return project == null ? WindowStateService.getInstance() : WindowStateService.getInstance(project);
}
}
@@ -23,7 +23,7 @@ import com.intellij.ui.DirtyUI;
import com.intellij.ui.popup.AbstractPopup;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.ui.EDT;
import com.intellij.util.ui.UIUtil;
import com.intellij.util.ui.StartupUiUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -57,7 +57,7 @@ public final class FocusManagerImpl extends IdeFocusManager implements Disposabl
ApplicationManager.getApplication().getMessageBus().connect().subscribe(ApplicationActivationListener.TOPIC, new AppListener());
UIUtil.addAwtListener(e -> {
StartupUiUtil.addAwtListener(e -> {
if (e instanceof FocusEvent) {
final FocusEvent fe = (FocusEvent)e;
final Component c = fe.getComponent();
@@ -70,15 +70,15 @@ public final class FocusManagerImpl extends IdeFocusManager implements Disposabl
}
}
else if (e instanceof WindowEvent) {
Window window = ((WindowEvent)e).getWindow();
Window window1 = ((WindowEvent)e).getWindow();
if (e.getID() == WindowEvent.WINDOW_CLOSED) {
if (window instanceof IdeFrame) {
myLastFocused.remove(window);
myLastFocusedAtDeactivation.remove(window);
if (window1 instanceof IdeFrame) {
myLastFocused.remove(window1);
myLastFocusedAtDeactivation.remove(window1);
}
}
}
}, AWTEvent.FOCUS_EVENT_MASK | AWTEvent.WINDOW_EVENT_MASK,this);
}, AWTEvent.FOCUS_EVENT_MASK | AWTEvent.WINDOW_EVENT_MASK, this);
KeyboardFocusManager.getCurrentKeyboardFocusManager().addPropertyChangeListener("focusedWindow", event -> {
Object value = event.getNewValue();
@@ -208,7 +208,7 @@ public final class FocusManagerImpl extends IdeFocusManager implements Disposabl
result = permOwner;
}
if (UIUtil.isMeaninglessFocusOwner(result)) {
if (ComponentUtil.isMeaninglessFocusOwner(result)) {
result = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
}
}
@@ -272,8 +272,7 @@ public final class FocusManagerImpl extends IdeFocusManager implements Disposabl
@Override
public void delayedApplicationDeactivated(@NotNull Window ideFrame) {
Component owner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
Component parent = UIUtil.findUltimateParent(owner);
if (parent == ideFrame) {
if (owner != null && ComponentUtil.findUltimateParent(owner) == ideFrame) {
myLastFocusedAtDeactivation.put(ideFrame, owner);
}
}
@@ -1,7 +1,8 @@
// 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-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.openapi.wm;
import com.intellij.reference.SoftReference;
import com.intellij.ui.ComponentUtil;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -145,7 +146,7 @@ public class FocusWatcher implements ContainerListener, FocusListener {
return;
}
if (UIUtil.isFocusProxy(component)) {
if (ComponentUtil.isFocusProxy(component)) {
_setFocused(getFocusedComponent(), cause);
return;
}
@@ -3,6 +3,7 @@ package com.intellij.ui;
import com.intellij.openapi.util.Key;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -13,13 +14,19 @@ import java.util.List;
import java.util.function.Predicate;
public final class ComponentUtil {
/** @deprecated use {@link ClientProperty#get(Component, Key)} instead */
private static final @NonNls String FOCUS_PROXY_KEY = "isFocusProxy";
/**
* @deprecated use {@link ClientProperty#get(Component, Key)} instead
*/
@Deprecated
public static <T> T getClientProperty(@NotNull JComponent component, @NotNull Key<T> key) {
return ClientProperty.get(component, key);
}
/** @deprecated use {@link JComponent#putClientProperty(Object, Object)} or {@link ClientProperty#put(JComponent, Key, Object)} instead */
/**
* @deprecated use {@link JComponent#putClientProperty(Object, Object)} or {@link ClientProperty#put(JComponent, Key, Object)} instead
*/
@Deprecated
public static <T> void putClientProperty(@NotNull JComponent component, @NotNull Key<T> key, T value) {
component.putClientProperty(key, value);
@@ -154,4 +161,15 @@ public final class ComponentUtil {
}
}
}
public static boolean isFocusProxy(@Nullable Component c) {
return c instanceof JComponent && Boolean.TRUE.equals(((JComponent)c).getClientProperty(FOCUS_PROXY_KEY));
}
public static boolean isMeaninglessFocusOwner(@Nullable Component c) {
if (c == null || !c.isShowing()) {
return true;
}
return c instanceof JFrame || c instanceof JDialog || c instanceof JWindow || c instanceof JRootPane || isFocusProxy(c);
}
}
@@ -1,6 +1,8 @@
// Copyright 2000-2022 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
package com.intellij.util.ui;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.util.Disposer;
import com.intellij.openapi.util.SystemInfoRt;
import com.intellij.ui.JreHiDpiUtil;
import com.intellij.ui.scale.JBUIScale;
@@ -17,6 +19,7 @@ import javax.swing.plaf.FontUIResource;
import javax.swing.text.DefaultEditorKit;
import javax.swing.text.StyleContext;
import java.awt.*;
import java.awt.event.AWTEventListener;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.awt.geom.AffineTransform;
@@ -329,4 +332,9 @@ public final class StartupUiUtil {
Font fontWithFallback = (SystemInfoRt.isMac || GraphicsEnvironment.isHeadless()) ? new Font(familyName, style, (int)size).deriveFont(size) : new StyleContext().getFont(familyName, style, (int)size).deriveFont(size);
return fontWithFallback instanceof FontUIResource ? (FontUIResource)fontWithFallback : new FontUIResource(fontWithFallback);
}
public static void addAwtListener(final @NotNull AWTEventListener listener, long mask, @NotNull Disposable parent) {
Toolkit.getDefaultToolkit().addAWTEventListener(listener, mask);
Disposer.register(parent, () -> Toolkit.getDefaultToolkit().removeAWTEventListener(listener));
}
}
@@ -360,8 +360,6 @@ public final class UIUtil {
private static final Pattern CLOSE_TAG_PATTERN = Pattern.compile("<\\s*([^<>/ ]+)([^<>]*)/\\s*>", Pattern.CASE_INSENSITIVE);
private static final @NonNls String FOCUS_PROXY_KEY = "isFocusProxy";
public static final Key<Integer> KEEP_BORDER_SIDES = Key.create("keepBorderSides");
private static final Key<UndoManager> UNDO_MANAGER = Key.create("undoManager");
/**
@@ -1625,9 +1623,8 @@ public final class UIUtil {
EDT.dispatchAllInvocationEvents();
}
public static void addAwtListener(final @NotNull AWTEventListener listener, long mask, @NotNull Disposable parent) {
Toolkit.getDefaultToolkit().addAWTEventListener(listener, mask);
Disposer.register(parent, () -> Toolkit.getDefaultToolkit().removeAWTEventListener(listener));
public static void addAwtListener(@NotNull AWTEventListener listener, long mask, @NotNull Disposable parent) {
StartupUiUtil.addAwtListener(listener, mask, parent);
}
public static void addParentChangeListener(@NotNull Component component, @NotNull PropertyChangeListener listener) {
@@ -2190,10 +2187,6 @@ public final class UIUtil {
}
}
public static boolean isFocusProxy(@Nullable Component c) {
return c instanceof JComponent && Boolean.TRUE.equals(((JComponent)c).getClientProperty(FOCUS_PROXY_KEY));
}
public static void maybeInstall(@NotNull InputMap map, String action, KeyStroke stroke) {
if (map.get(stroke) == null) {
map.put(stroke, action);
@@ -2513,12 +2506,6 @@ public final class UIUtil {
c.putClientProperty(ROOT_PANE, new WeakReference<>(pane));
}
public static boolean isMeaninglessFocusOwner(@Nullable Component c) {
if (c == null || !c.isShowing()) return true;
return c instanceof JFrame || c instanceof JDialog || c instanceof JWindow || c instanceof JRootPane || isFocusProxy(c);
}
public static boolean isDialogRootPane(JRootPane rootPane) {
if (rootPane != null) {
final Object isDialog = rootPane.getClientProperty("DIALOG_ROOT_PANE");