| TabBlinker |

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

| TabBlinker |