JAL-1780 JAL-653 moved AlignExportSettings reference on AlignViewportI to FileParse...
authorJim Procter <jprocter@issues.jalview.org>
Thu, 18 Jun 2015 17:54:53 +0000 (18:54 +0100)
committerJim Procter <jprocter@issues.jalview.org>
Thu, 18 Jun 2015 17:54:53 +0000 (18:54 +0100)
src/jalview/api/AlignViewportI.java
src/jalview/appletgui/AlignFrame.java
src/jalview/appletgui/AlignViewport.java
src/jalview/gui/AlignFrame.java
src/jalview/gui/AlignViewport.java
src/jalview/io/BioJsHTMLOutput.java
src/jalview/io/FileParse.java
src/jalview/io/HtmlSvgOutput.java
src/jalview/io/JSONFile.java

index fa73194..93b2134 100644 (file)
  */
 package jalview.api;
 
-import java.awt.Color;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Map;
-
 import jalview.analysis.Conservation;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
@@ -36,6 +31,11 @@ import jalview.datamodel.SequenceGroup;
 import jalview.datamodel.SequenceI;
 import jalview.schemes.ColourSchemeI;
 
+import java.awt.Color;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
 /**
  * @author jimp
  * 
@@ -372,26 +372,4 @@ public interface AlignViewportI extends ViewStyleI
    * Set whether view should scroll to show the highlighted region of a sequence
    */
   void setFollowHighlight(boolean b);
-
-  /**
-   * Returns a FeatureRenderer instance
-   * 
-   * @return
-   */
-  public FeatureRenderer getFeatureRenderer();
-
-  /**
-   * Sets a FeatureRenderer for a viewport
-   * 
-   * @param featureRenderer
-   */
-  public void setFeatureRenderer(FeatureRenderer featureRenderer);
-
-  /**
-   * Returns Settings for exporting an Alignment
-   * 
-   * @return
-   */
-  public AlignExportSettingI getExportSettings();
-
 }
index 6c8e733..aa90859 100644 (file)
@@ -1341,7 +1341,6 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
             { e.getActionCommand() }), 600, 500);
 
     FeatureRenderer fr = this.alignPanel.cloneFeatureRenderer();
-    viewport.setFeatureRenderer(fr);
     cap.setText(new AppletFormatAdapter(viewport).formatSequences(
             e.getActionCommand(), viewport.getAlignment(),
             viewport.getShowJVSuffix()));
index d7ec681..4b55697 100644 (file)
@@ -20,8 +20,6 @@
  */
 package jalview.appletgui;
 
-import java.awt.Font;
-
 import jalview.analysis.NJTree;
 import jalview.api.AlignExportSettingI;
 import jalview.api.AlignViewportI;
@@ -42,6 +40,8 @@ import jalview.structure.StructureSelectionManager;
 import jalview.structure.VamsasSource;
 import jalview.viewmodel.AlignmentViewport;
 
+import java.awt.Font;
+
 public class AlignViewport extends AlignmentViewport implements
         SelectionSource, VamsasSource, CommandListener
 {
@@ -473,28 +473,5 @@ public class AlignViewport extends AlignmentViewport implements
     }
   }
 
-  @Override
-  public FeatureRenderer getFeatureRenderer()
-  {
-    return featureRenderer;
-  }
-
-  @Override
-  public void setFeatureRenderer(FeatureRenderer featureRenderer)
-  {
-    this.featureRenderer = featureRenderer;
-
-  }
-
-  public AlignExportSettingI getExportSettings()
-  {
-    return exportSettings;
-  }
-
-  public void setExportSettings(AlignExportSettingI exportSettings)
-  {
-    this.exportSettings = exportSettings;
-  }
-
 
 }
index 2c6417e..14198b9 100644 (file)
  */
 package jalview.gui;
 
