Java 类com.intellij.ui.tabs.impl.JBEditorTabs 实例源码

项目:consulo    文件:DisposerDebugger.java   
private void initUi() {
  myComponent = new JPanel();

  myTreeTabs = new JBEditorTabs(null, ActionManager.getInstance(), null, this);

  final Splitter splitter = new Splitter(true);

  final JBTabsImpl bottom = new JBEditorTabs(null, ActionManager.getInstance(), null, this);
  final AllocationPanel allocations = new AllocationPanel(myTreeTabs);
  bottom.addTab(new TabInfo(allocations).setText("Allocation")).setActions(allocations.getActions(), ActionPlaces.UNKNOWN);


  splitter.setFirstComponent(myTreeTabs);
  splitter.setSecondComponent(bottom);

  myComponent.setLayout(new BorderLayout());
  myComponent.add(splitter, BorderLayout.CENTER);
  JLabel countLabel = new JLabel("Total disposable count: " + Disposer.getTree().size());
  myComponent.add(countLabel, BorderLayout.SOUTH);

  addTree(new DisposerTree(this), "All", false);
  addTree(new DisposerTree(this), "Watch", true);
}
项目:intellij-ce-playground    文件:JBTabsPaneImpl.java   
public JBTabsPaneImpl(@Nullable Project project, int tabPlacement, @NotNull Disposable parent) {
  myTabs = new JBEditorTabs(project, ActionManager.getInstance(), project == null ? null : IdeFocusManager.getInstance(project), parent) {
    @Override
    public boolean isAlphabeticalMode() {
      return false;
    }

    @Override
    public boolean supportsCompression() {
      return false;
    }

    @Override
    protected Color getEmptySpaceColor() {
      return UIUtil.getBgFillColor(getParent());
    }

    @Override
    protected void paintSelectionAndBorder(Graphics2D g2d) {
      super.paintSelectionAndBorder(g2d);
    }
  };
  myTabs.setFirstTabOffset(10);

  myTabs.addListener(new TabsListener.Adapter() {
    @Override
    public void selectionChanged(TabInfo oldSelection, TabInfo newSelection) {
      fireChanged(new ChangeEvent(myTabs));
    }
  }).getPresentation()
    .setPaintBorder(1, 1, 1, 1)
    .setTabSidePaintBorder(2)
    .setPaintFocus(UIUtil.isUnderDarcula() || UIUtil.isUnderIntelliJLaF())
    .setAlwaysPaintSelectedTab(UIUtil.isUnderDarcula() || UIUtil.isUnderIntelliJLaF())
    .setGhostsAlwaysVisible(true);

  setTabPlacement(tabPlacement);
}
项目:material-theme-jetbrains    文件:MTTabsPainterPatcherComponent.java   
@Override
public void initComponent() {
  final MessageBus bus = ApplicationManagerEx.getApplicationEx().getMessageBus();

  final MessageBusConnection connect = bus.connect();
  connect.subscribe(FileEditorManagerListener.FILE_EDITOR_MANAGER, new FileEditorManagerListener() {
    @Override
    public void selectionChanged(@NotNull final FileEditorManagerEvent event) {
      final FileEditor editor = event.getNewEditor();
      if (editor != null) {
        Component component = editor.getComponent();
        while (component != null) {
          if (component instanceof JBEditorTabs) {
            patchPainter((JBEditorTabs) component);
            return;
          }
          component = component.getParent();
        }
      }
    }
  });

  // Listen to option save to set tab height
  setTabsHeight();
  connect.subscribe(ConfigNotifier.CONFIG_TOPIC, mtConfig -> setTabsHeight());

  try {
    hackTabsGetHeight();
    hackToolWindowHeader();
  } catch (final Exception e) {
    e.printStackTrace();
  }
}
项目:material-theme-jetbrains    文件:MTTabsPainterPatcherComponent.java   
/**
 * Patch tabsPainter
 *
 * @param component
 */
