1   /*  TabBlinker.java
2    *
3    *  Copyright (c) 1998-2005, The University of Sheffield.
4    *
5    *  This file is part of GATE (see http://gate.ac.uk/), and is free
6    *  software, licenced under the GNU Library General Public License,
7    *  Version 2, June 1991 (in the distribution as file licence.html,
8    *  and also available at http://gate.ac.uk/gate/licence.html).
9    *
10   *  Valentin Tablan 30/03/2001
11   *
12   *  $Id: TabBlinker.java,v 1.6 2005/01/11 13:51:34 ian Exp $
13   *
14   */
15  package gate.gui;
16  
17  import java.awt.Color;
18  import java.awt.Component;
19  
20  import javax.swing.JTabbedPane;
21  import javax.swing.SwingUtilities;
22  
23  public class TabBlinker implements Runnable{
24      public TabBlinker(JTabbedPane pane, Component comp, Color blinkColor){
25        this.tPane = pane;
26        this.tab = tPane.indexOfComponent(comp);
27        this.blinkColor = blinkColor;
28        thread = new Thread(Thread.currentThread().getThreadGroup(),
29                            this,
30                            "TabBlinker1");
31        thread.setPriority(Thread.MIN_PRIORITY);
32      }// TabBlinker(JTabbedPane pane, Component comp, Color blinkColor)
33  
34      public void run(){
35        oldColor = tPane.getBackgroundAt(tab);
36        synchronized(this){
37          stopIt = false;
38        }
39        while(true){
40          synchronized(this){
41            if(tPane.getSelectedIndex() == tab) stopIt = true;
42            if(stopIt){
43              tPane.setBackgroundAt(tab, oldColor);
44              return;
45            }
46          }
47          SwingUtilities.invokeLater(new Runnable(){
48            public void run(){
49              if(tPane.getBackgroundAt(tab).equals(oldColor)){
50                tPane.setBackgroundAt(tab, blinkColor);
51              }else{
52                tPane.setBackgroundAt(tab, oldColor);
53              }
54            }// run()
55          });
56          try {
57            Thread.sleep(400);
58          } catch(InterruptedException ie){}
59        }// while
60      }//run()
61  
62      public void stopBlinking(int foo){
63        synchronized(this){
64          if(thread.isAlive()){
65            stopIt = true;
66          }
67        }
68      }// void stopBlinking()
69  
70      public void startBlinking(){
71        synchronized(this){
72          if(!thread.isAlive()){
73            thread = new Thread(Thread.currentThread().getThreadGroup(),
74                                this,
75                                "TabBlinker2");
76            thread.setPriority(Thread.MIN_PRIORITY);
77            thread.start();
78          }
79        }
80      }// void startBlinking()
81  
82      boolean stopIt;
83      JTabbedPane tPane;
84      int tab;
85      Color blinkColor;
86      Color oldColor;
87      Thread thread;
88    }//class TabBlinker implements Runnable