站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > NetBeans API Javadoc (Current Development Version)

BasicTabDisplayerUI (Tab Control) - NetBeans API Javadoc (Current Development Version)

org.netbeans.swing.tabcontrol 1.8

org.netbeans.swing.tabcontrol.plaf
Class BasicTabDisplayerUI

java.lang.Object
  extended by javax.swing.plaf.ComponentUI
      extended by org.netbeans.swing.tabcontrol.TabDisplayerUI
          extended by org.netbeans.swing.tabcontrol.plaf.AbstractTabDisplayerUI
              extended by org.netbeans.swing.tabcontrol.plaf.BasicTabDisplayerUI
Direct Known Subclasses:
BasicScrollingTabDisplayerUI

public abstract class BasicTabDisplayerUI
extends AbstractTabDisplayerUI

Base class for tab displayer UIs which use cell renderers to display tabs. This class does not contain much logic itself, but rather acts to connect events and data from various objects relating to the tab displayer, which it creates and installs. Basically, the things that are involved are:

The usage pattern of this class is similar to other 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.


Nested Class Summary
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
           
 
Nested classes/interfaces inherited from class org.netbeans.swing.tabcontrol.plaf.AbstractTabDisplayerUI
AbstractTabDisplayerUI.DisplayerHierarchyListener, AbstractTabDisplayerUI.DisplayerPropertyChangeListener, AbstractTabDisplayerUI.ModelListener
 
Field Summary
protected  TabCellRenderer defaultRenderer
           
protected  int repaintPolicy
           
protected  TabState tabState
           
 
Fields inherited from class org.netbeans.swing.tabcontrol.plaf.AbstractTabDisplayerUI
componentListener, hierarchyListener, layoutModel, modelListener, mouseListener, propertyChangeListener, selectionListener
 
Fields inherited from class org.netbeans.swing.tabcontrol.TabDisplayerUI
displayer, selectionModel
 
Constructor Summary
BasicTabDisplayerUI(TabDisplayer displayer)
           
 
Method Summary
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.
protected  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()
           
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)
           
 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.
 
Methods inherited from class org.netbeans.swing.tabcontrol.plaf.AbstractTabDisplayerUI
createComponentListener, createFont, createHierarchyListener, createLayoutModel, createSelectionModel, installListeners, installUI, registerShortcuts, toDropPoint, uninstallListeners, uninstallUI, unregisterShortcuts
 
Methods inherited from class org.netbeans.swing.tabcontrol.TabDisplayerUI
getButtonIcon, makeTabVisible, postTabAction, shouldPerformAction
 
Methods inherited from class javax.swing.plaf.ComponentUI
contains, createUI, getAccessibleChild, getAccessibleChildrenCount, getMaximumSize, getMinimumSize, getPreferredSize, update
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

tabState

protected TabState tabState

defaultRenderer

protected TabCellRenderer defaultRenderer

repaintPolicy

protected int repaintPolicy
Constructor Detail

BasicTabDisplayerUI

public BasicTabDisplayerUI(TabDisplayer displayer)
Method Detail

install

protected void install()
Overridden to initialize the tabState and defaultRenderer.

Overrides:
install in class AbstractTabDisplayerUI

uninstall

protected void uninstall()
Description copied from class: AbstractTabDisplayerUI
Called after uninstalling the mouse listener and selection model, but before references to that or the layout model or displayer have been nulled. Subclasses may use this method to do any cleanup they need to do at uninstall time.

Overrides:
uninstall in class AbstractTabDisplayerUI

createTabState

protected TabState createTabState()
Create a TabState instance. TabState manages the state of tabs - that is, which one contains the mouse, which one is pressed, and so forth, providing methods such as 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.

Returns:
An implementation of TabState
See Also:
BasicTabDisplayerUI.BasicTabState, BasicScrollingTabDisplayerUI.ScrollingTabState

createDefaultRenderer

protected abstract TabCellRenderer createDefaultRenderer()
Create the default cell renderer for this control. If it is desirable to have more than one renderer, override getTabCellRenderer()


getTabAreaInsets

public abstract Insets getTabAreaInsets()
Return a set of insets defining the margins into which tabs should not be painted. Subclasses that want to paint some controls to the right of the tabs should include space for those controls in these insets. If a bottom margin under the tabs is to be painted, include that as well.


getTabCellRenderer

protected TabCellRenderer getTabCellRenderer(int tab)
Get the cell renderer for a given tab. The default implementation simply returns the renderer created by createDefaultRenderer().


getTabsVisibleArea

protected final 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. The rectangle is determined by what is returned by getTabAreaInsets() - this is simply a convenience method for finding the rectange into which tabs will be painted.


createMouseListener

protected MouseListener createMouseListener()
Description copied from class: AbstractTabDisplayerUI
Create the mouse listener that will be responsible for changing the selection on mouse events, triggering repaints on mouse enter/exit/motion, etc. The installation code will detect if the resulting listener also implements MouseWheelListener or MouseMotionListener, and if so, will add it as such.

Specified by:
createMouseListener in class AbstractTabDisplayerUI
Returns:
A mouse listener, which may also implement MouseMotionListener and/or MouseWheelListener

createPropertyChangeListener