private void patchPainter(final JBEditorTabs component) {
  final JBEditorTabsPainter painter = ReflectionUtil.getField(JBEditorTabs.class, component,
      JBEditorTabsPainter.class, "myDarkPainter");

  if (painter instanceof MTTabsPainter) {
    return;
  }

  final MTTabsPainter tabsPainter = new MTTabsPainter(component);
  final JBEditorTabsPainter proxy = (MTTabsPainter) Enhancer.create(MTTabsPainter.class, (MethodInterceptor) (o, method, objects,
                                                                                                              methodProxy) -> {
    final Object result = method.invoke(tabsPainter, objects);
    final Color defaultColor = theme.getBorderColor();

    // Custom props
    final boolean isColorEnabled = config.isHighlightColorEnabled();
    final Color borderColor = isColorEnabled ? config.getHighlightColor() : defaultColor;
    final int borderThickness = config.getHighlightThickness();

    if ("paintSelectionAndBorder".equals(method.getName())) {
      paintSelectionAndBorder(objects, borderColor, borderThickness, tabsPainter);
    }

    return result;
  });

  ReflectionUtil.setField(JBEditorTabs.class, component, JBEditorTabsPainter.class, "myDarkPainter", proxy);
}
项目:consulo    文件:JBTabsPaneImpl.java   
public JBTabsPaneImpl(@Nullable Project project, int tabPlacement, @Nonnull Disposable parent) {
  myTabs = new JBEditorTabs(project, ActionManager.getInstance(), project == null ? null : IdeFocusManager.getInstance(project), parent) {
    @Override
    public boolean isAlphabeticalMode() {
      return false;
    }

    @Override
    public boolean supportsCompression() {
      return false;
    }
  };
  myTabs.setFirstTabOffset(10);

  myTabs.addListener(new TabsListener.Adapter() {
    @Override
    public void selectionChanged(TabInfo oldSelection, TabInfo newSelection) {
      fireChanged(new ChangeEvent(myTabs));
    }
  }).getPresentation()
          .setPaintBorder(1, 1, 1, 1)
          .setTabSidePaintBorder(2)
          .setPaintFocus(UIUtil.isUnderBuildInLaF())
          .setAlwaysPaintSelectedTab(UIUtil.isUnderBuildInLaF())
          .setGhostsAlwaysVisible(true);

  setTabPlacement(tabPlacement);
}
项目:ApiDebugger    文件:DebuggerTabsIml.java   
public DebuggerTabsIml(Project project, Disposable parent) {
    mTabs = new JBEditorTabs(project, ActionManager.getInstance(), IdeFocusManager.getInstance(project), parent);
    mTabs.addListener(createListener());
    mTabs.setTabDraggingEnabled(true);
}
项目:ApiDebugger    文件:DebuggerTabsIml.java   
@Override
public JBEditorTabs getComponent() {
    return mTabs;
}
项目:intellij-ce-playground    文件:EditorTabbedContainer.java   
public MyShadowBorder(JBEditorTabs tabs) {
  myTabs = tabs;
}
项目:intellij-ce-playground    文件:TabsAlphabeticalModeSwitcher.java   
@Override
public boolean isSelected(AnActionEvent e) {
  return Registry.is(JBEditorTabs.TABS_ALPHABETICAL_KEY);
}
项目:intellij-ce-playground    文件:TabsAlphabeticalModeSwitcher.java   
@Override
public void setSelected(AnActionEvent e, boolean state) {
  JBEditorTabs.setAlphabeticalMode(state);
}
项目:material-theme-jetbrains    文件:MTTabsPainterPatcherComponent.java   
/**
 * Paint tab selected and highlight border
 *
 * @param objects
 * @param borderColor
 * @param borderThickness
 * @param tabsPainter
 */
