logging-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sde...@apache.org
Subject svn commit: r1029225 - in /logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw: LogUI.java ReceiverConfigurationPanel.java helper/SwingHelper.java
Date Sat, 30 Oct 2010 23:54:16 GMT
Author: sdeboy
Date: Sat Oct 30 23:54:15 2010
New Revision: 1029225

URL: http://svn.apache.org/viewvc?rev=1029225&view=rev
Log:
Minor UI fixes
 - filedialog displayed on top of a jdialog has focus issues..now hiding the 'parent' dialog
while the file dialog is displayed from the receiver config screen
 - since MESSAGE is the default format, changed default pattern to LogFilePatternReceiver
pattern
 - fixed bug in filedialog usage

Modified:
    logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogUI.java
    logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ReceiverConfigurationPanel.java
    logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/helper/SwingHelper.java

Modified: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogUI.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogUI.java?rev=1029225&r1=1029224&r2=1029225&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogUI.java (original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/LogUI.java Sat Oct 30 23:54:15
2010
@@ -21,7 +21,6 @@ import java.awt.BorderLayout;
 import java.awt.Component;
 import java.awt.Container;
 import java.awt.Dimension;
-import java.awt.Event;
 import java.awt.EventQueue;
 import java.awt.Frame;
 import java.awt.Point;
@@ -1463,127 +1462,128 @@ public class LogUI extends JFrame implem
             new ActionListener() {
               public void actionPerformed(ActionEvent e) {
                 dialog.setVisible(false);
-              }
-            });
 
-          dialog.getContentPane().add(receiverConfigurationPanel);
+            applicationPreferenceModel.setShowNoReceiverWarning(!receiverConfigurationPanel.isDontWarnMeAgain());
+            //using this config next time - stop all plugins
+            if (receiverConfigurationPanel.isDontWarnMeAgain()) {
+                List plugins = pluginRegistry.getPlugins();
+                for (Iterator iter = plugins.iterator();iter.hasNext();) {
+                    Plugin plugin = (Plugin)iter.next();
+                    //don't stop ZeroConfPlugin if it is registered
+                    if (!plugin.getName().toLowerCase().contains("zeroconf")) {
+                      pluginRegistry.stopPlugin(plugin.getName());
+                    }
+                }
+            }
+            URL configURL = null;
 
