52 protected JTabbedPane tabPane;
53
54 protected Color highlight;
55 protected Color lightHighlight;
56 protected Color shadow;
57 protected Color darkShadow;
58 protected Color focus;
59 private Color selectedColor;
60
61 protected int textIconGap;
62
63 protected int tabRunOverlay;
64
65 protected Insets tabInsets;
66 protected Insets selectedTabPadInsets;
67 protected Insets tabAreaInsets;
68 protected Insets contentBorderInsets;
69 private boolean tabsOverlapBorder;
70 private boolean tabsOpaque = true;
71 private boolean contentOpaque = true;
72
73 /**
74 * As of Java 2 platform v1.3 this previously undocumented field is no
75 * longer used.
76 * Key bindings are now defined by the LookAndFeel, please refer to
77 * the key bindings specification for further details.
78 *
79 * @deprecated As of Java 2 platform v1.3.
80 */
81 @Deprecated
82 protected KeyStroke upKey;
83 /**
84 * As of Java 2 platform v1.3 this previously undocumented field is no
85 * longer used.
86 * Key bindings are now defined by the LookAndFeel, please refer to
87 * the key bindings specification for further details.
88 *
89 * @deprecated As of Java 2 platform v1.3.
90 */
91 @Deprecated
357 lightHighlight = UIManager.getColor("TabbedPane.highlight");
358 shadow = UIManager.getColor("TabbedPane.shadow");
359 darkShadow = UIManager.getColor("TabbedPane.darkShadow");
360 focus = UIManager.getColor("TabbedPane.focus");
361 selectedColor = UIManager.getColor("TabbedPane.selected");
362
363 textIconGap = UIManager.getInt("TabbedPane.textIconGap");
364 tabInsets = UIManager.getInsets("TabbedPane.tabInsets");
365 selectedTabPadInsets = UIManager.getInsets("TabbedPane.selectedTabPadInsets");
366 tabAreaInsets = UIManager.getInsets("TabbedPane.tabAreaInsets");
367 tabsOverlapBorder = UIManager.getBoolean("TabbedPane.tabsOverlapBorder");
368 contentBorderInsets = UIManager.getInsets("TabbedPane.contentBorderInsets");
369 tabRunOverlay = UIManager.getInt("TabbedPane.tabRunOverlay");
370 tabsOpaque = UIManager.getBoolean("TabbedPane.tabsOpaque");
371 contentOpaque = UIManager.getBoolean("TabbedPane.contentOpaque");
372 Object opaque = UIManager.get("TabbedPane.opaque");
373 if (opaque == null) {
374 opaque = Boolean.FALSE;
375 }
376 LookAndFeel.installProperty(tabPane, "opaque", opaque);
377 }
378
379 protected void uninstallDefaults() {
380 highlight = null;
381 lightHighlight = null;
382 shadow = null;
383 darkShadow = null;
384 focus = null;
385 tabInsets = null;
386 selectedTabPadInsets = null;
387 tabAreaInsets = null;
388 contentBorderInsets = null;
389 }
390
391 protected void installListeners() {
392 if ((propertyChangeListener = createPropertyChangeListener()) != null) {
393 tabPane.addPropertyChangeListener(propertyChangeListener);
394 }
395 if ((tabChangeListener = createChangeListener()) != null) {
396 tabPane.addChangeListener(tabChangeListener);
397 }
398 if ((mouseListener = createMouseListener()) != null) {
399 tabPane.addMouseListener(mouseListener);
400 }
401 tabPane.addMouseMotionListener(getHandler());
402 if ((focusListener = createFocusListener()) != null) {
403 tabPane.addFocusListener(focusListener);
404 }
405 tabPane.addContainerListener(getHandler());
406 if (tabPane.getTabCount() > 0) {
407 htmlViews = createHTMLVector();
408 }
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 }
|
52 protected JTabbedPane tabPane;
53
54 protected Color highlight;
55 protected Color lightHighlight;
56 protected Color shadow;
57 protected Color darkShadow;
58 protected Color focus;
59 private Color selectedColor;
60
61 protected int textIconGap;
62
63 protected int tabRunOverlay;
64
65 protected Insets tabInsets;
66 protected Insets selectedTabPadInsets;
67 protected Insets tabAreaInsets;
68 protected Insets contentBorderInsets;
69 private boolean tabsOverlapBorder;
70 private boolean tabsOpaque = true;
71 private boolean contentOpaque = true;
72 protected TextUIDrawing textUIDrawing;
73
74 /**
75 * As of Java 2 platform v1.3 this previously undocumented field is no
76 * longer used.
77 * Key bindings are now defined by the LookAndFeel, please refer to
78 * the key bindings specification for further details.
79 *
80 * @deprecated As of Java 2 platform v1.3.
81 */
82 @Deprecated
83 protected KeyStroke upKey;
84 /**
85 * As of Java 2 platform v1.3 this previously undocumented field is no
86 * longer used.
87 * Key bindings are now defined by the LookAndFeel, please refer to
88 * the key bindings specification for further details.
89 *
90 * @deprecated As of Java 2 platform v1.3.
91 */
92 @Deprecated
358 lightHighlight = UIManager.getColor("TabbedPane.highlight");
359 shadow = UIManager.getColor("TabbedPane.shadow");
360 darkShadow = UIManager.getColor("TabbedPane.darkShadow");
361 focus = UIManager.getColor("TabbedPane.focus");
362 selectedColor = UIManager.getColor("TabbedPane.selected");
363
364 textIconGap = UIManager.getInt("TabbedPane.textIconGap");
365 tabInsets = UIManager.getInsets("TabbedPane.tabInsets");
366 selectedTabPadInsets = UIManager.getInsets("TabbedPane.selectedTabPadInsets");
367 tabAreaInsets = UIManager.getInsets("TabbedPane.tabAreaInsets");
368 tabsOverlapBorder = UIManager.getBoolean("TabbedPane.tabsOverlapBorder");
369 contentBorderInsets = UIManager.getInsets("TabbedPane.contentBorderInsets");
370 tabRunOverlay = UIManager.getInt("TabbedPane.tabRunOverlay");
371 tabsOpaque = UIManager.getBoolean("TabbedPane.tabsOpaque");
372 contentOpaque = UIManager.getBoolean("TabbedPane.contentOpaque");
373 Object opaque = UIManager.get("TabbedPane.opaque");
374 if (opaque == null) {
375 opaque = Boolean.FALSE;
376 }
377 LookAndFeel.installProperty(tabPane, "opaque", opaque);
378 textUIDrawing = SwingUtilities2.getTextUIDrawing(textUIDrawing);
379 }
380
381 protected void uninstallDefaults() {
382 highlight = null;
383 lightHighlight = null;
384 shadow = null;
385 darkShadow = null;
386 focus = null;
387 tabInsets = null;
388 selectedTabPadInsets = null;
389 tabAreaInsets = null;
390 contentBorderInsets = null;
391 if (textUIDrawing != SwingUtilities2.DEFAULT_UI_TEXT_DRAWING
392 && textUIDrawing instanceof UIResource) {
393 textUIDrawing = SwingUtilities2.DEFAULT_UI_TEXT_DRAWING;
394 }
395 }
396
397 protected void installListeners() {
398 if ((propertyChangeListener = createPropertyChangeListener()) != null) {
399 tabPane.addPropertyChangeListener(propertyChangeListener);
400 }
401 if ((tabChangeListener = createChangeListener()) != null) {
402 tabPane.addChangeListener(tabChangeListener);
403 }
404 if ((mouseListener = createMouseListener()) != null) {
405 tabPane.addMouseListener(mouseListener);
406 }
407 tabPane.addMouseMotionListener(getHandler());
408 if ((focusListener = createFocusListener()) != null) {
409 tabPane.addFocusListener(focusListener);
410 }
411 tabPane.addContainerListener(getHandler());
412 if (tabPane.getTabCount() > 0) {
413 htmlViews = createHTMLVector();
414 }
816 final boolean isSelected = selectedIndex == tabIndex;
817
818 if (tabsOpaque || tabPane.isOpaque()) {
819 paintTabBackground(g, tabPlacement, tabIndex, tabRect.x, tabRect.y, tabRect.width, tabRect.height, isSelected);
820 }
821
822 paintTabBorder(g, tabPlacement, tabIndex, tabRect.x, tabRect.y, tabRect.width, tabRect.height, isSelected);
823
824 final String title = tabPane.getTitleAt(tabIndex);
825 final Font font = tabPane.getFont();
826 final FontMetrics metrics = SwingUtilities2.getFontMetrics(tabPane, g, font);
827 final Icon icon = getIconForTab(tabIndex);
828
829 layoutLabel(tabPlacement, metrics, tabIndex, title, icon, tabRect, iconRect, textRect, isSelected);
830
831 if (tabPane.getTabComponentAt(tabIndex) == null) {
832 String clippedTitle = title;
833
834 if (scrollableTabLayoutEnabled() && tabScroller.croppedEdge.isParamsSet() && tabScroller.croppedEdge.getTabIndex() == tabIndex && isHorizontalTabPlacement()) {
835 final int availTextWidth = tabScroller.croppedEdge.getCropline() - (textRect.x - tabRect.x) - tabScroller.croppedEdge.getCroppedSideWidth();
836 clippedTitle = textUIDrawing.getClippedString(null, metrics, title, availTextWidth);
837 }
838
839 paintText(g, tabPlacement, font, metrics, tabIndex, clippedTitle, textRect, isSelected);
840
841 paintIcon(g, tabPlacement, tabIndex, icon, iconRect, isSelected);
842 }
843 paintFocusIndicator(g, tabPlacement, rects, tabIndex, iconRect, textRect, isSelected);
844 }
845
846 private boolean isHorizontalTabPlacement() {
847 return tabPane.getTabPlacement() == TOP || tabPane.getTabPlacement() == BOTTOM;
848 }
849
850 /* This method will create and return a polygon shape for the given tab rectangle
851 * which has been cropped at the specified cropline with a torn edge visual.
852 * e.g. A "File" tab which has cropped been cropped just after the "i":
853 * -------------
854 * | ..... |
855 * | . |
856 * | ... . |
995
996 g.setFont(font);
997
998 final View v = getTextViewForTab(tabIndex);
999 if (v != null) {
1000 // html
1001 v.paint(g, textRect);
1002 } else {
1003 // plain text
1004 final int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);
1005
1006 if (tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex)) {
1007 Color fg = tabPane.getForegroundAt(tabIndex);
1008 if (isSelected && (fg instanceof UIResource)) {
1009 final Color selectedFG = UIManager.getColor("TabbedPane.selectedForeground");
1010 if (selectedFG != null) {
1011 fg = selectedFG;
1012 }
1013 }
1014 g.setColor(fg);
1015 textUIDrawing.drawStringUnderlineCharAt(tabPane, g, title, mnemIndex, textRect.x, textRect.y + metrics.getAscent());
1016
1017 } else { // tab disabled
1018 g.setColor(tabPane.getBackgroundAt(tabIndex).brighter());
1019 textUIDrawing.drawStringUnderlineCharAt(tabPane, g, title, mnemIndex, textRect.x, textRect.y + metrics.getAscent());
1020 g.setColor(tabPane.getBackgroundAt(tabIndex).darker());
1021 textUIDrawing.drawStringUnderlineCharAt(tabPane, g, title, mnemIndex, textRect.x - 1, textRect.y + metrics.getAscent() - 1);
1022
1023 }
1024 }
1025 }
1026
1027 protected int getTabLabelShiftX(final int tabPlacement, final int tabIndex, final boolean isSelected) {
1028 final Rectangle tabRect = rects[tabIndex];
1029 int nudge = 0;
1030 switch (tabPlacement) {
1031 case LEFT:
1032 nudge = isSelected ? -1 : 1;
1033 break;
1034 case RIGHT:
1035 nudge = isSelected ? 1 : -1;
1036 break;
1037 case BOTTOM:
1038 case TOP:
1039 default:
1040 nudge = tabRect.width % 2;
1041 }
1628 }
1629
1630 protected int calculateTabWidth(final int tabPlacement, final int tabIndex, final FontMetrics metrics) {
1631 final Insets tabInsets = getTabInsets(tabPlacement, tabIndex);
1632 int width = tabInsets.left + tabInsets.right + 3;
1633 final Component tabComponent = tabPane.getTabComponentAt(tabIndex);
1634 if (tabComponent != null) {
1635 width += tabComponent.getPreferredSize().width;
1636 } else {
1637 final Icon icon = getIconForTab(tabIndex);
1638 if (icon != null) {
1639 width += icon.getIconWidth() + textIconGap;
1640 }
1641 final View v = getTextViewForTab(tabIndex);
1642 if (v != null) {
1643 // html
1644 width += (int)v.getPreferredSpan(View.X_AXIS);
1645 } else {
1646 // plain text
1647 final String title = tabPane.getTitleAt(tabIndex);
1648 width += textUIDrawing.getStringWidth(tabPane, metrics, title);
1649 }
1650 }
1651 return width;
1652 }
1653
1654 protected int calculateMaxTabWidth(final int tabPlacement) {
1655 final FontMetrics metrics = getFontMetrics();
1656 final int tabCount = tabPane.getTabCount();
1657 int result = 0;
1658 for (int i = 0; i < tabCount; i++) {
1659 result = Math.max(calculateTabWidth(tabPlacement, i, metrics), result);
1660 }
1661 return result;
1662 }
1663
1664 protected int calculateTabAreaHeight(final int tabPlacement, final int horizRunCount, final int maxTabHeight) {
1665 final Insets tabAreaInsets = getTabAreaInsets(tabPlacement);
1666 final int tabRunOverlay = getTabRunOverlay(tabPlacement);
1667 return (horizRunCount > 0 ? horizRunCount * (maxTabHeight - tabRunOverlay) + tabRunOverlay + tabAreaInsets.top + tabAreaInsets.bottom : 0);
1668 }
|