psmith      2003/12/19 16:22:07

  Modified:    src/java/org/apache/log4j/chainsaw LogUI.java LogPanel.java
                        ChainsawStatusBar.java
               src/java/org/apache/log4j/chainsaw/receivers
                        ReceiversPanel.java
  Log:
  Decoupled components from having to know about the Status bar,
  now uses the message center.
  
  LogUI now installs an appender to forward new messages onto the status bar.
  
  Revision  Changes    Path
  1.60      +46 -30    jakarta-log4j/src/java/org/apache/log4j/chainsaw/LogUI.java
  
  Index: LogUI.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/LogUI.java,v
  retrieving revision 1.59
  retrieving revision 1.60
  diff -u -r1.59 -r1.60
  --- LogUI.java        19 Dec 2003 10:15:59 -0000      1.59
  +++ LogUI.java        20 Dec 2003 00:22:06 -0000      1.60
  @@ -104,19 +104,21 @@
   import javax.swing.event.HyperlinkEvent;
   import javax.swing.event.HyperlinkListener;
   
  +import org.apache.log4j.AppenderSkeleton;
   import org.apache.log4j.Level;
   import org.apache.log4j.LogManager;
  +import org.apache.log4j.Logger;
   import org.apache.log4j.Priority;
   import org.apache.log4j.UtilLoggingLevel;
   import org.apache.log4j.chainsaw.help.HelpManager;
   import org.apache.log4j.chainsaw.help.Tutorial;
   import org.apache.log4j.chainsaw.icons.ChainsawIcons;
  +import org.apache.log4j.chainsaw.messages.MessageCenter;
   import org.apache.log4j.chainsaw.prefs.LoadSettingsEvent;
   import org.apache.log4j.chainsaw.prefs.SaveSettingsEvent;
   import org.apache.log4j.chainsaw.prefs.SettingsListener;
   import org.apache.log4j.chainsaw.prefs.SettingsManager;
   import org.apache.log4j.chainsaw.receivers.ReceiversPanel;
  -import org.apache.log4j.helpers.LogLog;
   import org.apache.log4j.helpers.OptionConverter;
   import org.apache.log4j.net.SocketNodeEventListener;
   import org.apache.log4j.plugins.Plugin;
  @@ -124,6 +126,8 @@
   import org.apache.log4j.plugins.PluginListener;
   import org.apache.log4j.plugins.PluginRegistry;
   import org.apache.log4j.plugins.Receiver;
  +import org.apache.log4j.spi.LoggingEvent;
  +
   
   /**
    * The main entry point for Chainsaw, this class represents the first frame
  @@ -144,11 +148,11 @@
    * of 500 is used.
    *
    * @author Scott Deboy <[EMAIL PROTECTED]>
  - * @author Paul Smith
  - *                <[EMAIL PROTECTED]>
  + * @author Paul Smith  <[EMAIL PROTECTED]>
    *
    */
   public class LogUI extends JFrame implements ChainsawViewer, SettingsListener {
  +  private static final Logger messageLogger = 
Logger.getLogger(MessageCenter.getInstance().getClass());
     private static final String CONFIG_FILE_TO_USE = "config.file";
     static final String USE_CYCLIC_BUFFER_PROP_NAME = "chainsaw.usecyclicbuffer";
     static final String CYCLIC_BUFFER_SIZE_PROP_NAME =
  @@ -456,6 +460,24 @@
       toolbar.setVisible(applicationPreferenceModel.isToolbar());
       
       setStatusBarVisible(applicationPreferenceModel.isStatusBar());
  +
  +    /**
  +     * We add a simple appender to the MessageCenter logger
  +     * so that each message is displayed in the Status bar
  +     */
  +    messageLogger.addAppender(new AppenderSkeleton(){
  +
  +      protected void append(LoggingEvent event) {
  +        getStatusBar().setMessage(event.getMessage().toString());
  +      }
  +
  +      public void close() {
  +        
  +      }
  +
  +      public boolean requiresLayout() {
  +        return false;
  +      }});
       
       final SocketNodeEventListener socketListener =
         new SocketNodeEventListener() {
  @@ -464,14 +486,14 @@
           }
   
           public void socketClosedEvent(Exception e) {
  -          statusBar.setMessage("Connection lost! :: " + e.getMessage());
  +          messageLogger.info("Connection lost! :: " + e.getMessage());
           }
         };
   
       PluginListener pluginListener =
         new PluginListener() {
           public void pluginStarted(PluginEvent e) {
  -          statusBar.setMessage(e.getPlugin().getName() + " started!");
  +          messageLogger.info(e.getPlugin().getName() + " started!");
   
             Method method = getAddListenerMethod(e.getPlugin());
   
  @@ -479,7 +501,7 @@
               try {
                 method.invoke(e.getPlugin(), new Object[] { socketListener });
               } catch (Exception ex) {
  -              LogLog.error("Failed to add a SocketNodeEventListener", ex);
  +              messageLogger.error("Failed to add a SocketNodeEventListener", ex);
               }
             }
           }
  @@ -511,11 +533,11 @@
               try {
                 method.invoke(e.getPlugin(), new Object[] { socketListener });
               } catch (Exception ex) {
  -              LogLog.error("Failed to remove SocketNodeEventListener", ex);
  +              messageLogger.error("Failed to remove SocketNodeEventListener", ex);
               }
             }
   
  -          statusBar.setMessage(e.getPlugin().getName() + " stopped!");
  +          messageLogger.info(e.getPlugin().getName() + " stopped!");
           }
         };
   
  @@ -538,13 +560,13 @@
                   url, null, LogManager.getLoggerRepository());
   
                 if (LogUI.this.getStatusBar() != null) {
  -                LogUI.this.getStatusBar().setMessage(
  +                messageLogger.info(
                     "Configured Log4j using remembered URL :: " + url);
                 }
   
                 LogUI.this.configURLToUse = url;
               } catch (Exception e) {
  -              LogLog.error("error occurred initializing log4j", e);
  +              messageLogger.error("error occurred initializing log4j", e);
               }
             }
           }
  @@ -829,7 +851,7 @@
         tutorialArea.setPage(getWelcomePanel().getTutorialURL());
         container.add(new JScrollPane(tutorialArea), BorderLayout.CENTER);
       } catch (Exception e) {
  -      LogLog.error("Error occurred loading the Tutorial", e);
  +      messageLogger.error("Error occurred loading the Tutorial", e);
       }
   
       tutorialFrame.setIconImage(new ImageIcon(ChainsawIcons.HELP).getImage());
  @@ -933,7 +955,7 @@
                 try {
                   tutorialArea.setPage(e.getURL());
                 } catch (IOException e1) {
  -                LogLog.error("Failed to change the URL for the Tutorial", e1);
  +                messageLogger.error("Failed to change the URL for the Tutorial", 
e1);
                 }
               }
             }
  @@ -1032,8 +1054,8 @@
                 PluginRegistry.startPlugin(simpleReceiver);
                 receiversPanel.updateReceiverTreeInDispatchThread();
               } catch (Exception e) {
  -              LogLog.error("Error creating Receiver", e);
  -              getStatusBar().setMessage(
  +              messageLogger.error("Error creating Receiver", e);
  +              MessageCenter.getInstance().getLogger().info(
                   "An error occurred creating your Receiver");
               }
             } else if (noReceiversWarningPanel.getModel().isLoadConfig()) {
  @@ -1041,7 +1063,7 @@
                 noReceiversWarningPanel.getModel().getConfigToLoad();
   
               if (url != null) {
  -              LogLog.debug("Initialiazing Log4j with " + url.toExternalForm());
  +              messageLogger.debug("Initialiazing Log4j with " + 
url.toExternalForm());
   
                 new Thread(
                   new Runnable() {
  @@ -1050,7 +1072,7 @@
                         OptionConverter.selectAndConfigure(
                           url, null, LogManager.getLoggerRepository());
                       } catch (Exception e) {
  -                      LogLog.error("Error initializing Log4j", e);
  +                      messageLogger.error("Error initializing Log4j", e);
                       }
   
                       LogManager.getLoggerRepository().getRootLogger()
  @@ -1093,12 +1115,7 @@
       return receiversPanel.isVisible();
     }
   
  -  /**
  -   * DOCUMENT ME!
  -   *
  -   * @return DOCUMENT ME!
  -   */
  -  public ChainsawStatusBar getStatusBar() {
  +  ChainsawStatusBar getStatusBar() {
       return statusBar;
     }
   
  @@ -1222,7 +1239,7 @@
      *
      */
     private void performShutdownAction() {
  -    LogLog.debug("Calling the shutdown Action. Goodbye!");
  +    messageLogger.debug("Calling the shutdown Action. Goodbye!");
   
       shutdownAction.actionPerformed(
         new ActionEvent(this, ActionEvent.ACTION_PERFORMED, "Shutting Down"));
  @@ -1249,7 +1266,7 @@
      * @param b
      */
     private void setStatusBarVisible(final boolean visible) {
  -    LogLog.debug("Setting StatusBar to " + visible);
  +    messageLogger.debug("Setting StatusBar to " + visible);
       SwingUtilities.invokeLater(
           new Runnable() {
             public void run() {
  @@ -1320,21 +1337,21 @@
       if (
         UIManager.getLookAndFeel().getClass().getName().equals(
             lookAndFeelClassName)) {
  -      LogLog.debug("No need to change L&F, already the same");
  +      messageLogger.debug("No need to change L&F, already the same");
   
         return;
       }
   
   
       if(lookAndFeelClassName == null || lookAndFeelClassName.trim().equals("")) {
  -      LogLog.info("Using System native L&F");
  +      messageLogger.info("Using System native L&F");
         lookAndFeelClassName = UIManager.getSystemLookAndFeelClassName();
       }
  -    LogLog.debug("Setting L&F -> " + lookAndFeelClassName);
  +    messageLogger.debug("Setting L&F -> " + lookAndFeelClassName);
       try {
         UIManager.setLookAndFeel(lookAndFeelClassName);
        } catch (Exception e) {
  -      LogLog.error("Failed to change L&F", e);
  +      messageLogger.error("Failed to change L&F", e);
       }
     }
   
  @@ -1620,8 +1637,7 @@
             });
   
           String msg = "added tab " + ident;
  -        LogLog.debug(msg);
  -        statusBar.setMessage(msg);
  +        messageLogger.debug(msg);
         }
       }
   
  
  
  
  1.43      +4 -3      jakarta-log4j/src/java/org/apache/log4j/chainsaw/LogPanel.java
  
  Index: LogPanel.java
  ===================================================================
  RCS file: /home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/LogPanel.java,v
  retrieving revision 1.42
  retrieving revision 1.43
  diff -u -r1.42 -r1.43
  --- LogPanel.java     18 Dec 2003 21:37:38 -0000      1.42
  +++ LogPanel.java     20 Dec 2003 00:22:06 -0000      1.43
  @@ -64,6 +64,7 @@
   import org.apache.log4j.chainsaw.layout.DefaultLayoutFactory;
   import org.apache.log4j.chainsaw.layout.EventDetailLayout;
   import org.apache.log4j.chainsaw.layout.LayoutEditorPane;
  +import org.apache.log4j.chainsaw.messages.MessageCenter;
   import org.apache.log4j.chainsaw.prefs.LoadSettingsEvent;
   import org.apache.log4j.chainsaw.prefs.Profileable;
   import org.apache.log4j.chainsaw.prefs.SaveSettingsEvent;
  @@ -380,11 +381,11 @@
               new PropertyChangeListener() {
                   public void propertyChange(PropertyChangeEvent arg0) {
                       if (tableModel.isCyclic()) {
  -                        statusBar.setMessage(
  +                        MessageCenter.getInstance().getLogger().warn(
                               "Changed to Cyclic Mode. Maximum # events kept: " +
                               tableModel.getMaxSize());
                       } else {
  -                        statusBar.setMessage(
  +                      MessageCenter.getInstance().getLogger().warn(
                               "Changed to Unlimited Mode. Warning, you may run out of 
memory.");
                       }
                   }
  @@ -1037,7 +1038,7 @@
                           }
   
                           if (msg != null) {
  -                            statusBar.setMessage(msg);
  +                          MessageCenter.getInstance().getLogger().info(msg);
                           }
                       }
                   }
  
  
  
  1.8       +26 -1     
jakarta-log4j/src/java/org/apache/log4j/chainsaw/ChainsawStatusBar.java
  
  Index: ChainsawStatusBar.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/ChainsawStatusBar.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ChainsawStatusBar.java    18 Dec 2003 21:33:30 -0000      1.7
  +++ ChainsawStatusBar.java    20 Dec 2003 00:22:07 -0000      1.8
  @@ -50,15 +50,21 @@
   package org.apache.log4j.chainsaw;
   
   import org.apache.log4j.chainsaw.icons.ChainsawIcons;
  +import org.apache.log4j.chainsaw.messages.MessageCenter;
   
   import java.awt.Dimension;
   import java.awt.FlowLayout;
   import java.awt.GridBagConstraints;
   import java.awt.GridBagLayout;
   import java.awt.Insets;
  +import java.awt.event.ActionEvent;
  +import java.awt.event.MouseAdapter;
  +import java.awt.event.MouseEvent;
   
   import java.text.NumberFormat;
   
  +import javax.swing.AbstractAction;
  +import javax.swing.Action;
   import javax.swing.BorderFactory;
   import javax.swing.Icon;
   import javax.swing.ImageIcon;
  @@ -104,9 +110,28 @@
       nf.setGroupingUsed(false);
   
       JPanel statusMsgPanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 2, 2));
  +    Action showMessageCenterAction = new AbstractAction("...") {
  +
  +      public void actionPerformed(ActionEvent e) {
  +        MessageCenter.getInstance().setVisible(true);
  +      }};
  +    showMessageCenterAction.putValue(Action.SHORT_DESCRIPTION, "Displays the 
Message Center");
  +    
  +    SmallButton showMessageCenter = new SmallButton(showMessageCenterAction);
  +    
  +    
   
       statusMsgPanel.add(statusMsg);
  +    statusMsgPanel.add(showMessageCenter);
       statusMsgPanel.setBorder(statusBarComponentBorder);
  +    
  +    statusMsgPanel.addMouseListener(new MouseAdapter() {
  +      public void mouseClicked(MouseEvent e) {
  +        if(e.getClickCount() >1) {
  +          
MessageCenter.getInstance().setVisible(!MessageCenter.getInstance().isVisible());
  +        }
  +      }
  +    });
   
       pausedLabel.setBorder(statusBarComponentBorder);
       pausedLabel.setMinimumSize(
  @@ -249,7 +274,7 @@
      */
     void remoteConnectionReceived(String source) {
       lastReceivedConnection = System.currentTimeMillis();
  -    setMessage("Connection received from " + source);
  +    MessageCenter.getInstance().getLogger().info("Connection received from " + 
source);
       connectionThread.interrupt();
   
       //    TODO and maybe play a sound?
  
  
  
  1.5       +3 -2      
jakarta-log4j/src/java/org/apache/log4j/chainsaw/receivers/ReceiversPanel.java
  
  Index: ReceiversPanel.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-log4j/src/java/org/apache/log4j/chainsaw/receivers/ReceiversPanel.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ReceiversPanel.java       19 Dec 2003 10:10:06 -0000      1.4
  +++ ReceiversPanel.java       20 Dec 2003 00:22:07 -0000      1.5
  @@ -120,6 +120,7 @@
   import org.apache.log4j.chainsaw.icons.ChainsawIcons;
   import org.apache.log4j.chainsaw.icons.LevelIconFactory;
   import org.apache.log4j.chainsaw.icons.LineIconFactory;
  +import org.apache.log4j.chainsaw.messages.MessageCenter;
   import org.apache.log4j.helpers.LogLog;
   import org.apache.log4j.net.SocketAppender;
   import org.apache.log4j.net.SocketHubAppender;
  @@ -351,7 +352,7 @@
                       }
   
                       updateReceiverTreeInDispatchThread();
  -                    logui.getStatusBar().setMessage(
  +                    MessageCenter.getInstance().getLogger().info(
                         "All Receivers have been (re)started");
                     }
                   }).start();
  @@ -1233,7 +1234,7 @@
           }
         } catch (Exception e) {
           LogLog.error("Error occurred creating the Receiver", e);
  -        logui.getStatusBar().setMessage(
  +        MessageCenter.getInstance().getLogger().error(
             "Error occurred creating the Receiver ::" + e.getMessage());
   
           return;
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to