-          dialog.pack();
+            if (receiverConfigurationPanel.getModel().isNetworkReceiverMode()) {
+              int port = receiverConfigurationPanel.getModel().getNetworkReceiverPort();
 
-          Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
-          dialog.setLocation(
-            (screenSize.width / 2) - (dialog.getWidth() / 2),
-            (screenSize.height / 2) - (dialog.getHeight() / 2));
-
-          dialog.setVisible(true);
-          applicationPreferenceModel.setShowNoReceiverWarning(!receiverConfigurationPanel.isDontWarnMeAgain());
-          //using this config next time - stop all plugins
-          if (receiverConfigurationPanel.isDontWarnMeAgain()) {
-              List plugins = pluginRegistry.getPlugins();
-              for (Iterator iter = plugins.iterator();iter.hasNext();) {
-                  Plugin plugin = (Plugin)iter.next();
-                  //don't stop ZeroConfPlugin if it is registered
-                  if (!plugin.getName().toLowerCase().contains("zeroconf")) {
-                    pluginRegistry.stopPlugin(plugin.getName());
-                  }
+              try {
+                Class receiverClass = receiverConfigurationPanel.getModel().getNetworkReceiverClass();
+                Receiver networkReceiver = (Receiver) receiverClass.newInstance();
+                networkReceiver.setName(receiverClass.getSimpleName() + "-" + port);
+
+                Method portMethod =
+                  networkReceiver.getClass().getMethod(
+                    "setPort", new Class[] { int.class });
+                portMethod.invoke(
+                  networkReceiver, new Object[] { new Integer(port) });
+
+                networkReceiver.setThreshold(Level.TRACE);
+
+                pluginRegistry.addPlugin(networkReceiver);
+                networkReceiver.activateOptions();
+                receiversPanel.updateReceiverTreeInDispatchThread();
+                //setting config URL here ensures we have the receiver panel auto-saved config
loaded
+                if (receiverConfigurationPanel.isDontWarnMeAgain()) {
+                    configURL = receiverConfigurationPanel.getModel().getSavedConfigToLoad();
+                }
+              } catch (Exception e3) {
+                MessageCenter.getInstance().getLogger().error(
+                  "Error creating Receiver", e3);
+                MessageCenter.getInstance().getLogger().info(
+                  "An error occurred creating your Receiver");
               }
-          }
-          URL configURL = null;
-
-          if (receiverConfigurationPanel.getModel().isNetworkReceiverMode()) {
-            int port = receiverConfigurationPanel.getModel().getNetworkReceiverPort();
-
-            try {
-              Class receiverClass = receiverConfigurationPanel.getModel().getNetworkReceiverClass();
-              Receiver networkReceiver = (Receiver) receiverClass.newInstance();
-              networkReceiver.setName(receiverClass.getSimpleName() + "-" + port);
-
-              Method portMethod =
-                networkReceiver.getClass().getMethod(
-                  "setPort", new Class[] { int.class });
-              portMethod.invoke(
-                networkReceiver, new Object[] { new Integer(port) });
-
-              networkReceiver.setThreshold(Level.TRACE);
-
-              pluginRegistry.addPlugin(networkReceiver);
-              networkReceiver.activateOptions();
-              receiversPanel.updateReceiverTreeInDispatchThread();
-              //setting config URL here ensures we have the receiver panel auto-saved config
loaded
-              if (receiverConfigurationPanel.isDontWarnMeAgain()) {
+            } else if (receiverConfigurationPanel.getModel().isLoadConfig() ||
+                    receiverConfigurationPanel.getModel().isLoadSavedConfigs()) {
+              if (receiverConfigurationPanel.getModel().isLoadSavedConfigs()) {
                   configURL = receiverConfigurationPanel.getModel().getSavedConfigToLoad();
+              } else {
+                  configURL = receiverConfigurationPanel.getModel().getConfigToLoad();
+              }
+            } else if (receiverConfigurationPanel.getModel().isLogFileReceiverConfig()) {
+              try {
+                  URL fileURL = receiverConfigurationPanel.getModel().getLogFileURL();
+                  if (fileURL != null) {
+                      VFSLogFilePatternReceiver fileReceiver = new VFSLogFilePatternReceiver();
+                      fileReceiver.setName(fileURL.getFile());
+                      fileReceiver.setAutoReconnect(true);
+                      fileReceiver.setContainer(LogUI.this);
+                      fileReceiver.setAppendNonMatches(true);
+                      fileReceiver.setFileURL(fileURL.toURI().toString());
+                      fileReceiver.setTailing(true);
+                      if (receiverConfigurationPanel.getModel().isPatternLayoutLogFormat())
{
+                          fileReceiver.setLogFormat(LogFilePatternLayoutBuilder.getLogFormatFromPatternLayout(receiverConfigurationPanel.getModel().getLogFormat()));
+                      } else {
+                          fileReceiver.setLogFormat(receiverConfigurationPanel.getModel().getLogFormat());
+                      }
+                      fileReceiver.setTimestampFormat(receiverConfigurationPanel.getModel().getLogFormatTimestampFormat());
+                      fileReceiver.setThreshold(Level.TRACE);
+
+                      pluginRegistry.addPlugin(fileReceiver);
+                      fileReceiver.activateOptions();
+                      receiversPanel.updateReceiverTreeInDispatchThread();
+                      if (receiverConfigurationPanel.isDontWarnMeAgain()) {
+                          configURL = receiverConfigurationPanel.getModel().getSavedConfigToLoad();
+                      }
+                  }
+              } catch (Exception e2) {
+                  MessageCenter.getInstance().getLogger().error(
+                    "Error creating Receiver", e2);
+                  MessageCenter.getInstance().getLogger().info(
+                    "An error occurred creating your Receiver");
               }
-            } catch (Exception e) {
-              MessageCenter.getInstance().getLogger().error(
-                "Error creating Receiver", e);
-              MessageCenter.getInstance().getLogger().info(
-                "An error occurred creating your Receiver");
-            }
-          } else if (receiverConfigurationPanel.getModel().isLoadConfig() ||
-                  receiverConfigurationPanel.getModel().isLoadSavedConfigs()) {
-            if (receiverConfigurationPanel.getModel().isLoadSavedConfigs()) {
-                configURL = receiverConfigurationPanel.getModel().getSavedConfigToLoad();
-            } else {
-                configURL = receiverConfigurationPanel.getModel().getConfigToLoad();
             }
-          } else if (receiverConfigurationPanel.getModel().isLogFileReceiverConfig()) {
-            try {
-                URL fileURL = receiverConfigurationPanel.getModel().getLogFileURL();
-                if (fileURL != null) {
-                    VFSLogFilePatternReceiver fileReceiver = new VFSLogFilePatternReceiver();
-                    fileReceiver.setName(fileURL.getFile());
-                    fileReceiver.setAutoReconnect(true);
-                    fileReceiver.setContainer(LogUI.this);
-                    fileReceiver.setAppendNonMatches(true);
-                    fileReceiver.setFileURL(fileURL.toURI().toString());
-                    fileReceiver.setTailing(true);
-                    if (receiverConfigurationPanel.getModel().isPatternLayoutLogFormat())
{
-                        fileReceiver.setLogFormat(LogFilePatternLayoutBuilder.getLogFormatFromPatternLayout(receiverConfigurationPanel.getModel().getLogFormat()));
-                    } else {
-                        fileReceiver.setLogFormat(receiverConfigurationPanel.getModel().getLogFormat());
-                    }
-                    fileReceiver.setTimestampFormat(receiverConfigurationPanel.getModel().getLogFormatTimestampFormat());
-                    fileReceiver.setThreshold(Level.TRACE);
+              if (configURL != null) {
+                MessageCenter.getInstance().getLogger().debug(
+                  "Initialiazing Log4j with " + configURL.toExternalForm());
+                final URL finalURL = configURL;
+                new Thread(
+                  new Runnable() {
+                    public void run() {
+                      if (receiverConfigurationPanel.isDontWarnMeAgain()) {
+                          applicationPreferenceModel.setConfigurationURL(finalURL.toExternalForm());
+                      } else {
+                          try {
+                              if (new File(finalURL.toURI()).exists()) {
+                                  loadConfigurationUsingPluginClassLoader(finalURL);
+                              }
+                          }
+                          catch (URISyntaxException e) {
+                              //ignore
+                          }
+                      }
 
-                    pluginRegistry.addPlugin(fileReceiver);
-                    fileReceiver.activateOptions();
-                    receiversPanel.updateReceiverTreeInDispatchThread();
-                    if (receiverConfigurationPanel.isDontWarnMeAgain()) {
-                        configURL = receiverConfigurationPanel.getModel().getSavedConfigToLoad();
+                      receiversPanel.updateReceiverTreeInDispatchThread();
                     }
-                }
-            } catch (Exception e) {
-                MessageCenter.getInstance().getLogger().error(
-                  "Error creating Receiver", e);
-                MessageCenter.getInstance().getLogger().info(
-                  "An error occurred creating your Receiver");
-            }
+                  }).start();
+              }
           }
-            if (configURL != null) {
-              MessageCenter.getInstance().getLogger().debug(
-                "Initialiazing Log4j with " + configURL.toExternalForm());
-              final URL finalURL = configURL;
-              new Thread(
-                new Runnable() {
-                  public void run() {
-                    if (receiverConfigurationPanel.isDontWarnMeAgain()) {
-                        applicationPreferenceModel.setConfigurationURL(finalURL.toExternalForm());
-                    } else {
-                        try {
-                            if (new File(finalURL.toURI()).exists()) {
-                                loadConfigurationUsingPluginClassLoader(finalURL);
-                            }
-                        }
-                        catch (URISyntaxException e) {
-                            //ignore
-                        }
-                    }
+        });
 
-                    receiversPanel.updateReceiverTreeInDispatchThread();
-                  }
-                }).start();
-            }
+          receiverConfigurationPanel.setDialog(dialog);
+          dialog.getContentPane().add(receiverConfigurationPanel);
+
+          dialog.pack();
 
+          Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
+          dialog.setLocation(
+            (screenSize.width / 2) - (dialog.getWidth() / 2),
+            (screenSize.height / 2) - (dialog.getHeight() / 2));
+
+          dialog.setVisible(true);
         }
       });
   }

