uic.pjava.widgets.tabbedpane
Class TabPanel

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjava.awt.Panel
              extended byuic.pjava.widgets.tabbedpane.TabPanel
All Implemented Interfaces:
Accessible, ActionListener, EventListener, ImageObserver, MenuContainer, MouseListener, Serializable

public class TabPanel
extends Panel
implements ActionListener, MouseListener

TabPanel -- allows a user to select from several interface components by clicking a tab at the top of the panel.

See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.awt.Panel
Panel.AccessibleAWTPanel
 
Nested classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  Vector aTabSelectionListener
           
protected  Polygon leftArrow
           
protected  boolean leftEnabled
           
protected  Polygon rightArrow
           
protected  boolean rightEnabled
           
 
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
TabPanel()
          Constructor for the TabPanel
 
Method Summary
 void actionPerformed(ActionEvent e)
          Handle the popup menu item selections
protected  void addImpl(Component comp, Object constraints, int index)
          Adds a component to the TabPanel
 void addTabSelectionListener(TabSelectionListener newListener)
          Add a listener who cares about tab selections
 String[] determineTabText()
          Determines which text will be displayed in the tabs of the Tab panel.
protected  void determineVisible()
           
protected  void drawTabs(Graphics g)
          Draws the tabs at the top of the tab panel
protected  void fireTabSelected(TabSelectionEvent e)
          let those who care know when a tab was selected
 Color getBorderColor()
          Gets the borderColor property (java.awt.Color) value.
protected  String getExplicitTabText(Component c)
           
 int getFirstVisible()
          Get the number of the first-visible physical tab.
 Insets getInsets()
          Returns the insets of the TabPanel.
protected  PopupMenu getPopupMenu()
           
protected  int getPosition(Object comp)
          Return the position of the component in the tabsplitter (its physical tab number)
 String getSelectedName()
          Get the tab text of the currently-selected component
 int getSelectedTabNum()
          Get the number of the currently-selected tab
 Color getTabBackground()
          Gets the color that's behind the tabs
 Color getTabColor()
          Deprecated. the new tabColors property should be used instead.
 Color[] getTabColors()
          Get the colors used to draw the tabs.
 Color getTabColors(int index)
          get a specific tab color.
 String[] getTabText()
          Gets the explicitly-set tab text array.
 String getTabText(int index)
          Gets a specific string from the explicitly-set tab text array.
 Object getVisibleComponent()
          Get the component that is currently visible
 int[] getVisibleComponentNum()
          Return an array containing the selected tab number.
protected  void mergeOrShow(int n)
          A convenience method so TabSplitter can add merge capability
 void mouseClicked(MouseEvent e)
          Dummy method for the MouseListener interface...
 void mouseEntered(MouseEvent e)
          Dummy method for the MouseListener interface...
 void mouseExited(MouseEvent e)
          Dummy method for the MouseListener interface...
 void mousePressed(MouseEvent e)
          handle the mouse button being pressed -- check for right mouse click to bring up popup menu
 void mouseReleased(MouseEvent e)
          When the mouse is released, check for tab selection
 void next()
          Move to next tab, wrapping around to first tab if necessary.
 void paint(Graphics g)
          Paints the tab panel image (tabs, border, background)
 void previous()
          Move to previous tab, wrapping around to last tab if necessary.
 void remove(Component comp)
          Remove a component from the container.
 void remove(int index)
          Remove a component from the container.
 void removeAll()
          Remove all components from the container.
 void removeTabSelectionListener(TabSelectionListener newListener)
          Remove a TabSelectionListener.
protected  void selectTab(MouseEvent e)
          Check to see if the user clicked on a tab or one of the tab panel navigation buttons.
 void setBorderColor(Color borderColor)
          Sets the borderColor property (java.awt.Color) value.
