JAL-2344 handle null format, simplify JalviewFileChooser constructor
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 7 Dec 2016 12:10:00 +0000 (12:10 +0000)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Wed, 7 Dec 2016 12:10:00 +0000 (12:10 +0000)
src/jalview/gui/AlignFrame.java
src/jalview/gui/Desktop.java
src/jalview/gui/FeatureSettings.java
src/jalview/gui/Preferences.java
src/jalview/gui/TreePanel.java
src/jalview/gui/UserDefinedColours.java
src/jalview/gui/WsParamSetManager.java
src/jalview/io/HTMLOutput.java
src/jalview/io/HtmlSvgOutput.java
src/jalview/io/JalviewFileChooser.java
src/jalview/util/ImageMaker.java

index 8ca9085..9c4ff81 100644 (file)
@@ -1112,11 +1112,10 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   @Override
   public void saveAs_actionPerformed(ActionEvent e)
   {
+    String format = currentFileFormat == null ? null : currentFileFormat
+            .toString();
     JalviewFileChooser chooser = JalviewFileChooser.forWrite(
-            Cache.getProperty("LAST_DIRECTORY"),
-            // AppletFormatAdapter.WRITABLE_EXTENSIONS,
-            // AppletFormatAdapter.WRITABLE_FNAMES,
-            currentFileFormat.toString(), false);
+            Cache.getProperty("LAST_DIRECTORY"), format);
 
     chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(MessageManager
index 77bc7d4..cc897e3 100644 (file)
@@ -102,7 +102,6 @@ import javax.swing.JFrame;
 import javax.swing.JInternalFrame;
 import javax.swing.JLabel;
 import javax.swing.JMenuItem;
-import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JPopupMenu;
 import javax.swing.JProgressBar;
@@ -455,7 +454,6 @@ public class Desktop extends jalview.jbgui.GDesktop implements
       }
     });
 
-    // displayed.
     // Thread off a new instance of the file chooser - this reduces the time it
     // takes to open it later on.
     new Thread(new Runnable()
@@ -466,9 +464,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements
         Cache.log.debug("Filechooser init thread started.");
         String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
         JalviewFileChooser.forRead(Cache.getProperty("LAST_DIRECTORY"),
-        // jalview.io.AppletFormatAdapter.READABLE_EXTENSIONS,
-        // jalview.io.AppletFormatAdapter.READABLE_FNAMES,
-                fileFormat, true);
+                fileFormat);
         Cache.log.debug("Filechooser init thread finished.");
       }
     }).start();