-import java.awt.BorderLayout;
-import java.awt.Component;
-import java.awt.Rectangle;
-import java.awt.Toolkit;
-import java.awt.datatransfer.Clipboard;
-import java.awt.datatransfer.DataFlavor;
-import java.awt.datatransfer.StringSelection;
-import java.awt.datatransfer.Transferable;
-import java.awt.dnd.DnDConstants;
-import java.awt.dnd.DropTargetDragEvent;
-import java.awt.dnd.DropTargetDropEvent;
-import java.awt.dnd.DropTargetEvent;
-import java.awt.dnd.DropTargetListener;
-import java.awt.event.ActionEvent;
-import java.awt.event.ActionListener;
-import java.awt.event.ItemEvent;
-import java.awt.event.ItemListener;
-import java.awt.event.KeyAdapter;
-import java.awt.event.KeyEvent;
-import java.awt.event.MouseAdapter;
-import java.awt.event.MouseEvent;
-import java.awt.print.PageFormat;
-import java.awt.print.PrinterJob;
-import java.beans.PropertyChangeEvent;
-import java.io.File;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Deque;
-import java.util.Enumeration;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Set;
-import java.util.Vector;
-
-import javax.swing.JCheckBoxMenuItem;
-import javax.swing.JEditorPane;
-import javax.swing.JInternalFrame;
-import javax.swing.JLayeredPane;
-import javax.swing.JMenu;
-import javax.swing.JMenuItem;
-import javax.swing.JOptionPane;
-import javax.swing.JRadioButtonMenuItem;
-import javax.swing.JScrollPane;
-import javax.swing.SwingUtilities;
-
 import jalview.analysis.AAFrequency;
 import jalview.analysis.AlignmentSorter;
 import jalview.analysis.AlignmentUtils;
@@ -145,6 +99,52 @@ import jalview.ws.jws2.Jws2Discoverer;
 import jalview.ws.jws2.jabaws2.Jws2Instance;
 import jalview.ws.seqfetcher.DbSourceProxy;
 
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Rectangle;
+import java.awt.Toolkit;
+import java.awt.datatransfer.Clipboard;
+import java.awt.datatransfer.DataFlavor;
+import java.awt.datatransfer.StringSelection;
+import java.awt.datatransfer.Transferable;
+import java.awt.dnd.DnDConstants;
+import java.awt.dnd.DropTargetDragEvent;
+import java.awt.dnd.DropTargetDropEvent;
+import java.awt.dnd.DropTargetEvent;
+import java.awt.dnd.DropTargetListener;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.ItemEvent;
+import java.awt.event.ItemListener;
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.awt.print.PageFormat;
+import java.awt.print.PrinterJob;
+import java.beans.PropertyChangeEvent;
+import java.io.File;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Deque;
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Set;
+import java.util.Vector;
+
+import javax.swing.JCheckBoxMenuItem;
+import javax.swing.JEditorPane;
+import javax.swing.JInternalFrame;
+import javax.swing.JLayeredPane;
+import javax.swing.JMenu;
+import javax.swing.JMenuItem;
+import javax.swing.JOptionPane;
+import javax.swing.JRadioButtonMenuItem;
+import javax.swing.JScrollPane;
+import javax.swing.SwingUtilities;
+
 /**
  * DOCUMENT ME!
  * 
@@ -1244,8 +1244,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     AlignmentI alignmentToExport = null;
     String[] omitHidden = null;
     int[] alignmentStartEnd = new int[2];
-    FeatureRenderer fr = new FeatureRenderer(this.alignPanel);
-    viewport.setFeatureRenderer(fr);
+
     HiddenSequences hiddenSeqs = viewport.getAlignment()
             .getHiddenSequences();
 
@@ -1257,7 +1256,6 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     boolean hasHiddenSeqs = hiddenSeqs.getSize() > 0;
     AlignExportSettingI settings = new AlignExportSettings(hasHiddenSeqs,
             viewport.hasHiddenColumns(), exportFomat);
-    viewport.setExportSettings(settings);
     settings.isExportAnnotations();
 
     if (viewport.hasHiddenColumns() && !settings.isExportHiddenColumns())
@@ -1355,8 +1353,7 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   @Override
   public void bioJSMenuItem_actionPerformed(ActionEvent e)
   {
-    BioJsHTMLOutput bjs = new BioJsHTMLOutput(alignPanel,
-            alignPanel.getSeqPanel().seqCanvas.getFeatureRenderer());
+    BioJsHTMLOutput bjs = new BioJsHTMLOutput(alignPanel);
     bjs.exportJalviewAlignmentAsBioJsHtmlFile();
   }
   public void createImageMap(File file, String image)
index a6f7d41..fc889ad 100644 (file)
  */
 package jalview.gui;
 