Modified: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ReceiverConfigurationPanel.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ReceiverConfigurationPanel.java?rev=1029225&r1=1029224&r2=1029225&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ReceiverConfigurationPanel.java
(original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ReceiverConfigurationPanel.java
Sat Oct 30 23:54:15 2010
@@ -18,7 +18,9 @@ package org.apache.log4j.chainsaw;
 
 import java.awt.BorderLayout;
 import java.awt.Component;
+import java.awt.Container;
 import java.awt.Dimension;
+import java.awt.EventQueue;
 import java.awt.GridBagConstraints;
 import java.awt.GridBagLayout;
 import java.awt.Insets;
@@ -111,8 +113,10 @@ class ReceiverConfigurationPanel extends
 
     //set by LogUI to handle hiding of the dialog
     private ActionListener completionActionListener;
+    //used as frame for file open dialogs
+    private Container dialog;
 
-    ReceiverConfigurationPanel() {
+  ReceiverConfigurationPanel() {
         setBorder(BorderFactory.createEmptyBorder(5, 15, 5, 15));
         setLayout(new GridBagLayout());
 
@@ -363,8 +367,8 @@ class ReceiverConfigurationPanel extends
         panel.add(new JLabel(" Log file format type "), c);
 
         DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel();
-        comboBoxModel.addElement("PatternLayout format");
         comboBoxModel.addElement("LogFilePatternReceiver LogFormat");
+        comboBoxModel.addElement("PatternLayout format");
 
         logFileFormatTypeComboBox = new JComboBox(comboBoxModel);
         logFileFormatTypeComboBox.setOpaque(false);
@@ -553,15 +557,25 @@ class ReceiverConfigurationPanel extends
      * or null if they cancelled.
      */
     private URL browseConfig() throws MalformedURLException {
-        File selectedFile = SwingHelper.promptForFile(this, null, "Choose a Chainsaw configuration
file");
+        //hiding and showing the dialog to avoid focus issues with 2 dialogs
+        dialog.setVisible(false);
+        File selectedFile = SwingHelper.promptForFile(dialog, null, "Choose a Chainsaw configuration
file");
+        URL result = null;
         if (selectedFile == null) {
-            return null;
+            result = null;
         }
-
-        if (!selectedFile.exists() || !selectedFile.canRead()) {
-            return null;
+        if (selectedFile != null && (!selectedFile.exists() || !selectedFile.canRead()))
{
+            result = null;
+        }
+        if (selectedFile != null) {
+          result = selectedFile.toURI().toURL();
         }
-        return selectedFile.toURI().toURL();
+        EventQueue.invokeLater(new Runnable() {
+          public void run() {
+            dialog.setVisible(true);
+          }
+        });
+        return result;
     }
 
     /**
@@ -569,17 +583,25 @@ class ReceiverConfigurationPanel extends
      * or null if they cancelled.
      */
     private URL browseLogFile() throws MalformedURLException {
-
-        File selectedFile = SwingHelper.promptForFile(this, null, "Select a log file");
+        //hiding and showing the dialog to avoid focus issues with 2 dialogs
+        dialog.setVisible(false);
+        File selectedFile = SwingHelper.promptForFile(dialog, null, "Select a log file");
+        URL result = null;
         if (selectedFile == null) {
-            return null;
+            result = null;
         }
-
-        if (!selectedFile.exists() || !selectedFile.canRead()) {
-            return null;
+        if (selectedFile != null && (!selectedFile.exists() || !selectedFile.canRead()))
{
+            result = null;
         }
-
-        return selectedFile.toURI().toURL();
+        if (selectedFile != null) {
+          result = selectedFile.toURI().toURL();
+        }
+        EventQueue.invokeLater(new Runnable() {
+          public void run() {
+            dialog.setVisible(true);
+          }
+        });
+        return result;
     }
 
     public static void main(String[] args) {
@@ -599,7 +621,11 @@ class ReceiverConfigurationPanel extends
         return dontwarnIfNoReceiver.isSelected();
     }
 
-    /**
+  public void setDialog(Container dialog) {
+    this.dialog = dialog;
+  }
+
+  /**
      * This class represents the model of the chosen options the user
      * has configured.
      *

Modified: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/helper/SwingHelper.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/helper/SwingHelper.java?rev=1029225&r1=1029224&r2=1029225&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/helper/SwingHelper.java
(original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/helper/SwingHelper.java
Sat Oct 30 23:54:15 2010
@@ -20,10 +20,10 @@ package org.apache.log4j.chainsaw.helper
 import java.awt.Component;
 import java.awt.Container;
 import java.awt.Dimension;
+import java.awt.EventQueue;
 import java.awt.FileDialog;
 import java.awt.Frame;
 import java.awt.Toolkit;
-import java.awt.EventQueue;
 import java.awt.event.ActionEvent;
 import java.awt.event.KeyEvent;
 import java.io.File;
@@ -38,6 +38,7 @@ import javax.swing.JComponent;
 import javax.swing.JDialog;
 import javax.swing.JFileChooser;
 import javax.swing.KeyStroke;
+import javax.swing.SwingUtilities;
 
 /**
  * A collection of standard utility methods for use within Swing.
@@ -109,7 +110,14 @@ public final class SwingHelper {
   public static File promptForFile(Container parent, String defaultPath, String title) {
         if (SwingHelper.isMacOSX()) {
             //use filedialog on mac
-            FileDialog fileDialog = new FileDialog((Frame)null, title);
+            Component root = SwingUtilities.getRoot(parent);
+            Frame frame = null;
+            if (root instanceof Frame) {
+              frame = (Frame) root;
+            }
+
+            FileDialog fileDialog = new FileDialog(frame, title);
+            fileDialog.setModal(true);
             if (defaultPath != null) {
               fileDialog.setDirectory(defaultPath);
             }
@@ -118,7 +126,11 @@ public final class SwingHelper {
             if (fileString == null) {
               return null;
             }
+          if (fileDialog.getDirectory() != null) {
+            return new File(fileDialog.getDirectory(), fileString);
+          } else {
             return new File(fileString);
+          }
           } else {
 
                 JFileChooser chooser;



Mime
View raw message