@@ -1013,10 +1009,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements
   {
     String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
     JalviewFileChooser chooser = JalviewFileChooser.forRead(
-            Cache.getProperty("LAST_DIRECTORY"),
-            // AppletFormatAdapter.READABLE_EXTENSIONS,
-            // AppletFormatAdapter.READABLE_FNAMES,
-            fileFormat, true);
+            Cache.getProperty("LAST_DIRECTORY"), fileFormat);
 
     chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(MessageManager
@@ -1536,8 +1529,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements
   public void saveState_actionPerformed(ActionEvent e)
   {
     JalviewFileChooser chooser = new JalviewFileChooser(
-            Cache.getProperty("LAST_DIRECTORY"), "jvp", "Jalview Project",
-            "Jalview Project");
+            Cache.getProperty("LAST_DIRECTORY"), "jvp", "Jalview Project");
 
     chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(MessageManager.getString("label.save_state"));
@@ -2192,7 +2184,7 @@ public class Desktop extends jalview.jbgui.GDesktop implements
     {
       JalviewFileChooser chooser = new JalviewFileChooser(
               Cache.getProperty("LAST_DIRECTORY"), "vdj",// TODO: VAMSAS DOCUMENT EXTENSION is VDJ
-              "Vamsas Document", "Vamsas Document");
+              "Vamsas Document");
 
       chooser.setFileView(new JalviewFileView());
       chooser.setDialogTitle(MessageManager
index d65016e..bb5f13c 100644 (file)
@@ -27,6 +27,7 @@ import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
 import jalview.gui.Help.HelpId;
 import jalview.io.JalviewFileChooser;
+import jalview.io.JalviewFileView;
 import jalview.schemabinding.version2.JalviewUserColours;
 import jalview.schemes.FeatureColour;
 import jalview.util.Format;
@@ -79,7 +80,6 @@ import javax.swing.JInternalFrame;
 import javax.swing.JLabel;
 import javax.swing.JLayeredPane;
 import javax.swing.JMenuItem;
-import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JPopupMenu;
 import javax.swing.JScrollPane;
@@ -750,8 +750,8 @@ public class FeatureSettings extends JPanel implements
   {
     JalviewFileChooser chooser = new JalviewFileChooser(
             Cache.getProperty("LAST_DIRECTORY"), "fc",
-            "Sequence Feature Colours", "Sequence Feature Colours");
-    chooser.setFileView(new jalview.io.JalviewFileView());
+            "Sequence Feature Colours");
+    chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(MessageManager
             .getString("label.load_feature_colours"));
     chooser.setToolTipText(MessageManager.getString("action.load"));
@@ -843,8 +843,8 @@ public class FeatureSettings extends JPanel implements
   {
     JalviewFileChooser chooser = new JalviewFileChooser(
             Cache.getProperty("LAST_DIRECTORY"), "fc",
-            "Sequence Feature Colours", "Sequence Feature Colours");
-    chooser.setFileView(new jalview.io.JalviewFileView());
+            "Sequence Feature Colours");
+    chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(MessageManager
             .getString("label.save_feature_colours"));
     chooser.setToolTipText(MessageManager.getString("action.save"));
index e46a555..0b65c1b 100755 (executable)
@@ -56,7 +56,6 @@ import javax.help.HelpSetException;
 import javax.swing.JColorChooser;
 import javax.swing.JFileChooser;
 import javax.swing.JInternalFrame;
-import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 
 import ext.edu.ucsf.rbvi.strucviz2.StructureManager;
@@ -689,12 +688,7 @@ public class Preferences extends GPreferences
   {
     String fileFormat = Cache.getProperty("DEFAULT_FILE_FORMAT");
     JalviewFileChooser chooser = JalviewFileChooser.forRead(
-            Cache.getProperty("LAST_DIRECTORY"), fileFormat, true);
-    // new String[] {
-    // "fa, fasta, fastq", "aln", "pfam", "msf", "pir", "blc",
-    // "jar" }, new String[] { "Fasta", "Clustal", "PFAM", "MSF",
-    // "PIR", "BLC", "Jalview" },
-    // fileFormat);
+            Cache.getProperty("LAST_DIRECTORY"), fileFormat);
     chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(MessageManager
             .getString("label.select_startup_file"));
index af84dbc..6fa4493 100755 (executable)
@@ -750,8 +750,7 @@ public class TreePanel extends GTreePanel
     {
       JalviewFileChooser chooser = new JalviewFileChooser(
               Cache.getProperty("LAST_DIRECTORY"),
-              ImageMaker.EPS_EXTENSION, ImageMaker.EPS_EXTENSION,
-              ImageMaker.EPS_EXTENSION);
+              ImageMaker.EPS_EXTENSION, ImageMaker.EPS_EXTENSION);
       chooser.setFileView(new JalviewFileView());
       chooser.setDialogTitle(MessageManager
               .getString("label.create_eps_from_tree"));
@@ -798,8 +797,7 @@ public class TreePanel extends GTreePanel
     {
       JalviewFileChooser chooser = new JalviewFileChooser(
               Cache.getProperty("LAST_DIRECTORY"),
-              ImageMaker.PNG_EXTENSION, ImageMaker.PNG_DESCRIPTION,
-              ImageMaker.PNG_DESCRIPTION);
+              ImageMaker.PNG_EXTENSION, ImageMaker.PNG_DESCRIPTION);
 
       chooser.setFileView(new jalview.io.JalviewFileView());
       chooser.setDialogTitle(MessageManager
index c380049..0df23e0 100755 (executable)
@@ -24,6 +24,7 @@ import jalview.api.structures.JalviewStructureDisplayI;
 import jalview.bin.Cache;
 import jalview.datamodel.SequenceGroup;
 import jalview.io.JalviewFileChooser;
+import jalview.io.JalviewFileView;
 import jalview.jbgui.GUserDefinedColours;
 import jalview.schemes.ColourSchemeI;
 import jalview.schemes.ResidueProperties;
@@ -47,7 +48,6 @@ import java.util.StringTokenizer;
 
 import javax.swing.JButton;
 import javax.swing.JInternalFrame;
-import javax.swing.JOptionPane;
 import javax.swing.event.ChangeEvent;
 import javax.swing.event.ChangeListener;
 
@@ -599,8 +599,8 @@ public class UserDefinedColours extends GUserDefinedColours implements
 
     JalviewFileChooser chooser = new JalviewFileChooser(
             Cache.getProperty("LAST_DIRECTORY"), "jc",
-            "Jalview User Colours", "Jalview User Colours");
-    chooser.setFileView(new jalview.io.JalviewFileView());
+            "Jalview User Colours");
+    chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(MessageManager
             .getString("label.load_colour_scheme"));
     chooser.setToolTipText(MessageManager.getString("action.load"));
@@ -834,9 +834,9 @@ public class UserDefinedColours extends GUserDefinedColours implements
     }
     JalviewFileChooser chooser = new JalviewFileChooser(
             Cache.getProperty("LAST_DIRECTORY"), "jc",
-            "Jalview User Colours", "Jalview User Colours");
+            "Jalview User Colours");
 
