mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
simplify uiParents/uiTraverser
This commit is contained in:
@@ -27,7 +27,6 @@ import com.intellij.openapi.options.ConfigurationException;
|
||||
import com.intellij.openapi.options.SearchableConfigurable;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.ComboBox;
|
||||
import com.intellij.openapi.util.Condition;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.VirtualFileFilter;
|
||||
import com.intellij.ui.ColoredTableCellRenderer;
|
||||
@@ -44,8 +43,10 @@ import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ComponentAdapter;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
@@ -235,12 +236,7 @@ public abstract class LanguagePerFileConfigurable<T> implements SearchableConfig
|
||||
if (editCellAt(getSelectedRow(), 1)) {
|
||||
TableCellEditor editor = getCellEditor(editingRow, editingColumn);
|
||||
Component component = ((DefaultCellEditor)editor).getComponent();
|
||||
JButton button = (JButton)UIUtil.uiTraverser().withRoot(component).bfsTraversal().filter(new Condition<Component>() {
|
||||
@Override
|
||||
public boolean value(Component component) {
|
||||
return component instanceof JButton;
|
||||
}
|
||||
}).first();
|
||||
JButton button = UIUtil.uiTraverser(component).bfsTraversal().filter(JButton.class).first();
|
||||
if (button != null) {
|
||||
button.doClick();
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public abstract class ComboBoxAction extends AnAction implements CustomComponent
|
||||
JRootPane rootPane = UIUtil.getParentOfType(JRootPane.class, contextComponent);
|
||||
if (rootPane != null) {
|
||||
button = (ComboBoxButton)
|
||||
UIUtil.uiTraverser().withRoot(rootPane).bfsTraversal().filter(new Condition<Component>() {
|
||||
UIUtil.uiTraverser(rootPane).bfsTraversal().filter(new Condition<Component>() {
|
||||
@Override
|
||||
public boolean value(Component component) {
|
||||
return component instanceof ComboBoxButton && ((ComboBoxButton)component).getMyAction() == ComboBoxAction.this;
|
||||
|
||||
@@ -107,7 +107,7 @@ public class ToggleToolbarAction extends ToggleAction implements DumbAware {
|
||||
|
||||
@NotNull
|
||||
private static Iterable<ActionToolbar> iterateToolbars(JComponent root) {
|
||||
return UIUtil.uiTraverser().withRoot(root).preOrderDfsTraversal().filter(ActionToolbar.class);
|
||||
return UIUtil.uiTraverser(root).preOrderDfsTraversal().filter(ActionToolbar.class);
|
||||
}
|
||||
|
||||
private static class OptionsGroup extends ActionGroup implements DumbAware {
|
||||
|
||||
@@ -126,7 +126,7 @@ public class PluginManagerConfigurable extends BaseConfigurable implements Searc
|
||||
myPluginManagerMain.ignoreChanges();
|
||||
if (prev) return;
|
||||
|
||||
Disposable d = UIUtil.getParents(myPluginManagerMain.getMainPanel()).filter(Disposable.class).first();
|
||||
Disposable d = UIUtil.uiParents(myPluginManagerMain.getMainPanel(), false).filter(Disposable.class).first();
|
||||
if (d == null) return;
|
||||
Disposer.register(d, new Disposable() {
|
||||
@Override
|
||||
|
||||
+1
-1
@@ -117,7 +117,7 @@ public abstract class ToolbarUpdater implements Activatable {
|
||||
protected abstract void updateActionsImpl(boolean transparentOnly, boolean forced);
|
||||
|
||||
protected void updateActionTooltips() {
|
||||
for (ActionButton actionButton : UIUtil.uiTraverser().withRoot(myComponent).preOrderDfsTraversal().filter(ActionButton.class)) {
|
||||
for (ActionButton actionButton : UIUtil.uiTraverser(myComponent).preOrderDfsTraversal().filter(ActionButton.class)) {
|
||||
actionButton.updateToolTipText();
|
||||
}
|
||||
}
|
||||
|
||||
+1
-2
@@ -54,7 +54,6 @@ import com.intellij.openapi.wm.ex.ToolWindowManagerEx;
|
||||
import com.intellij.ui.*;
|
||||
import com.intellij.ui.awt.RelativePoint;
|
||||
import com.intellij.util.Alarm;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.ui.ButtonlessScrollBarUI;
|
||||
import com.intellij.util.ui.GraphicsUtil;
|
||||
@@ -195,7 +194,7 @@ public class EditorMarkupModelImpl extends MarkupModelImpl implements EditorMark
|
||||
boolean isVisible = area.contains(area.x, visualY) && myWheelAccumulator == 0;
|
||||
|
||||
TooltipRenderer bigRenderer;
|
||||
if (UIUtil.getParents(myEditor.getComponent()).filter(EditorWindowHolder.class).isEmpty() || isVisible || !UISettings.getInstance().SHOW_EDITOR_TOOLTIP) {
|
||||
if (UIUtil.uiParents(myEditor.getComponent(), false).filter(EditorWindowHolder.class).isEmpty() || isVisible || !UISettings.getInstance().SHOW_EDITOR_TOOLTIP) {
|
||||
final Set<RangeHighlighter> highlighters = new THashSet<RangeHighlighter>();
|
||||
getNearestHighlighters(this, me.getY(), highlighters);
|
||||
getNearestHighlighters(((EditorEx)getEditor()).getFilteredDocumentMarkupModel(), me.getY(), highlighters);
|
||||
|
||||
@@ -211,7 +211,7 @@ public abstract class ToolWindowHeader extends JPanel implements Disposable, UIS
|
||||
|
||||
@Override
|
||||
protected void updateActionTooltips() {
|
||||
for (ActionButton actionButton : UIUtil.uiTraverser().withRoot(myButtonPanel).preOrderDfsTraversal().filter(ActionButton.class)) {
|
||||
for (ActionButton actionButton : UIUtil.uiTraverser(myButtonPanel).preOrderDfsTraversal().filter(ActionButton.class)) {
|
||||
actionButton.updateTooltip();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -148,7 +148,7 @@ public class IJSwingUtilities extends JBSwingUtilities {
|
||||
*/
|
||||
public static void updateComponentTreeUI(@Nullable Component c) {
|
||||
if (c == null) return;
|
||||
for (Component component : UIUtil.uiTraverser().withRoot(c).postOrderDfsTraversal()) {
|
||||
for (Component component : UIUtil.uiTraverser(c).postOrderDfsTraversal()) {
|
||||
if (component instanceof JComponent) ((JComponent)component).updateUI();
|
||||
}
|
||||
c.invalidate();
|
||||
|
||||
@@ -2309,7 +2309,7 @@ public class UIUtil {
|
||||
|
||||
public static void removeScrollBorder(final Component c) {
|
||||
for (JScrollPane scrollPane : uiTraverser(c).filter(JScrollPane.class)) {
|
||||
if (!getParents(scrollPane)
|
||||
if (!uiParents(scrollPane, true)
|
||||
.takeWhile(Conditions.notEqualTo(c))
|
||||
.filter(Conditions.not(Conditions.instanceOf(JPanel.class, JLayeredPane.class)))
|
||||
.isEmpty()) continue;
|
||||
@@ -2774,24 +2774,14 @@ public class UIUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JBIterable<Component> getParents(@Nullable Component c) {
|
||||
return uiParents(c, true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JBIterable<Component> uiParents(@Nullable Component c, boolean strict) {
|
||||
return strict ? JBIterable.generate(c, COMPONENT_PARENT).skip(1) : JBIterable.generate(c, COMPONENT_PARENT);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JBTreeTraverser<Component> uiTraverser() {
|
||||
return new JBTreeTraverser<Component>(COMPONENT_CHILDREN);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JBTreeTraverser<Component> uiTraverser(@Nullable Component component) {
|
||||
return uiTraverser().withRoot(component);
|
||||
return new JBTreeTraverser<Component>(COMPONENT_CHILDREN).withRoot(component);
|
||||
}
|
||||
|
||||
public static final Key<Iterable<? extends Component>> NOT_IN_HIERARCHY_COMPONENTS = Key.create("NOT_IN_HIERARCHY_COMPONENTS");
|
||||
|
||||
Reference in New Issue
Block a user