JAL-769
[jalview.git] / src / jalview / appletgui / AlignFrame.java
index 2fde9ad..f7cfba0 100755 (executable)
@@ -17,7 +17,6 @@
  */
 package jalview.appletgui;
 
-import java.io.*;
 import java.net.*;
 import java.util.*;
 
@@ -31,6 +30,7 @@ import jalview.commands.*;
 import jalview.datamodel.*;
 import jalview.io.*;
 import jalview.schemes.*;
+import jalview.structure.StructureSelectionManager;
 
 public class AlignFrame extends EmbmenuFrame implements ActionListener,
         ItemListener, KeyListener
@@ -70,6 +70,11 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 
     annotationPanelMenuItem.setState(viewport.showAnnotation);
     displayNonconservedMenuItem.setState(viewport.getShowunconserved());
+    followMouseOverFlag.setState(viewport.getFollowHighlight());
+    showGroupConsensus.setState(viewport.showGroupConsensus);
+    showGroupConservation.setState(viewport.showGroupConservation);
+    showConsensusHistogram.setState(viewport.showConsensusHistogram);
+    showSequenceLogo.setState(viewport.showSequenceLogo);
 
     seqLimits.setState(viewport.showJVSuffix);
 
@@ -135,6 +140,9 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     alignPanel.idPanel.idCanvas.addKeyListener(this);
     alignPanel.scalePanel.addKeyListener(this);
     alignPanel.annotationPanel.addKeyListener(this);
+    alignPanel.annotationPanelHolder.addKeyListener(this);
+    alignPanel.annotationSpaceFillerHolder.addKeyListener(this);
+    alignPanel.alabels.addKeyListener(this);
     createAlignFrameWindow(embedded, title);
     alignPanel.validate();
     alignPanel.paintAlignment(true);
@@ -166,7 +174,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
       featuresFile = new jalview.io.FeaturesFile(file, type)
               .parse(viewport.alignment,
                       alignPanel.seqPanel.seqCanvas.getFeatureRenderer().featureColours,
-                      featureLinks, true);
+                      featureLinks, true, viewport.applet.getDefaultParameter("relaxedidmatch", false));
     } catch (Exception ex)
     {
       ex.printStackTrace();
@@ -202,6 +210,8 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     {
     case 27: // escape key
       deselectAllSequenceMenuItem_actionPerformed();
+      
+      alignPanel.alabels.cancelDrag(); 
       break;
     case KeyEvent.VK_X:
       if (evt.isControlDown() || evt.isMetaDown())
@@ -597,7 +607,26 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     {
       mouseOverFlag_stateChanged();
     }
-
+    else if (evt.getSource() == showGroupConsensus)
+    {
+      showGroupConsensus_actionPerformed();
+    }
+    else if (evt.getSource() == showGroupConservation)
+    {
+      showGroupConservation_actionPerformed();
+    }
+    else if (evt.getSource() == showSequenceLogo)
+    {
+      showSequenceLogo_actionPerformed();
+    }
+    else if (evt.getSource() == showConsensusHistogram)
+    {
+      showConsensusHistogram_actionPerformed();
+    }
+    else if (evt.getSource() == applyAutoAnnotationSettings)
+    {
+      applyAutoAnnotationSettings_actionPerformed();
+    }
     alignPanel.paintAlignment(true);
   }
 
@@ -787,6 +816,26 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
       viewport.showAllHiddenSeqs();
       alignPanel.paintAlignment(true);
     }
+    else if (source == showGroupConsensus)
+    {
+      showGroupConsensus_actionPerformed();
+    }
+    else if (source == showGroupConservation)
+    {
+      showGroupConservation_actionPerformed();
+    }
+    else if (source == showSequenceLogo)
+    {
+      showSequenceLogo_actionPerformed();
+    }
+    else if (source == showConsensusHistogram)
+    {
+      showConsensusHistogram_actionPerformed();
+    }
+    else if (source == applyAutoAnnotationSettings)
+    {
+      applyAutoAnnotationSettings_actionPerformed();
+    }
     else if (source == featureSettings)
     {
       new FeatureSettings(alignPanel);
@@ -1641,6 +1690,56 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     viewport.sendSelection();
   }
 
+  /**
+   * group consensus toggled
+   * 
+   */
+  protected void showGroupConsensus_actionPerformed()
+  {
+    viewport.setShowGroupConsensus(showGroupConsensus.getState());
+    alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
+
+  }
+
+  /**
+   * group conservation toggled.
+   */
+  protected void showGroupConservation_actionPerformed()
+  {
+    viewport.setShowGroupConservation(showGroupConservation.getState());
+    alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
+  }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
+   * .event.ActionEvent)
+   */
+  protected void showConsensusHistogram_actionPerformed()
+  {
+    viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
+    alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
+  }
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
+   * .event.ActionEvent)
+   */
+  protected void showSequenceLogo_actionPerformed()
+  {
+    viewport.setShowSequenceLogo(showSequenceLogo.getState());
+    alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
+  }
+
+  protected void applyAutoAnnotationSettings_actionPerformed()
+  {
+    alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
+  }
+
   protected void makeGrpsFromSelection_actionPerformed()
   {
     if (viewport.getSelectionGroup() != null)
@@ -1668,7 +1767,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
           ;
       }
       PaintRefresher.Refresh(this, viewport.getSequenceSetId());
