JAL-1667 updated test and internationalization messages
[jalview.git] / src / jalview / gui / PopupMenu.java
index 4cc3d6a..0a40af7 100644 (file)
@@ -29,6 +29,7 @@ import jalview.commands.EditCommand.Action;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.AlignmentI;
 import jalview.datamodel.Annotation;
+import jalview.datamodel.ColumnSelection;
 import jalview.datamodel.DBRefEntry;
 import jalview.datamodel.PDBEntry;
 import jalview.datamodel.Sequence;
@@ -140,6 +141,8 @@ public class PopupMenu extends JPopupMenu
   JMenuItem sequenceDetails = new JMenuItem();
 
   JMenuItem sequenceSelDetails = new JMenuItem();
+  
+  JMenuItem makeReferenceSeq = new JMenuItem();
 
   JMenuItem chooseAnnotations = new JMenuItem();
 
@@ -209,7 +212,7 @@ public class PopupMenu extends JPopupMenu
 
   JMenu jMenu1 = new JMenu();
 
-  JMenu structureMenu = new JMenu();
+  JMenuItem structureMenu = new JMenuItem();
 
   JMenu viewStructureMenu = new JMenu();
 
@@ -220,6 +223,8 @@ public class PopupMenu extends JPopupMenu
 
   JMenu groupLinksMenu;
 
