Java源码示例:com.intellij.ui.tabs.impl.JBTabsImpl

示例1
private void createUIComponents() {
    graphCanvas = new JPanel(new GridLayout(0, 1));
    consoleTabsPane = new JBTabsPaneImpl(null, SwingConstants.TOP, this);
    consoleTabs = (JBTabsImpl) consoleTabsPane.getTabs();

    consoleTabs.addTabMouseListener(new MouseAdapter() {
        @Override
        public void mouseReleased(MouseEvent e) {
            if (UIUtil.isCloseClick(e, MouseEvent.MOUSE_RELEASED)) {
                final TabInfo info = consoleTabs.findInfo(e);
                if (info != null) {
                    String tabTitle = info.getText();
                    if (tabTitle.startsWith(PROFILE_PLAN_TITLE) || tabTitle.startsWith(EXPLAIN_PLAN_TITLE)) {
                        IdeEventQueue.getInstance().blockNextEvents(e);
                        consoleTabs.removeTab(info);
                    }
                }
            }
        }
    });
}
 
示例2
protected void addHeaderSize(JBTabsImpl tabs, Dimension size, final int tabsCount) {
  Dimension header = computeHeaderPreferredSize(tabs, tabsCount);

  final boolean horizontal = tabs.getTabsPosition() == JBTabsPosition.top || tabs.getTabsPosition() == JBTabsPosition.bottom;
  if (horizontal) {
    size.height += header.height;
    size.width = Math.max(size.width, header.width);
  }
  else {
    size.height += Math.max(size.height, header.height);
    size.width += header.width;
  }

  final Insets insets = tabs.getLayoutInsets();
  size.width += insets.left + insets.right + 1;
  size.height += insets.top + insets.bottom + 1;
}
 
示例3
public Rectangle getMoreRect(final SingleRowPassInfo data) {
  int x;
  if (myTabs.isEditorTabs()) {
    x = data.layoutSize.width - data.moreRectAxisSize - 1;
  }
  else {
    x = data.position + (data.lastGhostVisible ? data.lastGhost.width : 0);
  }
  return new Rectangle(x, data.insets.top + JBTabsImpl.getSelectionTabVShift(),
                                        data.moreRectAxisSize - 1, myTabs.myHeaderFitSize.height - 1);
}
 
示例4
public SingleRowPassInfo(SingleRowLayout layout, List<TabInfo> visibleInfos) {
  super(visibleInfos);
  JBTabsImpl tabs = layout.myTabs;
  layoutSize = tabs.getSize();
  contentCount = tabs.getTabCount();
  toLayout = new ArrayList<TabInfo>();
  toDrop = new ArrayList<TabInfo>();
  moreRectAxisSize = layout.getStrategy().getMoreRectAxisSize();
  scrollOffset = layout.getScrollOffset();
}
 
示例5
private static void updateTabSizeLimit(DesktopEditorWindow editorWindow, String tabSizeLimit) {
  EditorTabbedContainer tabbedPane = editorWindow.getTabbedPane();
  if (tabbedPane != null) {
    if (tabSizeLimit != null) {
      try {
        int limit = Integer.parseInt(tabSizeLimit);
        UIUtil.invokeAndWaitIfNeeded((Runnable)() -> UIUtil.putClientProperty(tabbedPane.getComponent(), JBTabsImpl.SIDE_TABS_SIZE_LIMIT_KEY, limit));
      }
      catch (NumberFormatException ignored) {
      }
    }
  }
}
 
示例6
@Override
public void dragOutStarted(MouseEvent mouseEvent, TabInfo info) {
  final TabInfo previousSelection = info.getPreviousSelection();
  final Image img = JBTabsImpl.getComponentImage(info);
  info.setHidden(true);
  if (previousSelection != null) {
    myTabs.select(previousSelection, true);
  }

  myFile = (VirtualFile)info.getObject();
  Presentation presentation = new Presentation(info.getText());
  presentation.setIcon(info.getIcon());
  mySession = getDockManager().createDragSession(mouseEvent, createDockableEditor(myProject, img, myFile, presentation, myWindow));
}
 
