コード例 #1
0
  public void insertTab(
      final VirtualFile file,
      final Icon icon,
      final JComponent comp,
      final String tooltip,
      final int indexToInsert) {

    TabInfo tab = myTabs.findInfo(file);
    if (tab != null) return;

    tab =
        new TabInfo(comp)
            .setText(calcTabTitle(myProject, file))
            .setIcon(icon)
            .setTooltipText(tooltip)
            .setObject(file)
            .setTabColor(calcTabColor(myProject, file))
            .setDragOutDelegate(myDragOutDelegate);
    tab.setTestableUi(new MyQueryable(tab));

    final DefaultActionGroup tabActions = new DefaultActionGroup();
    tabActions.add(new CloseTab(comp, tab));

    tab.setTabLabelActions(tabActions, ActionPlaces.EDITOR_TAB);
    myTabs.addTab(tab, indexToInsert);
  }
コード例 #2
0
 public void setTabLayoutPolicy(final int policy) {
   switch (policy) {
     case JTabbedPane.SCROLL_TAB_LAYOUT:
       myTabs.getPresentation().setSingleRow(true);
       break;
     case JTabbedPane.WRAP_TAB_LAYOUT:
       myTabs.getPresentation().setSingleRow(false);
       break;
     default:
       throw new IllegalArgumentException("Unsupported tab layout policy: " + policy);
   }
 }
コード例 #3
0
 public ActionCallback removeTabAt(
     final int componentIndex, int indexToSelect, boolean transferFocus) {
   TabInfo toSelect =
       indexToSelect >= 0 && indexToSelect < myTabs.getTabCount()
           ? myTabs.getTabAt(indexToSelect)
           : null;
   final TabInfo info = myTabs.getTabAt(componentIndex);
   // removing hidden tab happens on end of drag-out, we've already selected the correct tab for
   // this case in dragOutStarted
   if (info.isHidden()) {
     toSelect = null;
   }
   final ActionCallback callback = myTabs.removeTab(info, toSelect, transferFocus);
   return myProject.isOpen() ? callback : new ActionCallback.Done();
 }
コード例 #4
0
 public void setTabPlacement(final int tabPlacement) {
   switch (tabPlacement) {
     case SwingConstants.TOP:
       myTabs.getPresentation().setTabsPosition(JBTabsPosition.top);
       break;
     case SwingConstants.BOTTOM:
       myTabs.getPresentation().setTabsPosition(JBTabsPosition.bottom);
       break;
     case SwingConstants.LEFT:
       myTabs.getPresentation().setTabsPosition(JBTabsPosition.left);
       break;
     case SwingConstants.RIGHT:
       myTabs.getPresentation().setTabsPosition(JBTabsPosition.right);
       break;
     default:
       throw new IllegalArgumentException("Unknown tab placement code=" + tabPlacement);
   }
 }
コード例 #5
0
  private void updateTabBorder() {
    if (!myProject.isOpen()) return;

    ToolWindowManagerEx mgr = (ToolWindowManagerEx) ToolWindowManager.getInstance(myProject);

    String[] ids = mgr.getToolWindowIds();

    Insets border = new Insets(0, 0, 0, 0);

    UISettings uiSettings = UISettings.getInstance();

    List<String> topIds = mgr.getIdsOn(ToolWindowAnchor.TOP);
    List<String> bottom = mgr.getIdsOn(ToolWindowAnchor.BOTTOM);
    List<String> rightIds = mgr.getIdsOn(ToolWindowAnchor.RIGHT);
    List<String> leftIds = mgr.getIdsOn(ToolWindowAnchor.LEFT);

    if (!uiSettings.HIDE_TOOL_STRIPES) {
      border.top = topIds.size() > 0 ? 1 : 0;
      border.bottom = bottom.size() > 0 ? 1 : 0;
      border.left = leftIds.size() > 0 ? 1 : 0;
      border.right = rightIds.size() > 0 ? 1 : 0;
    }

    for (String each : ids) {
      ToolWindow eachWnd = mgr.getToolWindow(each);
      if (!eachWnd.isAvailable()) continue;

      if (eachWnd.isVisible() && eachWnd.getType() == ToolWindowType.DOCKED) {
        ToolWindowAnchor eachAnchor = eachWnd.getAnchor();
        if (eachAnchor == ToolWindowAnchor.TOP) {
          border.top = 0;
        } else if (eachAnchor == ToolWindowAnchor.BOTTOM) {
          border.bottom = 0;
        } else if (eachAnchor == ToolWindowAnchor.LEFT) {
          border.left = 0;
        } else if (eachAnchor == ToolWindowAnchor.RIGHT) {
          border.right = 0;
        }
      }
    }

    myTabs
        .getPresentation()
        .setPaintBorder(border.top, border.left, border.right, border.bottom)
        .setTabSidePaintBorder(5);
  }
コード例 #6
0
  public void close() {
    TabInfo selected = myTabs.getTargetInfo();
    if (selected == null) return;

    final VirtualFile file = (VirtualFile) selected.getObject();
    final FileEditorManagerEx mgr = FileEditorManagerEx.getInstanceEx(myProject);

    AsyncResult<EditorWindow> window = mgr.getActiveWindow();
    window.doWhenDone(
        new AsyncResult.Handler<EditorWindow>() {
          @Override
          public void run(EditorWindow wnd) {
            if (wnd != null) {
              if (wnd.findFileComposite(file) != null) {
                mgr.closeFile(file, wnd);
              }
            }
          }
        });
  }
コード例 #7
0
 @Nullable
 public Object getSelectedComponent() {
   final TabInfo info = myTabs.getTargetInfo();
   return info != null ? info.getComponent() : null;
 }
