com.magelang.tabsplitter
Class TabSplitter

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Panel
                    |
                    +--com.magelang.tabsplitter.TabPanel
                          |
                          +--com.magelang.tabsplitter.TabSplitter
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.event.ActionListener, java.util.EventListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.io.Serializable
Direct Known Subclasses:
TextCollection

public class TabSplitter
extends TabPanel
implements java.awt.event.ActionListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener

TabSplitter -- allows a user to select from several interface components by clicking a tab at the top of the panel. In addition, it allows the user to merge any tabs together into a a single tab using a SplitterLayout.

Each contained component is represented by a tab at the top of the TabSplitter, much like file folders in a file cabinet. When a tab is clicked, it becomes the "selected" tab and its associated component will be displayed.

There are two types of navigational aids provided with the TabSplitter. If there are more tabs than can be displayed in the current window, two triangle buttons will appear. These buttons will scroll the set of tabs left and right.

There are also two buttons marked "+" and "-". These buttons move the user through each tab in succession.

To properly set up a tab panel, you need to do two things:

The thing that sets this tabbed panel apart is how it reacts to mouse drags on its tabs. Click on a tab and drag it to any other tab. The "source" tab will be merged into the "target" tab, combined via a panel with a SplitterLayout. The target tab's text will be modified to list both previous tab texts. In addition, each sub panel that has been merged will have a Button placed above it with the old tab text for that component. Clicking on this button will separate out the subpanel on its own tab once again.

Note: It is extremely important that the user of this tab panel not try to directly use the layoutmanger (via getLayout() and setLayout() ). These two methods could not be overridden to prevent modification, as many GUI builders expect to use it. If you want to switch between tabs, use the "next()" and "previous()" methods provided by TabSplitter, not those of CardLayout.

Use this code at your own risk! MageLang Institute is not responsible for any damage caused directly or indirctly through use of this code.

Use this code at your own risk! MageLang Institute is not responsible for any damage caused directly or indirectly through use of this code.

SOFTWARE RIGHTS

TabSplitter, version 2.0, Scott Stanchfield, MageLang Institute

We reserve no legal rights to this code--it is fully in the public domain. An individual or company may do whatever they wish with source code distributed with it, including including the incorporation of it into commerical software.

However, this code cannot be sold as a standalone product.

We encourage users to develop software with this code. However, we do ask that credit is given to us for developing it By "credit", we mean that if you use these components or incorporate any source code into one of your programs (commercial product, research project, or otherwise) that you acknowledge this fact somewhere in the documentation, research report, etc... If you like these components and have developed a nice tool with the output, please mention that you developed it using these components. In addition, we ask that the headers remain intact in our source code. As long as these guidelines are kept, we expect to continue enhancing this system and expect to make other tools available as they are completed.

The MageLang Support Classes Gang:

See Also:
SplitterLayout, TabPanel, Serialized Form

Inner classes inherited from class java.awt.Panel
java.awt.Panel.AccessibleAWTPanel
 
Inner classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent
 
Fields inherited from class com.magelang.tabsplitter.TabPanel
aTabSelectionListener, leftArrow, leftEnabled, rightArrow, 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
TabSplitter()
          Constructor
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Handle the menu selection events -- just adds in our processing for the swap orientation menu item
protected  void addImpl(java.awt.Component comp, java.lang.Object constraints, int index)
          adds a component to the TabSplitter.
protected  void findWhereToAdd(java.lang.String name, java.awt.Component comp)
          Determine where the component should be placed based on its position when added to the TabSplitter
protected  int getMaxPos()
           
protected  int getPosition(java.lang.Object comp)
          Return the position of the component in the tabsplitter (its physical tab number)
 java.lang.Object getVisibleComponent()
          Get the component that is currently visible
 int[] getVisibleComponentNum()
          Get an array of selected component numbers.
protected  void mergeOrShow(int n)
          Determine if we want to merge a tab or just select one
