KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sshtools > ui > swing > TabbedTabber


1 /*
2  * SSHTools - Java SSH2 API
3  *
4  * Copyright (C) 2002 Lee David Painter.
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public License
8  * as published by the Free Software Foundation; either version 2 of
9  * the License, or (at your option) any later version.
10  *
11  * You may also distribute it and/or modify it under the terms of the
12  * Apache style J2SSH Software License. A copy of which should have
13  * been provided with the distribution.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  * License document supplied with your distribution for more details.
19  *
20  */

21
22 package com.sshtools.ui.swing;
23
24 import java.awt.BorderLayout JavaDoc;
25 import java.awt.Component JavaDoc;
26
27 import javax.swing.BorderFactory JavaDoc;
28 import javax.swing.JPanel JavaDoc;
29 import javax.swing.event.ChangeEvent JavaDoc;
30 import javax.swing.event.ChangeListener JavaDoc;
31
32 /**
33  *
34  *
35  * @author $author$
36  * @version $Revision: 1.2 $
37  */

38
39 public class TabbedTabber
40
41 extends ClosableTabbedPane implements Tabber {
42
43     /**
44      * Creates a new TabbedTabber object.
45      */

46
47     public TabbedTabber() {
48         this(TOP);
49
50     }
51
52     /**
53      * Creates a new TabbedTabber object.
54      *
55      * @param tabPlacement
56      */

57
58     public TabbedTabber(int tabPlacement) {
59         super(tabPlacement);
60         addChangeListener(new ChangeListener JavaDoc() {
61
62             public void stateChanged(ChangeEvent JavaDoc e) {
63                 if (getSelectedIndex() != -1) {
64                     getTabAt(getSelectedIndex()).tabSelected();
65                 }
66
67             }
68
69         });
70
71     }
72
73     /**
74      *
75      *
76      * @param i
77      *
78      * @return
79      */

80
81     public Tab getTabAt(int i) {
82         return ((TabPanel) getComponentAt(i)).getTab();
83
84     }
85
86     /**
87      *
88      *
89      * @return
90      */

91
92     public boolean validateTabs() {
93         for (int i = 0; i < getTabCount(); i++) {
94             Tab tab = ((TabPanel) getComponentAt(i)).getTab();
95             if (!tab.validateTab()) {
96                 setSelectedIndex(i);
97                 return false;
98             }
99         }
100         return true;
101
102     }
103
104     /**
105      *
106      */

107
108     public void applyTabs() {
109         for (int i = 0; i < getTabCount(); i++) {
110             Tab tab = ((TabPanel) getComponentAt(i)).getTab();
111             tab.applyTab();
112         }
113
114     }
115
116     public synchronized Tab getSelectedTab() {
117         int idx = getSelectedIndex();
118         return idx == -1 ? null : getTabAt(idx);
119     }
120
121     /*
122      * (non-Javadoc)
123      *
124      * @see com.sshtools.appframework.ui.Tabber#getComponent()
125      */

126     public Component JavaDoc getComponent() {
127         return this;
128     }
129
130     /*
131      * (non-Javadoc)
132      *
133      * @see com.sshtools.appframework.ui.Tabber#removeAllTabs()
134      */

135     public void removeAllTabs() {
136         removeAll();
137     }
138
139     /**
140      *
141      *
142      * @param tab
143      */

144
145     public void addTab(Tab tab) {
146         addTab(tab.getTabTitle(), tab.getTabIcon(), new TabPanel(tab), tab.getTabToolTipText());
147
148     }
149
150     class TabPanel
151
152     extends JPanel JavaDoc {
153
154         private Tab tab;
155
156         TabPanel(Tab tab) {
157             super(new BorderLayout JavaDoc());
158             this.tab = tab;
159             setOpaque(false);
160             add(tab.getTabComponent(), BorderLayout.CENTER);
161
162         }
163
164         public Tab getTab() {
165             return tab;
166
167         }
168
169     }
170
171 }
172
Popular Tags