-import java.awt.Container;
-import java.awt.Dimension;
-import java.awt.Font;
-import java.awt.Rectangle;
-import java.util.ArrayList;
-import java.util.Hashtable;
-import java.util.List;
-import java.util.Set;
-import java.util.Vector;
-
-import javax.swing.JInternalFrame;
-import javax.swing.JOptionPane;
-
 import jalview.analysis.AlignmentUtils;
 import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
 import jalview.analysis.NJTree;
-import jalview.api.AlignExportSettingI;
 import jalview.api.AlignViewportI;
-import jalview.api.FeatureRenderer;
 import jalview.api.ViewStyleI;
 import jalview.bin.Cache;
 import jalview.commands.CommandI;
@@ -79,6 +64,19 @@ import jalview.util.MessageManager;
 import jalview.viewmodel.AlignmentViewport;
 import jalview.ws.params.AutoCalcSetting;
 
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.Font;
+import java.awt.Rectangle;
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Set;
+import java.util.Vector;
+
+import javax.swing.JInternalFrame;
+import javax.swing.JOptionPane;
+
 /**
  * DOCUMENT ME!
  * 
@@ -98,12 +96,6 @@ public class AlignViewport extends AlignmentViewport implements
 
   private Rectangle explodedGeometry;
 
-  private FeatureRenderer featureRenderer;
-
-  private boolean includeHiddenRegion = true;
-
-  private AlignExportSettingI exportSettings;
-
   String viewName;
 
   /*
@@ -1045,25 +1037,4 @@ public class AlignViewport extends AlignmentViewport implements
     }
   }
 
-  @Override
-  public FeatureRenderer getFeatureRenderer()
-  {
-    return featureRenderer;
-  }
-
-  @Override
-  public void setFeatureRenderer(FeatureRenderer featureRenderer)
-  {
-    this.featureRenderer = featureRenderer;
-  }
-
-  public AlignExportSettingI getExportSettings()
-  {
-    return exportSettings;
-  }
-
-  public void setExportSettings(AlignExportSettingI exportSettings)
-  {
-    this.exportSettings = exportSettings;
-  }
 }
index a026c57..74fb147 100644 (file)
@@ -1,9 +1,7 @@
 package jalview.io;
 
+import jalview.api.AlignmentViewPanel;
 import jalview.exceptions.NoFileSelectedException;
-import jalview.gui.AlignViewport;
-import jalview.gui.AlignmentPanel;
-import jalview.gui.FeatureRenderer;
 import jalview.json.binding.v1.BioJSReleasePojo;
 import jalview.json.binding.v1.BioJSRepositoryPojo;
 import jalview.util.MessageManager;
@@ -23,7 +21,7 @@ import java.util.TreeMap;
 
 public class BioJsHTMLOutput
 {
-  private AlignViewport av;
+  private AlignmentViewPanel ap;
 
   private static File currentBJSTemplateFile;
 
@@ -40,12 +38,11 @@ public class BioJsHTMLOutput
                   "biojs_template_git_repo",
                   "https://raw.githubusercontent.com/tcofoegbu/bjs-template/master/package.json");
 
-  public BioJsHTMLOutput(AlignmentPanel ap, FeatureRenderer fr1)
+  public BioJsHTMLOutput(AlignmentViewPanel ap)
   {
     if (ap != null)
     {
-      this.av = ap.av;
-      av.setFeatureRenderer(new FeatureRenderer(ap));
+      this.ap = ap;
     }
   }
 
@@ -54,7 +51,7 @@ public class BioJsHTMLOutput
     try
     {
       String outputFile = getOutputFile();
-      String jalviewAlignmentJson = JSONFile.getJSONData(av);
+      String jalviewAlignmentJson = JSONFile.getJSONData(ap);
       String bioJSTemplateString = getBioJsTemplateAsString();
       String generatedBioJsWithJalviewAlignmentAsJson = bioJSTemplateString
               .replaceAll(
index f9c717d..690e22a 100755 (executable)
@@ -20,6 +20,7 @@
  */
 package jalview.io;
 