protected  void setExplicitTabText(Component c, String text)
           
 void setFirstVisible(int value)
          Explicitly sets which tab is the first to be visible
 void setFont(Font f)
          set the font to use on the tabs
 void setSelectedTabNum(int num)
          Explicitly pick the selected tab by number.
 void setTabBackground(Color color)
          set the color to use behind the tabs
 void setTabColor(Color color)
          Deprecated. the new tabColors property should be used instead.
 void setTabColors(Color[] tabColors)
          Sets the colors to use when drawing the tabs.
 void setTabColors(int index, Color tabColor)
          Sets the colors to use when drawing the tabs.
 void setTabText(int index, String tabText)
          Sets the explicit tab text to use when drawing the tabs.
 void setTabText(String[] tabText)
          Sets the explicit tab text to use when drawing the tabs.
protected  void setupTabPolygons()
          Creates a Polygon object for each tab.
 void shiftLeft()
          Shifts the row of tabs one position to the left
 void shiftRight()
          Shifts the row of tabs one position to the right
 void show(Component comp)
          Select a tab by component
 void show(int n)
          Select a tab by number
 void show(String tabName)
          Select a tab by text
 void showPhysicalTab(int n)
          Select a tab by number
protected  void showPopup(MouseEvent e)
          bring up the popup menu for the tabsplitter
protected  boolean tabContains(int num, int x, int y)
          Check to see if the numbered tab contains an x,y location.
 void update(Graphics g)
          Overridden to get rid of screen erase between drawings
 
Methods inherited from class java.awt.Panel
addNotify, getAccessibleContext
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getListeners, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, removeContainerListener, removeNotify, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

leftArrow

protected transient Polygon leftArrow

rightArrow

protected transient Polygon rightArrow

leftEnabled

protected boolean leftEnabled

rightEnabled

protected boolean rightEnabled

aTabSelectionListener

protected transient Vector aTabSelectionListener
Constructor Detail

TabPanel

public TabPanel()
Constructor for the TabPanel

Method Detail

actionPerformed

public void actionPerformed(ActionEvent e)
Handle the popup menu item selections

Specified by:
actionPerformed in interface ActionListener
Parameters:
e - (java.awt.event.ActionEvent) -- the event that was fired to us

addImpl

protected void addImpl(Component comp,
                       Object constraints,
                       int index)
Adds a component to the TabPanel

Parameters:
comp - (Component) -- the component to be added
constraints - (Object) -- constraints on the component
index - (int) -- at which position will the component be added (-1 means at end)

addTabSelectionListener

public void addTabSelectionListener(TabSelectionListener newListener)
Add a listener who cares about tab selections

Parameters:
newListener - (TabSelectionListener) -- the component who cares...

determineTabText

public String[] determineTabText()
Determines which text will be displayed in the tabs of the Tab panel. The text for each tab is determined as follows:
     If an explicit text were passed to add(), that text is used
       (note if the text happens to have the same value as that component's
        getName() call, it is not considered an explicit text)
     else if the component implements TabNamedComponent
       call its getTabName() method to determine the text
     else if the tabText[] propery was set and the
       text for that component is non-null
       use the tabText[tab number]
     else
       call getName() as a "last resort"
  

Note that this method should be used to figure out the tab text, not getTabText(), as getTabText() only gets the tabText[] property.

Returns:
An array of Strings that will appear on the tabs.
See Also:
getTabText(), setTabText(java.lang.String[])

determineVisible

protected void determineVisible()

drawTabs

protected void drawTabs(Graphics g)
Draws the tabs at the top of the tab panel

Parameters:
g - (Graphics) -- the graphics context into which tabs are drawn

fireTabSelected

protected void fireTabSelected(TabSelectionEvent e)
let those who care know when a tab was selected

Parameters:
e - (TabSelectionEvent) -- the event to pass to the listeners
See Also:
addTabSelectionListener(uic.pjava.widgets.tabbedpane.TabSelectionListener), removeTabSelectionListener(uic.pjava.widgets.tabbedpane.TabSelectionListener)

getBorderColor

public Color getBorderColor()
Gets the borderColor property (java.awt.Color) value. The borderColor is the color to paint behind the tabs and around the edge of the panel display area.

Returns:
The borderColor property value.
See Also:
setBorderColor(java.awt.Color)

getExplicitTabText

protected String getExplicitTabText(Component c)

getFirstVisible

public int getFirstVisible()
Get the number of the first-visible physical tab.

Returns:
The number of the tab that is visible.
See Also:
setFirstVisible(int)

getInsets

