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

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

org.netbeans.swing.tabcontrol 1.8

org.netbeans.swing.tabcontrol.plaf
Class TabState

java.lang.Object
  extended by org.netbeans.swing.tabcontrol.plaf.TabState
Direct Known Subclasses:
BasicTabDisplayerUI.BasicTabState

public abstract class TabState
extends Object

Used by BasicTabDisplayerUI and its subclasses. Tracks and manages the state of tabs, mainly which one currently contains the mouse, if the mouse is in the close button, if the tab is adjacent to a selected tab, if it is leftmost, rightmost, active, etc. This class hides most of the complexity of deciding what mouse events should trigger a repaint of what areas in an optimized way. It provides setters which a mouse listener can call to indicate that the mouse has, say, moved into a tab, or from one tab to another, or the selection has changed, etc.

Essentially, this class is fed indices of tabs that have various states (selected, contains mouse, etc.), figures out if this affects one tab, two tabs (a different tab had the state, such as the mouse moving from one tab to another) or all tabs (activated). It determines a change type, and consults a repaint policy (an integer bitmask) to decide if one, both, all or no tabs should be repainted.

The typical use case is to implement a subclass, and override getState() to mix in bitmasks for things like whether a tab is clipped, etc. - things the base implementation can't know about.

Subclasses implement the repaintTab() method to do the actual repainting, and implement getRepaintPolicy(). The repainting will be called if an event happens that changes the state in a way that the repaint policy bitmask indicates should cause a repaint.

BasicTabDisplayerUI implements a mouse listener which will call the appropriate methods when the mouse enters/exits tabs, etc.

Details

State is composed as an integer bitmask which covers all of the supported states of a tab that may affect the way they paint. These are also the values that are passed to the methods of a TabCellRenderer to tell it how to paint itself. Two other integer bitmasks are used: The changeType, which indicates whether a change was from one tab to another tab, one tab to no tab (i.e. selection set to -1), one tab to the same tab (i.e. the mouse moved out of the tab control, and so the tab with the mouse in it is now no tab). RepaintPolicy is an integer bitmask composed of conditions under which the control should repaint one or all tabs, and determines what types of changes actually trigger repaints.

Subclasses are expected to override getState() to provide information about non-mouse-or-focus related states, such as clipping of scrollable tabs. Predefined states for tabs are: CLIP_RIGHT, CLIP_LEFT, ARMED, PRESSED, SELECTED, ACTIVE, NOT_ONSCREEN, LEFTMOST, RIGHTMOST, CLOSE_BUTTON_ARMED, BEFORE_SELECTED, AFTER_SELECTED, MOUSE_IN_TABS_AREA, MOUSE_PRESSED_IN_CLOSE_BUTTON. Subclasses must handle returning the following states if they wish to, which are not handled directly in TabState: LEFTMOST, RIGHTMOST, CLIP_LEFT, CLIP_RIGHT, NOT_ONSCREEN.

Most of the states are fairly self-explanatory; NOT_ONSCREEN is useful as an optimization so that no work is done for events that would try to produce a repaint for something not visible; CLIP_* refers to the case in scrollable tab UIs, in which a tab may only be partially visible; MOUSE_PRESSED_IN_CLOSE_BUTTON is distinct because the CLOSE_BUTTON_ARMED state will be reset if the mouse moves out of the close button area, but UIs should perform a close action if the mouse was pressed over the close button, moved away from the close button and then back to it, so this state preserves the information that the originating location of a mouse press was in the close button.


Field Summary
static int ACTIVE
          Bitmask indicating the tab is activated
static int AFTER_SELECTED
          Bitmask indicating that the tab's index is that of the selected index plus one
static int ALL_TABS
          Change type indicating one of the boolean state changes, such as STATE_ACTIVE
static int ARMED
          Bitmask indicating the tab contains the mouse
static int ATTENTION
          Bitmask indicating that the tab is in "attention" mode - blinking or flashing to get the user's attention.
static int BEFORE_ARMED
          Bitmask indicating that the tab's index is that of the armed index less one
