下面列出了怎么用javax.swing.plaf.metal.MetalTabbedPaneUI的API类实例代码及写法,或者点击链接到github查看源代码。
@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;
}
}
@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);
}
}
});
}
@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;
}
}
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;
}
}
/**
* 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));
}