2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.4)
3 * Copyright (C) 2008 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License
7 * as published by the Free Software Foundation; either version 2
8 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 import java.awt.event.*;
28 import jalview.analysis.*;
29 import jalview.commands.*;
30 import jalview.datamodel.*;
32 import jalview.schemes.*;
33 import jalview.util.UrlLink;
41 public class PopupMenu extends JPopupMenu
43 JMenu groupMenu = new JMenu();
45 JMenuItem groupName = new JMenuItem();
47 protected JRadioButtonMenuItem clustalColour = new JRadioButtonMenuItem();
49 protected JRadioButtonMenuItem zappoColour = new JRadioButtonMenuItem();
51 protected JRadioButtonMenuItem taylorColour = new JRadioButtonMenuItem();
53 protected JRadioButtonMenuItem hydrophobicityColour = new JRadioButtonMenuItem();
55 protected JRadioButtonMenuItem helixColour = new JRadioButtonMenuItem();
57 protected JRadioButtonMenuItem strandColour = new JRadioButtonMenuItem();
59 protected JRadioButtonMenuItem turnColour = new JRadioButtonMenuItem();
61 protected JRadioButtonMenuItem buriedColour = new JRadioButtonMenuItem();
63 protected JCheckBoxMenuItem abovePIDColour = new JCheckBoxMenuItem();
65 protected JRadioButtonMenuItem userDefinedColour = new JRadioButtonMenuItem();
67 protected JRadioButtonMenuItem PIDColour = new JRadioButtonMenuItem();
69 protected JRadioButtonMenuItem BLOSUM62Colour = new JRadioButtonMenuItem();
71 JRadioButtonMenuItem noColourmenuItem = new JRadioButtonMenuItem();
73 protected JCheckBoxMenuItem conservationMenuItem = new JCheckBoxMenuItem();
77 JMenu sequenceMenu = new JMenu();
79 JMenuItem sequenceName = new JMenuItem();
83 JMenuItem unGroupMenuItem = new JMenuItem();
85 JMenuItem outline = new JMenuItem();
87 JRadioButtonMenuItem nucleotideMenuItem = new JRadioButtonMenuItem();
89 JMenu colourMenu = new JMenu();
91 JCheckBoxMenuItem showBoxes = new JCheckBoxMenuItem();
93 JCheckBoxMenuItem showText = new JCheckBoxMenuItem();
95 JCheckBoxMenuItem showColourText = new JCheckBoxMenuItem();
97 JMenu editMenu = new JMenu();
99 JMenuItem cut = new JMenuItem();
101 JMenuItem copy = new JMenuItem();
103 JMenuItem upperCase = new JMenuItem();
105 JMenuItem lowerCase = new JMenuItem();
107 JMenuItem toggle = new JMenuItem();
109 JMenu pdbMenu = new JMenu();
111 JMenuItem pdbFromFile = new JMenuItem();
113 JMenuItem enterPDB = new JMenuItem();
115 JMenuItem discoverPDB = new JMenuItem();
117 JMenu outputMenu = new JMenu();
119 JMenuItem sequenceFeature = new JMenuItem();
121 JMenuItem textColour = new JMenuItem();
123 JMenu jMenu1 = new JMenu();
125 JMenu structureMenu = new JMenu();
127 JMenu viewStructureMenu = new JMenu();
129 // JMenu colStructureMenu = new JMenu();
130 JMenuItem editSequence = new JMenuItem();
132 // JMenuItem annotationMenuItem = new JMenuItem();
135 * Creates a new PopupMenu object.
142 public PopupMenu(final AlignmentPanel ap, Sequence seq, Vector links)
144 // /////////////////////////////////////////////////////////
145 // If this is activated from the sequence panel, the user may want to
146 // edit or annotate a particular residue. Therefore display the residue menu
148 // If from the IDPanel, we must display the sequence menu
149 // ////////////////////////////////////////////////////////
153 ButtonGroup colours = new ButtonGroup();
154 colours.add(noColourmenuItem);
155 colours.add(clustalColour);
156 colours.add(zappoColour);
157 colours.add(taylorColour);
158 colours.add(hydrophobicityColour);
159 colours.add(helixColour);
160 colours.add(strandColour);
161 colours.add(turnColour);
162 colours.add(buriedColour);
163 colours.add(abovePIDColour);
164 colours.add(userDefinedColour);
165 colours.add(PIDColour);
166 colours.add(BLOSUM62Colour);
168 for (int i = 0; i < jalview.io.FormatAdapter.WRITEABLE_FORMATS.length; i++)
170 JMenuItem item = new JMenuItem(
171 jalview.io.FormatAdapter.WRITEABLE_FORMATS[i]);
173 item.addActionListener(new java.awt.event.ActionListener()
175 public void actionPerformed(ActionEvent e)
177 outputText_actionPerformed(e);
181 outputMenu.add(item);
187 } catch (Exception e)
194 sequenceMenu.setText(sequence.getName());
197 if (seq.getDatasetSequence().getPDBId() != null
198 && seq.getDatasetSequence().getPDBId().size() > 0)
200 java.util.Enumeration e = seq.getDatasetSequence().getPDBId()
203 while (e.hasMoreElements())
205 final PDBEntry pdb = (PDBEntry) e.nextElement();
207 menuItem = new JMenuItem();
208 menuItem.setText(pdb.getId());
209 menuItem.addActionListener(new java.awt.event.ActionListener()
211 public void actionPerformed(ActionEvent e)
213 Vector seqs = new Vector();
214 for (int i = 0; i < ap.av.alignment.getHeight(); i++)
216 Vector pdbs = ap.av.alignment.getSequenceAt(i)
217 .getDatasetSequence().getPDBId();
221 for (int p = 0; p < pdbs.size(); p++)
223 PDBEntry p1 = (PDBEntry) pdbs.elementAt(p);
224 if (p1.getId().equals(pdb.getId()))
226 if (!seqs.contains(ap.av.alignment.getSequenceAt(i)))
227 seqs.addElement(ap.av.alignment.getSequenceAt(i));
234 SequenceI[] seqs2 = new SequenceI[seqs.size()];
237 new AppJmol(pdb, seqs2, null, ap);
238 // new PDBViewer(pdb, seqs2, null, ap, AppletFormatAdapter.FILE);
241 viewStructureMenu.add(menuItem);
244 * menuItem = new JMenuItem(); menuItem.setText(pdb.getId());
245 * menuItem.addActionListener(new java.awt.event.ActionListener() {
246 * public void actionPerformed(ActionEvent e) {
247 * colourByStructure(pdb.getId()); } });
248 * colStructureMenu.add(menuItem);
254 structureMenu.remove(viewStructureMenu);
255 // structureMenu.remove(colStructureMenu);
258 menuItem = new JMenuItem("Hide Sequences");
259 menuItem.addActionListener(new java.awt.event.ActionListener()
261 public void actionPerformed(ActionEvent e)
263 hideSequences(false);
268 if (ap.av.getSelectionGroup() != null
269 && ap.av.getSelectionGroup().getSize() > 1)
271 menuItem = new JMenuItem("Represent Group with " + seq.getName());
272 menuItem.addActionListener(new java.awt.event.ActionListener()
274 public void actionPerformed(ActionEvent e)
279 sequenceMenu.add(menuItem);
282 if (ap.av.hasHiddenRows)
284 final int index = ap.av.alignment.findIndex(seq);
286 if (ap.av.adjustForHiddenSeqs(index)
287 - ap.av.adjustForHiddenSeqs(index - 1) > 1)
289 menuItem = new JMenuItem("Reveal Sequences");
290 menuItem.addActionListener(new ActionListener()
292 public void actionPerformed(ActionEvent e)
294 ap.av.showSequence(index);
295 if (ap.overviewPanel != null)
297 ap.overviewPanel.updateOverviewImage();
304 menuItem = new JMenuItem("Reveal All");
305 menuItem.addActionListener(new ActionListener()
307 public void actionPerformed(ActionEvent e)
309 ap.av.showAllHiddenSeqs();
310 if (ap.overviewPanel != null)
312 ap.overviewPanel.updateOverviewImage();
322 SequenceGroup sg = ap.av.getSelectionGroup();
326 groupName.setText(sg.getName());
328 if (sg.cs instanceof ZappoColourScheme)
330 zappoColour.setSelected(true);
332 else if (sg.cs instanceof TaylorColourScheme)
334 taylorColour.setSelected(true);
336 else if (sg.cs instanceof PIDColourScheme)
338 PIDColour.setSelected(true);
340 else if (sg.cs instanceof Blosum62ColourScheme)
342 BLOSUM62Colour.setSelected(true);
344 else if (sg.cs instanceof UserColourScheme)
346 userDefinedColour.setSelected(true);
348 else if (sg.cs instanceof HydrophobicColourScheme)
350 hydrophobicityColour.setSelected(true);
352 else if (sg.cs instanceof HelixColourScheme)
354 helixColour.setSelected(true);
356 else if (sg.cs instanceof StrandColourScheme)
358 strandColour.setSelected(true);
360 else if (sg.cs instanceof TurnColourScheme)
362 turnColour.setSelected(true);
364 else if (sg.cs instanceof BuriedColourScheme)
366 buriedColour.setSelected(true);
368 else if (sg.cs instanceof ClustalxColourScheme)
370 clustalColour.setSelected(true);
374 noColourmenuItem.setSelected(true);
377 if (sg.cs != null && sg.cs.conservationApplied())
379 conservationMenuItem.setSelected(true);
382 showText.setSelected(sg.getDisplayText());
383 showColourText.setSelected(sg.getColourText());
384 showBoxes.setSelected(sg.getDisplayBoxes());
388 groupMenu.setVisible(false);
389 editMenu.setVisible(false);
392 if (!ap.av.alignment.getGroups().contains(sg))
394 unGroupMenuItem.setVisible(false);
399 sequenceMenu.setVisible(false);
400 structureMenu.setVisible(false);
403 if (links != null && links.size() > 0)
405 JMenu linkMenu = new JMenu("Link");
407 for (int i = 0; i < links.size(); i++)
409 String link = links.elementAt(i).toString();
410 UrlLink urlLink = null;
413 urlLink = new UrlLink(link);
414 } catch (Exception foo)
416 jalview.bin.Cache.log.error("Exception for URLLink '" + link
421 if (!urlLink.isValid())
423 jalview.bin.Cache.log.error(urlLink.getInvalidMessage());
426 final String label = urlLink.getLabel();
427 if (urlLink.isDynamic())
430 // collect matching db-refs
431 DBRefEntry[] dbr = jalview.util.DBRefUtils.selectRefs(seq
432 .getDBRef(), new String[]
433 { urlLink.getTarget() });
434 // collect id string too
435 String id = seq.getName();
436 String descr = seq.getDescription();
437 if (descr!=null && descr.length()<1)
444 for (int r = 0; r < dbr.length; r++)
446 if (id != null && dbr[r].getAccessionId().equals(id))
448 // suppress duplicate link creation for the bare sequence ID
449 // string with this link
452 // create Bare ID link for this RUL
453 String[] urls = urlLink.makeUrls(dbr[r].getAccessionId(),
457 for (int u = 0; u < urls.length; u += 2)
459 addshowLink(linkMenu, label + "|" + urls[u], urls[u + 1]);
466 // create Bare ID link for this RUL
467 String[] urls = urlLink.makeUrls(id, true);
470 for (int u = 0; u < urls.length; u += 2)
472 addshowLink(linkMenu, label, urls[u + 1]);
476 // hard-disable construction of URLs from regexes that match the description
477 // TODO: introduce a Cache preferences option to dis/en/able URl generation from description
478 // if (descr != null)
480 // // create link for this URL from description where regex matches
481 // String[] urls = urlLink.makeUrls(descr, false);
484 // for (int u = 0; u < urls.length; u += 2)
486 // addshowLink(linkMenu, label, urls[u + 1]);
493 // Add a non-dynamic link
494 addshowLink(linkMenu, label, urlLink.getUrl_prefix());
497 if (sequence != null)
499 sequenceMenu.add(linkMenu);
509 * add a show URL menu item to the given linkMenu
517 private void addshowLink(JMenu linkMenu, String label, final String url)
519 JMenuItem item = new JMenuItem(label);
520 item.setToolTipText("open URL: " + url);
521 item.addActionListener(new java.awt.event.ActionListener()
523 public void actionPerformed(ActionEvent e)
525 new Thread(new Runnable()
546 private void jbInit() throws Exception
548 groupMenu.setText("Group");
549 groupMenu.setText("Selection");
550 groupName.setText("Name");
551 groupName.addActionListener(new java.awt.event.ActionListener()
553 public void actionPerformed(ActionEvent e)
555 groupName_actionPerformed();
558 sequenceMenu.setText("Sequence");
559 sequenceName.setText("Edit Name/Description");
560 sequenceName.addActionListener(new java.awt.event.ActionListener()
562 public void actionPerformed(ActionEvent e)
564 sequenceName_actionPerformed();
567 PIDColour.setFocusPainted(false);
568 unGroupMenuItem.setText("Remove Group");
569 unGroupMenuItem.addActionListener(new java.awt.event.ActionListener()
571 public void actionPerformed(ActionEvent e)
573 unGroupMenuItem_actionPerformed();
577 outline.setText("Border colour");
578 outline.addActionListener(new java.awt.event.ActionListener()
580 public void actionPerformed(ActionEvent e)
582 outline_actionPerformed();
585 nucleotideMenuItem.setText("Nucleotide");
586 nucleotideMenuItem.addActionListener(new ActionListener()
588 public void actionPerformed(ActionEvent e)
590 nucleotideMenuItem_actionPerformed();
593 colourMenu.setText("Group Colour");
594 showBoxes.setText("Boxes");
595 showBoxes.setState(true);
596 showBoxes.addActionListener(new ActionListener()
598 public void actionPerformed(ActionEvent e)
600 showBoxes_actionPerformed();
603 showText.setText("Text");
604 showText.setState(true);
605 showText.addActionListener(new ActionListener()
607 public void actionPerformed(ActionEvent e)
609 showText_actionPerformed();
612 showColourText.setText("Colour Text");
613 showColourText.addActionListener(new ActionListener()
615 public void actionPerformed(ActionEvent e)
617 showColourText_actionPerformed();
620 editMenu.setText("Edit");
622 cut.addActionListener(new ActionListener()
624 public void actionPerformed(ActionEvent e)
626 cut_actionPerformed();
629 upperCase.setText("To Upper Case");
630 upperCase.addActionListener(new ActionListener()
632 public void actionPerformed(ActionEvent e)
637 copy.setText("Copy");
638 copy.addActionListener(new ActionListener()
640 public void actionPerformed(ActionEvent e)
642 copy_actionPerformed();
645 lowerCase.setText("To Lower Case");
646 lowerCase.addActionListener(new ActionListener()
648 public void actionPerformed(ActionEvent e)
653 toggle.setText("Toggle Case");
654 toggle.addActionListener(new ActionListener()
656 public void actionPerformed(ActionEvent e)
661 pdbMenu.setText("Associate Structure with Sequence");
662 pdbFromFile.setText("From File");
663 pdbFromFile.addActionListener(new ActionListener()
665 public void actionPerformed(ActionEvent e)
667 pdbFromFile_actionPerformed();
670 enterPDB.setText("Enter PDB Id");
671 enterPDB.addActionListener(new ActionListener()
673 public void actionPerformed(ActionEvent e)
675 enterPDB_actionPerformed();
678 discoverPDB.setText("Discover PDB ids");
679 discoverPDB.addActionListener(new ActionListener()
681 public void actionPerformed(ActionEvent e)
683 discoverPDB_actionPerformed();
686 outputMenu.setText("Output to Textbox...");
687 sequenceFeature.setText("Create Sequence Feature");
688 sequenceFeature.addActionListener(new ActionListener()
690 public void actionPerformed(ActionEvent e)
692 sequenceFeature_actionPerformed();
695 textColour.setText("Text Colour");
696 textColour.addActionListener(new ActionListener()
698 public void actionPerformed(ActionEvent e)
700 textColour_actionPerformed();
703 jMenu1.setText("Group");
704 structureMenu.setText("Structure");
705 viewStructureMenu.setText("View Structure");
706 // colStructureMenu.setText("Colour By Structure");
707 editSequence.setText("Edit Sequence...");
708 editSequence.addActionListener(new ActionListener()
710 public void actionPerformed(ActionEvent actionEvent)
712 editSequence_actionPerformed(actionEvent);
716 * annotationMenuItem.setText("By Annotation");
717 * annotationMenuItem.addActionListener(new ActionListener() { public void
718 * actionPerformed(ActionEvent actionEvent) {
719 * annotationMenuItem_actionPerformed(actionEvent); } });
725 this.add(structureMenu);
726 groupMenu.add(editMenu);
727 groupMenu.add(outputMenu);
728 groupMenu.add(sequenceFeature);
729 groupMenu.add(jMenu1);
730 sequenceMenu.add(sequenceName);
731 colourMenu.add(textColour);
732 colourMenu.add(noColourmenuItem);
733 colourMenu.add(clustalColour);
734 colourMenu.add(BLOSUM62Colour);
735 colourMenu.add(PIDColour);
736 colourMenu.add(zappoColour);
737 colourMenu.add(taylorColour);
738 colourMenu.add(hydrophobicityColour);
739 colourMenu.add(helixColour);
740 colourMenu.add(strandColour);
741 colourMenu.add(turnColour);
742 colourMenu.add(buriedColour);
743 colourMenu.add(nucleotideMenuItem);
744 colourMenu.add(userDefinedColour);
746 if (jalview.gui.UserDefinedColours.getUserColourSchemes() != null)
748 java.util.Enumeration userColours = jalview.gui.UserDefinedColours
749 .getUserColourSchemes().keys();
751 while (userColours.hasMoreElements())
753 JMenuItem item = new JMenuItem(userColours.nextElement().toString());
754 item.addActionListener(new ActionListener()
756 public void actionPerformed(ActionEvent evt)
758 userDefinedColour_actionPerformed(evt);
761 colourMenu.add(item);
765 colourMenu.addSeparator();
766 colourMenu.add(abovePIDColour);
767 colourMenu.add(conservationMenuItem);
768 // colourMenu.add(annotationMenuItem);
771 editMenu.add(editSequence);
772 editMenu.add(upperCase);
773 editMenu.add(lowerCase);
774 editMenu.add(toggle);
775 pdbMenu.add(pdbFromFile);
776 pdbMenu.add(enterPDB);
777 pdbMenu.add(discoverPDB);
778 jMenu1.add(groupName);
779 jMenu1.add(unGroupMenuItem);
780 jMenu1.add(colourMenu);
781 jMenu1.add(showBoxes);
782 jMenu1.add(showText);
783 jMenu1.add(showColourText);
785 structureMenu.add(pdbMenu);
786 structureMenu.add(viewStructureMenu);
787 // structureMenu.add(colStructureMenu);
788 noColourmenuItem.setText("None");
789 noColourmenuItem.addActionListener(new java.awt.event.ActionListener()
791 public void actionPerformed(ActionEvent e)
793 noColourmenuItem_actionPerformed();
797 clustalColour.setText("Clustalx colours");
798 clustalColour.addActionListener(new java.awt.event.ActionListener()
800 public void actionPerformed(ActionEvent e)
802 clustalColour_actionPerformed();
805 zappoColour.setText("Zappo");
806 zappoColour.addActionListener(new java.awt.event.ActionListener()
808 public void actionPerformed(ActionEvent e)
810 zappoColour_actionPerformed();
813 taylorColour.setText("Taylor");
814 taylorColour.addActionListener(new java.awt.event.ActionListener()
816 public void actionPerformed(ActionEvent e)
818 taylorColour_actionPerformed();
821 hydrophobicityColour.setText("Hydrophobicity");
823 .addActionListener(new java.awt.event.ActionListener()
825 public void actionPerformed(ActionEvent e)
827 hydrophobicityColour_actionPerformed();
830 helixColour.setText("Helix propensity");
831 helixColour.addActionListener(new java.awt.event.ActionListener()
833 public void actionPerformed(ActionEvent e)
835 helixColour_actionPerformed();
838 strandColour.setText("Strand propensity");
839 strandColour.addActionListener(new java.awt.event.ActionListener()
841 public void actionPerformed(ActionEvent e)
843 strandColour_actionPerformed();
846 turnColour.setText("Turn propensity");
847 turnColour.addActionListener(new java.awt.event.ActionListener()
849 public void actionPerformed(ActionEvent e)
851 turnColour_actionPerformed();
854 buriedColour.setText("Buried Index");
855 buriedColour.addActionListener(new java.awt.event.ActionListener()
857 public void actionPerformed(ActionEvent e)
859 buriedColour_actionPerformed();
862 abovePIDColour.setText("Above % Identity");
863 abovePIDColour.addActionListener(new java.awt.event.ActionListener()
865 public void actionPerformed(ActionEvent e)
867 abovePIDColour_actionPerformed();
870 userDefinedColour.setText("User Defined...");
871 userDefinedColour.addActionListener(new java.awt.event.ActionListener()
873 public void actionPerformed(ActionEvent e)
875 userDefinedColour_actionPerformed(e);
878 PIDColour.setText("Percentage Identity");
879 PIDColour.addActionListener(new java.awt.event.ActionListener()
881 public void actionPerformed(ActionEvent e)
883 PIDColour_actionPerformed();
886 BLOSUM62Colour.setText("BLOSUM62");
887 BLOSUM62Colour.addActionListener(new java.awt.event.ActionListener()
889 public void actionPerformed(ActionEvent e)
891 BLOSUM62Colour_actionPerformed();
894 conservationMenuItem.setText("Conservation");
896 .addActionListener(new java.awt.event.ActionListener()
898 public void actionPerformed(ActionEvent e)
900 conservationMenuItem_actionPerformed();
910 ap.paintAlignment(true);
912 PaintRefresher.Refresh(this, ap.av.getSequenceSetId());
921 protected void clustalColour_actionPerformed()
923 SequenceGroup sg = getGroup();
924 sg.cs = new ClustalxColourScheme(sg
925 .getSequences(ap.av.hiddenRepSequences), ap.av.alignment
936 protected void zappoColour_actionPerformed()
938 getGroup().cs = new ZappoColourScheme();
948 protected void taylorColour_actionPerformed()
950 getGroup().cs = new TaylorColourScheme();
960 protected void hydrophobicityColour_actionPerformed()
962 getGroup().cs = new HydrophobicColourScheme();
972 protected void helixColour_actionPerformed()
974 getGroup().cs = new HelixColourScheme();
984 protected void strandColour_actionPerformed()
986 getGroup().cs = new StrandColourScheme();
996 protected void turnColour_actionPerformed()
998 getGroup().cs = new TurnColourScheme();
1008 protected void buriedColour_actionPerformed()
1010 getGroup().cs = new BuriedColourScheme();
1020 public void nucleotideMenuItem_actionPerformed()
1022 getGroup().cs = new NucleotideColourScheme();
1032 protected void abovePIDColour_actionPerformed()
1034 SequenceGroup sg = getGroup();
1040 if (abovePIDColour.isSelected())
1042 sg.cs.setConsensus(AAFrequency.calculate(sg
1043 .getSequences(ap.av.hiddenRepSequences), sg.getStartRes(), sg
1046 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs, getGroup()
1049 sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus());
1051 SliderPanel.showPIDSlider();
1054 // remove PIDColouring
1056 sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
1068 protected void userDefinedColour_actionPerformed(ActionEvent e)
1070 SequenceGroup sg = getGroup();
1072 if (e.getActionCommand().equals("User Defined..."))
1074 new UserDefinedColours(ap, sg);
1078 UserColourScheme udc = (UserColourScheme) UserDefinedColours
1079 .getUserColourSchemes().get(e.getActionCommand());
1092 protected void PIDColour_actionPerformed()
1094 SequenceGroup sg = getGroup();
1095 sg.cs = new PIDColourScheme();
1096 sg.cs.setConsensus(AAFrequency.calculate(sg
1097 .getSequences(ap.av.hiddenRepSequences), sg.getStartRes(), sg
1108 protected void BLOSUM62Colour_actionPerformed()
1110 SequenceGroup sg = getGroup();
1112 sg.cs = new Blosum62ColourScheme();
1114 sg.cs.setConsensus(AAFrequency.calculate(sg
1115 .getSequences(ap.av.hiddenRepSequences), sg.getStartRes(), sg
1127 protected void noColourmenuItem_actionPerformed()
1129 getGroup().cs = null;
1139 protected void conservationMenuItem_actionPerformed()
1141 SequenceGroup sg = getGroup();
1147 if (conservationMenuItem.isSelected())
1149 Conservation c = new Conservation("Group",
1150 ResidueProperties.propHash, 3, sg
1151 .getSequences(ap.av.hiddenRepSequences), sg
1152 .getStartRes(), sg.getEndRes() + 1);
1155 c.verdict(false, ap.av.ConsPercGaps);
1157 sg.cs.setConservation(c);
1159 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
1160 SliderPanel.showConservationSlider();
1163 // remove ConservationColouring
1165 sg.cs.setConservation(null);
1171 public void annotationMenuItem_actionPerformed(ActionEvent actionEvent)
1173 SequenceGroup sg = getGroup();
1179 AnnotationColourGradient acg = new AnnotationColourGradient(sequence
1180 .getAnnotation()[0], null,
1181 AnnotationColourGradient.NO_THRESHOLD);
1183 acg.predefinedColours = true;
1195 protected void groupName_actionPerformed()
1198 SequenceGroup sg = getGroup();
1199 EditNameDialog dialog = new EditNameDialog(sg.getName(), sg
1200 .getDescription(), " Group Name ", "Group Description ",
1201 "Edit Group Name/Description");
1208 sg.setName(dialog.getName());
1209 sg.setDescription(dialog.getDescription());
1215 * @return DOCUMENT ME!
1217 SequenceGroup getGroup()
1219 SequenceGroup sg = ap.av.getSelectionGroup();
1220 // this method won't add a new group if it already exists
1223 ap.av.alignment.addGroup(sg);
1235 void sequenceName_actionPerformed()
1237 EditNameDialog dialog = new EditNameDialog(sequence.getName(), sequence
1238 .getDescription(), " Sequence Name ",
1239 "Sequence Description ", "Edit Sequence Name/Description");
1246 if (dialog.getName() != null)
1248 if (dialog.getName().indexOf(" ") > -1)
1250 JOptionPane.showMessageDialog(ap,
1251 "Spaces have been converted to \"_\"",
1252 "No spaces allowed in Sequence Name",
1253 JOptionPane.WARNING_MESSAGE);
1256 sequence.setName(dialog.getName().replace(' ', '_'));
1257 ap.paintAlignment(false);
1260 sequence.setDescription(dialog.getDescription());
1262 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
1273 void unGroupMenuItem_actionPerformed()
1275 SequenceGroup sg = ap.av.getSelectionGroup();
1276 ap.av.alignment.deleteGroup(sg);
1277 ap.av.setSelectionGroup(null);
1287 protected void outline_actionPerformed()
1289 SequenceGroup sg = getGroup();
1290 Color col = JColorChooser.showDialog(this, "Select Outline Colour",
1295 sg.setOutlineColour(col);
1307 public void showBoxes_actionPerformed()
1309 getGroup().setDisplayBoxes(showBoxes.isSelected());
1319 public void showText_actionPerformed()
1321 getGroup().setDisplayText(showText.isSelected());
1331 public void showColourText_actionPerformed()
1333 getGroup().setColourText(showColourText.isSelected());
1337 public void showLink(String url)
1341 jalview.util.BrowserLauncher.openURL(url);
1342 } catch (Exception ex)
1345 .showInternalMessageDialog(
1347 "Unixers: Couldn't find default web browser."
1348 + "\nAdd the full path to your browser in Preferences.",
1349 "Web browser not found", JOptionPane.WARNING_MESSAGE);
1351 ex.printStackTrace();
1355 void hideSequences(boolean representGroup)
1357 SequenceGroup sg = ap.av.getSelectionGroup();
1358 if (sg == null || sg.getSize() < 1)
1360 ap.av.hideSequence(new SequenceI[]
1365 ap.av.setSelectionGroup(null);
1369 ap.av.hideRepSequences(sequence, sg);
1374 int gsize = sg.getSize();
1377 hseqs = new SequenceI[gsize];
1380 for (int i = 0; i < gsize; i++)
1382 hseqs[index++] = sg.getSequenceAt(i);
1385 ap.av.hideSequence(hseqs);
1388 public void copy_actionPerformed()
1390 ap.alignFrame.copy_actionPerformed(null);
1393 public void cut_actionPerformed()
1395 ap.alignFrame.cut_actionPerformed(null);
1398 void changeCase(ActionEvent e)
1400 Object source = e.getSource();
1401 SequenceGroup sg = ap.av.getSelectionGroup();
1405 int[][] startEnd = ap.av.getVisibleRegionBoundaries(sg.getStartRes(),
1406 sg.getEndRes() + 1);
1411 if (source == toggle)
1413 description = "Toggle Case";
1414 caseChange = ChangeCaseCommand.TOGGLE_CASE;
1416 else if (source == upperCase)
1418 description = "To Upper Case";
1419 caseChange = ChangeCaseCommand.TO_UPPER;
1423 description = "To Lower Case";
1424 caseChange = ChangeCaseCommand.TO_LOWER;
1427 ChangeCaseCommand caseCommand = new ChangeCaseCommand(description, sg
1428 .getSequencesAsArray(ap.av.hiddenRepSequences), startEnd,
1431 ap.alignFrame.addHistoryItem(caseCommand);
1433 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()
1439 public void outputText_actionPerformed(ActionEvent e)
1441 CutAndPasteTransfer cap = new CutAndPasteTransfer();
1442 cap.setForInput(null);
1443 Desktop.addInternalFrame(cap, "Alignment output - "
1444 + e.getActionCommand(), 600, 500);
1446 String[] omitHidden = null;
1448 System.out.println("PROMPT USER HERE"); // TODO: decide if a prompt happens
1449 // or we simply trust the user wants
1450 // wysiwig behaviour
1451 SequenceGroup sg = ap.av.getSelectionGroup();
1452 ColumnSelection csel = new ColumnSelection(ap.av.getColumnSelection());
1453 omitHidden = ap.av.getViewAsString(true);
1454 Alignment oal = new Alignment(ap.av.getSequenceSelection());
1455 AlignmentAnnotation[] nala = ap.av.alignment.getAlignmentAnnotation();
1456 for (int i = 0; i < nala.length; i++)
1458 AlignmentAnnotation na = nala[i];
1459 oal.addAnnotation(na);
1461 cap.setText(new FormatAdapter().formatSequences(e.getActionCommand(),
1462 oal, omitHidden, csel, sg));
1466 public void pdbFromFile_actionPerformed()
1468 jalview.io.JalviewFileChooser chooser = new jalview.io.JalviewFileChooser(
1469 jalview.bin.Cache.getProperty("LAST_DIRECTORY"));
1470 chooser.setFileView(new jalview.io.JalviewFileView());
1471 chooser.setDialogTitle("Select a PDB file");
1472 chooser.setToolTipText("Load a PDB file");
1474 int value = chooser.showOpenDialog(null);
1476 if (value == jalview.io.JalviewFileChooser.APPROVE_OPTION)
1478 PDBEntry entry = new PDBEntry();
1479 String choice = chooser.getSelectedFile().getPath();
1480 jalview.bin.Cache.setProperty("LAST_DIRECTORY", choice);
1483 MCview.PDBfile pdbfile = new MCview.PDBfile(choice,
1484 jalview.io.AppletFormatAdapter.FILE);
1486 if (pdbfile.id == null)
1488 String reply = JOptionPane
1489 .showInternalInputDialog(
1491 "Couldn't find a PDB id in the file supplied."
1492 + "Please enter an Id to identify this structure.",
1493 "No PDB Id in File", JOptionPane.QUESTION_MESSAGE);
1503 entry.setId(pdbfile.id);
1505 } catch (java.io.IOException ex)
1507 ex.printStackTrace();
1510 entry.setFile(choice);
1511 sequence.getDatasetSequence().addPDBId(entry);
1516 public void enterPDB_actionPerformed()
1518 String id = JOptionPane.showInternalInputDialog(Desktop.desktop,
1519 "Enter PDB Id", "Enter PDB Id", JOptionPane.QUESTION_MESSAGE);
1521 if (id != null && id.length() > 0)
1523 PDBEntry entry = new PDBEntry();
1524 entry.setId(id.toUpperCase());
1525 sequence.getDatasetSequence().addPDBId(entry);
1529 public void discoverPDB_actionPerformed()
1532 final SequenceI[] sequences = ((ap.av.selectionGroup == null) ? new Sequence[]
1534 : ap.av.selectionGroup.getSequencesInOrder(ap.av.alignment));
1535 Thread discpdb = new Thread(new Runnable()
1540 new jalview.ws.DBRefFetcher(sequences, ap.alignFrame)
1541 .fetchDBRefs(false);
1548 public void sequenceFeature_actionPerformed()
1550 SequenceGroup sg = ap.av.getSelectionGroup();
1556 int gSize = sg.getSize();
1557 SequenceI[] seqs = new SequenceI[gSize];
1558 SequenceFeature[] features = new SequenceFeature[gSize];
1560 for (int i = 0; i < gSize; i++)
1562 seqs[i] = sg.getSequenceAt(i).getDatasetSequence();
1563 int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
1564 int end = sg.findEndRes(sg.getSequenceAt(i));
1565 features[i] = new SequenceFeature(null, null, null, start, end,
1569 if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
1570 features, true, ap))
1572 ap.alignFrame.showSeqFeatures.setSelected(true);
1573 ap.av.setShowSequenceFeatures(true);
1574 ap.highlightSearchResults(null);
1578 public void textColour_actionPerformed()
1580 SequenceGroup sg = getGroup();
1583 new TextColourChooser().chooseColour(ap, sg);
1587 public void colourByStructure(String pdbid)
1589 Annotation[] anots = jalview.structure.StructureSelectionManager
1590 .getStructureSelectionManager().colourSequenceFromStructure(
1593 AlignmentAnnotation an = new AlignmentAnnotation("Structure",
1594 "Coloured by " + pdbid, anots);
1596 ap.av.alignment.addAnnotation(an);
1597 an.createSequenceMapping(sequence, 0, true);
1598 // an.adjustForAlignment();
1599 ap.av.alignment.setAnnotationIndex(an, 0);
1601 ap.adjustAnnotationHeight();
1603 sequence.addAlignmentAnnotation(an);
1607 public void editSequence_actionPerformed(ActionEvent actionEvent)
1609 SequenceGroup sg = ap.av.getSelectionGroup();
1613 if (sequence == null)
1614 sequence = (Sequence) sg.getSequenceAt(0);
1616 EditNameDialog dialog = new EditNameDialog(sequence
1617 .getSequenceAsString(sg.getStartRes(), sg.getEndRes() + 1),
1618 null, "Edit Sequence ", null, "Edit Sequence");
1622 EditCommand editCommand = new EditCommand("Edit Sequences",
1623 EditCommand.REPLACE, dialog.getName().replace(' ',
1624 ap.av.getGapCharacter()), sg
1625 .getSequencesAsArray(ap.av.hiddenRepSequences), sg
1626 .getStartRes(), sg.getEndRes() + 1, ap.av.alignment);
1628 ap.alignFrame.addHistoryItem(editCommand);
1630 ap.av.firePropertyChange("alignment", null, ap.av.getAlignment()