public Insets getInsets()
Returns the insets of the TabPanel. The insets indicate the size of the border of the container.

See Also:
LayoutManager

getPopupMenu

protected PopupMenu getPopupMenu()

getPosition

protected int getPosition(Object comp)
Return the position of the component in the tabsplitter (its physical tab number)

Parameters:
comp - (Component) -- the component to search for.
Returns:
The position of the component (-1 means not found)

getSelectedName

public String getSelectedName()
Get the tab text of the currently-selected component

Returns:
A String containing the currently-selected tab's text

getSelectedTabNum

public int getSelectedTabNum()
Get the number of the currently-selected tab

Returns:
an int for the currently-selected tab
See Also:
setSelectedTabNum(int)

getTabBackground

public Color getTabBackground()
Gets the color that's behind the tabs

Returns:
The color behind the tabs
See Also:
setTabBackground(java.awt.Color)

getTabColor

public Color getTabColor()
Deprecated. the new tabColors property should be used instead.

Get the color to use when drawing the tabs

See Also:
getTabColors()

getTabColors

public Color[] getTabColors()
Get the colors used to draw the tabs. These colors are cycled through all tabs that are painted.

Returns:
The tabColors property value.
See Also:
setTabColors(java.awt.Color[])

getTabColors

public Color getTabColors(int index)
get a specific tab color.

Parameters:
index - The index value into the property array.
Returns:
The tabColor property value.
See Also:
getTabColors(), setTabColors(java.awt.Color[])

getTabText

public String[] getTabText()
Gets the explicitly-set tab text array. Note that this method should not be used to see the text displayed on the tabs; instead, determineTabText() should be used.

Returns:
The tabText property value.
See Also:
setTabText(java.lang.String[]), determineTabText()

getTabText

public String getTabText(int index)
Gets a specific string from the explicitly-set tab text array. Note that this method should not be used to see the text displayed on the tabs; instead, determineTabText() should be used.

Returns:
The tabText property value.
See Also:
setTabText(java.lang.String[]), determineTabText()

getVisibleComponent

public Object getVisibleComponent()
Get the component that is currently visible

Returns:
the component that is on the currently-selected tab (note that this method returns an Object because its subclass returns an array of visible comps)

getVisibleComponentNum