+import jalview.api.AlignExportSettingI;
 import jalview.api.AlignViewportI;
 import jalview.util.MessageManager;
 
@@ -52,6 +53,10 @@ public class FileParse
   private AlignViewportI viewport;
 
   public int index = 1; // sequence counter for FileParse object created from
+  /**
+   * specific settings for exporting data from the current context
+   */
+  private AlignExportSettingI exportSettings;
 
   // same data source
 
@@ -501,4 +506,23 @@ public class FileParse
   {
     this.viewport = viewport;
   }
+
+  /**
+   * @return the currently configured exportSettings for writing data.
+   */
+  public AlignExportSettingI getExportSettings()
+  {
+    return exportSettings;
+  }
+
+  /**
+   * Set configuration for export of data.
+   * 
+   * @param exportSettings
+   *          the exportSettings to set
+   */
+  public void setExportSettings(AlignExportSettingI exportSettings)
+  {
+    this.exportSettings = exportSettings;
+  }
 }
index db34c2f..7e02118 100644 (file)
@@ -1,10 +1,9 @@
 package jalview.io;
 
+import jalview.api.FeatureRenderer;
 import jalview.datamodel.SequenceI;
 import jalview.gui.AlignViewport;
 import jalview.gui.AlignmentPanel;
-import jalview.gui.AnnotationPanel;
-import jalview.gui.FeatureRenderer;
 import jalview.gui.HTMLOptions;
 import jalview.math.AlignmentDimension;
 import jalview.util.MessageManager;
@@ -27,15 +26,12 @@ public class HtmlSvgOutput
   FeatureRenderer fr;
   AlignmentPanel ap;
 
-  AnnotationPanel annotationPanel;
 
   public HtmlSvgOutput(File file, AlignmentPanel ap)
   {
-
-      this.av = ap.av;
-      this.ap = ap;
-    av.setFeatureRenderer(new FeatureRenderer(ap));
-      this.annotationPanel = ap.getAnnotationPanel();
+    this.av = ap.av;
+    this.ap = ap;
+    fr = ap.cloneFeatureRenderer();
     generateHtmlSvgOutput(file);
   }
 
@@ -101,7 +97,7 @@ public class HtmlSvgOutput
 
       String titleSvgData = g1.getSVGDocument();
       String alignSvgData = g2.getSVGDocument();
-      String jsonData = JSONFile.getJSONData(av);
+      String jsonData = JSONFile.getJSONData(ap);
       String htmlData = getHtml(titleSvgData, alignSvgData, jsonData);
 
       out.write(htmlData.getBytes());
index bbbc122..20f1f94 100644 (file)
@@ -21,7 +21,7 @@
 
 package jalview.io;
 
-import jalview.api.AlignViewportI;
+import jalview.api.AlignmentViewPanel;
 import jalview.api.ComplexAlignFile;
 import jalview.api.FeatureRenderer;
 import jalview.api.FeaturesDisplayedI;
@@ -109,7 +109,6 @@ public class JSONFile extends AlignFile implements ComplexAlignFile
     parse(getReader());
 
   }