static int BEFORE_SELECTED
          Bitmask indicating that the tab's index is that of the selected index less one
static int CHANGE_NONE_TO_TAB
          Change type indicating that a state was added that no tab previously had
static int CHANGE_TAB_TO_NONE
          Change type indicating a change happened (such as the mouse leaving a tab) such that now no tab has the state previously held by the affected tab
static int CHANGE_TAB_TO_SELF
           
static int CHANGE_TAB_TO_TAB
          Change type indicating a change of state for two tabs
static int CLIP_LEFT
          Bitmask for state of tabs clipped on the right side - that is, partially displayed
static int CLIP_RIGHT
          Bitmask for state of tabs clipped on the right side - that is, partially displayed
static int CLOSE_BUTTON_ARMED
          Bitmask indicating that the tab contains the mouse and the mouse is in the close button
static int LEFTMOST
          Bitmask indicating the tab is at the extreme left and not clipped
static int MOUSE_IN_TABS_AREA
          Bitmask indicating that the mouse is in the tabs area
static int MOUSE_PRESSED_IN_CLOSE_BUTTON
          Bitmask indicating that the mouse is inside the close button and has been pressed.
static int NO_CHANGE
          Change type indicating no change happened (i.e.
static int NOT_ONSCREEN
          State bitmask indicating a tab is not displayed at all and shouldn't be painted.
static int PRESSED
          Bitmask indicating the tab contains the mouse and the mouse button has been pressed
static int REPAINT_ALL_ON_MOUSE_ENTER_TABS_AREA
          Repaint policy bitmask indicating that all tabs should be repainted whenever the mouse enters or leaves the area in which tabs are painted
static int REPAINT_ALL_TABS_ON_ACTIVATION_CHANGE
          Repaint policy bitmask indicating that all tabs should be repainted when the activated state changes
static int REPAINT_ALL_TABS_ON_SELECTION_CHANGE
          Repaint policy bitmask indicating that all tabs should be repainted whenever the selection changes
static int REPAINT_ON_CLOSE_BUTTON_PRESSED
          Repaint policy bitmask indicating that the tab should be repainted when the close button is pressed
static int REPAINT_ON_MOUSE_ENTER_CLOSE_BUTTON
          Repaint policy bitmask indicating that the tab should be repainted when the mouse enters or exits the close button region
static int REPAINT_ON_MOUSE_ENTER_TAB
          Repaint policy bitmask indicating that a tab should be repainted whenever the mouse enters or exits it
static int REPAINT_ON_MOUSE_PRESSED
          Repaint policy bitmask indicating that the tab should be repainted on mouse pressed events
static int REPAINT_ON_SELECTION_CHANGE
          Repaint policy bitmask indicating that a tab should be repainted when it becomes selected/unselected
static int REPAINT_SELECTION_ON_ACTIVATION_CHANGE
          Repaint policy bitmask indicating that the selected tab should be repainted when the activated state changes
static int RIGHTMOST
          Bitmask indicating the tab is at the extreme right and not clipped
static int SELECTED
          Bitmask indicating the tab is selected
static int STATE_LAST
          Indicates the last constant defined - renderers that wish to add their own bitmasks should use multiples of this number
 
Constructor Summary
TabState()
           
 
Method Summary
 void addAlarmTab(int alarmTab)
          Add a tab to the list of those which should "flash" or otherwise give some notification to the user to get their attention
protected  void change(int lastTab, int currTab, int type, int changeType)
          Called when a setter for a tab index has produced a change in a state-affecting property, such as which tab contains the mouse.
 void clearTransientStates()
          Clear all mouse position related state information.
abstract  int getRepaintPolicy(int tab)
          Get the repaint policy that will be used to determine what tabs to repaint, based on state changes.
 int getState(int tab)
          Get the state of a given tab.
protected  void maybeRepaint(int tab, int type)
           
protected  void possibleChange(boolean prevVal, boolean currVal, int type)
           
protected  void possibleChange(int lastTab, int currTab, int type)
           
 void removeAlarmTab(int alarmTab)
          Remove a tab to the list of those which should "flash" or otherwise give some notification to the user to get their attention
protected abstract  void repaintAllTabs()
           
protected abstract  void repaintTab(int tab)
           
 boolean setActive(boolean b)
          Set the condition for all tabs of the component being activated.
 int setCloseButtonContainsMouse(int i)
          Set the index of the tab whose close button contains the mouse cursor.
 int setContainsMouse(int i)
          Set the index of the tab which currently contains the mouse cursor.
 boolean setMouseInTabsArea(boolean b)
          Set the condition for all tabs of the mouse being in the tabs area.
 int setMousePressedInCloseButton(int i)
          Set the index of the tab in which the mouse button has been pressed in the close button.
 int setPressed(int i)
          Set the index of the tab over which a mouse button has been pressed.
 int setSelected(int i)
          Set the index of the tab which is currently selected.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

CLIP_RIGHT

public static final int CLIP_RIGHT
Bitmask for state of tabs clipped on the right side - that is, partially displayed

See Also:
Constant Field Values

CLIP_LEFT

public static final int CLIP_LEFT
Bitmask for state of tabs clipped on the right side - that is, partially displayed

See Also:
Constant Field Values

ARMED

public static final int ARMED
Bitmask indicating the tab contains the mouse

See Also:
Constant Field Values

PRESSED

public static final int PRESSED
Bitmask indicating the tab contains the mouse and the mouse button has been pressed

See Also:
Constant Field Values

SELECTED

public static final int SELECTED
Bitmask indicating the tab is selected

See Also:
Constant Field Values

ACTIVE

public static final int ACTIVE
Bitmask indicating the tab is activated

See Also:
Constant Field Values

NOT_ONSCREEN

public static final int NOT_ONSCREEN
State bitmask indicating a tab is not displayed at all and shouldn't be painted. Implementations may more simply avoid not painting a tab by not including it in the range returned by getFirstVisibleTab()/getLastVisibleTab(). This state exists so that implementations have the option of returning the entire range of tabs as visible and determining if one is truly visble or not in getTabState() - sometimes doing it this way will be less expensive.

See Also:
Constant Field Values

LEFTMOST

public static final int LEFTMOST
Bitmask indicating the tab is at the extreme left and not clipped

See Also:
Constant Field Values

RIGHTMOST

public static final int RIGHTMOST
Bitmask indicating the tab is at the extreme right and not clipped

See Also:
Constant Field Values

CLOSE_BUTTON_ARMED

public static final int CLOSE_BUTTON_ARMED
Bitmask indicating that the tab contains the mouse and the mouse is in the close button

See Also:
Constant Field Values

BEFORE_SELECTED

public static final int BEFORE_SELECTED
Bitmask indicating that the tab's index is that of the selected index less one

See Also:
Constant Field Values

AFTER_SELECTED

public static final int AFTER_SELECTED
Bitmask indicating that the tab's index is that of the selected index plus one

See Also:
Constant Field Values

MOUSE_IN_TABS_AREA

public static final int MOUSE_IN_TABS_AREA
Bitmask indicating that the mouse is in the tabs area

See Also:
Constant Field Values

MOUSE_PRESSED_IN_CLOSE_BUTTON

public static final int MOUSE_PRESSED_IN_CLOSE_BUTTON
Bitmask indicating that the mouse is inside the close button and has been pressed.

See Also:
Constant Field Values

ATTENTION

public static final int ATTENTION
Bitmask indicating that the tab is in "attention" mode - blinking or flashing to get the user's attention.

See Also:
Constant Field Values

BEFORE_ARMED

public static final int BEFORE_ARMED
Bitmask indicating that the tab's index is that of the armed index less one

See Also:
Constant Field Values

STATE_LAST

public static int STATE_LAST
Indicates the last constant defined - renderers that wish to add their own bitmasks should use multiples of this number


REPAINT_ON_MOUSE_ENTER_TAB

public static final int REPAINT_ON_MOUSE_ENTER_TAB
Repaint policy bitmask indicating that a tab should be repainted whenever the mouse enters or exits it

See Also:
Constant Field Values

REPAINT_ALL_ON_MOUSE_ENTER_TABS_AREA

public static final int REPAINT_ALL_ON_MOUSE_ENTER_TABS_AREA
Repaint policy bitmask indicating that all tabs should be repainted whenever the mouse enters or leaves the area in which tabs are painted

See Also:
Constant Field Values

REPAINT_ON_MOUSE_ENTER_CLOSE_BUTTON

public static final int REPAINT_ON_MOUSE_ENTER_CLOSE_BUTTON
Repaint policy bitmask indicating that the tab should be repainted when the mouse enters or exits the close button region

See Also:
Constant Field Values

REPAINT_ON_MOUSE_PRESSED

public static final int REPAINT_ON_MOUSE_PRESSED
Repaint policy bitmask indicating that the tab should be repainted on mouse pressed events

See Also:
Constant Field Values

REPAINT_SELECTION_ON_ACTIVATION_CHANGE

public static final int REPAINT_SELECTION_ON_ACTIVATION_CHANGE
Repaint policy bitmask indicating that the selected tab should be repainted when the activated state changes

See Also:
Constant Field Values

REPAINT_ALL_TABS_ON_ACTIVATION_CHANGE

public static final int REPAINT_ALL_TABS_ON_ACTIVATION_CHANGE
Repaint policy bitmask indicating that all tabs should be repainted when the activated state changes

See Also:
Constant Field Values

REPAINT_ON_SELECTION_CHANGE

public static final int REPAINT_ON_SELECTION_CHANGE
Repaint policy bitmask indicating that a tab should be repainted when it becomes selected/unselected

See Also:
Constant Field Values

REPAINT_ALL_TABS_ON_SELECTION_CHANGE

public static final int REPAINT_ALL_TABS_ON_SELECTION_CHANGE
Repaint policy bitmask indicating that all tabs should be repainted whenever the selection changes

See Also:
Constant Field Values

REPAINT_ON_CLOSE_BUTTON_PRESSED

public static final int REPAINT_ON_CLOSE_BUTTON_PRESSED
Repaint policy bitmask indicating that the tab should be repainted when the close button is pressed

See Also:
Constant Field Values

NO_CHANGE

public static final int NO_CHANGE
Change type indicating no change happened (i.e. calling setSelected() with the same value it was previously called with).

See Also:
Constant Field Values

CHANGE_TAB_TO_TAB

public static final int CHANGE_TAB_TO_TAB
Change type indicating a change of state for two tabs

See Also:
Constant Field Values

CHANGE_TAB_TO_NONE

public static final int CHANGE_TAB_TO_NONE
Change type indicating a change happened (such as the mouse leaving a tab) such that now no tab has the state previously held by the affected tab

See Also:
Constant Field Values

CHANGE_NONE_TO_TAB

public static final int CHANGE_NONE_TO_TAB
Change type indicating that a state was added that no tab previously had

See Also:
Constant Field Values

CHANGE_TAB_TO_SELF

public static final int CHANGE_TAB_TO_SELF
See Also:
Constant Field Values

ALL_TABS

public static final int ALL_TABS
Change type indicating one of the boolean state changes, such as STATE_ACTIVE

See Also:
Constant Field Values
Constructor Detail

TabState

public TabState()
Method Detail

getState

public int getState(int tab)
Get the state of a given tab. Subclasses are expected to override this to provide information about states such as clipping which can only be found out via layout information, such as LEFTMOST, RIGHTMOST, CLIP_LEFT and CLIP_RIGHT. The state is used by tab renderers to determine how they should paint themselves.

Parameters:
tab - The index of the tab
Returns:
The state

clearTransientStates

public void clearTransientStates()
Clear all mouse position related state information. This should be done following events in the model that alter the state sufficiently that the cached information is probably wrong.


setPressed

public final int setPressed(int i)
Set the index of the tab over which a mouse button has been pressed.

Parameters:
i - The tab which is pressed, or -1 to clear PRESSED from the state of the previously pressed tab
Returns:
Index of the tab which previously had the state PRESSED, or -1

setContainsMouse

public final int setContainsMouse(int i)
Set the index of the tab which currently contains the mouse cursor.

Parameters:
i - The tab which contains the mouse cursor, or -1 to clear ARMED from the state of the tab
Returns:
Index of the tab which previously had the state ARMED, or -1

setCloseButtonContainsMouse

public final int setCloseButtonContainsMouse(int i)
Set the index of the tab whose close button contains the mouse cursor.

Parameters:
i - The index of the tab whose close button contains the mouse cursor, or -1 to clear CLOSE_BUTTON_CONTAINS_MOUSE from the state of the tab which previously had it
Returns:
Index of the tab which formerly had the state CLOSE_BUTTON_CONTAINS_MOUSE, or -1

setMousePressedInCloseButton

public final int setMousePressedInCloseButton(int i)
Set the index of the tab in which the mouse button has been pressed in the close button. This is distinct from the combination of CLOSE_BUTTON_ARMED and PRESSED, since the user may press the close button and then drag away from the close button (clearing the CLOSE_BUTTON_ARMED state) to abort closing a tab.

Parameters:
i - The tab in which the mouse was pressed while over the close button
Returns:
Index of the tab which previously had the state MOUSE_PRESSED_IN_CLOSE_BUTTON, or -1

setSelected

public final int setSelected(int i)
Set the index of the tab which is currently selected. Note that users of this class must ensure that this value stays up to date when changes occur in the model such as inserting tabs before the selected one.

Parameters:
i - The tab index which is selected
Returns:
Index of the tab which previously was selected, or -1 if none

setMouseInTabsArea

public final boolean setMouseInTabsArea(boolean b)
Set the condition for all tabs of the mouse being in the tabs area.

Parameters:
b - Whether the mouse is in the tabs area or not
Returns:
The previous state with regard to the mouse being in the tabs area

setActive

public final boolean setActive(boolean b)
Set the condition for all tabs of the component being activated.

Parameters:
b - Whether or not the component is activated
Returns:
The previous state with regard to the component being activated

addAlarmTab

public final void addAlarmTab(int alarmTab)
Add a tab to the list of those which should "flash" or otherwise give some notification to the user to get their attention


removeAlarmTab

public final void removeAlarmTab(int alarmTab)
Remove a tab to the list of those which should "flash" or otherwise give some notification to the user to get their attention


possibleChange

protected void possibleChange(boolean prevVal,
                              boolean currVal,
                              int type)

possibleChange

protected void possibleChange(int lastTab,
                              int currTab,
                              int type)

toString

public String toString()
Overrides:
toString in class Object

change

protected void change(int lastTab,
                      int currTab,
                      int type,
                      int changeType)
Called when a setter for a tab index has produced a change in a state-affecting property, such as which tab contains the mouse. Fetches the repaint policies, and if the change is one that the policy says should produce a repaint, calls repaintTab for the appropriate tabs.

Parameters:
lastTab - The tab previously holding the state which has changed, or -1
currTab - The tab currently holding the state which has changed, or -1
type - The thing that changed. This will be one of the state constants.
changeType - This is one of the defined change types such as ALL_TABS, TAB_TO_TAB, etc.

maybeRepaint

protected void maybeRepaint(int tab,
                            int type)

repaintTab

protected abstract void repaintTab(int tab)

repaintAllTabs

protected abstract void repaintAllTabs()

getRepaintPolicy

public abstract int getRepaintPolicy(int tab)
Get the repaint policy that will be used to determine what tabs to repaint, based on state changes. The default implementation in BasicTabDisplayerUI simply ignores the tab argument and returns a single policy for all tabs created in BasicTabDisplayerUI.createRepaintPolicy()

Parameters:
tab - Index of tab in question
Returns:
Type of repaint policy for given tab

org.netbeans.swing.tabcontrol 1.8

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