|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.Component | +--java.awt.Container | +--java.awt.Panel | +--com.magelang.tabsplitter.TabPanel
TabPanel -- allows a user to select from several interface components by clicking a tab at the top of the panel. Note that this class is only dependent on the JDK; no other class libraries or files are necessary
Each contained component is represented by a tab at the top of the TabPanel, 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 TabPanel. 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:
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 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:
SplitterLayout
, Serialized FormInner 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 |
Field Summary | |
protected java.util.Vector |
aTabSelectionListener
|
protected java.awt.Polygon |
leftArrow
|
protected boolean |
leftEnabled
|
protected java.awt.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(java.awt.event.ActionEvent e)
Handle the popup menu item selections |
protected void |
addImpl(java.awt.Component comp,
java.lang.Object constraints,
int index)
Adds a component to the TabPanel |
void |
addTabSelectionListener(TabSelectionListener newListener)
Add a listener who cares about tab selections |
java.lang.String[] |
determineTabText()
Determines which text will be displayed in the tabs of the Tab panel. |
protected void |
determineVisible()
|
protected void |
drawTabs(java.awt.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 |
java.awt.Color |
getBorderColor()
Gets the borderColor property (java.awt.Color) value. |
protected java.lang.String |
getExplicitTabText(java.awt.Component c)
|
int |
getFirstVisible()
Get the number of the first-visible physical tab. |
java.awt.Insets |
getInsets()
Returns the insets of the TabPanel. |
protected java.awt.PopupMenu |
getPopupMenu()
|
protected int |
getPosition(java.lang.Object comp)
Return the position of the component in the tabsplitter (its physical tab number) |
java.lang.String |
getSelectedName()
Get the tab text of the currently-selected component |
int |
getSelectedTabNum()
Get the number of the currently-selected tab |
java.awt.Color |
getTabBackground()
Gets the color that's behind the tabs |
java.awt.Color |
getTabColor()
Deprecated. the new tabColors property should be used instead. |
java.awt.Color[] |
getTabColors()
Get the colors used to draw the tabs. |
java.awt.Color |
getTabColors(int index)
get a specific tab color. |
java.lang.String[] |
getTabText()
Gets the explicitly-set tab text array. |
java.lang.String |
getTabText(int index)
Gets a specific string from the explicitly-set tab text array. |
java.lang.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(java.awt.event.MouseEvent e)
Dummy method for the MouseListener interface... |
void |
mouseEntered(java.awt.event.MouseEvent e)
Dummy method for the MouseListener interface... |
void |
mouseExited(java.awt.event.MouseEvent e)
Dummy method for the MouseListener interface... |
void |
mousePressed(java.awt.event.MouseEvent e)
handle the mouse button being pressed -- check for right mouse click to bring up popup menu |
void |
mouseReleased(java.awt.event.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(java.awt.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(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 |
removeTabSelectionListener(TabSelectionListener newListener)
Remove a TabSelectionListener. |
protected void |
selectTab(java.awt.event.MouseEvent e)
Check to see if the user clicked on a tab or one of the tab panel navigation buttons. |
void |
setBorderColor(java.awt.Color borderColor)
Sets the borderColor property (java.awt.Color) value. |
protected void |
setExplicitTabText(java.awt.Component c,
java.lang.String text)
|
void |
setFirstVisible(int value)
Explicitly sets which tab is the first to be visible |
void |
setFont(java.awt.Font f)
set the font to use on the tabs |
void |
setSelectedTabNum(int num)
Explicitly pick the selected tab by number. |
void |
setTabBackground(java.awt.Color color)
set the color to use behind the tabs |
void |
setTabColor(java.awt.Color color)
Deprecated. the new tabColors property should be used instead. |
void |
setTabColors(java.awt.Color[] tabColors)
Sets the colors to use when drawing the tabs. |
void |
setTabColors(int index,
java.awt.Color tabColor)
Sets the colors to use when drawing the tabs. |
void |
setTabText(int index,
java.lang.String tabText)
Sets the explicit tab text to use when drawing the tabs. |
void |
setTabText(java.lang.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(java.awt.Component comp)
Select a tab by component |
void |
show(int n)
Select a tab by number |
void |
show(java.lang.String tabName)
Select a tab by text |
void |
showPhysicalTab(int n)
Select a tab by number |
protected void |
showPopup(java.awt.event.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(java.awt.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, 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 |
Field Detail |
protected transient java.awt.Polygon leftArrow
protected transient java.awt.Polygon rightArrow
protected boolean leftEnabled
protected boolean rightEnabled
protected transient java.util.Vector aTabSelectionListener
Constructor Detail |
public TabPanel()
Method Detail |
public void actionPerformed(java.awt.event.ActionEvent e)
actionPerformed
in interface java.awt.event.ActionListener
e
- (java.awt.event.ActionEvent) -- the event that was fired to usprotected void addImpl(java.awt.Component comp, java.lang.Object constraints, int index)
addImpl
in class java.awt.Container
comp
- (Component) -- the component to be addedconstraints
- (Object) -- constraints on the componentindex
- (int) -- at which position will the component be added (-1 means at end)public void addTabSelectionListener(TabSelectionListener newListener)
newListener
- (TabSelectionListener) -- the component who cares...public java.lang.String[] determineTabText()
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.
getTabText()
,
setTabText(java.lang.String[])
protected void determineVisible()
protected void drawTabs(java.awt.Graphics g)
g
- (Graphics) -- the graphics context into which tabs are drawnprotected void fireTabSelected(TabSelectionEvent e)
e
- (TabSelectionEvent) -- the event to pass to the listenersaddTabSelectionListener(com.magelang.tabsplitter.TabSelectionListener)
,
removeTabSelectionListener(com.magelang.tabsplitter.TabSelectionListener)
public java.awt.Color getBorderColor()
setBorderColor(java.awt.Color)
protected java.lang.String getExplicitTabText(java.awt.Component c)
public int getFirstVisible()
setFirstVisible(int)
public java.awt.Insets getInsets()
getInsets
in class java.awt.Container
LayoutManager
protected java.awt.PopupMenu getPopupMenu()
protected int getPosition(java.lang.Object comp)
comp
- (Component) -- the component to search for.public java.lang.String getSelectedName()
public int getSelectedTabNum()
setSelectedTabNum(int)
public java.awt.Color getTabBackground()
setTabBackground(java.awt.Color)
public java.awt.Color getTabColor()
getTabColors()
public java.awt.Color[] getTabColors()
setTabColors(java.awt.Color[])
public java.awt.Color getTabColors(int index)
index
- The index value into the property array.getTabColors()
,
setTabColors(java.awt.Color[])
public java.lang.String[] getTabText()
setTabText(java.lang.String[])
,
determineTabText()
public java.lang.String getTabText(int index)
setTabText(java.lang.String[])
,
determineTabText()
public java.lang.Object getVisibleComponent()
public int[] getVisibleComponentNum()
protected void mergeOrShow(int n)
n
- (int) -- the target tab or a merge or tab to showpublic void mouseClicked(java.awt.event.MouseEvent e)
mouseClicked
in interface java.awt.event.MouseListener
public void mouseEntered(java.awt.event.MouseEvent e)
mouseEntered
in interface java.awt.event.MouseListener
public void mouseExited(java.awt.event.MouseEvent e)
mouseExited
in interface java.awt.event.MouseListener
public void mousePressed(java.awt.event.MouseEvent e)
mousePressed
in interface java.awt.event.MouseListener
public void mouseReleased(java.awt.event.MouseEvent e)
mouseReleased
in interface java.awt.event.MouseListener
e
- (MouseEvent)public void next()
public void paint(java.awt.Graphics g)
paint
in class java.awt.Container
g
- (Graphics) The graphics context into which the tab panel is paintedpublic void previous()
public void remove(int index)
remove
in class java.awt.Container
index
- (int) Which component to remove.public void remove(java.awt.Component comp)
remove
in class java.awt.Container
comp
- (Component) Which component to remove.public void removeAll()
removeAll
in class java.awt.Container
public void removeTabSelectionListener(TabSelectionListener newListener)
newListener
- com.magelang.tabsplitter.TabSelectionListeneraddTabSelectionListener(com.magelang.tabsplitter.TabSelectionListener)
protected void selectTab(java.awt.event.MouseEvent e)
e
- (java.awt.event.MouseEvent) The mouse click.public void setBorderColor(java.awt.Color borderColor)
borderColor
- The new value for the property.getBorderColor()
protected void setExplicitTabText(java.awt.Component c, java.lang.String text)
public void setFirstVisible(int value)
value
- (int) the number for the first tabpublic void setFont(java.awt.Font f)
setFont
in class java.awt.Container
f
- (Font) -- the font to use when writing tab textpublic void setSelectedTabNum(int num)
num
- int -- the tab number to selectgetSelectedTabNum()
public void setTabBackground(java.awt.Color color)
color
- (Color) the color to draw behind the tabspublic void setTabColor(java.awt.Color color)
setTabColors(java.awt.Color[])
public void setTabColors(java.awt.Color[] tabColors)
tabColors
- The new value for the property.getTabColors()
public void setTabColors(int index, java.awt.Color tabColor)
tabColors
- The new value for the property.getTabColors()
public void setTabText(java.lang.String[] tabText)
tabText
- The new value for the property.getTabText()
,
determineTabText()
public void setTabText(int index, java.lang.String tabText)
index
- (int) the specific text to settabText
- The new value for the property.getTabText()
,
determineTabText()
protected void setupTabPolygons()
g
- (java.awt.Graphics) The graphics context into which the tabs will be drawnpublic void shiftLeft()
public void shiftRight()
public void show(int n)
n
- (int) the number of the tab to selectpublic void show(java.awt.Component comp)
comp
- (Component) the main component of the tab to selectpublic void show(java.lang.String tabName)
tabName
- (String) the text of the tab to be selectedpublic void showPhysicalTab(int n)
n
- (int) the number of the tab to selectprotected void showPopup(java.awt.event.MouseEvent e)
e
- (MouseEvent) tells where to bring it upprotected boolean tabContains(int num, int x, int y)
num
- (int) number of the tab to checkx
- (int) x-coord to checky
- (int) y-coord to checkpublic void update(java.awt.Graphics g)
update
in class java.awt.Container
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |