public abstract class BasicTabDisplayerUI extends AbstractTabDisplayerUI
TabLayoutModel
) - A data model providing the positions and sizes of tabsTabState
) - A data model which tracks state data (selected, pressed, etc.)
for each tab, and can be queried when a tab is painted to determine how that should be done.SingleSelectionModel
) - Which tracks which tab is selectedTabDisplayer
component itselfTabDisplayer
's data model, which contains the list of tab names, their icons and
tooltips and the user object (or Component
) they identifyTabCellRenderer
, which is what will actually paint the tabs, and which
is also responsible for providing some miscellaneous data such as the number of
pixels the layout model should add to tab widths to make room for decorations,
etc.ComponentUI
subclasses -
ComponentUI.installUI(javax.swing.JComponent)
is called via JComponent.updateUI()
. installUI
initializes protected fields which
subclasses will need, in a well defined way; abstract methods are provided for subclasses to
create these objects (such as the things listed above), and convenience implementations of some
are provided. Under no circumstances should subclasses modify these protected fields -
due to the circuitousness of the way Swing installs UIs, they cannot be declared final, but should
be treated as read-only.
The goal of this class is to make it quite easy to implement new appearances
for tabs: To create a new appearance, implement a TabCellRenderer
that can
paint individual tabs as desired. This is made even easier via the
TabPainter
interface - simply create the painting logic needed there. Then
subclass BasicTabDisplayerUI
and include any painting logic for the background,
scroll buttons, etc. needed. A good example is AquaEditorTabDisplayerUI
.
Modifier and Type | Class and Description |
---|---|
protected class |
BasicTabDisplayerUI.BasicDisplayerMouseListener |
protected class |
BasicTabDisplayerUI.BasicModelListener
Listener on data model which will pass modified indices to the
TabState object, so it can update which tab indices are flashing in
"attention" mode, if any.
|
protected class |
BasicTabDisplayerUI.BasicSelectionListener
A simple selection listener implementation which updates the TabState model
with the new selected index from the selection model when it changes.
|
protected class |
BasicTabDisplayerUI.BasicTabState |
AbstractTabDisplayerUI.DisplayerHierarchyListener, AbstractTabDisplayerUI.DisplayerPropertyChangeListener, AbstractTabDisplayerUI.ModelListener
Modifier and Type | Field and Description |
---|---|
protected TabCellRenderer |
defaultRenderer |
protected int |
repaintPolicy |
protected TabState |
tabState |
componentListener, hierarchyListener, layoutModel, modelListener, mouseListener, propertyChangeListener, selectionListener
displayer, selectionModel
Constructor and Description |
---|
BasicTabDisplayerUI(TabDisplayer displayer) |
Modifier and Type | Method and Description |
---|---|
protected void |
cancelRequestAttention(int tab) |
protected abstract TabCellRenderer |
createDefaultRenderer()
Create the default cell renderer for this control.
|
Image |
createImageOfTab(int index)
Returns an image suitable for use in drag and drop operations,
representing the tab at this index.
|
protected AbstractTabDisplayerUI.ModelListener |
createModelListener()
Create a listener on the data model that triggers repaints on appropriate
changes.
|
protected MouseListener |
createMouseListener()
Create the mouse listener that will be responsible for changing the
selection on mouse events, triggering repaints on mouse enter/exit/motion, etc.
|
protected PropertyChangeListener |
createPropertyChangeListener()
Create a PropertyChangeListener which listens on any interesting
properties of the control
|
protected int |
createRepaintPolicy()
Create the policy that will determine what types of events trigger a repaint of one or more tabs.
|
protected ChangeListener |
createSelectionListener()
Create a
ChangeListener to be attached to the selection model. |
protected TabState |
createTabState()
Create a TabState instance.
|
int |
dropIndexOfPoint(Point p)
A very basic implementation of dropIndexOfPoint, which simply iterates
all of the tab rectangles to see if they contain the point.
|
Polygon |
getExactTabIndication(int index)
Get a shape representing the exact outline of the numbered tab.
|
protected int |
getFirstVisibleTab()
Scrollable implementations will override this method to provide the first
visible (even if clipped) tab.
|
Polygon |
getInsertTabIndication(int index)
Get a shape representing the area of visual feedback during a drag and
drop operation, which represents where a tab will be inserted if a drop
operation is performed over the indicated tab.
|
protected Point |
getLastKnownMouseLocation() |
protected int |
getLastVisibleTab()
Scrollable implementations will override this method to provide the last
visible (even if clipped) tab.
|
abstract Insets |
getTabAreaInsets()
Return a set of insets defining the margins into which tabs should not be
painted.
|
TabCellRenderer |
getTabCellRenderer(int tab)
Get the cell renderer for a given tab.
|
Rectangle |
getTabRect(int idx,
Rectangle rect)
Configure the passed rectangle with the shape of the tab at the given
index.
|
protected Rectangle |
getTabRectForRepaint(int tab,
Rectangle rect) |
protected void |
getTabsVisibleArea(Rectangle rect)
Set the passed rectangle's bounds to the recangle in which tabs will be
painted; if your look and feel reserves some part of the tab area for its
own painting.
|
protected void |
install()
Overridden to initialize the
tabState and defaultRenderer . |
protected boolean |
isAntialiased()
Deprecated.
|
protected void |
modelChanged()
Convenience method called by ModelListener.stateChanged() when the data model changes.
|
void |
paint(Graphics g,
JComponent c)
Paints the tab control.
|
protected void |
paintAfterTabs(Graphics g)
Override this method to provide painting of areas outside the tabs
rectangle, such as margins and controls
|
protected void |
paintBackground(Graphics g)
Fill in the background of the component prior to painting the tabs.
|
protected void |
processMouseWheelEvent(MouseWheelEvent e)
Convenience method to override for handling mouse wheel events.
|
protected void |
requestAttention(int tab) |
protected void |
setAttentionHighlight(int tab,
boolean highlight)
Turn tab highlight on/off
|
int |
tabForCoordinate(Point p)
Returns the index of the tab at the passed point, or -1 if no tab is at
that location.
|
protected void |
uninstall()
Called after uninstalling the mouse listener and selection model, but
before references to that or the layout model or displayer have been
nulled.
|
createComponentListener, createFont, createHierarchyListener, createLayoutModel, createSelectionModel, installListeners, installUI, registerShortcuts, toDropPoint, uninstallListeners, uninstallUI, unregisterShortcuts
autoscroll, getAutoscrollInsets, getButtonIcon, getTxtFont, isTabBusy, makeTabVisible, postTabAction, shouldPerformAction, shouldPerformAction
contains, createUI, getAccessibleChild, getAccessibleChildrenCount, getBaseline, getBaselineResizeBehavior, getMaximumSize, getMinimumSize, getPreferredSize, update
protected TabState tabState
protected TabCellRenderer defaultRenderer
protected int repaintPolicy
public BasicTabDisplayerUI(TabDisplayer displayer)
protected void install()
tabState
and defaultRenderer
.install
in class AbstractTabDisplayerUI
protected void uninstall()
AbstractTabDisplayerUI
uninstall
in class AbstractTabDisplayerUI
protected TabState createTabState()
setMouseInTab(int tab)
. Its getState() method returns a bitmask of
states a tab may have which affect the way it is painted.
Usage: It is expected that UIs will subclass TabState, to implement the
repaint methods, and possibly override getState(int tab)
to mix
additional state bits into the bitmask. For example, scrollable tabs have the
possible states CLIP_LEFT and CLIP_RIGHT; BasicScrollingTabDisplayerUI's
implementation of this determines these states by consulting its layout model, and
adds them in when appropriate.
BasicTabDisplayerUI.BasicTabState
,
BasicScrollingTabDisplayerUI.ScrollingTabState
protected abstract TabCellRenderer createDefaultRenderer()
public abstract Insets getTabAreaInsets()
public TabCellRenderer getTabCellRenderer(int tab)
tab
- protected final void getTabsVisibleArea(Rectangle rect)
protected MouseListener createMouseListener()
AbstractTabDisplayerUI
createMouseListener
in class AbstractTabDisplayerUI
protected PropertyChangeListener createPropertyChangeListener()
AbstractTabDisplayerUI
createPropertyChangeListener
in class AbstractTabDisplayerUI
public Polygon getExactTabIndication(int index)
TabDisplayerUI
EqualPolygon
from this method; other implementations may
return what they want, but for performance reasons, it is highly
desirable that the shape object returned honor equals()
and
hashCode()
, as there are significant optimizations in
NetBeans' drag and drop support that depend on this.getExactTabIndication
in class TabDisplayerUI
public Polygon getInsertTabIndication(int index)
TabDisplayerUI
The implementations in
the package will return instances of EqualPolygon
from this
method; other implementations may return what they want, but for
performance reasons, it is highly desirable that the shape object
returned honor equals()
and hashCode()
, as
there are significant optimizations in NetBeans' drag and drop support
that depened on this.
getInsertTabIndication
in class TabDisplayerUI
public int tabForCoordinate(Point p)
TabDisplayerUI
tabForCoordinate
in class TabDisplayerUI
public Rectangle getTabRect(int idx, Rectangle rect)
TabDisplayerUI
getTabRect
in class TabDisplayerUI
public Image createImageOfTab(int index)
TabDisplayerUI
createImageOfTab
in class TabDisplayerUI
index
- A tab indexpublic int dropIndexOfPoint(Point p)
AbstractTabDisplayerUI
dropIndexOfPoint
in class AbstractTabDisplayerUI
p
- A point@Deprecated protected boolean isAntialiased()
GraphicsUtils.configureDefaultRenderingHints(java.awt.Graphics)
instead.public final void paint(Graphics g, JComponent c)
paint
in class ComponentUI
protected void paintBackground(Graphics g)
protected void paintAfterTabs(Graphics g)
protected int getFirstVisibleTab()
protected int getLastVisibleTab()
protected ChangeListener createSelectionListener()
AbstractTabDisplayerUI
ChangeListener
to be attached to the selection model. This
listener will be responsible for repainting the appropriate areas on selection changes.createSelectionListener
in class AbstractTabDisplayerUI
protected final Point getLastKnownMouseLocation()
protected void processMouseWheelEvent(MouseWheelEvent e)
protected final void requestAttention(int tab)
requestAttention
in class TabDisplayerUI
protected final void cancelRequestAttention(int tab)
cancelRequestAttention
in class TabDisplayerUI
protected final void setAttentionHighlight(int tab, boolean highlight)
TabDisplayerUI
setAttentionHighlight
in class TabDisplayerUI
protected void modelChanged()
AbstractTabDisplayerUI
displayer.repaint()
.modelChanged
in class AbstractTabDisplayerUI
protected int createRepaintPolicy()
TabState.REPAINT_SELECTION_ON_ACTIVATION_CHANGE | TabState.REPAINT_ON_SELECTION_CHANGE | TabState.REPAINT_ON_MOUSE_ENTER_TAB | TabState.REPAINT_ON_MOUSE_ENTER_CLOSE_BUTTON | TabState.REPAINT_ON_MOUSE_PRESSED;
protected Rectangle getTabRectForRepaint(int tab, Rectangle rect)
protected AbstractTabDisplayerUI.ModelListener createModelListener()
AbstractTabDisplayerUI
createModelListener
in class AbstractTabDisplayerUI