protected  void mergeTabs(int target, int source)
          Merges two tabs' components onto one tab by putting them both on a splitter panel
 void mouseDragged(java.awt.event.MouseEvent e)
           
 void mouseExited(java.awt.event.MouseEvent e)
          Handle the mouse exiting the TabSplitter
 void mouseMoved(java.awt.event.MouseEvent e)
           
 void mousePressed(java.awt.event.MouseEvent e)
          Handle the mouse being pressed on a TabSplitter
 void mouseReleased(java.awt.event.MouseEvent e)
          Handle the mouse being released on a tabsplitter
 void remove(java.awt.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 separateTabs(java.lang.String name1, java.awt.Component comp1, java.lang.String exp1, java.lang.String name2, java.awt.Component comp2, java.lang.String exp2, com.magelang.tabsplitter.SplitterPanel p)
          separateTabs -- split the selected tab out from its parent Splitterlayout panel
 void setFont(java.awt.Font f)
          Set the font to use when writing the tab text
 void show(java.awt.Component comp)
          Show a component.
 void show(int n)
          Show the nth tab (starting at 0) The number refers to the tab added in the nth position to the tab splitter, not the actual nth tab on the panel.
 void show(java.lang.String tabName)
          Show a component based on tab name This method will find where the component with the specified text is located and display it, even if it is in a SplitterPanel
 void swapOrientation()
          Change the orientation (horizontal/vertical) of all SplitterPanels
 
Methods inherited from class com.magelang.tabsplitter.TabPanel
addTabSelectionListener, determineTabText, determineVisible, drawTabs, fireTabSelected, getBorderColor, getExplicitTabText, getFirstVisible, getInsets, getPopupMenu, getSelectedName, getSelectedTabNum, getTabBackground, getTabColor, getTabColors, getTabColors, getTabText, getTabText, mouseClicked, mouseEntered, next, paint, previous, removeTabSelectionListener, selectTab, setBorderColor, setExplicitTabText, setFirstVisible, setSelectedTabNum, setTabBackground, setTabColor, setTabColors, setTabColors, setTabText, setTabText, setupTabPolygons, shiftLeft, shiftRight, showPhysicalTab, showPopup, tabContains, update
 
Methods inherited from class java.awt.Panel
addNotify, getAccessibleContext
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, getListeners, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, removeContainerListener, removeNotify, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, 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, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.awt.event.MouseListener
mouseClicked, mouseEntered
 

Constructor Detail

TabSplitter

public TabSplitter()
Constructor
Method Detail

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Handle the menu selection events -- just adds in our processing for the swap orientation menu item
Specified by:
actionPerformed in interface java.awt.event.ActionListener
Overrides:
actionPerformed in class TabPanel
Following copied from class: com.magelang.tabsplitter.TabPanel
Parameters:
e - (java.awt.event.ActionEvent) -- the event that was fired to us

addImpl

protected void addImpl(java.awt.Component comp,
                       java.lang.Object constraints,
                       int index)
adds a component to the TabSplitter. Performs the extra processing to keep track of the original position of the component within the TabSplitter
Overrides:
addImpl in class TabPanel
Parameters:
comp - (java.awt.Component) -- the component to be added
constraints - (java.lang.Object) -- constraints on the component
index - (int) -- at which position will the component be added

findWhereToAdd

protected void findWhereToAdd(java.lang.String name,
                              java.awt.Component comp)
Determine where the component should be placed based on its position when added to the TabSplitter

getMaxPos

protected int getMaxPos()

getPosition

protected int getPosition(java.lang.Object comp)
Description copied from class: TabPanel
Return the position of the component in the tabsplitter (its physical tab number)
Overrides:
getPosition in class TabPanel
Following copied from class: com.magelang.tabsplitter.TabPanel
Parameters:
comp - (Component) -- the component to search for.
Returns:
The position of the component (-1 means not found)

getVisibleComponent

public java.lang.Object getVisibleComponent()
Get the component that is currently visible
Overrides:
getVisibleComponent in class TabPanel
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()
Get an array of selected component numbers. These numbers will match the positions of the components when they were originally added to the panel. Each visible component in the currently-selected tab will have its original position returned.
Overrides:
getVisibleComponentNum in class TabPanel
Returns:
array of original positions of visible components.

mergeOrShow

protected void mergeOrShow(int n)
Determine if we want to merge a tab or just select one
Overrides:
mergeOrShow in class TabPanel
Following copied from class: com.magelang.tabsplitter.TabPanel
Parameters:
n - (int) -- the target tab or a merge or tab to show

mergeTabs

protected void mergeTabs(int target,
                         int source)
Merges two tabs' components onto one tab by putting them both on a splitter panel

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Handle the mouse exiting the TabSplitter
Specified by:
mouseExited in interface java.awt.event.MouseListener
Overrides:
mouseExited in class TabPanel

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Handle the mouse being pressed on a TabSplitter
Specified by:
mousePressed in interface java.awt.event.MouseListener
Overrides:
mousePressed in class TabPanel

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Handle the mouse being released on a tabsplitter
Specified by:
mouseReleased in interface java.awt.event.MouseListener
Overrides:
mouseReleased in class TabPanel
Following copied from class: com.magelang.tabsplitter.TabPanel
Parameters:
e - (MouseEvent)

remove

public void remove(int index)
Remove a component from the container. Need to determine a good way to do this! This method is overridden to force a repaint in design mode.
Overrides:
remove in class TabPanel
Parameters:
index - (int) Which component to remove.

remove

public void remove(java.awt.Component comp)
Description copied from class: TabPanel
Remove a component from the container.
Overrides:
remove in class TabPanel
Following copied from class: com.magelang.tabsplitter.TabPanel
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.
Overrides:
removeAll in class TabPanel

separateTabs

public void separateTabs(java.lang.String name1,
                         java.awt.Component comp1,
                         java.lang.String exp1,
                         java.lang.String name2,
                         java.awt.Component comp2,
                         java.lang.String exp2,
                         com.magelang.tabsplitter.SplitterPanel p)
separateTabs -- split the selected tab out from its parent Splitterlayout panel

setFont

public void setFont(java.awt.Font f)
Set the font to use when writing the tab text
Overrides:
setFont in class TabPanel
Following copied from class: com.magelang.tabsplitter.TabPanel
Parameters:
f - (Font) -- the font to use when writing tab text

show

public void show(int n)
Show the nth tab (starting at 0) The number refers to the tab added in the nth position to the tab splitter, not the actual nth tab on the panel. This method will find where component number n is located and display it, even if it is in a SplitterPanel
Overrides:
show in class TabPanel
Following copied from class: com.magelang.tabsplitter.TabPanel
Parameters:
n - (int) the number of the tab to select

show

public void show(java.awt.Component comp)
Show a component. This method will find where the component is located and display it, even if it is in a SplitterPanel
Overrides:
show in class TabPanel
Following copied from class: com.magelang.tabsplitter.TabPanel
Parameters:
comp - (Component) the main component of the tab to select

show

public void show(java.lang.String tabName)
Show a component based on tab name This method will find where the component with the specified text is located and display it, even if it is in a SplitterPanel
Overrides:
show in class TabPanel
Following copied from class: com.magelang.tabsplitter.TabPanel
Parameters:
tabName - (String) the text of the tab to be selected

swapOrientation

public void swapOrientation()
Change the orientation (horizontal/vertical) of all SplitterPanels