home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Java 1.2 How-To
/
JavaHowTo.iso
/
3rdParty
/
jbuilder
/
unsupported
/
JDK1.2beta3
/
SOURCE
/
SRC.ZIP
/
java
/
awt
/
swing
/
JTabbedPane.java
< prev
next >
Encoding:
Amiga
Atari
Commodore
DOS
FM Towns/JPY
Macintosh
Macintosh JP
NeXTSTEP
RISC OS/Acorn
UTF-8
Wrap
Java Source
|
1998-03-20
|
34.7 KB
|
1,106 lines
/*
* %W% %E%
*
* Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
*
* This software is the confidential and proprietary information of Sun
* Microsystems, Inc. ("Confidential Information"). You shall not
* disclose such Confidential Information and shall use it only in
* accordance with the terms of the license agreement you entered into
* with Sun.
*
* SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
* SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
* SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
* THIS SOFTWARE OR ITS DERIVATIVES.
*
*/
package java.awt.swing;
import java.awt.*;
import java.awt.event.*;
import java.beans.*;
import java.util.*;
import java.awt.swing.event.*;
import java.awt.swing.plaf.*;
import java.awt.accessibility.*;
import java.io.Serializable;
/**
* A component which lets the user switch between a group of components by
* clicking on a tab with a given title and/or icon.
* <p>
* Tabs/components are added to a TabbedPane object by using the addTab and
* insertTab methods. A tab is represented by an index corresponding
* to the position it was added in, where the first tab has an index equal to 0
* and the last tab has an index equal to the tab count minus 1.
* <p>
* The TabbedPane uses a SingleSelectionModel to represent the set
* of tab indeces and the currently selected index. If the tab count
* is greater than 0, then there will always be a selected index, which
* by default will be initialized to the first tab. If the tab count is
* 0, then the selected index will be -1.
*
* @see SingleSelectionModel
* <p>
* See <a href="http://java.sun.com/docs/books/tutorial/ui/swing/tabbedpane.html">How to Use Tabbed Panes</a>
* in <a href="http://java.sun.com/Series/Tutorial/index.html"><em>The Java Tutorial</em></a>
* for further documentation.
* <p>
* Warning: serialized objects of this class will not be compatible with
* future swing releases. The current serialization support is appropriate
* for short term storage or RMI between Swing1.0 applications. It will
* not be possible to load serialized Swing1.0 objects with future releases
* of Swing. The JDK1.2 release of Swing will be the compatibility
* baseline for the serialized form of Swing objects.
*
* @beaninfo
* attribute: isContainer true
* description: A component which provides a tab folder metaphor for
* displaying one component from a set of components.
*
* @version %I% %G%
* @author Dave Moore
* @author Philip Milne
* @author Amy Fowler
*/
public class JTabbedPane extends JComponent
implements Serializable, Accessible, SwingConstants {
protected int tabPlacement = TOP;
protected SingleSelectionModel model;
private boolean haveRegistered;
/**
* The changeListener is the listener we add to the
* model.
*/
protected ChangeListener changeListener = null;
Vector pages;
/**
* Only one ChangeEvent is needed per TabPane instance since the
* event's only (read-only) state is the source property. The source
* of events generated here is always "this".
*/
protected transient ChangeEvent changeEvent = null;
/**
* Creates an empty TabbedPane.
* @see #addTab
*/
public JTabbedPane() {
this(TOP);
}
/**
* Creates an empty TabbedPane with the specified tab placement
* of either: TOP, BOTTOM, LEFT, or RIGHT.
* @param tabPlacement the placement for the tabs relative to the content
* @see #addTab
*/
public JTabbedPane(int tabPlacement) {
setTabPlacement(tabPlacement);
pages = new Vector(1);
setModel(new DefaultSingleSelectionModel());
updateUI();
}
/**
* Returns the UI object which implements the L&F for this component.
* @see #setUI
*/
public TabbedPaneUI getUI() {
return (TabbedPaneUI)ui;
}
/**
* Sets the UI object which implements the L&F for this component.
* @param ui the new UI object
* @see UIDefaults#getUI
* @beaninfo
* bound: true
* hidden: true
* description: The UI object that implements the tabbedpane's LookAndFeel
*/
public void setUI(TabbedPaneUI ui) {
super.setUI(ui);
}
/**
* Notification from the UIManager that the L&F has changed.
* Called to replace the UI with the latest version from the
* default UIFactory.
*
* @see JComponent#updateUI
*/
public void updateUI() {
int count = getTabCount();
while (count-- > 0) {
Page page = (Page)pages.elementAt(count);
Component component = page.component;
if (component.getParent() != this && component instanceof Container) {
page.needsUIUpdate = true;
} else {
page.needsUIUpdate = false;
}
}
setUI((TabbedPaneUI)UIManager.getUI(this));
}
/**
* Returns the name of the UI class that implements the
* L&F for this component.
*
* @return "TabbedPaneUI"
* @see JComponent#getUIClassID
* @see UIDefaults#getUI
*/
public String getUIClassID() {
return "TabbedPaneUI";
}
/**
* We pass ModelChanged events along to the listeners with
* the tabbedpane (instead of the model itself) as the event source.
*/
protected class ModelListener implements ChangeListener, Serializable {
public void stateChanged(ChangeEvent e) {
fireStateChanged();
int count = getTabCount();
while (count-- > 0) {
Page page = (Page)pages.elementAt(count);
Component component = page.component;
if (page.needsUIUpdate && component.getParent() == JTabbedPane.this && component instanceof Container) {
SwingUtilities.updateComponentTreeUI(component);
page.needsUIUpdate = false;
component.validate();
}
}
}
}
/**
* Subclasses that want to handle ChangeEvents differently
* can override this to return a subclass of ModelListener or
* another ChangeListener implementation.
*
* @see #fireStateChanged
*/
protected ChangeListener createChangeListener() {
return new ModelListener();
}
/**
* Adds a ChangeListener to this tabbedpane.
*
* @param l the ChangeListener to add
* @see #fireStateChanged
* @see #removeChangeListener
*/
public void addChangeListener(ChangeListener l) {
listenerList.add(ChangeListener.class, l);
}
/**
* Removes a ChangeListener from this tabbedpane.
*
* @param l the ChangeListener to remove
* @see #fireStateChanged
* @see #addChangeListener
*/
public void removeChangeListener(ChangeListener l) {
listenerList.remove(ChangeListener.class, l);
}
/**
* Send a ChangeEvent, whose source is this tabbedpane, to
* each listener. This method method is called each time
* a ChangeEvent is received from the model.
*
* @see #addChangeListener
* @see EventListenerList
*/
protected void fireStateChanged() {
// Guaranteed to return a non-null array
Object[] listeners = listenerList.getListenerList();
// Process the listeners last to first, notifying
// those that are interested in this event
for (int i = listeners.length-2; i>=0; i-=2) {
if (listeners[i]==ChangeListener.class) {
// Lazily create the event:
if (changeEvent == null)
changeEvent = new ChangeEvent(this);
((ChangeListener)listeners[i+1]).stateChanged(changeEvent);
}
}
}
/**
* Returns the model associated with this tabbedpane.
*
* @see #setModel
*/
public SingleSelectionModel getModel() {
return model;
}
/**
* Sets the model to be used with this tabbedpane.
* @param model the model to be used
*
* @see #getModel
* @beaninfo
* bound: true
* description: The tabbedpane's SingleSelectionModel.
*/
public void setModel(SingleSelectionModel model) {
SingleSelectionModel oldModel = getModel();
if (oldModel != null) {
oldModel.removeChangeListener(changeListener);
changeListener = null;
}
this.model = model;
if (model != null) {
changeListener = createChangeListener();
model.addChangeListener(changeListener);
}
firePropertyChange("model", oldModel, model);
}
/**
* Returns the placement of the tabs for this tabbedpane.
* @see #setPlacement
*/
public int getTabPlacement() {
return tabPlacement;
}
/**
* Sets the tab placement for this tabbedpane to be either
* TOP, LEFT, BOTTOM, or RIGHT.
* @param tabPlacement the placement for the tabs relative to the content
*
* @see #getPlacement
* @beaninfo
* preferred: true
* bound: true
* description: The tabbedpane's tab placement.
* enum: TOP JTabbedPane.TOP
* LEFT JTabbedPane.LEFT
* BOTTOM JTabbedPane.BOTTOM
* RIGHT JTabbedPane.RIGHT
*
*/
public void setTabPlacement(int tabPlacement) {
if (tabPlacement != TOP && tabPlacement != LEFT &&
tabPlacement != BOTTOM && tabPlacement != RIGHT) {
throw new IllegalArgumentException("illegal tab placement: must be TOP, BOTTOM, LEFT, or RIGHT");
}
if (this.tabPlacement != tabPlacement) {
int old = this.tabPlacement;
this.tabPlacement = tabPlacement;
firePropertyChange("tabPlacement", old, tabPlacement);
invalidate();
}
}
/**
* Returns the currently selected index for this tabbedpane.
* Returns -1 if there is no currently selected tab.
*
* @return the index of the selected tab
* @see #setSelectedIndex
*/
public int getSelectedIndex() {
return model.getSelectedIndex();
}
/**
* Sets the selected index for this tabbedpane.
*
* @see #getSelectedIndex
* @see SingleSelectionModel#setSelectedIndex
* @beaninfo
* preferred: true
* description: The tabbedpane's selected tab index.
*/
public void setSelectedIndex(int index) {
int oldIndex = model.getSelectedIndex();
model.setSelectedIndex(index);
if ((oldIndex >= 0) && (oldIndex != index)) {
Page oldPage = (Page) pages.elementAt(oldIndex);
if (accessibleContext != null) {
accessibleContext.firePropertyChange(
AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
AccessibleState.SELECTED, null);
}
}
if ((index >= 0) && (oldIndex != index)) {
Page newPage = (Page) pages.elementAt(index);
if (accessibleContext != null) {
accessibleContext.firePropertyChange(
AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
null, AccessibleState.SELECTED);
}
}
}
/**
* Returns the currently selected component for this tabbedpane.
* Returns null if there is no currently selected tab.
*
* @return the component corresponding to the selected tab
* @see #setSelectedComponent
*/
public Component getSelectedComponent() {
int index = getSelectedIndex();
if (index == -1) {
return null;
}
return getComponentAt(index);
}
/**
* Sets the selected component for this tabbedpane. This
* will automatically set the selectedIndex to the index
* corresponding to the specified component.
*
* @see #getSelectedComponent
* @beaninfo
* preferred: true
* description: The tabbedpane's selected component.
*/
public void setSelectedComponent(Component c) {
int index = indexOfComponent(c);
if (index != -1) {
setSelectedIndex(index);
} else {
throw new IllegalArgumentException("component not found in tabbed pane");
}
}
/**
* Inserts a <i>component</i>, at <i>index</i>, represented by a
* <i>title</i> and/or <i>icon</i>, either of which may be null.
* Uses java.util.Vector internally, see insertElementAt()
* for details of insertion conventions.
* @param title the title to be displayed in this tab
* @param icon the icon to be displayed in this tab
* @param component The component to be displayed when this tab is clicked.
* @param tip the tooltip to be displayed for this tab
* @param index the position to insert this new tab
*
* @see #addTab
* @see #removeTabAt
*/
public void insertTab(String title, Icon icon, Component component, String tip, int index) {
Icon disabledIcon = null;
if (icon != null && icon instanceof ImageIcon) {
disabledIcon = new ImageIcon(
GrayFilter.createDisabledImage(
((ImageIcon)icon).getImage()));
}
pages.insertElementAt(new Page(this, title != null? title : "", icon, disabledIcon,
component, tip), index);
invalidate();
if (pages.size() == 1) {
setSelectedIndex(0);
}
if (!haveRegistered && tip != null) {
ToolTipManager.sharedInstance().registerComponent(this);
haveRegistered = true;
}
if (accessibleContext != null) {
accessibleContext.firePropertyChange(
AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
null, component);
}
}
/**
* Adds a <i>component</i> and <i>tip</i> represented by a <i>title</i>
* and/or <i>icon</i>, either of which can be null.
* Cover method for insertTab().
* @param title the title to be displayed in this tab
* @param icon the icon to be displayed in this tab
* @param component The component to be displayed when this tab is clicked.
* @param tip the tooltip to be displayed for this tab
*
* @see #insertTab
* @see #removeTabAt
*/
public void addTab(String title, Icon icon, Component component, String tip) {
insertTab(title, icon, component, tip, pages.size());
}
/**
* Adds a <i>component</i> represented by a <i>title</b> and/or <i>icon</i>,
* either of which can be null.
* Cover method for insertTab().
* @param title the title to be displayed in this tab
* @param icon the icon to be displayed in this tab
* @param component The component to be displayed when this tab is clicked.
*
* @see #insertTab
* @see #removeTabAt
*/
public void addTab(String title, Icon icon, Component component) {
insertTab(title, icon, component, null, pages.size());
}
/**
* Adds a <i>component</i> represented by a <i>title</b> and no icon.
* Cover method for insertTab().
* @param title the title to be displayed in this tab
* @param component The component to be displayed when this tab is clicked.
*
* @see #insertTab
* @see #removeTabAt
*/
public void addTab(String title, Component component) {
insertTab(title, null, component, null, pages.size());
}
/**
* Removes the tab at <i>index</i>.
* @param index the index of the tab to be removed
*
* @see #addTab
* @see #removeTabAt
*/
public void removeTabAt(int index) {
// If we are removing the currently selected tab AND
// it happens to be the last tab in the bunch, then
// select the previous tab
int tabCount = getTabCount();
int selected = getSelectedIndex();
if (selected >= (tabCount - 1)) {
setSelectedIndex(selected - 1);
}
Component oldvalue = getComponentAt(index);
if (accessibleContext != null) {
accessibleContext.firePropertyChange(
AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
oldvalue, null);
}
pages.removeElementAt(index);
invalidate();
}
/**
* Returns the number of tabs in this tabbedpane.
*/
public int getTabCount() {
return pages.size();
}
/**
* Returns the number of tab runs currently used to display
* the tabs. This returns the number of rows if the tabPlacement
* is TOP or BOTTOM and the number of columns if tabPlacement
* is LEFT or RIGHT.
* If there is no UI set on this tabbedpane, then returns 0.
*/
public int getTabRunCount() {
if (ui != null) {
return ((TabbedPaneUI)ui).getTabRunCount(this);
}
return 0;
}
// Getters for the Pages
/**
* Returns the tab title at <i>index</i>.
*
* @see #setTitleAt
*/
public String getTitleAt(int index) {
return ((Page)pages.elementAt(index)).title;
}
/**
* Returns the tab icon at <i>index</i>.
*
* @see #setIconAt
*/
public Icon getIconAt(int index) {
return ((Page)pages.elementAt(index)).icon;
}
/**
* Returns the tab disabled icon at <i>index</i>.
*
* @see #setDisabledIconAt
*/
public Icon getDisabledIconAt(int index) {
return ((Page)pages.elementAt(index)).disabledIcon;
}
/**
* Returns the tab background color at <i>index</i>.
*
* @see #setBackgroundAt
*/
public Color getBackgroundAt(int index) {
return ((Page)pages.elementAt(index)).getBackground();
}
/**
* Returns the tab foreground color at <i>index</i>.
*
* @see #setForegroundAt
*/
public Color getForegroundAt(int index) {
return ((Page)pages.elementAt(index)).getForeground();
}
/**
* Returns whether or not the tab at <i>index</i> is
* currently enabled.
*
* @see #setEnabledAt
*/
public boolean isEnabledAt(int index) {
return ((Page)pages.elementAt(index)).isEnabled();
}
/**
* Returns the component at <i>index</i>.
*
* @see #setComponentAt
*/
public Component getComponentAt(int index) {
return ((Page)pages.elementAt(index)).component;
}
/**
* Returns the tab bounds at <i>index</i>.
* If there is no UI set on this tabbedpane, then returns null.
*/
public Rectangle getBoundsAt(int index) {
if (ui != null) {
return ((TabbedPaneUI)ui).getTabBounds(this, index);
}
return null;
}
// Setters for the Pages
/**
* Sets the title at <i>index</i> to <i>title</i> which can be null.
* An internal exception is raised if there is no tab at that index.
* @param index the tab index where the title should be set
* @param title the title to be displayed in the tab
*
* @see #getTitleAt
*/
public void setTitleAt(int index, String title) {
String oldTitle =((Page)pages.elementAt(index)).title;
((Page)pages.elementAt(index)).title = title;
invalidate();
if ((oldTitle != title) && (accessibleContext != null)) {
accessibleContext.firePropertyChange(
AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
oldTitle, title);
}
}
/**
* Sets the icon at <i>index</i> to <i>icon</i> which can be null.
* An internal exception is raised if there is no tab at that index.
* @param index the tab index where the icon should be set
* @param icon the icon to be displayed in the tab
*
* @see #getIconAt
*/
public void setIconAt(int index, Icon icon) {
Icon oldIcon = ((Page)pages.elementAt(index)).icon;
((Page)pages.elementAt(index)).icon = icon;
invalidate();
AccessibleContext ac = getAccessibleContext();
// Fire the accessibility Visible data change
if ((oldIcon != icon) && (accessibleContext != null)) {
accessibleContext.firePropertyChange(
AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
oldIcon, icon);
}
}
/**
* Sets the disabled icon at <i>index</i> to <i>icon</i> which can be null.
* An internal exception is raised if there is no tab at that index.
* @param index the tab index where the disabled icon should be set
* @param icon the icon to be displayed in the tab when disabled
*
* @see #getDisabledIconAt
*/
public void setDisabledIconAt(int index, Icon disabledIcon) {
((Page)pages.elementAt(index)).disabledIcon = disabledIcon;
if (!isEnabledAt(index)) {
invalidate();
}
}
/**
* Sets the background color at <i>index</i> to <i>background</i>
* which can be null, in which case the tab's background color
* will default to the background color of the tabbedpane.
* An internal exception is raised if there is no tab at that index.
* @param index the tab index where the background should be set
* @param background the color to be displayed in the tab's background
*
* @see #getBackgroundAt
*/
public void setBackgroundAt(int index, Color background) {
((Page)pages.elementAt(index)).setBackground(background);
repaint();
}
/**
* Sets the foreground color at <i>index</i> to <i>foreground</i>
* which can be null, in which case the tab's foreground color
* will default to the foreground color of this tabbedpane.
* An internal exception is raised if there is no tab at that index.
* @param index the tab index where the foreground should be set
* @param foreground the color to be displayed as the tab's foreground
*
* @see #getForegroundAt
*/
public void setForegroundAt(int index, Color foreground) {
((Page)pages.elementAt(index)).setForeground(foreground);
repaint();
}
/**
* Sets whether or not the tab at <i>index</i> is enabled.
* An internal exception is raised if there is no tab at that index.
* @param index the tab index which should be enabled/disabled
* @param enabled whether or not the tab should be enabled
*
* @see #isEnabledAt
*/
public void setEnabledAt(int index, boolean enabled) {
((Page)pages.elementAt(index)).setEnabled(enabled);
repaint();
}
/**
* Sets the component at <i>index</i> to <i>component</i>.
* An internal exception is raised if there is no tab at that index.
* @param index the tab index where this component is being placed
* @param component the component for the tab
*
* @see #getComponentAt
*/
public void setComponentAt(int index, Component component) {
((Page)pages.elementAt(index)).component = component;
invalidate();
}
/**
* Returns the first tab index with a given <i>title</i>,
* Returns -1 if no tab has this title.
* @param title the title for the tab
*/
public int indexOfTab(String title) {
for(int i = 0; i < getTabCount(); i++) {
if (getTitleAt(i).equals(title == null? "" : title)) {
return i;
}
}
return -1;
}
/**
* Returns the first tab index with a given <i>icon</i>.
* Returns -1 if no tab has this icon.
* @param icon the icon for the tab
*/
public int indexOfTab(Icon icon) {
for(int i = 0; i < getTabCount(); i++) {
if (getIconAt(i).equals(icon)) {
return i;
}
}
return -1;
}
/**
* Returns the index of the tab for the specified component.
* Returns -1 if there is no tab for this component.
* @param component the component for the tab
*/
public int indexOfComponent(Component component) {
for(int i = 0; i < getTabCount(); i++) {
if (getComponentAt(i).equals(component)) {
return i;
}
}
return -1;
}
public String getToolTipText(MouseEvent event) {
if (ui != null) {
int index = ((TabbedPaneUI)ui).tabForCoordinate(this, event.getX(), event.getY());
if (index != -1) {
return ((Page)pages.elementAt(index)).tip;
}
}
return super.getToolTipText(event);
}
/////////////////
// Accessibility support
////////////////
/**
* Get the AccessibleContext associated with this JComponent
*
* @return the AccessibleContext of this JComponent
*/
public AccessibleContext getAccessibleContext() {
if (accessibleContext == null) {
accessibleContext = new AccessibleJTabbedPane();
}
return accessibleContext;
}
/**
* The class used to obtain the accessible role for this object.
* <p>
* Warning: serialized objects of this class will not be compatible with
* future swing releases. The current serialization support is appropriate
* for short term storage or RMI between Swing1.0 applications. It will
* not be possible to load serialized Swing1.0 objects with future releases
* of Swing. The JDK1.2 release of Swing will be the compatibility
* baseline for the serialized form of Swing objects.
*/
protected class AccessibleJTabbedPane extends AccessibleJComponent
implements AccessibleSelection, ChangeListener {
public AccessibleJTabbedPane() {
super();
JTabbedPane.this.model.addChangeListener(this);
}
public void stateChanged(ChangeEvent e) {
Object o = e.getSource();
firePropertyChange(AccessibleContext.ACCESSIBLE_SELECTION_PROPERTY,
null, o);
}
public AccessibleRole getAccessibleRole() {
return AccessibleRole.PAGE_TAB_LIST;
}
public int getAccessibleChildrenCount() {
return getTabCount();
}
public Accessible getAccessibleChild(int i) {
if (i < 0 || i >= getTabCount()) {
return null;
}
return (Accessible) pages.elementAt(i);
}
public AccessibleSelection getAccessibleSelection() {
return this;
}
public Accessible getAccessibleAt(Point p) {
int tab = ((TabbedPaneUI) ui).tabForCoordinate(JTabbedPane.this,
p.x, p.y);
if (tab == -1) {
tab = getSelectedIndex();
}
return getAccessibleChild(tab);
}
public int getAccessibleSelectionCount() {
return 1;
}
public Accessible getAccessibleSelection(int i) {
int index = getSelectedIndex();
if (index == -1) {
return null;
}
return (Accessible) pages.elementAt(index);
}
public boolean isAccessibleChildSelected(int i) {
return (i == getSelectedIndex());
}
public void addAccessibleSelection(int i) {
setSelectedIndex(i);
}
public void removeAccessibleSelection(int i) {
// can't do
}
public void clearAccessibleSelection() {
// can't do
}
public void selectAllAccessibleSelection() {
// can't do
}
}
private class Page extends AccessibleContext
implements Serializable, Accessible, AccessibleComponent {
String title;
Color background;
Color foreground;
Icon icon;
Icon disabledIcon;
JTabbedPane parent;
Component component;
String tip;
boolean enabled = true;
boolean needsUIUpdate;
Page(JTabbedPane parent,
String title, Icon icon, Icon disabledIcon, Component component, String tip) {
this.title = title;
this.icon = icon;
this.disabledIcon = disabledIcon;
this.parent = parent;
this.setAccessibleParent(parent);
this.component = component;
this.tip = tip;
if (component instanceof Accessible) {
AccessibleContext ac;
ac = ((Accessible) component).getAccessibleContext();
if (ac != null) {
ac.setAccessibleParent(this);
}
}
}
/////////////////
// Accessibility support
////////////////
public AccessibleContext getAccessibleContext() {
return this;
}
// AccessibleContext methods
public String getAccessibleName() {
if (accessibleName != null) {
return accessibleName;
} else if (title != null) {
return title;
}
return null;
}
public String getAccessibleDescription() {
if (accessibleDescription != null) {
return accessibleDescription;
} else if (tip != null) {
return tip;
}
return null;
}
public AccessibleRole getAccessibleRole() {
return AccessibleRole.PAGE_TAB;
}
public AccessibleStateSet getAccessibleStateSet() {
AccessibleStateSet states;
states = parent.getAccessibleContext().getAccessibleStateSet();
states.add(AccessibleState.SELECTABLE);
int i = parent.indexOfTab(title);
if (i == parent.getSelectedIndex()) {
states.add(AccessibleState.SELECTED);
}
return states;
}
public int getAccessibleIndexInParent() {
return parent.indexOfTab(title);
}
public int getAccessibleChildrenCount() {
if (component instanceof Accessible) {
return 1;
} else {
return 0;
}
}
public Accessible getAccessibleChild(int i) {
if (component instanceof Accessible) {
return (Accessible) component;
} else {
return null;
}
}
public Locale getLocale() {
return parent.getLocale();
}
public AccessibleComponent getAccessibleComponent() {
return this;
}
// AccessibleComponent methods
public Color getBackground() {
return background != null? background : parent.getBackground();
}
public void setBackground(Color c) {
background = c;
}
public Color getForeground() {
return foreground != null? foreground : parent.getForeground();
}
public void setForeground(Color c) {
foreground = c;
}
public Cursor getCursor() {
return parent.getCursor();
}
public void setCursor(Cursor c) {
parent.setCursor(c);
}
public Font getFont() {
return parent.getFont();
}
public void setFont(Font f) {
parent.setFont(f);
}
public FontMetrics getFontMetrics(Font f) {
return parent.getFontMetrics(f);
}
public boolean isEnabled() {
return enabled;
}
public void setEnabled(boolean b) {
enabled = b;
}
public boolean isVisible() {
return parent.isVisible();
}
public void setVisible(boolean b) {
parent.setVisible(b);
}
public boolean isShowing() {
return parent.isShowing();
}
public boolean contains(Point p) {
Rectangle r = getBounds();
return r.contains(p);
}
public Point getLocationOnScreen() {
Point parentLocation = parent.getLocationOnScreen();
Point componentLocation = getLocation();
componentLocation.translate(parentLocation.x, parentLocation.y);
return componentLocation;
}
public Point getLocation() {
Rectangle r = getBounds();
return new Point(r.x, r.y);
}
public void setLocation(Point p) {
// do nothing
}
public Rectangle getBounds() {
return parent.getUI().getTabBounds(parent,
parent.indexOfTab(title));
}
public void setBounds(Rectangle r) {
// do nothing
}
public Dimension getSize() {
Rectangle r = getBounds();
return new Dimension(r.width, r.height);
}
public void setSize(Dimension d) {
// do nothing
}
public Accessible getAccessibleAt(Point p) {
if (component instanceof Accessible) {
return (Accessible) component;
} else {
return null;
}
}
public boolean isFocusTraversable() {
return false;
}
public void requestFocus() {
// do nothing
}
public void addFocusListener(FocusListener l) {
// do nothing
}
public void removeFocusListener(FocusListener l) {
// do nothing
}
}
}