001: /*
002: * SSHTools - Java SSH2 API
003: *
004: * Copyright (C) 2002-2003 Lee David Painter and Contributors.
005: *
006: * Contributions made by:
007: *
008: * Brett Smith
009: * Richard Pernavas
010: * Erwin Bolwidt
011: *
012: * This program is free software; you can redistribute it and/or
013: * modify it under the terms of the GNU General Public License
014: * as published by the Free Software Foundation; either version 2
015: * of the License, or (at your option) any later version.
016: *
017: * This program is distributed in the hope that it will be useful,
018: * but WITHOUT ANY WARRANTY; without even the implied warranty of
019: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
020: * GNU General Public License for more details.
021: *
022: * You should have received a copy of the GNU General Public License
023: * along with this program; if not, write to the Free Software
024: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
025: */
026: package com.sshtools.common.ui;
027:
028: import java.awt.*;
029:
030: import javax.swing.*;
031: import javax.swing.event.*;
032:
033: /**
034: *
035: *
036: * @author $author$
037: * @version $Revision: 1.13 $
038: */
039: public class Tabber extends JTabbedPane {
040: /**
041: * Creates a new Tabber object.
042: */
043: public Tabber() {
044: this (TOP);
045: }
046:
047: /**
048: * Creates a new Tabber object.
049: *
050: * @param tabPlacement
051: */
052: public Tabber(int tabPlacement) {
053: super (tabPlacement);
054: addChangeListener(new ChangeListener() {
055: public void stateChanged(ChangeEvent e) {
056: if (getSelectedIndex() != -1) {
057: getTabAt(getSelectedIndex()).tabSelected();
058: }
059: }
060: });
061: }
062:
063: /**
064: *
065: *
066: * @param i
067: *
068: * @return
069: */
070: public Tab getTabAt(int i) {
071: return ((TabPanel) getComponentAt(i)).getTab();
072: }
073:
074: /**
075: *
076: *
077: * @return
078: */
079: public boolean validateTabs() {
080: for (int i = 0; i < getTabCount(); i++) {
081: Tab tab = ((TabPanel) getComponentAt(i)).getTab();
082:
083: if (!tab.validateTab()) {
084: setSelectedIndex(i);
085:
086: return false;
087: }
088: }
089:
090: return true;
091: }
092:
093: /**
094: *
095: */
096: public void applyTabs() {
097: for (int i = 0; i < getTabCount(); i++) {
098: Tab tab = ((TabPanel) getComponentAt(i)).getTab();
099: tab.applyTab();
100: }
101: }
102:
103: /**
104: *
105: *
106: * @param tab
107: */
108: public void addTab(Tab tab) {
109: addTab(tab.getTabTitle(), tab.getTabIcon(), new TabPanel(tab),
110: tab.getTabToolTipText());
111: }
112:
113: class TabPanel extends JPanel {
114: private Tab tab;
115:
116: TabPanel(Tab tab) {
117: super (new BorderLayout());
118: this .tab = tab;
119: setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
120: add(tab.getTabComponent(), BorderLayout.CENTER);
121: }
122:
123: public Tab getTab() {
124: return tab;
125: }
126: }
127: }
|