/*
 * Copyright 2000-2014 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.
 */
package com.intellij.openapi.wm.impl.content;

import com.intellij.ui.content.TabbedContent;

import java.awt.*;

/**
 * @author Konstantin Bulenkov
 */
public class TabbedContentTabLabel extends ContentTabLabel {
  private final ComboIcon myComboIcon = new ComboIcon() {
    @Override
    public Rectangle getIconRec() {
      return new Rectangle(getWidth() - getIconWidth() - 3, 0, getIconWidth(), getHeight());
    }

    @Override
    public boolean isActive() {
      return true;
    }
  };
  private final TabbedContent myContent;

  public TabbedContentTabLabel(TabbedContent content, TabContentLayout layout) {
    super(content, layout);
    myContent = content;
  }

  @Override
  public void update() {
    super.update();
    if (myContent != null) {
      setText(myContent.getTabName());
    }
    setHorizontalAlignment(LEFT);
  }

  @Override
  public Dimension getPreferredSize() {
    final Dimension size = super.getPreferredSize();
    return new Dimension(size.width + 12, size.height);
  }

  @Override
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    myComboIcon.paintIcon(this, g);
  }
}

@@ -665,52 +665,389 @@
 lij.
-ui.content.TabbedContent;%0A%0Aimport java.awt.*
+ide.IdeEventQueue;%0Aimport com.intellij.openapi.ui.popup.JBPopupFactory;%0Aimport com.intellij.openapi.util.Pair;%0Aimport com.intellij.ui.ClickListener;%0Aimport com.intellij.ui.components.JBList;%0Aimport com.intellij.ui.content.TabbedContent;%0Aimport org.jetbrains.annotations.NotNull;%0A%0Aimport javax.swing.*;%0Aimport java.awt.*;%0Aimport java.awt.event.MouseEvent;%0Aimport java.util.ArrayList
 ;%0A%0A/
@@ -1605,16 +1605,823 @@
 ontent;%0A
+    new ClickListener() %7B%0A      @Override%0A      public boolean onClick(@NotNull MouseEvent event, int clickCount) %7B%0A        showPopup();%0A        return true;%0A      %7D%0A    %7D.installOn(this);%0A  %7D%0A%0A  private void showPopup() %7B%0A    IdeEventQueue.getInstance().getPopupManager().closeAllPopups();%0A    ArrayList%3CString%3E names = new ArrayList%3CString%3E();%0A    for (Pair%3CString, JComponent%3E tab : myContent.getTabs()) %7B%0A      names.add(tab.first);%0A    %7D%0A    final JBList list = new JBList(names);%0A    JBPopupFactory.getInstance().createListPopupBuilder(list).setItemChoosenCallback(new Runnable() %7B%0A      @Override%0A      public void run() %7B%0A        int index = list.getSelectedIndex();%0A        if (index != -1) %7B%0A          myContent.selectContent(index);%0A        %7D%0A      %7D%0A    %7D).createPopup().showUnderneathOf(this);%0A
   %7D%0A%0A  @

add ability to switch between content tabs via popup