com.objectplanet.gui.tabs
Class TabbedPanel

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjava.awt.Panel
              extended bycom.objectplanet.gui.tabs.TabbedPanel
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class TabbedPanel
extends java.awt.Panel

This class implements a tabbed panel component. You can place any component in the panel, and each component will have a named tab assosiated with it. The user can choose between the components by selecting the tabs.

The tabs can be either at the top, bottom, left, or right of the panel. The user can also detach a tab into its own top-level window.

The user can detach a component into its own window by selecting a tab with the right mouse button. The component will then be detached into it's own top-level application window which the user can change the size of. The window is reattached to the tabbed panel by closing it.

Author:
Bjorn J. Kvande.
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class java.awt.Panel
java.awt.Panel.AccessibleAWTPanel
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static int BOTTOM
          Tabs go at the bottom.
static int LEFT
          Tabs go at the left.
static int RIGHT
          Tabs go at the right.
static int TOP
          Tabs go at the top.
 
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
TabbedPanel()
          Creates an empty TabbedPanel with the tabs at the top.
TabbedPanel(int orientation)
          Creates an empty TabbedPanel with the given tab orientation.
 
Method Summary
 java.awt.Component add(java.lang.String name, java.awt.Component component)
          Adds a new component to the panel.
 void addMouseListener(java.awt.event.MouseListener listener)
          Adds a mouse listener to the tabbed panel.
 void addTabbedListener(TabbedListener listener)
          Adds a tabbed panel event listener.
 boolean contains(java.lang.String name)
          Checks if a tab with this name exists in the panel.
 void destroy()
          Call this method to release any image resources used.
 java.awt.Frame detach(java.lang.String tab)
          Detaches the specified tab into a top-level window.
 java.awt.Frame detachAll()
          Detaches all the tabs into it's own top-level window frame.
 void doLayout()
          Lays out the current visible component.
 java.awt.Component get(java.lang.String name)
          Gets the component with the given name from the panel.
 int getBorderSize()
          Gets the size of the border.
 java.awt.Image getDetachedIcon(java.lang.String name)
          Gets the icon used for the detached frame.
 java.awt.Image getDetachedImage()
          Gets the detach image.
 java.lang.String getDetachedTitle()
          Gets the title used in the detached window frame.
 java.awt.Insets getInsets()
          This method is overridden to pad the panel to make space for the tabs.
 int getOrientation()
          Gets the current orientation of the tabs.
 java.lang.String getShowing()
          Gets the name of the tab currently showed.
 java.awt.Color getTabColor()
          Gets the default color of the tabs.
 java.awt.Color getTabColor(java.lang.String tab)
          Gets the color of the specified tab.
 int getTabCount()
          Gets the number of tabs in the panel.
 java.awt.Font getTabFont()
          Gets the font used for the tab labels.
 java.awt.Image getTabImage(java.lang.String name)
          Gets the image used for the specified tab.
 java.awt.Color getTabLabelColor()
          Gets the default color of the tab labels.
 java.awt.Color getTabLabelColor(java.lang.String tab)
          Gets the color of the specified tab label.
 java.lang.String getTabName(int index)
          Gets the name of the specified tab.
 java.lang.String getTitle()
          Gets the title of the panel.
 java.awt.Font getTitleFont()
          Gets the title font.
 boolean isAllDetachable()
          Checks if all the tabs can be detached at once.
 boolean isAllDetached()
          Checks if all the tabs (as one component) is detached into it's own top-level window frame.
 boolean isAnyDetached()
          Checks if any given tab is detached.
 boolean isDetachable()
          Checks if the tabs in the panel are detachable.
 boolean isDetached(java.lang.String tab)
          Checks if the given tab is detached.
 boolean isDoLayoutOn()
          Checks if automatic layout is on.
 boolean isDoubleBufferingOn()
          Checks if double buffering is turned on or off.
 boolean isEnabled(java.lang.String tab)
          Checks if the given tab is enabled or disabled.
 boolean isShowing(java.lang.String tab)
          Checks if the given tab is the one currently showing.
 boolean isTabImageOn(java.lang.String name)
          Checks if the tab image for the specified tab is turned on.
 boolean isTabLabelOn(java.lang.String name)
          Checks if the tab label for the specified tab is turned on.
 boolean isTabsOn()
          Checks if the tabs are on or off.
 java.awt.Component remove(java.lang.String name)
          Removes the component with the given name from the panel.
 void removeTabbedListener(TabbedListener listener)
          Removes the specified event listener from the panel.
