|
org.netbeans.swing.tabcontrol 1.8 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
org.netbeans.swing.tabcontrol.TabbedContainer
public class TabbedContainer
A tabbed container similar to a JTabbedPane. The tabbed container is a simple container which contains two components - the tabs displayer, and the content displayer. The tabs displayer is the thing that actually draws the tabs; the content displayer contains the components that are being shown.
The first difference from a JTabbedPane is that it is entirely model driven - the tab contents are in a data model owned by the displayer. It is not strictly necessary for the contained components to even be installed in the AWT hierarchy when not displayed.
Other differences are more flexibility in the way tabs are displayed by completely separating the implementation and UI for that from that of displaying the contents.
Other interesting aspects are the ability of TabDataModel to deliver complex, granular events in a single pass with no information loss. Generally, great effort has been gone to to conflate nothing - that is, adding a component does not equal selecting it does not equal changing focus, et. cetera, leaving these decisions more in the hands of the user of the control.
It is possible to implement a subclass which provides the API of JTabbedPane, making it a drop-in replacement.
There are several UI styles a TabbedContainer
can have. The type
is passed as an argument to the constructor (support for changing these on the
fly may be added in the future, but such a change is a very heavyweight operation,
and is only desirable to enable use of this component in its various permutations
inside GUI designers). The following styles are supported:
TYPE_SLIDING
tabs, simply implementing an alternate UI delegate for the buttons used to represent tabs
is all that is needed.
TabActionEvent
, which can provide
the index of the tab that was pressed, and the command name of the action that was performed.
A client which wants to handle the event itself (for example, the asking a user if they want
to save data, and possibly vetoing the closing of a tab) may veto (or take full responsibility
for performing) the action by consuming the TabActionEvent.
active
is provided to allow a tabbed container to indicate that it
contains the currently focused component. However, no effort is made to track focus on the
part of the tabbed control - there is too much variability possible (for example, if
a component inside a tab opens a modal dialog, is the tab active or not?). In fact, using
keyboard focus at all to manage the activated state of the component turns out to be a potent
source of hard-to-fix, hard-to-reproduce bugs (especially when components are being added
and removed, or hidden and shown or components which do not reliably produce focus events).
What NetBeans does to solve the problem in a reliable way is the following:
TabDisplayer
,
Serialized FormNested Class Summary |
---|
Nested classes/interfaces inherited from class javax.swing.JComponent |
---|
JComponent.AccessibleJComponent |
Nested classes/interfaces inherited from class java.awt.Container |
---|
Container.AccessibleAWTContainer |
Nested classes/interfaces inherited from class java.awt.Component |
---|
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy |
Field Summary | |
---|---|
static String |
COMMAND_CLOSE
Action command indicating that the action event signifies the user clicking the Close button on a tab. |
static String |
COMMAND_CLOSE_ALL
|
static String |
COMMAND_CLOSE_ALL_BUT_THIS
|
static String |
COMMAND_DISABLE_AUTO_HIDE
|
static String |
COMMAND_ENABLE_AUTO_HIDE
|
static String |
COMMAND_MAXIMIZE
Command indicating a maximize (double-click) request |
static String |
COMMAND_POPUP_REQUEST
Action command indicating that a popup menu should be shown |
static String |
COMMAND_SELECT
Action command indicating that the action event fired signifies the user selecting a tab |
static int |
CONTENT_POLICY_ADD_ALL
Content policy in which all components contained in the data model should immediately be added to the AWT hierarchy at the time they appear in the data model. |
static int |
CONTENT_POLICY_ADD_ON_FIRST_USE
Content policy by which components contained in the data model are added to the AWT hierarchy the first time they are shown, and remain their thereafter unless removed from the data model. |
static int |
CONTENT_POLICY_ADD_ONLY_SELECTED
Content policy by which components contained in the data model are added to the AWT hierarchy the when they are shown, and removed immediately when the user changes tabs. |
protected static int |
DEFAULT_CONTENT_POLICY
The default content policy, currently CONTENT_POLICY_ADD_ALL. |
static String |
PROP_ACTIVE
Property fired when setActive() is called |
static String |
PROP_MANAGE_TAB_POSITION
Client property applicable only to TYPE_SLIDING tabs. |
static String |
TABBED_CONTAINER_UI_CLASS_ID
UIManager key for the UI Delegate to be used by tabbed containers. |
static int |
TYPE_EDITOR
Creates a "editor" style displayer; typically this uses a scrolling tabs UI for the tab displayer. |
static int |
TYPE_SLIDING
Creates a "sliding" view, typically with tabs rendered as buttons along the left, bottom or right edge, with no scrolling behavior for tabs. |
static int |
TYPE_TOOLBAR
Creates a Toolbar-style displayer (the style used by the NetBeans Form Editor's Component Inspector and a few other places in NetBeans). |
static int |
TYPE_VIEW
Creates a "view" style displayer; typically this will have a fixed width and a single row of tabs which get smaller as more tabs are added, as seen in NetBeans’ Explorer window. |
Fields inherited from class javax.swing.JComponent |
---|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW |
Fields inherited from class java.awt.Component |
---|
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.image.ImageObserver |
---|
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
---|---|
TabbedContainer()
Create a new pane with the default model and tabs displayer |
|
TabbedContainer(int type)
|
|
TabbedContainer(TabDataModel model)
Create a new pane with asociated model and the default tabs displayer |
|
TabbedContainer(TabDataModel model,
int type)
Create a new pane with the specified model and displayer type |
|
TabbedContainer(TabDataModel model,
int type,
LocationInformer locationInformer)
Deprecated. |
|
TabbedContainer(TabDataModel model,
int type,
WinsysInfoForTabbed winsysInfo)
Create a new pane with the specified model, displayer type and extra information from winsys |
Method Summary | |
---|---|
void |
addActionListener(ActionListener listener)
Register an ActionListener. |
void |
cancelRequestAttention(int tab)
|
void |
cancelRequestAttention(TabData data)
|
Image |
createImageOfTab(int idx)
Create an image of a single tab, suitable for use in drag and drop operations |
int |
dropIndexOfPoint(Point location)
The index at which a tab should be inserted if a drop operation occurs at this point. |
AccessibleContext |
getAccessibleContext()
|
ComponentConverter |
getComponentConverter()
Get the component converter which is used to fetch a component corresponding to an element in the data model. |
int |
getContentPolicy()
Determine the policy by which components are added to the container. |
Shape |
getDropIndication(Object dragged,
Point location)
Get a shape appropriate for drawing on the window's glass pane to indicate where a component should appear in the tab order if it is dropped here. |
LocationInformer |
getLocationInformer()
Deprecated. |
TabDataModel |
getModel()
Get the data model that represents the tabs this component has. |
SingleSelectionModel |
getSelectionModel()
Get the selection model. |
int |
getTabCount()
Get the number of tabs. |
Rectangle |
getTabRect(int index,
Rectangle r)
Fetch the rectangle of the tab for a given index, in the coordinate space of this component, by reconfiguring the passed rectangle object |
int |
getType()
Get the type of this displayer - it is either TYPE_EDITOR or TYPE_VIEW. |
TabbedContainerUI |
getUI()
Get the ui delegate for this component |
String |
getUIClassID()
Returns TabbedContainer.TABBED_CONTAINER_UI_CLASS_ID |
WinsysInfoForTabbed |
getWinsysInfo()
|
int |
indexOf(Component comp)
Get the index of a component |
boolean |
isActive()
Determine if this component thinks it is "active", which affects how the tabs are painted - typically used to indicate that keyboard focus is somewhere within the component |
boolean |
isPaintingOrigin()
|
boolean |
isShowCloseButton()
Determine whether or not close buttons are being shown. |
boolean |
isValidateRoot()
|
protected void |
postActionEvent(TabActionEvent event)
Used by the UI to post action events for selection and close operations. |
void |
removeActionListener(ActionListener listener)
Remove an action listener. |
void |
requestAttention(int tab)
Cause the tab at the specified index to blink or otherwise suggest that the user should click it. |
boolean |
requestAttention(TabData data)
Cause the specified tab to blink or otherwisse suggest that the user should click it. |
void |
setActive(boolean active)
Set the "active" state of this tab control - this affects the way the tabs are displayed, to indicate focus. |
void |
setComponentConverter(ComponentConverter cc)
Set the converter that converts user objects in the data model into components to display. |
void |
setContentPolicy(int i)
Experimental property - alter the policy by which the components in the model are added to the container. |
void |
setIconAt(int index,
Icon icon)
|
void |
setShowCloseButton(boolean val)
Set whether or not close buttons should be shown. |
void |
setTitleAt(int index,
String title)
|
void |
setToolTipTextAt(int index,
String toolTip)
|
int |
tabForCoordinate(Point p)
Gets the index of the tab at point p, or -1 if no tab is there |
void |
updateUI()
Overridden as follows: When called by the superclass constructor (before the type field is set), it will simply return; the
TabbedContainer constructor will call updateUI() explicitly later. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
public static final String TABBED_CONTAINER_UI_CLASS_ID
public static final int TYPE_VIEW
public static final int TYPE_EDITOR
public static final int TYPE_SLIDING
This is the least scalable of the available UI types, and is intended primarily for use with a small, fixed set of tabs. By default, the position of the tab displayer will be determined based on the proximity of the container to the edges of its parent window. This can be turned off by setting the client property PROP_MANAGE_TAB_POSITION to Boolean.FALSE.
public static final int TYPE_TOOLBAR
public static final String PROP_ACTIVE
setActive()
is called
public static final String PROP_MANAGE_TAB_POSITION
public static final String COMMAND_CLOSE
public static final String COMMAND_SELECT
public static final String COMMAND_POPUP_REQUEST
public static final String COMMAND_MAXIMIZE
public static final String COMMAND_CLOSE_ALL
public static final String COMMAND_CLOSE_ALL_BUT_THIS
public static final String COMMAND_ENABLE_AUTO_HIDE
public static final String COMMAND_DISABLE_AUTO_HIDE
public static final int CONTENT_POLICY_ADD_ALL
setContentPolicy(int)
,
Constant Field Valuespublic static final int CONTENT_POLICY_ADD_ON_FIRST_USE
setContentPolicy(int)
,
Constant Field Valuespublic static final int CONTENT_POLICY_ADD_ONLY_SELECTED
protected static int DEFAULT_CONTENT_POLICY
Error
). Do not manipulate this value at runtime, it will likely become
a final field in a future release. It is a protected field only to ensure its inclusion in documentation.
setContentPolicy(int)
Constructor Detail |
---|
public TabbedContainer()
public TabbedContainer(TabDataModel model)
public TabbedContainer(int type)
public TabbedContainer(TabDataModel model, int type)
model
- The model@Deprecated public TabbedContainer(TabDataModel model, int type, LocationInformer locationInformer)
public TabbedContainer(TabDataModel model, int type, WinsysInfoForTabbed winsysInfo)
Method Detail |
---|
public void updateUI()
type
field is set), it will simply return; the
TabbedContainer constructor will call updateUI() explicitly later.
Will first search UIManager for a matching UI class. If non-null (by default it is set in the core/swing/plaf library), it will compare the found class name with the current UI. If they are a match, it will call TabbedContainerUI.shouldReplaceUI() to decide whether to actually do anything or not (in most cases it would just replace an instance of DefaultTabbedContainerUI with another one; but this call allows DefaultTabbedContainerUI.uichange() to update the tab displayer as needed).
If no UIManager UI class is defined, this method will silently use an instance of DefaultTabbedContainerUI.
updateUI
in class JComponent
public final int getType()
public String getUIClassID()
TabbedContainer.TABBED_CONTAINER_UI_CLASS_ID
getUIClassID
in class JComponent
public TabbedContainerUI getUI()
public final void setComponentConverter(ComponentConverter cc)
For use cases where a single component is to be displayed for more than one tab, just reconfigured when the selection changes, simply supply a ComponentConverter.Fixed with the component that should be used for all tabs.
public final ComponentConverter getComponentConverter()
public final void setContentPolicy(int i)
public int getContentPolicy()
public boolean isValidateRoot()
isValidateRoot
in class JComponent
public boolean isPaintingOrigin()
public void setToolTipTextAt(int index, String toolTip)
public final TabDataModel getModel()
public final SingleSelectionModel getSelectionModel()
public final Rectangle getTabRect(int index, Rectangle r)
public int tabForCoordinate(Point p)
public final void setActive(boolean active)
public final void requestAttention(int tab)
public final void cancelRequestAttention(int tab)
public final boolean requestAttention(TabData data)
public final void cancelRequestAttention(TabData data)
public final boolean isActive()
public final void addActionListener(ActionListener listener)
listener
- The listener to register.public final void removeActionListener(ActionListener listener)
listener
- The listener to remove.protected final void postActionEvent(TabActionEvent event)
event
- The event to be firedpublic void setIconAt(int index, Icon icon)
public void setTitleAt(int index, String title)
public Image createImageOfTab(int idx)
public int getTabCount()
getModel().size()
public final void setShowCloseButton(boolean val)
nb.tabs.suppressCloseButton
; if the system
property is not set, the default is true.
public final boolean isShowCloseButton()
public int indexOf(Component comp)
public int dropIndexOfPoint(Point location)
location
- A point anywhere on the TabbedContainer
public Shape getDropIndication(Object dragged, Point location)
dragged
- An object being dragged, or null. The object may be an instance
of TabData
or Component
, in which case a check
will be done of whether the dragged object is already in the data model,
so that attempts to drop the object over the place it already is in the
model will always return the exact indication of that tab's position.location
- A point
@Deprecated public LocationInformer getLocationInformer()
public WinsysInfoForTabbed getWinsysInfo()
public AccessibleContext getAccessibleContext()
getAccessibleContext
in interface Accessible
getAccessibleContext
in class JComponent
|
org.netbeans.swing.tabcontrol 1.8 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |