KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > swixml > XTabbedPane


1 /*--
2  $Id: XTabbedPane.java,v 1.1 2004/03/01 07:56:09 wolfpaulus Exp $
3
4  Copyright (C) 2003-2004 Wolf Paulus.
5  All rights reserved.
6
7  Redistribution and use in source and binary forms, with or without
8  modification, are permitted provided that the following conditions
9  are met:
10
11  1. Redistributions of source code must retain the above copyright
12  notice, this list of conditions, and the following disclaimer.
13
14  2. Redistributions in binary form must reproduce the above copyright
15  notice, this list of conditions, and the disclaimer that follows
16  these conditions in the documentation and/or other materials provided
17  with the distribution.
18
19  3. The end-user documentation included with the redistribution,
20  if any, must include the following acknowledgment:
21         "This product includes software developed by the
22          SWIXML Project (http://www.swixml.org/)."
23  Alternately, this acknowledgment may appear in the software itself,
24  if and wherever such third-party acknowledgments normally appear.
25
26  4. The name "Swixml" must not be used to endorse or promote products
27  derived from this software without prior written permission. For
28  written permission, please contact <info_AT_swixml_DOT_org>
29
30  5. Products derived from this software may not be called "Swixml",
31  nor may "Swixml" appear in their name, without prior written
32  permission from the Swixml Project Management.
33
34  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
35  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
36  OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
37  DISCLAIMED. IN NO EVENT SHALL THE SWIXML PROJECT OR ITS
38  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
40  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
41  USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
42  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
43  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
44  OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45  SUCH DAMAGE.
46  ====================================================================
47
48  This software consists of voluntary contributions made by many
49  individuals on behalf of the Swixml Project and was originally
50  created by Wolf Paulus <wolf_AT_swixml_DOT_org>. For more information
51  on the Swixml Project, please see <http://www.swixml.org/>.
52 */

53
54 package org.swixml;
55
56 import org.jdom.Attribute;
57 import org.swixml.converters.ImageIconConverter;
58
59 import javax.swing.*;
60 import java.util.StringTokenizer JavaDoc;
61
62 /**
63  * XSplitPane simple extends JSplitPane to clear components
64  * during the construction process
65  *
66  * @author <a HREF="mailto:wolf@paulus.com">Wolf Paulus</a>
67  * @version $Revision: 1.1 $
68  */

