예제 #1
0
  public void paint(final Graphics g) {
    if (myTabs.isDropTarget(myInfo)) return;

    if (myTabs.getSelectedInfo() != myInfo) {
      doPaint(g);
    }
  }
예제 #2
0
  private void handlePopup(final MouseEvent e) {
    if (e.getClickCount() != 1 || !e.isPopupTrigger()) return;

    if (e.getX() < 0
        || e.getX() >= e.getComponent().getWidth()
        || e.getY() < 0
        || e.getY() >= e.getComponent().getHeight()) return;

    String place = myTabs.getPopupPlace();
    place = place != null ? place : ActionPlaces.UNKNOWN;
    myTabs.myPopupInfo = myInfo;

    final DefaultActionGroup toShow = new DefaultActionGroup();
    if (myTabs.getPopupGroup() != null) {
      toShow.addAll(myTabs.getPopupGroup());
      toShow.addSeparator();
    }

    JBTabsImpl tabs =
        JBTabsImpl.NAVIGATION_ACTIONS_KEY.getData(
            DataManager.getInstance().getDataContext(e.getComponent(), e.getX(), e.getY()));
    if (tabs == myTabs && myTabs.myAddNavigationGroup) {
      toShow.addAll(myTabs.myNavigationActions);
    }

    if (toShow.getChildrenCount() == 0) return;

    myTabs.myActivePopup =
        myTabs.myActionManager.createActionPopupMenu(place, toShow).getComponent();
    myTabs.myActivePopup.addPopupMenuListener(myTabs.myPopupListener);

    myTabs.myActivePopup.addPopupMenuListener(myTabs);
    myTabs.myActivePopup.show(e.getComponent(), e.getX(), e.getY());
  }
예제 #3
0
 @Override
 public void setProportion(float proportion) {
   int width = myTabs.getWidth();
   if (myTabs.getTabsPosition() == JBTabsPosition.left) {
     setSideTabsLimit((int) Math.max(JBTabsImpl.MIN_TAB_WIDTH, proportion * width));
   } else if (myTabs.getTabsPosition() == JBTabsPosition.right) {
     setSideTabsLimit(width - (int) Math.max(JBTabsImpl.MIN_TAB_WIDTH, proportion * width));
   }
 }
예제 #4
0
  protected int getNonSelectedOffset() {
    if (myTabs.isEditorTabs()) {
      int offset = (TabsUtil.ACTIVE_TAB_UNDERLINE_HEIGHT / 2);
      if (myTabs.isSingleRow()) {
        return myTabs.getTabsPosition() == JBTabsPosition.bottom ? -(offset + 1) : -offset + 1;
      } else {
        return ((TableLayout) myTabs.getEffectiveLayout()).isLastRow(getInfo())
            ? -offset + 1
            : offset - 1;
      }
    }

    return 2;
  }
예제 #5
0
 void setSideTabsLimit(int sideTabsLimit) {
   if (mySideTabsLimit != sideTabsLimit) {
     mySideTabsLimit = sideTabsLimit;
     //      UIUtil.putClientProperty(myTabs, JBTabsImpl.SIDE_TABS_SIZE_LIMIT_KEY,
     // mySideTabsLimit);
     myTabs.resetLayout(true);
     myTabs.doLayout();
     myTabs.repaint();
     TabInfo info = myTabs.getSelectedInfo();
     JComponent page = info != null ? info.getComponent() : null;
     if (page != null) {
       page.revalidate();
       page.repaint();
     }
   }
 }
예제 #6
0
  @Override
  public Insets getInsets() {
    Insets insets = super.getInsets();
    if (myTabs.isEditorTabs()) {
      if (UISettings.getInstance().SHOW_CLOSE_BUTTON) {
        return new Insets(insets.top, insets.left, insets.bottom, 3);
      }
    }

    return insets;
  }
예제 #7
0
  @Override
  public Dimension getPreferredSize() {
    final Dimension size = super.getPreferredSize();
    if (myActionPanel != null && !myActionPanel.isVisible()) {
      final Dimension actionPanelSize = myActionPanel.getPreferredSize();
      size.width += actionPanelSize.width;
    }

    final JBTabsPosition pos = myTabs.getTabsPosition();
    switch (pos) {
      case top:
      case bottom:
        size.height +=
            myTabs.isEditorTabs() ? TabsUtil.ACTIVE_TAB_UNDERLINE_HEIGHT : getSelectedOffset();
        break;
      case left:
      case right:
        size.width += getSelectedOffset();
        break;
    }

    return size;
  }
