JAL-1807
[jalview.git] / src / jalview / appletgui / AlignFrame.java
index 1fd4231..5d3f33c 100644 (file)
@@ -52,7 +52,9 @@ import jalview.io.AnnotationFile;
 import jalview.io.AppletFormatAdapter;
 import jalview.io.FeaturesFile;
 import jalview.io.NewickFile;
+import jalview.io.AlignFile;
 import jalview.io.TCoffeeScoreFile;
+import jalview.jsdev.GenericFileAdapter;
 import jalview.schemes.Blosum62ColourScheme;
 import jalview.schemes.BuriedColourScheme;
 import jalview.schemes.ClustalxColourScheme;
@@ -77,17 +79,10 @@ import jalview.util.MessageManager;
 import jalview.viewmodel.AlignmentViewport;
 
 import java.awt.BorderLayout;
-import java.awt.Canvas;
-import java.awt.CheckboxMenuItem;
 import java.awt.Color;
 import java.awt.Font;
 import java.awt.FontMetrics;
-import java.awt.Frame;
 import java.awt.Graphics;
-import java.awt.Label;
-import java.awt.Menu;
-import java.awt.MenuBar;
-import java.awt.MenuItem;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.FocusEvent;
@@ -110,7 +105,15 @@ import java.util.Map;
 import java.util.StringTokenizer;
 import java.util.Vector;
 
-import org.jmol.viewer.Viewer;
+import awt2swing.Canvas;
+import awt2swing.CheckboxMenuItem;
+import awt2swing.Frame;
+import awt2swing.Label;
+import awt2swing.Menu;
+import awt2swing.MenuBar;
+import awt2swing.MenuItem;
+
+//import org.jmol.viewer.Viewer;
 
 public class AlignFrame extends EmbmenuFrame implements ActionListener,
         ItemListener, KeyListener, AlignViewControllerGuiI
@@ -401,7 +404,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
         viewport.featureSettings.refreshTable();
       }
       alignPanel.paintAlignment(true);
-      statusBar.setText(MessageManager
+      setStatus(MessageManager
               .getString("label.successfully_added_features_alignment"));
     }
     return featuresFile;
@@ -556,7 +559,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 
     case KeyEvent.VK_F2:
       viewport.cursorMode = !viewport.cursorMode;
-      statusBar.setText(MessageManager.formatMessage(
+      setStatus(MessageManager.formatMessage(
               "label.keyboard_editing_mode", new String[]
               { (viewport.cursorMode ? "on" : "off") }));
       if (viewport.cursorMode)
@@ -2278,7 +2281,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
                 viewport.getSelectionGroup());
       }
 
