1
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 }
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 } });
56 try {
57 Thread.sleep(400);
58 } catch(InterruptedException ie){}
59 } }
62 public void stopBlinking(int foo){
63 synchronized(this){
64 if(thread.isAlive()){
65 stopIt = true;
66 }
67 }
68 }
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 }
82 boolean stopIt;
83 JTabbedPane tPane;
84 int tab;
85 Color blinkColor;
86 Color oldColor;
87 Thread thread;
88 }