Author: ruschein
Date: 2010-07-15 09:53:23 -0700 (Thu, 15 Jul 2010)
New Revision: 20937

Modified:
   cytoscape/trunk/src/cytoscape/util/FileUtil.java
Log:
Fixed an ugly file-open bug.

Modified: cytoscape/trunk/src/cytoscape/util/FileUtil.java
===================================================================
--- cytoscape/trunk/src/cytoscape/util/FileUtil.java    2010-07-15 16:36:13 UTC 
(rev 20936)
+++ cytoscape/trunk/src/cytoscape/util/FileUtil.java    2010-07-15 16:53:23 UTC 
(rev 20937)
@@ -1,15 +1,8 @@
 /*
   File: FileUtil.java
 
-  Copyright (c) 2006, The Cytoscape Consortium (www.cytoscape.org)
+  Copyright (c) 2006, 2010, The Cytoscape Consortium (www.cytoscape.org)
 
-  The Cytoscape Consortium is:
-  - Institute for Systems Biology
-  - University of California San Diego
-  - Memorial Sloan-Kettering Cancer Center
-  - Institut Pasteur
-  - Agilent Technologies
-
   This library is free software; you can redistribute it and/or modify it
   under the terms of the GNU Lesser General Public License as published
   by the Free Software Foundation; either version 2.1 of the License, or
@@ -42,7 +35,12 @@
 
 import cytoscape.task.TaskMonitor;
 
+import java.awt.Component;
+import java.awt.Container;
 import java.awt.FileDialog;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
 
 import java.io.BufferedReader;
 import java.io.File;
@@ -56,15 +54,62 @@
 import java.util.Iterator;
 
 import javax.swing.JFileChooser;
+import javax.swing.JList;
 import javax.swing.JOptionPane;
-import java.awt.Component;
 
+
 /**
  * Provides a platform-dependent way to open files. Mainly
  * because Mac would prefer that you use java.awt.FileDialog
  * instead of the Swing FileChooser.
  */
 public abstract class FileUtil {
+       /**
+        *  This class exists to work around a bug in JFileChooser that will 
allow editing of
+        *  file and directory names even when LOAD has been specified.
+        */
+       static class NoEditFileChooser extends JFileChooser {
+               public NoEditFileChooser(final File start) {
+                       super(start);
+                       
+                       final JList list = findFileList(this);
+                       for (MouseListener l : list.getMouseListeners()) {
+                               if (l.getClass().getName().indexOf("FilePane") 
>= 0) {
+                                       list.removeMouseListener(l);
+                                       list.addMouseListener(new 
MyMouseListener(l));
+                               }
+                       }
+               }
+
+               private JList findFileList(final Component comp) {
+                       if (comp instanceof JList)
+                               return (JList)comp;
+
+                       if (comp instanceof Container) {
+                               for (Component child : 
((Container)comp).getComponents()) {
+                                       JList list = findFileList(child);
+                                       if (list != null)
+                                               return list;    
+                               }
+                       }
+
+                       return null;
+               }
+
+               private class MyMouseListener extends MouseAdapter {
+                       MyMouseListener(final MouseListener listenerChain) {
+                               m_listenerChain = listenerChain;
+                       }
+                       
+                       public void mouseClicked(final MouseEvent event) {
+                               if (event.getClickCount() > 1)
+                                       m_listenerChain.mouseClicked(event);
+                       }
+                       
+                       private MouseListener m_listenerChain;
+               }
+       }
+
        protected static CyLogger logger = CyLogger.getLogger(FileUtil.class);
 
        /**
@@ -337,7 +382,7 @@
                        return null;
                } else {
                        // this is not a mac, use the Swing based file dialog
-                       JFileChooser chooser = new JFileChooser(start);
+                       final JFileChooser chooser = (load_save_custom == LOAD) 
? new NoEditFileChooser(start) : new JFileChooser(start);
 
                        if (multiselect && selectedFiles != null){
                                chooser.setSelectedFiles(selectedFiles);        
                                

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to