JAL-3141 Found a good fix for updating the FileChooser list of files when 'Include...
authorBen Soares <bsoares@dundee.ac.uk>
Tue, 29 Jan 2019 14:15:51 +0000 (14:15 +0000)
committerBen Soares <bsoares@dundee.ac.uk>
Tue, 29 Jan 2019 14:15:51 +0000 (14:15 +0000)
src/jalview/io/JalviewFileChooser.java

index 8fc5ddd..0d78bda 100755 (executable)
@@ -259,62 +259,19 @@ public class JalviewFileChooser extends JFileChooser
             Cache.setProperty(BackupFiles.NS + "_FC_INCLUDE",
                     String.valueOf(includeBackupFiles));
 
-            if (Platform.isAMac())
+            FileFilter f = jfc.getFileFilter();
+            // deselect the selected file if it's no longer choosable
+            File selectedFile = jfc.getSelectedFile();
+            if (selectedFile != null && !f.accept(selectedFile))
             {
-              // This is a kludge. Cannot find out how to get the file list to
-              // refresh on its own! This works the best out of a number of
-              // different attempts!
-              FileFilter ff = jfc.getFileFilter();
-              jfc.setFileFilter(jfc.getAcceptAllFileFilter());
-              jfc.setFileFilter(ff);
-
-              /*
-              jfc.setFileHidingEnabled(!jfc.isFileHidingEnabled());
-              jfc.setFileHidingEnabled(!jfc.isFileHidingEnabled());
-              */
-
-              /*
-              jfc.getRootPane()
-                      .paintImmediately(jfc.getRootPane().getBounds());
-              jfc.paintImmediately(jfc.getBounds());
-              */
-
-              /*
-              Object o = jfc.getClientProperty(
-                      CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY);
-              jfc.firePropertyChange(CHOOSABLE_FILE_FILTER_CHANGED_PROPERTY,
-                      o, o);
-              */
-
-              /*
-              File f = jfc.getSelectedFile();
               jfc.setSelectedFile(null);
-              if (f != null)
-              {
-                jfc.setSelectedFile(f);
-              }
-              */
-
-              /*
-              Graphics g = jfc.getGraphics();
-              jfc.update(g);
-              jfc.paintAll(g);
-              */
-
-              /*
-              jfc.setFileHidingEnabled(!jfc.isFileHidingEnabled());
-              jfc.setFileHidingEnabled(!jfc.isFileHidingEnabled());
-              */
-              /*
-              jfc.invalidate();
-              Component[] c = jfc.getComponents();
-              for (int i = 0; i < c.length; i++)
-              {
-                c[i].invalidate();
-                System.out.println("INVALIDATING " + c[i].getName());
-              }
-              */
             }
+            // fake the OK button changing (to force it to upate)
+            String s = jfc.getApproveButtonText();
+            jfc.firePropertyChange(
+                    APPROVE_BUTTON_TEXT_CHANGED_PROPERTY, null, s);
+            // fake the file filter changing (its behaviour actually has)
+            jfc.firePropertyChange(FILE_FILTER_CHANGED_PROPERTY, null, f);
 
             jfc.rescanCurrentDirectory();
             jfc.revalidate();