protected  void render(java.awt.Graphics g, TabbedContainer container)
          Renders the tabs.
 void repaint()
          The tab contains is the actual component the buttons are painted on.
 void retach(java.lang.String tab)
          Reattaches a component that has been detached from the panel.
 void retachAll()
          Retaches all the back into the main tabbed panel container.
 void setAllDetachable(boolean detachable)
          Turns on or off the possibility to detach all the tabs at once tabs into it's own top-level window frame.
 void setBorderSize(int size)
          Sets the tab's border size.
 void setDetachable(boolean detachable)
          Turns on or off the possibility to detach a tab.
 void setDetachedIcon(java.lang.String name, java.awt.Image image)
          Sets the icon used for the detached frame.
 void setDetachedImage(java.awt.Image image)
          Sets the image to be painted on the component when all the tabs are detached.
 void setDetachedTitle(java.lang.String title)
          Sets the title used in the detached window frame.
 void setDoLayoutOn(boolean state)
          Turns on or off automatic layout.
 void setDoubleBufferingOn(boolean state)
          Turns on or off double buffering.
 void setEnabled(java.lang.String tab, boolean enabled)
          Enables or disables the given tab.
 void setOrientation(int orientation)
          Sets the orientation of the tabs.
 void setTabColor(java.awt.Color color)
          Sets the color of the tabs.
 void setTabColor(java.lang.String tab, java.awt.Color color)
          Sets the color of the specified tab.
 void setTabFont(java.awt.Font font)
          Sets the font used for the tab labels.
 void setTabImage(java.lang.String name, java.awt.Image image)
          Sets an image for the specified tab.
 void setTabImageOn(java.lang.String name, boolean on)
          Turns on or off the image of the specified tab.
 void setTabLabelColor(java.awt.Color color)
          Sets the color of the tab labels.
 void setTabLabelColor(java.lang.String tab, java.awt.Color color)
          Sets the color of the specified tab label.
 void setTabLabelOn(java.lang.String name, boolean on)
          Turns on or off the label of the specified tab.
 void setTabsOn(boolean on)
          Turns on or off the tabs.
 void setTitle(java.lang.String title)
          Sets the title of the panel.
 void setTitleFont(java.awt.Font font)
          Sets the font of the title.
 java.awt.Component show(java.lang.String name)
          Shows the component with the given name.
 void update(java.awt.Graphics g)
          Implemented to avoid flicker.
 
Methods inherited from class java.awt.Panel
addNotify, getAccessibleContext
 
Methods inherited from class java.awt.Container
add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, 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, paint, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFont, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, 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, 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

BOTTOM

public static final int BOTTOM
Tabs go at the bottom.

See Also:
Constant Field Values

LEFT

public static final int LEFT
Tabs go at the left.

See Also:
Constant Field Values

RIGHT

public static final int RIGHT
Tabs go at the right.

See Also:
Constant Field Values

TOP

public static final int TOP
Tabs go at the top.

See Also:
Constant Field Values
Constructor Detail

TabbedPanel

public TabbedPanel()
Creates an empty TabbedPanel with the tabs at the top.


TabbedPanel

public TabbedPanel(int orientation)
Creates an empty TabbedPanel with the given tab orientation.

Parameters:
orientation - The tab bar orientation (TOP, BOTTOM, LEFT, RIGHT).
Method Detail

add

public java.awt.Component add(java.lang.String name,
                              java.awt.Component component)
