|
TabHighlighter |
|
1 /* 2 * Copyright (c) 1998-2001, The University of Sheffield. 3 * 4 * This file is part of GATE (see http://gate.ac.uk/), and is free 5 * software, licenced under the GNU Library General Public License, 6 * Version 2, June 1991 (in the distribution as file licence.html, 7 * and also available at http://gate.ac.uk/gate/licence.html). 8 * 9 * Valentin Tablan 07/11/2001 10 * 11 * $Id: TabHighlighter.java,v 1.5 2001/11/12 16:08:02 valyt Exp $ 12 */ 13 package gate.gui; 14 15 16 import javax.swing.*; 17 import java.awt.Color; 18 import java.awt.Component; 19 import java.awt.event.*; 20 import javax.swing.event.*; 21 22 /** 23 * Highligts a tab in a JTabbedPane. Removes the highlight automatically when 24 * the highlighted tab is selected. 25 */ 26 public class TabHighlighter { 27 public TabHighlighter(JTabbedPane pane, Component comp, 28 Color highlightColour){ 29 this.tPane = pane; 30 this.tab = tPane.indexOfComponent(comp); 31 this.highlightColour = highlightColour; 32 tPane.getModel().addChangeListener(new ChangeListener() { 33 public void stateChanged(ChangeEvent e) { 34 if(tPane.getSelectedIndex() == tab) removeHighlight(); 35 } 36 }); 37 38 tPane.addMouseListener(new MouseAdapter() { 39 public void mouseClicked(MouseEvent e) { 40 if(tPane.getSelectedIndex() == tab) removeHighlight(); 41 } 42 }); 43 44 }// TabBlinker(JTabbedPane pane, Component comp, Color blinkColor) 45 46 /** 47 * Highlights the tab unless is selected 48 */ 49 public void highlight(){ 50 if(tPane.getSelectedIndex() != tab){ 51 if(tPane.getBackgroundAt(tab).equals(highlightColour)) return; 52 53 oldColour = tPane.getBackgroundAt(tab); 54 tPane.setBackgroundAt(tab, highlightColour); 55 } 56 }//public void highlight() 57 58 59 /** 60 * Restores the tab to the normal colour 61 */ 62 public void removeHighlight(){ 63 tPane.setBackgroundAt(tab, oldColour); 64 }// public void removeHighlight() 65 66 JTabbedPane tPane; 67 int tab; 68 Color highlightColour; 69 Color oldColour; 70 }
|
TabHighlighter |
|