public int[] getVisibleComponentNum()
Return an array containing the selected tab number. (It's done this way to provide a consistent interface for TabSplitter.) If you are using TabPanel and just want the int, use getSelectedTabNum()

Returns:
an array containing the selected tab number.

mergeOrShow

protected void mergeOrShow(int n)
A convenience method so TabSplitter can add merge capability

Parameters:
n - (int) -- the target tab or a merge or tab to show

mouseClicked

public void mouseClicked(MouseEvent e)
Dummy method for the MouseListener interface...

Specified by:
mouseClicked in interface MouseListener

mouseEntered

public void mouseEntered(MouseEvent e)
Dummy method for the MouseListener interface...

Specified by:
mouseEntered in interface MouseListener

mouseExited

public void mouseExited(MouseEvent e)
Dummy method for the MouseListener interface...

Specified by:
mouseExited in interface MouseListener

mousePressed

public void mousePressed(MouseEvent e)
handle the mouse button being pressed -- check for right mouse click to bring up popup menu

Specified by:
mousePressed in interface MouseListener

mouseReleased

public void mouseReleased(MouseEvent e)
When the mouse is released, check for tab selection

Specified by:
mouseReleased in interface MouseListener
Parameters:
e - (MouseEvent)

next

public void next()
Move to next tab, wrapping around to first tab if necessary.


paint

public void paint(Graphics g)
Paints the tab panel image (tabs, border, background)

Parameters:
g - (Graphics) The graphics context into which the tab panel is painted

previous

public void previous()
Move to previous tab, wrapping around to last tab if necessary.


remove

public void remove(int index)
Remove a component from the container.

Parameters:
index - (int) Which component to remove.

remove

public void remove(Component comp)
Remove a component from the container.

Parameters:
comp - (Component) Which component to remove.

removeAll

public void removeAll()
Remove all components from the container. This method is overridden to force a repaint in design mode.


removeTabSelectionListener

public void removeTabSelectionListener(TabSelectionListener newListener)
Remove a TabSelectionListener.

Parameters:
newListener - com.magelang.tabsplitter.TabSelectionListener
See Also:
addTabSelectionListener(uic.pjava.widgets.tabbedpane.TabSelectionListener)

selectTab

protected void selectTab(MouseEvent e)
Check to see if the user clicked on a tab or one of the tab panel navigation buttons.

Parameters:
e - (java.awt.event.MouseEvent) The mouse click.

setBorderColor

public void setBorderColor(Color borderColor)
Sets the borderColor property (java.awt.Color) value. The borderColor is the color to paint behind the tabs and around the edge of the panel display area.

Parameters:
borderColor - The new value for the property.
See Also:
getBorderColor()

setExplicitTabText

protected void setExplicitTabText(Component c,
                                  String text)

setFirstVisible

public void setFirstVisible(int value)
Explicitly sets which tab is the first to be visible

Parameters:
value - (int) the number for the first tab

setFont

public void setFont(Font f)
set the font to use on the tabs

Parameters:
f - (Font) -- the font to use when writing tab text

setSelectedTabNum

public void setSelectedTabNum(int num)
Explicitly pick the selected tab by number. Note that the number refers to the current tabs visible on the screen

Parameters:
num - int -- the tab number to select
See Also:
getSelectedTabNum()

setTabBackground

public void setTabBackground(Color color)
set the color to use behind the tabs

Parameters:
color - (Color) the color to draw behind the tabs

setTabColor

public void setTabColor(Color color)
Deprecated. the new tabColors property should be used instead.

Set the color to use when drawing the tabs

See Also:
setTabColors(java.awt.Color[])

setTabColors

public void setTabColors(Color[] tabColors)
Sets the colors to use when drawing the tabs. This an an array of colors that will be cycled through, ie, if there are more tabs than colors, the next tab will reuse the first color.

Parameters:
tabColors - The new value for the property.
See Also:
getTabColors()

setTabColors

public void setTabColors(int index,
                         Color tabColor)
Sets the colors to use when drawing the tabs. This an an array of colors that will be cycled through, ie, if there are more tabs than colors, the next tab will reuse the first color.

Parameters:
tabColor - The new value for the property.
See Also:
getTabColors()

setTabText

public void setTabText(String[] tabText)
Sets the explicit tab text to use when drawing the tabs.

Parameters:
tabText - The new value for the property.
See Also:
getTabText(), determineTabText()

setTabText

public void setTabText(int index,
                       String tabText)
Sets the explicit tab text to use when drawing the tabs.

Parameters:
index - (int) the specific text to set
tabText - The new value for the property.
See Also:
getTabText(), determineTabText()

setupTabPolygons

protected void setupTabPolygons()
Creates a Polygon object for each tab. This polygon object is used to draw the tab and to test if the user has clicked the mouse within that tab. The navigation buttons are also set up in this method.


shiftLeft

public void shiftLeft()
Shifts the row of tabs one position to the left


shiftRight

public void shiftRight()
Shifts the row of tabs one position to the right


show

public void show(int n)
Select a tab by number

Parameters:
n - (int) the number of the tab to select

show

public void show(Component comp)
Select a tab by component

Parameters:
comp - (Component) the main component of the tab to select

show

public void show(String tabName)
Select a tab by text

Parameters:
tabName - (String) the text of the tab to be selected

showPhysicalTab

public void showPhysicalTab(int n)
Select a tab by number

Parameters:
n - (int) the number of the tab to select

showPopup

protected void showPopup(MouseEvent e)
bring up the popup menu for the tabsplitter

Parameters:
e - (MouseEvent) tells where to bring it up

tabContains

protected boolean tabContains(int num,
                              int x,
                              int y)
Check to see if the numbered tab contains an x,y location. Used to determine if the mouse was clicked in a given tab

Parameters:
num - (int) number of the tab to check
x - (int) x-coord to check
y - (int) y-coord to check
Returns:
true if the (x,y) point is in the tab; false otherwise

update

public void update(Graphics g)
Overridden to get rid of screen erase between drawings



Copyright © 2002,2003 Thomas Zander Available under the Free Apache licence