示例7
@Override
public void add(@Nonnull DockableContent content, RelativePoint dropTarget) {
  EditorWindow window = null;
  if (myCurrentOver != null) {
    final DataProvider provider = myCurrentOver.getDataProvider();
    if (provider != null) {
      window = provider.getDataUnchecked(EditorWindow.DATA_KEY);
    }
  }

  final EditorTabbedContainer.DockableEditor dockableEditor = (EditorTabbedContainer.DockableEditor)content;
  VirtualFile file = dockableEditor.getFile();


  if (window == null || window.isDisposed()) {
    window = mySplitters.getOrCreateCurrentWindow(file);
  }


  if (myCurrentOver != null) {
    int index = ((JBTabsImpl)myCurrentOver).getDropInfoIndex();
    file.putUserData(DesktopEditorWindow.INITIAL_INDEX_KEY, index);
  }

  ((FileEditorManagerImpl)FileEditorManagerEx.getInstanceEx(myProject)).openFileImpl2(UIAccess.get(), window, file, true);
  window.setFilePinned(file, dockableEditor.isPinned());
}
 
示例8
@Override
public void actionPerformed(AnActionEvent e) {
  JBTabsImpl tabs = e.getData(JBTabsImpl.NAVIGATION_ACTIONS_KEY);
  if (tabs != null) {
    tabs.showMorePopup(null);
  }
}
 
示例9
private static boolean isTabListAvailable(AnActionEvent e) {
  JBTabsImpl tabs = e.getData(JBTabsImpl.NAVIGATION_ACTIONS_KEY);
  if (tabs == null || !tabs.isEditorTabs()) {
    return false;
  }
  return tabs.canShowMorePopup();
}
 
示例10
@Override
public void installUI(JComponent c) {
  super.installUI(c);

  JBTabsImpl tabs = (JBTabsImpl)c;
  tabs.setBackground(getBackground());
  tabs.setForeground(getForeground());
}
 
示例11
protected Dimension computeSize(JBTabsImpl tabs, Function<JComponent, Dimension> transform, int tabCount) {
  Dimension size = new Dimension();
  for (TabInfo each : tabs.getVisibleInfos()) {
    final JComponent c = each.getComponent();
    if (c != null) {
      final Dimension eachSize = transform.fun(c);
      size.width = Math.max(eachSize.width, size.width);
      size.height = Math.max(eachSize.height, size.height);
    }
  }

  addHeaderSize(tabs, size, tabCount);
  return size;
}
 
示例12
protected Dimension computeHeaderPreferredSize(JBTabsImpl tabs, int tabsCount) {
  final Iterator<TabInfo> infos = tabs.myInfo2Label.keySet().iterator();
  Dimension size = new Dimension();
  int currentTab = 0;

  final boolean horizontal = tabs.getTabsPosition() == JBTabsPosition.top || tabs.getTabsPosition() == JBTabsPosition.bottom;

  while (infos.hasNext()) {
    final boolean canGrow = currentTab < tabsCount;

    TabInfo eachInfo = infos.next();
    final TabLabel eachLabel = tabs.myInfo2Label.get(eachInfo);
    final Dimension eachPrefSize = eachLabel.getPreferredSize();
    if (horizontal) {
      if (canGrow) {
        size.width += eachPrefSize.width;
      }
      size.height = Math.max(size.height, eachPrefSize.height);
    }
    else {
      size.width = Math.max(size.width, eachPrefSize.width);
      if (canGrow) {
        size.height += eachPrefSize.height;
      }
    }

    currentTab++;
  }


  if (horizontal) {
    size.height += tabs.getTabsBorder().getTabBorderSize();
  }
  else {
    size.width += tabs.getTabsBorder().getTabBorderSize();
  }

  return size;
}
 
示例13
protected void doPaintInactive(JBTabsImpl t,
                               Graphics2D g2d,
                               boolean leftGhostExists,
                               TabLabel label,
                               Rectangle effectiveBounds,
                               boolean rightGhostExists,
                               int row,
                               int column) {
  Insets insets = t.getTabsBorder().getEffectiveBorder();

  int _x = effectiveBounds.x + insets.left;
  int _y = effectiveBounds.y + insets.top;
  int _width = effectiveBounds.width - insets.left - insets.right + (t.getTabsPosition() == JBTabsPosition.right ? 1 : 0);
  int _height = effectiveBounds.height - insets.top - insets.bottom;


  if ((!t.isSingleRow() /* for multiline */) || (t.isSingleRow() && t.isHorizontalTabs())) {
    if (t.isSingleRow() && t.getPosition() == JBTabsPosition.bottom) {
      _y += t.getActiveTabUnderlineHeight();
    }
    else {
      if (t.isSingleRow()) {
        _height -= t.getActiveTabUnderlineHeight();
      }
      else {
        TabInfo info = label.getInfo();
        if (((TableLayout)t.getEffectiveLayout()).isLastRow(info)) {
          _height -= t.getActiveTabUnderlineHeight();
        }
      }
    }
  }

  final boolean vertical = t.getTabsPosition() == JBTabsPosition.left || t.getTabsPosition() == JBTabsPosition.right;
  final Color tabColor = label.getInfo().getTabColor();
  doPaintInactive(g2d, effectiveBounds, _x, _y, _width, _height, tabColor, row, column, vertical);
}
 
