Merge branch 'features/typed_annotations_calcId' into develop
authorJim Procter <jprocter@dundee.ac.uk>
Wed, 12 Nov 2014 12:41:52 +0000 (12:41 +0000)
committerJim Procter <jprocter@dundee.ac.uk>
Wed, 12 Nov 2014 12:41:52 +0000 (12:41 +0000)
1  2 
src/jalview/gui/AlignFrame.java
src/jalview/jbgui/GAlignFrame.java

@@@ -53,7 -53,6 +53,7 @@@ import jalview.datamodel.SequenceGroup
  import jalview.datamodel.SequenceI;
  import jalview.io.AlignmentProperties;
  import jalview.io.AnnotationFile;
 +import jalview.io.BioJsHTMLOutput;
  import jalview.io.FeaturesFile;
  import jalview.io.FileLoader;
  import jalview.io.FormatAdapter;
@@@ -280,7 -279,7 +280,7 @@@ public class AlignFrame extends GAlignF
    }
  
    /**
-    * Make a new AlignFrame from exisiting alignmentPanels
+    * Make a new AlignFrame from existing alignmentPanels
     * 
     * @param ap
     *          AlignmentPanel
      scaleRight.setVisible(av.wrapAlignment);
      annotationPanelMenuItem.setState(av.showAnnotation);
      /*
-      * Show/hide all annotations only enabled if annotation panel is shown
+      * Show/hide annotations only enabled if annotation panel is shown
       */
-     showAllAnnotations.setEnabled(annotationPanelMenuItem.getState());
-     hideAllAnnotations.setEnabled(annotationPanelMenuItem.getState());
+     showAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
+     hideAllSeqAnnotations.setEnabled(annotationPanelMenuItem.getState());
+     showAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
+     hideAllAlAnnotations.setEnabled(annotationPanelMenuItem.getState());
      viewBoxesMenuItem.setSelected(av.showBoxes);
      viewTextMenuItem.setSelected(av.showText);
      showNonconservedMenuItem.setSelected(av.getShowUnconserved());
              alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
    }
  
 +  @Override
 +  public void bioJSMenuItem_actionPerformed(ActionEvent e)
 +  {
 +    new BioJsHTMLOutput(alignPanel,
 +            alignPanel.seqPanel.seqCanvas.getSequenceRenderer(),
 +            alignPanel.seqPanel.seqCanvas.getFeatureRenderer());
 +  }
    public void createImageMap(File file, String image)
    {
      alignPanel.makePNGImageMap(file, image);
      final boolean setVisible = annotationPanelMenuItem.isSelected();
      viewport.setShowAnnotation(setVisible);
      alignPanel.setAnnotationVisible(setVisible);
-     this.showAllAnnotations.setEnabled(setVisible);
-     this.hideAllAnnotations.setEnabled(setVisible);
+     this.showAllSeqAnnotations.setEnabled(setVisible);
+     this.hideAllSeqAnnotations.setEnabled(setVisible);
+     this.showAllAlAnnotations.setEnabled(setVisible);
+     this.hideAllAlAnnotations.setEnabled(setVisible);
    }
  
    @Override
    }
  
    /**
-    * Action on selection of menu option to Show or Hide all annotations.
+    * Action on selection of menu options to Show or Hide annotations.
     * 
-    * @param visibile
+    * @param visible
+    * @param forSequences
+    *          update sequence-related annotations
+    * @param forAlignment
+    *          update non-sequence-related annotations
     */
    @Override
-   protected void setAllAnnotationsVisibility(boolean visible)
+   protected void setAnnotationsVisibility(boolean visible,
+           boolean forSequences, boolean forAlignment)
    {
      for (AlignmentAnnotation aa : alignPanel.getAlignment()
              .getAlignmentAnnotation())
      {
-       aa.visible = visible;
+       boolean apply = (aa.sequenceRef == null && forAlignment)
+               || (aa.sequenceRef != null && forSequences);
+       if (apply)
+       {
+         aa.visible = visible;
+       }
      }
      this.alignPanel.paintAlignment(true);
    }
+   /**
+    * Store selected annotation sort order for the view and repaint.
+    */
+   @Override
+   protected void sortAnnotations_actionPerformed()
+   {
+     this.alignPanel.av.setSortAnnotationsBy(getAnnotationSortOrder());
+     this.alignPanel.av
+             .setShowAutocalculatedAbove(isShowAutoCalculatedAbove());
+     alignPanel.paintAlignment(true);
+   }
  }
  
  class PrintThread extends Thread
   */
  package jalview.jbgui;
  
+ import jalview.analysis.AnnotationSorter.SequenceAnnotationOrder;
  import jalview.bin.Cache;
  import jalview.gui.JvSwingUtils;
