TabbedContent: unused/inconsistent/wrong API removed

This commit is contained in:
Anton Makeev
2016-12-05 14:57:12 +01:00
parent df6fc23a4f
commit cbddf1eb94
5 changed files with 13 additions and 118 deletions
@@ -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<Pair<String, JComponent>> getTabs();
String getTitlePrefix();
@@ -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 {
@@ -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<JBPopup> myPopupReference = null;
private Reference<JBPopup> 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<String> names = new ArrayList<>();
ArrayList<String> names = new ArrayList<String>();
for (Pair<String, JComponent> 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<JBPopup>(popup);
popup.showUnderneathOf(this);
}
private void setIconInPopupLabel(JLabel label, String tabName) {
Icon baseIcon = getBaseIcon();
boolean hasIconsInTabs = baseIcon != null;
for (Pair<String, JComponent> 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<String, JComponent> 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<String, JComponent> 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();
@@ -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<Pair<String, JComponent>> myTabs = new ArrayList<>();
private final List<Pair<String, JComponent>> myTabs = new ArrayList<Pair<String, JComponent>>();
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<String, JComponent> toRemove = null;
for (Pair<String, JComponent> 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<String, JComponent> 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<Pair<String, JComponent>> copy = new ArrayList<>(myTabs);
List<Pair<String, JComponent>> copy = new ArrayList<Pair<String, JComponent>>(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);
}
@@ -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));
}
}