예제 #8
0
  public void doTranslate(PairConsumer<Integer, Integer> consumer) {
    final JBTabsPosition pos = myTabs.getTabsPosition();

    int dX = 0;
    int dXs = 0;
    int dY = 0;
    int dYs = 0;
    int selected = getSelectedOffset();
    int plain = getNonSelectedOffset();

    switch (pos) {
      case bottom:
        dY = -plain;
        dYs = -selected;
        break;
      case left:
        dX = plain;
        dXs = selected;
        break;
      case right:
        dX = -plain;
        dXs = -selected;
        break;
      case top:
        dY = plain;
        dYs = selected;
        break;
    }

    if (!myTabs.isDropTarget(myInfo)) {
      if (myTabs.getSelectedInfo() != myInfo) {
        consumer.consume(dX, dY);
      } else {
        consumer.consume(dXs, dYs);
      }
    }
  }
예제 #9
0
  public TabLabel(JBTabsImpl tabs, final TabInfo info) {
    super(false);

    myTabs = tabs;
    myInfo = info;
    myLabel.setOpaque(false);
    myLabel.setBorder(null);
    myLabel.setIconTextGap(tabs.isEditorTabs() ? 2 : new JLabel().getIconTextGap());
    myLabel.setIconOpaque(false);
    myLabel.setIpad(new Insets(0, 0, 0, 0));
    setOpaque(false);
    setLayout(new BorderLayout());

    myLabelPlaceholder.setOpaque(false);
    add(myLabelPlaceholder, BorderLayout.CENTER);

    setAlignmentToCenter(true);

    myIcon = new LayeredIcon(2);

    addMouseListener(
        new MouseAdapter() {
          public void mousePressed(final MouseEvent e) {
            if (JBTabsImpl.isSelectionClick(e, false) && myInfo.isEnabled()) {
              final TabInfo selectedInfo = myTabs.getSelectedInfo();
              if (selectedInfo != myInfo) {
                myInfo.setPreviousSelection(selectedInfo);
              }
              Component c =
                  SwingUtilities.getDeepestComponentAt(e.getComponent(), e.getX(), e.getY());
              if (c instanceof InplaceButton) return;
              myTabs.select(info, true);
            } else {
              handlePopup(e);
            }
          }

          public void mouseClicked(final MouseEvent e) {
            handlePopup(e);
          }

          public void mouseReleased(final MouseEvent e) {
            myInfo.setPreviousSelection(null);
            handlePopup(e);
          }
        });
  }
예제 #10
0
  private void invalidateIfNeeded() {
    if (myLabel.getRootPane() == null) return;

    Dimension d = myLabel.getSize();
    Dimension pref = myLabel.getPreferredSize();
    if (d != null && d.equals(pref)) {
      return;
    }

    setInactiveStateImage(null);

    myLabel.invalidate();

    if (myActionPanel != null) {
      myActionPanel.invalidate();
    }

    myTabs.revalidateAndRepaint(false);
  }
예제 #11
0
  public void setTabActions(ActionGroup group) {
    removeOldActionPanel();

    if (group == null) return;

    myActionPanel =
        new ActionPanel(
            myTabs,
            myInfo,
            new Pass<MouseEvent>() {
              public void pass(final MouseEvent event) {
                final MouseEvent me =
                    SwingUtilities.convertMouseEvent(event.getComponent(), event, TabLabel.this);
                processMouseEvent(me);
              }
            });

    toggleShowActions(false);

    add(myActionPanel, BorderLayout.EAST);

    myTabs.revalidateAndRepaint(false);
  }
예제 #12
0
 @Override
 public float getMinProportion(boolean first) {
   return Math.min(.5F, (float) JBTabsImpl.MIN_TAB_WIDTH / Math.max(1, myTabs.getWidth()));
 }
예제 #13
0
 protected int getSelectedOffset() {
   return myTabs.isEditorTabs() ? -(TabsUtil.ACTIVE_TAB_UNDERLINE_HEIGHT / 2) + 1 : 1;
 }