1 /***
2 * The contents of this file are subject to the Mozilla Public
3 * License Version 1.1 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of
5 * the License at http://www.mozilla.org/MPL/
6 *
7 * Software distributed under the License is distributed on an "AS
8 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
9 * implied. See the License for the specific language governing
10 * rights and limitations under the License.
11 *
12 * The Original Code is pow2WebGui library.
13 *
14 * The Initial Owner of the Original Code is Power Of Two S.R.L.
15 * Portions created by Power Of Two S.R.L. are Copyright (C) Power Of Two S.R.L.
16 * All Rights Reserved.
17 *
18 * Contributor(s):
19 */
20
21 package com.pow2.webgui.tabbedselector;
22
23
24 import java.util.ArrayList;
25
26 import com.pow2.webgui.Widget;
27
28
29 /***
30 * TabbedSelector class.
31 *
32 * @author Luca Fossato
33 * @created 22 September 2001
34 */
35 public class TabbedSelector extends Widget
36 {
37 /*** tabbedSelector key */
38 public final static String KEY = "tabbedSelector";
39
40 /*** tab list */
41 protected ArrayList tabs = null;
42
43 /*** name of the selected tab */
44 protected String selectedTab = null;
45
46
47 /***
48 * Default protected constructor.
49 */
50 public TabbedSelector()
51 {
52 tabs = new ArrayList();
53 }
54
55
56 /***
57 * Sets the selectedTab attribute of the TabbedPanel object
58 *
59 * @param newSelectedTab the new selectedTab value
60 */
61 public void setSelectedTab(String newSelectedTab)
62 {
63 selectedTab = newSelectedTab;
64 }
65
66
67 /***
68 * Gets the selectedTab attribute of the TabbedPanel object
69 *
70 * @return The selectedTab value
71 */
72 public String getSelectedTab()
73 {
74 return selectedTab;
75 }
76
77
78 /***
79 * Gets the the tabs list of this TabbedPanel
80 *
81 * @return the ArrayList object containing the tabs list.
82 */
83 public ArrayList getTabs()
84 {
85 return tabs;
86 }
87
88
89 /***
90 * Adds a tab widget to this TabbedPanel.
91 *
92 * @param tab the tab object to add to.
93 * @param cnt the tab content.
94 */
95 public void addTab(Tab tab, StringBuffer cnt)
96 {
97 addTab(tab);
98
99 if (tab.isSelected())
100 content = cnt;
101 }
102
103
104 /***
105 * Adds a tab widget to this TabbedPanel.
106 *
107 * @param tab the tab object to add to.
108 */
109 public void addTab(Tab tab)
110 {
111 tabs.add(tab);
112 tab.setParentW(this);
113 tab.setType();
114 }
115
116
117 /***
118 * Removes the input tab component from the tabbedPanel list.
119 *
120 * @param tab the tab object to remove.
121 */
122 public void removeTab(Tab tab)
123 {
124 if (tab != null)
125 removeTab(tab.getName());
126 }
127
128
129 /***
130 * Removes the tab component with the given name
131 * from the tabbedPanel list.
132 *
133 * @param name the name of the tab component to remove.
134 */
135 public synchronized void removeTab(String name)
136 {
137 if (name == null)
138 {
139 cat.warn("::removeTab - cannot remove a tab with a null name.");
140 return;
141 }
142
143 for (int i = 0; i < tabs.size(); i++)
144 {
145 Tab tab = (Tab) tabs.get(i);
146
147 if (tab.getId().equals(name))
148 {
149 tabs.remove(i);
150 tab.setParentW(null);
151 return;
152 }
153 }
154 }
155
156
157 /***
158 * Removes all the tab components
159 */
160 public synchronized void removeTabs()
161 {
162 for (int i = 0; i < tabs.size(); i++)
163 {
164 Tab tab = (Tab) tabs.get(i);
165 tabs.remove(i);
166 tab.setParentW(null);
167 }
168 }
169
170
171 /***
172 * Updates the input TabbedSelector attributes using the attributes
173 * of this class.
174 * <br>
175 * THis method is called by the relative widget tag class.
176 *
177 * @param w Description of the Parameter
178 */
179 public void updateAttributes(TabbedSelector w)
180 {
181 super.updateAttributes(w);
182 selectedTab = w.getSelectedTab();
183 }
184
185
186
187
188 /***
189 * PROTECTED METHODS here
190 */
191
192
193 /***
194 * Gets the description of the TabbedPanel tabs.
195 *
196 * @return the description of the TabbedPanel tabs
197 * @exception Exception if any error occurs
198 */
199 protected StringBuffer getTabsDescription() throws Exception
200 {
201 StringBuffer sb = new StringBuffer();
202 Tab tab = null;
203
204 if (tabs != null)
205 {
206 for (int i = 0; i < tabs.size(); i++)
207 {
208 tab = (Tab)tabs.get(i);
209 sb.append(tab.draw());
210
211 }
212 }
213
214 return sb;
215 }
216 }