-    chooser.setFileView(new jalview.io.JalviewFileView());
+    chooser.setFileView(new JalviewFileView());
     chooser.setDialogTitle(MessageManager
             .getString("label.save_colour_scheme"));
     chooser.setToolTipText(MessageManager.getString("action.save"));
index 80798c6..b260e1b 100644 (file)
@@ -39,8 +39,6 @@ import java.util.Hashtable;
 import java.util.List;
 import java.util.StringTokenizer;
 
-import javax.swing.JOptionPane;
-
 /**
  * store and retrieve web service parameter sets.
  * 
@@ -187,7 +185,7 @@ public class WsParamSetManager implements ParamManager
     {
       JalviewFileChooser chooser = new JalviewFileChooser(
               Cache.getProperty("LAST_DIRECTORY"), "wsparams",
-              "Web Service Parameter File", "Web Service Parameter File");
+              "Web Service Parameter File");
       chooser.setFileView(new JalviewFileView());
       chooser.setDialogTitle(MessageManager
               .getString("label.choose_filename_for_param_file"));
index 381a40b..b0ca25b 100755 (executable)
@@ -1,6 +1,7 @@
 package jalview.io;
 
 import jalview.api.AlignExportSettingI;
+import jalview.bin.Cache;
 import jalview.datamodel.AlignmentExportData;
 import jalview.exceptions.NoFileSelectedException;
 import jalview.gui.AlignmentPanel;
@@ -243,9 +244,7 @@ public abstract class HTMLOutput implements Runnable
     }
 
     JalviewFileChooser jvFileChooser = new JalviewFileChooser(
-            jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
-            new String[] { "html" }, new String[] { "HTML files" },
-            "HTML files");
+            Cache.getProperty("LAST_DIRECTORY"), "html", "HTML files");
     jvFileChooser.setFileView(new JalviewFileView());
 
     jvFileChooser.setDialogTitle(MessageManager
index 1ec3a4e..3fb3cf2 100644 (file)
@@ -71,16 +71,6 @@ public class HtmlSvgOutput extends HTMLOutput
     new Thread(this).start();
   }
 
-
-  static JalviewFileChooser getHTMLChooser()
-  {
-    return new jalview.io.JalviewFileChooser(
-            jalview.bin.Cache.getProperty("LAST_DIRECTORY"),
-            new String[] { "html" },
-            new String[] { "Hypertext Markup Language" },
-            "Hypertext Markup Language");
-  }
-
   public int printUnwrapped(int pwidth, int pheight, int pi,
           Graphics idGraphics, Graphics alignmentGraphics)
           throws PrinterException
index 7ebe081..7ccdaa9 100755 (executable)
@@ -33,7 +33,6 @@ import java.awt.event.MouseAdapter;
 import java.awt.event.MouseEvent;
 import java.io.File;
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 import java.util.StringTokenizer;
 import java.util.Vector;
@@ -44,7 +43,6 @@ import javax.swing.JList;
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
 import javax.swing.SpringLayout;
-import javax.swing.filechooser.FileView;
 import javax.swing.plaf.basic.BasicFileChooserUI;
 
 /**
@@ -64,11 +62,9 @@ public class JalviewFileChooser extends JFileChooser
    * 
    * @param directory
    * @param selected
-   * @param selectAll
    * @return
    */
