eliminate utf8 compilation errors
[jalview.git] / src / jalview / appletgui / AlignFrame.java
index c5f37fd..1496595 100755 (executable)
@@ -1,5 +1,5 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.5)
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
  * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
  * 
  * This file is part of Jalview.
@@ -21,12 +21,9 @@ import java.io.*;
 import java.net.*;
 import java.util.*;
 
-import java.applet.Applet;
 import java.awt.*;
 import java.awt.event.*;
 
-import org.jmol.api.JmolViewer;
-
 import jalview.analysis.*;
 import jalview.api.SequenceStructureBinding;
 import jalview.bin.JalviewLite;
@@ -73,6 +70,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 
     annotationPanelMenuItem.setState(viewport.showAnnotation);
     displayNonconservedMenuItem.setState(viewport.getShowunconserved());
+    followMouseOverFlag.setState(viewport.getFollowHighlight());
 
     seqLimits.setState(viewport.showJVSuffix);
 
@@ -796,38 +794,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     }
     else if (source == alProperties)
     {
-      StringBuffer contents = new StringBuffer();
-
-      float avg = 0;
-      int min = Integer.MAX_VALUE, max = 0;
-      for (int i = 0; i < viewport.alignment.getHeight(); i++)
-      {
-        int size = viewport.alignment.getSequenceAt(i).getEnd()
-                - viewport.alignment.getSequenceAt(i).getStart();
-        avg += size;
-        if (size > max)
-          max = size;
-        if (size < min)
-          min = size;
-      }
-      avg = avg / (float) viewport.alignment.getHeight();
-
-      contents.append("\nSequences: " + viewport.alignment.getHeight());
-      contents.append("\nMinimum Sequence Length: " + min);
-      contents.append("\nMaximum Sequence Length: " + max);
-      contents.append("\nAverage Length: " + (int) avg);
-
-      if (((Alignment) viewport.alignment).alignmentProperties != null)
-      {
-        Hashtable props = ((Alignment) viewport.alignment).alignmentProperties;
-        Enumeration en = props.keys();
-        while (en.hasMoreElements())
-        {
-          String key = en.nextElement().toString();
-          contents.append("\n" + key + "\t" + props.get(key));
-        }
-      }
-
+      StringBuffer contents = new jalview.io.AlignmentProperties(
+              viewport.alignment).formatAsString();
       CutAndPasteTransfer cap = new CutAndPasteTransfer(false, this);
       cap.setText(contents.toString());
       Frame frame = new Frame();
@@ -1671,6 +1639,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     {
       this.setVisible(false);
     }
+    viewport.sendSelection();
   }
 
   protected void makeGrpsFromSelection_actionPerformed()
@@ -1725,6 +1694,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     viewport.setSelectionGroup(sg);
     alignPanel.paintAlignment(true);
     PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
+    viewport.sendSelection();
   }
 
   public void deselectAllSequenceMenuItem_actionPerformed()
@@ -1741,6 +1711,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
     alignPanel.paintAlignment(true);
     PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
+    viewport.sendSelection();
   }
 
   public void invertSequenceMenuItem_actionPerformed()
@@ -1752,6 +1723,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     }
 
     PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
+    viewport.sendSelection();
   }
 
   public void invertColSel_actionPerformed()
@@ -1759,6 +1731,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     viewport.invertColumnSelection();
     alignPanel.paintAlignment(true);
     PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
+    viewport.sendSelection();
   }
 
   void trimAlignment(boolean trimLeft)
@@ -2519,7 +2492,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
         g.drawString("Build date: " + builddate, x, y += fh);
         g.setFont(new Font("Helvetica", Font.PLAIN, 12));
         g.drawString(
-                "Authors:  Andrew Waterhouse, Jim Procter, Michele Clamp, James Cuff, Steve Searle,",
+                "Authors:  Jim Procter, Andrew Waterhouse, Michele Clamp, James Cuff, Steve Searle,",
                 x, y += fh * 1.5);
         g.drawString("David Martin & Geoff Barton.", x + 50, y += fh);
         g.drawString(
@@ -3170,6 +3143,23 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
               viewport.applet.getSize().height - embeddedMenu.HEIGHT
                       - statusBar.HEIGHT);
       viewport.applet.add(alignPanel, BorderLayout.CENTER);
+      final AlignFrame me = this;
+      viewport.applet.addFocusListener(new FocusListener()
+      {
+        
+        @Override
+        public void focusLost(FocusEvent e)
+        {
+          if (me.viewport.applet.currentAlignFrame==me) {
+                  me.viewport.applet.currentAlignFrame = null;
+        }}
+        
+        @Override
+        public void focusGained(FocusEvent e)
+        {
+          me.viewport.applet.currentAlignFrame = me;
+        }
+      });
       viewport.applet.validate();
     }
     else
