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:
javax.swing.SwingConstants
public final class PlasticTabbedPaneUI extends javax.swing.plaf.metal.MetalTabbedPaneUI
The JGoodies Plastic Look&Feel implementation ofTabbedPaneUI
. It differs from its superclassMetalTabbedPaneUI
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 useJTabbedPane 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:
Options
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private static class
PlasticTabbedPaneUI.AbstractRenderer
This is the abstract superclass for all TabbedPane renderers.private static class
PlasticTabbedPaneUI.ArrowButton
private static class
PlasticTabbedPaneUI.BottomEmbeddedRenderer
The renderer for the case where tabs are displayed below the contents and with minimal decoration.private static class
PlasticTabbedPaneUI.BottomRenderer
The renderer for the case where Tabs are below the content and decoration is standard.private static class
PlasticTabbedPaneUI.LeftEmbeddedRenderer
The renderer for tabs on the left with minimal decoration.private static class
PlasticTabbedPaneUI.LeftRenderer
Renderer for tabs on the left with normal decoration.private class
PlasticTabbedPaneUI.MyPropertyChangeHandler
Catches and handles property change events.private static class
PlasticTabbedPaneUI.RightEmbeddedRenderer
The renderer for tabs on the right with minimal decoration.private static class
PlasticTabbedPaneUI.RightRenderer
Renderer for tabs on the right with normal decoration.private class
PlasticTabbedPaneUI.ScrollableTabPanel
private class
PlasticTabbedPaneUI.ScrollableTabSupport
private class
PlasticTabbedPaneUI.ScrollableTabViewport
private static class
PlasticTabbedPaneUI.ScrollTabsBackwardAction
private static class
PlasticTabbedPaneUI.ScrollTabsForwardAction
private class
PlasticTabbedPaneUI.TabbedPaneLayout
Does all the layout work.private class
PlasticTabbedPaneUI.TabbedPaneScrollLayout
private class
PlasticTabbedPaneUI.TabSelectionHandler
private static class
PlasticTabbedPaneUI.TopEmbeddedRenderer
Renderer for tabs on top with minimal decoration.private static class
PlasticTabbedPaneUI.TopRenderer
Renderer for tabs on top with normal decoration.
-
Field Summary
Fields Modifier and Type Field Description private static int
CROP_SEGMENT
private java.lang.Boolean
embeddedTabs
Describes if we paint tabs in an embedded style that is with less decoration; this is false by default.private static boolean
isTabIconsEnabled
Describes if tabs are painted with or without icons.private java.lang.Boolean
noContentBorder
Describes if we paint no content border or not; is false by default.private PlasticTabbedPaneUI.AbstractRenderer
renderer
Holds the renderer that is used to render the tabs.private PlasticTabbedPaneUI.ScrollableTabSupport
tabScroller
For use when tabLayoutPolicy == SCROLL_TAB_LAYOUT.private int[]
xCropLen
private int[]
yCropLen
-
Fields inherited from class javax.swing.plaf.metal.MetalTabbedPaneUI
minTabWidth, selectColor, selectHighlight, tabAreaBackground
-
Fields 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, upKey
-
-
Constructor Summary
Constructors Constructor Description PlasticTabbedPaneUI()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected javax.swing.event.ChangeListener
createChangeListener()
private java.awt.Polygon
createCroppedTabClip(int tabPlacement, java.awt.Rectangle tabRect, int cropline)
protected java.awt.LayoutManager
createLayoutManager()
Creates the layout manager used to set the tab's bounds.protected java.beans.PropertyChangeListener
createPropertyChangeListener()
Creates and answer a handler that listens to property changes.private PlasticTabbedPaneUI.AbstractRenderer
createRenderer(javax.swing.JTabbedPane tabbedPane)
Creates the renderer used to lay out and paint the tabs.static javax.swing.plaf.ComponentUI
createUI(javax.swing.JComponent tabPane)
Creates thePlasticTabbedPaneUI
.private void
doLayout()
private void
embeddedTabsPropertyChanged(java.lang.Boolean newValue)
Updates the embedded tabs property.private void
ensureCurrentLayout()
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.protected java.awt.Insets
getContentBorderInsets(int tabPlacement)
Returns the insets (i.e.protected javax.swing.Icon
getIconForTab(int tabIndex)
Answers the icon for the tab with the specified index.protected java.awt.Insets
getSelectedTabPadInsets(int tabPlacement)
Returns the insets for selected tab.protected java.awt.Insets
getTabAreaInsets(int tabPlacement)
Returns the amount by which the Tab Area is inset.protected java.awt.Rectangle
getTabBounds(int tabIndex, java.awt.Rectangle dest)
protected java.awt.Insets
getTabInsets(int tabPlacement, int tabIndex)
Returns the insets for this tab.protected int
getTabLabelShiftX(int tabPlacement, int tabIndex, boolean isSelected)
Returns the amount by which the label should be shifted horizontally.protected int
getTabLabelShiftY(int tabPlacement, int tabIndex, boolean isSelected)
Returns the amount by which the label should be shifted vertically.protected int
getTabRunIndent(int tabPlacement, int run)
Returns the amount by which the run numberrun
should be indented.protected int
getTabRunOverlay(int tabPlacement)
Returns the amount (in pixels) by which two runs should overlap.private boolean
hasEmbeddedTabs()
Checks and answers if tabs are painted with minimal decoration.private boolean
hasNoContentBorder()
Checks and answers if content border will be painted.protected void
installComponents()
Creates and installs any required subcomponents for the JTabbedPane.protected void
installKeyboardActions()
void
installUI(javax.swing.JComponent c)
Installs the UI.protected boolean
isTabInFirstRun(int tabIndex)
protected void
layoutLabel(int tabPlacement, java.awt.FontMetrics metrics, int tabIndex, java.lang.String title, javax.swing.Icon icon, java.awt.Rectangle tabRect, java.awt.Rectangle iconRect, java.awt.Rectangle textRect, boolean isSelected)
private void
noContentBorderPropertyChanged(java.lang.Boolean newValue)
Updates the no content border property.void
paint(java.awt.Graphics g, javax.swing.JComponent c)
protected void
paintContentBorder(java.awt.Graphics g, int tabPlacement, int selectedIndex)
private void
paintCroppedTabEdge(java.awt.Graphics g, int tabPlacement, int tabIndex, boolean isSelected, int x, int y)
protected void
paintFocusIndicator(java.awt.Graphics g, int tabPlacement, java.awt.Rectangle[] rectangles, int tabIndex, java.awt.Rectangle iconRect, java.awt.Rectangle textRect, boolean isSelected)
Draws the rectancle around the Tab label which indicates keyboard focus.protected void
paintTab(java.awt.Graphics g, int tabPlacement, java.awt.Rectangle[] rects, int tabIndex, java.awt.Rectangle iconRect, java.awt.Rectangle textRect)
protected void
paintTabArea(java.awt.Graphics g, int tabPlacement, int selectedIndex)
protected void
paintTabBackground(java.awt.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 void
paintTabBorder(java.awt.Graphics g, int tabPlacement, int tabIndex, int x, int y, int w, int h, boolean isSelected)
Paints the border for one tab.private boolean
requestFocusForVisibleComponent()
private boolean
scrollableTabLayoutEnabled()
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).protected boolean
shouldRotateTabRuns(int tabPlacement)
Answers wheather tab runs should be rotated.int
tabForCoordinate(javax.swing.JTabbedPane pane, int x, int y)
Returns the tab index which intersects the specified point in the JTabbedPane's coordinate space.private void
tabPlacementChanged()
Updates the renderer and layout.private java.awt.Point
translatePointToTabPanel(int srcx, int srcy, java.awt.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 void
uninstallComponents()
Removes any installed subcomponents from the JTabbedPane.void
uninstallUI(javax.swing.JComponent c)
Uninstalls 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, update
-
Methods 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, uninstallListeners
-
-
-
-
Field Detail
-
isTabIconsEnabled
private static boolean isTabIconsEnabled
Describes if tabs are painted with or without icons.
-
noContentBorder
private java.lang.Boolean 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
private java.lang.Boolean 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
private PlasticTabbedPaneUI.AbstractRenderer renderer
Holds the renderer that is used to render the tabs.
-
tabScroller
private PlasticTabbedPaneUI.ScrollableTabSupport 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:
- Constant Field Values
-
-
Method Detail
-
createUI
public static javax.swing.plaf.ComponentUI createUI(javax.swing.JComponent tabPane)
Creates thePlasticTabbedPaneUI
.- See Also:
ComponentUI.createUI(JComponent)
-
installUI
public void installUI(javax.swing.JComponent c)
Installs the UI.- Overrides:
installUI
in classjavax.swing.plaf.basic.BasicTabbedPaneUI
- See Also:
ComponentUI.installUI(JComponent)
-
uninstallUI
public void uninstallUI(javax.swing.JComponent c)
Uninstalls the UI.- Overrides:
uninstallUI
in classjavax.swing.plaf.basic.BasicTabbedPaneUI
- See Also:
ComponentUI.uninstallUI(JComponent)
-
installComponents
protected void installComponents()
Creates and installs any required subcomponents for the JTabbedPane. Invoked by installUI.- Overrides:
installComponents
in classjavax.swing.plaf.basic.BasicTabbedPaneUI
- See Also:
BasicTabbedPaneUI.installComponents()
-
uninstallComponents
protected void uninstallComponents()
Removes any installed subcomponents from the JTabbedPane. Invoked by uninstallUI.- Overrides:
uninstallComponents
in classjavax.swing.plaf.basic.BasicTabbedPaneUI
- See Also:
BasicTabbedPaneUI.uninstallComponents()
-
installKeyboardActions
protected void installKeyboardActions()
- Overrides:
installKeyboardActions
in classjavax.swing.plaf.basic.BasicTabbedPaneUI
-
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
private PlasticTabbedPaneUI.AbstractRenderer createRenderer(javax.swing.JTabbedPane tabbedPane)
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
protected java.beans.PropertyChangeListener createPropertyChangeListener()
Creates and answer a handler that listens to property changes. Unlike the superclass BasicTabbedPane, the PlasticTabbedPaneUI uses an extended Handler.- Overrides:
createPropertyChangeListener
in classjavax.swing.plaf.basic.BasicTabbedPaneUI
-
createChangeListener
protected javax.swing.event.ChangeListener createChangeListener()
- Overrides:
createChangeListener
in classjavax.swing.plaf.basic.BasicTabbedPaneUI
-
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
private void embeddedTabsPropertyChanged(java.lang.Boolean newValue)
Updates the embedded tabs property. This message is sent by my PropertyChangeHandler whenever the embedded tabs property changes.
-
noContentBorderPropertyChanged
private void noContentBorderPropertyChanged(java.lang.Boolean newValue)
Updates the no content border property. This message is sent by my PropertyChangeHandler whenever the noContentBorder property changes.
-
paint
public void paint(java.awt.Graphics g, javax.swing.JComponent c)
- Overrides:
paint
in classjavax.swing.plaf.metal.MetalTabbedPaneUI
-
paintTab
protected void paintTab(java.awt.Graphics g, int tabPlacement, java.awt.Rectangle[] rects, int tabIndex, java.awt.Rectangle iconRect, java.awt.Rectangle textRect)
- Overrides:
paintTab
in classjavax.swing.plaf.basic.BasicTabbedPaneUI
-
createCroppedTabClip
private java.awt.Polygon createCroppedTabClip(int tabPlacement, java.awt.Rectangle tabRect, int cropline)
-
paintCroppedTabEdge
private void paintCroppedTabEdge(java.awt.Graphics g, int tabPlacement, int tabIndex, boolean isSelected, int x, int y)
-
ensureCurrentLayout
private void ensureCurrentLayout()
-
tabForCoordinate
public int tabForCoordinate(javax.swing.JTabbedPane pane, int x, int y)
Returns the tab index which intersects the specified point in the JTabbedPane's coordinate space.- Overrides:
tabForCoordinate
in classjavax.swing.plaf.basic.BasicTabbedPaneUI
-
getTabBounds
protected java.awt.Rectangle getTabBounds(int tabIndex, java.awt.Rectangle dest)
- Overrides:
getTabBounds
in classjavax.swing.plaf.basic.BasicTabbedPaneUI
-
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
private java.awt.Point translatePointToTabPanel(int srcx, int srcy, java.awt.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. This is used for SCROLL_TAB_LAYOUT ONLY.
-
paintTabArea
protected void paintTabArea(java.awt.Graphics g, int tabPlacement, int selectedIndex)
- Overrides:
paintTabArea
in classjavax.swing.plaf.basic.BasicTabbedPaneUI
-
layoutLabel
protected void layoutLabel(int tabPlacement, java.awt.FontMetrics metrics, int tabIndex, java.lang.String title, javax.swing.Icon icon, java.awt.Rectangle tabRect, java.awt.Rectangle iconRect, java.awt.Rectangle textRect, boolean isSelected)
- Overrides:
layoutLabel
in classjavax.swing.plaf.basic.BasicTabbedPaneUI
-
getIconForTab
protected javax.swing.Icon getIconForTab(int tabIndex)
Answers the icon for the tab with the specified index. In case, we have globally switched of the use tab icons, we answernull
if and only if we have a title.- Overrides:
getIconForTab
in classjavax.swing.plaf.basic.BasicTabbedPaneUI
-
createLayoutManager
protected java.awt.LayoutManager createLayoutManager()
Creates the layout manager used to set the tab's bounds.- Overrides:
createLayoutManager
in classjavax.swing.plaf.metal.MetalTabbedPaneUI
-
scrollableTabLayoutEnabled
private boolean scrollableTabLayoutEnabled()
-
isTabInFirstRun
protected boolean isTabInFirstRun(int tabIndex)
-
paintContentBorder
protected void paintContentBorder(java.awt.Graphics g, int tabPlacement, int selectedIndex)
- Overrides:
paintContentBorder
in classjavax.swing.plaf.basic.BasicTabbedPaneUI
-
getContentBorderInsets
protected java.awt.Insets getContentBorderInsets(int tabPlacement)
Returns the insets (i.e. the width) of the content Border.- Overrides:
getContentBorderInsets
in classjavax.swing.plaf.basic.BasicTabbedPaneUI
-
getTabAreaInsets
protected java.awt.Insets getTabAreaInsets(int tabPlacement)
Returns the amount by which the Tab Area is inset.- Overrides:
getTabAreaInsets
in classjavax.swing.plaf.basic.BasicTabbedPaneUI
-
getTabLabelShiftX
protected int getTabLabelShiftX(int tabPlacement, int tabIndex, boolean isSelected)
Returns the amount by which the label should be shifted horizontally.- Overrides:
getTabLabelShiftX
in classjavax.swing.plaf.metal.MetalTabbedPaneUI
-
getTabLabelShiftY
protected int getTabLabelShiftY(int tabPlacement, int tabIndex, boolean isSelected)
Returns the amount by which the label should be shifted vertically.- Overrides:
getTabLabelShiftY
in classjavax.swing.plaf.metal.MetalTabbedPaneUI
-
getTabRunOverlay
protected int getTabRunOverlay(int tabPlacement)
Returns the amount (in pixels) by which two runs should overlap.- Overrides:
getTabRunOverlay
in classjavax.swing.plaf.metal.MetalTabbedPaneUI
-
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:
shouldPadTabRun
in classjavax.swing.plaf.metal.MetalTabbedPaneUI
-
getTabRunIndent
protected int getTabRunIndent(int tabPlacement, int run)
Returns the amount by which the run numberrun
should be indented. Add six pixels for every run to make diagonal lines align.- Overrides:
getTabRunIndent
in classjavax.swing.plaf.basic.BasicTabbedPaneUI
-
getTabInsets
protected java.awt.Insets getTabInsets(int tabPlacement, int tabIndex)
Returns the insets for this tab.- Overrides:
getTabInsets
in classjavax.swing.plaf.basic.BasicTabbedPaneUI
-
getSelectedTabPadInsets
protected java.awt.Insets getSelectedTabPadInsets(int tabPlacement)
Returns the insets for selected tab.- Overrides:
getSelectedTabPadInsets
in classjavax.swing.plaf.basic.BasicTabbedPaneUI
-
paintFocusIndicator
protected void paintFocusIndicator(java.awt.Graphics g, int tabPlacement, java.awt.Rectangle[] rectangles, int tabIndex, java.awt.Rectangle iconRect, java.awt.Rectangle textRect, boolean isSelected)
Draws the rectancle around the Tab label which indicates keyboard focus.- Overrides:
paintFocusIndicator
in classjavax.swing.plaf.metal.MetalTabbedPaneUI
-
paintTabBackground
protected void paintTabBackground(java.awt.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:
paintTabBackground
in classjavax.swing.plaf.metal.MetalTabbedPaneUI
-
paintTabBorder
protected void paintTabBorder(java.awt.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:
paintTabBorder
in classjavax.swing.plaf.metal.MetalTabbedPaneUI
-
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:
shouldRotateTabRuns
in classjavax.swing.plaf.basic.BasicTabbedPaneUI
-
requestFocusForVisibleComponent
private boolean requestFocusForVisibleComponent()
-
-