+ import jalview.gui.Preferences;
  import jalview.schemes.ColourSchemeProperty;
  import jalview.util.MessageManager;
  
@@@ -65,6 -67,8 +67,8 @@@ public class GAlignFrame extends JInter
  
    protected JMenu viewMenu = new JMenu();
  
+   protected JMenu annotationsMenu = new JMenu();
    protected JMenu colourMenu = new JMenu();
  
    protected JMenu calculateMenu = new JMenu();
  
    JMenuItem createPNG = new JMenuItem();
  
 +  JMenuItem createBioJS = new JMenuItem();
 +
    protected JMenuItem font = new JMenuItem();
  
    public JCheckBoxMenuItem seqLimits = new JCheckBoxMenuItem();
  
    JMenuItem showAllhidden = new JMenuItem();
  
-   protected JMenuItem showAllAnnotations = new JMenuItem();
+   protected JMenuItem showAllSeqAnnotations = new JMenuItem();
+   protected JMenuItem hideAllSeqAnnotations = new JMenuItem();
+   protected JMenuItem showAllAlAnnotations = new JMenuItem();
+   protected JMenuItem hideAllAlAnnotations = new JMenuItem();
+   protected JCheckBoxMenuItem sortAnnBySequence = new JCheckBoxMenuItem();
  
-   protected JMenuItem hideAllAnnotations = new JMenuItem();
+   protected JCheckBoxMenuItem sortAnnByLabel = new JCheckBoxMenuItem();
  
    protected JCheckBoxMenuItem hiddenMarkers = new JCheckBoxMenuItem();
  
  
    protected JCheckBoxMenuItem applyAutoAnnotationSettings = new JCheckBoxMenuItem();
  
+   protected JRadioButtonMenuItem showAutoFirst = new JRadioButtonMenuItem();
+   protected JRadioButtonMenuItem showAutoLast = new JRadioButtonMenuItem();
    private JMenuItem grpsFromSelection = new JMenuItem();
  
+   private SequenceAnnotationOrder annotationSortOrder;
+   private boolean showAutoCalculatedAbove = false;
    public GAlignFrame()
    {
      try
      });
      editMenu.setText(MessageManager.getString("action.edit"));
      viewMenu.setText(MessageManager.getString("action.view"));
+     annotationsMenu.setText(MessageManager.getString("action.annotations"));
      colourMenu.setText(MessageManager.getString("action.colour"));
      calculateMenu.setText(MessageManager.getString("action.calculate"));
      webService.setText(MessageManager.getString("action.web_service"));
          annotationPanelMenuItem_actionPerformed(e);
        }
      });
