001: /*
002: #IFNDEF ALT_LICENSE
003: ThinWire(R) RIA Ajax Framework
004: Copyright (C) 2003-2007 Custom Credit Systems
005:
006: This library is free software; you can redistribute it and/or modify it under
007: the terms of the GNU Lesser General Public License as published by the Free
008: Software Foundation; either version 2.1 of the License, or (at your option) any
009: later version.
010:
011: This library is distributed in the hope that it will be useful, but WITHOUT ANY
012: WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
013: PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
014:
015: You should have received a copy of the GNU Lesser General Public License along
016: with this library; if not, write to the Free Software Foundation, Inc., 59
017: Temple Place, Suite 330, Boston, MA 02111-1307 USA
018:
019: Users who would rather have a commercial license, warranty or support should
020: contact the following company who invented, built and supports the technology:
021:
022: Custom Credit Systems, Richardson, TX 75081, USA.
023: email: info@thinwire.com ph: +1 (888) 644-6405
024: http://www.thinwire.com
025: #ENDIF
026: [ v1.2_RC2 ]
027: */
028: package thinwire.ui;
029:
030: import java.util.List;
031:
032: import thinwire.util.ImageInfo;
033:
034: /**
035: * A TabSheet is a Panel that can be layered, so that a user can switch between
036: * tab sheets.
037: * <p>
038: * <b>Example:</b> <br>
039: * <img src="doc-files/TabFolder-1.png"> <br>
040: *
041: * <pre>
042: * Dialog dlg = new Dialog("TabFolder Test");
043: * dlg.setBounds(25, 25, 600, 400);
044: *
045: * TabSheet tSheet1 = new TabSheet("Sheet 1");
046: * TabSheet tSheet2 = new TabSheet("Sheet 2");
047: *
048: * TabFolder tFolder = new TabFolder();
049: * tFolder.setBounds(50, 25, 500, 300);
050: * tFolder.getChildren().add(tSheet1);
051: * tFolder.getChildren().add(tSheet2);
052: *
053: * TextField tf = new TextField();
054: * tf.setBounds(25, 25, 150, 20);
055: * tSheet2.getChildren().add(tf);
056: *
057: * Button firstButton = new Button("Change Tab Title 1");
058: * firstButton.setBounds(50, 50, 150, 30);
059: * firstButton.addActionListener(Button.ACTION_CLICK, new ActionListener() {
060: * public void actionPerformed(ActionEvent ev) {
061: * ((TabSheet) ((Button) ev.getSource()).getParent()).setText("New Title 1");
062: * }
063: * });
064: * tSheet1.getChildren().add(firstButton);
065: * dlg.getChildren().add(tFolder);
066: * dlg.setVisible(true);
067: * </pre>
068: *
069: * </p>
070: * <p>
071: * <b>Keyboard Navigation:</b><br>
072: * <table border="1">
073: * <tr>
074: * <td>KEY</td>
075: * <td>RESPONSE</td>
076: * <td>NOTE</td>
077: * </tr>
078: * </table>
079: * </p>
080: *
081: * @author Joshua J. Gertzen
082: */
083: public class TabSheet extends AbstractContainer<Component> implements
084: TextComponent, ImageComponent {
085: private String text = "";
086: private boolean allowBoundsChange;
087: private ImageInfo imageInfo = new ImageInfo(null);
088:
089: /**
090: * Construct a new TabSheet with no text.
091: */
092: public TabSheet() {
093: this (null, null);
094: }
095:
096: /**
097: * Creates a new TabSheet with the specified text.
098: * @param text the text to dispaly on the tab part of the TabSheet.
099: */
100: public TabSheet(String text) {
101: this (text, null);
102: }
103:
104: public TabSheet(String text, String image) {
105: setText(text);
106: setImage(image);
107: }
108:
109: public String getImage() {
110: return imageInfo.getName();
111: }
112:
113: public void setImage(String image) {
114: String oldImage = this .imageInfo.getName();
115: imageInfo = new ImageInfo(image);
116: firePropertyChange(this , PROPERTY_IMAGE, oldImage,
117: this .imageInfo.getName());
118: }
119:
120: public ImageInfo getImageInfo() {
121: return imageInfo;
122: }
123:
124: /**
125: * Returns the text displayed on the tab part of the TabSheet.
126: * @return the text displayed on the tab part of the TabSheet.
127: */
128: public String getText() {
129: return text;
130: }
131:
132: /**
133: * Sets the text that is displayed on the tab part of the TabSheet.
134: * @param text the text to be shown.
135: */
136: public void setText(String text) {
137: String oldText = this .text;
138: this .text = text == null ? "" : text;
139: firePropertyChange(this , PROPERTY_TEXT, oldText, this .text);
140: }
141:
142: void boundsChanged(int x, int y, int width, int height) {
143: try {
144: allowBoundsChange = true;
145: super .setBounds(x, y, width, height);
146: } finally {
147: allowBoundsChange = false;
148: }
149: }
150:
151: public int getInnerHeight() {
152: int innerHeight = super .getInnerHeight()
153: - TabFolder.TABS_HEIGHT;
154: return innerHeight < 0 ? 0 : innerHeight;
155: }
156:
157: public void setWidth(int width) {
158: if (allowBoundsChange) {
159: super .setWidth(width);
160: } else {
161: TabFolder tf = (TabFolder) getParent();
162:
163: if (tf == null) {
164: throw new IllegalStateException(
165: "You must first add a TabSheet to a TabFolder before you can set the 'width' property");
166: } else {
167: tf.setWidth(width);
168: }
169: }
170: }
171:
172: public void setHeight(int height) {
173: if (allowBoundsChange) {
174: super .setHeight(height);
175: } else {
176: TabFolder tf = (TabFolder) getParent();
177:
178: if (tf == null) {
179: throw new IllegalStateException(
180: "You must first add a TabSheet to a TabFolder before you can set the 'height' property");
181: } else {
182: tf.setHeight(height);
183: }
184: }
185: }
186:
187: public void setX(int x) {
188: if (allowBoundsChange) {
189: super .setX(x);
190: } else {
191: TabFolder tf = (TabFolder) getParent();
192:
193: if (tf == null) {
194: throw new IllegalStateException(
195: "You must first add a TabSheet to a TabFolder before you can set the 'x' property");
196: } else {
197: tf.setX(x);
198: }
199: }
200: }
201:
202: public void setY(int y) {
203: if (allowBoundsChange) {
204: super .setY(y);
205: } else {
206: TabFolder tf = (TabFolder) getParent();
207:
208: if (tf == null) {
209: throw new IllegalStateException(
210: "You must first add a TabSheet to a TabFolder before you can set the 'y' property");
211: } else {
212: tf.setY(y);
213: }
214: }
215: }
216:
217: public void setVisible(boolean visible) {
218: boolean oldVisible = isVisible();
219: super .setVisible(visible);
220:
221: if (oldVisible != visible) {
222: TabFolder tf = (TabFolder) getParent();
223:
224: if (tf != null) {
225: List<TabSheet> l = tf.getChildren();
226: int index = l.indexOf(this );
227:
228: if (index == tf.getCurrentIndex()) {
229: if (index + 1 < l.size()) {
230: index++;
231: } else if (index > 0) {
232: index--;
233: } else {
234: index = -1;
235: }
236:
237: tf.setCurrentIndex(index);
238: }
239: }
240: }
241: }
242:
243: /**
244: * This property is unsupported by the TabSheet component.
245: * @throws UnsupportedOperationException indicating this property is not supported by TabSheet.
246: */
247: public Object getLimit() {
248: throw new UnsupportedOperationException(
249: getStandardPropertyUnsupportedMsg(PROPERTY_LIMIT, true));
250: }
251:
252: /**
253: * This property is unsupported by the TabSheet component.
254: * @throws UnsupportedOperationException indicating this property is not supported by TabSheet.
255: */
256: public Component setLimit(Object limit) {
257: throw new UnsupportedOperationException(
258: getStandardPropertyUnsupportedMsg(PROPERTY_LIMIT, false));
259: }
260: }
|