/***************************************************************************** gui.TabPanel Container for a set of Tab Cards or Tab Folders. bruce.miller@nist.gov Contribution of the National Institute of Standards and Technology, not subject to copyright. *****************************************************************************/ package gui; import java.applet.*; import java.awt.*; import java.util.*; /** ************************************************************************** TabPanel is a container for a set of tabbed cards, lying atop each other, but with the labelled tabs exposed at the top. That is, the classic Tab Folder. Each card is an awt.component of whatever design you wish. The topmost card can be selected programmatically (Using first(), last(), next(), previous(), or show(name)), or by clicking on the tab with the mouse.
Components should be added using add(name,component)); the name is used to label the tab. If you set the layout manager, it should be a subclass of CardLayout. You probably want to setBackground() to a color contrasting that of the parent and the components.
Whenever a card is selected (whether by software or mouse), an event with
id = Event.WINDOW_EXPOSE is sent to the selected component. Handling this
event may be useful for deferred initialization.
@author Bruce R. Miller (bruce.miller@nist.gov)
@author Contribution of the National Institute of Standards and Technology,
@author not subject to copyright.
*/
public class TabPanel extends Panel {
/** The width of the margins around the cards. */
public int margin = 3; // width of margins around cards
Font tabFont; // for tab labels
FontMetrics metric;
int nCards = 0; // total # of cards
Vector names = new Vector(10,10); // contains the (interned) card names
int pos[], width[]; // position & width of each tab
int selected = 0; // index of selected (displayed) card
int offset = 0; // left shift to allow for `too many' tabs
int tabH; // height of tab (set from tabFont)
int tabN = 12, // #points along edges: must = (2*int + 2)
tabLeft[][] = new int[2][tabN], // coordinates of tab edge curves
tabRight[][] = new int[2][tabN];
Image offscreen=null;
/** Creates an empty TabPanel. */
public TabPanel() {
setLayout(new CardLayout());
setTabFont(new Font("Helvetica",Font.BOLD,12)); }
/***************************************************
internals */
int findComponent(Component c) { // find index of a given component
for (int i=0; i