private void paintSelectionAndBorder(final Object[] objects,
                                     final Color borderColor,
                                     final int borderThickness,
                                     final MTTabsPainter tabsPainter)
    throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
  // Get the shapeinfo class because it is protected
  final Class<?> clazz = Class.forName("com.intellij.ui.tabs.impl.JBTabsImpl$ShapeInfo");

  // Retrieve arguments
  final Graphics2D g2d = (Graphics2D) objects[0];
  final Rectangle rect = (Rectangle) objects[1];
  final Object selectedShape = objects[2];
  final Color tabColor = (Color) objects[4];

  // Retrieve private fields of ShapeInfo class
  final Field fillPathField = clazz.getField("fillPath");
  final ShapeTransform fillPath = (ShapeTransform) fillPathField.get(selectedShape);

  // Other properties needed for drawing
  final int rectX = rect.x;
  final int rectY = rect.y;
  final int rectHeight = rect.height;

  // The tabs component
  final JBEditorTabs tabsComponent = tabsPainter.getTabsComponent();

  // Position of tabs
  final JBTabsPosition position = tabsComponent.getTabsPosition();

  // color me
  tabsPainter.fillSelectionAndBorder(g2d, fillPath, tabColor, rectX, rectY, rectHeight);
  g2d.setColor(borderColor);

  if (position == JBTabsPosition.bottom) {
    // Paint on top
    g2d.fillRect(rect.x, rect.y - 1, rect.width, borderThickness);
  } else if (position == JBTabsPosition.top) {
    // Paint on bottom
    g2d.fillRect(rect.x, rect.y + rect.height - borderThickness + 1, rect.width, borderThickness);
    g2d.setColor(UIUtil.CONTRAST_BORDER_COLOR);
    g2d.drawLine(Math.max(0, rect.x - 1), rect.y, rect.x + rect.width, rect.y);
  } else if (position == JBTabsPosition.left) {
    g2d.fillRect(rect.x, rect.y, borderThickness, rect.height);
  } else if (position == JBTabsPosition.right) {
    g2d.fillRect(rect.x + rect.width - borderThickness + 1, rect.y, borderThickness, rect.height);
  }
}
项目:material-theme-jetbrains    文件:MTTabsPainterPatcherComponent.java   
public MTTabsPainter(final JBEditorTabs tabs) {
  super(tabs);
}
项目:material-theme-jetbrains    文件:MTTabsPainterPatcherComponent.java   
public final JBEditorTabs getTabsComponent() {
  return myTabs;
}
项目:tools-idea    文件:EditorTabbedContainer.java   
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() {
    @NotNull
    @Override
    public ActionCallback execute(TabInfo info, boolean requestFocus, @NotNull 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);
  myTabs.addMouseListener(new MouseAdapter() {
    @Override
    public void mouseClicked(MouseEvent e) {
      if (myTabs.findInfo(e) != null || isFloating()) return;
      if (!e.isPopupTrigger() && SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2) {
        final ActionManager mgr = ActionManager.getInstance();
        mgr.tryToExecute(mgr.getAction("HideAllWindows"), e, null, ActionPlaces.UNKNOWN, 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);
}
项目:tools-idea    文件:TabsAlphabeticalModeSwitcher.java   
@Override
public boolean isSelected(AnActionEvent e) {
  return JBEditorTabs.isAlphabeticalMode();
}
项目:tools-idea    文件:TabsAlphabeticalModeSwitcher.java   
@Override
public void setSelected(AnActionEvent e, boolean state) {
  JBEditorTabs.setAlphabeticalMode(state);
}
项目:consulo    文件:EditorTabbedContainer.java   
EditorTabbedContainer(final DesktopEditorWindow window, Project project) {
  myWindow = window;
  myProject = project;
  final ActionManager actionManager = ActionManager.getInstance();
  myTabs = new JBEditorTabs(project, actionManager, IdeFocusManager.getInstance(project), this);
  myTabs.setBorder(new MyShadowBorder(myTabs));
  myTabs.setTransferHandler(new MyTransferHandler());
  myTabs.setDataProvider(new MyDataProvider())
          .setPopupGroup(() -> (ActionGroup)CustomActionsSchema.getInstance().getCorrectedAction(IdeActions.GROUP_EDITOR_TAB_POPUP),
                         ActionPlaces.EDITOR_TAB_POPUP, false).addTabMouseListener(new TabMouseListener()).getPresentation().setTabDraggingEnabled(true)
          .setUiDecorator(() -> new UiDecorator.UiDecoration(null, new Insets(TabsUtil.TAB_VERTICAL_PADDING, 8, TabsUtil.TAB_VERTICAL_PADDING, 8)))
          .setTabLabelActionsMouseDeadzone(TimedDeadzone.NULL).setGhostsAlwaysVisible(true).setTabLabelActionsAutoHide(false)
          .setActiveTabFillIn(EditorColorsManager.getInstance().getGlobalScheme().getDefaultBackground()).setPaintFocus(false).getJBTabs()
          .addListener(new TabsListener.Adapter() {
            @Override
            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();
              }

              VirtualFile newFile = (VirtualFile)newSelection.getObject();
              final FileEditor newEditor = editorManager.getSelectedEditor(newFile);
              if (newEditor != null) {
                newEditor.selectNotify();
              }

              if (GeneralSettings.getInstance().isSyncOnFrameActivation()) {
                VfsUtil.markDirtyAndRefresh(true, false, false, newFile);
              }
            }
          }).setSelectionChangeHandler((info, requestFocus, doChangeSelection) -> {
    final ActionCallback result = new ActionCallback();
    CommandProcessor.getInstance().executeCommand(myProject, () -> {
      ((IdeDocumentHistoryImpl)IdeDocumentHistory.getInstance(myProject)).onSelectionChanged();
      result.notify(doChangeSelection.run());
    }, "EditorChange", null);
    return result;
  }).getPresentation().setRequestFocusOnLastFocusedComponent(true);
  myTabs.addMouseListener(new MouseAdapter() {
    @Override
    public void mouseClicked(MouseEvent e) {
      if (myTabs.findInfo(e) != null || isFloating()) return;
      if (!e.isPopupTrigger() && SwingUtilities.isLeftMouseButton(e) && e.getClickCount() == 2) {
        final ActionManager mgr = ActionManager.getInstance();
        mgr.tryToExecute(mgr.getAction("HideAllWindows"), e, null, ActionPlaces.UNKNOWN, true);
      }
    }
  });

  setTabPlacement(UISettings.getInstance().EDITOR_TAB_PLACEMENT);

  updateTabBorder();

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

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

  project.getMessageBus().connect().subscribe(UISettingsListener.TOPIC, uiSettings -> updateTabBorder());

  Disposer.register(project, this);
}
项目:consulo    文件:EditorTabbedContainer.java   
MyShadowBorder(JBEditorTabs tabs) {
  myTabs = tabs;
}
项目:consulo    文件:TabsAlphabeticalModeSwitcher.java   
@Override
public boolean isSelected(AnActionEvent e) {
  return Registry.is(JBEditorTabs.TABS_ALPHABETICAL_KEY);
}
项目:consulo    文件:TabsAlphabeticalModeSwitcher.java   
@Override
public void setSelected(AnActionEvent e, boolean state) {
  JBEditorTabs.setAlphabeticalMode(state);
}
项目:ApiDebugger    文件:IDebuggerTabs.java   
JBEditorTabs getComponent();