コード例 #8
0
 public void setBackgroundColorAt(final int index, final Color color) {
   myTabs.getTabAt(index).setTabColor(color);
 }
コード例 #9
0
 public ActionCallback setSelectedIndex(final int indexToSelect, boolean focusEditor) {
   return myTabs.select(myTabs.getTabAt(indexToSelect), focusEditor);
 }
コード例 #10
0
 public void requestFocus(boolean forced) {
   if (myTabs != null) {
     IdeFocusManager.getInstance(myProject).requestFocus(myTabs.getComponent(), forced);
   }
 }
コード例 #11
0
 public void setWaveColor(final int index, @Nullable final Color color) {
   final TabInfo tab = myTabs.getTabAt(index);
   tab.setDefaultStyle(
       color == null ? SimpleTextAttributes.STYLE_PLAIN : SimpleTextAttributes.STYLE_WAVED);
   tab.setDefaultWaveColor(color);
 }
コード例 #12
0
 public void setForegroundAt(final int index, final Color color) {
   myTabs.getTabAt(index).setDefaultForeground(color);
 }
コード例 #13
0
 public int getSelectedIndex() {
   return myTabs.getIndexOf(myTabs.getSelectedInfo());
 }
コード例 #14
0
 public Component getComponent() {
   return myTabs.getComponent();
 }
コード例 #15
0
 public void setIconAt(final int index, final Icon icon) {
   myTabs.getTabAt(index).setIcon(icon);
 }
コード例 #16
0
 public boolean isEmptyVisible() {
   return myTabs.isEmptyVisible();
 }
コード例 #17
0
 public void setTitleAt(final int index, final String text) {
   myTabs.getTabAt(index).setText(text);
 }
コード例 #18
0
 public Component getComponentAt(final int i) {
   final TabInfo tab = myTabs.getTabAt(i);
   return tab.getComponent();
 }
コード例 #19
0
 public void setToolTipTextAt(final int index, final String text) {
   myTabs.getTabAt(index).setTooltipText(text);
 }
コード例 #20
0
  EditorTabbedContainer(final EditorWindow window, Project project, final int tabPlacement) {
    myWindow = window;
    myProject = project;
    final ActionManager actionManager = ActionManager.getInstance();
    myTabs = new JBEditorTabs(project, actionManager, IdeFocusManager.getInstance(project), this);
    myTabs
        .setDataProvider(new MyDataProvider())
        .setPopupGroup(
            new Getter<ActionGroup>() {
              public ActionGroup get() {
                return (ActionGroup)
                    CustomActionsSchema.getInstance()
                        .getCorrectedAction(IdeActions.GROUP_EDITOR_TAB_POPUP);
              }
            },
            ActionPlaces.EDITOR_TAB_POPUP,
            false)
        .setNavigationActionsEnabled(false)
        .addTabMouseListener(new TabMouseListener())
        .getPresentation()
        .setTabDraggingEnabled(true)
        .setUiDecorator(
            new UiDecorator() {
              @NotNull
              public UiDecoration getDecoration() {
                return new UiDecoration(
                    null,
                    new Insets(
                        TabsUtil.TAB_VERTICAL_PADDING, 10, TabsUtil.TAB_VERTICAL_PADDING, 10));
              }
            })
        .setTabLabelActionsMouseDeadzone(TimedDeadzone.NULL)
        .setGhostsAlwaysVisible(true)
        .setTabLabelActionsAutoHide(false)
        .setActiveTabFillIn(
            EditorColorsManager.getInstance().getGlobalScheme().getDefaultBackground())
        .setPaintFocus(false)
        .getJBTabs()
        .addListener(
            new TabsListener.Adapter() {
              public void selectionChanged(final TabInfo oldSelection, final TabInfo newSelection) {
                final FileEditorManager editorManager = FileEditorManager.getInstance(myProject);
                final FileEditor oldEditor =
                    oldSelection != null
                        ? editorManager.getSelectedEditor((VirtualFile) oldSelection.getObject())
                        : null;
                if (oldEditor != null) {
                  oldEditor.deselectNotify();
                }

                final FileEditor newEditor =
                    editorManager.getSelectedEditor((VirtualFile) newSelection.getObject());
                if (newEditor != null) {
                  newEditor.selectNotify();
                }
              }
            })
        .setAdditionalSwitchProviderWhenOriginal(new MySwitchProvider())
        .setSelectionChangeHandler(
            new JBTabs.SelectionChangeHandler() {
              @Override
              public ActionCallback execute(
                  TabInfo info, boolean requestFocus, final ActiveRunnable doChangeSelection) {
                final ActionCallback result = new ActionCallback();
                CommandProcessor.getInstance()
                    .executeCommand(
                        myProject,
                        new Runnable() {
                          @Override
                          public void run() {
                            ((IdeDocumentHistoryImpl) IdeDocumentHistory.getInstance(myProject))
                                .onSelectionChanged();
                            result.notify(doChangeSelection.run());
                          }
                        },
                        "EditorChange",
                        null);
                return result;
              }
            })
        .getPresentation()
        .setRequestFocusOnLastFocusedComponent(true);

    setTabPlacement(UISettings.getInstance().EDITOR_TAB_PLACEMENT);

    updateTabBorder();

    ((ToolWindowManagerEx) ToolWindowManager.getInstance(myProject))
        .addToolWindowManagerListener(
            new ToolWindowManagerAdapter() {
              public void stateChanged() {
                updateTabBorder();
              }

              public void toolWindowRegistered(@NotNull final String id) {
                updateTabBorder();
              }
            });

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

    Disposer.register(project, this);
  }
コード例 #21
0
 public int getTabCount() {
   return myTabs.getTabCount();
 }