@@ -3195,61 +3185,73 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
    * 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
+   * 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
-   * This method doesn't work. See http://issues.jalview.org/browse/JAL-621
-   * 
-  public SequenceStructureBinding addStructureViewInstance(Object jmolviewer, String[] sequenceIds)
+   */
+  public SequenceStructureBinding addStructureViewInstance(
+          Object jmolviewer, String[] sequenceIds)
   {
-    org.jmol.api.JmolViewer viewer=null;
-    try {
+    org.jmol.api.JmolViewer viewer = null;
+    try
+    {
       viewer = (org.jmol.api.JmolViewer) jmolviewer;
-    } 
-    catch (ClassCastException ex) {
-      System.err.println("Unsupported viewer object :"+jmolviewer.getClass());
+    } catch (ClassCastException ex)
+    {
+      System.err.println("Unsupported viewer object :"
+              + jmolviewer.getClass());
     }
-    if (viewer==null)
+    if (viewer == null)
     {
-      System.err.println("Can't use this object as a structure viewer:"+jmolviewer.getClass());
+      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)
+    SequenceI[] seqs = null;
+    if (sequenceIds == null || sequenceIds.length == 0)
     {
       seqs = viewport.getAlignment().getSequencesArray();
-    } else {
-      Vector sqi=new Vector();
+    }
+    else
+    {
+      Vector sqi = new Vector();
       AlignmentI al = viewport.getAlignment();
-      for (int sid=0;sid<sequenceIds.length;sid++) {
+      for (int sid = 0; sid < sequenceIds.length; sid++)
+      {
         SequenceI sq = al.findName(sequenceIds[sid]);
-        if (sq!=null) {
+        if (sq != null)
+        {
           sqi.addElement(sq);
         }
       }
-      if (sqi.size()>0) {
+      if (sqi.size() > 0)
+      {
         seqs = new SequenceI[sqi.size()];
-        for (int sid=0,sSize=sqi.size();sid<sSize;sid++)
+        for (int sid = 0, sSize = sqi.size(); sid < sSize; sid++)
         {
           seqs[sid] = (SequenceI) sqi.elementAt(sid);
         }
-      } else {
+      }
+      else
+      {
         return null;
       }
     }
-    ExtJmol jmv=null;
+    ExtJmol jmv = null;
     // TODO: search for a jmv that involves viewer
-    if (jmv==null){
-      // create a new viewer/jalview binding.
-      jmv = new ExtJmol(viewer, alignPanel, seqs);
+    if (jmv == null)
+    { // create a new viewer/jalview binding.
+      jmv = new ExtJmol(viewer, alignPanel, new SequenceI[][] {seqs});
     }
     return jmv;
-    
+
   }
-   **/
+
   public boolean addPdbFile(String sequenceId, String pdbEntryString,
           String pdbFile)
   {
@@ -3292,14 +3294,17 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
       if (needtoadd)
       {
         // make a note of the access mode and add
-        if (pdbentry.getProperty()==null)
-          {pdbentry.setProperty(new Hashtable());}
+        if (pdbentry.getProperty() == null)
+        {
+          pdbentry.setProperty(new Hashtable());
+        }
         pdbentry.getProperty().put("protocol", protocol);
         toaddpdb.addPDBId(pdbentry);
       }
     }
     return true;
   }
+
   private Object[] cleanSeqChainArrays(SequenceI[] seqs, String[] chains)
   {
     if (seqs != null)
@@ -3309,7 +3314,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
       {
         if (seqs[i] != null)
         {
-          sequences.addElement(new Object[] { seqs[i], (chains!=null) ? chains[i] : null});
+          sequences.addElement(new Object[]
+          { seqs[i], (chains != null) ? chains[i] : null });
         }
       }
       seqs = new SequenceI[sequences.size()];
@@ -3322,9 +3328,11 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
         chains[i] = (String) oj[1];
       }
     }
-    return new Object[] { seqs, chains};
+    return new Object[]
+    { seqs, chains };
 
   }
+
   public void newStructureView(JalviewLite applet, PDBEntry pdb,
           SequenceI[] seqs, String[] chains, String protocol)
   {
@@ -3364,9 +3372,10 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
           break;
         }
       }
-      if (ajm!=null)
+      if (ajm != null)
       {
-        System.err.println("Incremental adding and aligning structure to existing Jmol view not yet implemented.");
+        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;
@@ -3393,4 +3402,14 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     // TODO Auto-generated method stub
     System.err.println("Aligned Structure View: Not yet implemented.");
   }
+
+  /**
+   * modify the current selection, providing the user has not made a selection already.
+   * @param sel - sequences from this alignment 
+   * @param csel - columns to be selected on the alignment
+   */
+  public void select(SequenceGroup sel, ColumnSelection csel)
+  {
+    alignPanel.seqPanel.selection(sel, csel, null);
+  }
 }