Adds a new component to the panel. If the name of the tab given for the component exists from before, the old component will be replaced.

Parameters:
name - The name of the tab for the component.
component - The component to add.
Returns:
The component added, or null if none was added
See Also:
remove(java.lang.String)

addMouseListener

public void addMouseListener(java.awt.event.MouseListener listener)
Adds a mouse listener to the tabbed panel.

Parameters:
listener - The mouse listener to add.

addTabbedListener

public void addTabbedListener(TabbedListener listener)
Adds a tabbed panel event listener. The listener will receive events when a tab is selected or deselected, as well as when the tab is detached from the panel, and reattached again.

Parameters:
listener - The listener to add
See Also:
removeTabbedListener(com.objectplanet.gui.tabs.TabbedListener)

contains

public boolean contains(java.lang.String name)
Checks if a tab with this name exists in the panel.

Parameters:
name - The name to check for.
Returns:
True if found, false if not there.

destroy

public void destroy()
Call this method to release any image resources used.


detach

public java.awt.Frame detach(java.lang.String tab)
Detaches the specified tab into a top-level window. An event will be sent to the event listeners, saying that the component was detached. If detachable is turned off, the tab will not be detached.

Parameters:
tab - The name of the tab to detach, or null if it failed.
See Also:
retach(java.lang.String)

detachAll

public java.awt.Frame detachAll()
Detaches all the tabs into it's own top-level window frame.

Returns:
The window the tabbed panel was detached to.

doLayout

public void doLayout()
Lays out the current visible component.


get

public java.awt.Component get(java.lang.String name)
Gets the component with the given name from the panel.

Parameters:
name - The name of the tab for the component.
Returns:
The component, or null if not found.

getBorderSize

public int getBorderSize()
Gets the size of the border.


getDetachedIcon

public java.awt.Image getDetachedIcon(java.lang.String name)
Gets the icon used for the detached frame.

Parameters:
name - The name of the tab or null for default and the detachAll frame icon.
Returns:
The icon, or null if no icon is specified.

getDetachedImage

public java.awt.Image getDetachedImage()
Gets the detach image.

Returns:
The image or null if no image is used.

getDetachedTitle

public java.lang.String getDetachedTitle()
Gets the title used in the detached window frame.

Returns:
The title or null if no title is specified.

getInsets

public java.awt.Insets getInsets()
This method is overridden to pad the panel to make space for the tabs. In general you should not override this method, and if you do so, call super.getInsets(), and pad the insets you get from there.


getOrientation

public int getOrientation()
Gets the current orientation of the tabs.

Returns:
TOP, BOTTOM, LEFT, or RIGHT.

getShowing

public java.lang.String getShowing()
Gets the name of the tab currently showed.


getTabColor

public java.awt.Color getTabColor()
Gets the default color of the tabs.

Returns:
The tab color set, or the background if not set.

getTabColor

public java.awt.Color getTabColor(java.lang.String tab)
Gets the color of the specified tab.

Parameters:
tab - The name of the tab.

getTabCount

public int getTabCount()
Gets the number of tabs in the panel.


getTabFont

public java.awt.Font getTabFont()
Gets the font used for the tab labels.


getTabImage

public java.awt.Image getTabImage(java.lang.String name)
Gets the image used for the specified tab.

Parameters:
name - The name of the tab.
Returns:
The image used, or null if no image is used.

getTabLabelColor

public java.awt.Color getTabLabelColor()
Gets the default color of the tab labels.


getTabLabelColor

public java.awt.Color getTabLabelColor(java.lang.String tab)
Gets the color of the specified tab label.

Parameters:
tab - The name of the tab.

getTabName

public java.lang.String getTabName(int index)
Gets the name of the specified tab.

Parameters:
index - The index of the tab (0-based).
Returns:
The name of the tab, or null if not found.

getTitle

public java.lang.String getTitle()
Gets the title of the panel.

Returns:
The title of the panel, or null if no title is set.

getTitleFont

public java.awt.Font getTitleFont()
Gets the title font.


