📄 tabbedpaneui.java
字号:
case EAST :
selectNextTabInRun(current);
break;
case WEST :
selectPreviousTabInRun(current);
break;
default :
}
}
}
protected void selectNextTabInRun(int current)
{
int tabCount= tabPane.getTabCount();
int tabIndex= getNextTabIndexInRun(tabCount, current);
while (tabIndex != current && !tabPane.isEnabledAt(tabIndex))
{
tabIndex= getNextTabIndexInRun(tabCount, tabIndex);
}
tabPane.setSelectedIndex(tabIndex);
}
protected void selectPreviousTabInRun(int current)
{
int tabCount= tabPane.getTabCount();
int tabIndex= getPreviousTabIndexInRun(tabCount, current);
while (tabIndex != current && !tabPane.isEnabledAt(tabIndex))
{
tabIndex= getPreviousTabIndexInRun(tabCount, tabIndex);
}
tabPane.setSelectedIndex(tabIndex);
}
protected void selectNextTab(int current)
{
int tabIndex= getNextTabIndex(current);
while (tabIndex != current && !tabPane.isEnabledAt(tabIndex))
{
tabIndex= getNextTabIndex(tabIndex);
}
tabPane.setSelectedIndex(tabIndex);
}
protected void selectPreviousTab(int current)
{
int tabIndex= getPreviousTabIndex(current);
while (tabIndex != current && !tabPane.isEnabledAt(tabIndex))
{
tabIndex= getPreviousTabIndex(tabIndex);
}
tabPane.setSelectedIndex(tabIndex);
}
protected void selectAdjacentRunTab(
int tabPlacement,
int tabIndex,
int offset)
{
if (runCount < 2)
{
return;
}
int newIndex;
Rectangle r= rects[tabIndex];
switch (tabPlacement)
{
case LEFT :
case RIGHT :
newIndex=
getTabAtLocation(r.x + r.width / 2 + offset, r.y + r.height / 2);
break;
case BOTTOM :
case TOP :
default :
newIndex=
getTabAtLocation(r.x + r.width / 2, r.y + r.height / 2 + offset);
}
if (newIndex != -1)
{
while (!tabPane.isEnabledAt(newIndex) && newIndex != tabIndex)
{
newIndex= getNextTabIndex(newIndex);
}
tabPane.setSelectedIndex(newIndex);
}
}
protected int getTabRunOffset(
int tabPlacement,
int tabCount,
int tabIndex,
boolean forward)
{
int run= getRunForTab(tabCount, tabIndex);
int offset;
switch (tabPlacement)
{
case LEFT :
{
if (run == 0)
{
offset=
(forward
? - (
calculateTabAreaWidth(
tabPlacement,
runCount,
maxTabWidth)
- maxTabWidth)
: -maxTabWidth);
}
else if (run == runCount - 1)
{
offset=
(forward
? maxTabWidth
: calculateTabAreaWidth(
tabPlacement,
runCount,
maxTabWidth)
- maxTabWidth);
}
else
{
offset= (forward ? maxTabWidth : -maxTabWidth);
}
break;
}
case RIGHT :
{
if (run == 0)
{
offset=
(forward
? maxTabWidth
: calculateTabAreaWidth(
tabPlacement,
runCount,
maxTabWidth)
- maxTabWidth);
}
else if (run == runCount - 1)
{
offset=
(forward
? - (
calculateTabAreaWidth(
tabPlacement,
runCount,
maxTabWidth)
- maxTabWidth)
: -maxTabWidth);
}
else
{
offset= (forward ? maxTabWidth : -maxTabWidth);
}
break;
}
case BOTTOM :
{
if (run == 0)
{
offset=
(forward
? maxTabHeight
: calculateTabAreaHeight(
tabPlacement,
runCount,
maxTabHeight)
- maxTabHeight);
}
else if (run == runCount - 1)
{
offset=
(forward
? - (
calculateTabAreaHeight(
tabPlacement,
runCount,
maxTabHeight)
- maxTabHeight)
: -maxTabHeight);
}
else
{
offset= (forward ? maxTabHeight : -maxTabHeight);
}
break;
}
case TOP :
default :
{
if (run == 0)
{
offset=
(forward
? - (
calculateTabAreaHeight(
tabPlacement,
runCount,
maxTabHeight)
- maxTabHeight)
: -maxTabHeight);
}
else if (run == runCount - 1)
{
offset=
(forward
? maxTabHeight
: calculateTabAreaHeight(
tabPlacement,
runCount,
maxTabHeight)
- maxTabHeight);
}
else
{
offset= (forward ? maxTabHeight : -maxTabHeight);
}
}
}
return offset;
}
protected int getPreviousTabIndex(int base)
{
int tabIndex= (base - 1 >= 0 ? base - 1 : tabPane.getTabCount() - 1);
return (tabIndex >= 0 ? tabIndex : 0);
}
protected int getNextTabIndex(int base)
{
return (base + 1) % tabPane.getTabCount();
}
protected int getNextTabIndexInRun(int tabCount, int base)
{
if (runCount < 2)
{
return getNextTabIndex(base);
}
int currentRun= getRunForTab(tabCount, base);
int next= getNextTabIndex(base);
if (next == tabRuns[getNextTabRun(currentRun)])
{
return tabRuns[currentRun];
}
return next;
}
protected int getPreviousTabIndexInRun(int tabCount, int base)
{
if (runCount < 2)
{
return getPreviousTabIndex(base);
}
int currentRun= getRunForTab(tabCount, base);
if (base == tabRuns[currentRun])
{
int previous= tabRuns[getNextTabRun(currentRun)] - 1;
return (previous != -1 ? previous : tabCount - 1);
}
return getPreviousTabIndex(base);
}
protected int getPreviousTabRun(int baseRun)
{
int runIndex= (baseRun - 1 >= 0 ? baseRun - 1 : runCount - 1);
return (runIndex >= 0 ? runIndex : 0);
}
protected int getNextTabRun(int baseRun)
{
return (baseRun + 1) % runCount;
}
protected static void rotateInsets(
Insets topInsets,
Insets targetInsets,
int targetPlacement)
{
switch (targetPlacement)
{
case LEFT :
targetInsets.top= topInsets.left;
targetInsets.left= topInsets.top;
targetInsets.bottom= topInsets.right;
targetInsets.right= topInsets.bottom;
break;
case BOTTOM :
targetInsets.top= topInsets.bottom;
targetInsets.left= topInsets.left;
targetInsets.bottom= topInsets.top;
targetInsets.right= topInsets.right;
break;
case RIGHT :
targetInsets.top= topInsets.left;
targetInsets.left= topInsets.bottom;
targetInsets.bottom= topInsets.right;
targetInsets.right= topInsets.top;
break;
case TOP :
default :
targetInsets.top= topInsets.top;
targetInsets.left= topInsets.left;
targetInsets.bottom= topInsets.bottom;
targetInsets.right= topInsets.right;
}
}
// REMIND(aim,7/29/98): This method should be made
// protected in the next release where
// API changes are allowed
//
boolean requestMyFocusForVisibleComponent()
{
Component visibleComponent= getVisibleComponent();
if (visibleComponent.isFocusTraversable())
{
visibleComponent.requestFocus();
return true;
}
else if (visibleComponent instanceof JComponent)
{
if (((JComponent) visibleComponent).requestDefaultFocus())
{
return true;
}
}
return false;
}
private static class RightAction extends AbstractAction
{
public void actionPerformed(ActionEvent e)
{
JTabbedPane pane= (JTabbedPane) e.getSource();
TabbedPaneUI ui= (TabbedPaneUI) pane.getUI();
ui.navigateSelectedTab(EAST);
}
};
private static class LeftAction extends AbstractAction
{
public void actionPerformed(ActionEvent e)
{
JTabbedPane pane= (JTabbedPane) e.getSource();
TabbedPaneUI ui= (TabbedPaneUI) pane.getUI();
ui.navigateSelectedTab(WEST);
}
};
private static class UpAction extends AbstractAction
{
public void actionPerformed(ActionEvent e)
{
JTabbedPane pane= (JTabbedPane) e.getSource();
TabbedPaneUI ui= (TabbedPaneUI) pane.getUI();
ui.navigateSelectedTab(NORTH);
}
};
private static class DownAction extends AbstractAction
{
public void actionPerformed(ActionEvent e)
{
JTabbedPane pane= (JTabbedPane) e.getSource();
TabbedPaneUI ui= (TabbedPaneUI) pane.getUI();
ui.navigateSelectedTab(SOUTH);
}
};
private static class NextAction extends AbstractAction
{
public void actionPerformed(ActionEvent e)
{
JTabbedPane pane= (JTabbedPane) e.getSource();
TabbedPaneUI ui= (TabbedPaneUI) pane.getUI();
ui.navigateSelectedTab(NEXT);
}
};
private static class PreviousAction extends AbstractAction
{
public void actionPerformed(ActionEvent e)
{
JTabbedPane pane= (JTabbedPane) e.getSource();
TabbedPaneUI ui= (TabbedPaneUI) pane.getUI();
ui.navigateSelectedTab(PREVIOUS);
}
};
private static class PageUpAction extends AbstractAction
{
public void actionPerformed(ActionEvent e)
{
JTabbedPane pane= (JTabbedPane) e.getSource();
TabbedPaneUI ui= (TabbedPaneUI) pane.getUI();
int tabPlacement= pane.getTabPlacement();
if (tabPlacement == TOP || tabPlacement == BOTTOM)
{
ui.navigateSelectedTab(WEST);
}
else
{
ui.navigateSelectedTab(NORTH);
}
}
};
private static class PageDownAction extends AbstractAction
{
public void actionPerformed(ActionEvent e)
{
JTabbedPane pane= (JTabbedPane) e.getSource();
TabbedPaneUI ui= (TabbedPaneUI) pane.getUI();
int tabPlacement= pane.getTabPlacement();
if (tabPlacement == TOP || tabPlacement == BOTTOM)
{
ui.navigateSelectedTab(EAST);
}
else
{
ui.navigateSelectedTab(SOUTH);
}
}
};
private static class RequestFocusAction extends AbstractAction
{
public void actionPerformed(ActionEvent e)
{
JTabbedPane pane= (JTabbedPane) e.getSource();
pane.requestFocus();
}
};
private static class RequestFocusForVisibleAction extends AbstractAction
{
public void actionPerformed(ActionEvent e)
{
JTabbedPane pane= (JTabbedPane) e.getSource();
TabbedPaneUI ui= (TabbedPaneUI) pane.getUI();
ui.requestMyFocusForVisibleComponent();
}
};
/**
* Selects a tab in the JTabbedPane based on the String of the
* action command. The tab selected is based on the first tab that
* has a mnemonic matching the first character of the action command.
*/
private static class SetSelectedIndexAction extends AbstractAction
{
public void actionPerformed(ActionEvent e)
{
JTabbedPane pane= (JTabbedPane) e.getSource();
if (pane != null && (pane.getUI() instanceof BasicTabbedPaneUI))
{
TabbedPaneUI ui= (TabbedPaneUI) pane.getUI();
String command= e.getActionCommand();
if (command != null && command.length() > 0)
{
int mnemonic= (int) e.getActionCommand().charAt(0);
if (mnemonic >= 'a' && mnemonic <= 'z')
{
mnemonic -= ('a' - 'A');
}
Integer index=
(Integer) ui.mnemonicToIndexMap.get(new Integer(mnemonic));
if (index != null)
{
pane.setSelectedIndex(index.intValue());
}
}
}
}
};
private static class ScrollTabsForwardAction extends AbstractAction
{
public void actionPerformed(ActionEvent e)
{
JTabbedPane pane= null;
Object src= e.getSource();
if (src instanceof JTabbedPane)
{
pane= (JTabbedPane) src;
}
else if (src instanceof ScrollableTabButton)
{
pane= (JTabbedPane) ((ScrollableTabButton) src).getParent();
}
else
{
return; // shouldn't happen
}
TabbedPaneUI ui= (TabbedPaneUI) pane.getUI();
if (ui.scrollableTabLayoutEnabled())
{
ui.tabScroller.scrollForward(pane.getTabPlacement());
}
}
}
private static class ScrollTabsBackwardAction extends AbstractAction
{
public void actionPerformed
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -