Java Code Examples for javax.swing.plaf.metal.MetalTabbedPaneUI

The following examples show how to use javax.swing.plaf.metal.MetalTabbedPaneUI. 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
Source Project: java-swing-tips   Source File: MainPanel.java    License: 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 Project: java-swing-tips   Source File: MainPanel.java    License: 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 Project: java-swing-tips   Source File: MainPanel.java    License: 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 Project: SikuliX1   Source File: CloseableTabbedPane.java    License: 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 Project: ramus   Source File: CloseableTabbedPane.java    License: 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));
}