isAllDetachable

public boolean isAllDetachable()
Checks if all the tabs can be detached at once.

Returns:
True if detachable, false otherwise.

isAllDetached

public boolean isAllDetached()
Checks if all the tabs (as one component) is detached into it's own top-level window frame.

Returns:
True if detached, false otherwise.

isAnyDetached

public boolean isAnyDetached()
Checks if any given tab is detached.

Returns:
True if any of the tabs are detached.

isDetachable

public boolean isDetachable()
Checks if the tabs in the panel are detachable.

Returns:
True if detachable, false otherwise.

isDetached

public boolean isDetached(java.lang.String tab)
Checks if the given tab is detached.

Parameters:
tab - The name of the tab to check.
Returns:
True if detached, false otherwise.

isDoLayoutOn

public boolean isDoLayoutOn()
Checks if automatic layout is on.

Returns:
True if on, false is off.

isDoubleBufferingOn

public boolean isDoubleBufferingOn()
Checks if double buffering is turned on or off.

Returns:
True if on, false if off.

isEnabled

public boolean isEnabled(java.lang.String tab)
Checks if the given tab is enabled or disabled.

Parameters:
tab - The name of the tab.
Returns:
True for enabled, false for disabled.
See Also:
setEnabled(java.lang.String, boolean)

isShowing

public boolean isShowing(java.lang.String tab)
Checks if the given tab is the one currently showing.

Parameters:
tab - The name of the tab to check.
Returns:
True if shown, false otherwise.
See Also:
show(java.lang.String)

isTabImageOn

public boolean isTabImageOn(java.lang.String name)
Checks if the tab image for the specified tab is turned on.

Parameters:
name - The name of the tab.
Returns:
True if turned on, false otherwise.

isTabLabelOn

public boolean isTabLabelOn(java.lang.String name)
Checks if the tab label for the specified tab is turned on.

Parameters:
name - The name of the tab.
Returns:
True if turned on, false otherwise.

isTabsOn

public boolean isTabsOn()
Checks if the tabs are on or off. They are on by default.

Returns:
True if on, false if off.

remove

public java.awt.Component remove(java.lang.String name)
Removes the component with the given name from the panel. If the component is detached, the detach window will be closed before the component is removed from the tabbed panel.

Parameters:
name - The name of the tab for the component.
Returns:
The component removed, or null if not found.
See Also:
add(java.lang.String, java.awt.Component)

removeTabbedListener

public void removeTabbedListener(TabbedListener listener)
Removes the specified event listener from the panel.

Parameters:
listener - The event listener to remove.
See Also:
addTabbedListener(com.objectplanet.gui.tabs.TabbedListener)

render

protected void render(java.awt.Graphics g,
                      TabbedContainer container)
Renders the tabs.

Parameters:
g - The graphics context used for painting.
container - The tab container to paint the tabs on.

repaint

public void repaint()
The tab contains is the actual component the buttons are painted on. The tabContainer.paint() method calls this paintContains(g) method.


retach

public void retach(java.lang.String tab)
Reattaches a component that has been detached from the panel. An event will be sent to the event listeners, saying that the component was reattached to the panel.

Parameters:
tab - The name of the tab that is to be reattached again.
See Also:
detach(java.lang.String)

retachAll

public void retachAll()
Retaches all the back into the main tabbed panel container.


setAllDetachable

public void setAllDetachable(boolean detachable)
Turns on or off the possibility to detach all the tabs at once tabs into it's own top-level window frame. This is set to false by default.

Parameters:
detachable - True for detachable, false otherwise.

setBorderSize

public void setBorderSize(int size)
Sets the tab's border size.

Parameters:
size - The size in pixels, 0 for off.

setDetachable

public void setDetachable(boolean detachable)
Turns on or off the possibility to detach a tab.

Parameters:
detachable - True for detachable, false otherwise.

setDetachedIcon

public void setDetachedIcon(java.lang.String name,
                            java.awt.Image image)
Sets the icon used for the detached frame.

