Source code: com/paradoxpoint/libitina/gui/JTabbedPaneHelper.java
1 /*
2 * Libitina - Funeral Monument Image Compositor
3 * Copyright (C) 2003,2004 Luke Imhoff
4 *
5 * Contact Info:
6 * luke@paradoxpoint.com
7 * Luke Imhoff
8 * 2514 Pied Piper Lane
9 * Wausau, WI 54403
10 *
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 *
25 * JTabbedPaneHelper.java
26 *
27 * Created on May 23, 2003, 2:36 PM
28 */
29
30 package com.paradoxpoint.libitina.gui;
31
32 /** Allows selection and index retrieve in <CODE>JTabbedPane</CODE>s based on tab
33 * title
34 * @author Luke Imhoff
35 */
36 public final class JTabbedPaneHelper {
37
38 /** Returns the index of the tab with the title in the given pane
39 * @param pane pane in which to search for tab title
40 * @param title title for which to search
41 * @param ignoreCase <CODE>true</CODE> if tab title search is case-insensitive, otherwise <CODE>false</CODE>
42 * @return index of tab with title
43 */
44 static public int getTitleIndex(javax.swing.JTabbedPane pane, java.lang.String title, boolean ignoreCase) {
45 int tabnum = pane.getTabCount();
46 for (int i = 0; i < tabnum; i++)
47 if (ignoreCase ? pane.getTitleAt(i).equalsIgnoreCase(title) : pane.getTitleAt(i).equals(title))
48 return i;
49 return -1;
50 }
51
52 /** Selects the tab with the given title in the pane
53 * @param pane pane in which to search for tab title
54 * @param title title for which to search
55 * @param ignoreCase <CODE>true</CODE> if tab title search is case-insensitive, otherwise <CODE>false</CODE>
56 */
57 static public void setSelectedTabTitle(javax.swing.JTabbedPane pane, java.lang.String title, boolean ignoreCase) {
58 int tabnum = pane.getTabCount();
59 for (int i = 0; i < tabnum; i++) {
60 if (ignoreCase ? pane.getTitleAt(i).equalsIgnoreCase(title) : pane.getTitleAt(i).equals(title)) {
61 pane.setSelectedIndex(i);
62 break;
63 }
64 }
65 }
66
67 }