示例14
protected void doPaintAdditionalBackgroundIfFirstOffsetSet(JBTabsImpl tabs, Graphics2D g2d, Rectangle clip) {
  if (tabs.getTabsPosition() == JBTabsPosition.top && tabs.isSingleRow() && tabs.getFirstTabOffset() > 0) {
    int maxOffset = 0;
    int maxLength = 0;

    for (int i = tabs.getVisibleInfos().size() - 1; i >= 0; i--) {
      TabInfo visibleInfo = tabs.getVisibleInfos().get(i);
      TabLabel tabLabel = tabs.myInfo2Label.get(visibleInfo);
      Rectangle r = tabLabel.getBounds();
      if (r.width == 0 || r.height == 0) continue;
      maxOffset = r.x + r.width;
      maxLength = r.height;
      break;
    }

    maxOffset++;
    g2d.setPaint(UIUtil.getPanelBackground());
    if (tabs.getFirstTabOffset() > 0) {
      g2d.fillRect(clip.x, clip.y, clip.x + JBUI.scale(tabs.getFirstTabOffset() - 1), clip.y + maxLength - tabs.getActiveTabUnderlineHeight());
    }
    g2d.fillRect(clip.x + maxOffset, clip.y, clip.width - maxOffset, clip.y + maxLength - tabs.getActiveTabUnderlineHeight());
    g2d.setPaint(new JBColor(Gray._181, UIUtil.getPanelBackground()));
    g2d.drawLine(clip.x + maxOffset, clip.y + maxLength - tabs.getActiveTabUnderlineHeight(), clip.x + clip.width,
                 clip.y + maxLength - tabs.getActiveTabUnderlineHeight());
    g2d.setPaint(UIUtil.getPanelBackground());
    g2d.drawLine(clip.x, clip.y + maxLength, clip.width, clip.y + maxLength);
  }
}
 
示例15
public void paintChildren(JBTabsImpl tabs, Graphics g) {
  final GraphicsConfig config = new GraphicsConfig(g);
  config.setAntialiasing(true);
  paintSelectionAndBorder(tabs, (Graphics2D)g);
  config.restore();

  final TabLabel selected = tabs.getSelectedLabel();
  if (selected != null) {
    selected.paintImage(g);
  }

  tabs.getSingleRowLayoutInternal().myMoreIcon.paintIcon(tabs, g);
}
 
示例16
protected ShapeInfo _computeSelectedLabelShape(JBTabsImpl tabs) {
  final ShapeInfo shape = new ShapeInfo();

  shape.path = tabs.getEffectiveLayout().createShapeTransform(tabs.getSize());
  shape.insets = shape.path.transformInsets(tabs.getLayoutInsets());
  shape.labelPath = shape.path.createTransform(tabs.getSelectedLabel().getBounds());

  shape.labelBottomY = shape.labelPath.getMaxY() - shape.labelPath.deltaY(tabs.getActiveTabUnderlineHeight() - 1);
  shape.labelTopY =
          shape.labelPath.getY() + (tabs.getPosition() == JBTabsPosition.top || tabs.getPosition() == JBTabsPosition.bottom ? shape.labelPath.deltaY(1) : 0);
  shape.labelLeftX =
          shape.labelPath.getX() + (tabs.getPosition() == JBTabsPosition.top || tabs.getPosition() == JBTabsPosition.bottom ? 0 : shape.labelPath.deltaX(1));
  shape.labelRightX = shape.labelPath.getMaxX() - shape.labelPath.deltaX(1);

  int leftX = shape.insets.left + (tabs.getPosition() == JBTabsPosition.top || tabs.getPosition() == JBTabsPosition.bottom ? 0 : shape.labelPath.deltaX(1));

  shape.path.moveTo(leftX, shape.labelBottomY);
  shape.path.lineTo(shape.labelLeftX, shape.labelBottomY);
  shape.path.lineTo(shape.labelLeftX, shape.labelTopY);
  shape.path.lineTo(shape.labelRightX, shape.labelTopY);
  shape.path.lineTo(shape.labelRightX, shape.labelBottomY);

  int lastX = shape.path.getWidth() - shape.path.deltaX(shape.insets.right);

  shape.path.lineTo(lastX, shape.labelBottomY);
  shape.path.lineTo(lastX, shape.labelBottomY + shape.labelPath.deltaY(tabs.getActiveTabUnderlineHeight() - 1));
  shape.path.lineTo(leftX, shape.labelBottomY + shape.labelPath.deltaY(tabs.getActiveTabUnderlineHeight() - 1));

  shape.path.closePath();
  shape.fillPath = shape.path.copy();

  return shape;
}
 
