TabBlinker.java
01 /*  TabBlinker.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 30/03/2001
12  *
13  *  $Id: TabBlinker.java 12006 2009-12-01 17:24:28Z thomas_heitz $
14  *
15  */
16 package gate.gui;
17 
18 import java.awt.Color;
19 import java.awt.Component;
20 
21 import javax.swing.JTabbedPane;
22 import javax.swing.SwingUtilities;
23 
24 public class TabBlinker implements Runnable{
25     public TabBlinker(JTabbedPane pane, Component comp, Color blinkColor){
26       this.tPane = pane;
27       this.tab = tPane.indexOfComponent(comp);
28       this.blinkColor = blinkColor;
29       thread = new Thread(Thread.currentThread().getThreadGroup(),
30                           this,
31                           "TabBlinker1");
32       thread.setPriority(Thread.MIN_PRIORITY);
33     }// TabBlinker(JTabbedPane pane, Component comp, Color blinkColor)
34 
35     public void run(){
36       oldColor = tPane.getBackgroundAt(tab);
37       synchronized(this){
38         stopIt = false;
39       }
40       while(true){
41         synchronized(this){
42           if(tPane.getSelectedIndex() == tabstopIt = true;
43           if(stopIt){
44             tPane.setBackgroundAt(tab, oldColor);
45             return;
46           }
47         }
48         SwingUtilities.invokeLater(new Runnable(){
49           public void run(){
50             if(tPane.getBackgroundAt(tab).equals(oldColor)){
51               tPane.setBackgroundAt(tab, blinkColor);
52             }else{
53               tPane.setBackgroundAt(tab, oldColor);
54             }
55           }// run()
56         });
57         try {
58           Thread.sleep(400);
59         catch(InterruptedException ie){}
60       }// while
61     }//run()
62 
63     public void stopBlinking(int foo){
64       synchronized(this){
65         if(thread.isAlive()){
66           stopIt = true;
67         }
68       }
69     }// void stopBlinking()
70 
71     public void startBlinking(){
72       synchronized(this){
73         if(!thread.isAlive()){
74           thread = new Thread(Thread.currentThread().getThreadGroup(),
75                               this,
76                               "TabBlinker2");
77           thread.setPriority(Thread.MIN_PRIORITY);
78           thread.start();
79         }
80       }
81     }// void startBlinking()
82 
83     boolean stopIt;
84     JTabbedPane tPane;
85     int tab;
86     Color blinkColor;
87     Color oldColor;
88     Thread thread;
89   }//class TabBlinker implements Runnable