Package com.jgoodies.looks.plastic
Class PlasticTabbedPaneUI
java.lang.Object
javax.swing.plaf.ComponentUI
javax.swing.plaf.TabbedPaneUI
javax.swing.plaf.basic.BasicTabbedPaneUI
javax.swing.plaf.metal.MetalTabbedPaneUI
com.jgoodies.looks.plastic.PlasticTabbedPaneUI
- All Implemented Interfaces:
SwingConstants
The JGoodies Plastic Look&Feel implementation of
TabbedPaneUI. It differs from its superclass
MetalTabbedPaneUI in that it paints new tab shapes,
provides two options, and supports ClearLook.
You can enable or disable icons in tabs globally via com.jgoodies.looks.Options.setTabIconsEnabled(boolean).
To disable the content border set
JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.putClientProperty(Option.NO_CONTENT_BORDER_KEY, Boolean.TRUE);To paint embedded tabs use
JTabbedPane tabbedPane = new JTabbedPane(); tabbedPane.putClientProperty(Option.EMBEDDED_TABS_KEY, Boolean.TRUE);
There's a special mode that helps you detect content borders in heavily wrapped component hierarchies - such as the NetBeans IDE. In this marked mode the content border is painted as a Magenta line. You can enable this mode by setting the System property markContentBorders to true; in a command line:
java -DmarkContentBorders=true
Thanks to Andrej Golovnin for his feedback and suggestions.
- Version:
- $Revision: 1.15 $
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classThis is the abstract superclass for all TabbedPane renderers.private static final classprivate static final classThe renderer for the case where tabs are displayed below the contents and with minimal decoration.private static final classThe renderer for the case where Tabs are below the content and decoration is standard.private static final classThe renderer for tabs on the left with minimal decoration.private static final classRenderer for tabs on the left with normal decoration.private final classCatches and handles property change events.private static final classThe renderer for tabs on the right with minimal decoration.private static final classRenderer for tabs on the right with normal decoration.private final classprivate final classprivate final classprivate static classprivate static classprivate classDoes all the layout work.private final classprivate final classprivate static final classRenderer for tabs on top with minimal decoration.private static final classRenderer for tabs on top with normal decoration.Nested classes/interfaces inherited from class javax.swing.plaf.basic.BasicTabbedPaneUI
BasicTabbedPaneUI.FocusHandler, BasicTabbedPaneUI.MouseHandler, BasicTabbedPaneUI.PropertyChangeHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intprivate BooleanDescribes if we paint tabs in an embedded style that is with less decoration; this is false by default.private static booleanDescribes if tabs are painted with or without icons.private BooleanDescribes if we paint no content border or not; is false by default.Holds the renderer that is used to render the tabs.For use when tabLayoutPolicy == SCROLL_TAB_LAYOUT.private final int[]private final int[]Fields inherited from class javax.swing.plaf.metal.MetalTabbedPaneUI
minTabWidth, selectColor, selectHighlight, tabAreaBackgroundFields inherited from class javax.swing.plaf.basic.BasicTabbedPaneUI
calcRect, contentBorderInsets, darkShadow, downKey, focus, focusListener, highlight, leftKey, lightHighlight, maxTabHeight, maxTabWidth, mouseListener, propertyChangeListener, rects, rightKey, runCount, selectedRun, selectedTabPadInsets, shadow, tabAreaInsets, tabChangeListener, tabInsets, tabPane, tabRunOverlay, tabRuns, textIconGap, upKeyFields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected ChangeListenerprivate PolygoncreateCroppedTabClip(int tabPlacement, Rectangle tabRect, int cropline) protected LayoutManagerCreates the layout manager used to set the tab's bounds.protected PropertyChangeListenerCreates and answer a handler that listens to property changes.createRenderer(JTabbedPane tabbedPane) Creates the renderer used to lay out and paint the tabs.static ComponentUIcreateUI(JComponent tabPane) Creates thePlasticTabbedPaneUI.private voiddoLayout()private voidembeddedTabsPropertyChanged(Boolean newValue) Updates the embedded tabs property.private voidprivate intgetClosestTab(int x, int y) Returns the index of the tab closest to the passed in location, note that the returned tab may not contain the location x,y.protected InsetsgetContentBorderInsets(int tabPlacement) Returns the insets (i.e.protected IcongetIconForTab(int tabIndex) Answers the icon for the tab with the specified index.protected InsetsgetSelectedTabPadInsets(int tabPlacement) Returns the insets for selected tab.protected InsetsgetTabAreaInsets(int tabPlacement) Returns the amount by which the Tab Area is inset.protected RectanglegetTabBounds(int tabIndex, Rectangle dest) protected InsetsgetTabInsets(int tabPlacement, int tabIndex) Returns the insets for this tab.protected intgetTabLabelShiftX(int tabPlacement, int tabIndex, boolean isSelected) Returns the amount by which the label should be shifted horizontally.protected intgetTabLabelShiftY(int tabPlacement, int tabIndex, boolean isSelected) Returns the amount by which the label should be shifted vertically.protected intgetTabRunIndent(int tabPlacement, int run) Returns the amount by which the run numberrunshould be indented.protected intgetTabRunOverlay(int tabPlacement) Returns the amount (in pixels) by which two runs should overlap.private booleanChecks and answers if tabs are painted with minimal decoration.private booleanChecks and answers if content border will be painted.protected voidCreates and installs any required subcomponents for the JTabbedPane.protected voidvoidInstalls the UI.protected booleanisTabInFirstRun(int tabIndex) protected voidlayoutLabel(int tabPlacement, FontMetrics metrics, int tabIndex, String title, Icon icon, Rectangle tabRect, Rectangle iconRect, Rectangle textRect, boolean isSelected) private voidnoContentBorderPropertyChanged(Boolean newValue) Updates the no content border property.voidpaint(Graphics g, JComponent c) protected voidpaintContentBorder(Graphics g, int tabPlacement, int selectedIndex) private voidpaintCroppedTabEdge(Graphics g, int tabPlacement, int tabIndex, boolean isSelected, int x, int y) protected voidpaintFocusIndicator(Graphics g, int tabPlacement, Rectangle[] rectangles, int tabIndex, Rectangle iconRect, Rectangle textRect, boolean isSelected) Draws the rectancle around the Tab label which indicates keyboard focus.protected voidpaintTab(Graphics g, int tabPlacement, Rectangle[] rects, int tabIndex, Rectangle iconRect, Rectangle textRect) protected voidpaintTabArea(Graphics g, int tabPlacement, int selectedIndex) protected voidpaintTabBackground(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected) Fills the background of the given tab to make sure overlap of tabs is handled correctly.protected voidpaintTabBorder(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected) Paints the border for one tab.private booleanprivate booleanprotected booleanshouldPadTabRun(int tabPlacement, int run) This boolean controls wheather the given run should be padded to use up as much space as the others (with more tabs in them).protected booleanshouldRotateTabRuns(int tabPlacement) Answers wheather tab runs should be rotated.inttabForCoordinate(JTabbedPane pane, int x, int y) Returns the tab index which intersects the specified point in the JTabbedPane's coordinate space.private voidUpdates the renderer and layout.private PointtranslatePointToTabPanel(int srcx, int srcy, Point dest) Returns a point which is translated from the specified point in the JTabbedPane's coordinate space to the coordinate space of the ScrollableTabPanel.protected voidRemoves any installed subcomponents from the JTabbedPane.voidUninstalls the UI.Methods inherited from class javax.swing.plaf.metal.MetalTabbedPaneUI
calculateMaxTabHeight, getBaselineOffset, getColorForGap, installDefaults, paintBottomTabBorder, paintContentBorderBottomEdge, paintContentBorderLeftEdge, paintContentBorderRightEdge, paintContentBorderTopEdge, paintHighlightBelowTab, paintLeftTabBorder, paintRightTabBorder, paintTopTabBorder, shouldFillGap, shouldRotateTabRuns, updateMethods inherited from class javax.swing.plaf.basic.BasicTabbedPaneUI
assureRectsCreated, calculateMaxTabWidth, calculateTabAreaHeight, calculateTabAreaWidth, calculateTabHeight, calculateTabWidth, createFocusListener, createMouseListener, createScrollButton, expandTabRunsArray, getBaseline, getBaseline, getBaselineResizeBehavior, getFocusIndex, getFontMetrics, getMaximumSize, getMinimumSize, getNextTabIndex, getNextTabIndexInRun, getNextTabRun, getPreviousTabIndex, getPreviousTabIndexInRun, getPreviousTabRun, getRolloverTab, getRunForTab, getTabBounds, getTabRunCount, getTabRunOffset, getTextViewForTab, getVisibleComponent, installListeners, lastTabInRun, navigateSelectedTab, paintIcon, paintText, rotateInsets, selectAdjacentRunTab, selectNextTab, selectNextTabInRun, selectPreviousTab, selectPreviousTabInRun, setRolloverTab, setVisibleComponent, uninstallDefaults, uninstallKeyboardActions, uninstallListenersMethods inherited from class javax.swing.plaf.ComponentUI
contains, getAccessibleChild, getAccessibleChildrenCount, getPreferredSize
-
Field Details
-
isTabIconsEnabled
private static boolean isTabIconsEnabledDescribes if tabs are painted with or without icons. -
noContentBorder
Describes if we paint no content border or not; is false by default. You can disable the content border by setting the client property Options.NO_CONTENT_BORDER_KEY to Boolean.TRUE; -
embeddedTabs
Describes if we paint tabs in an embedded style that is with less decoration; this is false by default. You can enable the embedded tabs style by setting the client property Options.EMBEDDED_TABS_KEY to Boolean.TRUE. -
renderer
Holds the renderer that is used to render the tabs. -
tabScroller
For use when tabLayoutPolicy == SCROLL_TAB_LAYOUT. -
xCropLen
private final int[] xCropLen -
yCropLen
private final int[] yCropLen -
CROP_SEGMENT
private static final int CROP_SEGMENT- See Also:
-
-
Constructor Details
-
PlasticTabbedPaneUI
public PlasticTabbedPaneUI()
-
-
Method Details
-
createUI
Creates thePlasticTabbedPaneUI.- See Also:
-
installUI
Installs the UI.- Overrides:
installUIin classBasicTabbedPaneUI- See Also:
-
uninstallUI
Uninstalls the UI.- Overrides:
uninstallUIin classBasicTabbedPaneUI- See Also:
-
installComponents
protected void installComponents()Creates and installs any required subcomponents for the JTabbedPane. Invoked by installUI.- Overrides:
installComponentsin classBasicTabbedPaneUI- See Also:
-
uninstallComponents
protected void uninstallComponents()Removes any installed subcomponents from the JTabbedPane. Invoked by uninstallUI.- Overrides:
uninstallComponentsin classBasicTabbedPaneUI- See Also:
-
installKeyboardActions
protected void installKeyboardActions()- Overrides:
installKeyboardActionsin classBasicTabbedPaneUI
-
hasNoContentBorder
private boolean hasNoContentBorder()Checks and answers if content border will be painted. This is controlled by the component's client property Options.NO_CONTENT_BORDER or Options.EMBEDDED. -
hasEmbeddedTabs
private boolean hasEmbeddedTabs()Checks and answers if tabs are painted with minimal decoration. -
createRenderer
Creates the renderer used to lay out and paint the tabs.- Parameters:
tabbedPane- the UIs component- Returns:
- AbstractRenderer the renderer that will be used to paint
-
createPropertyChangeListener
Creates and answer a handler that listens to property changes. Unlike the superclass BasicTabbedPane, the PlasticTabbedPaneUI uses an extended Handler.- Overrides:
createPropertyChangeListenerin classBasicTabbedPaneUI
-
createChangeListener
- Overrides:
createChangeListenerin classBasicTabbedPaneUI
-
doLayout
private void doLayout() -
tabPlacementChanged
private void tabPlacementChanged()Updates the renderer and layout. This message is sent by my PropertyChangeHandler whenever the tab placement changes. -
embeddedTabsPropertyChanged
Updates the embedded tabs property. This message is sent by my PropertyChangeHandler whenever the embedded tabs property changes. -
noContentBorderPropertyChanged
Updates the no content border property. This message is sent by my PropertyChangeHandler whenever the noContentBorder property changes. -
paint
- Overrides:
paintin classMetalTabbedPaneUI
-
paintTab
protected void paintTab(Graphics g, int tabPlacement, Rectangle[] rects, int tabIndex, Rectangle iconRect, Rectangle textRect) - Overrides:
paintTabin classBasicTabbedPaneUI
-
createCroppedTabClip
-
paintCroppedTabEdge
private void paintCroppedTabEdge(Graphics g, int tabPlacement, int tabIndex, boolean isSelected, int x, int y) -
ensureCurrentLayout
private void ensureCurrentLayout() -
tabForCoordinate
Returns the tab index which intersects the specified point in the JTabbedPane's coordinate space.- Overrides:
tabForCoordinatein classBasicTabbedPaneUI
-
getTabBounds
- Overrides:
getTabBoundsin classBasicTabbedPaneUI
-
getClosestTab
private int getClosestTab(int x, int y) Returns the index of the tab closest to the passed in location, note that the returned tab may not contain the location x,y. -
translatePointToTabPanel
Returns a point which is translated from the specified point in the JTabbedPane's coordinate space to the coordinate space of the ScrollableTabPanel. This is used for SCROLL_TAB_LAYOUT ONLY. -
paintTabArea
- Overrides:
paintTabAreain classBasicTabbedPaneUI
-
layoutLabel
protected void layoutLabel(int tabPlacement, FontMetrics metrics, int tabIndex, String title, Icon icon, Rectangle tabRect, Rectangle iconRect, Rectangle textRect, boolean isSelected) - Overrides:
layoutLabelin classBasicTabbedPaneUI
-
getIconForTab
Answers the icon for the tab with the specified index. In case, we have globally switched of the use tab icons, we answernullif and only if we have a title.- Overrides:
getIconForTabin classBasicTabbedPaneUI
-
createLayoutManager
Creates the layout manager used to set the tab's bounds.- Overrides:
createLayoutManagerin classMetalTabbedPaneUI
-
scrollableTabLayoutEnabled
private boolean scrollableTabLayoutEnabled() -
isTabInFirstRun
protected boolean isTabInFirstRun(int tabIndex) -
paintContentBorder
- Overrides:
paintContentBorderin classBasicTabbedPaneUI
-
getContentBorderInsets
Returns the insets (i.e. the width) of the content Border.- Overrides:
getContentBorderInsetsin classBasicTabbedPaneUI
-
getTabAreaInsets
Returns the amount by which the Tab Area is inset.- Overrides:
getTabAreaInsetsin classBasicTabbedPaneUI
-
getTabLabelShiftX
protected int getTabLabelShiftX(int tabPlacement, int tabIndex, boolean isSelected) Returns the amount by which the label should be shifted horizontally.- Overrides:
getTabLabelShiftXin classMetalTabbedPaneUI
-
getTabLabelShiftY
protected int getTabLabelShiftY(int tabPlacement, int tabIndex, boolean isSelected) Returns the amount by which the label should be shifted vertically.- Overrides:
getTabLabelShiftYin classMetalTabbedPaneUI
-
getTabRunOverlay
protected int getTabRunOverlay(int tabPlacement) Returns the amount (in pixels) by which two runs should overlap.- Overrides:
getTabRunOverlayin classMetalTabbedPaneUI
-
shouldPadTabRun
protected boolean shouldPadTabRun(int tabPlacement, int run) This boolean controls wheather the given run should be padded to use up as much space as the others (with more tabs in them).- Overrides:
shouldPadTabRunin classMetalTabbedPaneUI
-
getTabRunIndent
protected int getTabRunIndent(int tabPlacement, int run) Returns the amount by which the run numberrunshould be indented. Add six pixels for every run to make diagonal lines align.- Overrides:
getTabRunIndentin classBasicTabbedPaneUI
-
getTabInsets
Returns the insets for this tab.- Overrides:
getTabInsetsin classBasicTabbedPaneUI
-
getSelectedTabPadInsets
Returns the insets for selected tab.- Overrides:
getSelectedTabPadInsetsin classBasicTabbedPaneUI
-
paintFocusIndicator
protected void paintFocusIndicator(Graphics g, int tabPlacement, Rectangle[] rectangles, int tabIndex, Rectangle iconRect, Rectangle textRect, boolean isSelected) Draws the rectancle around the Tab label which indicates keyboard focus.- Overrides:
paintFocusIndicatorin classMetalTabbedPaneUI
-
paintTabBackground
protected void paintTabBackground(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected) Fills the background of the given tab to make sure overlap of tabs is handled correctly. Note: that tab backgrounds seem to be painted somewhere else, too.- Overrides:
paintTabBackgroundin classMetalTabbedPaneUI
-
paintTabBorder
protected void paintTabBorder(Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected) Paints the border for one tab. Gets the bounds of the tab as parameters. Note that the result is not clipped so you can paint outside that rectangle. Tabs painted later on have a chance to overwrite though.- Overrides:
paintTabBorderin classMetalTabbedPaneUI
-
shouldRotateTabRuns
protected boolean shouldRotateTabRuns(int tabPlacement) Answers wheather tab runs should be rotated. If true, the layout mechanism will move the run containing the selected tab so that it touches the content pane.- Overrides:
shouldRotateTabRunsin classBasicTabbedPaneUI
-
requestFocusForVisibleComponent
private boolean requestFocusForVisibleComponent()
-