XJTabbedPane.java
01 /*  XJTabbedPane.java
02  *
03  *  Copyright (c) 1995-2010, The University of Sheffield. See the file
04  *  COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
05  *
06  *  This file is part of GATE (see http://gate.ac.uk/), and is free
07  *  software, licenced under the GNU Library General Public License,
08  *  Version 2, June 1991 (in the distribution as file licence.html,
09  *  and also available at http://gate.ac.uk/gate/licence.html).
10  *
11  *  Valentin Tablan 04/04/2001
12  *
13  *  $Id: XJTabbedPane.java 12006 2009-12-01 17:24:28Z thomas_heitz $
14  *
15  */
16 
17 package gate.swing;
18 
19 import java.awt.Point;
20 import java.awt.Component;
21 
22 import javax.swing.JTabbedPane;
23 import javax.swing.Icon;
24 
25 /**
26  * An extended version of {@link javax.swing.JTabbedPane}.
27  */
28 public class XJTabbedPane extends JTabbedPane {
29 
30   public XJTabbedPane(int tabPlacement){
31     super(tabPlacement);
32   }
33 
34   /**
35    * Gets the tab index for a given location
36    */
37   public int getIndexAt(Point p){
38     for(int i = 0; i < getTabCount(); i++){
39       if(getBoundsAt(i).contains(p)) return i;
40     }
41     return -1;
42   }// int getIndexAt(Point p)
43 
44   public void setTitleAt(int index, String title) {
45     if (title.length() 15) { // shorten the tab title with ellipsis
46       setToolTipText("<html>" + title + "<br>" + getToolTipText() "</html>");
47       title = title.substring(015"\u2026";
48       super.setTitleAt(index, title);
49     else {
50       super.setTitleAt(index, title);
51     }
52   }
53 
54   public void insertTab(String title, Icon icon, Component component, String tip, int index) {
55     if (title.length() 15) { // shorten the tab title with ellispsis
56       tip = "<html>" + title + "<br>" + tip + "</html>";
57       title = title.substring(015"\u2026";
58       super.insertTab(title, icon, component, tip, index);
59     else {
60       super.insertTab(title, icon, component, tip, index);
61     }
62   }
63 
64 }// class XJTabbedPane extends JTabbedPane