< prev index next >

src/java.desktop/macosx/classes/com/apple/laf/AquaTabbedPaneCopyFromBasicUI.java

Print this page




 195     static void loadActionMap(final LazyActionMap map) {
 196         map.put(new Actions(Actions.NEXT));
 197         map.put(new Actions(Actions.PREVIOUS));
 198         map.put(new Actions(Actions.RIGHT));
 199         map.put(new Actions(Actions.LEFT));
 200         map.put(new Actions(Actions.UP));
 201         map.put(new Actions(Actions.DOWN));
 202         map.put(new Actions(Actions.PAGE_UP));
 203         map.put(new Actions(Actions.PAGE_DOWN));
 204         map.put(new Actions(Actions.REQUEST_FOCUS));
 205         map.put(new Actions(Actions.REQUEST_FOCUS_FOR_VISIBLE));
 206         map.put(new Actions(Actions.SET_SELECTED));
 207         map.put(new Actions(Actions.SELECT_FOCUSED));
 208         map.put(new Actions(Actions.SCROLL_FORWARD));
 209         map.put(new Actions(Actions.SCROLL_BACKWARD));
 210     }
 211 
 212 // UI Installation/De-installation
 213 
 214     public void installUI(final JComponent c) {

 215         this.tabPane = (JTabbedPane)c;
 216 
 217         calculatedBaseline = false;
 218         rolloverTabIndex = -1;
 219         focusIndex = -1;
 220         c.setLayout(createLayoutManager());
 221         installComponents();
 222         installDefaults();
 223         installListeners();
 224         installKeyboardActions();
 225     }
 226 
 227     public void uninstallUI(final JComponent c) {
 228         uninstallKeyboardActions();
 229         uninstallListeners();
 230         uninstallDefaults();
 231         uninstallComponents();
 232         c.setLayout(null);
 233 
 234         this.tabPane = null;


 810         final boolean isSelected = selectedIndex == tabIndex;
 811 
 812         if (tabsOpaque || tabPane.isOpaque()) {
 813             paintTabBackground(g, tabPlacement, tabIndex, tabRect.x, tabRect.y, tabRect.width, tabRect.height, isSelected);
 814         }
 815 
 816         paintTabBorder(g, tabPlacement, tabIndex, tabRect.x, tabRect.y, tabRect.width, tabRect.height, isSelected);
 817 
 818         final String title = tabPane.getTitleAt(tabIndex);
 819         final Font font = tabPane.getFont();
 820         final FontMetrics metrics = SwingUtilities2.getFontMetrics(tabPane, g, font);
 821         final Icon icon = getIconForTab(tabIndex);
 822 
 823         layoutLabel(tabPlacement, metrics, tabIndex, title, icon, tabRect, iconRect, textRect, isSelected);
 824 
 825         if (tabPane.getTabComponentAt(tabIndex) == null) {
 826             String clippedTitle = title;
 827 
 828             if (scrollableTabLayoutEnabled() && tabScroller.croppedEdge.isParamsSet() && tabScroller.croppedEdge.getTabIndex() == tabIndex && isHorizontalTabPlacement()) {
 829                 final int availTextWidth = tabScroller.croppedEdge.getCropline() - (textRect.x - tabRect.x) - tabScroller.croppedEdge.getCroppedSideWidth();
 830                 clippedTitle = SwingUtilities2.clipStringIfNecessary(null, metrics, title, availTextWidth);
 831             }
 832 
 833             paintText(g, tabPlacement, font, metrics, tabIndex, clippedTitle, textRect, isSelected);
 834 
 835             paintIcon(g, tabPlacement, tabIndex, icon, iconRect, isSelected);
 836         }
 837         paintFocusIndicator(g, tabPlacement, rects, tabIndex, iconRect, textRect, isSelected);
 838     }
 839 
 840     private boolean isHorizontalTabPlacement() {
 841         return tabPane.getTabPlacement() == TOP || tabPane.getTabPlacement() == BOTTOM;
 842     }
 843 
 844     /* This method will create and return a polygon shape for the given tab rectangle
 845      * which has been cropped at the specified cropline with a torn edge visual.
 846      * e.g. A "File" tab which has cropped been cropped just after the "i":
 847      *             -------------
 848      *             |  .....     |
 849      *             |  .          |
 850      *             |  ...  .    |


 989 
 990         g.setFont(font);
 991 
 992         final View v = getTextViewForTab(tabIndex);
 993         if (v != null) {
 994             // html
 995             v.paint(g, textRect);
 996         } else {
 997             // plain text
 998             final int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);
 999 
1000             if (tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex)) {
1001                 Color fg = tabPane.getForegroundAt(tabIndex);
1002                 if (isSelected && (fg instanceof UIResource)) {
1003                     final Color selectedFG = UIManager.getColor("TabbedPane.selectedForeground");
1004                     if (selectedFG != null) {
1005                         fg = selectedFG;
1006                     }
1007                 }
1008                 g.setColor(fg);
1009                 SwingUtilities2.drawStringUnderlineCharAt(tabPane, g, title, mnemIndex, textRect.x, textRect.y + metrics.getAscent());
1010 
1011             } else { // tab disabled
1012                 g.setColor(tabPane.getBackgroundAt(tabIndex).brighter());
1013                 SwingUtilities2.drawStringUnderlineCharAt(tabPane, g, title, mnemIndex, textRect.x, textRect.y + metrics.getAscent());
1014                 g.setColor(tabPane.getBackgroundAt(tabIndex).darker());
1015                 SwingUtilities2.drawStringUnderlineCharAt(tabPane, g, title, mnemIndex, textRect.x - 1, textRect.y + metrics.getAscent() - 1);
1016 
1017             }
1018         }
1019     }
1020 
1021     protected int getTabLabelShiftX(final int tabPlacement, final int tabIndex, final boolean isSelected) {
1022         final Rectangle tabRect = rects[tabIndex];
1023         int nudge = 0;
1024         switch (tabPlacement) {
1025             case LEFT:
1026                 nudge = isSelected ? -1 : 1;
1027                 break;
1028             case RIGHT:
1029                 nudge = isSelected ? 1 : -1;
1030                 break;
1031             case BOTTOM:
1032             case TOP:
1033             default:
1034                 nudge = tabRect.width % 2;
1035         }


1622     }
1623 
1624     protected int calculateTabWidth(final int tabPlacement, final int tabIndex, final FontMetrics metrics) {
1625         final Insets tabInsets = getTabInsets(tabPlacement, tabIndex);
1626         int width = tabInsets.left + tabInsets.right + 3;
1627         final Component tabComponent = tabPane.getTabComponentAt(tabIndex);
1628         if (tabComponent != null) {
1629             width += tabComponent.getPreferredSize().width;
1630         } else {
1631             final Icon icon = getIconForTab(tabIndex);
1632             if (icon != null) {
1633                 width += icon.getIconWidth() + textIconGap;
1634             }
1635             final View v = getTextViewForTab(tabIndex);
1636             if (v != null) {
1637                 // html
1638                 width += (int)v.getPreferredSpan(View.X_AXIS);
1639             } else {
1640                 // plain text
1641                 final String title = tabPane.getTitleAt(tabIndex);
1642                 width += SwingUtilities2.stringWidth(tabPane, metrics, title);
1643             }
1644         }
1645         return width;
1646     }
1647 
1648     protected int calculateMaxTabWidth(final int tabPlacement) {
1649         final FontMetrics metrics = getFontMetrics();
1650         final int tabCount = tabPane.getTabCount();
1651         int result = 0;
1652         for (int i = 0; i < tabCount; i++) {
1653             result = Math.max(calculateTabWidth(tabPlacement, i, metrics), result);
1654         }
1655         return result;
1656     }
1657 
1658     protected int calculateTabAreaHeight(final int tabPlacement, final int horizRunCount, final int maxTabHeight) {
1659         final Insets tabAreaInsets = getTabAreaInsets(tabPlacement);
1660         final int tabRunOverlay = getTabRunOverlay(tabPlacement);
1661         return (horizRunCount > 0 ? horizRunCount * (maxTabHeight - tabRunOverlay) + tabRunOverlay + tabAreaInsets.top + tabAreaInsets.bottom : 0);
1662     }




 195     static void loadActionMap(final LazyActionMap map) {
 196         map.put(new Actions(Actions.NEXT));
 197         map.put(new Actions(Actions.PREVIOUS));
 198         map.put(new Actions(Actions.RIGHT));
 199         map.put(new Actions(Actions.LEFT));
 200         map.put(new Actions(Actions.UP));
 201         map.put(new Actions(Actions.DOWN));
 202         map.put(new Actions(Actions.PAGE_UP));
 203         map.put(new Actions(Actions.PAGE_DOWN));
 204         map.put(new Actions(Actions.REQUEST_FOCUS));
 205         map.put(new Actions(Actions.REQUEST_FOCUS_FOR_VISIBLE));
 206         map.put(new Actions(Actions.SET_SELECTED));
 207         map.put(new Actions(Actions.SELECT_FOCUSED));
 208         map.put(new Actions(Actions.SCROLL_FORWARD));
 209         map.put(new Actions(Actions.SCROLL_BACKWARD));
 210     }
 211 
 212 // UI Installation/De-installation
 213 
 214     public void installUI(final JComponent c) {
 215         super.installUI(c);
 216         this.tabPane = (JTabbedPane)c;
 217 
 218         calculatedBaseline = false;
 219         rolloverTabIndex = -1;
 220         focusIndex = -1;
 221         c.setLayout(createLayoutManager());
 222         installComponents();
 223         installDefaults();
 224         installListeners();
 225         installKeyboardActions();
 226     }
 227 
 228     public void uninstallUI(final JComponent c) {
 229         uninstallKeyboardActions();
 230         uninstallListeners();
 231         uninstallDefaults();
 232         uninstallComponents();
 233         c.setLayout(null);
 234 
 235         this.tabPane = null;


 811         final boolean isSelected = selectedIndex == tabIndex;
 812 
 813         if (tabsOpaque || tabPane.isOpaque()) {
 814             paintTabBackground(g, tabPlacement, tabIndex, tabRect.x, tabRect.y, tabRect.width, tabRect.height, isSelected);
 815         }
 816 
 817         paintTabBorder(g, tabPlacement, tabIndex, tabRect.x, tabRect.y, tabRect.width, tabRect.height, isSelected);
 818 
 819         final String title = tabPane.getTitleAt(tabIndex);
 820         final Font font = tabPane.getFont();
 821         final FontMetrics metrics = SwingUtilities2.getFontMetrics(tabPane, g, font);
 822         final Icon icon = getIconForTab(tabIndex);
 823 
 824         layoutLabel(tabPlacement, metrics, tabIndex, title, icon, tabRect, iconRect, textRect, isSelected);
 825 
 826         if (tabPane.getTabComponentAt(tabIndex) == null) {
 827             String clippedTitle = title;
 828 
 829             if (scrollableTabLayoutEnabled() && tabScroller.croppedEdge.isParamsSet() && tabScroller.croppedEdge.getTabIndex() == tabIndex && isHorizontalTabPlacement()) {
 830                 final int availTextWidth = tabScroller.croppedEdge.getCropline() - (textRect.x - tabRect.x) - tabScroller.croppedEdge.getCroppedSideWidth();
 831                 clippedTitle = getTextUIDrawing().getClippedString(null, metrics, title, availTextWidth);
 832             }
 833 
 834             paintText(g, tabPlacement, font, metrics, tabIndex, clippedTitle, textRect, isSelected);
 835 
 836             paintIcon(g, tabPlacement, tabIndex, icon, iconRect, isSelected);
 837         }
 838         paintFocusIndicator(g, tabPlacement, rects, tabIndex, iconRect, textRect, isSelected);
 839     }
 840 
 841     private boolean isHorizontalTabPlacement() {
 842         return tabPane.getTabPlacement() == TOP || tabPane.getTabPlacement() == BOTTOM;
 843     }
 844 
 845     /* This method will create and return a polygon shape for the given tab rectangle
 846      * which has been cropped at the specified cropline with a torn edge visual.
 847      * e.g. A "File" tab which has cropped been cropped just after the "i":
 848      *             -------------
 849      *             |  .....     |
 850      *             |  .          |
 851      *             |  ...  .    |


 990 
 991         g.setFont(font);
 992 
 993         final View v = getTextViewForTab(tabIndex);
 994         if (v != null) {
 995             // html
 996             v.paint(g, textRect);
 997         } else {
 998             // plain text
 999             final int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);
1000 
1001             if (tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex)) {
1002                 Color fg = tabPane.getForegroundAt(tabIndex);
1003                 if (isSelected && (fg instanceof UIResource)) {
1004                     final Color selectedFG = UIManager.getColor("TabbedPane.selectedForeground");
1005                     if (selectedFG != null) {
1006                         fg = selectedFG;
1007                     }
1008                 }
1009                 g.setColor(fg);
1010                 getTextUIDrawing().drawStringUnderlineCharAt(tabPane, g, title, mnemIndex, textRect.x, textRect.y + metrics.getAscent());
1011 
1012             } else { // tab disabled
1013                 g.setColor(tabPane.getBackgroundAt(tabIndex).brighter());
1014                 getTextUIDrawing().drawStringUnderlineCharAt(tabPane, g, title, mnemIndex, textRect.x, textRect.y + metrics.getAscent());
1015                 g.setColor(tabPane.getBackgroundAt(tabIndex).darker());
1016                 getTextUIDrawing().drawStringUnderlineCharAt(tabPane, g, title, mnemIndex, textRect.x - 1, textRect.y + metrics.getAscent() - 1);
1017 
1018             }
1019         }
1020     }
1021 
1022     protected int getTabLabelShiftX(final int tabPlacement, final int tabIndex, final boolean isSelected) {
1023         final Rectangle tabRect = rects[tabIndex];
1024         int nudge = 0;
1025         switch (tabPlacement) {
1026             case LEFT:
1027                 nudge = isSelected ? -1 : 1;
1028                 break;
1029             case RIGHT:
1030                 nudge = isSelected ? 1 : -1;
1031                 break;
1032             case BOTTOM:
1033             case TOP:
1034             default:
1035                 nudge = tabRect.width % 2;
1036         }


1623     }
1624 
1625     protected int calculateTabWidth(final int tabPlacement, final int tabIndex, final FontMetrics metrics) {
1626         final Insets tabInsets = getTabInsets(tabPlacement, tabIndex);
1627         int width = tabInsets.left + tabInsets.right + 3;
1628         final Component tabComponent = tabPane.getTabComponentAt(tabIndex);
1629         if (tabComponent != null) {
1630             width += tabComponent.getPreferredSize().width;
1631         } else {
1632             final Icon icon = getIconForTab(tabIndex);
1633             if (icon != null) {
1634                 width += icon.getIconWidth() + textIconGap;
1635             }
1636             final View v = getTextViewForTab(tabIndex);
1637             if (v != null) {
1638                 // html
1639                 width += (int)v.getPreferredSpan(View.X_AXIS);
1640             } else {
1641                 // plain text
1642                 final String title = tabPane.getTitleAt(tabIndex);
1643                 width += getTextUIDrawing().getStringWidth(tabPane, metrics, title);
1644             }
1645         }
1646         return width;
1647     }
1648 
1649     protected int calculateMaxTabWidth(final int tabPlacement) {
1650         final FontMetrics metrics = getFontMetrics();
1651         final int tabCount = tabPane.getTabCount();
1652         int result = 0;
1653         for (int i = 0; i < tabCount; i++) {
1654             result = Math.max(calculateTabWidth(tabPlacement, i, metrics), result);
1655         }
1656         return result;
1657     }
1658 
1659     protected int calculateTabAreaHeight(final int tabPlacement, final int horizRunCount, final int maxTabHeight) {
1660         final Insets tabAreaInsets = getTabAreaInsets(tabPlacement);
1661         final int tabRunOverlay = getTabRunOverlay(tabPlacement);
1662         return (horizRunCount > 0 ? horizRunCount * (maxTabHeight - tabRunOverlay) + tabRunOverlay + tabAreaInsets.top + tabAreaInsets.bottom : 0);
1663     }


< prev index next >