-  public static JalviewFileChooser forRead(String directory,
-          String selected, boolean selectAll)
+  public static JalviewFileChooser forRead(String directory, String selected)
   {
     List<String> extensions = new ArrayList<String>();
     List<String> descs = new ArrayList<String>();
@@ -82,8 +78,7 @@ public class JalviewFileChooser extends JFileChooser
     }
     return new JalviewFileChooser(directory,
             extensions.toArray(new String[extensions.size()]),
-            descs.toArray(new String[descs.size()]),
-            selected);
+            descs.toArray(new String[descs.size()]), selected, true);
   }
 
   /**
@@ -92,11 +87,10 @@ public class JalviewFileChooser extends JFileChooser
    * 
    * @param directory
    * @param selected
-   * @param selectAll
    * @return
    */
   public static JalviewFileChooser forWrite(String directory,
-          String selected, boolean selectAll)
+          String selected)
   {
     // TODO in Java 8, forRead and forWrite can be a single method
     // with a lambda expression parameter for isReadable/isWritable
@@ -112,7 +106,7 @@ public class JalviewFileChooser extends JFileChooser
     }
     return new JalviewFileChooser(directory,
             extensions.toArray(new String[extensions.size()]),
-            descs.toArray(new String[descs.size()]), selected);
+            descs.toArray(new String[descs.size()]), selected, false);
   }
 
   public JalviewFileChooser(String dir)
@@ -121,16 +115,29 @@ public class JalviewFileChooser extends JFileChooser
     setAccessory(new RecentlyOpened());
   }
 
-  public JalviewFileChooser(String dir, String extension, String desc,
+  public JalviewFileChooser(String dir, String[] suffix, String[] desc,
           String selected)
   {
-    super(safePath(dir));
-    init(Collections.singletonList(new String[] { extension, desc }),
-            selected);
+    this(dir, suffix, desc, selected, true);
   }
 
-  public JalviewFileChooser(String dir, String[] extensions, String[] descs,
-          String selected)
+  /**
+   * Constructor for a single choice of file extension and description
+   * 
+   * @param dir
+   * @param extension
+   * @param desc
+   */
+  public JalviewFileChooser(String dir, String extension, String desc)
+  {
+    // TODO inline dir as Cache.getProperty("LAST_DIRECTORY") ? if applet
+    // builds ok
+    this(dir, new String[] { extension }, new String[] { desc }, desc,
+            true);
+  }
+
+  JalviewFileChooser(String dir, String[] extensions, String[] descs,
+          String selected, boolean allFiles)
   {
     super(safePath(dir));
     if (extensions.length == descs.length)
@@ -140,7 +147,7 @@ public class JalviewFileChooser extends JFileChooser
       {
         formats.add(new String[] { extensions[i], descs[i] });
       }
-      init(formats, selected);
+      init(formats, selected, allFiles);
     }
     else
     {
@@ -169,15 +176,17 @@ public class JalviewFileChooser extends JFileChooser
    * @param formats
    *          a list of {extensions, description} for each file format
    * @param selected
+   * @param allFiles
+   *          if true, 'any format' option is included
    */
-  void init(List<String[]> formats, String selected)
+  void init(List<String[]> formats, String selected, boolean allFiles)
   {
 
     JalviewFileFilter chosen = null;
 
     // SelectAllFilter needs to be set first before adding further
     // file filters to fix bug on Mac OSX
-    setAcceptAllFileFilterUsed(true);
+    setAcceptAllFileFilterUsed(allFiles);
 
     for (String[] format : formats)
     {
index 71e2c7e..8f8af54 100755 (executable)
@@ -311,7 +311,7 @@ public class ImageMaker
       return null;
     }
     return new JalviewFileChooser(Cache.getProperty("LAST_DIRECTORY"),
-            PNG_EXTENSION, PNG_DESCRIPTION, PNG_DESCRIPTION);
+            PNG_EXTENSION, PNG_DESCRIPTION);
   }
 
   static JalviewFileChooser getEPSChooser()
@@ -321,7 +321,7 @@ public class ImageMaker
       return null;
     }
     return new JalviewFileChooser(Cache.getProperty("LAST_DIRECTORY"),
-            EPS_EXTENSION, EPS_DESCRIPTION, EPS_DESCRIPTION);
+            EPS_EXTENSION, EPS_DESCRIPTION);
   }
 
   private void setProgressMessage(String message)
@@ -339,6 +339,6 @@ public class ImageMaker
       return null;
     }
     return new JalviewFileChooser(Cache.getProperty("LAST_DIRECTORY"),
-            SVG_EXTENSION, SVG_DESCRIPTION, SVG_DESCRIPTION);
+            SVG_EXTENSION, SVG_DESCRIPTION);
   }
 }