New class for defining groups and selections
authoramwaterhouse <Andrew Waterhouse>
Tue, 14 Dec 2004 11:24:26 +0000 (11:24 +0000)
committeramwaterhouse <Andrew Waterhouse>
Tue, 14 Dec 2004 11:24:26 +0000 (11:24 +0000)
src/jalview/gui/PopupMenu.java [new file with mode: 0755]

diff --git a/src/jalview/gui/PopupMenu.java b/src/jalview/gui/PopupMenu.java
new file mode 100755 (executable)
index 0000000..4928189
--- /dev/null
@@ -0,0 +1,520 @@
+package jalview.gui;\r
+\r
+import jalview.datamodel.*;\r
+import jalview.analysis.*;\r
+import jalview.schemes.*;\r
+import javax.swing.*;\r
+import java.awt.event.*;\r
+\r
+\r
+public class PopupMenu extends JPopupMenu\r
+{\r
+  JMenuItem residueMenu = new JMenuItem();\r
+  JMenu groupMenu = new JMenu();\r
+  JMenuItem copyGroup = new JMenuItem();\r
+  JMenuItem moveGroup = new JMenuItem();\r
+  JMenuItem deleteSequences = new JMenuItem();\r
+  JMenuItem analyze = new JMenuItem();\r
+  JMenu defineMenu = new JMenu();\r
+  JMenuItem groupName = new JMenuItem();\r
+  JMenuItem groupAnnotation = new JMenuItem();\r
+  protected JRadioButtonMenuItem clustalColour = new JRadioButtonMenuItem();\r
+  protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem();\r
+  protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem();\r
+  protected JRadioButtonMenuItem hydrophobicityColour = new JRadioButtonMenuItem();\r
+  protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem();\r
+  protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem();\r
+  protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem();\r
+  protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem();\r
+  protected JRadioButtonMenuItem abovePIDColour = new JRadioButtonMenuItem();\r
+  protected JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem();\r
+  protected JRadioButtonMenuItem PIDColour = new JRadioButtonMenuItem();\r
+  protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem();\r
+  JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem();\r
+  protected JMenuItem conservationColourIncMenuItem = new JMenuItem();\r
+  protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();\r
+\r
+\r
+  AlignViewport av;\r
+  SeqPanel seqPanel;\r
+\r
+  public PopupMenu(AlignViewport av, SeqPanel sp)\r
+  {\r
+    this.av = av;\r
+    seqPanel = sp;\r
+\r
+    ButtonGroup colours = new ButtonGroup();\r
+    colours.add(noColourmenuItem);\r
+    colours.add(clustalColour);\r
+    colours.add(zappoColour);\r
+    colours.add(taylorColour);\r
+    colours.add(hydrophobicityColour);\r
+    colours.add(helixColour);\r
+    colours.add(strandColour);\r
+    colours.add(turnColour);\r
+    colours.add(buriedColour);\r
+    colours.add(abovePIDColour);\r
+    colours.add(userDefinedColour);\r
+    colours.add(PIDColour);\r
+    colours.add(BLOSUM62Colour);\r
+\r
+    try\r
+    {\r
+      jbInit();\r
+    }\r
+    catch(Exception e)\r
+    {\r
+      e.printStackTrace();\r
+    }\r
+\r
+    SequenceGroup sg = av.getRubberbandGroup();\r
+    groupName.setText( sg.getName() );\r
+  }\r
+  private void jbInit() throws Exception\r
+  {\r
+    residueMenu.setText("Residue");\r
+    groupMenu.setText("Group");\r
+    copyGroup.setText("Copy region to new Alignment");\r
+    copyGroup.addActionListener(new java.awt.event.ActionListener()\r
+    {\r
+      public void actionPerformed(ActionEvent e)\r
+      {\r
+        copyGroup_actionPerformed(e);\r
+      }\r
+    });\r
+    moveGroup.setText("Move sequences to new Alignment");\r
+    moveGroup.addActionListener(new java.awt.event.ActionListener()\r
+    {\r
+      public void actionPerformed(ActionEvent e)\r
+      {\r
+        moveGroup_actionPerformed(e);\r
+      }\r
+    });\r
+    deleteSequences.setText("Delete sequences");\r
+    deleteSequences.addActionListener(new java.awt.event.ActionListener()\r
+    {\r
+      public void actionPerformed(ActionEvent e)\r
+      {\r
+        deleteSequences_actionPerformed(e);\r
+      }\r
+    });\r
+    analyze.setText("Analyze");\r
+    analyze.addActionListener(new java.awt.event.ActionListener()\r
+    {\r
+      public void actionPerformed(ActionEvent e)\r
+      {\r
+        analyze_actionPerformed(e);\r
+      }\r
+    });\r
+    defineMenu.setText("Define");\r
+    groupName.setText("Name");\r
+    groupName.addActionListener(new java.awt.event.ActionListener()\r
+    {\r
+      public void actionPerformed(ActionEvent e)\r
+      {\r
+        groupName_actionPerformed(e);\r
+      }\r
+    });\r
+    groupAnnotation.setText("Annotation");\r
+    groupAnnotation.addActionListener(new java.awt.event.ActionListener()\r
+    {\r
+      public void actionPerformed(ActionEvent e)\r
+      {\r
+        groupAnnotation_actionPerformed(e);\r
+      }\r
+    });\r
+    add(groupMenu);\r
+    add(residueMenu);\r
+    groupMenu.add(defineMenu);\r
+    groupMenu.addSeparator();\r
+    groupMenu.add(copyGroup);\r
+    groupMenu.add(moveGroup);\r
+    groupMenu.add(deleteSequences);\r
+    groupMenu.addSeparator();\r
+    groupMenu.add(analyze);\r
+    defineMenu.add(groupName);\r
+    defineMenu.add(groupAnnotation);\r
+    defineMenu.addSeparator();\r
+    defineMenu.add(noColourmenuItem);\r
+    defineMenu.add(clustalColour);\r
+    defineMenu.add(zappoColour);\r
+    defineMenu.add(taylorColour);\r
+    defineMenu.add(hydrophobicityColour);\r
+    defineMenu.add(helixColour);\r
+    defineMenu.add(strandColour);\r
+    defineMenu.add(turnColour);\r
+    defineMenu.add(buriedColour);\r
+    defineMenu.add(userDefinedColour);\r
+    defineMenu.addSeparator();\r
+    defineMenu.add(conservationMenuItem);\r
+    defineMenu.add(conservationColourIncMenuItem);\r
+    defineMenu.addSeparator();\r
+    defineMenu.add(abovePIDColour);\r
+    defineMenu.add(PIDColour);\r
+    defineMenu.add(BLOSUM62Colour);\r
+\r
+    noColourmenuItem.setText("None");\r
+    noColourmenuItem.setSelected(true);\r
+    noColourmenuItem.addActionListener(new java.awt.event.ActionListener()\r
+    {\r
+      public void actionPerformed(ActionEvent e)\r
+      {\r
+        noColourmenuItem_actionPerformed(e);\r
+      }\r
+    });\r
+\r
+    clustalColour.setEnabled(false);\r
+    clustalColour.setSelected(false);\r
+    clustalColour.setText("Clustalx colours");\r
+    clustalColour.addActionListener(new java.awt.event.ActionListener()\r
+    {\r
+      public void actionPerformed(ActionEvent e)\r
+      {\r
+        clustalColour_actionPerformed(e);\r
+      }\r
+    });\r
+    zappoColour.setText("Zappo colour scheme");\r
+    zappoColour.addActionListener(new java.awt.event.ActionListener()\r
+    {\r
+      public void actionPerformed(ActionEvent e)\r
+      {\r
+        zappoColour_actionPerformed(e);\r
+      }\r
+    });\r
+    taylorColour.setText("Taylor colour scheme");\r
+    taylorColour.addActionListener(new java.awt.event.ActionListener()\r
+    {\r
+      public void actionPerformed(ActionEvent e)\r
+      {\r
+        taylorColour_actionPerformed(e);\r
+      }\r
+    });\r
+    hydrophobicityColour.setText("By hydrophobicity");\r
+    hydrophobicityColour.addActionListener(new java.awt.event.ActionListener()\r
+    {\r
+      public void actionPerformed(ActionEvent e)\r
+      {\r
+        hydrophobicityColour_actionPerformed(e);\r
+      }\r
+    });\r
+    helixColour.setText("Helix propensity");\r
+    helixColour.addActionListener(new java.awt.event.ActionListener()\r
+    {\r
+      public void actionPerformed(ActionEvent e)\r
+      {\r
+        helixColour_actionPerformed(e);\r
+      }\r
+    });\r
+    strandColour.setText("Strand propensity");\r
+    strandColour.addActionListener(new java.awt.event.ActionListener()\r
+    {\r
+      public void actionPerformed(ActionEvent e)\r
+      {\r
+        strandColour_actionPerformed(e);\r
+      }\r
+    });\r
+    turnColour.setText("Turn propensity");\r
+    turnColour.addActionListener(new java.awt.event.ActionListener()\r
+    {\r
+      public void actionPerformed(ActionEvent e)\r
+      {\r
+        turnColour_actionPerformed(e);\r
+      }\r
+    });\r
+    buriedColour.setText("Buried index");\r
+    buriedColour.addActionListener(new java.awt.event.ActionListener()\r
+    {\r
+      public void actionPerformed(ActionEvent e)\r
+      {\r
+        buriedColour_actionPerformed(e);\r
+      }\r
+    });\r
+    abovePIDColour.setEnabled(false);\r
+    abovePIDColour.setText("Above PID threshold only");\r
+    abovePIDColour.addActionListener(new java.awt.event.ActionListener()\r
+    {\r
+      public void actionPerformed(ActionEvent e)\r
+      {\r
+        abovePIDColour_actionPerformed(e);\r
+      }\r
+    });\r
+    userDefinedColour.setText("User defined colours");\r
+    userDefinedColour.addActionListener(new java.awt.event.ActionListener()\r
+    {\r
+      public void actionPerformed(ActionEvent e)\r
+      {\r
+        userDefinedColour_actionPerformed(e);\r
+      }\r
+    });\r
+    PIDColour.setEnabled(false);\r
+    PIDColour.setText("By PID");\r
+    PIDColour.addActionListener(new java.awt.event.ActionListener()\r
+    {\r
+      public void actionPerformed(ActionEvent e)\r
+      {\r
+        PIDColour_actionPerformed(e);\r
+      }\r
+    });\r
+    BLOSUM62Colour.setText("By BLOSUM62 score");\r
+    BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()\r
+    {\r
+      public void actionPerformed(ActionEvent e)\r
+      {\r
+        BLOSUM62Colour_actionPerformed(e);\r
+      }\r
+    });\r
+    conservationMenuItem.setText("By conservation");\r
+   conservationMenuItem.addActionListener(new java.awt.event.ActionListener()\r
+   {\r
+     public void actionPerformed(ActionEvent e)\r
+     {\r
+       conservationMenuItem_actionPerformed(e);\r
+     }\r
+   });\r
+\r
+    conservationColourIncMenuItem.setEnabled(false);\r
+    conservationColourIncMenuItem.setText("Conservation Colour Increment");\r
+    conservationColourIncMenuItem.addActionListener(new java.awt.event.ActionListener()\r
+    {\r
+      public void actionPerformed(ActionEvent e)\r
+      {\r
+        conservationColourIncMenuItem_actionPerformed(e);\r
+      }\r
+    });\r
+\r
+\r
+  }\r
+\r
+  void refresh()\r
+  {\r
+    seqPanel.seqCanvas.paintFlag=true;\r
+    seqPanel.repaint();\r
+  }\r
+\r
+  protected void clustalColour_actionPerformed(ActionEvent e)\r
+  {\r
+\r
+  }\r
+\r
+  protected void zappoColour_actionPerformed(ActionEvent e)\r
+  {\r
+    getGroup().cs = new ZappoColourScheme();\r
+    refresh();\r
+  }\r
+\r
+  protected void taylorColour_actionPerformed(ActionEvent e)\r
+  {\r
+    getGroup().cs = new TaylorColourScheme();\r
+    refresh();\r
+  }\r
+\r
+\r
+  protected void hydrophobicityColour_actionPerformed(ActionEvent e)\r
+  {\r
+    getGroup().cs = new HydrophobicColourScheme();\r
+    refresh();\r
+  }\r
+\r
+  protected void helixColour_actionPerformed(ActionEvent e)\r
+  {\r
+    getGroup().cs = new HelixColourScheme();\r
+    refresh();\r
+  }\r
+\r
+  protected void strandColour_actionPerformed(ActionEvent e)\r
+  {\r
+    getGroup().cs = new StrandColourScheme();\r
+    refresh();\r
+  }\r
+\r
+  protected void turnColour_actionPerformed(ActionEvent e)\r
+  {\r
+    getGroup().cs = new TurnColourScheme();\r
+    refresh();\r
+  }\r
+\r
+  protected void buriedColour_actionPerformed(ActionEvent e)\r
+  {\r
+    getGroup().cs = new BuriedColourScheme();\r
+    refresh();\r
+  }\r
+\r
+\r
+  protected void conservationColourIncMenuItem_actionPerformed(ActionEvent e)\r
+ {\r
+\r
+}\r
+/*\r
+public void conservationColourIncMenuItem_actionPerformed(ActionEvent e)\r
+{\r
+ConservationIncrementPanel cip = new ConservationIncrementPanel(viewport, alignPanel);\r
+JInternalFrame frame = new JInternalFrame();\r
+frame.setContentPane(cip);\r
+Desktop.addInternalFrame(frame, "Conservation Colour Increment", 400,90);\r
+frame.setMaximizable(false);\r
+\r
+ }*/\r
+\r
+\r
+  protected void abovePIDColour_actionPerformed(ActionEvent e)\r
+  {\r
+\r
+  }\r
+\r
+\r
+  protected void userDefinedColour_actionPerformed(ActionEvent e)\r
+  {\r
+\r
+  }\r
+\r
+  protected void PIDColour_actionPerformed(ActionEvent e)\r
+  {\r
+\r
+  }\r
+\r
+  protected void BLOSUM62Colour_actionPerformed(ActionEvent e)\r
+  {\r
+    getGroup().cs = new Blosum62ColourScheme(av);\r
+    refresh();\r
+  }\r
+\r
+\r
+  protected void noColourmenuItem_actionPerformed(ActionEvent e)\r
+  {\r
+    getGroup().cs = null;\r
+    refresh();\r
+  }\r
+\r
+  protected  void conservationMenuItem_actionPerformed(ActionEvent e)\r
+  {\r
+    SequenceGroup sg = getGroup();\r
+\r
+    Alignment al = (Alignment)av.getAlignment();\r
+    Conservation c = new Conservation("Group", al.cons,\r
+                          ResidueProperties.propHash, 3, sg.sequences, sg.getStartRes(),\r
+                          sg.getEndRes() );\r
+\r
+     c.calculate();\r
+     c.verdict(false, 100);\r
+     ConservationColourScheme ccs = new ConservationColourScheme(c, sg.cs);\r
+\r
+     sg.cs = ccs;\r
+\r
+     refresh();\r
+  }\r
+\r
+  protected void groupAnnotation_actionPerformed(ActionEvent e)\r
+  {\r
+\r
+  }\r
+\r
+  protected void groupName_actionPerformed(ActionEvent e)\r
+  {\r
+    SequenceGroup sg = getGroup();\r
+    String reply = JOptionPane.showInternalInputDialog(Desktop.desktop, "Enter new group name", "Edit group name", JOptionPane.QUESTION_MESSAGE);\r
+    if(reply==null)\r
+      return;\r
+\r
+    sg.setName(reply);\r
+    groupName.setText(reply);\r
+  }\r
+  /*  public void deleteSelectedMenuItem_actionPerformed(ActionEvent e)\r
+    {\r
+      addHistoryItem("delete selection");\r
+\r
+      for (int i=0;i < viewport.getSelection().size(); i++)\r
+              viewport.getAlignment().deleteSequence(viewport.getSelection().sequenceAt(i));\r
+\r
+      viewport.getSelection().clear();\r
+      viewport.resetSeqLimits(alignPanel.seqPanel.seqCanvas.getHeight());\r
+      alignPanel.RefreshPanels();\r
+    }\r
+\r
+    public void moveSelectedMenuItem_actionPerformed(ActionEvent e)\r
+    {\r
+      copySelectedMenuItem_actionPerformed(null);\r
+      deleteSelectedMenuItem_actionPerformed(null);\r
+      alignPanel.repaint();\r
+    }\r
+\r
+    public void copySelectedMenuItem_actionPerformed(ActionEvent e)\r
+    {\r
+      if(viewport.getSelection().size()==0)\r
+        return;\r
+\r
+     SequenceI[] s = new Sequence[viewport.getSelection().size()];\r
+     for (int i=0; i < viewport.getSelection().size(); i++) {\r
+       s[i] = new Sequence(viewport.getSelection().sequenceAt(i));\r
+      }\r
+      AlignFrame af = new AlignFrame(new Alignment(s));\r
+      int newHeight = s.length * af.viewport.getCharHeight() + 200;\r
+      if(newHeight>500)\r
+        newHeight=500;\r
+      Desktop.addInternalFrame(af, "Copied sequences", 700,newHeight);\r
+    }\r
+*/\r
+  protected void copyGroup_actionPerformed(ActionEvent e)\r
+  {\r
+    SequenceGroup sg = av.getRubberbandGroup();\r
+\r
+    SequenceI[] s = new Sequence[sg.sequences.size()];\r
+     for (int i=0; i < sg.sequences.size(); i++)\r
+     {\r
+       s[i] = new Sequence( sg.getSequenceAt(i));\r
+       s[i].setSequence( s[i].getSequence(sg.getStartRes(), sg.getEndRes()+1) );\r
+     }\r
+     AlignFrame af = new AlignFrame(new Alignment(s));\r
+     int newHeight = s.length * af.viewport.getCharHeight() + 200;\r
+     if (newHeight > 500)\r
+       newHeight = 500;\r
+     Desktop.addInternalFrame(af, "Copied sequences", 700, newHeight);\r
+  }\r
+\r
+  protected  void moveGroup_actionPerformed(ActionEvent e)\r
+  {\r
+\r
+  }\r
+\r
+  protected void deleteSequences_actionPerformed(ActionEvent e)\r
+  {\r
+    SequenceGroup sg = av.getRubberbandGroup();\r
+    for (int i=0;i < sg.sequences.size(); i++)\r
+            av.getAlignment().deleteSequence(sg.getSequenceAt(i));\r
+\r
+    av.alignment.deleteGroup(sg);\r
+    av.resetSeqLimits(seqPanel.seqCanvas.getHeight());\r
+    seqPanel.parent.RefreshPanels();\r
+\r
+  }\r
+\r
+  protected void analyze_actionPerformed(ActionEvent e)\r
+  {\r
+     CutAndPasteTransfer cap = new CutAndPasteTransfer(false);\r
+     JInternalFrame frame = new JInternalFrame();\r
+     cap.formatForOutput();\r
+     frame.setContentPane(cap);\r
+     Desktop.addInternalFrame(frame, "Analyze this - ", 400, 300);\r
+     SequenceGroup sg = getGroup();\r
+     StringBuffer sb = new StringBuffer();\r
+\r
+     for(int i=0; i<sg.sequences.size(); i++)\r
+     {\r
+       Sequence tmp = (Sequence)sg.sequences.get(i);\r
+       sb.append(  tmp.getSequence(sg.getStartRes(), sg.getEndRes()+1));\r
+       sb.append("\n");\r
+     }\r
+\r
+     sb.append("Something amazing will happen soon");\r
+     cap.setText( sb.toString() );\r
+\r
+  }\r
+\r
+  SequenceGroup getGroup()\r
+  {\r
+    SequenceGroup sg = av.getRubberbandGroup();\r
+\r
+    // this method won't add a new group if it already exists\r
+    av.alignment.addGroup(sg);\r
+    return sg;\r
+  }\r
+}\r