示例17
public CompressibleSingleRowLayout(JBTabsImpl tabs) {
  super(tabs);
}
 
示例18
public ScrollableSingleRowLayout(final JBTabsImpl tabs) {
  super(tabs);
}
 
示例19
public Rectangle getMoreRect(final SingleRowPassInfo data) {
  return new Rectangle(data.insets.left + JBTabsImpl.getSelectionTabVShift(),
                       myTabs.getHeight() - data.insets.bottom - data.moreRectAxisSize - 1,
                       myTabs.myHeaderFitSize.width - 1,
                       data.moreRectAxisSize - 1);
}
 
示例20
TablePassInfo(final JBTabsImpl tabs, List<TabInfo> visibleInfos) {
  super(visibleInfos);
  myTabs = tabs;
}
 
示例21
public TableLayout(final JBTabsImpl tabs) {
  myTabs = tabs;
}
 
示例22
@Override
protected JPanel processFiles(@Nonnull List<Element> fileElements, final JPanel context, Element parent, UIAccess uiAccess) {
  final Ref<DesktopEditorWindow> windowRef = new Ref<>();
  UIUtil.invokeAndWaitIfNeeded((Runnable)() -> {
    DesktopEditorWindow editorWindow = context == null ? createEditorWindow() : findWindowWith(context);
    windowRef.set(editorWindow);
    if (editorWindow != null) {
      updateTabSizeLimit(editorWindow, parent.getAttributeValue(JBTabsImpl.SIDE_TABS_SIZE_LIMIT_KEY.toString()));
    }
  });

  final DesktopEditorWindow window = windowRef.get();
  LOG.assertTrue(window != null);
  VirtualFile focusedFile = null;

  for (int i = 0; i < fileElements.size(); i++) {
    final Element file = fileElements.get(i);
    Element historyElement = file.getChild(HistoryEntry.TAG);
    String fileName = historyElement.getAttributeValue(HistoryEntry.FILE_ATTR);
    Activity activity = StartUpMeasurer.startActivity(PathUtil.getFileName(fileName), ActivityCategory.REOPENING_EDITOR);
    VirtualFile virtualFile = null;
    try {
      final FileEditorManagerImpl fileEditorManager = getManager();
      final HistoryEntry entry = HistoryEntry.createLight(fileEditorManager.getProject(), historyElement);
      virtualFile = entry.getFile();
      if (virtualFile == null) throw new InvalidDataException("No file exists: " + entry.getFilePointer().getUrl());
      virtualFile.putUserData(OPENED_IN_BULK, Boolean.TRUE);
      VirtualFile finalVirtualFile = virtualFile;
      Document document = ReadAction.compute(() -> finalVirtualFile.isValid() ? FileDocumentManager.getInstance().getDocument(finalVirtualFile) : null);

      boolean isCurrentTab = Boolean.valueOf(file.getAttributeValue(CURRENT_IN_TAB)).booleanValue();
      FileEditorOpenOptions openOptions = new FileEditorOpenOptions().withPin(Boolean.valueOf(file.getAttributeValue(PINNED))).withIndex(i).withReopeningEditorsOnStartup();

      fileEditorManager.openFileImpl4(uiAccess, window, virtualFile, entry, openOptions);
      if (isCurrentTab) {
        focusedFile = virtualFile;
      }
      if (document != null) {
        // This is just to make sure document reference is kept on stack till this point
        // so that document is available for folding state deserialization in HistoryEntry constructor
        // and that document will be created only once during file opening
        document.putUserData(DUMMY_KEY, null);
      }
      updateProgress();
    }
    catch (InvalidDataException e) {
      if (ApplicationManager.getApplication().isUnitTestMode()) {
        LOG.error(e);
      }
    }
    finally {
      if (virtualFile != null) virtualFile.putUserData(OPENED_IN_BULK, null);
    }
    activity.end();
  }
  if (focusedFile != null) {
    getManager().addSelectionRecord(focusedFile, window);
    VirtualFile finalFocusedFile = focusedFile;
    uiAccess.giveAndWaitIfNeed(() -> {
      EditorWithProviderComposite editor = window.findFileComposite(finalFocusedFile);
      if (editor != null) {
        window.setEditor(editor, true, true);
      }
    });
  }
  else {
    ToolWindowManager manager = ToolWindowManager.getInstance(getManager().getProject());
    manager.invokeLater(() -> {
      if (null == manager.getActiveToolWindowId()) {
        ToolWindow toolWindow = manager.getToolWindow(ToolWindowId.PROJECT_VIEW);
        if (toolWindow != null) toolWindow.activate(null);
      }
    });
  }
  return window.myPanel;
}
 
