logging-general mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sde...@apache.org
Subject svn commit: r1029159 - in /logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw: AbstractPreferencePanel.java ApplicationPreferenceModelPanel.java FileLoadAction.java ReceiverConfigurationPanel.java helper/SwingHelper.java
Date Sat, 30 Oct 2010 18:58:21 GMT
Author: sdeboy
Date: Sat Oct 30 18:58:21 2010
New Revision: 1029159

URL: http://svn.apache.org/viewvc?rev=1029159&view=rev
Log:
Slight improvements to UI fidelity (on Mac)
 - ok/cancel button order is cancel/ok on Mac, ok/cancel everywhere else
 - use 'FileDialog' instead of JFileChooser on Mac since it looks more like a native Mac file-open
dialog

Modified:
    logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/AbstractPreferencePanel.java
    logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ApplicationPreferenceModelPanel.java
    logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/FileLoadAction.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/AbstractPreferencePanel.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/AbstractPreferencePanel.java?rev=1029159&r1=1029158&r2=1029159&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/AbstractPreferencePanel.java
(original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/AbstractPreferencePanel.java
Sat Oct 30 18:58:21 2010
@@ -23,6 +23,7 @@ import java.awt.Component;
 import java.awt.Dimension;
 import java.awt.event.ActionListener;
 import java.util.Enumeration;
+import java.util.List;
 
 import javax.swing.BorderFactory;
 import javax.swing.Box;
@@ -42,6 +43,7 @@ import javax.swing.tree.TreeModel;
 import javax.swing.tree.TreePath;
 import javax.swing.tree.TreeSelectionModel;
 
+import org.apache.log4j.chainsaw.helper.SwingHelper;
 import org.apache.log4j.chainsaw.icons.ChainsawIcons;
 /**
  * Some basic plumbing for Preference related dialogs.
@@ -106,14 +108,12 @@ public abstract class AbstractPreference
   
     add(mainPanel, BorderLayout.CENTER);
   
-  
-
-  
     Box buttonBox = Box.createHorizontalBox();
+    List buttons = SwingHelper.orderOKCancelButtons(okButton, cancelButton);
     buttonBox.add(Box.createHorizontalGlue());
-    buttonBox.add(okButton);
+    buttonBox.add((JButton)buttons.get(0));
     buttonBox.add(Box.createHorizontalStrut(10));
-    buttonBox.add(cancelButton);
+    buttonBox.add((JButton)buttons.get(1));
   
     add(buttonBox, BorderLayout.SOUTH);
   

Modified: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ApplicationPreferenceModelPanel.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ApplicationPreferenceModelPanel.java?rev=1029159&r1=1029158&r2=1029159&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ApplicationPreferenceModelPanel.java
(original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/ApplicationPreferenceModelPanel.java
Sat Oct 30 18:58:21 2010
@@ -40,7 +40,6 @@ import javax.swing.JButton;
 import javax.swing.JCheckBox;
 import javax.swing.JComboBox;
 import javax.swing.JComponent;
-import javax.swing.JFileChooser;
 import javax.swing.JFrame;
 import javax.swing.JLabel;
 import javax.swing.JOptionPane;
@@ -58,6 +57,7 @@ import javax.swing.tree.TreeModel;
 
 import org.apache.log4j.LogManager;
 import org.apache.log4j.Logger;
+import org.apache.log4j.chainsaw.helper.SwingHelper;
 import org.apache.log4j.chainsaw.osx.OSXIntegration;
 
 
@@ -509,7 +509,7 @@ public static void main(String[] args) {
 
       p6.add(configURLPanel);
 
-      JButton browseButton = new JButton(" Browse ");
+      JButton browseButton = new JButton(" Open File... ");
       browseButton.addActionListener(new ActionListener()
       {
           public void actionPerformed(ActionEvent e)
@@ -552,7 +552,7 @@ public static void main(String[] args) {
                   File currentConfigurationPath = new File(selectedItem.toString()).getParentFile();
                   if (currentConfigurationPath != null) {
                       defaultPath = currentConfigurationPath.getPath();
-                      //JFileChooser constructor will not navigate to this location unless
we remove the prefixing protocol and slash
+                      //FileDialog will not navigate to this location unless we remove the
prefixing protocol and slash
                       //at least on winxp
                       if (defaultPath.toLowerCase().startsWith("file:\\")) {
                           defaultPath = defaultPath.substring("file:\\".length());
@@ -560,14 +560,11 @@ public static void main(String[] args) {
                   }
               }
           }
-
-          JFileChooser chooser = new JFileChooser(defaultPath);
-          int result = chooser.showOpenDialog(ApplicationPreferenceModelPanel.this);
-          if (JFileChooser.APPROVE_OPTION == result) {
-              File f = chooser.getSelectedFile();
+      File selectedFile = SwingHelper.promptForFile(this, defaultPath, "Select a Chainsaw
configuration file");
+      if (selectedFile != null) {
               try
               {
-                  String newConfigurationFile = f.toURI().toURL().toExternalForm();
+                  String newConfigurationFile = selectedFile.toURI().toURL().toExternalForm();
                   if (!committedPreferenceModel.getConfigurationURLs().contains(newConfigurationFile))
{
                     configurationURL.addItem(newConfigurationFile);
                   }
@@ -575,7 +572,7 @@ public static void main(String[] args) {
               }
               catch (MalformedURLException e1)
               {
-                  e1.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
+                  e1.printStackTrace();
               }
           }
       }

Modified: logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/FileLoadAction.java
URL: http://svn.apache.org/viewvc/logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/FileLoadAction.java?rev=1029159&r1=1029158&r2=1029159&view=diff
==============================================================================
--- logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/FileLoadAction.java (original)
+++ logging/chainsaw/trunk/src/main/java/org/apache/log4j/chainsaw/FileLoadAction.java Sat
Oct 30 18:58:21 2010
@@ -27,11 +27,10 @@ import java.util.Map;
 import java.util.Vector;
 
 import javax.swing.AbstractAction;
-import javax.swing.JFileChooser;
 import javax.swing.JOptionPane;
-import javax.swing.filechooser.FileFilter;
 
 import org.apache.log4j.Logger;
+import org.apache.log4j.chainsaw.helper.SwingHelper;
 import org.apache.log4j.chainsaw.prefs.MRUFileList;
 import org.apache.log4j.helpers.Constants;
 import org.apache.log4j.spi.Decoder;
@@ -57,8 +56,6 @@ class FileLoadAction extends AbstractAct
 
     private LogUI parent;
 
-    private JFileChooser chooser = null;
-
     private boolean remoteURL = false;
 
     public FileLoadAction(LogUI parent, Decoder decoder, String title,
@@ -81,35 +78,13 @@ class FileLoadAction extends AbstractAct
         String name = "";
         URL url = null;
 
-        if (!remoteURL) {
-            if (chooser == null) {
-                chooser = new JFileChooser();
-
-                chooser.setDialogTitle("Load Events from XML file...");
-
-                chooser.setAcceptAllFileFilterUsed(true);
-
-                chooser.setFileFilter(new FileFilter() {
-                    public boolean accept(File f) {
-                        return (f.getName().toLowerCase().endsWith(".xml") || f.getName().toLowerCase().endsWith(".zip")
-                                || f.isDirectory());
-                    }
-
-                    public String getDescription() {
-                        return "XML files (*.xml), ZIP files (*.zip)";
-                    }
-                });
-            }
-
-            int i = chooser.showOpenDialog(parent);
-            if (i != JFileChooser.APPROVE_OPTION) {
-                return;
-            }
-            File selectedFile = chooser.getSelectedFile();
-
+      if (!remoteURL) {
             try {
+              File selectedFile = SwingHelper.promptForFile(parent, null, "Load Events from
XML file or zipped XML file...");
+              if (selectedFile != null) {
                 url = selectedFile.toURI().toURL();
                 name = selectedFile.getName();
+              }
             } catch (Exception ex) {
                 // TODO: handle exception
             }

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=1029159&r1=1029158&r2=1029159&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 18:58:21 2010
@@ -29,6 +29,7 @@ import java.awt.event.FocusListener;
 import java.io.File;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.List;
 
 import javax.swing.AbstractAction;
 import javax.swing.BorderFactory;
@@ -37,7 +38,6 @@ import javax.swing.DefaultComboBoxModel;
 import javax.swing.JButton;
 import javax.swing.JCheckBox;
 import javax.swing.JComboBox;
-import javax.swing.JFileChooser;
 import javax.swing.JFrame;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
@@ -45,13 +45,13 @@ import javax.swing.JRadioButton;
 import javax.swing.JTextField;
 import javax.swing.JTextPane;
 import javax.swing.SwingUtilities;
-import javax.swing.filechooser.FileFilter;
 import javax.swing.text.SimpleAttributeSet;
 import javax.swing.text.StyleConstants;
 import javax.swing.text.StyledDocument;
 
 import org.apache.log4j.LogManager;
 import org.apache.log4j.Logger;
+import org.apache.log4j.chainsaw.helper.SwingHelper;
 import org.apache.log4j.chainsaw.prefs.SettingsManager;
 import org.apache.log4j.net.SocketReceiver;
 import org.apache.log4j.net.UDPReceiver;
@@ -210,20 +210,24 @@ class ReceiverConfigurationPanel extends
         dontwarnIfNoReceiver = new JCheckBox("Always start Chainsaw with this configuration");
         panel.add(dontwarnIfNoReceiver, c);
 
+        okButton = new JButton(" OK ");
+        cancelButton = new JButton(" Cancel ");
+
+        List okCancelButtons = SwingHelper.orderOKCancelButtons(okButton, cancelButton);
+
         c = new GridBagConstraints();
         c.fill = GridBagConstraints.HORIZONTAL;
         c.gridx = 1;
         c.gridy = 0;
         c.insets = new Insets(0, 0, 0, 10);
-        okButton = new JButton(" OK ");
-        panel.add(okButton, c);
+        panel.add((JButton)okCancelButtons.get(0), c);
 
         c = new GridBagConstraints();
         c.fill = GridBagConstraints.HORIZONTAL;
         c.gridx = 2;
         c.gridy = 0;
-        cancelButton = new JButton(" Cancel ");
-        panel.add(cancelButton, c);
+        panel.add((JButton)okCancelButtons.get(1), c);
+
         cancelButton.addActionListener(new ActionListener()
         {
             public void actionPerformed(ActionEvent e)
@@ -308,7 +312,7 @@ class ReceiverConfigurationPanel extends
 
     private JPanel buildLogFileReceiverPanel() {
         JPanel panel = new JPanel(new GridBagLayout());
-        browseLogFileButton = new JButton(new AbstractAction(" Find a log file ") {
+        browseLogFileButton = new JButton(new AbstractAction(" Open File... ") {
             public void actionPerformed(ActionEvent e) {
                 try {
 
@@ -465,7 +469,7 @@ class ReceiverConfigurationPanel extends
                 }
             });
 
-        browseForAnExistingConfigurationButton = new JButton(new AbstractAction(" Find an
existing configuration ") {
+        browseForAnExistingConfigurationButton = new JButton(new AbstractAction(" Open File...
") {
                     public void actionPerformed(ActionEvent e) {
                         try {
 
@@ -549,39 +553,15 @@ class ReceiverConfigurationPanel extends
      * or null if they cancelled.
      */
     private URL browseConfig() throws MalformedURLException {
-
-        JFileChooser chooser = new JFileChooser();
-        chooser.setDialogTitle("Use an existing configuration file...");
-        chooser.setDialogType(JFileChooser.OPEN_DIALOG);
-        chooser.setFileFilter(new FileFilter() {
-                public boolean accept(File f) {
-
-                    return f.isDirectory() ||
-                    f.getName().endsWith(".properties") ||
-                    f.getName().endsWith(".xml");
-                }
-
-                public String getDescription() {
-
-                    return "Log4j Configuration file";
-                }
-            });
-
-        chooser.showOpenDialog(this);
-
-        File selectedFile = chooser.getSelectedFile();
-
+        File selectedFile = SwingHelper.promptForFile(this, null, "Choose a Chainsaw configuration
file");
         if (selectedFile == null) {
-
             return null;
         }
 
         if (!selectedFile.exists() || !selectedFile.canRead()) {
-
             return null;
         }
-
-        return chooser.getSelectedFile().toURI().toURL();
+        return selectedFile.toURI().toURL();
     }
 
     /**
@@ -590,13 +570,7 @@ class ReceiverConfigurationPanel extends
      */
     private URL browseLogFile() throws MalformedURLException {
 
-        JFileChooser chooser = new JFileChooser();
-        chooser.setDialogTitle("Browse for a log file...");
-        chooser.setDialogType(JFileChooser.OPEN_DIALOG);
-        chooser.showOpenDialog(this);
-
-        File selectedFile = chooser.getSelectedFile();
-
+        File selectedFile = SwingHelper.promptForFile(this, null, "Select a log file");
         if (selectedFile == null) {
             return null;
         }
@@ -605,7 +579,7 @@ class ReceiverConfigurationPanel extends
             return null;
         }
 
-        return chooser.getSelectedFile().toURI().toURL();
+        return selectedFile.toURI().toURL();
     }
 
     public static void main(String[] args) {

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=1029159&r1=1029158&r2=1029159&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 18:58:21 2010
@@ -18,11 +18,17 @@
 package org.apache.log4j.chainsaw.helper;
 
 import java.awt.Component;
+import java.awt.Container;
 import java.awt.Dimension;
+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;
+import java.util.ArrayList;
+import java.util.List;
 
 import javax.swing.AbstractAction;
 import javax.swing.Action;
@@ -30,6 +36,7 @@ import javax.swing.InputMap;
 import javax.swing.JButton;
 import javax.swing.JComponent;
 import javax.swing.JDialog;
+import javax.swing.JFileChooser;
 import javax.swing.KeyStroke;
 
 /**
@@ -82,4 +89,54 @@ public final class SwingHelper {
       EventQueue.invokeLater(runnable);
     }
   }
+
+  public static boolean isMacOSX() {
+    return System.getProperty("os.name").toLowerCase().startsWith("mac os x");
+  }
+
+  public static List orderOKCancelButtons(JButton okButton, JButton cancelButton) {
+    List result = new ArrayList();
+    if (isMacOSX()) {
+      result.add(cancelButton);
+      result.add(okButton);
+    } else {
+      result.add(okButton);
+      result.add(cancelButton);
+    }
+    return result;
+  }
+
+  public static File promptForFile(Container parent, String defaultPath, String title) {
+        if (SwingHelper.isMacOSX()) {
+            //use filedialog on mac
+            FileDialog fileDialog = new FileDialog((Frame)null, title);
+            if (defaultPath != null) {
+              fileDialog.setDirectory(defaultPath);
+            }
+            fileDialog.setVisible(true);
+            String fileString = fileDialog.getFile();
+            if (fileString == null) {
+              return null;
+            }
+            return new File(fileString);
+          } else {
+
+                JFileChooser chooser;
+                if (defaultPath != null) {
+                  chooser = new JFileChooser(defaultPath);
+                } else {
+                  chooser = new JFileChooser();
+                }
+
+                chooser.setDialogTitle(title);
+
+                chooser.setAcceptAllFileFilterUsed(true);
+
+                int i = chooser.showOpenDialog(parent);
+                if (i != JFileChooser.APPROVE_OPTION) {
+                    return null;
+                }
+            return chooser.getSelectedFile();
+        }
+    }
 }



Mime
View raw message