+  JMenuItem hideInsertions = new JMenuItem();
+
   /**
    * Creates a new PopupMenu object.
    * 
@@ -322,6 +327,12 @@ public class PopupMenu extends JPopupMenu
     if (seq != null)
     {
       sequenceMenu.setText(sequence.getName());
+      if (seq == ap.av.getAlignment().getSeqrep())
+      {
+        makeReferenceSeq.setText("Unmark representative");
+      } else {
+        makeReferenceSeq.setText("Mark as representative");
+      }
 
       if (seq.getDatasetSequence().getPDBId() != null
               && seq.getDatasetSequence().getPDBId().size() > 0)
@@ -369,7 +380,6 @@ public class PopupMenu extends JPopupMenu
         }
         // structureMenu.remove(colStructureMenu);
       }
-
       if (ap.av.getAlignment().isNucleotide() == true)
       {
         AlignmentAnnotation[] aa = ap.av.getAlignment()
@@ -441,7 +451,6 @@ public class PopupMenu extends JPopupMenu
             }
           }
         }
-
       }
 
       menuItem = new JMenuItem(
@@ -630,50 +639,50 @@ public class PopupMenu extends JPopupMenu
                 new PDBEntry[pdbe.size()]), pr = reppdb.values().toArray(
                 new PDBEntry[reppdb.size()]);
         final JMenuItem gpdbview, rpdbview;
-        if (pdbe.size() == 1)
-        {
-          structureMenu.add(gpdbview = new JMenuItem(MessageManager
-                  .formatMessage("label.view_structure_for", new String[]
-                  { sqass.getDisplayId(false) })));
-        }
-        else
-        {
-          structureMenu.add(gpdbview = new JMenuItem(MessageManager
-                  .formatMessage("label.view_all_structures", new String[]
-                  { new Integer(pdbe.size()).toString() })));
-        }
-        gpdbview.setToolTipText(MessageManager
-                .getString("label.open_new_jmol_view_with_all_structures_associated_current_selection_superimpose_using_alignment"));
-        gpdbview.addActionListener(new ActionListener()
-        {
-
-          @Override
-          public void actionPerformed(ActionEvent e)
-          {
-            new StructureViewer(ap.getStructureSelectionManager())
-                    .viewStructures(ap, pe, ap.av.collateForPDB(pe));
-          }
-        });
-        if (reppdb.size() > 1 && reppdb.size() < pdbe.size())
-        {
-          structureMenu.add(rpdbview = new JMenuItem(MessageManager
-                  .formatMessage(
-                          "label.view_all_representative_structures",
-                          new String[]
-                          { new Integer(reppdb.size()).toString() })));
-          rpdbview.setToolTipText(MessageManager
-                  .getString("label.open_new_jmol_view_with_all_representative_structures_associated_current_selection_superimpose_using_alignment"));
-          rpdbview.addActionListener(new ActionListener()
-          {
-
-            @Override
-            public void actionPerformed(ActionEvent e)
-            {
-              new StructureViewer(ap.getStructureSelectionManager())
-                      .viewStructures(ap, pr, ap.av.collateForPDB(pr));
-            }
-          });
-        }
+        // if (pdbe.size() == 1)
+        // {
+        // structureMenu.add(gpdbview = new JMenuItem(MessageManager
+        // .formatMessage("label.view_structure_for", new String[]
+        // { sqass.getDisplayId(false) })));
+        // }
+        // else
+        // {
+        // structureMenu.add(gpdbview = new JMenuItem(MessageManager
+        // .formatMessage("label.view_all_structures", new String[]
+        // { new Integer(pdbe.size()).toString() })));
+        // }
+        // gpdbview.setToolTipText(MessageManager
+        // .getString("label.open_new_jmol_view_with_all_structures_associated_current_selection_superimpose_using_alignment"));
+        // gpdbview.addActionListener(new ActionListener()
+        // {
+        //
+        // @Override
+        // public void actionPerformed(ActionEvent e)
+        // {
+        // new StructureViewer(ap.getStructureSelectionManager())
+        // .viewStructures(ap, pe, ap.av.collateForPDB(pe));
+        // }
+        // });
+        // if (reppdb.size() > 1 && reppdb.size() < pdbe.size())
+        // {
+        // structureMenu.add(rpdbview = new JMenuItem(MessageManager
+        // .formatMessage(
+        // "label.view_all_representative_structures",
+        // new String[]
+        // { new Integer(reppdb.size()).toString() })));
+        // rpdbview.setToolTipText(MessageManager
+        // .getString("label.open_new_jmol_view_with_all_representative_structures_associated_current_selection_superimpose_using_alignment"));
+        // rpdbview.addActionListener(new ActionListener()
+        // {
+        //
+        // @Override
+        // public void actionPerformed(ActionEvent e)
+        // {
+        // new StructureViewer(ap.getStructureSelectionManager())
+        // .viewStructures(ap, pr, ap.av.collateForPDB(pr));
+        // }
+        // });
+        // }
       }
     }
     else
@@ -1493,7 +1502,23 @@ public class PopupMenu extends JPopupMenu
       }
     });
     jMenu1.setText(MessageManager.getString("label.group"));
-    structureMenu.setText(MessageManager.getString("label.structure"));
+    // structureMenu.setText(MessageManager.getString("label.structure"));
+    structureMenu.setText(MessageManager.getString("label.view_structure"));
+    structureMenu.addActionListener(new ActionListener()
+    {
+      @Override
+      public void actionPerformed(ActionEvent actionEvent)
+      {
+        SequenceI[] selectedSeqs = new SequenceI[]
+        { sequence };
+        if (ap.av.getSelectionGroup() != null)
+        {
+          selectedSeqs = ap.av.getSequenceSelection();
+        }
+        new StructureChooser(selectedSeqs, sequence, ap);
+      }
+    });
+
     viewStructureMenu.setText(MessageManager
             .getString("label.view_structure"));
     // colStructureMenu.setText("Colour By Structure");
@@ -1507,7 +1532,28 @@ public class PopupMenu extends JPopupMenu
         editSequence_actionPerformed(actionEvent);
       }
     });
+    makeReferenceSeq.setText(MessageManager
+            .getString("label.mark_as_representative"));
+    makeReferenceSeq.addActionListener(new ActionListener()
+    {
+      
+      @Override
+      public void actionPerformed(ActionEvent actionEvent)
+      {
+        makeReferenceSeq_actionPerformed(actionEvent);
+        
+      }
+    });
+    hideInsertions.setText(MessageManager.getString("label.hide_insertions"));
+    hideInsertions.addActionListener(new ActionListener()
+    {
 
+      @Override
+      public void actionPerformed(ActionEvent e)
+      {
+        hideInsertions_actionPerformed(e);
+      }
+    });
     /*
      * annotationMenuItem.setText("By Annotation");
      * annotationMenuItem.addActionListener(new ActionListener() { public void
@@ -1517,7 +1563,11 @@ public class PopupMenu extends JPopupMenu
     groupMenu.add(sequenceSelDetails);
     add(groupMenu);
     add(sequenceMenu);
-    this.add(structureMenu);
+    add(structureMenu);
+    if (sequence!=null)
+    {
+      add(hideInsertions);
+    }
     // annotations configuration panel suppressed for now
     // groupMenu.add(chooseAnnotations);
 
@@ -1539,6 +1589,7 @@ public class PopupMenu extends JPopupMenu
     groupMenu.add(jMenu1);
     sequenceMenu.add(sequenceName);
     sequenceMenu.add(sequenceDetails);
+    sequenceMenu.add(makeReferenceSeq);
     colourMenu.add(textColour);
     colourMenu.add(noColourmenuItem);
     colourMenu.add(clustalColour);
@@ -1605,8 +1656,8 @@ public class PopupMenu extends JPopupMenu
     jMenu1.add(showColourText);
     jMenu1.add(outline);
     jMenu1.add(displayNonconserved);
-    structureMenu.add(pdbMenu);
-    structureMenu.add(viewStructureMenu);
+    // structureMenu.add(pdbMenu);
+    // structureMenu.add(viewStructureMenu);
     // structureMenu.add(colStructureMenu);
     noColourmenuItem.setText(MessageManager.getString("label.none"));
     noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
@@ -1913,6 +1964,43 @@ public class PopupMenu extends JPopupMenu
     refresh();
   }
 
+  protected void makeReferenceSeq_actionPerformed(ActionEvent actionEvent)
+  {
+    if (!ap.av.getAlignment().hasSeqrep())
+    {
+      // initialise the display flags so the user sees something happen
+      ap.av.setDisplayReferenceSeq(true);
+      ap.av.setColourByReferenceSeq(true);
+      ap.av.getAlignment().setSeqrep(sequence);
+    }
+    else
+    {
+      if (ap.av.getAlignment().getSeqrep() == sequence)
+      {
+        ap.av.getAlignment().setSeqrep(null);
+      }
+      else
+      {
+        ap.av.getAlignment().setSeqrep(sequence);
+      }
+    }
+    refresh();
+  }
+
+  protected void hideInsertions_actionPerformed(ActionEvent actionEvent)
+  {
+    if (sequence != null)
+    {
+      ColumnSelection cs = ap.av.getColumnSelection();
+      if (cs == null)
+      {
+        cs = new ColumnSelection();
+      }
+      cs.hideInsertionsFor(sequence);
+      ap.av.setColumnSelection(cs);
+    }
+    refresh();
+  }
   protected void sequenceSelectionDetails_actionPerformed()
   {
     createSequenceDetailsReport(ap.av.getSequenceSelection());
@@ -1943,16 +2031,18 @@ public class PopupMenu extends JPopupMenu
                       true,
                       true,
                       false,
-                      (ap.getSeqPanel().seqCanvas.fr != null) ? ap.getSeqPanel().seqCanvas.fr.minmax
+                      (ap.getSeqPanel().seqCanvas.fr != null) ? ap
+                              .getSeqPanel().seqCanvas.fr
+                              .getMinMax()
                               : null);
       contents.append("</p>");
     }
     cap.setText("<html>" + contents.toString() + "</html>");
 
-    Desktop.instance.addInternalFrame(cap, MessageManager.formatMessage(
-            "label.sequece_details_for",
-            (sequences.length == 1 ? new String[]
-            { sequences[0].getDisplayId(true) } : new String[]
+    Desktop.addInternalFrame(cap, MessageManager.formatMessage(
+            "label.sequence_details_for",
+            (sequences.length == 1 ? new Object[]
+            { sequences[0].getDisplayId(true) } : new Object[]
             { MessageManager.getString("label.selection") })), 500, 400);
 
   }