001: /*
002: * de.jwic.controls.TabStripControl
003: * $Id: TabStripControl.java,v 1.5 2007/04/03 12:44:41 aroncotrau Exp $
004: */
005: package de.jwic.controls;
006:
007: import java.util.ArrayList;
008: import java.util.List;
009:
010: import de.jwic.base.Control;
011: import de.jwic.base.ControlContainer;
012: import de.jwic.base.IControlContainer;
013: import de.jwic.base.JWicException;
014:
015: /**
016: * A TabStrip acts like the dividers in a notebook or the labels on a group of file folders.
017: * By using a TabStrip control, you can define multiple pages for the same area of a panel.
018: *
019: * @author Florian Lippisch
020: */
021: public class TabStripControl extends ControlContainer {
022:
023: private static final long serialVersionUID = 1L;
024:
025: public static final String LOCATION_TOP = "top";
026: public static final String LOCATION_BOTTOM = "bottom";
027: public static final String LOCATION_LEFT = "left";
028: public static final String LOCATION_RIGHT = "right";
029:
030: public final static String ACTION_OPENTAB = "opentab";
031: private String strActiveTabName = null;
032: private String location = LOCATION_TOP;
033:
034: private List tabs = new ArrayList();
035:
036: /**
037: * @param container
038: */
039: public TabStripControl(IControlContainer container) {
040: super (container);
041: }
042:
043: /**
044: * @param container
045: * @param name
046: */
047: public TabStripControl(IControlContainer container, String name) {
048: super (container, name);
049: }
050:
051: /* (non-Javadoc)
052: * @see de.jwic.base.ControlContainer#registerControl(de.jwic.base.Control, java.lang.String)
053: */
054: public void registerControl(Control control, String name)
055: throws JWicException {
056: if (!(control instanceof TabControl)) {
057: throw new IllegalArgumentException(
058: "Only TabControls may be added to a TabStripControl.");
059: }
060: super .registerControl(control, name);
061: tabs.add(control);
062:
063: }
064:
065: /* (non-Javadoc)
066: * @see de.jwic.base.ControlContainer#unregisterControl(de.jwic.base.Control)
067: */
068: public void unregisterControl(Control control) {
069: if (control != null) {
070: tabs.remove(control);
071: if (control.getName().equals(getActiveTabName())) {
072: if (tabs.size() > 0) {
073: setActiveTabName(((Control) tabs.get(0)).getName());
074: } else {
075: setActiveTabName(null);
076: }
077: }
078: }
079: super .unregisterControl(control);
080: }
081:
082: /**
083: * Add a new tab with a default name.
084: * @param titleID java.lang.String
085: * @param name java.lang.String
086: */
087: public TabControl addTab(String titleID) {
088: return addTab(titleID, null);
089: }
090:
091: /**
092: * Add a new tab with the specified title and name.
093: * @param titleID java.lang.String
094: * @param name java.lang.String
095: */
096: public TabControl addTab(String titleID, String name) {
097: TabControl tc = new TabControl(this , name);
098: tc.setTitle(titleID);
099:
100: if (strActiveTabName == null)
101: setActiveTabName(tc.getName());
102:
103: return tc;
104: }
105:
106: /* (non-Javadoc)
107: * @see de.jwic.base.ControlContainer#actionPerformed(java.lang.String, java.lang.String)
108: */
109: public void actionPerformed(String actionId, String parameter) {
110:
111: if (actionId.equals(ACTION_OPENTAB)) {
112: setActiveTabName(parameter);
113: }
114:
115: }
116:
117: /**
118: * Returns the name of the active tab.
119: * @return java.lang.String
120: */
121: public String getActiveTabName() {
122: return strActiveTabName;
123: }
124:
125: /**
126: * Creation date: (03.02.2003 12:26:12)
127: * @param newActiveTabName java.lang.String
128: */
129: public void setActiveTabName(java.lang.String newActiveTabName) {
130: strActiveTabName = newActiveTabName;
131: setRequireRedraw(true);
132: }
133:
134: /**
135: * Returns the list of tabs.
136: * @return List of TabControl objects.
137: */
138: public List getTabs() {
139: return tabs;
140: }
141:
142: /* (non-Javadoc)
143: * @see de.jwic.base.ControlContainer#isRenderingRelevant(de.jwic.base.Control)
144: */
145: public boolean isRenderingRelevant(Control childControl) {
146: return childControl.getName().equals(strActiveTabName);
147: }
148:
149: /**
150: * @return the location of the tabs
151: */
152: public String getLocation() {
153: return location;
154: }
155:
156: /**
157: * Set the location of the tabs
158: * @param newLocation
159: */
160: public void setLocation(String newLocation) {
161: if (!this .location.equals(newLocation)) {
162: setRequireRedraw(true);
163: }
164:
165: this.location = newLocation;
166: }
167: }
|