Parameters:
name - The name of the tab or null for default and the detachAll frame icon.
image - The icon image to use, null for none.

setDetachedImage

public void setDetachedImage(java.awt.Image image)
Sets the image to be painted on the component when all the tabs are detached.

Parameters:
image - The image to be used, null for none.

setDetachedTitle

public void setDetachedTitle(java.lang.String title)
Sets the title used in the detached window frame.

Parameters:
title - The frame title.

setDoLayoutOn

public void setDoLayoutOn(boolean state)
Turns on or off automatic layout. Some browsers might freeze if this is being called by multiple threads at the same time. Turn this off until you explisitly call doLayout() if you experience any problems.

Parameters:
state - True for automatic layout, false for manual.

setDoubleBufferingOn

public void setDoubleBufferingOn(boolean state)
Turns on or off double buffering. Double buffering is used to avoid flickering when repainting, but uses more memory for offscreen images. Turn this off if you have other means of double buffering. This is turned on by default.

Parameters:
state - True for on (default), false for off.

setEnabled

public void setEnabled(java.lang.String tab,
                       boolean enabled)
Enables or disables the given tab.

Parameters:
tab - The name of the tab.
enabled - True for enabled, false for disabled.
See Also:
isEnabled(java.lang.String)

setOrientation

public void setOrientation(int orientation)
Sets the orientation of the tabs.

Parameters:
orientation - TOP, BOTTOM, LEFT, or RIGHT.

setTabColor

public void setTabColor(java.awt.Color color)
Sets the color of the tabs.

Parameters:
color - The color to use.

setTabColor

public void setTabColor(java.lang.String tab,
                        java.awt.Color color)
Sets the color of the specified tab. This overrides the default tab color set with setTabColor(Color).

Parameters:
tab - The name of the tab.
color - The color to use (null to use default tab color).
See Also:
setTabColor(java.awt.Color)

setTabFont

public void setTabFont(java.awt.Font font)
Sets the font used for the tab labels.

Parameters:
font - The font to use.

setTabImage

public void setTabImage(java.lang.String name,
                        java.awt.Image image)
Sets an image for the specified tab. This also sets the detach icon if this is not set before by calling setDetachedIcon(). You might need to call doLayout() after this is called to lay out the component properly.

Parameters:
name - The name of the tab.
image - The image to use, null for none.

setTabImageOn

public void setTabImageOn(java.lang.String name,
                          boolean on)
Turns on or off the image of the specified tab.

Parameters:
name - The name of the tab.
on - True for on, false for off.

setTabLabelColor

public void setTabLabelColor(java.awt.Color color)
Sets the color of the tab labels.

Parameters:
color - The color to use.

setTabLabelColor

public void setTabLabelColor(java.lang.String tab,
                             java.awt.Color color)
Sets the color of the specified tab label. This overrides the default tab label color set with setTabLabelColor(Color).

Parameters:
tab - The name of the tab.
color - The color to use (null to use default tab label color).
See Also:
setTabLabelColor(java.awt.Color)

setTabLabelOn

public void setTabLabelOn(java.lang.String name,
                          boolean on)
Turns on or off the label of the specified tab.

Parameters:
name - The name of the tab.
on - True for on, false for off.

setTabsOn

public void setTabsOn(boolean on)
Turns on or off the tabs. They are on by default.

Parameters:
on - True for on, false for off.

setTitle

public void setTitle(java.lang.String title)
Sets the title of the panel. The title will be displayed to the side of the tabs.

Parameters:
title - The title or null if no title should be used.

setTitleFont

public void setTitleFont(java.awt.Font font)
Sets the font of the title.

Parameters:
font - The font to use.

show

public java.awt.Component show(java.lang.String name)
Shows the component with the given name. An event will be sent to the registered event listeners saying that the event was shown.

Parameters:
name - The name of the tab for the component.
Returns:
The component that was shown, or null if none.

update

public void update(java.awt.Graphics g)
Implemented to avoid flicker.