javax.swing.plaf.metal.MetalTabbedPaneUI Java Examples

The following examples show how to use javax.swing.plaf.metal.MetalTabbedPaneUI. 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
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
@Override public void mouseDragged(MouseEvent e) {
  Point tabPt = e.getPoint(); // e.getDragOrigin();
  if (Objects.nonNull(startPt) && startPt.distance(tabPt) > gestureMotionThreshold) {
    DnDTabbedPane src = (DnDTabbedPane) e.getComponent();
    TransferHandler th = src.getTransferHandler();
    // When a tab runs rotation occurs, a tab that is not the target is dragged.
    // pointed out by Arjen
    int idx = src.indexAtLocation(tabPt.x, tabPt.y);
    int selIdx = src.getSelectedIndex();
    boolean isRotateTabRuns = !(src.getUI() instanceof MetalTabbedPaneUI)
        && src.getTabLayoutPolicy() == JTabbedPane.WRAP_TAB_LAYOUT
        && idx != selIdx;
    dragTabIndex = isRotateTabRuns ? selIdx : idx;
    th.exportAsDrag(src, e, TransferHandler.MOVE);
    startPt = null;
  }
}
 
Example #2
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
@Override public void dragGestureRecognized(DragGestureEvent e) {
  Optional.ofNullable(e.getComponent())
      .filter(c -> c instanceof DnDTabbedPane).map(c -> (DnDTabbedPane) c)
      .filter(tabbedPane -> tabbedPane.getTabCount() > 1)
      .ifPresent(tabbedPane -> {
        Point tabPt = e.getDragOrigin();
        int idx = tabbedPane.indexAtLocation(tabPt.x, tabPt.y);
        int selIdx = tabbedPane.getSelectedIndex();
        // When a tab runs rotation occurs, a tab that is not the target is dragged.
        // pointed out by Arjen
        boolean isTabRunsRotated = !(tabbedPane.getUI() instanceof MetalTabbedPaneUI)
            && tabbedPane.getTabLayoutPolicy() == JTabbedPane.WRAP_TAB_LAYOUT
            && idx != selIdx;
        tabbedPane.dragTabIndex = isTabRunsRotated ? selIdx : idx;
        if (tabbedPane.dragTabIndex >= 0 && tabbedPane.isEnabledAt(tabbedPane.dragTabIndex)) {
          tabbedPane.initGlassPane(tabPt);
          try {
            e.startDrag(DragSource.DefaultMoveDrop, new TabTransferable(tabbedPane), new TabDragSourceListener());
          } catch (InvalidDnDOperationException ex) {
            throw new IllegalStateException(ex);
          }
        }
      });
}
 
Example #3
Source File: MainPanel.java    From java-swing-tips with MIT License 6 votes vote down vote up
@Override public void mouseDragged(MouseEvent e) {
  Point tabPt = e.getPoint(); // e.getDragOrigin();
  if (Objects.nonNull(startPt) && startPt.distance(tabPt) > gestureMotionThreshold) {
    DnDTabbedPane src = (DnDTabbedPane) e.getComponent();
    TransferHandler th = src.getTransferHandler();
    // When a tab runs rotation occurs, a tab that is not the target is dragged.
    // pointed out by Arjen
    int idx = src.indexAtLocation(tabPt.x, tabPt.y);
    int selIdx = src.getSelectedIndex();
    boolean isRotateTabRuns = !(src.getUI() instanceof MetalTabbedPaneUI)
        && src.getTabLayoutPolicy() == JTabbedPane.WRAP_TAB_LAYOUT
        && idx != selIdx;
    dragTabIndex = isRotateTabRuns ? selIdx : idx;
    th.exportAsDrag(src, e, TransferHandler.MOVE);
    RECT_LINE.setBounds(0, 0, 0, 0);
    src.getRootPane().getGlassPane().setVisible(true);
    src.updateTabDropLocation(new DnDTabbedPane.DropLocation(tabPt, -1), null, true);
    startPt = null;
  }
}
 
Example #4
Source File: CloseableTabbedPane.java    From SikuliX1 with MIT License 5 votes vote down vote up
public CloseableTabbedPane() {
  super();
  listenerList = new EventListenerList();
  addMouseListener(this);
  addMouseMotionListener(this);
  if (getUI() instanceof MetalTabbedPaneUI) {
    setUI(new CloseableMetalTabbedPaneUI(SwingUtilities.LEFT));
  }
  popMenuTab = new SikuliIDEPopUpMenu("POP_TAB", this);
  if (!popMenuTab.isValidMenu()) {
    popMenuTab = null;
  }
}
 
Example #5
Source File: CloseableTabbedPane.java    From ramus with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Initializes the <code>CloseableTabbedPane</code>
 *
 * @param horizontalTextPosition the horizontal position of the text (e.g.
 *                               SwingUtilities.TRAILING or SwingUtilities.LEFT)
 */
private void init(int horizontalTextPosition) {
    listenerList = new EventListenerList();
    addMouseListener(this);
    addMouseMotionListener(this);

    if (getUI() instanceof MetalTabbedPaneUI)
        setUI(new CloseableMetalTabbedPaneUI(horizontalTextPosition));
    else
        setUI(new CloseableTabbedPaneUI(horizontalTextPosition));
}