logging-log4j-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From psm...@apache.org
Subject cvs commit: jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw ChainsawStatusBar.java
Date Tue, 20 May 2003 07:18:03 GMT
psmith      2003/05/20 00:18:03

  Modified:    src/java/org/apache/log4j/chainsaw ChainsawStatusBar.java
  Log:
  added a little "Receiving..." label in the status bar, which appears
  when a new event in any tab is received, and disappears after 5 seconds
  if no more events are received.  The text will eventually be replaced
  with a nice little Radio tower animated icon, as soon as I can con
  someone with design skills to make it.
  
  Revision  Changes    Path
  1.3       +58 -4     jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/ChainsawStatusBar.java
  
  Index: ChainsawStatusBar.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j-sandbox/src/java/org/apache/log4j/chainsaw/ChainsawStatusBar.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- ChainsawStatusBar.java	20 May 2003 06:42:29 -0000	1.2
  +++ ChainsawStatusBar.java	20 May 2003 07:18:03 -0000	1.3
  @@ -60,7 +60,6 @@
   import javax.swing.JPanel;
   import javax.swing.SwingUtilities;
   import javax.swing.border.Border;
  -import javax.swing.border.SoftBevelBorder;
   
   
   /**
  @@ -70,10 +69,14 @@
    *
    */
   class ChainsawStatusBar extends JPanel {
  +  private static final int DELAY_PERIOD = 5000;
     private final String DEFAULT_MSG = "Welcome to Chainsaw v2!";
     private final JLabel statusMsg = new JLabel(DEFAULT_MSG);
     private final JLabel pausedLabel = new JLabel("", JLabel.CENTER);
     private final JLabel lineSelectionLabel = new JLabel("", JLabel.CENTER);
  +  private final JLabel receivedEventLabel = new JLabel("", JLabel.CENTER);
  +  private volatile long lastReceivedEvent = System.currentTimeMillis();
  +  private final Thread receiveThread;
   
     //  private final Border statusBarComponentBorder =
     //    BorderFactory.createEmptyBorder();
  @@ -94,11 +97,20 @@
       pausedLabel.setPreferredSize(
         new Dimension(
           pausedLabel.getFontMetrics(pausedLabel.getFont()).stringWidth(
  -          "Paused"), (int) pausedLabel.getPreferredSize().getHeight()));
  +          "Paused") + 10, (int) pausedLabel.getPreferredSize().getHeight()));
   
       pausedLabel.setToolTipText(
         "Shows whether the current Log panel is paused or not");
   
  +    receivedEventLabel.setBorder(statusBarComponentBorder);
  +    receivedEventLabel.setToolTipText(
  +      "Indicates whether Chainsaw is receiving events");
  +    receivedEventLabel.setPreferredSize(
  +      new Dimension(
  +        pausedLabel.getFontMetrics(receivedEventLabel.getFont()).stringWidth(
  +          "Receiving...") + 10,
  +        (int) receivedEventLabel.getPreferredSize().getHeight()));
  +
       lineSelectionLabel.setBorder(statusBarComponentBorder);
       lineSelectionLabel.setPreferredSize(
         new Dimension(
  @@ -127,13 +139,48 @@
       c.weightx = 0.0;
       c.weighty = 0.0;
       c.gridx = 1;
  -    add(lineSelectionLabel, c);
  +    add(receivedEventLabel, c);
   
       c.weightx = 0.0;
       c.weighty = 0.0;
       c.gridx = 2;
  +    add(lineSelectionLabel, c);
  +
  +    c.weightx = 0.0;
  +    c.weighty = 0.0;
  +    c.gridx = 3;
   
       add(pausedLabel, c);
  +
  +    receiveThread =
  +      new Thread(
  +        new Runnable() {
  +          public void run() {
  +            while (true) {
  +              try {
  +                Thread.sleep(DELAY_PERIOD);
  +              } catch (InterruptedException e) {
  +              }
  +
  +              String msg = "";
  +
  +              if ((System.currentTimeMillis() - lastReceivedEvent) < DELAY_PERIOD) {
  +                msg = "Receiving...";
  +              } else {
  +                msg = "";
  +              }
  +
  +              final String finalMsg = msg;
  +              SwingUtilities.invokeLater(
  +                new Runnable() {
  +                  public void run() {
  +                    receivedEventLabel.setText(finalMsg);
  +                  }
  +                });
  +            }
  +          }
  +        });
  +    receiveThread.start();
     }
   
     /**
  @@ -145,7 +192,8 @@
      *
      */
     void receivedEvent() {
  -    //		TODO implement this method	
  +    lastReceivedEvent = System.currentTimeMillis();
  +    receiveThread.interrupt();
     }
   
     /**
  @@ -193,6 +241,12 @@
     void clear() {
       setMessage(DEFAULT_MSG);
       setNothingSelected();
  +    SwingUtilities.invokeLater(
  +      new Runnable() {
  +        public void run() {
  +          receivedEventLabel.setText("");
  +        }
  +      });
     }
   
     void setMessage(final String msg) {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: log4j-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: log4j-dev-help@jakarta.apache.org


Mime
View raw message