-      // alignPanel.updateAnnotation();
+      alignPanel.updateAnnotation();
       alignPanel.paintAlignment(true);
     }
   }
@@ -2371,7 +2470,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
             || (viewport.getSelectionGroup() == null && viewport.alignment
                     .getHeight() > 1))
     {
-      final TreePanel tp = new TreePanel(viewport, type, pwType);
+      final TreePanel tp = new TreePanel(alignPanel, type, pwType);
 
       addTreeMenuItem(tp, title);
 
@@ -2391,7 +2490,7 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
 
   public void loadTree(jalview.io.NewickFile tree, String treeFile)
   {
-    TreePanel tp = new TreePanel(viewport, treeFile, "From File - ", tree);
+    TreePanel tp = new TreePanel(alignPanel, treeFile, "From File - ", tree);
     jalview.bin.JalviewLite.addFrame(tp, treeFile, 600, 500);
     addTreeMenuItem(tp, treeFile);
   }
@@ -2453,7 +2552,22 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
       };
     });
   }
-
+  public boolean sortBy(AlignmentOrder alorder, String undoname)
+  {
+    SequenceI[] oldOrder = viewport.getAlignment()
+    .getSequencesArray();
+    if (viewport.applet.debug)
+    {
+      System.err.println("Sorting "+alorder.getOrder().size()+" in alignment '"+getTitle()+"'");
+    }
+    AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
+    if (undoname!=null)
+    {
+      addHistoryItem(new OrderCommand(undoname, oldOrder, viewport.alignment));
+    }
+    alignPanel.paintAlignment(true);
+    return true;
+  }
   protected void documentation_actionPerformed()
   {
     showURL("http://www.jalview.org/help.html", "HELP");
@@ -2741,8 +2855,14 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
   CheckboxMenuItem seqLimits = new CheckboxMenuItem();
 
   CheckboxMenuItem centreColumnLabelFlag = new CheckboxMenuItem();
-
+  
   CheckboxMenuItem followMouseOverFlag = new CheckboxMenuItem();
+  Menu autoAnnMenu=new Menu();
+  CheckboxMenuItem showSequenceLogo= new CheckboxMenuItem();
+  CheckboxMenuItem applyAutoAnnotationSettings = new CheckboxMenuItem();
+  CheckboxMenuItem showConsensusHistogram = new CheckboxMenuItem();
+  CheckboxMenuItem showGroupConsensus = new CheckboxMenuItem();
+  CheckboxMenuItem showGroupConservation = new CheckboxMenuItem();
 
   private void jbInit() throws Exception
   {
@@ -2946,6 +3066,14 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     hideAllButSelection.setLabel("All but Selected Region (Shift+Ctrl+H)");
     hideAllSelection.setLabel("Selected Region");
     showAllHidden.setLabel("All Sequences and Columns");
+    showGroupConsensus.setLabel("Group Consensus");
+    showGroupConservation.setLabel("Group Conservation");
+    showConsensusHistogram.setLabel("Show Consensus Histogram");
+    showSequenceLogo.setLabel("Show Consensus Logo");
+    applyAutoAnnotationSettings.setLabel("Apply to all groups");
+    applyAutoAnnotationSettings.setState(true);
+    autoAnnMenu.setLabel("Autocalculated Annotation");
+    
     invertColSel.addActionListener(this);
     showColumns.addActionListener(this);
     showSeqs.addActionListener(this);
@@ -2954,6 +3082,11 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     hideAllButSelection.addActionListener(this);
     hideAllSelection.addActionListener(this);
     showAllHidden.addActionListener(this);
+    showGroupConsensus.addItemListener(this);
+    showGroupConservation.addItemListener(this);
+    showConsensusHistogram.addItemListener(this);
+    showSequenceLogo.addItemListener(this);
+    applyAutoAnnotationSettings.addItemListener(this);
     formatMenu.setLabel("Format");
     selectMenu.setLabel("Select");
     newView.setLabel("New View");
@@ -3003,6 +3136,13 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
     viewMenu.addSeparator();
     viewMenu.add(followMouseOverFlag);
     viewMenu.add(annotationPanelMenuItem);
+    autoAnnMenu.add(applyAutoAnnotationSettings);
+    autoAnnMenu.add(showConsensusHistogram);
+    autoAnnMenu.add(showSequenceLogo);
+    autoAnnMenu.addSeparator();
+    autoAnnMenu.add(showGroupConservation);
+    autoAnnMenu.add(showGroupConsensus);
+    viewMenu.add(autoAnnMenu);
     viewMenu.addSeparator();
     viewMenu.add(sequenceFeatures);
     viewMenu.add(featureSettings);
@@ -3142,6 +3282,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
@@ -3338,6 +3495,12 @@ public class AlignFrame extends EmbmenuFrame implements ActionListener,
         return;
       }
     }
+    if (applet.useXtrnalSviewer)
+    {
+      // register the association(s) and quit, don't create any windows.
+      StructureSelectionManager.getStructureSelectionManager().setMapping(seqs, chains, pdb.getFile(), protocol);
+      return;
+    }
     if (applet.isAlignPdbStructures() && applet.jmolAvailable)
     {
       // can only do alignments with Jmol