< prev index next >

src/java.desktop/share/classes/javax/swing/plaf/basic/BasicTabbedPaneUI.java

Print this page

        

*** 1,7 **** /* ! * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this --- 1,7 ---- /* ! * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. Oracle designates this
*** 54,79 **** public class BasicTabbedPaneUI extends TabbedPaneUI implements SwingConstants { // Instance variables initialized at installation protected JTabbedPane tabPane; protected Color highlight; protected Color lightHighlight; protected Color shadow; protected Color darkShadow; protected Color focus; private Color selectedColor; protected int textIconGap; ! protected int tabRunOverlay; protected Insets tabInsets; protected Insets selectedTabPadInsets; protected Insets tabAreaInsets; protected Insets contentBorderInsets; private boolean tabsOverlapBorder; private boolean tabsOpaque = true; private boolean contentOpaque = true; --- 54,90 ---- 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,140 **** @Deprecated protected KeyStroke rightKey; // Transient variables (recalculated each time TabbedPane is layed out) ! protected int tabRuns[] = new int[10]; protected int runCount = 0; protected int selectedRun = -1; protected Rectangle rects[] = new Rectangle[0]; protected int maxTabHeight; protected int maxTabWidth; // Listeners protected ChangeListener tabChangeListener; protected PropertyChangeListener propertyChangeListener; protected MouseListener mouseListener; protected FocusListener focusListener; // Private instance data private Insets currentPadInsets = new Insets(0,0,0,0); --- 129,160 ---- @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,197 **** --- 208,222 ---- 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,362 **** --- 378,390 ---- 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,396 **** --- 415,427 ---- 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,408 **** --- 430,442 ---- selectedTabPadInsets = null; tabAreaInsets = null; contentBorderInsets = null; } + /** + * Install the listeners. + */ protected void installListeners() { if ((propertyChangeListener = createPropertyChangeListener()) != null) { tabPane.addPropertyChangeListener(propertyChangeListener); } if ((tabChangeListener = createChangeListener()) != null) {
*** 419,428 **** --- 453,465 ---- if (tabPane.getTabCount()>0) { htmlViews = createHTMLVector(); } } + /** + * Uninstall the listeners. + */ protected void uninstallListeners() { if (mouseListener != null) { tabPane.removeMouseListener(mouseListener); mouseListener = null; }
*** 446,467 **** --- 483,520 ---- 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,478 **** --- 522,534 ---- 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,505 **** --- 552,564 ---- "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,851 **** --- 901,919 ---- 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,1019 **** --- 1078,1099 ---- 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,1060 **** --- 1123,1160 ---- 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,1104 **** } } } ! 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); --- 1194,1210 ---- } } } ! /** ! * 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,1122 **** --- 1219,1235 ---- 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,1139 **** --- 1243,1262 ---- 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,1252 **** --- 1366,1387 ---- 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,1274 **** --- 1400,1415 ---- 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,1336 **** --- 1468,1487 ---- 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,1365 **** --- 1507,1526 ---- 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,1391 **** --- 1543,1562 ---- 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,1424 **** --- 1586,1605 ---- } } } + /** + * 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,1629 **** --- 1797,1818 ---- 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,1643 **** --- 1823,1836 ---- 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,1664 **** --- 1841,1866 ---- } } } + /** + * 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,1675 **** --- 1868,1883 ---- } } 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,1702 **** --- 1885,1937 ---- 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,1725 **** --- 1951,1967 ---- 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,1750 **** --- 1983,1997 ---- 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,1761 **** --- 1999,2015 ---- 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,1839 **** --- 2030,2141 ---- } } 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,1955 **** --- 2210,2279 ---- 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,2033 **** --- 2348,2365 ---- */ 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,2108 **** --- 2422,2456 ---- } } 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,2120 **** --- 2459,2474 ---- 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,2141 **** --- 2477,2511 ---- 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,2299 **** --- 2660,2674 ---- 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,2353 **** --- 2719,2734 ---- 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,2377 **** --- 2749,2764 ---- 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,2402 **** --- 2780,2790 ---- 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,2524 **** --- 2903,2915 ---- tabPane.requestFocus(); } } } + /** + * Calculates the layout info. + */ public void calculateLayoutInfo() { int tabCount = tabPane.getTabCount(); assureRectsCreated(tabCount); calculateTabRects(tabPane.getTabPlacement(), tabCount); isRunsDirty = false;
*** 2554,2563 **** --- 2945,2959 ---- 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,2750 **** } } } ! /* ! * Rotates the run-index array so that the selected run is run[0] */ 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++) { --- 3135,3148 ---- } } } ! /** ! * 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,2761 **** --- 3150,3166 ---- } 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,2829 **** --- 3225,3241 ---- 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,2860 **** --- 3263,3277 ---- } 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 >