-      statusBar.setText(MessageManager.formatMessage(
+      setStatus(MessageManager.formatMessage(
               "label.removed_columns", new String[]
               { Integer.valueOf(trimRegion.getSize()).toString() }));
       addHistoryItem(trimRegion);
@@ -2320,7 +2323,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 
     addHistoryItem(removeGapCols);
 
-    statusBar.setText(MessageManager.formatMessage(
+    setStatus(MessageManager.formatMessage(
             "label.removed_empty_columns", new String[]
             { Integer.valueOf(removeGapCols.getSize()).toString() }));
 
@@ -2926,7 +2929,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
       }
 
       @Override
-      public void paint(Graphics g)
+      public void paintComponent(Graphics g)
       {
         g.setColor(Color.white);
         g.fillRect(0, 0, getSize().width, getSize().height);
@@ -2934,7 +2937,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
         FontMetrics fm = g.getFontMetrics();
         int fh = fm.getHeight();
         int y = 5, x = 7;
-        g.setColor(Color.black);
+        g.setColor(Color.black); 
         // TODO: update this text for each release or centrally store it for
         // lite and application
         g.setFont(new Font("Helvetica", Font.BOLD, 14));
@@ -3054,7 +3057,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 
   BorderLayout borderLayout1 = new BorderLayout();
 
-  public Label statusBar = new Label();
+  Label statusBar = new Label();
 
   MenuItem clustalColour = new MenuItem();
 
@@ -3727,11 +3730,11 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
      */
     statusBar.setBackground(Color.white);
     statusBar.setFont(new java.awt.Font("Verdana", 0, 11));
-    statusBar.setText(MessageManager.getString("label.status_bar"));
+    setStatus(MessageManager.getString("label.status_bar"));
     this.add(statusBar, BorderLayout.SOUTH);
   }
 
-  public void setStatus(String string)
+       public void setStatus(String string)
   {
     statusBar.setText(string);
   };
@@ -3860,77 +3863,77 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     theApplet.validate();
   }
 
-  /**
-   * create a new binding between structures in an existing jmol viewer instance
-   * and an alignpanel with sequences that have existing PDBFile entries. Note,
-   * this does not open a new Jmol window, or modify the display of the
-   * structures in the original jmol window. Note This method doesn't work
-   * without an additional javascript library to exchange messages between the
-   * distinct applets. See http://issues.jalview.org/browse/JAL-621
-   * 
-   * @param viewer
-   *          JmolViewer instance
-   * @param sequenceIds
-   *          - sequence Ids to search for associations
-   */
-  public SequenceStructureBinding addStructureViewInstance(
-          Object jmolviewer, String[] sequenceIds)
-  {
-    Viewer viewer = null;
-    try
-    {
-      viewer = (Viewer) jmolviewer;
-    } catch (ClassCastException ex)
-    {
-      System.err.println("Unsupported viewer object :"
-              + jmolviewer.getClass());
-    }
-    if (viewer == null)
-    {
-      System.err.println("Can't use this object as a structure viewer:"
-              + jmolviewer.getClass());
-      return null;
-    }
-    SequenceI[] seqs = null;
-    if (sequenceIds == null || sequenceIds.length == 0)
-    {
-      seqs = viewport.getAlignment().getSequencesArray();
-    }
-    else
-    {
-      Vector sqi = new Vector();
-      AlignmentI al = viewport.getAlignment();
-      for (int sid = 0; sid < sequenceIds.length; sid++)
-      {
-        SequenceI sq = al.findName(sequenceIds[sid]);
-        if (sq != null)
-        {
-          sqi.addElement(sq);
-        }
-      }
-      if (sqi.size() > 0)
-      {
-        seqs = new SequenceI[sqi.size()];
-        for (int sid = 0, sSize = sqi.size(); sid < sSize; sid++)
-        {
-          seqs[sid] = (SequenceI) sqi.elementAt(sid);
-        }
-      }
-      else
-      {
-        return null;
-      }
-    }
-    AAStructureBindingModel jmv = null;
-    // TODO: search for a jmv that involves viewer
-    if (jmv == null)
-    { // create a new viewer/jalview binding.
-      jmv = new ExtJmol(viewer, alignPanel, new SequenceI[][]
-      { seqs });
-    }
-    return jmv;
-
-  }
+       /**
+        * create a new binding between structures in an existing jmol viewer instance
+        * and an alignpanel with sequences that have existing PDBFile entries. Note,
+        * this does not open a new Jmol window, or modify the display of the
+        * structures in the original jmol window. Note This method doesn't work
+        * without an additional javascript library to exchange messages between the
+        * distinct applets. See http://issues.jalview.org/browse/JAL-621
+        * 
+        * @param viewer
+        *          JmolViewer instance
+        * @param sequenceIds
+        *          - sequence Ids to search for associations
+        */
+       public SequenceStructureBinding addStructureViewInstance(Object jmolviewer,
+                       String[] sequenceIds) {
+               return null;
+               // Viewer viewer = null;
+               // try
+               // {
+               // viewer = (Viewer) jmolviewer;
+               // } catch (ClassCastException ex)
+               // {
+               // System.err.println("Unsupported viewer object :"
+               // + jmolviewer.getClass());
+               // }
+               // if (viewer == null)
+               // {
+               // System.err.println("Can't use this object as a structure viewer:"
+               // + jmolviewer.getClass());
+               // return null;
+               // }
+               // SequenceI[] seqs = null;
+               // if (sequenceIds == null || sequenceIds.length == 0)
+               // {
+               // seqs = viewport.getAlignment().getSequencesArray();
+               // }
+               // else
+               // {
+               // Vector sqi = new Vector();
+               // AlignmentI al = viewport.getAlignment();
+               // for (int sid = 0; sid < sequenceIds.length; sid++)
+               // {
+               // SequenceI sq = al.findName(sequenceIds[sid]);
+               // if (sq != null)
+               // {
+               // sqi.addElement(sq);
+               // }
+               // }
+               // if (sqi.size() > 0)
+               // {
+               // seqs = new SequenceI[sqi.size()];
+               // for (int sid = 0, sSize = sqi.size(); sid < sSize; sid++)
+               // {
+               // seqs[sid] = (SequenceI) sqi.elementAt(sid);
+               // }
+               // }
+               // else
+               // {
+               // return null;
+               // }
+               // }
+               // AAStructureBindingModel jmv = null;
+               // // TODO: search for a jmv that involves viewer
+               // if (jmv == null)
+               // { // create a new viewer/jalview binding.
+               // jmv = new ExtJmol(viewer, alignPanel, new SequenceI[][]
+               // { seqs });
+               // }
+               // return jmv;
+               //
+       }
 
   /**
    * bind a pdb file to a sequence in the current view
@@ -4028,78 +4031,67 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 
   }
 
-  public void newStructureView(JalviewLite applet, PDBEntry pdb,
-          SequenceI[] seqs, String[] chains, String protocol)
-  {
-    // Scrub any null sequences from the array
-    Object[] sqch = cleanSeqChainArrays(seqs, chains);
-    seqs = (SequenceI[]) sqch[0];
-    chains = (String[]) sqch[1];
-    if (seqs == null || seqs.length == 0)
-    {
-      System.err
-              .println("JalviewLite.AlignFrame:newStructureView: No sequence to bind structure to.");
-    }
-    if (protocol == null || protocol.trim().length() == 0
-            || protocol.equals("null"))
-    {
-      protocol = (String) pdb.getProperty().get("protocol");
-      if (protocol == null)
-      {
-        System.err.println("Couldn't work out protocol to open structure: "
-                + pdb.getId());
-        return;
-      }
-    }
-    if (applet.useXtrnalSviewer)
-    {
-      // register the association(s) and quit, don't create any windows.
-      if (StructureSelectionManager.getStructureSelectionManager(applet)
-              .setMapping(seqs, chains, pdb.getFile(), protocol) == null)
-      {
-        System.err.println("Failed to map " + pdb.getFile() + " ("
-                + protocol + ") to any sequences");
-      }
-      return;
-    }
-    if (applet.isAlignPdbStructures() && applet.jmolAvailable)
-    {
-      // can only do alignments with Jmol
-      // find the last jmol window assigned to this alignment
-      AppletJmol ajm = null, tajm;
-      Vector jmols = applet
-.getAppletWindow(AppletJmol.class);
-      for (int i = 0, iSize = jmols.size(); i < iSize; i++)
-      {
-        tajm = (AppletJmol) jmols.elementAt(i);
-        if (tajm.ap.alignFrame == this)
-        {
-          ajm = tajm;
-          break;
-        }
-      }
-      if (ajm != null)
-      {
-        System.err
-                .println("Incremental adding and aligning structure to existing Jmol view not yet implemented.");
-        // try and add the pdb structure
-        // ajm.addS
-        ajm = null;
-      }
-    }
-    // otherwise, create a new window
-    if (applet.jmolAvailable)
-    {
-      new AppletJmol(pdb, seqs, chains, alignPanel, protocol);
-      applet.lastFrameX += 40;
-      applet.lastFrameY += 40;
-    }
-    else
-    {
-      new MCview.AppletPDBViewer(pdb, seqs, chains, alignPanel, protocol);
-    }
-
-  }
+       public void newStructureView(JalviewLite applet, PDBEntry pdb,
+                       SequenceI[] seqs, String[] chains, String protocol) {
+               // Scrub any null sequences from the array
+               Object[] sqch = cleanSeqChainArrays(seqs, chains);
+               seqs = (SequenceI[]) sqch[0];
+               chains = (String[]) sqch[1];
+               if (seqs == null || seqs.length == 0) {
+                       System.err
+                                       .println("JalviewLite.AlignFrame:newStructureView: No sequence to bind structure to.");
+               }
+               if (protocol == null || protocol.trim().length() == 0
+                               || protocol.equals("null")) {
+                       protocol = (String) pdb.getProperty().get("protocol");
+                       if (protocol == null) {
+                               System.err.println("Couldn't work out protocol to open structure: "
+                                               + pdb.getId());
+                               return;
+                       }
+               }
+               if (applet.useXtrnalSviewer) {
+                       // register the association(s) and quit, don't create any windows.
+                       if (StructureSelectionManager.getStructureSelectionManager(applet)
+                                       .setMapping(seqs, chains, pdb.getFile(), protocol) == null) {
+                               System.err.println("Failed to map " + pdb.getFile() + " (" + protocol
+                                               + ") to any sequences");
+                       }
+                       return;
+               }
+               if (applet.isAlignPdbStructures() && applet.jmolAvailable) {
+                       // can only do alignments with Jmol
+                       // find the last jmol window assigned to this alignment
+                       AppletJmol ajm = null, tajm;
+                       Vector jmols = applet.getAppletWindow(AppletJmol.class);
+                       for (int i = 0, iSize = jmols.size(); i < iSize; i++) {
+                               tajm = (AppletJmol) jmols.elementAt(i);
+                               if (tajm.ap.alignFrame == this) {
+                                       ajm = tajm;
+                                       break;
+                               }
+                       }
+                       if (ajm != null) {
+                               System.err
+                                               .println("Incremental adding and aligning structure to existing Jmol view not yet implemented.");
+                               // try and add the pdb structure
+                               // ajm.addS
+                               ajm = null;
+                       }
+               }
+               // otherwise, create a new window
+               // if (applet.jmolAvailable)
+               // {
+               new AppletJmol(pdb, seqs, chains, alignPanel, protocol);
+               applet.lastFrameX += 40;
+               applet.lastFrameY += 40;
+               // }
+               // else
+               // {
+               // new MCview.AppletPDBViewer(pdb, seqs, chains, alignPanel, protocol);
+               // }
+
+       }
 
   public void alignedStructureView(JalviewLite applet, PDBEntry[] pdb,
           SequenceI[][] seqs, String[][] chains, String[] protocols)
@@ -4148,22 +4140,22 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   /**
    * Load the (T-Coffee) score file from the specified url
    * 
-   * @param source
+   * @param inFile
    *          File/URL/T-COFFEE score file contents
    * @throws IOException
    * @return true if alignment was annotated with data from source
    */
-  public boolean loadScoreFile(String source) throws IOException
+  public boolean loadScoreFile(String inFile) throws IOException
   {
 
-    TCoffeeScoreFile file = new TCoffeeScoreFile(source,
-            AppletFormatAdapter.checkProtocol(source));
+    TCoffeeScoreFile file = (TCoffeeScoreFile) GenericFileAdapter.getFile("TCoffeeScoreFile", inFile, 
+            AppletFormatAdapter.checkProtocol(inFile));        
     if (!file.isValid())
     {
       // TODO: raise dialog for gui
       System.err.println("Problems parsing T-Coffee scores: "
               + file.getWarningMessage());
-      System.err.println("Origin was:\n" + source);
+      System.err.println("Origin was:\n" + inFile);
       return false;
     }