-     /*
-      * Show/hide all annotations only enabled if annotation panel is shown
-      */
-     showAllAnnotations.setText(MessageManager
-             .getString("label.show_all_annotations"));
-     showAllAnnotations.setEnabled(annotationPanelMenuItem.getState());
-     showAllAnnotations.addActionListener(new ActionListener()
+     showAllAlAnnotations.setText(MessageManager
+             .getString("label.show_all_al_annotations"));
+     final boolean isAnnotationPanelShown = annotationPanelMenuItem
+             .getState();
+     showAllAlAnnotations.setEnabled(isAnnotationPanelShown);
+     showAllAlAnnotations.addActionListener(new ActionListener()
+     {
+       @Override
+       public void actionPerformed(ActionEvent e)
+       {
+         showAllAnnotations_actionPerformed(false, true);
+       }
+     });
+     hideAllAlAnnotations.setText(MessageManager
+             .getString("label.hide_all_al_annotations"));
+     hideAllAlAnnotations.setEnabled(isAnnotationPanelShown);
+     hideAllAlAnnotations.addActionListener(new ActionListener()
+     {
+       @Override
+       public void actionPerformed(ActionEvent e)
+       {
+         hideAllAnnotations_actionPerformed(false, true);
+       }
+     });
+     showAllSeqAnnotations.setText(MessageManager
+             .getString("label.show_all_seq_annotations"));
+     showAllSeqAnnotations.setEnabled(isAnnotationPanelShown);
+     showAllSeqAnnotations.addActionListener(new ActionListener()
+     {
+       @Override
+       public void actionPerformed(ActionEvent e)
+       {
+         showAllAnnotations_actionPerformed(true, false);
+       }
+     });
+     hideAllSeqAnnotations.setText(MessageManager
+             .getString("label.hide_all_seq_annotations"));
+     hideAllSeqAnnotations.setEnabled(isAnnotationPanelShown);
+     hideAllSeqAnnotations.addActionListener(new ActionListener()
+     {
+       @Override
+       public void actionPerformed(ActionEvent e)
+       {
+         hideAllAnnotations_actionPerformed(true, false);
+       }
+     });
+     SequenceAnnotationOrder sortAnnotationsBy = SequenceAnnotationOrder
+             .valueOf(Cache.getDefault(Preferences.SORT_ANNOTATIONS,
+                     SequenceAnnotationOrder.NONE.name()));
+     sortAnnBySequence.setText(MessageManager
+             .getString("label.sort_annotations_by_sequence"));
+     sortAnnBySequence
+             .setSelected(sortAnnotationsBy == SequenceAnnotationOrder.SEQUENCE_AND_LABEL);
+     sortAnnBySequence.addActionListener(new ActionListener()
      {
        @Override
        public void actionPerformed(ActionEvent e)
        {
-         showAllAnnotations_actionPerformed();
+         boolean newState = sortAnnBySequence.getState();
+         sortAnnByLabel.setSelected(false);
+         setAnnotationSortOrder(newState ? SequenceAnnotationOrder.SEQUENCE_AND_LABEL
+                 : SequenceAnnotationOrder.NONE);
+         sortAnnotations_actionPerformed();
        }
      });
-     hideAllAnnotations.setText(MessageManager
-             .getString("label.hide_all_annotations"));
-     hideAllAnnotations.setEnabled(annotationPanelMenuItem.getState());
-     hideAllAnnotations.addActionListener(new ActionListener()
+     sortAnnByLabel.setText(MessageManager
+             .getString("label.sort_annotations_by_label"));
+     sortAnnByLabel
+             .setSelected(sortAnnotationsBy == SequenceAnnotationOrder.LABEL_AND_SEQUENCE);
+     sortAnnByLabel.addActionListener(new ActionListener()
      {
        @Override
        public void actionPerformed(ActionEvent e)
        {
-         hideAllAnnotations_actionPerformed();
+         boolean newState = sortAnnByLabel.getState();
+         sortAnnBySequence.setSelected(false);
+         setAnnotationSortOrder(newState ? SequenceAnnotationOrder.LABEL_AND_SEQUENCE
+                 : SequenceAnnotationOrder.NONE);
+         sortAnnotations_actionPerformed();
        }
      });
      colourTextMenuItem.setText(MessageManager
          htmlMenuItem_actionPerformed(e);
        }
      });
 +
 +    // TODO uncomment when supported by MassageManager
 +    // createBioJS.setText(MessageManager.getString("label.biojs_html_export"));
 +    createBioJS.setText("BioJS");
 +    createBioJS.addActionListener(new java.awt.event.ActionListener()
 +    {
 +      @Override
 +      public void actionPerformed(ActionEvent e)
 +      {
 +        bioJSMenuItem_actionPerformed(e);
 +      }
 +    });
 +
      overviewMenuItem.setText(MessageManager
              .getString("label.overview_window"));
      overviewMenuItem.addActionListener(new java.awt.event.ActionListener()
      applyAutoAnnotationSettings.setVisible(true);
      applyAutoAnnotationSettings.addActionListener(new ActionListener()
      {
        @Override
        public void actionPerformed(ActionEvent e)
        {
          applyAutoAnnotationSettings_actionPerformed(e);
        }
+     });
  
+     ButtonGroup buttonGroup = new ButtonGroup();
+     buttonGroup.add(showAutoFirst);
+     buttonGroup.add(showAutoLast);
+     showAutoFirst.setText(MessageManager.getString("label.show_first"));
+     showAutoFirst.setSelected(Cache.getDefault(
+             Preferences.SHOW_AUTOCALC_ABOVE,
+             false));
+     showAutoFirst.addActionListener(new ActionListener()
+     {
+       @Override
+       public void actionPerformed(ActionEvent e)
+       {
+         setShowAutoCalculatedAbove(showAutoFirst.isSelected());
+         sortAnnotations_actionPerformed();
+       }
+     });
+     showAutoLast.setText(MessageManager.getString("label.show_last"));
+     showAutoLast.setSelected(!showAutoFirst.isSelected());
+     showAutoLast.addActionListener(new ActionListener()
+     {
+       @Override
+       public void actionPerformed(ActionEvent e)
+       {
+         setShowAutoCalculatedAbove(!showAutoLast.isSelected());
+         sortAnnotations_actionPerformed();
+       }
      });
  
      nucleotideColour.setText(MessageManager.getString("label.nucleotide"));
          font_actionPerformed(e);
        }
      });
 -
      seqLimits.setText(MessageManager
              .getString("label.show_sequence_limits"));
      seqLimits.setState(jalview.bin.Cache.getDefault("SHOW_JVSUFFIX", true));
      alignFrameMenuBar.add(editMenu);
      alignFrameMenuBar.add(selectMenu);
      alignFrameMenuBar.add(viewMenu);
