generation of additional URLs for DBRefs on a sequence that match the URL link name.
authorjprocter <Jim Procter>
Wed, 6 Aug 2008 12:16:51 +0000 (12:16 +0000)
committerjprocter <Jim Procter>
Wed, 6 Aug 2008 12:16:51 +0000 (12:16 +0000)
src/jalview/appletgui/APopupMenu.java
src/jalview/gui/PopupMenu.java

index 803f323..ff1c3c8 100755 (executable)
-/*\r
- * Jalview - A Sequence Alignment Editor and Viewer\r
- * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
- *\r
- * This program is free software; you can redistribute it and/or\r
- * modify it under the terms of the GNU General Public License\r
- * as published by the Free Software Foundation; either version 2\r
- * of the License, or (at your option) any later version.\r
- *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
- *\r
- * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA\r
- */\r
-\r
-package jalview.appletgui;\r
-\r
-import java.util.*;\r
-\r
-import java.awt.*;\r
-import java.awt.event.*;\r
-\r
-import jalview.analysis.*;\r
-import jalview.commands.*;\r
-import jalview.datamodel.*;\r
-import jalview.schemes.*;\r
-import jalview.io.AppletFormatAdapter;\r
-\r
-public class APopupMenu\r
-    extends java.awt.PopupMenu implements ActionListener, ItemListener\r
-{\r
-  Menu groupMenu = new Menu();\r
-  MenuItem editGroupName = new MenuItem();\r
-  protected MenuItem clustalColour = new MenuItem();\r
-  protected MenuItem zappoColour = new MenuItem();\r
-  protected MenuItem taylorColour = new MenuItem();\r
-  protected MenuItem hydrophobicityColour = new MenuItem();\r
-  protected MenuItem helixColour = new MenuItem();\r
-  protected MenuItem strandColour = new MenuItem();\r
-  protected MenuItem turnColour = new MenuItem();\r
-  protected MenuItem buriedColour = new MenuItem();\r
-  protected CheckboxMenuItem abovePIDColour = new CheckboxMenuItem();\r
-  protected MenuItem userDefinedColour = new MenuItem();\r
-  protected MenuItem PIDColour = new MenuItem();\r
-  protected MenuItem BLOSUM62Colour = new MenuItem();\r
-  MenuItem noColourmenuItem = new MenuItem();\r
-  protected CheckboxMenuItem conservationMenuItem = new CheckboxMenuItem();\r
-\r
-  final AlignmentPanel ap;\r
-  MenuItem unGroupMenuItem = new MenuItem();\r
-  MenuItem nucleotideMenuItem = new MenuItem();\r
-  Menu colourMenu = new Menu();\r
-  CheckboxMenuItem showBoxes = new CheckboxMenuItem();\r
-  CheckboxMenuItem showText = new CheckboxMenuItem();\r
-  CheckboxMenuItem showColourText = new CheckboxMenuItem();\r
-  Menu editMenu = new Menu("Edit");\r
-  MenuItem copy = new MenuItem("Copy (Jalview Only)");\r
-  MenuItem cut = new MenuItem("Cut (Jalview Only)");\r
-  MenuItem toUpper = new MenuItem("To Upper Case");\r
-  MenuItem toLower = new MenuItem("To Lower Case");\r
-  MenuItem toggleCase = new MenuItem("Toggle Case");\r
-  Menu outputmenu = new Menu();\r
-  Menu seqMenu = new Menu();\r
-  MenuItem pdb = new MenuItem();\r
-  MenuItem hideSeqs = new MenuItem();\r
-  MenuItem repGroup = new MenuItem();\r
-  MenuItem sequenceName = new MenuItem("Edit Name/Description");\r
-  MenuItem sequenceFeature = new MenuItem("Create Sequence Feature");\r
-  MenuItem editSequence = new MenuItem("Edit Sequence");\r
-\r
-  Sequence seq;\r
-  MenuItem revealAll = new MenuItem();\r
-  Menu menu1 = new Menu();\r
-\r
-  public APopupMenu(AlignmentPanel apanel, final Sequence seq, Vector links)\r
-  {\r
-    ///////////////////////////////////////////////////////////\r
-    // If this is activated from the sequence panel, the user may want to\r
-    // edit or annotate a particular residue. Therefore display the residue menu\r
-    //\r
-    // If from the IDPanel, we must display the sequence menu\r
-    //////////////////////////////////////////////////////////\r
-\r
-    this.ap = apanel;\r
-    this.seq = seq;\r
-\r
-    try\r
-    {\r
-      jbInit();\r
-    }\r
-    catch (Exception e)\r
-    {\r
-      e.printStackTrace();\r
-    }\r
-\r
-    for (int i = 0; i < jalview.io.AppletFormatAdapter.WRITEABLE_FORMATS.length;\r
-         i++)\r
-    {\r
-      MenuItem item = new MenuItem(jalview.io.AppletFormatAdapter.\r
-                                   WRITEABLE_FORMATS[i]);\r
-\r
-      item.addActionListener(this);\r
-      outputmenu.add(item);\r
-    }\r
-\r
-    SequenceGroup sg = ap.av.getSelectionGroup();\r
-\r
-    if (sg != null && sg.getSize() > 0)\r
-    {\r
-      editGroupName.setLabel(sg.getName());\r
-      showText.setState(sg.getDisplayText());\r
-      showColourText.setState(sg.getColourText());\r
-      showBoxes.setState(sg.getDisplayBoxes());\r
-      if (!ap.av.alignment.getGroups().contains(sg))\r
-      {\r
-        groupMenu.remove(unGroupMenuItem);\r
-      }\r
-\r
-    }\r
-    else\r
-    {\r
-      remove(hideSeqs);\r
-      remove(groupMenu);\r
-    }\r
-\r
-    if (links != null)\r
-    {\r
-      Menu linkMenu = new Menu("Link");\r
-      MenuItem item;\r
-      String link;\r
-      for (int i = 0; i < links.size(); i++)\r
-      {\r
-        link = links.elementAt(i).toString();\r
-        final String target = link.substring(0, link.indexOf("|"));\r
-        item = new MenuItem(target);\r
-\r
-        final String url;\r
-\r
-        if (link.indexOf("$SEQUENCE_ID$") > -1)\r
-        {\r
-          String id = seq.getName();\r
-          if (id.indexOf("|") > -1)\r
-          {\r
-            id = id.substring(id.lastIndexOf("|") + 1);\r
-          }\r
-\r
-          url = link.substring(link.indexOf("|") + 1,\r
-                               link.indexOf("$SEQUENCE_ID$"))\r
-              + id +\r
-              link.substring(link.indexOf("$SEQUENCE_ID$") + 13);\r
-        }\r
-        else\r
-        {\r
-          url = link.substring(link.lastIndexOf("|") + 1);\r
-        }\r
-\r
-        item.addActionListener(new java.awt.event.ActionListener()\r
-        {\r
-          public void actionPerformed(ActionEvent e)\r
-          {\r
-            ap.alignFrame.showURL(url, target);\r
-          }\r
-        });\r
-        linkMenu.add(item);\r
-      }\r
-      if (seq != null)\r
-      {\r
-        seqMenu.add(linkMenu);\r
-      }\r
-      else\r
-      {\r
-        add(linkMenu);\r
-      }\r
-    }\r
-    if (seq != null)\r
-    {\r
-      seqMenu.setLabel(seq.getName());\r
-      repGroup.setLabel("Represent Group with " + seq.getName());\r
-    }\r
-    else\r
-    {\r
-      remove(seqMenu);\r
-    }\r
-\r
-    if (!ap.av.hasHiddenRows)\r
-    {\r
-      remove(revealAll);\r
-    }\r
-  }\r
-\r
-  public void itemStateChanged(ItemEvent evt)\r
-  {\r
-    if (evt.getSource() == abovePIDColour)\r
-    {\r
-      abovePIDColour_itemStateChanged();\r
-    }\r
-    else if (evt.getSource() == showColourText)\r
-    {\r
-      showColourText_itemStateChanged();\r
-    }\r
-    else if (evt.getSource() == showText)\r
-    {\r
-      showText_itemStateChanged();\r
-    }\r
-    else if (evt.getSource() == showBoxes)\r
-    {\r
-      showBoxes_itemStateChanged();\r
-    }\r
-  }\r
-\r
-  public void actionPerformed(ActionEvent evt)\r
-  {\r
-    Object source = evt.getSource();\r
-    if (source == clustalColour)\r
-    {\r
-      clustalColour_actionPerformed();\r
-    }\r
-    else if (source == zappoColour)\r
-    {\r
-      zappoColour_actionPerformed();\r
-    }\r
-    else if (source == taylorColour)\r
-    {\r
-      taylorColour_actionPerformed();\r
-    }\r
-    else if (source == hydrophobicityColour)\r
-    {\r
-      hydrophobicityColour_actionPerformed();\r
-    }\r
-    else if (source == helixColour)\r
-    {\r
-      helixColour_actionPerformed();\r
-    }\r
-    else if (source == strandColour)\r
-    {\r
-      strandColour_actionPerformed();\r
-    }\r
-    else if (source == turnColour)\r
-    {\r
-      turnColour_actionPerformed();\r
-    }\r
-    else if (source == buriedColour)\r
-    {\r
-      buriedColour_actionPerformed();\r
-    }\r
-    else if (source == nucleotideMenuItem)\r
-    {\r
-      nucleotideMenuItem_actionPerformed();\r
-    }\r
-\r
-    else if (source == userDefinedColour)\r
-    {\r
-      userDefinedColour_actionPerformed();\r
-    }\r
-    else if (source == PIDColour)\r
-    {\r
-      PIDColour_actionPerformed();\r
-    }\r
-    else if (source == BLOSUM62Colour)\r
-    {\r
-      BLOSUM62Colour_actionPerformed();\r
-    }\r
-    else if (source == noColourmenuItem)\r
-    {\r
-      noColourmenuItem_actionPerformed();\r
-    }\r
-    else if (source == conservationMenuItem)\r
-    {\r
-      conservationMenuItem_itemStateChanged();\r
-    }\r
-    else if (source == unGroupMenuItem)\r
-    {\r
-      unGroupMenuItem_actionPerformed();\r
-    }\r
-\r
-    else if (source == sequenceName)\r
-    {\r
-      editName();\r
-    }\r
-    else if (source == pdb)\r
-    {\r
-      addPDB();\r
-    }\r
-    else if (source == hideSeqs)\r
-    {\r
-      hideSequences(false);\r
-    }\r
-    else if (source == repGroup)\r
-    {\r
-      hideSequences(true);\r
-    }\r
-    else if (source == revealAll)\r
-    {\r
-      ap.av.showAllHiddenSeqs();\r
-    }\r
-\r
-    else if (source == editGroupName)\r
-    {\r
-      EditNameDialog dialog = new EditNameDialog(\r
-          getGroup().getName(),\r
-          getGroup().getDescription(),\r
-          "       Group Name",\r
-          "Group Description",\r
-          ap.alignFrame,\r
-          "Edit Group Name / Description",\r
-          500,100, true);\r
-\r
-      if (dialog.accept)\r
-      {\r
-        getGroup().setName(dialog.getName().replace(' ', '_'));\r
-        getGroup().setDescription(dialog.getDescription());\r
-      }\r
-\r
-    }\r
-    else if (source == copy)\r
-    {\r
-      ap.alignFrame.copy_actionPerformed();\r
-    }\r
-    else if (source == cut)\r
-    {\r
-      ap.alignFrame.cut_actionPerformed();\r
-    }\r
-    else if(source == editSequence)\r
-    {\r
-      SequenceGroup sg = ap.av.getSelectionGroup();\r
-\r
-      if(sg!=null)\r
-      {\r
-        if (seq == null)\r
-          seq = (Sequence) sg.getSequenceAt(0);\r
-\r
-        EditNameDialog dialog = new EditNameDialog(seq.getSequenceAsString(\r
-            sg.getStartRes(),\r
-            sg.getEndRes() + 1),\r
-                                                   null,\r
-                                                   "Edit Sequence ",\r
-                                                   null,\r
-\r
-                                                   ap.alignFrame,\r
-                                                   "Edit Sequence",\r
-                                                   500, 100, true);\r
-\r
-        if (dialog.accept)\r
-        {\r
-          EditCommand editCommand = new EditCommand(\r
-              "Edit Sequences", EditCommand.REPLACE,\r
-              dialog.getName().replace(' ', ap.av.getGapCharacter()),\r
-              sg.getSequencesAsArray(ap.av.hiddenRepSequences),\r
-              sg.getStartRes(), sg.getEndRes()+1, ap.av.alignment\r
-              );\r
-\r
-          ap.alignFrame.addHistoryItem(editCommand);\r
-\r
-          ap.av.firePropertyChange("alignment", null,\r
-                                 ap.av.getAlignment().getSequences());\r
-        }\r
-      }\r
-    }\r
-    else if (source == toUpper || source == toLower || source == toggleCase)\r
-    {\r
-      SequenceGroup sg = ap.av.getSelectionGroup();\r
-      Vector regions = new Vector();\r
-      if (sg != null)\r
-      {\r
-        int start = sg.getStartRes();\r
-        int end = sg.getEndRes() + 1;\r
-\r
-        do\r
-        {\r
-          if (ap.av.hasHiddenColumns)\r
-          {\r
-            if (start == 0)\r
-            {\r
-              start = ap.av.colSel.adjustForHiddenColumns(start);\r
-            }\r
-\r
-            end = ap.av.colSel.getHiddenBoundaryRight(start);\r
-            if (start == end)\r
-            {\r
-              end = sg.getEndRes() + 1;\r
-            }\r
-            if (end > sg.getEndRes())\r
-            {\r
-              end = sg.getEndRes() + 1;\r
-            }\r
-          }\r
-\r
-          regions.addElement(new int[]\r
-                             {start, end});\r
-\r
-          if (ap.av.hasHiddenColumns)\r
-          {\r
-            start = ap.av.colSel.adjustForHiddenColumns(end);\r
-            start = ap.av.colSel.getHiddenBoundaryLeft(start) + 1;\r
-          }\r
-        }\r
-        while (end < sg.getEndRes());\r
-\r
-        int[][] startEnd = new int[regions.size()][2];\r
-        for (int i = 0; i < regions.size(); i++)\r
-        {\r
-          startEnd[i] = (int[]) regions.elementAt(i);\r
-        }\r
-\r
-        String description;\r
-        int caseChange;\r
-\r
-        if (source == toggleCase)\r
-        {\r
-          description = "Toggle Case";\r
-          caseChange = ChangeCaseCommand.TOGGLE_CASE;\r
-        }\r
-        else if (source == toUpper)\r
-        {\r
-          description = "To Upper Case";\r
-          caseChange = ChangeCaseCommand.TO_UPPER;\r
-        }\r
-        else\r
-        {\r
-          description = "To Lower Case";\r
-          caseChange = ChangeCaseCommand.TO_LOWER;\r
-        }\r
-\r
-        ChangeCaseCommand caseCommand = new ChangeCaseCommand(\r
-            description, sg.getSequencesAsArray(ap.av.hiddenRepSequences),\r
-            startEnd, caseChange\r
-            );\r
-\r
-        ap.alignFrame.addHistoryItem(caseCommand);\r
-\r
-        ap.av.firePropertyChange("alignment", null,\r
-                                 ap.av.getAlignment().getSequences());\r
-\r
-      }\r
-    }\r
-    else if(source == sequenceFeature)\r
-    {\r
-      SequenceGroup sg = ap.av.getSelectionGroup();\r
-      if (sg == null)\r
-      {\r
-        return;\r
-      }\r
-\r
-      int gSize = sg.getSize();\r
-      SequenceI[] seqs = new SequenceI[gSize];\r
-      SequenceFeature[] features = new SequenceFeature[gSize];\r
-\r
-      for (int i = 0; i < gSize; i++)\r
-      {\r
-        seqs[i] = sg.getSequenceAt(i);\r
-        int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());\r
-        int end = sg.findEndRes(sg.getSequenceAt(i));\r
-        features[i] = new SequenceFeature(null, null, null, start, end,\r
-                                          "Jalview");\r
-      }\r
-\r
-      if (ap.seqPanel.seqCanvas.getFeatureRenderer()\r
-          .amendFeatures(seqs, features, true, ap))\r
-      {\r
-        ap.alignFrame.sequenceFeatures.setState(true);\r
-        ap.av.showSequenceFeatures(true);\r
-        ap.highlightSearchResults(null);\r
-      }\r
-    }\r
-    else\r
-    {\r
-      outputText(evt);\r
-    }\r
-\r
-  }\r
-\r
-  void outputText(ActionEvent e)\r
-  {\r
-    CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);\r
-\r
-    Frame frame = new Frame();\r
-    frame.add(cap);\r
-    jalview.bin.JalviewLite.addFrame(frame,\r
-                                     "Selection output - " + e.getActionCommand(),\r
-                                     600, 500);\r
-\r
-    cap.setText(new jalview.io.AppletFormatAdapter().formatSequences(\r
-        e.getActionCommand(),\r
-        new Alignment(ap.av.getSelectionAsNewSequence()),\r
-        ap.av.showJVSuffix));\r
-\r
-  }\r
-\r
-  void editName()\r
-  {\r
-    EditNameDialog dialog = new EditNameDialog(\r
-        seq.getName(),\r
-        seq.getDescription(),\r
-        "       Sequence Name",\r
-        "Sequence Description",\r
-        ap.alignFrame,\r
-        "Edit Sequence Name / Description",\r
-        500,100, true);\r
-\r
-    if (dialog.accept)\r
-    {\r
-      seq.setName(dialog.getName());\r
-      seq.setDescription(dialog.getDescription());\r
-      ap.paintAlignment(false);\r
-    }\r
-  }\r
-\r
-  void addPDB()\r
-  {\r
-    if(seq.getPDBId()!=null)\r
-    {\r
-      PDBEntry entry = (PDBEntry)seq.getPDBId().firstElement();\r
-\r
-      if ( ap.av.applet.jmolAvailable )\r
-       new jalview.appletgui.AppletJmol(entry,\r
-                                        new Sequence[]{seq},\r
-                                        null,\r
-                                        ap,\r
-                                        AppletFormatAdapter.URL);\r
-     else\r
-       new MCview.AppletPDBViewer(entry,\r
-                                  new Sequence[]{seq},\r
-                                  null,\r
-                                  ap,\r
-                                  AppletFormatAdapter.URL);\r
-\r
-    }\r
-    else\r
-    {\r
-      CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);\r
-      cap.setText("Paste your PDB file here.");\r
-      cap.setPDBImport(seq);\r
-      Frame frame = new Frame();\r
-      frame.add(cap);\r
-      jalview.bin.JalviewLite.addFrame(frame, "Paste PDB file ", 400, 300);\r
-    }\r
-  }\r
-\r
-  private void jbInit()\r
-      throws Exception\r
-  {\r
-    groupMenu.setLabel("Group");\r
-    groupMenu.setLabel("Selection");\r
-    sequenceFeature.addActionListener(this);\r
-\r
-    editGroupName.addActionListener(this);\r
-    unGroupMenuItem.setLabel("Remove Group");\r
-    unGroupMenuItem.addActionListener(this);\r
-\r
-    nucleotideMenuItem.setLabel("Nucleotide");\r
-    nucleotideMenuItem.addActionListener(this);\r
-    conservationMenuItem.addItemListener(this);\r
-    abovePIDColour.addItemListener(this);\r
-    colourMenu.setLabel("Group Colour");\r
-    showBoxes.setLabel("Boxes");\r
-    showBoxes.setState(true);\r
-    showBoxes.addItemListener(this);\r
-    sequenceName.addActionListener(this);\r
-\r
-    showText.setLabel("Text");\r
-    showText.addItemListener(this);\r
-    showColourText.setLabel("Colour Text");\r
-    showColourText.addItemListener(this);\r
-    outputmenu.setLabel("Output to Textbox...");\r
-    seqMenu.setLabel("Sequence");\r
-    pdb.setLabel("View PDB Structure");\r
-    hideSeqs.setLabel("Hide Sequences");\r
-    repGroup.setLabel("Represent Group with");\r
-    revealAll.setLabel("Reveal All");\r
-    menu1.setLabel("Group");\r
-    add(groupMenu);\r
-    this.add(seqMenu);\r
-    this.add(hideSeqs);\r
-    this.add(revealAll);\r
-    groupMenu.add(editGroupName);\r
-    groupMenu.add(editMenu);\r
-    groupMenu.add(outputmenu);\r
-    groupMenu.add(sequenceFeature);\r
-    groupMenu.add(menu1);\r
-\r
-    colourMenu.add(noColourmenuItem);\r
-    colourMenu.add(clustalColour);\r
-    colourMenu.add(BLOSUM62Colour);\r
-    colourMenu.add(PIDColour);\r
-    colourMenu.add(zappoColour);\r
-    colourMenu.add(taylorColour);\r
-    colourMenu.add(hydrophobicityColour);\r
-    colourMenu.add(helixColour);\r
-    colourMenu.add(strandColour);\r
-    colourMenu.add(turnColour);\r
-    colourMenu.add(buriedColour);\r
-    colourMenu.add(nucleotideMenuItem);\r
-    colourMenu.add(userDefinedColour);\r
-    colourMenu.addSeparator();\r
-    colourMenu.add(abovePIDColour);\r
-    colourMenu.add(conservationMenuItem);\r
-\r
-    noColourmenuItem.setLabel("None");\r
-    noColourmenuItem.addActionListener(this);\r
-\r
-    clustalColour.setLabel("Clustalx colours");\r
-    clustalColour.addActionListener(this);\r
-    zappoColour.setLabel("Zappo");\r
-    zappoColour.addActionListener(this);\r
-    taylorColour.setLabel("Taylor");\r
-    taylorColour.addActionListener(this);\r
-    hydrophobicityColour.setLabel("Hydrophobicity");\r
-    hydrophobicityColour.addActionListener(this);\r
-    helixColour.setLabel("Helix propensity");\r
-    helixColour.addActionListener(this);\r
-    strandColour.setLabel("Strand propensity");\r
-    strandColour.addActionListener(this);\r
-    turnColour.setLabel("Turn propensity");\r
-    turnColour.addActionListener(this);\r
-    buriedColour.setLabel("Buried Index");\r
-    buriedColour.addActionListener(this);\r
-    abovePIDColour.setLabel("Above % Identity");\r
-\r
-    userDefinedColour.setLabel("User Defined");\r
-    userDefinedColour.addActionListener(this);\r
-    PIDColour.setLabel("Percentage Identity");\r
-    PIDColour.addActionListener(this);\r
-    BLOSUM62Colour.setLabel("BLOSUM62");\r
-    BLOSUM62Colour.addActionListener(this);\r
-    conservationMenuItem.setLabel("Conservation");\r
-\r
-    editMenu.add(copy);\r
-    copy.addActionListener(this);\r
-    editMenu.add(cut);\r
-    cut.addActionListener(this);\r
-\r
-    editMenu.add(editSequence);\r
-    editSequence.addActionListener(this);\r
-\r
-    editMenu.add(toUpper);\r
-    toUpper.addActionListener(this);\r
-    editMenu.add(toLower);\r
-    toLower.addActionListener(this);\r
-    editMenu.add(toggleCase);\r
-    seqMenu.add(sequenceName);\r
-    seqMenu.add(pdb);\r
-    seqMenu.add(repGroup);\r
-    menu1.add(unGroupMenuItem);\r
-    menu1.add(colourMenu);\r
-    menu1.add(showBoxes);\r
-    menu1.add(showText);\r
-    menu1.add(showColourText);\r
-    toggleCase.addActionListener(this);\r
-    pdb.addActionListener(this);\r
-    hideSeqs.addActionListener(this);\r
-    repGroup.addActionListener(this);\r
-    revealAll.addActionListener(this);\r
-  }\r
-\r
-  void refresh()\r
-  {\r
-    ap.paintAlignment(true);\r
-  }\r
-\r
-  protected void clustalColour_actionPerformed()\r
-  {\r
-    SequenceGroup sg = getGroup();\r
-    sg.cs = new ClustalxColourScheme(sg.getSequences(ap.av.hiddenRepSequences),\r
-                                     ap.av.alignment.getWidth());\r
-    refresh();\r
-  }\r
-\r
-  protected void zappoColour_actionPerformed()\r
-  {\r
-    getGroup().cs = new ZappoColourScheme();\r
-    refresh();\r
-  }\r
-\r
-  protected void taylorColour_actionPerformed()\r
-  {\r
-    getGroup().cs = new TaylorColourScheme();\r
-    refresh();\r
-  }\r
-\r
-  protected void hydrophobicityColour_actionPerformed()\r
-  {\r
-    getGroup().cs = new HydrophobicColourScheme();\r
-    refresh();\r
-  }\r
-\r
-  protected void helixColour_actionPerformed()\r
-  {\r
-    getGroup().cs = new HelixColourScheme();\r
-    refresh();\r
-  }\r
-\r
-  protected void strandColour_actionPerformed()\r
-  {\r
-    getGroup().cs = new StrandColourScheme();\r
-    refresh();\r
-  }\r
-\r
-  protected void turnColour_actionPerformed()\r
-  {\r
-    getGroup().cs = new TurnColourScheme();\r
-    refresh();\r
-  }\r
-\r
-  protected void buriedColour_actionPerformed()\r
-  {\r
-    getGroup().cs = new BuriedColourScheme();\r
-    refresh();\r
-  }\r
-\r
-  public void nucleotideMenuItem_actionPerformed()\r
-  {\r
-    getGroup().cs = new NucleotideColourScheme();\r
-    refresh();\r
-  }\r
-\r
-  protected void abovePIDColour_itemStateChanged()\r
-  {\r
-    SequenceGroup sg = getGroup();\r
-    if (sg.cs == null)\r
-    {\r
-      return;\r
-    }\r
-\r
-    if (abovePIDColour.getState())\r
-    {\r
-      sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av.\r
-          hiddenRepSequences), 0,\r
-                                               ap.av.alignment.getWidth()));\r
-      int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs,\r
-          getGroup().getName());\r
-\r
-      sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus());\r
-\r
-      SliderPanel.showPIDSlider();\r
-\r
-    }\r
-    else // remove PIDColouring\r
-    {\r
-      sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus());\r
-    }\r
-\r
-    refresh();\r
-\r
-  }\r
-\r
-  protected void userDefinedColour_actionPerformed()\r
-  {\r
-    new UserDefinedColours(ap, getGroup());\r
-  }\r
-\r
-  protected void PIDColour_actionPerformed()\r
-  {\r
-    SequenceGroup sg = getGroup();\r
-    sg.cs = new PIDColourScheme();\r
-    sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av.\r
-        hiddenRepSequences), 0,\r
-                                             ap.av.alignment.getWidth()));\r
-    refresh();\r
-  }\r
-\r
-  protected void BLOSUM62Colour_actionPerformed()\r
-  {\r
-    SequenceGroup sg = getGroup();\r
-\r
-    sg.cs = new Blosum62ColourScheme();\r
-\r
-    sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av.\r
-        hiddenRepSequences), 0,\r
-                                             ap.av.alignment.getWidth()));\r
-\r
-    refresh();\r
-  }\r
-\r
-  protected void noColourmenuItem_actionPerformed()\r
-  {\r
-    getGroup().cs = null;\r
-    refresh();\r
-  }\r
-\r
-  protected void conservationMenuItem_itemStateChanged()\r
-  {\r
-    SequenceGroup sg = getGroup();\r
-    if (sg.cs == null)\r
-    {\r
-      return;\r
-    }\r
-\r
-    if (conservationMenuItem.getState())\r
-    {\r
-\r
-      Conservation c = new Conservation("Group",\r
-                                        ResidueProperties.propHash, 3,\r
-                                        sg.getSequences(ap.av.\r
-          hiddenRepSequences), 0,\r
-                                        ap.av.alignment.getWidth());\r
-\r
-      c.calculate();\r
-      c.verdict(false, ap.av.ConsPercGaps);\r
-\r
-      sg.cs.setConservation(c);\r
-\r
-      SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());\r
-      SliderPanel.showConservationSlider();\r
-    }\r
-    else // remove ConservationColouring\r
-    {\r
-      sg.cs.setConservation(null);\r
-    }\r
-\r
-    refresh();\r
-  }\r
-\r
-  SequenceGroup getGroup()\r
-  {\r
-    SequenceGroup sg = ap.av.getSelectionGroup();\r
-\r
-    // this method won't add a new group if it already exists\r
-    if (sg != null)\r
-    {\r
-      ap.av.alignment.addGroup(sg);\r
-    }\r
-\r
-    return sg;\r
-  }\r
-\r
-  void unGroupMenuItem_actionPerformed()\r
-  {\r
-    SequenceGroup sg = ap.av.getSelectionGroup();\r
-    ap.av.alignment.deleteGroup(sg);\r
-    ap.av.setSelectionGroup(null);\r
-    ap.paintAlignment(true);\r
-  }\r
-\r
-  public void showColourText_itemStateChanged()\r
-  {\r
-    getGroup().setColourText(showColourText.getState());\r
-    refresh();\r
-  }\r
-\r
-  public void showText_itemStateChanged()\r
-  {\r
-    getGroup().setDisplayText(showText.getState());\r
-    refresh();\r
-  }\r
-\r
-  public void showBoxes_itemStateChanged()\r
-  {\r
-    getGroup().setDisplayBoxes(showBoxes.getState());\r
-    refresh();\r
-  }\r
-\r
-  void hideSequences(boolean representGroup)\r
-  {\r
-    SequenceGroup sg = ap.av.getSelectionGroup();\r
-    if (sg == null || sg.getSize() < 1)\r
-    {\r
-      ap.av.hideSequence(new SequenceI[]\r
-                         {seq});\r
-      return;\r
-    }\r
-\r
-    ap.av.setSelectionGroup(null);\r
-\r
-    if (representGroup)\r
-    {\r
-      ap.av.hideRepSequences(seq, sg);\r
-\r
-      return;\r
-    }\r
-\r
-    int gsize = sg.getSize();\r
-    SequenceI[] hseqs;\r
-\r
-    hseqs = new SequenceI[gsize];\r
-\r
-    int index = 0;\r
-    for (int i = 0; i < gsize; i++)\r
-    {\r
-      hseqs[index++] = sg.getSequenceAt(i);\r
-    }\r
-\r
-    ap.av.hideSequence(hseqs);\r
-  }\r
-\r
-}\r
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer
+ * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
+ */
+
+package jalview.appletgui;
+
+import java.util.*;
+
+import java.awt.*;
+import java.awt.event.*;
+
+import jalview.analysis.*;
+import jalview.commands.*;
+import jalview.datamodel.*;
+import jalview.schemes.*;
+import jalview.io.AppletFormatAdapter;
+
+public class APopupMenu
+    extends java.awt.PopupMenu implements ActionListener, ItemListener
+{
+  Menu groupMenu = new Menu();
+  MenuItem editGroupName = new MenuItem();
+  protected MenuItem clustalColour = new MenuItem();
+  protected MenuItem zappoColour = new MenuItem();
+  protected MenuItem taylorColour = new MenuItem();
+  protected MenuItem hydrophobicityColour = new MenuItem();
+  protected MenuItem helixColour = new MenuItem();
+  protected MenuItem strandColour = new MenuItem();
+  protected MenuItem turnColour = new MenuItem();
+  protected MenuItem buriedColour = new MenuItem();
+  protected CheckboxMenuItem abovePIDColour = new CheckboxMenuItem();
+  protected MenuItem userDefinedColour = new MenuItem();
+  protected MenuItem PIDColour = new MenuItem();
+  protected MenuItem BLOSUM62Colour = new MenuItem();
+  MenuItem noColourmenuItem = new MenuItem();
+  protected CheckboxMenuItem conservationMenuItem = new CheckboxMenuItem();
+
+  final AlignmentPanel ap;
+  MenuItem unGroupMenuItem = new MenuItem();
+  MenuItem nucleotideMenuItem = new MenuItem();
+  Menu colourMenu = new Menu();
+  CheckboxMenuItem showBoxes = new CheckboxMenuItem();
+  CheckboxMenuItem showText = new CheckboxMenuItem();
+  CheckboxMenuItem showColourText = new CheckboxMenuItem();
+  Menu editMenu = new Menu("Edit");
+  MenuItem copy = new MenuItem("Copy (Jalview Only)");
+  MenuItem cut = new MenuItem("Cut (Jalview Only)");
+  MenuItem toUpper = new MenuItem("To Upper Case");
+  MenuItem toLower = new MenuItem("To Lower Case");
+  MenuItem toggleCase = new MenuItem("Toggle Case");
+  Menu outputmenu = new Menu();
+  Menu seqMenu = new Menu();
+  MenuItem pdb = new MenuItem();
+  MenuItem hideSeqs = new MenuItem();
+  MenuItem repGroup = new MenuItem();
+  MenuItem sequenceName = new MenuItem("Edit Name/Description");
+  MenuItem sequenceFeature = new MenuItem("Create Sequence Feature");
+  MenuItem editSequence = new MenuItem("Edit Sequence");
+
+  Sequence seq;
+  MenuItem revealAll = new MenuItem();
+  Menu menu1 = new Menu();
+
+  public APopupMenu(AlignmentPanel apanel, final Sequence seq, Vector links)
+  {
+    ///////////////////////////////////////////////////////////
+    // If this is activated from the sequence panel, the user may want to
+    // edit or annotate a particular residue. Therefore display the residue menu
+    //
+    // If from the IDPanel, we must display the sequence menu
+    //////////////////////////////////////////////////////////
+
+    this.ap = apanel;
+    this.seq = seq;
+
+    try
+    {
+      jbInit();
+    }
+    catch (Exception e)
+    {
+      e.printStackTrace();
+    }
+
+    for (int i = 0; i < jalview.io.AppletFormatAdapter.WRITEABLE_FORMATS.length;
+         i++)
+    {
+      MenuItem item = new MenuItem(jalview.io.AppletFormatAdapter.
+                                   WRITEABLE_FORMATS[i]);
+
+      item.addActionListener(this);
+      outputmenu.add(item);
+    }
+
+    SequenceGroup sg = ap.av.getSelectionGroup();
+
+    if (sg != null && sg.getSize() > 0)
+    {
+      editGroupName.setLabel(sg.getName());
+      showText.setState(sg.getDisplayText());
+      showColourText.setState(sg.getColourText());
+      showBoxes.setState(sg.getDisplayBoxes());
+      if (!ap.av.alignment.getGroups().contains(sg))
+      {
+        groupMenu.remove(unGroupMenuItem);
+      }
+
+    }
+    else
+    {
+      remove(hideSeqs);
+      remove(groupMenu);
+    }
+
+    if (links != null && links.size()>0)
+    {
+      Menu linkMenu = new Menu("Link");
+      String link;
+      for (int i = 0; i < links.size(); i++)
+      {
+        link = links.elementAt(i).toString();
+        final String target = link.substring(0, link.indexOf("|"));
+        
+        final String url;
+
+        if (link.indexOf("$SEQUENCE_ID$") > -1)
+        {
+          // Substitute SEQUENCE_ID string and any matching database reference accessions
+          String url_pref = link.substring(link.indexOf("|") + 1,
+                  link.indexOf("$SEQUENCE_ID$"));
+          
+          String url_suff = link.substring(link.indexOf("$SEQUENCE_ID$") + 13); 
+
+          // collect matching db-refs
+          DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(seq.getDBRef(), new String[]{target});
+          // collect id string too
+          String id = seq.getName();
+          if (id.indexOf("|") > -1)
+          {
+            id = id.substring(id.lastIndexOf("|") + 1);
+          }
+          if (dbr!=null)
+          {
+            for (int r=0;r<dbr.length; r++)
+            {
+              if (dbr[r].getAccessionId().equals(id))
+              {
+                // suppress duplicate link creation for the bare sequence ID string with this link
+                id = null;
+              }
+              addshowLink(linkMenu, dbr[r].getSource()+"|"+dbr[r].getAccessionId(), target,
+                      url_pref+dbr[r].getAccessionId()+url_suff);
+            }
+          }
+          if (id!=null)
+          {
+            // create Bare ID link for this RUL
+            addshowLink(linkMenu, target,  url_pref + id + url_suff);
+          }
+        } else {
+          addshowLink(linkMenu, target, link.substring(link.lastIndexOf("|")+1));
+        }
+      }
+    
+      if (seq != null)
+      {
+        seqMenu.add(linkMenu);
+      }
+      else
+      {
+        add(linkMenu);
+      }
+    }
+    if (seq != null)
+    {
+      seqMenu.setLabel(seq.getName());
+      repGroup.setLabel("Represent Group with " + seq.getName());
+    }
+    else
+    {
+      remove(seqMenu);
+    }
+
+    if (!ap.av.hasHiddenRows)
+    {
+      remove(revealAll);
+    }
+  }
+  /**
+   * add a show URL menu item to the given linkMenu
+   * @param linkMenu
+   * @param target - menu label string
+   * @param url - url to open
+   */
+  private void addshowLink(Menu linkMenu, final String target, final String url)
+  {
+    addshowLink(linkMenu, target, target, url);
+  }
+  /**
+   * add a show URL menu item to the given linkMenu
+   * @param linkMenu
+   * @param target - URL target window
+   * @param label - menu label string
+   * @param url - url to open
+   */
+  private void addshowLink(Menu linkMenu, final String target, final String label, final String url)
+  {
+    MenuItem item = new MenuItem(label);
+    item.addActionListener(new java.awt.event.ActionListener()
+    {
+      public void actionPerformed(ActionEvent e)
+      {
+        ap.alignFrame.showURL(url, target);
+      }
+    });
+    linkMenu.add(item);
+  }
+
+  public void itemStateChanged(ItemEvent evt)
+  {
+    if (evt.getSource() == abovePIDColour)
+    {
+      abovePIDColour_itemStateChanged();
+    }
+    else if (evt.getSource() == showColourText)
+    {
+      showColourText_itemStateChanged();
+    }
+    else if (evt.getSource() == showText)
+    {
+      showText_itemStateChanged();
+    }
+    else if (evt.getSource() == showBoxes)
+    {
+      showBoxes_itemStateChanged();
+    }
+  }
+
+  public void actionPerformed(ActionEvent evt)
+  {
+    Object source = evt.getSource();
+    if (source == clustalColour)
+    {
+      clustalColour_actionPerformed();
+    }
+    else if (source == zappoColour)
+    {
+      zappoColour_actionPerformed();
+    }
+    else if (source == taylorColour)
+    {
+      taylorColour_actionPerformed();
+    }
+    else if (source == hydrophobicityColour)
+    {
+      hydrophobicityColour_actionPerformed();
+    }
+    else if (source == helixColour)
+    {
+      helixColour_actionPerformed();
+    }
+    else if (source == strandColour)
+    {
+      strandColour_actionPerformed();
+    }
+    else if (source == turnColour)
+    {
+      turnColour_actionPerformed();
+    }
+    else if (source == buriedColour)
+    {
+      buriedColour_actionPerformed();
+    }
+    else if (source == nucleotideMenuItem)
+    {
+      nucleotideMenuItem_actionPerformed();
+    }
+
+    else if (source == userDefinedColour)
+    {
+      userDefinedColour_actionPerformed();
+    }
+    else if (source == PIDColour)
+    {
+      PIDColour_actionPerformed();
+    }
+    else if (source == BLOSUM62Colour)
+    {
+      BLOSUM62Colour_actionPerformed();
+    }
+    else if (source == noColourmenuItem)
+    {
+      noColourmenuItem_actionPerformed();
+    }
+    else if (source == conservationMenuItem)
+    {
+      conservationMenuItem_itemStateChanged();
+    }
+    else if (source == unGroupMenuItem)
+    {
+      unGroupMenuItem_actionPerformed();
+    }
+
+    else if (source == sequenceName)
+    {
+      editName();
+    }
+    else if (source == pdb)
+    {
+      addPDB();
+    }
+    else if (source == hideSeqs)
+    {
+      hideSequences(false);
+    }
+    else if (source == repGroup)
+    {
+      hideSequences(true);
+    }
+    else if (source == revealAll)
+    {
+      ap.av.showAllHiddenSeqs();
+    }
+
+    else if (source == editGroupName)
+    {
+      EditNameDialog dialog = new EditNameDialog(
+          getGroup().getName(),
+          getGroup().getDescription(),
+          "       Group Name",
+          "Group Description",
+          ap.alignFrame,
+          "Edit Group Name / Description",
+          500,100, true);
+
+      if (dialog.accept)
+      {
+        getGroup().setName(dialog.getName().replace(' ', '_'));
+        getGroup().setDescription(dialog.getDescription());
+      }
+
+    }
+    else if (source == copy)
+    {
+      ap.alignFrame.copy_actionPerformed();
+    }
+    else if (source == cut)
+    {
+      ap.alignFrame.cut_actionPerformed();
+    }
+    else if(source == editSequence)
+    {
+      SequenceGroup sg = ap.av.getSelectionGroup();
+
+      if(sg!=null)
+      {
+        if (seq == null)
+          seq = (Sequence) sg.getSequenceAt(0);
+
+        EditNameDialog dialog = new EditNameDialog(seq.getSequenceAsString(
+            sg.getStartRes(),
+            sg.getEndRes() + 1),
+                                                   null,
+                                                   "Edit Sequence ",
+                                                   null,
+
+                                                   ap.alignFrame,
+                                                   "Edit Sequence",
+                                                   500, 100, true);
+
+        if (dialog.accept)
+        {
+          EditCommand editCommand = new EditCommand(
+              "Edit Sequences", EditCommand.REPLACE,
+              dialog.getName().replace(' ', ap.av.getGapCharacter()),
+              sg.getSequencesAsArray(ap.av.hiddenRepSequences),
+              sg.getStartRes(), sg.getEndRes()+1, ap.av.alignment
+              );
+
+          ap.alignFrame.addHistoryItem(editCommand);
+
+          ap.av.firePropertyChange("alignment", null,
+                                 ap.av.getAlignment().getSequences());
+        }
+      }
+    }
+    else if (source == toUpper || source == toLower || source == toggleCase)
+    {
+      SequenceGroup sg = ap.av.getSelectionGroup();
+      Vector regions = new Vector();
+      if (sg != null)
+      {
+        int start = sg.getStartRes();
+        int end = sg.getEndRes() + 1;
+
+        do
+        {
+          if (ap.av.hasHiddenColumns)
+          {
+            if (start == 0)
+            {
+              start = ap.av.colSel.adjustForHiddenColumns(start);
+            }
+
+            end = ap.av.colSel.getHiddenBoundaryRight(start);
+            if (start == end)
+            {
+              end = sg.getEndRes() + 1;
+            }
+            if (end > sg.getEndRes())
+            {
+              end = sg.getEndRes() + 1;
+            }
+          }
+
+          regions.addElement(new int[]
+                             {start, end});
+
+          if (ap.av.hasHiddenColumns)
+          {
+            start = ap.av.colSel.adjustForHiddenColumns(end);
+            start = ap.av.colSel.getHiddenBoundaryLeft(start) + 1;
+          }
+        }
+        while (end < sg.getEndRes());
+
+        int[][] startEnd = new int[regions.size()][2];
+        for (int i = 0; i < regions.size(); i++)
+        {
+          startEnd[i] = (int[]) regions.elementAt(i);
+        }
+
+        String description;
+        int caseChange;
+
+        if (source == toggleCase)
+        {
+          description = "Toggle Case";
+          caseChange = ChangeCaseCommand.TOGGLE_CASE;
+        }
+        else if (source == toUpper)
+        {
+          description = "To Upper Case";
+          caseChange = ChangeCaseCommand.TO_UPPER;
+        }
+        else
+        {
+          description = "To Lower Case";
+          caseChange = ChangeCaseCommand.TO_LOWER;
+        }
+
+        ChangeCaseCommand caseCommand = new ChangeCaseCommand(
+            description, sg.getSequencesAsArray(ap.av.hiddenRepSequences),
+            startEnd, caseChange
+            );
+
+        ap.alignFrame.addHistoryItem(caseCommand);
+
+        ap.av.firePropertyChange("alignment", null,
+                                 ap.av.getAlignment().getSequences());
+
+      }
+    }
+    else if(source == sequenceFeature)
+    {
+      SequenceGroup sg = ap.av.getSelectionGroup();
+      if (sg == null)
+      {
+        return;
+      }
+
+      int gSize = sg.getSize();
+      SequenceI[] seqs = new SequenceI[gSize];
+      SequenceFeature[] features = new SequenceFeature[gSize];
+
+      for (int i = 0; i < gSize; i++)
+      {
+        seqs[i] = sg.getSequenceAt(i);
+        int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
+        int end = sg.findEndRes(sg.getSequenceAt(i));
+        features[i] = new SequenceFeature(null, null, null, start, end,
+                                          "Jalview");
+      }
+
+      if (ap.seqPanel.seqCanvas.getFeatureRenderer()
+          .amendFeatures(seqs, features, true, ap))
+      {
+        ap.alignFrame.sequenceFeatures.setState(true);
+        ap.av.showSequenceFeatures(true);
+        ap.highlightSearchResults(null);
+      }
+    }
+    else
+    {
+      outputText(evt);
+    }
+
+  }
+
+  void outputText(ActionEvent e)
+  {
+    CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
+
+    Frame frame = new Frame();
+    frame.add(cap);
+    jalview.bin.JalviewLite.addFrame(frame,
+                                     "Selection output - " + e.getActionCommand(),
+                                     600, 500);
+
+    cap.setText(new jalview.io.AppletFormatAdapter().formatSequences(
+        e.getActionCommand(),
+        new Alignment(ap.av.getSelectionAsNewSequence()),
+        ap.av.showJVSuffix));
+
+  }
+
+  void editName()
+  {
+    EditNameDialog dialog = new EditNameDialog(
+        seq.getName(),
+        seq.getDescription(),
+        "       Sequence Name",
+        "Sequence Description",
+        ap.alignFrame,
+        "Edit Sequence Name / Description",
+        500,100, true);
+
+    if (dialog.accept)
+    {
+      seq.setName(dialog.getName());
+      seq.setDescription(dialog.getDescription());
+      ap.paintAlignment(false);
+    }
+  }
+
+  void addPDB()
+  {
+    if(seq.getPDBId()!=null)
+    {
+      PDBEntry entry = (PDBEntry)seq.getPDBId().firstElement();
+
+      if ( ap.av.applet.jmolAvailable )
+       new jalview.appletgui.AppletJmol(entry,
+                                        new Sequence[]{seq},
+                                        null,
+                                        ap,
+                                        AppletFormatAdapter.URL);
+     else
+       new MCview.AppletPDBViewer(entry,
+                                  new Sequence[]{seq},
+                                  null,
+                                  ap,
+                                  AppletFormatAdapter.URL);
+
+    }
+    else
+    {
+      CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
+      cap.setText("Paste your PDB file here.");
+      cap.setPDBImport(seq);
+      Frame frame = new Frame();
+      frame.add(cap);
+      jalview.bin.JalviewLite.addFrame(frame, "Paste PDB file ", 400, 300);
+    }
+  }
+
+  private void jbInit()
+      throws Exception
+  {
+    groupMenu.setLabel("Group");
+    groupMenu.setLabel("Selection");
+    sequenceFeature.addActionListener(this);
+
+    editGroupName.addActionListener(this);
+    unGroupMenuItem.setLabel("Remove Group");
+    unGroupMenuItem.addActionListener(this);
+
+    nucleotideMenuItem.setLabel("Nucleotide");
+    nucleotideMenuItem.addActionListener(this);
+    conservationMenuItem.addItemListener(this);
+    abovePIDColour.addItemListener(this);
+    colourMenu.setLabel("Group Colour");
+    showBoxes.setLabel("Boxes");
+    showBoxes.setState(true);
+    showBoxes.addItemListener(this);
+    sequenceName.addActionListener(this);
+
+    showText.setLabel("Text");
+    showText.addItemListener(this);
+    showColourText.setLabel("Colour Text");
+    showColourText.addItemListener(this);
+    outputmenu.setLabel("Output to Textbox...");
+    seqMenu.setLabel("Sequence");
+    pdb.setLabel("View PDB Structure");
+    hideSeqs.setLabel("Hide Sequences");
+    repGroup.setLabel("Represent Group with");
+    revealAll.setLabel("Reveal All");
+    menu1.setLabel("Group");
+    add(groupMenu);
+    this.add(seqMenu);
+    this.add(hideSeqs);
+    this.add(revealAll);
+    groupMenu.add(editGroupName);
+    groupMenu.add(editMenu);
+    groupMenu.add(outputmenu);
+    groupMenu.add(sequenceFeature);
+    groupMenu.add(menu1);
+
+    colourMenu.add(noColourmenuItem);
+    colourMenu.add(clustalColour);
+    colourMenu.add(BLOSUM62Colour);
+    colourMenu.add(PIDColour);
+    colourMenu.add(zappoColour);
+    colourMenu.add(taylorColour);
+    colourMenu.add(hydrophobicityColour);
+    colourMenu.add(helixColour);
+    colourMenu.add(strandColour);
+    colourMenu.add(turnColour);
+    colourMenu.add(buriedColour);
+    colourMenu.add(nucleotideMenuItem);
+    colourMenu.add(userDefinedColour);
+    colourMenu.addSeparator();
+    colourMenu.add(abovePIDColour);
+    colourMenu.add(conservationMenuItem);
+
+    noColourmenuItem.setLabel("None");
+    noColourmenuItem.addActionListener(this);
+
+    clustalColour.setLabel("Clustalx colours");
+    clustalColour.addActionListener(this);
+    zappoColour.setLabel("Zappo");
+    zappoColour.addActionListener(this);
+    taylorColour.setLabel("Taylor");
+    taylorColour.addActionListener(this);
+    hydrophobicityColour.setLabel("Hydrophobicity");
+    hydrophobicityColour.addActionListener(this);
+    helixColour.setLabel("Helix propensity");
+    helixColour.addActionListener(this);
+    strandColour.setLabel("Strand propensity");
+    strandColour.addActionListener(this);
+    turnColour.setLabel("Turn propensity");
+    turnColour.addActionListener(this);
+    buriedColour.setLabel("Buried Index");
+    buriedColour.addActionListener(this);
+    abovePIDColour.setLabel("Above % Identity");
+
+    userDefinedColour.setLabel("User Defined");
+    userDefinedColour.addActionListener(this);
+    PIDColour.setLabel("Percentage Identity");
+    PIDColour.addActionListener(this);
+    BLOSUM62Colour.setLabel("BLOSUM62");
+    BLOSUM62Colour.addActionListener(this);
+    conservationMenuItem.setLabel("Conservation");
+
+    editMenu.add(copy);
+    copy.addActionListener(this);
+    editMenu.add(cut);
+    cut.addActionListener(this);
+
+    editMenu.add(editSequence);
+    editSequence.addActionListener(this);
+
+    editMenu.add(toUpper);
+    toUpper.addActionListener(this);
+    editMenu.add(toLower);
+    toLower.addActionListener(this);
+    editMenu.add(toggleCase);
+    seqMenu.add(sequenceName);
+    seqMenu.add(pdb);
+    seqMenu.add(repGroup);
+    menu1.add(unGroupMenuItem);
+    menu1.add(colourMenu);
+    menu1.add(showBoxes);
+    menu1.add(showText);
+    menu1.add(showColourText);
+    toggleCase.addActionListener(this);
+    pdb.addActionListener(this);
+    hideSeqs.addActionListener(this);
+    repGroup.addActionListener(this);
+    revealAll.addActionListener(this);
+  }
+
+  void refresh()
+  {
+    ap.paintAlignment(true);
+  }
+
+  protected void clustalColour_actionPerformed()
+  {
+    SequenceGroup sg = getGroup();
+    sg.cs = new ClustalxColourScheme(sg.getSequences(ap.av.hiddenRepSequences),
+                                     ap.av.alignment.getWidth());
+    refresh();
+  }
+
+  protected void zappoColour_actionPerformed()
+  {
+    getGroup().cs = new ZappoColourScheme();
+    refresh();
+  }
+
+  protected void taylorColour_actionPerformed()
+  {
+    getGroup().cs = new TaylorColourScheme();
+    refresh();
+  }
+
+  protected void hydrophobicityColour_actionPerformed()
+  {
+    getGroup().cs = new HydrophobicColourScheme();
+    refresh();
+  }
+
+  protected void helixColour_actionPerformed()
+  {
+    getGroup().cs = new HelixColourScheme();
+    refresh();
+  }
+
+  protected void strandColour_actionPerformed()
+  {
+    getGroup().cs = new StrandColourScheme();
+    refresh();
+  }
+
+  protected void turnColour_actionPerformed()
+  {
+    getGroup().cs = new TurnColourScheme();
+    refresh();
+  }
+
+  protected void buriedColour_actionPerformed()
+  {
+    getGroup().cs = new BuriedColourScheme();
+    refresh();
+  }
+
+  public void nucleotideMenuItem_actionPerformed()
+  {
+    getGroup().cs = new NucleotideColourScheme();
+    refresh();
+  }
+
+  protected void abovePIDColour_itemStateChanged()
+  {
+    SequenceGroup sg = getGroup();
+    if (sg.cs == null)
+    {
+      return;
+    }
+
+    if (abovePIDColour.getState())
+    {
+      sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av.
+          hiddenRepSequences), 0,
+                                               ap.av.alignment.getWidth()));
+      int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs,
+          getGroup().getName());
+
+      sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus());
+
+      SliderPanel.showPIDSlider();
+
+    }
+    else // remove PIDColouring
+    {
+      sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
+    }
+
+    refresh();
+
+  }
+
+  protected void userDefinedColour_actionPerformed()
+  {
+    new UserDefinedColours(ap, getGroup());
+  }
+
+  protected void PIDColour_actionPerformed()
+  {
+    SequenceGroup sg = getGroup();
+    sg.cs = new PIDColourScheme();
+    sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av.
+        hiddenRepSequences), 0,
+                                             ap.av.alignment.getWidth()));
+    refresh();
+  }
+
+  protected void BLOSUM62Colour_actionPerformed()
+  {
+    SequenceGroup sg = getGroup();
+
+    sg.cs = new Blosum62ColourScheme();
+
+    sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av.
+        hiddenRepSequences), 0,
+                                             ap.av.alignment.getWidth()));
+
+    refresh();
+  }
+
+  protected void noColourmenuItem_actionPerformed()
+  {
+    getGroup().cs = null;
+    refresh();
+  }
+
+  protected void conservationMenuItem_itemStateChanged()
+  {
+    SequenceGroup sg = getGroup();
+    if (sg.cs == null)
+    {
+      return;
+    }
+
+    if (conservationMenuItem.getState())
+    {
+
+      Conservation c = new Conservation("Group",
+                                        ResidueProperties.propHash, 3,
+                                        sg.getSequences(ap.av.
+          hiddenRepSequences), 0,
+                                        ap.av.alignment.getWidth());
+
+      c.calculate();
+      c.verdict(false, ap.av.ConsPercGaps);
+
+      sg.cs.setConservation(c);
+
+      SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
+      SliderPanel.showConservationSlider();
+    }
+    else // remove ConservationColouring
+    {
+      sg.cs.setConservation(null);
+    }
+
+    refresh();
+  }
+
+  SequenceGroup getGroup()
+  {
+    SequenceGroup sg = ap.av.getSelectionGroup();
+
+    // this method won't add a new group if it already exists
+    if (sg != null)
+    {
+      ap.av.alignment.addGroup(sg);
+    }
+
+    return sg;
+  }
+
+  void unGroupMenuItem_actionPerformed()
+  {
+    SequenceGroup sg = ap.av.getSelectionGroup();
+    ap.av.alignment.deleteGroup(sg);
+    ap.av.setSelectionGroup(null);
+    ap.paintAlignment(true);
+  }
+
+  public void showColourText_itemStateChanged()
+  {
+    getGroup().setColourText(showColourText.getState());
+    refresh();
+  }
+
+  public void showText_itemStateChanged()
+  {
+    getGroup().setDisplayText(showText.getState());
+    refresh();
+  }
+
+  public void showBoxes_itemStateChanged()
+  {
+    getGroup().setDisplayBoxes(showBoxes.getState());
+    refresh();
+  }
+
+  void hideSequences(boolean representGroup)
+  {
+    SequenceGroup sg = ap.av.getSelectionGroup();
+    if (sg == null || sg.getSize() < 1)
+    {
+      ap.av.hideSequence(new SequenceI[]
+                         {seq});
+      return;
+    }
+
+    ap.av.setSelectionGroup(null);
+
+    if (representGroup)
+    {
+      ap.av.hideRepSequences(seq, sg);
+
+      return;
+    }
+
+    int gsize = sg.getSize();
+    SequenceI[] hseqs;
+
+    hseqs = new SequenceI[gsize];
+
+    int index = 0;
+    for (int i = 0; i < gsize; i++)
+    {
+      hseqs[index++] = sg.getSequenceAt(i);
+    }
+
+    ap.av.hideSequence(hseqs);
+  }
+
+}
index 01a0907..546ce65 100755 (executable)
@@ -361,41 +361,54 @@ public class PopupMenu
     if (links != null && links.size() > 0)
     {
       JMenu linkMenu = new JMenu("Link");
-      JMenuItem item;
+
       for (int i = 0; i < links.size(); i++)
       {
         String link = links.elementAt(i).toString();
         final String label = link.substring(0, link.indexOf("|"));
-        item = new JMenuItem(label);
-        final String url;
-
+        
+        
         if (link.indexOf("$SEQUENCE_ID$") > -1)
         {
+          // Substitute SEQUENCE_ID string and any matching database reference accessions
+          String url_pref = link.substring(link.indexOf("|") + 1,
+                  link.indexOf("$SEQUENCE_ID$"));
+          
+          String url_suff = link.substring(link.indexOf("$SEQUENCE_ID$") + 13); 
+
+          // collect matching db-refs
+          DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(seq.getDBRef(), new String[]{label});
+          // collect id string too
           String id = seq.getName();
           if (id.indexOf("|") > -1)
           {
             id = id.substring(id.lastIndexOf("|") + 1);
           }
 
-          url = link.substring(link.indexOf("|") + 1,
-                               link.indexOf("$SEQUENCE_ID$"))
-              + id +
-              link.substring(link.indexOf("$SEQUENCE_ID$") + 13);
+          if (dbr!=null)
+          {
+            for (int r=0;r<dbr.length; r++)
+            {
+              if (dbr[r].getAccessionId().equals(id))
+              {
+                // suppress duplicate link creation for the bare sequence ID string with this link
+                id = null;
+              }
+              addshowLink(linkMenu, dbr[r].getSource()+"|"+dbr[r].getAccessionId(), 
+                      url_pref+dbr[r].getAccessionId()+url_suff);
+            }
+          }
+          if (id!=null)
+          {
+            // create Bare ID link for this RUL
+            addshowLink(linkMenu, label,  url_pref + id + url_suff);
+          }
         }
         else
         {
-          url = link.substring(link.lastIndexOf("|") + 1);
+          // Add a non-dynamic link
+          addshowLink(linkMenu, label, link.substring(link.lastIndexOf("|") + 1));
         }
-
-        item.addActionListener(new java.awt.event.ActionListener()
-        {
-          public void actionPerformed(ActionEvent e)
-          {
-            showLink(url);
-          }
-        });
-
-        linkMenu.add(item);
       }
       if (sequence != null)
       {
@@ -409,6 +422,33 @@ public class PopupMenu
   }
 
   /**
+   * add a show URL menu item to the given linkMenu
+   * @param linkMenu
+   * @param label - menu label string
+   * @param url - url to open
+   */
+  private void addshowLink(JMenu linkMenu, String label, final String url)
+  {
+    JMenuItem item = new JMenuItem(label);
+    item.addActionListener(new java.awt.event.ActionListener()
+    {
+      public void actionPerformed(ActionEvent e)
+      {
+        new Thread(new Runnable() {
+
+          public void run()
+          {
+            showLink(url);
+          }
+          
+        }).start();
+      }
+    });
+
+    linkMenu.add(item);    
+  }
+
+  /**
    * DOCUMENT ME!
    *
    * @throws Exception DOCUMENT ME!