JAL-3048 inlined 1-line methods, small refactor of ImageMaker.TYPE
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 19 Jul 2018 10:46:04 +0000 (11:46 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Thu, 19 Jul 2018 10:46:04 +0000 (11:46 +0100)
src/jalview/gui/AlignFrame.java
src/jalview/gui/AlignmentPanel.java
src/jalview/util/ImageMaker.java

index f8e5e30..145653a 100644 (file)
@@ -87,6 +87,7 @@ import jalview.schemes.ColourSchemeI;
 import jalview.schemes.ColourSchemes;
 import jalview.schemes.ResidueColourScheme;
 import jalview.schemes.TCoffeeColourScheme;
 import jalview.schemes.ColourSchemes;
 import jalview.schemes.ResidueColourScheme;
 import jalview.schemes.TCoffeeColourScheme;
+import jalview.util.ImageMaker.TYPE;
 import jalview.util.MessageManager;
 import jalview.util.dialogrunner.RunResponse;
 import jalview.viewmodel.AlignmentViewport;
 import jalview.util.MessageManager;
 import jalview.util.dialogrunner.RunResponse;
 import jalview.viewmodel.AlignmentViewport;
@@ -1399,33 +1400,39 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   }
 
   /**
   }
 
   /**
-   * DOCUMENT ME!
+   * Creates a PNG image of the alignment and writes it to the given file. If
+   * the file is null, the user is prompted to choose a file.
    * 
    * 
-   * @param e
-   *          DOCUMENT ME!
+   * @param f
    */
   @Override
   public void createPNG(File f)
   {
    */
   @Override
   public void createPNG(File f)
   {
-    alignPanel.makePNG(f);
+    alignPanel.makeAlignmentImage(TYPE.PNG, f);
   }
 
   /**
   }
 
   /**
-   * DOCUMENT ME!
+   * Creates an EPS image of the alignment and writes it to the given file. If
+   * the file is null, the user is prompted to choose a file.
    * 
    * 
-   * @param e
-   *          DOCUMENT ME!
+   * @param f
    */
   @Override
   public void createEPS(File f)
   {
    */
   @Override
   public void createEPS(File f)
   {
-    alignPanel.makeEPS(f);
+    alignPanel.makeAlignmentImage(TYPE.EPS, f);
   }
 
   }
 
+  /**
+   * Creates an SVG image of the alignment and writes it to the given file. If
+   * the file is null, the user is prompted to choose a file.
+   * 
+   * @param f
+   */
   @Override
   public void createSVG(File f)
   {
   @Override
   public void createSVG(File f)
   {
-    alignPanel.makeSVG(f);
+    alignPanel.makeAlignmentImage(TYPE.SVG, f);
   }
 
   @Override
   }
 
   @Override
index 065d0c3..e1d4800 100644 (file)
@@ -36,6 +36,7 @@ import jalview.math.AlignmentDimension;
 import jalview.schemes.ResidueProperties;
 import jalview.structure.StructureSelectionManager;
 import jalview.util.Comparison;
 import jalview.schemes.ResidueProperties;
 import jalview.structure.StructureSelectionManager;
 import jalview.util.Comparison;
+import jalview.util.ImageMaker;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
 import jalview.viewmodel.ViewportListenerI;
 import jalview.util.MessageManager;
 import jalview.util.Platform;
 import jalview.viewmodel.ViewportListenerI;
@@ -1298,14 +1299,14 @@ public class AlignmentPanel extends GAlignmentPanel implements
       AlignmentDimension aDimension = getAlignmentDimension();
       try
       {
       AlignmentDimension aDimension = getAlignmentDimension();
       try
       {
-        jalview.util.ImageMaker im;
+        ImageMaker im;
         final String imageAction, imageTitle;
         final String imageAction, imageTitle;
-        if (type == jalview.util.ImageMaker.TYPE.PNG)
+        if (type == ImageMaker.TYPE.PNG)
         {
           imageAction = "Create PNG image from alignment";
           imageTitle = null;
         }
         {
           imageAction = "Create PNG image from alignment";
           imageTitle = null;
         }
-        else if (type == jalview.util.ImageMaker.TYPE.EPS)
+        else if (type == ImageMaker.TYPE.EPS)
         {
           imageAction = "Create EPS file from alignment";
           imageTitle = alignFrame.getTitle();
         {
           imageAction = "Create EPS file from alignment";
           imageTitle = alignFrame.getTitle();
@@ -1316,8 +1317,7 @@ public class AlignmentPanel extends GAlignmentPanel implements
           imageTitle = alignFrame.getTitle();
         }
 
           imageTitle = alignFrame.getTitle();
         }
 
-        im = new jalview.util.ImageMaker(this, type, imageAction,
-                aDimension.getWidth(),
+        im = new ImageMaker(this, type, imageAction, aDimension.getWidth(),
                 aDimension.getHeight() + boarderBottomOffset, file,
                 imageTitle, alignFrame, pSessionId, headless);
         Graphics graphics = im.getGraphics();
                 aDimension.getHeight() + boarderBottomOffset, file,
                 imageTitle, alignFrame, pSessionId, headless);
         Graphics graphics = im.getGraphics();
@@ -1398,27 +1398,6 @@ public class AlignmentPanel extends GAlignmentPanel implements
 
   }
 
 
   }
 
-  /**
-   * DOCUMENT ME!
-   */
-  public void makeEPS(File epsFile)
-  {
-    makeAlignmentImage(jalview.util.ImageMaker.TYPE.EPS, epsFile);
-  }
-
-  /**
-   * DOCUMENT ME!
-   */
-  public void makePNG(File pngFile)
-  {
-    makeAlignmentImage(jalview.util.ImageMaker.TYPE.PNG, pngFile);
-  }
-
-  public void makeSVG(File svgFile)
-  {
-    makeAlignmentImage(jalview.util.ImageMaker.TYPE.SVG, svgFile);
-  }
-
   public void makePNGImageMap(File imgMapFile, String imageName)
   {
     // /////ONLY WORKS WITH NON WRAPPED ALIGNMENTS
   public void makePNGImageMap(File imgMapFile, String imageName)
   {
     // /////ONLY WORKS WITH NON WRAPPED ALIGNMENTS
index 284b7be..493e210 100755 (executable)
@@ -20,6 +20,7 @@
  */
 package jalview.util;
 
  */
 package jalview.util;
 
+import jalview.bin.Cache;
 import jalview.bin.Jalview;
 import jalview.gui.IProgressIndicator;
 import jalview.gui.LineartOptions;
 import jalview.bin.Jalview;
 import jalview.gui.IProgressIndicator;
 import jalview.gui.LineartOptions;
@@ -77,22 +78,26 @@ public class ImageMaker
 
   public enum TYPE
   {
 
   public enum TYPE
   {
-    EPS("EPS", MessageManager.getString("label.eps_file"), getEPSChooser()),
-    PNG("PNG", MessageManager.getString("label.png_image"),
-            getPNGChooser()),
-    SVG("SVG", "SVG", getSVGChooser());
+    EPS("EPS", MessageManager.getString("label.eps_file"), EPS_EXTENSION,
+            EPS_DESCRIPTION),
+    PNG("PNG", MessageManager.getString("label.png_image"), PNG_EXTENSION,
+            PNG_DESCRIPTION),
+    SVG("SVG", "SVG", SVG_EXTENSION, SVG_DESCRIPTION);
 
 
-    private JalviewFileChooser chooser;
+    public final String name;
 
 
-    private String name;
+    public final String label;
 
 
-    private String label;
+    public final String extension;
 
 
-    TYPE(String name, String label, JalviewFileChooser chooser)
+    public final String description;
+
+    TYPE(String name, String label, String ext, String desc)
     {
       this.name = name;
       this.label = label;
     {
       this.name = name;
       this.label = label;
-      this.chooser = chooser;
+      this.extension = ext;
+      this.description = desc;
     }
 
     public String getName()
     }
 
     public String getName()
@@ -102,7 +107,7 @@ public class ImageMaker
 
     public JalviewFileChooser getChooser()
     {
 
     public JalviewFileChooser getChooser()
     {
-      return chooser;
+      return new JalviewFileChooser(extension, description);
     }
 
     public String getLabel()
     }
 
     public String getLabel()
@@ -112,6 +117,21 @@ public class ImageMaker
 
   }
 
 
   }
 
+  /**
+   * Constructor builds the image and writes it to file. If the supplied file
+   * name is null, the user is prompted for the output file.
+   * 
+   * @param parent
+   * @param type
+   * @param title
+   * @param width
+   * @param height
+   * @param file
+   * @param fileTitle
+   * @param pIndicator
+   * @param pSessionId
+   * @param headless
+   */
   public ImageMaker(Component parent, TYPE type, String title, int width,
           int height, File file, String fileTitle,
           IProgressIndicator pIndicator, long pSessionId, boolean headless)
   public ImageMaker(Component parent, TYPE type, String title, int width,
           int height, File file, String fileTitle,
           IProgressIndicator pIndicator, long pSessionId, boolean headless)
@@ -120,10 +140,8 @@ public class ImageMaker
     this.type = type;
     this.pSessionId = pSessionId;
     this.headless = headless;
     this.type = type;
     this.pSessionId = pSessionId;
     this.headless = headless;
-    if (file == null)
+    if (file == null && !Jalview.isHeadlessMode())
     {
     {
-      // TODO: JAL-3048 export SVG/EPS/PNG- not required for Jalview-JS
-
       setProgressMessage(MessageManager.formatMessage(
               "status.waiting_for_user_to_select_output_file", type.name));
       JalviewFileChooser chooser;
       setProgressMessage(MessageManager.formatMessage(
               "status.waiting_for_user_to_select_output_file", type.name));
       JalviewFileChooser chooser;
@@ -133,9 +151,9 @@ public class ImageMaker
       chooser.setToolTipText(MessageManager.getString("action.save"));
       int value = chooser.showSaveDialog(parent);
 
       chooser.setToolTipText(MessageManager.getString("action.save"));
       int value = chooser.showSaveDialog(parent);
 
-      if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
+      if (value == JalviewFileChooser.APPROVE_OPTION)
       {
       {
-        jalview.bin.Cache.setProperty("LAST_DIRECTORY",
+        Cache.setProperty("LAST_DIRECTORY",
                 chooser.getSelectedFile().getParent());
         file = chooser.getSelectedFile();
       }
                 chooser.getSelectedFile().getParent());
         file = chooser.getSelectedFile();
       }
@@ -214,7 +232,7 @@ public class ImageMaker
   {
     boolean accurateText = true;
 
   {
     boolean accurateText = true;
 
-    String renderStyle = jalview.bin.Cache.getDefault("EPS_RENDERING",
+    String renderStyle = Cache.getDefault("EPS_RENDERING",
             "Prompt each time");
 
     // If we need to prompt, and if the GUI is visible then
             "Prompt each time");
 
     // If we need to prompt, and if the GUI is visible then
@@ -253,6 +271,7 @@ public class ImageMaker
               .formatMessage("status.export_complete", type.getName()));
     } catch (Exception ex)
     {
               .formatMessage("status.export_complete", type.getName()));
     } catch (Exception ex)
     {
+      System.err.println("Error writing PNG: " + ex.toString());
     }
   }
 
     }
   }