69
70 public class XTabbedPane extends JTabbedPane {
71
72   /**
73    * Sets the title for all tabs.
74    * An internal exception is raised if there is no tab at that index.
75    *
76    * @param titles <code>String</code> comma sep. list of titles, for all tabs
77    * @exception IndexOutOfBoundsException if index is out of range
78    * (index &lt; 0 || index &gt;= tab count)
79    */

80   public void setTitles( String JavaDoc titles ) {
81     StringTokenizer JavaDoc st = new StringTokenizer JavaDoc( titles, "," );
82     int n = st.countTokens();
83     for (int i = 0; i < n; i++) {
84       super.setTitleAt( i, st.nextToken().trim() );
85     }
86   }
87
88
89   /**
90    * Sets the keyboard mnemonic for accessing the specified tab.
91    * The mnemonic is the key which when combined with the look and feel's
92    * mouseless modifier (usually Alt) will activate the specified
93    * tab.
94    * <p>
95    * A mnemonic must correspond to a single key on the keyboard
96    * and should be specified using one of the <code>VK_XXX</code>
97    * keycodes defined in <code>java.awt.event.KeyEvent</code>.
98    * Mnemonics are case-insensitive, therefore a key event
99    * with the corresponding keycode would cause the button to be
100    * activated whether or not the Shift modifier was pressed.
101    * <p>
102    * This will update the displayed mnemonic property for the specified
103    * tab.
104    *
105    * @since 1.4
106    * @param mnemonics <code>String</code> comma sep. list of mnemonic, for all tabs
107    * @exception IndexOutOfBoundsException if index is out of range
108    * (index &lt; 0 || index &gt;= tab count)
109    * @see #getMnemonicAt(int)
110    * @see #setDisplayedMnemonicIndexAt(int,int)
111    */

112   public void setMnemonics( String JavaDoc mnemonics ) {
113     StringTokenizer JavaDoc st = new StringTokenizer JavaDoc( mnemonics, "," );
114     int n = st.countTokens();
115     for (int i = 0; i < n; i++) {
116       super.setMnemonicAt( i, Integer.parseInt( st.nextToken().trim() ) );
117     }
118   }
119
120
121   /**
122    * Provides a hint to the look and feel as to which character in the
123    * text should be decorated to represent the mnemonic. Not all look and
124    * feels may support this. A value of -1 indicates either there is
125    * no mnemonic for this tab, or you do not wish the mnemonic to be
126    * displayed for this tab.
127    * <p>
128    * The value of this is updated as the properties relating to the
129    * mnemonic change (such as the mnemonic itself, the text...).
130    * You should only ever have to call this if
131    * you do not wish the default character to be underlined. For example, if
132    * the text at tab index 3 was 'Apple Price', with a mnemonic of 'p',
133    * and you wanted the 'P'
134    * to be decorated, as 'Apple <u>P</u>rice', you would have to invoke
135    * <code>setDisplayedMnemonicIndex(3, 6)</code> after invoking
136    * <code>setMnemonicAt(3, KeyEvent.VK_P)</code>.
137    * <p>Note that it is the programmer's responsibility to ensure
138    * that each tab has a unique mnemonic or unpredictable results may
139    * occur.
140    *
141    * @since 1.4
142
143    * @param displaymnemonics <code>String</code> comma sep. list of index into the <code>String</code>
144    * to underline for all tabs
145    * @exception IndexOutOfBoundsException if <code>tabIndex</code> is
146    * out of range (<code>tabIndex < 0 || tabIndex >= tab
147    * count</code>)
148    * @exception IllegalArgumentException will be thrown if
149    * <code>mnemonicIndex</code> is &gt;= length of the tab
150    * title , or &lt; -1
151    * @see #setMnemonicAt(int,int)
152    * @see #getDisplayedMnemonicIndexAt(int)
153    */

154   public void setDisplayedMnemonics( String JavaDoc displaymnemonics ) {
155     StringTokenizer JavaDoc st = new StringTokenizer JavaDoc( displaymnemonics, "," );
156     int n = st.countTokens();
157     for (int i = 0; i < n; i++) {
158       super.setDisplayedMnemonicIndexAt( i, Integer.parseInt( st.nextToken().trim() ) );
159     }
160   }
161
162   /**
163    * Sets whether or not the tab at <code>index</code> is enabled.
164    * An internal exception is raised if there is no tab at that index.
165    *
166    * @param enabled <code>String</code> comma sep. list of booleans, if or not the tab should be enabled
167    * @exception IndexOutOfBoundsException if index is out of range
168    * (index &lt; 0 || index &gt;= tab count)
169    *
170    * @see #isEnabledAt
171    */

172   public void setEnabled( String JavaDoc enabled ) {
173     StringTokenizer JavaDoc st = new StringTokenizer JavaDoc( enabled, "," );
174     int n = st.countTokens();
175     for (int i = 0; i < n; i++) {
176       super.setEnabledAt( i, Boolean.valueOf( st.nextToken().trim() ).booleanValue() );
177     }
178   }
179
180
181   /**
182    * Sets the tooltip text at <code>index</code> to <code>toolTipText</code>
183    * which can be <code>null</code>.
184    * An internal exception is raised if there is no tab at that index.
185    *
186    * @param toolTipTexts <code>String</code> comma sep. list of tooltip texts to be displayed for all the tabs
187    * @exception IndexOutOfBoundsException if index is out of range
188    * (index &lt; 0 || index &gt;= tab count)
189    *
190    * @see #getToolTipTextAt
191    */

192   public void setToolTipTexts( String JavaDoc toolTipTexts ) {
193     StringTokenizer JavaDoc st = new StringTokenizer JavaDoc( toolTipTexts, "," );
194     int n = st.countTokens();
195     for (int i = 0; i < n; i++) {
196       super.setToolTipTextAt( i, st.nextToken().trim() );
197     }
198   }
199
200
201   /**
202    * Sets the icons for all tabs. Does not set disabled icon at <code>icon</code>
203    * To set disabled icon, use <code>setDisableIconAt()</code>.
204    * An internal exception is raised if there is no tab at that index.
205    *
206    * @param icons <code>String</code> comma sep. list of icons to be displayed in alls tabs
207    * @exception IndexOutOfBoundsException if index is out of range
208    * (index < 0 || index >= tab count)
209    *
210    * @see #setDisabledIconAt
211    * @see #getIconAt
212    */

213   public void setIcons( String JavaDoc icons ) {
214     StringTokenizer JavaDoc st = new StringTokenizer JavaDoc( icons, "," );
215     int n = st.countTokens();
216     for (int i = 0; i < n; i++) {
217       Attribute attr = new Attribute( "icon", st.nextToken() );
218       super.setIconAt( i, (ImageIcon) ImageIconConverter.conv( null, attr, null ) );
219     }
220   }
221
222
223   /**
224    * Sets the disabled icon at <code>index</code> to <code>icon</code>
225    * which can be <code>null</code>.
226    * An internal exception is raised if there is no tab at that index.
227    *
228    * @param icons <code>String</code> comma sep. list of icons to be displayed in alls tabs
229    * @exception IndexOutOfBoundsException if index is out of range
230    * (index &lt; 0 || index &gt;= tab count)
231    *
232    * @see #getDisabledIconAt
233    */

234   public void setDisabledIcons( String JavaDoc icons ) {
235     StringTokenizer JavaDoc st = new StringTokenizer JavaDoc( icons, "," );
236     int n = st.countTokens();
237     for (int i = 0; i < n; i++) {
238       Attribute attr = new Attribute( "icon", st.nextToken() );
239       super.setDisabledIconAt( i, (ImageIcon) ImageIconConverter.conv( null, attr, null ) );
240     }
241   }
242 }
243
244
Popular Tags