001: /*
002: * Copyright (C) 2004 NNL Technology AB
003: * Visit www.infonode.net for information about InfoNode(R)
004: * products and how to contact NNL Technology AB.
005: *
006: * This program is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU General Public License
008: * as published by the Free Software Foundation; either version 2
009: * of the License, or (at your option) any later version.
010: *
011: * This program is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
014: * GNU General Public License for more details.
015: *
016: * You should have received a copy of the GNU General Public License
017: * along with this program; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
019: * MA 02111-1307, USA.
020: */
021:
022: // $Id: TabContentPanel.java,v 1.19 2005/12/04 13:46:05 jesper Exp $
023: package net.infonode.tabbedpanel;
024:
025: import net.infonode.gui.layout.StackableLayout;
026:
027: import javax.swing.*;
028: import java.awt.*;
029:
030: /**
031: * A TabContentPanel is a container for tabs' content components. It listens to
032: * a tabbed panel and manages the tabs' content components by showing and hiding
033: * the components based upon the selection of tabs in the tabbed panel.
034: *
035: * @author $Author: jesper $
036: * @version $Revision: 1.19 $
037: * @see TabbedPanel
038: * @see Tab
039: */
040: public class TabContentPanel extends JPanel {
041: private TabbedPanel tabbedPanel;
042: private StackableLayout layout = new StackableLayout(this );
043: private TabListener listener = new TabAdapter() {
044: public void tabSelected(TabStateChangedEvent event) {
045: layout.showComponent(event.getTab() == null ? null : event
046: .getTab().getContentComponent());
047: }
048:
049: public void tabRemoved(TabRemovedEvent event) {
050: if (event.getTab().getContentComponent() != null)
051: remove(event.getTab().getContentComponent());
052: }
053:
054: public void tabAdded(TabEvent event) {
055: if (event.getTab().getContentComponent() != null)
056: add(event.getTab().getContentComponent());
057: }
058: };
059:
060: /**
061: * <p>
062: * Constructs a TabContentPanel
063: * </p>
064: *
065: * <p><strong>Note:</strong> setTabbedPanel(...) must be called before the tabs'
066: * content components can be shown on the screen.
067: * </p>
068: *
069: * @since ITP 1.4.0
070: */
071: public TabContentPanel() {
072: setLayout(layout);
073: setOpaque(false);
074: layout.setAutoShowFirstComponent(false);
075: }
076:
077: /**
078: * Constructs a TabContentPanel
079: *
080: * @param tabbedPanel the TabbedPanel for whom this component is the tabs' content
081: * component container
082: */
083: public TabContentPanel(TabbedPanel tabbedPanel) {
084: this ();
085: setTabbedPanel(tabbedPanel);
086: }
087:
088: /**
089: * Gets the TabbedPanel for whom this component is the tabs' content component
090: * container
091: *
092: * @return the TabbedPanel
093: */
094: public TabbedPanel getTabbedPanel() {
095: return tabbedPanel;
096: }
097:
098: /**
099: * Sets the TabbedPanel
100: *
101: * @param tabbedPanel the TabbedPanel for whom this component is the tabs' content
102: * component container
103: * @since ITP 1.4.0
104: */
105: public void setTabbedPanel(TabbedPanel tabbedPanel) {
106: if (this .tabbedPanel != tabbedPanel) {
107: if (this .tabbedPanel != null) {
108: this .tabbedPanel.removeTabListener(listener);
109: removeAll();
110: }
111:
112: this .tabbedPanel = tabbedPanel;
113:
114: if (this .tabbedPanel != null) {
115: tabbedPanel.addTabListener(listener);
116: for (int i = 0; i < tabbedPanel.getTabCount(); i++) {
117: Component c = tabbedPanel.getTabAt(i)
118: .getContentComponent();
119: if (c != null)
120: add(tabbedPanel.getTabAt(i)
121: .getContentComponent());
122: }
123: }
124: }
125: }
126: }
|