< prev index next >
src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java
Print this page
@@ -54,26 +54,37 @@
public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants {
// Instance variables initialized at installation
+ /** The tab pane */
protected JTabbedPane tabPane;
+ /** Highlight color */
protected Color highlight;
+ /** Light highlight color */
protected Color lightHighlight;
+ /** Shadow color */
protected Color shadow;
+ /** Dark shadow color */
protected Color darkShadow;
+ /** Focus color */
protected Color focus;
private Color selectedColor;
+ /** Text icon gap */
protected int textIconGap;
-
+ /** Tab run overlay */
protected int tabRunOverlay;
+ /** Tab insets */
protected Insets tabInsets;
+ /** Selected tab insets */
protected Insets selectedTabPadInsets;
+ /** Tab area insets */
protected Insets tabAreaInsets;
+ /** Content border insets */
protected Insets contentBorderInsets;
private boolean tabsOverlapBorder;
private boolean tabsOpaque = true;
private boolean contentOpaque = true;
@@ -118,23 +129,32 @@
@Deprecated
protected KeyStroke rightKey;
// Transient variables (recalculated each time TabbedPane is layed out)
-
+ /** Tab runs */
protected int tabRuns[] = new int[10];
+ /** Run count */
protected int runCount = 0;
+ /** Selected run */
protected int selectedRun = -1;
+ /** Tab rects */
protected Rectangle rects[] = new Rectangle[0];
+ /** Maximum tab height */
protected int maxTabHeight;
+ /** Maximum tab width */
protected int maxTabWidth;
// Listeners
+ /** Tab change listener */
protected ChangeListener tabChangeListener;
+ /** Property change listener */
protected PropertyChangeListener propertyChangeListener;
+ /** Mouse change listener */
protected MouseListener mouseListener;
+ /** Focus change listener */
protected FocusListener focusListener;
// Private instance data
private Insets currentPadInsets = new Insets(0,0,0,0);
@@ -188,10 +208,15 @@
private boolean calculatedBaseline;
private int baseline;
// UI creation
+ /**
+ * Create a UI.
+ * @param c a component
+ * @return a UI
+ */
public static ComponentUI createUI(JComponent c) {
return new BasicTabbedPaneUI();
}
static void loadActionMap(LazyActionMap map) {
@@ -353,10 +378,13 @@
tabPane.remove(tabContainer);
}
tabContainer = null;
}
+ /**
+ * Install the defaults.
+ */
protected void installDefaults() {
LookAndFeel.installColorsAndFont(tabPane, "TabbedPane.background",
"TabbedPane.foreground", "TabbedPane.font");
highlight = UIManager.getColor("TabbedPane.light");
lightHighlight = UIManager.getColor("TabbedPane.highlight");
@@ -387,10 +415,13 @@
if (selectedTabPadInsets == null) selectedTabPadInsets = new Insets(2,2,2,1);
if (tabAreaInsets == null) tabAreaInsets = new Insets(3,2,0,2);
if (contentBorderInsets == null) contentBorderInsets = new Insets(2,2,3,3);
}
+ /**
+ * Uninstall the defaults.
+ */
protected void uninstallDefaults() {
highlight = null;
lightHighlight = null;
shadow = null;
darkShadow = null;
@@ -399,10 +430,13 @@
selectedTabPadInsets = null;
tabAreaInsets = null;
contentBorderInsets = null;
}
+ /**
+ * Install the listeners.
+ */
protected void installListeners() {
if ((propertyChangeListener = createPropertyChangeListener()) != null) {
tabPane.addPropertyChangeListener(propertyChangeListener);
}
if ((tabChangeListener = createChangeListener()) != null) {
@@ -419,10 +453,13 @@
if (tabPane.getTabCount()>0) {
htmlViews = createHTMLVector();
}
}
+ /**
+ * Uninstall the listeners.
+ */
protected void uninstallListeners() {
if (mouseListener != null) {
tabPane.removeMouseListener(mouseListener);
mouseListener = null;
}
@@ -446,22 +483,38 @@
propertyChangeListener = null;
}
handler = null;
}
+ /**
+ * Creates a mouse listener.
+ * @return a mouse listener
+ */
protected MouseListener createMouseListener() {
return getHandler();
}
+ /**
+ * Creates a focus listener.
+ * @return a focus listener
+ */
protected FocusListener createFocusListener() {
return getHandler();
}
+ /**
+ * Creates a change listener.
+ * @return a change listener
+ */
protected ChangeListener createChangeListener() {
return getHandler();
}
+ /**
+ * Creates a property change listener.
+ * @return a property change listener
+ */
protected PropertyChangeListener createPropertyChangeListener() {
return getHandler();
}
private Handler getHandler() {
@@ -469,10 +522,13 @@
handler = new Handler();
}
return handler;
}
+ /**
+ * Installs the keyboard actions.
+ */
protected void installKeyboardActions() {
InputMap km = getInputMap(JComponent.
WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
SwingUtilities.replaceUIInputMap(tabPane, JComponent.
@@ -496,10 +552,13 @@
"TabbedPane.focusInputMap");
}
return null;
}
+ /**
+ * Uninstalls the keyboard actions.
+ */
protected void uninstallKeyboardActions() {
SwingUtilities.replaceUIActionMap(tabPane, null);
SwingUtilities.replaceUIInputMap(tabPane, JComponent.
WHEN_ANCESTOR_OF_FOCUSED_COMPONENT,
null);
@@ -842,10 +901,19 @@
if (selectedIndex >= 0 && rects[selectedIndex].intersects(clipRect)) {
paintTab(g, tabPlacement, rects, selectedIndex, iconRect, textRect);
}
}
+ /**
+ * Paints a tab.
+ * @param g the graphics
+ * @param tabPlacement the tab placement
+ * @param rects rectangles
+ * @param tabIndex the tab index
+ * @param iconRect the icon rectangle
+ * @param textRect the text rectangle
+ */
protected void paintTab(Graphics g, int tabPlacement,
Rectangle[] rects, int tabIndex,
Rectangle iconRect, Rectangle textRect) {
Rectangle tabRect = rects[tabIndex];
int selectedIndex = tabPane.getSelectedIndex();
@@ -1010,10 +1078,22 @@
yy+=CROP_SEGMENT;
}
}
}
+ /**
+ * Laysout a label.
+ * @param tabPlacement the tab placement
+ * @param metrics the font metric
+ * @param tabIndex the tab index
+ * @param title the title
+ * @param icon the icon
+ * @param tabRect the tab rectangle
+ * @param iconRect the icon rectangle
+ * @param textRect the text rectangle
+ * @param isSelected selection status
+ */
protected void layoutLabel(int tabPlacement,
FontMetrics metrics, int tabIndex,
String title, Icon icon,
Rectangle tabRect, Rectangle iconRect,
Rectangle textRect, boolean isSelected ) {
@@ -1043,18 +1123,38 @@
iconRect.y += yNudge;
textRect.x += xNudge;
textRect.y += yNudge;
}
+ /**
+ * Paints an icon.
+ * @param g the graphics
+ * @param tabPlacement the tab placement
+ * @param tabIndex the tab index
+ * @param icon the icon
+ * @param iconRect the icon rectangle
+ * @param isSelected selection status
+ */
protected void paintIcon(Graphics g, int tabPlacement,
int tabIndex, Icon icon, Rectangle iconRect,
boolean isSelected ) {
if (icon != null) {
icon.paintIcon(tabPane, g, iconRect.x, iconRect.y);
}
}
+ /**
+ * Paints text.
+ * @param g the graphics
+ * @param tabPlacement the tab placement
+ * @param font the font
+ * @param metrics the font metrics
+ * @param tabIndex the tab index
+ * @param title the title
+ * @param textRect the text rectangle
+ * @param isSelected selection status
+ */
protected void paintText(Graphics g, int tabPlacement,
Font font, FontMetrics metrics, int tabIndex,
String title, Rectangle textRect,
boolean isSelected) {
@@ -1094,11 +1194,17 @@
}
}
}
-
+ /**
+ * Returns the tab label shift x.
+ * @param tabPlacement the tab placement
+ * @param tabIndex the tab index
+ * @param isSelected selection status
+ * @return the tab label shift x
+ */
protected int getTabLabelShiftX(int tabPlacement, int tabIndex, boolean isSelected) {
Rectangle tabRect = rects[tabIndex];
String propKey = (isSelected ? "selectedLabelShift" : "labelShift");
int nudge = DefaultLookup.getInt(
tabPane, this, "TabbedPane." + propKey, 1);
@@ -1113,10 +1219,17 @@
default:
return tabRect.width % 2;
}
}
+ /**
+ * Returns the tab label shift y.
+ * @param tabPlacement the tab placement
+ * @param tabIndex the tab index
+ * @param isSelected selection status
+ * @return the tab label shift y
+ */
protected int getTabLabelShiftY(int tabPlacement, int tabIndex, boolean isSelected) {
Rectangle tabRect = rects[tabIndex];
int nudge = (isSelected ? DefaultLookup.getInt(tabPane, this, "TabbedPane.selectedLabelShift", -1) :
DefaultLookup.getInt(tabPane, this, "TabbedPane.labelShift", 1));
@@ -1130,10 +1243,20 @@
default:
return nudge;
}
}
+ /**
+ * Paints the focus indicator.
+ * @param g the graphics
+ * @param tabPlacement the tab placement
+ * @param rects rectangles
+ * @param tabIndex the tab index
+ * @param iconRect the icon rectangle
+ * @param textRect the text rectangle
+ * @param isSelected selection status
+ */
protected void paintFocusIndicator(Graphics g, int tabPlacement,
Rectangle[] rects, int tabIndex,
Rectangle iconRect, Rectangle textRect,
boolean isSelected) {
Rectangle tabRect = rects[tabIndex];
@@ -1243,10 +1366,22 @@
g.drawLine(x+w-1, y+2, x+w-1, y+h-1); // right dark-shadow
g.drawLine(x+w-2, y+1, x+w-2, y+1); // top-right shadow
}
}
+ /**
+ * Paints the tab background.
+ * @param g the graphics context in which to paint
+ * @param tabPlacement the placement (left, right, bottom, top) of the tab
+ * @param tabIndex the index of the tab with respect to other tabs
+ * @param x the x coordinate of tab
+ * @param y the y coordinate of tab
+ * @param w the width of the tab
+ * @param h the height of the tab
+ * @param isSelected a {@code boolean} which determines whether or not
+ * the tab is selected
+ */
protected void paintTabBackground(Graphics g, int tabPlacement,
int tabIndex,
int x, int y, int w, int h,
boolean isSelected ) {
g.setColor(!isSelected || selectedColor == null?
@@ -1265,10 +1400,16 @@
default:
g.fillRect(x+1, y+1, w-3, h-1);
}
}
+ /**
+ * Paints the content border.
+ * @param g the graphics context in which to paint
+ * @param tabPlacement the placement (left, right, bottom, top) of the tab
+ * @param selectedIndex the tab index of the selected component
+ */
protected void paintContentBorder(Graphics g, int tabPlacement, int selectedIndex) {
int width = tabPane.getWidth();
int height = tabPane.getHeight();
Insets insets = tabPane.getInsets();
Insets tabAreaInsets = getTabAreaInsets(tabPlacement);
@@ -1327,10 +1468,20 @@
paintContentBorderBottomEdge(g, tabPlacement, selectedIndex, x, y, w, h);
paintContentBorderRightEdge(g, tabPlacement, selectedIndex, x, y, w, h);
}
+ /**
+ * Paints the content border top edge.
+ * @param g the graphics context in which to paint
+ * @param tabPlacement the placement (left, right, bottom, top) of the tab
+ * @param selectedIndex the tab index of the selected component
+ * @param x the x coordinate of tab
+ * @param y the y coordinate of tab
+ * @param w the width of the tab
+ * @param h the height of the tab
+ */
protected void paintContentBorderTopEdge(Graphics g, int tabPlacement,
int selectedIndex,
int x, int y, int w, int h) {
Rectangle selRect = selectedIndex < 0? null :
getTabBounds(selectedIndex, calcRect);
@@ -1356,10 +1507,20 @@
g.drawLine(x+w-2, y, x+w-2, y);
}
}
}
+ /**
+ * Paints the content border left edge.
+ * @param g the graphics context in which to paint
+ * @param tabPlacement the placement (left, right, bottom, top) of the tab
+ * @param selectedIndex the tab index of the selected component
+ * @param x the x coordinate of tab
+ * @param y the y coordinate of tab
+ * @param w the width of the tab
+ * @param h the height of the tab
+ */
protected void paintContentBorderLeftEdge(Graphics g, int tabPlacement,
int selectedIndex,
int x, int y, int w, int h) {
Rectangle selRect = selectedIndex < 0? null :
getTabBounds(selectedIndex, calcRect);
@@ -1382,10 +1543,20 @@
x, y+h-2);
}
}
}
+ /**
+ * Paints the content border bottom edge.
+ * @param g the graphics context in which to paint
+ * @param tabPlacement the placement (left, right, bottom, top) of the tab
+ * @param selectedIndex the tab index of the selected component
+ * @param x the x coordinate of tab
+ * @param y the y coordinate of tab
+ * @param w the width of the tab
+ * @param h the height of the tab
+ */
protected void paintContentBorderBottomEdge(Graphics g, int tabPlacement,
int selectedIndex,
int x, int y, int w, int h) {
Rectangle selRect = selectedIndex < 0? null :
getTabBounds(selectedIndex, calcRect);
@@ -1415,10 +1586,20 @@
}
}
}
+ /**
+ * Paints the content border right edge.
+ * @param g the graphics context in which to paint
+ * @param tabPlacement the placement (left, right, bottom, top) of the tab
+ * @param selectedIndex the tab index of the selected component
+ * @param x the x coordinate of tab
+ * @param y the y coordinate of tab
+ * @param w the width of the tab
+ * @param h the height of the tab
+ */
protected void paintContentBorderRightEdge(Graphics g, int tabPlacement,
int selectedIndex,
int x, int y, int w, int h) {
Rectangle selRect = selectedIndex < 0? null :
getTabBounds(selectedIndex, calcRect);
@@ -1616,14 +1797,22 @@
return dest;
}
// BasicTabbedPaneUI methods
+ /**
+ * Returns the visible component.
+ * @return the visible component
+ */
protected Component getVisibleComponent() {
return visibleComponent;
}
+ /**
+ * Sets the visible component.
+ * @param component the component
+ */
protected void setVisibleComponent(Component component) {
if (visibleComponent != null
&& visibleComponent != component
&& visibleComponent.getParent() == tabPane
&& visibleComponent.isVisible()) {
@@ -1634,10 +1823,14 @@
component.setVisible(true);
}
visibleComponent = component;
}
+ /**
+ * Assure the rectangles are created.
+ * @param tabCount the tab count
+ */
protected void assureRectsCreated(int tabCount) {
int rectArrayLen = rects.length;
if (tabCount != rectArrayLen ) {
Rectangle[] tempRectArray = new Rectangle[tabCount];
System.arraycopy(rects, 0, tempRectArray, 0,
@@ -1648,17 +1841,26 @@
}
}
}
+ /**
+ * Expands the tab runs array.
+ */
protected void expandTabRunsArray() {
int rectLen = tabRuns.length;
int[] newArray = new int[rectLen+10];
System.arraycopy(tabRuns, 0, newArray, 0, runCount);
tabRuns = newArray;
}
+ /**
+ * Returns the run for a tab.
+ * @param tabCount the tab count
+ * @param tabIndex the tab index.
+ * @return the run for a tab
+ */
protected int getRunForTab(int tabCount, int tabIndex) {
for (int i = 0; i < runCount; i++) {
int first = tabRuns[i];
int last = lastTabInRun(tabCount, i);
if (tabIndex >= first && tabIndex <= last) {
@@ -1666,10 +1868,16 @@
}
}
return 0;
}
+ /**
+ * Returns the last tab in a run.
+ * @param tabCount the tab count
+ * @param run the run
+ * @return the last tab in a run
+ */
protected int lastTabInRun(int tabCount, int run) {
if (runCount == 1) {
return tabCount - 1;
}
int nextRun = (run == runCount - 1? 0 : run + 1);
@@ -1677,26 +1885,53 @@
return tabCount - 1;
}
return tabRuns[nextRun]-1;
}
+ /**
+ * Returns the tab run overlay.
+ * @param tabPlacement the placement (left, right, bottom, top) of the tab
+ * @return the tab run overlay
+ */
protected int getTabRunOverlay(int tabPlacement) {
return tabRunOverlay;
}
+ /**
+ * Returns the tab run indent.
+ * @param tabPlacement the placement (left, right, bottom, top) of the tab
+ * @param run the tab run
+ * @return the tab run indent
+ */
protected int getTabRunIndent(int tabPlacement, int run) {
return 0;
}
+ /**
+ * Returns whether or not the tab run should be padded.
+ * @param tabPlacement the placement (left, right, bottom, top) of the tab
+ * @param run the tab run
+ * @return whether or not the tab run should be padded
+ */
protected boolean shouldPadTabRun(int tabPlacement, int run) {
return runCount > 1;
}
+ /**
+ * Returns whether or not the tab run should be rotated.
+ * @param tabPlacement the placement (left, right, bottom, top) of the tab
+ * @return whether or not the tab run should be rotated
+ */
protected boolean shouldRotateTabRuns(int tabPlacement) {
return true;
}
+ /**
+ * Returns the icon for a tab.
+ * @param tabIndex the index of the tab
+ * @return the icon for a tab
+ */
protected Icon getIconForTab(int tabIndex) {
return (!tabPane.isEnabled() || !tabPane.isEnabledAt(tabIndex))?
tabPane.getDisabledIconAt(tabIndex) : tabPane.getIconAt(tabIndex);
}
@@ -1716,10 +1951,17 @@
return htmlViews.elementAt(tabIndex);
}
return null;
}
+ /**
+ * Calculates the tab height.
+ * @param tabPlacement the placement (left, right, bottom, top) of the tab
+ * @param tabIndex the index of the tab with respect to other tabs
+ * @param fontHeight the font height
+ * @return the tab height
+ */
protected int calculateTabHeight(int tabPlacement, int tabIndex, int fontHeight) {
int height = 0;
Component c = tabPane.getTabComponentAt(tabIndex);
if (c != null) {
height = c.getPreferredSize().height;
@@ -1741,10 +1983,15 @@
Insets tabInsets = getTabInsets(tabPlacement, tabIndex);
height += tabInsets.top + tabInsets.bottom + 2;
return height;
}
+ /**
+ * Calculates the maximum tab height.
+ * @param tabPlacement the placement (left, right, bottom, top) of the tab
+ * @return the maximum tab height
+ */
protected int calculateMaxTabHeight(int tabPlacement) {
FontMetrics metrics = getFontMetrics();
int tabCount = tabPane.getTabCount();
int result = 0;
int fontHeight = metrics.getHeight();
@@ -1752,10 +1999,17 @@
result = Math.max(calculateTabHeight(tabPlacement, i, fontHeight), result);
}
return result;
}
+ /**
+ * Calculates the tab width.
+ * @param tabPlacement the placement (left, right, bottom, top) of the tab
+ * @param tabIndex the index of the tab with respect to other tabs
+ * @param metrics the font metrics
+ * @return the tab width
+ */
protected int calculateTabWidth(int tabPlacement, int tabIndex, FontMetrics metrics) {
Insets tabInsets = getTabInsets(tabPlacement, tabIndex);
int width = tabInsets.left + tabInsets.right + 3;
Component tabComponent = tabPane.getTabComponentAt(tabIndex);
if (tabComponent != null) {
@@ -1776,64 +2030,112 @@
}
}
return width;
}
+ /**
+ * Calculates the maximum tab width.
+ * @param tabPlacement the placement (left, right, bottom, top) of the tab
+ * @return the maximum tab width
+ */
protected int calculateMaxTabWidth(int tabPlacement) {
FontMetrics metrics = getFontMetrics();
int tabCount = tabPane.getTabCount();
int result = 0;
for(int i = 0; i < tabCount; i++) {
result = Math.max(calculateTabWidth(tabPlacement, i, metrics), result);
}
return result;
}
+ /**
+ * Calculates the tab area height.
+ * @param tabPlacement the placement (left, right, bottom, top) of the tab
+ * @param horizRunCount horizontal run count
+ * @param maxTabHeight maximum tab height
+ * @return the tab area height
+ */
protected int calculateTabAreaHeight(int tabPlacement, int horizRunCount, int maxTabHeight) {
Insets tabAreaInsets = getTabAreaInsets(tabPlacement);
int tabRunOverlay = getTabRunOverlay(tabPlacement);
return (horizRunCount > 0?
horizRunCount * (maxTabHeight-tabRunOverlay) + tabRunOverlay +
tabAreaInsets.top + tabAreaInsets.bottom :
0);
}
+ /**
+ * Calculates the tab area width.
+ * @param tabPlacement the placement (left, right, bottom, top) of the tab
+ * @param vertRunCount vertical run count
+ * @param maxTabWidth maximum tab width
+ * @return the tab area width
+ */
protected int calculateTabAreaWidth(int tabPlacement, int vertRunCount, int maxTabWidth) {
Insets tabAreaInsets = getTabAreaInsets(tabPlacement);
int tabRunOverlay = getTabRunOverlay(tabPlacement);
return (vertRunCount > 0?
vertRunCount * (maxTabWidth-tabRunOverlay) + tabRunOverlay +
tabAreaInsets.left + tabAreaInsets.right :
0);
}
+ /**
+ * Returns the tab insets.
+ * @param tabPlacement the placement (left, right, bottom, top) of the tab
+ * @param tabIndex the tab index
+ * @return the tab insets
+ */
protected Insets getTabInsets(int tabPlacement, int tabIndex) {
return tabInsets;
}
+ /**
+ * Returns the selected tab pad insets.
+ * @param tabPlacement the placement (left, right, bottom, top) of the tab
+ * @return the selected tab pad insets
+ */
protected Insets getSelectedTabPadInsets(int tabPlacement) {
rotateInsets(selectedTabPadInsets, currentPadInsets, tabPlacement);
return currentPadInsets;
}
+ /**
+ * Returns the tab area insets.
+ * @param tabPlacement the placement (left, right, bottom, top) of the tab
+ * @return the pad area insets
+ */
protected Insets getTabAreaInsets(int tabPlacement) {
rotateInsets(tabAreaInsets, currentTabAreaInsets, tabPlacement);
return currentTabAreaInsets;
}
+ /**
+ * Returns the content border insets.
+ * @param tabPlacement the placement (left, right, bottom, top) of the tab
+ * @return the content border insets
+ */
protected Insets getContentBorderInsets(int tabPlacement) {
return contentBorderInsets;
}
+ /**
+ * Returns the font metrics.
+ * @return the font metrics
+ */
protected FontMetrics getFontMetrics() {
Font font = tabPane.getFont();
return tabPane.getFontMetrics(font);
}
// Tab Navigation methods
+ /**
+ * Navigate the selected tab.
+ * @param direction the direction
+ */
protected void navigateSelectedTab(int direction) {
int tabPlacement = tabPane.getTabPlacement();
int current = DefaultLookup.getBoolean(tabPane, this,
"TabbedPane.selectionFollowsFocus", true) ?
tabPane.getSelectedIndex() : getFocusIndex();
@@ -1908,48 +2210,70 @@
default:
}
}
}
+ /**
+ * Select the next tab in the run.
+ * @param current the current tab
+ */
protected void selectNextTabInRun(int current) {
int tabCount = tabPane.getTabCount();
int tabIndex = getNextTabIndexInRun(tabCount, current);
while(tabIndex != current && !tabPane.isEnabledAt(tabIndex)) {
tabIndex = getNextTabIndexInRun(tabCount, tabIndex);
}
navigateTo(tabIndex);
}
+ /**
+ * Select the previous tab in the run.
+ * @param current the current tab
+ */
protected void selectPreviousTabInRun(int current) {
int tabCount = tabPane.getTabCount();
int tabIndex = getPreviousTabIndexInRun(tabCount, current);
while(tabIndex != current && !tabPane.isEnabledAt(tabIndex)) {
tabIndex = getPreviousTabIndexInRun(tabCount, tabIndex);
}
navigateTo(tabIndex);
}
+ /**
+ * Select the next tab.
+ * @param current the current tab
+ */
protected void selectNextTab(int current) {
int tabIndex = getNextTabIndex(current);
while (tabIndex != current && !tabPane.isEnabledAt(tabIndex)) {
tabIndex = getNextTabIndex(tabIndex);
}
navigateTo(tabIndex);
}
+ /**
+ * Select the previous tab.
+ * @param current the current tab
+ */
protected void selectPreviousTab(int current) {
int tabIndex = getPreviousTabIndex(current);
while (tabIndex != current && !tabPane.isEnabledAt(tabIndex)) {
tabIndex = getPreviousTabIndex(tabIndex);
}
navigateTo(tabIndex);
}
+ /**
+ * Selects an adjacent run of tabs.
+ * @param tabPlacement the placement (left, right, bottom, top) of the tab
+ * @param tabIndex the index of the tab with respect to other tabs
+ * @param offset selection offset
+ */
protected void selectAdjacentRunTab(int tabPlacement,
int tabIndex, int offset) {
if ( runCount < 2 ) {
return;
}
@@ -2024,10 +2348,18 @@
*/
protected int getFocusIndex() {
return focusIndex;
}
+ /**
+ * Returns the tab run offset.
+ * @param tabPlacement the placement (left, right, bottom, top) of the tab
+ * @param tabCount the tab count
+ * @param tabIndex the index of the tab with respect to other tabs
+ * @param forward forward or not
+ * @return the tab run offset
+ */
protected int getTabRunOffset(int tabPlacement, int tabCount,
int tabIndex, boolean forward) {
int run = getRunForTab(tabCount, tabIndex);
int offset;
switch(tabPlacement) {
@@ -2090,19 +2422,35 @@
}
}
return offset;
}
+ /**
+ * Returns the previous tab index.
+ * @param base the base
+ * @return the previous tab index
+ */
protected int getPreviousTabIndex(int base) {
int tabIndex = (base - 1 >= 0? base - 1 : tabPane.getTabCount() - 1);
return (tabIndex >= 0? tabIndex : 0);
}
+ /**
+ * Returns the next tab index.
+ * @param base the base
+ * @return the next tab index
+ */
protected int getNextTabIndex(int base) {
return (base+1)%tabPane.getTabCount();
}
+ /**
+ * Returns the next tab index in the run.
+ * @param tabCount the tab count
+ * @param base the base
+ * @return the next tab index in the run
+ */
protected int getNextTabIndexInRun(int tabCount, int base) {
if (runCount < 2) {
return getNextTabIndex(base);
}
int currentRun = getRunForTab(tabCount, base);
@@ -2111,10 +2459,16 @@
return tabRuns[currentRun];
}
return next;
}
+ /**
+ * Returns the previous tab index in the run.
+ * @param tabCount the tab count
+ * @param base the base
+ * @return the previous tab index in the run
+ */
protected int getPreviousTabIndexInRun(int tabCount, int base) {
if (runCount < 2) {
return getPreviousTabIndex(base);
}
int currentRun = getRunForTab(tabCount, base);
@@ -2123,19 +2477,35 @@
return (previous != -1? previous : tabCount-1);
}
return getPreviousTabIndex(base);
}
+ /**
+ * Returns the previous tab run.
+ * @param baseRun the base run
+ * @return the previous tab run
+ */
protected int getPreviousTabRun(int baseRun) {
int runIndex = (baseRun - 1 >= 0? baseRun - 1 : runCount - 1);
return (runIndex >= 0? runIndex : 0);
}
+ /**
+ * Returns the next tab run.
+ * @param baseRun the base run
+ * @return the next tab run
+ */
protected int getNextTabRun(int baseRun) {
return (baseRun+1)%runCount;
}
+ /**
+ * Rotates the insets.
+ * @param topInsets the top insets
+ * @param targetInsets the target insets
+ * @param targetPlacement the target placement
+ */
protected static void rotateInsets(Insets topInsets, Insets targetInsets, int targetPlacement) {
switch(targetPlacement) {
case LEFT:
targetInsets.top = topInsets.left;
@@ -2290,10 +2660,15 @@
public Dimension minimumLayoutSize(Container parent) {
return calculateSize(true);
}
+ /**
+ * Returns the calculated size.
+ * @param minimum use the minimum size or preferred size
+ * @return the calculated size
+ */
protected Dimension calculateSize(boolean minimum) {
int tabPlacement = tabPane.getTabPlacement();
Insets insets = tabPane.getInsets();
Insets contentInsets = getContentBorderInsets(tabPlacement);
Insets tabAreaInsets = getTabAreaInsets(tabPlacement);
@@ -2344,10 +2719,16 @@
return new Dimension(width + insets.left + insets.right + contentInsets.left + contentInsets.right,
height + insets.bottom + insets.top + contentInsets.top + contentInsets.bottom);
}
+ /**
+ * Returns the preferred tab area height.
+ * @param tabPlacement the tab placement
+ * @param width the width
+ * @return the preferred tab area height
+ */
protected int preferredTabAreaHeight(int tabPlacement, int width) {
FontMetrics metrics = getFontMetrics();
int tabCount = tabPane.getTabCount();
int total = 0;
if (tabCount > 0) {
@@ -2368,10 +2749,16 @@
total = calculateTabAreaHeight(tabPlacement, rows, maxTabHeight);
}
return total;
}
+ /**
+ * Returns the preferred tab area width.
+ * @param tabPlacement the tab placement
+ * @param height the height
+ * @return the preferred tab area widty
+ */
protected int preferredTabAreaWidth(int tabPlacement, int height) {
FontMetrics metrics = getFontMetrics();
int tabCount = tabPane.getTabCount();
int total = 0;
if (tabCount > 0) {
@@ -2393,10 +2780,11 @@
total = calculateTabAreaWidth(tabPlacement, columns, maxTabWidth);
}
return total;
}
+ /** {@inheritDoc} */
@SuppressWarnings("deprecation")
public void layoutContainer(Container parent) {
/* Some of the code in this method deals with changing the
* visibility of components to hide and show the contents for the
* selected tab. This is older code that has since been duplicated
@@ -2515,10 +2903,13 @@
tabPane.requestFocus();
}
}
}
+ /**
+ * Calculates the layout info.
+ */
public void calculateLayoutInfo() {
int tabCount = tabPane.getTabCount();
assureRectsCreated(tabCount);
calculateTabRects(tabPane.getTabPlacement(), tabCount);
isRunsDirty = false;
@@ -2554,10 +2945,15 @@
y + getTabLabelShiftY(tabPlacement, i, isSeleceted),
preferredSize.width, preferredSize.height);
}
}
+ /**
+ * Calculate the tab rectangles.
+ * @param tabPlacement the tab placement
+ * @param tabCount the tab count
+ */
protected void calculateTabRects(int tabPlacement, int tabCount) {
FontMetrics metrics = getFontMetrics();
Dimension size = tabPane.getSize();
Insets insets = tabPane.getInsets();
Insets tabAreaInsets = getTabAreaInsets(tabPlacement);
@@ -2739,12 +3135,14 @@
}
}
}
- /*
- * Rotates the run-index array so that the selected run is run[0]
+ /**
+ * Rotates the run-index array so that the selected run is run[0].
+ * @param tabPlacement the tab placement
+ * @param selectedRun the selected run
*/
protected void rotateTabRuns(int tabPlacement, int selectedRun) {
for (int i = 0; i < selectedRun; i++) {
int save = tabRuns[0];
for (int j = 1; j < runCount; j++) {
@@ -2752,10 +3150,17 @@
}
tabRuns[runCount-1] = save;
}
}
+ /**
+ * Normalizes the tab runs.
+ * @param tabPlacement the tab placement
+ * @param tabCount the tab count
+ * @param start the start
+ * @param max the max
+ */
protected void normalizeTabRuns(int tabPlacement, int tabCount,
int start, int max) {
boolean verticalTabRuns = (tabPlacement == LEFT || tabPlacement == RIGHT);
int run = runCount - 1;
boolean keepAdjusting = true;
@@ -2820,10 +3225,17 @@
weight += .25;
}
}
}
+ /**
+ * Pads the tab run.
+ * @param tabPlacement the tab placement
+ * @param start the start
+ * @param end the end
+ * @param max the max
+ */
protected void padTabRun(int tabPlacement, int start, int end, int max) {
Rectangle lastRect = rects[end];
if (tabPlacement == TOP || tabPlacement == BOTTOM) {
int runWidth = (lastRect.x + lastRect.width) - rects[start].x;
int deltaWidth = max - (lastRect.x + lastRect.width);
@@ -2851,10 +3263,15 @@
}
lastRect.height = max - lastRect.y;
}
}
+ /**
+ * Pads selected tab.
+ * @param tabPlacement the tab placement
+ * @param selectedIndex the selected index
+ */
protected void padSelectedTab(int tabPlacement, int selectedIndex) {
if (selectedIndex >= 0) {
Rectangle selRect = rects[selectedIndex];
Insets padInsets = getSelectedTabPadInsets(tabPlacement);
< prev index next >