Java Code Examples for javax.swing.plaf.TabbedPaneUI#tabForCoordinate()

The following examples show how to use javax.swing.plaf.TabbedPaneUI#tabForCoordinate() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private void handlePopup( final MouseEvent e ) {
  final JTabbedPane reportEditorPane = getReportEditorPane();
  final TabbedPaneUI ui = reportEditorPane.getUI();
  final int tabIndex = ui.tabForCoordinate( reportEditorPane, e.getX(), e.getY() );
  final JPopupMenu popupMenu = new JPopupMenu();

  final CloseReportAction closeThisAction = new CloseReportAction( tabIndex );
  closeThisAction.setReportDesignerContext( getContext() );
  final CloseChildReportsAction closeChildsAction = new CloseChildReportsAction( tabIndex );
  closeChildsAction.setReportDesignerContext( getContext() );
  final CloseOtherReportsAction closeOthersAction = new CloseOtherReportsAction( tabIndex );
  closeOthersAction.setReportDesignerContext( getContext() );
  final CloseAllReportsAction closeAllAction = new CloseAllReportsAction();
  closeAllAction.setReportDesignerContext( getContext() );
  final CloseUnmodifiedReportsAction closeUnmodifiedReportsAction = new CloseUnmodifiedReportsAction();
  closeUnmodifiedReportsAction.setReportDesignerContext( getContext() );

  popupMenu.add( new JMenuItem( closeThisAction ) );
  popupMenu.addSeparator();
  popupMenu.add( new JMenuItem( closeChildsAction ) );
  popupMenu.add( new JMenuItem( closeUnmodifiedReportsAction ) );
  popupMenu.add( new JMenuItem( closeOthersAction ) );
  popupMenu.add( new JMenuItem( closeAllAction ) );
  popupMenu.show( reportEditorPane, e.getX(), e.getY() );
}
 
Example 2
Source Project: netbeans   File: MergeDialogComponent.java    License: Apache License 2.0 5 votes vote down vote up
/** Called when the seqeunce of mouse events should lead to actual
 *  showing of the popup menu. */
@Override
protected void showPopup(java.awt.event.MouseEvent mouseEvent) {
    TabbedPaneUI tabUI = mergeTabbedPane.getUI();
    int clickTab = tabUI.tabForCoordinate(mergeTabbedPane, mouseEvent.getX(), mouseEvent.getY());
    MergePanel panel = getSelectedMergePanel();
    if (panel == null) {
        return;
    }
    if (clickTab != -1) {
        //Click is on valid tab, not on empty area in tab
        showPopupMenu(createPopupMenu(panel), mouseEvent.getPoint(), mergeTabbedPane);
    }
}
 
Example 3
Source Project: workcraft   File: DockableWindow.java    License: MIT License 5 votes vote down vote up
@Override
public void mouseClicked(MouseEvent e) {
    if ((e.getButton() == MouseEvent.BUTTON2) && (e.getSource() instanceof  JTabbedPane)) {
        JTabbedPane tabbedPane = (JTabbedPane) e.getSource();
        TabbedPaneUI ui = tabbedPane.getUI();
        int tabIndex = ui.tabForCoordinate(tabbedPane, e.getX(), e.getY());
        DockingUtils.closeTab(tabbedPane, tabIndex);
    }
}
 
Example 4
Source Project: consulo   File: TabbedPaneContentUI.java    License: Apache License 2.0 5 votes vote down vote up
private void closeTabAt(int x, int y) {
  TabbedPaneUI ui = getUI();
  int index = ui.tabForCoordinate(this, x, y);
  if (index < 0 || !myManager.canCloseContents()) {
    return;
  }
  final Content content = myManager.getContent(index);
  if (content != null && content.isCloseable()) {
    myManager.removeContent(content, true);
  }
}
 
Example 5
Source Project: consulo   File: TabbedPaneContentUI.java    License: Apache License 2.0 5 votes vote down vote up
protected void processMouseEvent(MouseEvent e) {
  if (e.isPopupTrigger()) { // Popup doesn't activate clicked tab.
    showPopup(e.getX(), e.getY());
    return;
  }

  if (!e.isShiftDown() && (MouseEvent.BUTTON1_MASK & e.getModifiers()) > 0) { // RightClick without Shift modifiers just select tab
    if (MouseEvent.MOUSE_RELEASED == e.getID()) {
      TabbedPaneUI ui = getUI();
      int index = ui.tabForCoordinate(this, e.getX(), e.getY());
      if (index != -1) {
        setSelectedIndex(index);
      }
      hideMenu();
    }
  }
  else if (e.isShiftDown() && (MouseEvent.BUTTON1_MASK & e.getModifiers()) > 0) { // Shift+LeftClick closes the tab
    if (MouseEvent.MOUSE_RELEASED == e.getID()) {
      closeTabAt(e.getX(), e.getY());
      hideMenu();
    }
  }
  else if ((MouseEvent.BUTTON2_MASK & e.getModifiers()) > 0) { // MouseWheelClick closes the tab
    if (MouseEvent.MOUSE_RELEASED == e.getID()) {
      closeTabAt(e.getX(), e.getY());
      hideMenu();
    }
  }
  else if ((MouseEvent.BUTTON3_MASK & e.getModifiers()) > 0 && SystemInfo.isWindows) { // Right mouse button doesn't activate tab
  }
  else {
    super.processMouseEvent(e);
  }
}
 
Example 6
Source Project: consulo   File: TabbedPaneContentUI.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @return content at the specified location.  <code>x</code> and <code>y</code> are in
 * tabbed pane coordinate system. The method returns <code>null</code> if there is no contnt at the
 * specified location.
 */
private Content getContentAt(int x, int y) {
  TabbedPaneUI ui = getUI();
  int index = ui.tabForCoordinate(this, x, y);
  if (index < 0) {
    return null;
  }
  return myManager.getContent(index);
}