protected PropertyChangeListener createPropertyChangeListener()
Description copied from class: AbstractTabDisplayerUI
Create a PropertyChangeListener which listens on any interesting properties of the control

Overrides:
createPropertyChangeListener in class AbstractTabDisplayerUI

getExactTabIndication

public Polygon getExactTabIndication(int index)
Description copied from class: TabDisplayerUI
Get a shape representing the exact outline of the numbered tab. 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 depend on this.

Specified by:
getExactTabIndication in class TabDisplayerUI

getInsertTabIndication

public Polygon getInsertTabIndication(int index)
Description copied from class: TabDisplayerUI
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.

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.

Specified by:
getInsertTabIndication in class TabDisplayerUI
Returns:
Shape representing feedback shape

tabForCoordinate

public int tabForCoordinate(Point p)
Description copied from class: TabDisplayerUI
Returns the index of the tab at the passed point, or -1 if no tab is at that location. Note that this method may return -1 for coordinates which are within a tab as returned by getTabRect(), but are not within the visible shape of the tab as the UI paints it.

Specified by:
tabForCoordinate in class TabDisplayerUI

getTabRect

public Rectangle getTabRect(int idx,
                            Rectangle rect)
Description copied from class: TabDisplayerUI
Configure the passed rectangle with the shape of the tab at the given index.

Specified by:
getTabRect in class TabDisplayerUI

createImageOfTab

public Image createImageOfTab(int index)
Description copied from class: TabDisplayerUI
Returns an image suitable for use in drag and drop operations, representing the tab at this index. The default implementation returns null.

Overrides:
createImageOfTab in class TabDisplayerUI
Parameters:
index - A tab index

dropIndexOfPoint

public int dropIndexOfPoint(Point p)
Description copied from class: AbstractTabDisplayerUI
A very basic implementation of dropIndexOfPoint, which simply iterates all of the tab rectangles to see if they contain the point. It is preferred to override this and provide a more efficient implementation unless the UI is not designed to display more than a few tabs.

Overrides:
dropIndexOfPoint in class AbstractTabDisplayerUI
Parameters:
p - A point
Returns:
The index, or -1 if none

isAntialiased

protected boolean isAntialiased()

paint

public final void paint(Graphics g,
                        JComponent c)
Paints the tab control. Calls paintBackground(), then paints the tabs using their cell renderers, then calls paintAfterTabs

Overrides:
paint in class ComponentUI

paintBackground

protected void paintBackground(Graphics g)
Fill in the background of the component prior to painting the tabs. The default implementation does nothing. If it's just a matter of filling in a background color, setOpaque (true) on the displayer, and ComponentUI.update() will take care of the rest.


paintAfterTabs

protected void paintAfterTabs(Graphics g)
Override this method to provide painting of areas outside the tabs rectangle, such as margins and controls


getFirstVisibleTab

protected int getFirstVisibleTab()
Scrollable implementations will override this method to provide the first visible (even if clipped) tab. The default implementation returns 0 if there is at least one tab in the data model, or -1 to indicate the model is completely empty


getLastVisibleTab

protected int getLastVisibleTab()
Scrollable implementations will override this method to provide the last visible (even if clipped) tab. The default implementation returns 0 if there is at least one tab in the data model, or -1 to indicate the model is completely empty


createSelectionListener

protected ChangeListener createSelectionListener()
Description copied from class: AbstractTabDisplayerUI
Create a ChangeListener to be attached to the selection model. This listener will be responsible for repainting the appropriate areas on selection changes.

Specified by:
createSelectionListener in class AbstractTabDisplayerUI
Returns:
A changeListener that will be notified of selection changes

getLastKnownMouseLocation

protected final Point getLastKnownMouseLocation()

processMouseWheelEvent

protected void processMouseWheelEvent(MouseWheelEvent e)
Convenience method to override for handling mouse wheel events. The defualt implementation does nothing.


requestAttention

protected final void requestAttention(int tab)
Specified by:
requestAttention in class TabDisplayerUI

cancelRequestAttention

protected final void cancelRequestAttention(int tab)
Specified by:
cancelRequestAttention in class TabDisplayerUI

modelChanged

protected void modelChanged()
Description copied from class: AbstractTabDisplayerUI
Convenience method called by ModelListener.stateChanged() when the data model changes. Eliminates the need for custom subclasses where the only purpose is to discard some small amount of cached data. The default implementation simply calls displayer.repaint().

Overrides:
modelChanged in class AbstractTabDisplayerUI

createRepaintPolicy

protected int createRepaintPolicy()
Create the policy that will determine what types of events trigger a repaint of one or more tabs. This is a bitmask composed of constants defined in TabState. The default value is
  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;

Returns:
The repaint policy that should be used in conjunction with mouse events to determine when a repaint is needed.

getTabRectForRepaint

protected Rectangle getTabRectForRepaint(int tab,
                                         Rectangle rect)
Returns:
Rectangle of the tab to be repainted

createModelListener

protected AbstractTabDisplayerUI.ModelListener createModelListener()
Description copied from class: AbstractTabDisplayerUI
Create a listener on the data model that triggers repaints on appropriate changes.

Overrides:
createModelListener in class AbstractTabDisplayerUI

org.netbeans.swing.tabcontrol 1.8

Built on May 28 2007.  |  Portions Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.