示例23
private DockWindow(String id, Project project, DockContainer container, boolean dialog) {
  super(project, null, dialog);
  myId = id;
  myContainer = container;
  setProject(project);

  if (!(container instanceof DockContainer.Dialog)) {
    setStatusBar(WindowManager.getInstance().getStatusBar(project).createChild());
  }

  myUiContainer = new NonOpaquePanel(new BorderLayout());

  NonOpaquePanel center = new NonOpaquePanel(new BorderLayout(0, 2));
  if (UIUtil.isUnderAquaLookAndFeel()) {
    center.setOpaque(true);
    center.setBackground(JBTabsImpl.MAC_AQUA_BG_COLOR);
  }

  center.add(myNorthPanel, BorderLayout.NORTH);

  myDockContentUiContainer = new NonOpaquePanel(new BorderLayout());
  myDockContentUiContainer.add(myContainer.getContainerComponent(), BorderLayout.CENTER);
  center.add(myDockContentUiContainer, BorderLayout.CENTER);

  myUiContainer.add(center, BorderLayout.CENTER);
  if (myStatusBar != null) {
    myUiContainer.add(myStatusBar.getComponent(), BorderLayout.SOUTH);
  }

  setComponent(myUiContainer);
  addDisposable(container);

  IdeEventQueue.getInstance().addPostprocessor(this, this);

  myContainer.addListener(new DockContainer.Listener.Adapter() {
    @Override
    public void contentRemoved(Object key) {
      getReady().doWhenDone(() -> {
        if (myContainer.isEmpty()) {
          close();
        }
      });
    }
  }, this);

  UISettings.getInstance().addUISettingsListener(new UISettingsListener() {
    @Override
    public void uiSettingsChanged(UISettings source) {
      updateNorthPanel();
    }
  }, this);

  updateNorthPanel();
}
 
示例24
public MyTabLabel(JBTabsImpl tabs, final TabInfo info) {
  super(tabs, info);
}
 
示例25
@Override
public Dimension getMinimumSize(JComponent c) {
  return computeSize((JBTabsImpl)c, JComponent::getMinimumSize, 1);
}
 
示例26
@Override
public Dimension getPreferredSize(JComponent c) {
  return computeSize((JBTabsImpl)c, JComponent::getPreferredSize, 3);
}
 
示例27
protected void paintSelectionAndBorder(JBTabsImpl tabs, Graphics2D g2d) {
  if (tabs.getSelectedInfo() == null || tabs.isHideTabs()) return;

  TabLabel label = tabs.getSelectedLabel();
  Rectangle r = label.getBounds();

  ShapeInfo selectedShape = _computeSelectedLabelShape(tabs);

  Insets insets = tabs.getTabsBorder().getEffectiveBorder();

  Color tabColor = label.getInfo().getTabColor();
  final boolean isHorizontalTabs = tabs.isHorizontalTabs();

  paintSelectionAndBorder(g2d, r, selectedShape, insets, tabColor, isHorizontalTabs);
}
 
示例28
public abstract void paintChildren(JBTabsImpl tabs, Graphics g);