-
   @Override
   public String print()
   {
@@ -119,12 +118,8 @@ public class JSONFile extends AlignFile implements ComplexAlignFile
       AlignmentPojo jsonAlignmentPojo = new AlignmentPojo();
       if (getViewport() != null)
       {
-        globalColorScheme = ColourSchemeProperty
-                .getColourName(getViewport()
-                .getGlobalColourScheme());
-        setDisplayedFeatures(getViewport().getFeaturesDisplayed());
-        showSeqFeatures = getViewport().isShowSequenceFeatures();
-        fr = getViewport().getFeatureRenderer();
+        configureFromViewport();
+
       }
 
       int count = 0;
@@ -154,14 +149,14 @@ public class JSONFile extends AlignFile implements ComplexAlignFile
       if (hiddenSections != null)
       {
         if (hiddenSections[0] != null
-                && getViewport().getExportSettings()
+                && getExportSettings()
                         .isExportHiddenColumns())
         {
           jsonAlignmentPojo.getAppSettings().put("hiddenCols",
                   String.valueOf(hiddenSections[0]));
         }
         if (hiddenSections[1] != null
-                && getViewport().getExportSettings()
+                && getExportSettings()
                         .isExportHiddenSequences())
         {
           jsonAlignmentPojo.getAppSettings().put("hiddenSeqs",
@@ -169,19 +164,19 @@ public class JSONFile extends AlignFile implements ComplexAlignFile
         }
       }
 
-      if (getViewport().getExportSettings().isExportAnnotations())
+      if (getExportSettings().isExportAnnotations())
       {
         jsonAlignmentPojo
                 .setAlignAnnotation(annotationToJsonPojo(annotations));
       }
 
-      if (getViewport().getExportSettings().isExportFeatures())
+      if (getExportSettings().isExportFeatures())
       {
         jsonAlignmentPojo
                 .setSeqFeatures(sequenceFeatureToJsonPojo(seqs, fr));
       }
 
-      if (getViewport().getExportSettings().isExportGroups()
+      if (getExportSettings().isExportGroups()
               && seqGroups != null
               && seqGroups.size() > 0)
       {
@@ -600,21 +595,21 @@ public class JSONFile extends AlignFile implements ComplexAlignFile
     this.displayedFeatures = displayedFeatures;
   }
 
-
-  public static String getJSONData(AlignViewportI av)
+  public void configureForView(AlignmentViewPanel avpanel)
   {
-    JSONFile jsonFile = new JSONFile();
-    jsonFile.setViewport(av);
-    jsonFile.seqGroups = av.getAlignment().getGroups();
-    jsonFile.setDisplayedFeatures(av.getFeaturesDisplayed());
 
-    for (SequenceI seq : av.getAlignment().getSequences())
+    setViewport(avpanel.getAlignViewport());
+    seqGroups = avpanel.getAlignment().getGroups();
+    setDisplayedFeatures(getViewport().getFeaturesDisplayed());
+    fr = avpanel.cloneFeatureRenderer();
+
+    for (SequenceI seq : getViewport().getAlignment().getSequences())
     {
-      jsonFile.seqs.add(seq);
+      seqs.add(seq);
     }
   
     // Add non auto calculated annotation to AlignFile
-    for (AlignmentAnnotation annot : av.getAlignment()
+    for (AlignmentAnnotation annot : getViewport().getAlignment()
             .getAlignmentAnnotation())
     {
       if (annot != null && !annot.autoCalculated)
@@ -623,9 +618,27 @@ public class JSONFile extends AlignFile implements ComplexAlignFile
         {
           continue;
         }
-        jsonFile.annotations.add(annot);
+        annotations.add(annot);
       }
     }
+  }
+
+  public void configureFromViewport()
+  {
+    if (getViewport() == null)
+    {
+      return;
+    }
+    globalColorScheme = ColourSchemeProperty.getColourName(getViewport()
+            .getGlobalColourScheme());
+    setDisplayedFeatures(getViewport().getFeaturesDisplayed());
+    showSeqFeatures = getViewport().isShowSequenceFeatures();
+  }
+
+  public static String getJSONData(AlignmentViewPanel av)
+  {
+    JSONFile jsonFile = new JSONFile();
+    jsonFile.configureForView(av);
     String jsonString = jsonFile.print();
     return jsonString;
   }