From cbddf1eb944f7229e7854c8ae82b9ba31cdcfed7 Mon Sep 17 00:00:00 2001 From: Anton Makeev Date: Mon, 5 Dec 2016 14:51:31 +0100 Subject: [PATCH] TabbedContent: unused/inconsistent/wrong API removed --- .../intellij/ui/content/TabbedContent.java | 3 +- .../openapi/wm/impl/content/BaseLabel.java | 14 ++-- .../impl/content/TabbedContentTabLabel.java | 65 ++----------------- .../ui/content/impl/TabbedContentImpl.java | 40 +----------- .../src/com/intellij/util/ContentUtilEx.java | 9 +-- 5 files changed, 13 insertions(+), 118 deletions(-) diff --git a/platform/platform-api/src/com/intellij/ui/content/TabbedContent.java b/platform/platform-api/src/com/intellij/ui/content/TabbedContent.java index f473229b6c46..f3606dac8238 100644 --- a/platform/platform-api/src/com/intellij/ui/content/TabbedContent.java +++ b/platform/platform-api/src/com/intellij/ui/content/TabbedContent.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -30,7 +30,6 @@ public interface TabbedContent extends Content { void addContent(@NotNull JComponent content, @NotNull String name, boolean selectTab); void removeContent(@NotNull JComponent content); - void renameContent(@NotNull JComponent tab, @NotNull String newTabName); void selectContent(int index); List> getTabs(); String getTitlePrefix(); diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/content/BaseLabel.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/content/BaseLabel.java index 001c425d5416..d5e16d371260 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/content/BaseLabel.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/content/BaseLabel.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2013 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -16,7 +16,6 @@ package com.intellij.openapi.wm.impl.content; import com.intellij.ide.ui.AntialiasingType; -import com.intellij.openapi.util.Iconable; import com.intellij.openapi.wm.ToolWindow; import com.intellij.ui.EngravedTextGraphics; import com.intellij.ui.Gray; @@ -114,18 +113,13 @@ public class BaseLabel extends JLabel { setToolTipText(content.getDescription()); - final boolean show = Boolean.TRUE.equals(content.getUserData(ToolWindow.SHOW_CONTENT_ICON)) - || content.getComponent() instanceof Iconable; - Icon icon = content.getIcon(); - if (content.getComponent() instanceof Iconable) { // handling tabbed content after 'split group' action - icon = ((Iconable)content.getComponent()).getIcon(Iconable.ICON_FLAG_VISIBILITY); - } + final boolean show = Boolean.TRUE.equals(content.getUserData(ToolWindow.SHOW_CONTENT_ICON)); if (show) { if (isSelected) { - setIcon(icon); + setIcon(content.getIcon()); } else { - setIcon(icon != null ? new WatermarkIcon(icon, .5f) : null); + setIcon(content.getIcon() != null ? new WatermarkIcon(content.getIcon(), .5f) : null); } } else { diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/content/TabbedContentTabLabel.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/content/TabbedContentTabLabel.java index 3b03307e5637..7537e337e5ba 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/content/TabbedContentTabLabel.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/content/TabbedContentTabLabel.java @@ -19,19 +19,14 @@ import com.intellij.ide.IdeEventQueue; import com.intellij.openapi.ui.popup.JBPopup; import com.intellij.openapi.ui.popup.JBPopupFactory; import com.intellij.openapi.util.Disposer; -import com.intellij.openapi.util.Iconable; import com.intellij.openapi.util.Pair; import com.intellij.reference.SoftReference; import com.intellij.ui.ClickListener; import com.intellij.ui.components.JBList; import com.intellij.ui.content.TabbedContent; -import com.intellij.util.ContentUtilEx; import com.intellij.util.NotNullFunction; -import com.intellij.util.ui.EmptyIcon; import com.intellij.util.ui.UIUtil; -import com.intellij.util.ui.WatermarkIcon; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.border.EmptyBorder; @@ -57,7 +52,7 @@ public class TabbedContentTabLabel extends ContentTabLabel { } }; private final TabbedContent myContent; - @Nullable private Reference myPopupReference = null; + private Reference myPopupReference = null; public TabbedContentTabLabel(TabbedContent content, TabContentLayout layout) { super(content, layout); @@ -73,7 +68,7 @@ public class TabbedContentTabLabel extends ContentTabLabel { private void showPopup() { IdeEventQueue.getInstance().getPopupManager().closeAllPopups(); - ArrayList names = new ArrayList<>(); + ArrayList names = new ArrayList(); for (Pair tab : myContent.getTabs()) { names.add(tab.first); } @@ -86,9 +81,7 @@ public class TabbedContentTabLabel extends ContentTabLabel { @NotNull @Override public JComponent fun(Object dom) { - String tabName = dom.toString(); - label.setText(tabName); - setIconInPopupLabel(label, tabName); + label.setText(dom.toString()); return label; } }); @@ -99,67 +92,19 @@ public class TabbedContentTabLabel extends ContentTabLabel { myContent.selectContent(index); } }).createPopup(); - myPopupReference = new WeakReference<>(popup); + myPopupReference = new WeakReference(popup); popup.showUnderneathOf(this); } - private void setIconInPopupLabel(JLabel label, String tabName) { - Icon baseIcon = getBaseIcon(); - boolean hasIconsInTabs = baseIcon != null; - for (Pair nextTabWithName : myContent.getTabs()) { - if (nextTabWithName.getFirst().equals(tabName)) { - JComponent tab = nextTabWithName.getSecond(); - Icon tabIcon = null; - if (tab instanceof Iconable) { - tabIcon = ((Iconable)tab).getIcon(Iconable.ICON_FLAG_VISIBILITY); - if (hasIconsInTabs && tabIcon == null) { - tabIcon = EmptyIcon.create(baseIcon); - } - } - label.setIcon(tabIcon); - } - } - } - - @Nullable - private Icon getBaseIcon() { - Icon baseIcon = null; - for (Pair nextTabWithName : myContent.getTabs()) { - JComponent tabComponent = nextTabWithName.getSecond(); - if (tabComponent instanceof Iconable) { - Icon tabIcon = ((Iconable)tabComponent).getIcon(Iconable.ICON_FLAG_VISIBILITY); - if (tabIcon != null) { - baseIcon = tabIcon; - break; - } - } - } - return baseIcon; - } - @Override public void update() { super.update(); if (myContent != null) { - String tabName = myContent.getTabName(); - setText(tabName); - setTabIcon(tabName, this); + setText(myContent.getTabName()); } setHorizontalAlignment(LEFT); } - private void setTabIcon(String tabName, JLabel jLabel) { - for (Pair nextTabWithName : myContent.getTabs()) { - if (tabName != null && nextTabWithName.getFirst().equals(ContentUtilEx.getTabNameWithoutPrefix(myContent, tabName))) { - JComponent tab = nextTabWithName.getSecond(); - if (tab instanceof Iconable) { - Icon baseIcon = ((Iconable)tab).getIcon(Iconable.ICON_FLAG_VISIBILITY); - jLabel.setIcon(isSelected() || baseIcon == null ? baseIcon : new WatermarkIcon(baseIcon, .5f)); - } - } - } - } - @Override public Dimension getPreferredSize() { final Dimension size = super.getPreferredSize(); diff --git a/platform/platform-impl/src/com/intellij/ui/content/impl/TabbedContentImpl.java b/platform/platform-impl/src/com/intellij/ui/content/impl/TabbedContentImpl.java index a9e3af62790d..cd52c0383806 100644 --- a/platform/platform-impl/src/com/intellij/ui/content/impl/TabbedContentImpl.java +++ b/platform/platform-impl/src/com/intellij/ui/content/impl/TabbedContentImpl.java @@ -17,12 +17,10 @@ package com.intellij.ui.content.impl; import com.intellij.ide.util.PropertiesComponent; import com.intellij.openapi.util.Disposer; -import com.intellij.openapi.util.Iconable; import com.intellij.openapi.util.Pair; import com.intellij.ui.content.ContentManager; import com.intellij.ui.content.TabbedContent; import com.intellij.util.ContentUtilEx; -import com.intellij.util.ui.WatermarkIcon; import org.jetbrains.annotations.NotNull; import javax.swing.*; @@ -35,7 +33,7 @@ import java.util.List; * @author Konstantin Bulenkov */ public class TabbedContentImpl extends ContentImpl implements TabbedContent { - private final List> myTabs = new ArrayList<>(); + private final List> myTabs = new ArrayList>(); private String myPrefix; public TabbedContentImpl(JComponent component, String displayName, boolean isPinnable, String titlePrefix) { @@ -86,25 +84,6 @@ public class TabbedContentImpl extends ContentImpl implements TabbedContent { } } - @Override - public void renameContent(@NotNull JComponent tab, @NotNull String newTabName) { - Pair toRemove = null; - for (Pair existingTab : myTabs) { - if (existingTab.second == tab) { - toRemove = existingTab; - break; - } - } - int index = myTabs.indexOf(toRemove); - if (index != -1) { - myTabs.remove(index); - } - myTabs.add(Pair.create(newTabName, tab)); - if (getComponent() == tab) { - super.setDisplayName(newTabName); - } - } - @Override public String getDisplayName() { return getTabName(); @@ -168,23 +147,9 @@ public class TabbedContentImpl extends ContentImpl implements TabbedContent { myPrefix = titlePrefix; } - @Override - public void setIcon(Icon icon) { - for (Pair nextTabWithName : getTabs()) { - if (nextTabWithName.getFirst().equals(ContentUtilEx.getTabNameWithoutPrefix(this, getTabName()))) { - JComponent tab = nextTabWithName.getSecond(); - if (tab instanceof Iconable) { - Icon baseIcon = ((Iconable)tab).getIcon(Iconable.ICON_FLAG_VISIBILITY); - super.setIcon(isSelected() || baseIcon == null ? baseIcon : new WatermarkIcon(baseIcon, .5f)); - break; - } - } - } - } - @Override public void split() { - List> copy = new ArrayList<>(myTabs); + List> copy = new ArrayList>(myTabs); int selectedTab = ContentUtilEx.getSelectedTab(this); ContentManager manager = getManager(); String prefix = getTitlePrefix(); @@ -196,7 +161,6 @@ public class TabbedContentImpl extends ContentImpl implements TabbedContent { final String tabName = copy.get(i).first; ContentUtilEx.addTabbedContent(manager, component, prefix, tabName, select); } - setShouldDisposeContent(false); Disposer.dispose(this); } diff --git a/platform/platform-impl/src/com/intellij/util/ContentUtilEx.java b/platform/platform-impl/src/com/intellij/util/ContentUtilEx.java index 52f6ea2d0e2e..e699fbc8dd81 100644 --- a/platform/platform-impl/src/com/intellij/util/ContentUtilEx.java +++ b/platform/platform-impl/src/com/intellij/util/ContentUtilEx.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2015 JetBrains s.r.o. + * Copyright 2000-2016 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. @@ -21,7 +21,6 @@ import com.intellij.openapi.util.Comparing; import com.intellij.openapi.util.Condition; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.Pair; -import com.intellij.openapi.util.text.StringUtil; import com.intellij.ui.content.Content; import com.intellij.ui.content.ContentFactory; import com.intellij.ui.content.ContentManager; @@ -196,10 +195,4 @@ public class ContentUtilEx extends ContentsUtil { } return -1; } - - @Nullable - public static String getTabNameWithoutPrefix(@NotNull TabbedContent content, @NotNull String fullTabName) { - String prefix = content.getTitlePrefix(); - return prefix == null ? fullTabName : StringUtil.trimStart(fullTabName, getFullPrefix(prefix)); - } }