+     alignFrameMenuBar.add(annotationsMenu);
      alignFrameMenuBar.add(formatMenu);
      alignFrameMenuBar.add(colourMenu);
      alignFrameMenuBar.add(calculateMenu);
      viewMenu.add(hideMenu);
      viewMenu.addSeparator();
      viewMenu.add(followHighlightMenuItem);
-     viewMenu.add(annotationPanelMenuItem);
-     viewMenu.add(showAllAnnotations);
-     viewMenu.add(hideAllAnnotations);
+     annotationsMenu.add(annotationPanelMenuItem);
+     annotationsMenu.addSeparator();
+     annotationsMenu.add(showAllAlAnnotations);
+     annotationsMenu.add(hideAllAlAnnotations);
+     annotationsMenu.addSeparator();
+     annotationsMenu.add(showAllSeqAnnotations);
+     annotationsMenu.add(hideAllSeqAnnotations);
+     annotationsMenu.add(sortAnnBySequence);
+     annotationsMenu.add(sortAnnByLabel);
+     annotationsMenu.addSeparator();
+     autoAnnMenu.add(showAutoFirst);
+     autoAnnMenu.add(showAutoLast);
+     autoAnnMenu.addSeparator();
      autoAnnMenu.add(applyAutoAnnotationSettings);
      autoAnnMenu.add(showConsensusHistogram);
      autoAnnMenu.add(showSequenceLogo);
      autoAnnMenu.addSeparator();
      autoAnnMenu.add(showGroupConservation);
      autoAnnMenu.add(showGroupConsensus);
-     viewMenu.add(autoAnnMenu);
+     annotationsMenu.add(autoAnnMenu);
      viewMenu.addSeparator();
      viewMenu.add(showSeqFeatures);
      // viewMenu.add(showSeqFeaturesHeight);
      jMenu2.add(htmlMenuItem);
      jMenu2.add(epsFile);
      jMenu2.add(createPNG);
 +    jMenu2.add(createBioJS);
      addSequenceMenu.add(addFromFile);
      addSequenceMenu.add(addFromText);
      addSequenceMenu.add(addFromURL);
    }
  
    /**
+    * Action on clicking sort annotations by type.
+    * 
+    * @param sortOrder
+    */
+   protected void sortAnnotations_actionPerformed()
+   {
+   }
+   /**
     * Action on clicking Show all annotations.
+    * 
+    * @param forSequences
+    *          update sequence-related annotations
+    * @param forAlignment
+    *          update non-sequence-related annotations
     */
-   protected void showAllAnnotations_actionPerformed()
+   protected void showAllAnnotations_actionPerformed(boolean forSequences,
+           boolean forAlignment)
    {
-     setAllAnnotationsVisibility(true);
+     setAnnotationsVisibility(true, forSequences, forAlignment);
    }
  
    /**
     * Action on clicking Hide all annotations.
+    * 
+    * @param forSequences
+    *          update sequence-related annotations
+    * @param forAlignment
+    *          update non-sequence-related annotations
     */
-   protected void hideAllAnnotations_actionPerformed()
+   protected void hideAllAnnotations_actionPerformed(boolean forSequences,
+           boolean forAlignment)
    {
-     setAllAnnotationsVisibility(false);
+     setAnnotationsVisibility(false, forSequences, forAlignment);
    }
  
    /**
-    * Set the visibility of all annotations to true or false.
+    * Set the visibility of annotations to true or false. Can act on
+    * sequence-related annotations, or alignment-related, or both.
     * 
     * @param visible
+    * @param forSequences
+    *          update sequence-related annotations
+    * @param forAlignment
+    *          update non-sequence-related annotations
     */
-   protected void setAllAnnotationsVisibility(boolean visible)
+   protected void setAnnotationsVisibility(boolean visible,
+           boolean forSequences, boolean forAlignment)
    {
  
    }
    {
    }
  
 +  protected void bioJSMenuItem_actionPerformed(ActionEvent e)
 +  {
 +
 +  }
 +
    protected void closeMenuItem_actionPerformed(boolean b)
    {
    }
      // TODO Auto-generated method stub
  
    }
+   protected boolean isShowAutoCalculatedAbove()
+   {
+     return showAutoCalculatedAbove;
+   }
+   protected void setShowAutoCalculatedAbove(boolean showAutoCalculatedAbove)
+   {
+     this.showAutoCalculatedAbove = showAutoCalculatedAbove;
+   }
+   protected SequenceAnnotationOrder getAnnotationSortOrder()
+   {
+     return annotationSortOrder;
+   }
+   protected void setAnnotationSortOrder(SequenceAnnotationOrder annotationSortOrder)
+   {
+     this.annotationSortOrder = annotationSortOrder;
+   }
  }