2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2007 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle
\r
5 * This program is free software; you can redistribute it and/or
\r
6 * modify it under the terms of the GNU General Public License
\r
7 * as published by the Free Software Foundation; either version 2
\r
8 * of the License, or (at your option) any later version.
\r
10 * This program is distributed in the hope that it will be useful,
\r
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 * GNU General Public License for more details.
\r
15 * You should have received a copy of the GNU General Public License
\r
16 * along with this program; if not, write to the Free Software
\r
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
\r
20 package jalview.appletgui;
\r
25 import java.awt.event.*;
\r
27 import jalview.analysis.*;
\r
28 import jalview.commands.*;
\r
29 import jalview.datamodel.*;
\r
30 import jalview.schemes.*;
\r
32 public class APopupMenu
\r
33 extends java.awt.PopupMenu implements ActionListener, ItemListener
\r
35 Menu groupMenu = new Menu();
\r
36 MenuItem editGroupName = new MenuItem();
\r
37 protected MenuItem clustalColour = new MenuItem();
\r
38 protected MenuItem zappoColour = new MenuItem();
\r
39 protected MenuItem taylorColour = new MenuItem();
\r
40 protected MenuItem hydrophobicityColour = new MenuItem();
\r
41 protected MenuItem helixColour = new MenuItem();
\r
42 protected MenuItem strandColour = new MenuItem();
\r
43 protected MenuItem turnColour = new MenuItem();
\r
44 protected MenuItem buriedColour = new MenuItem();
\r
45 protected CheckboxMenuItem abovePIDColour = new CheckboxMenuItem();
\r
46 protected MenuItem userDefinedColour = new MenuItem();
\r
47 protected MenuItem PIDColour = new MenuItem();
\r
48 protected MenuItem BLOSUM62Colour = new MenuItem();
\r
49 MenuItem noColourmenuItem = new MenuItem();
\r
50 protected CheckboxMenuItem conservationMenuItem = new CheckboxMenuItem();
\r
52 final AlignmentPanel ap;
\r
53 MenuItem unGroupMenuItem = new MenuItem();
\r
54 MenuItem nucleotideMenuItem = new MenuItem();
\r
55 Menu colourMenu = new Menu();
\r
56 CheckboxMenuItem showBoxes = new CheckboxMenuItem();
\r
57 CheckboxMenuItem showText = new CheckboxMenuItem();
\r
58 CheckboxMenuItem showColourText = new CheckboxMenuItem();
\r
59 Menu editMenu = new Menu("Edit");
\r
60 MenuItem copy = new MenuItem("Copy (Jalview Only)");
\r
61 MenuItem cut = new MenuItem("Cut (Jalview Only)");
\r
62 MenuItem toUpper = new MenuItem("To Upper Case");
\r
63 MenuItem toLower = new MenuItem("To Lower Case");
\r
64 MenuItem toggleCase = new MenuItem("Toggle Case");
\r
65 Menu outputmenu = new Menu();
\r
66 Menu seqMenu = new Menu();
\r
67 MenuItem pdb = new MenuItem();
\r
68 MenuItem hideSeqs = new MenuItem();
\r
69 MenuItem repGroup = new MenuItem();
\r
70 MenuItem sequenceName = new MenuItem("Edit Name/Description");
\r
73 MenuItem revealAll = new MenuItem();
\r
74 Menu menu1 = new Menu();
\r
76 public APopupMenu(AlignmentPanel apanel, final Sequence seq, Vector links)
\r
78 ///////////////////////////////////////////////////////////
\r
79 // If this is activated from the sequence panel, the user may want to
\r
80 // edit or annotate a particular residue. Therefore display the residue menu
\r
82 // If from the IDPanel, we must display the sequence menu
\r
83 //////////////////////////////////////////////////////////
\r
94 e.printStackTrace();
\r
97 for (int i = 0; i < jalview.io.AppletFormatAdapter.WRITEABLE_FORMATS.length;
\r
100 MenuItem item = new MenuItem(jalview.io.AppletFormatAdapter.
\r
101 WRITEABLE_FORMATS[i]);
\r
103 item.addActionListener(this);
\r
104 outputmenu.add(item);
\r
107 SequenceGroup sg = ap.av.getSelectionGroup();
\r
109 if (sg != null && sg.getSize() > 0)
\r
111 editGroupName.setLabel(sg.getName());
\r
112 showText.setState(sg.getDisplayText());
\r
113 showColourText.setState(sg.getColourText());
\r
114 showBoxes.setState(sg.getDisplayBoxes());
\r
115 if (!ap.av.alignment.getGroups().contains(sg))
\r
117 groupMenu.remove(unGroupMenuItem);
\r
129 Menu linkMenu = new Menu("Link");
\r
132 for (int i = 0; i < links.size(); i++)
\r
134 link = links.elementAt(i).toString();
\r
135 final String target = link.substring(0, link.indexOf("|"));
\r
136 item = new MenuItem(target);
\r
140 if (link.indexOf("$SEQUENCE_ID$") > -1)
\r
142 String id = seq.getName();
\r
143 if (id.indexOf("|") > -1)
\r
145 id = id.substring(id.lastIndexOf("|") + 1);
\r
148 url = link.substring(link.indexOf("|") + 1,
\r
149 link.indexOf("$SEQUENCE_ID$"))
\r
151 link.substring(link.indexOf("$SEQUENCE_ID$") + 13);
\r
155 url = link.substring(link.lastIndexOf("|") + 1);
\r
158 item.addActionListener(new java.awt.event.ActionListener()
\r
160 public void actionPerformed(ActionEvent e)
\r
162 ap.alignFrame.showURL(url, target);
\r
165 linkMenu.add(item);
\r
169 seqMenu.add(linkMenu);
\r
178 seqMenu.setLabel(seq.getName());
\r
179 repGroup.setLabel("Represent Group with " + seq.getName());
\r
186 if (!ap.av.hasHiddenRows)
\r
192 public void itemStateChanged(ItemEvent evt)
\r
194 if (evt.getSource() == abovePIDColour)
\r
196 abovePIDColour_itemStateChanged();
\r
198 else if (evt.getSource() == showColourText)
\r
200 showColourText_itemStateChanged();
\r
202 else if (evt.getSource() == showText)
\r
204 showText_itemStateChanged();
\r
206 else if (evt.getSource() == showBoxes)
\r
208 showBoxes_itemStateChanged();
\r
212 public void actionPerformed(ActionEvent evt)
\r
214 Object source = evt.getSource();
\r
215 if (source == clustalColour)
\r
217 clustalColour_actionPerformed();
\r
219 else if (source == zappoColour)
\r
221 zappoColour_actionPerformed();
\r
223 else if (source == taylorColour)
\r
225 taylorColour_actionPerformed();
\r
227 else if (source == hydrophobicityColour)
\r
229 hydrophobicityColour_actionPerformed();
\r
231 else if (source == helixColour)
\r
233 helixColour_actionPerformed();
\r
235 else if (source == strandColour)
\r
237 strandColour_actionPerformed();
\r
239 else if (source == turnColour)
\r
241 turnColour_actionPerformed();
\r
243 else if (source == buriedColour)
\r
245 buriedColour_actionPerformed();
\r
247 else if (source == nucleotideMenuItem)
\r
249 nucleotideMenuItem_actionPerformed();
\r
252 else if (source == userDefinedColour)
\r
254 userDefinedColour_actionPerformed();
\r
256 else if (source == PIDColour)
\r
258 PIDColour_actionPerformed();
\r
260 else if (source == BLOSUM62Colour)
\r
262 BLOSUM62Colour_actionPerformed();
\r
264 else if (source == noColourmenuItem)
\r
266 noColourmenuItem_actionPerformed();
\r
268 else if (source == conservationMenuItem)
\r
270 conservationMenuItem_itemStateChanged();
\r
272 else if (source == unGroupMenuItem)
\r
274 unGroupMenuItem_actionPerformed();
\r
277 else if (source == sequenceName)
\r
281 else if (source == pdb)
\r
285 else if (source == hideSeqs)
\r
287 hideSequences(false);
\r
289 else if (source == repGroup)
\r
291 hideSequences(true);
\r
293 else if (source == revealAll)
\r
295 ap.av.showAllHiddenSeqs();
\r
298 else if (source == editGroupName)
\r
300 EditNameDialog dialog = new EditNameDialog(
\r
301 getGroup().getName(),
\r
302 getGroup().getDescription(),
\r
304 "Group Description",
\r
306 "Edit Group Name / Description");
\r
311 getGroup().setName(dialog.getName().replace(' ', '_'));
\r
312 getGroup().setDescription(dialog.getDescription());
\r
316 else if (source == copy)
\r
318 ap.alignFrame.copy_actionPerformed();
\r
320 else if (source == cut)
\r
322 ap.alignFrame.cut_actionPerformed();
\r
324 else if (source == toUpper || source == toLower || source == toggleCase)
\r
326 SequenceGroup sg = ap.av.getSelectionGroup();
\r
327 Vector regions = new Vector();
\r
330 int start = sg.getStartRes();
\r
331 int end = sg.getEndRes() + 1;
\r
335 if (ap.av.hasHiddenColumns)
\r
339 start = ap.av.colSel.adjustForHiddenColumns(start);
\r
342 end = ap.av.colSel.getHiddenBoundaryRight(start);
\r
345 end = sg.getEndRes() + 1;
\r
347 if (end > sg.getEndRes())
\r
349 end = sg.getEndRes() + 1;
\r
353 regions.addElement(new int[]
\r
356 if (ap.av.hasHiddenColumns)
\r
358 start = ap.av.colSel.adjustForHiddenColumns(end);
\r
359 start = ap.av.colSel.getHiddenBoundaryLeft(start) + 1;
\r
362 while (end < sg.getEndRes());
\r
364 int[][] startEnd = new int[regions.size()][2];
\r
365 for (int i = 0; i < regions.size(); i++)
\r
367 startEnd[i] = (int[]) regions.elementAt(i);
\r
370 String description;
\r
373 if (source == toggleCase)
\r
375 description = "Toggle Case";
\r
376 caseChange = ChangeCaseCommand.TOGGLE_CASE;
\r
378 else if (source == toUpper)
\r
380 description = "To Upper Case";
\r
381 caseChange = ChangeCaseCommand.TO_UPPER;
\r
385 description = "To Lower Case";
\r
386 caseChange = ChangeCaseCommand.TO_LOWER;
\r
389 ChangeCaseCommand caseCommand = new ChangeCaseCommand(
\r
390 description, sg.getSequencesAsArray(ap.av.hiddenRepSequences),
\r
391 startEnd, caseChange
\r
394 ap.alignFrame.addHistoryItem(caseCommand);
\r
396 ap.av.firePropertyChange("alignment", null,
\r
397 ap.av.getAlignment().getSequences());
\r
408 void outputText(ActionEvent e)
\r
410 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
\r
412 Frame frame = new Frame();
\r
414 jalview.bin.JalviewLite.addFrame(frame,
\r
415 "Selection output - " + e.getActionCommand(),
\r
418 cap.setText(new jalview.io.AppletFormatAdapter().formatSequences(
\r
419 e.getActionCommand(),
\r
420 new Alignment(ap.av.getSelectionAsNewSequence()),
\r
421 ap.av.showJVSuffix));
\r
427 EditNameDialog dialog = new EditNameDialog(
\r
429 seq.getDescription(),
\r
431 "Sequence Description",
\r
433 "Edit Sequence Name / Description");
\r
437 seq.setName(dialog.getName());
\r
438 seq.setDescription(dialog.getDescription());
\r
439 ap.paintAlignment(false);
\r
445 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
\r
446 cap.setText("Paste your PDB file here.");
\r
447 cap.setPDBImport(seq);
\r
448 Frame frame = new Frame();
\r
450 jalview.bin.JalviewLite.addFrame(frame, "Paste PDB file ", 400, 300);
\r
453 private void jbInit()
\r
456 groupMenu.setLabel("Group");
\r
457 groupMenu.setLabel("Selection");
\r
459 editGroupName.addActionListener(this);
\r
460 unGroupMenuItem.setLabel("Remove Group");
\r
461 unGroupMenuItem.addActionListener(this);
\r
463 nucleotideMenuItem.setLabel("Nucleotide");
\r
464 nucleotideMenuItem.addActionListener(this);
\r
465 conservationMenuItem.addItemListener(this);
\r
466 abovePIDColour.addItemListener(this);
\r
467 colourMenu.setLabel("Group Colour");
\r
468 showBoxes.setLabel("Boxes");
\r
469 showBoxes.setState(true);
\r
470 showBoxes.addItemListener(this);
\r
471 sequenceName.addActionListener(this);
\r
473 showText.setLabel("Text");
\r
474 showText.addItemListener(this);
\r
475 showColourText.setLabel("Colour Text");
\r
476 showColourText.addItemListener(this);
\r
477 outputmenu.setLabel("Output to Textbox...");
\r
478 seqMenu.setLabel("Sequence");
\r
479 pdb.setLabel("View PDB Structure");
\r
480 hideSeqs.setLabel("Hide Sequences");
\r
481 repGroup.setLabel("Represent Group with");
\r
482 revealAll.setLabel("Reveal All");
\r
483 menu1.setLabel("Group");
\r
486 this.add(hideSeqs);
\r
487 this.add(revealAll);
\r
488 groupMenu.add(editGroupName);
\r
489 groupMenu.add(editMenu);
\r
490 groupMenu.add(outputmenu);
\r
491 groupMenu.add(menu1);
\r
492 colourMenu.add(noColourmenuItem);
\r
493 colourMenu.add(clustalColour);
\r
494 colourMenu.add(BLOSUM62Colour);
\r
495 colourMenu.add(PIDColour);
\r
496 colourMenu.add(zappoColour);
\r
497 colourMenu.add(taylorColour);
\r
498 colourMenu.add(hydrophobicityColour);
\r
499 colourMenu.add(helixColour);
\r
500 colourMenu.add(strandColour);
\r
501 colourMenu.add(turnColour);
\r
502 colourMenu.add(buriedColour);
\r
503 colourMenu.add(nucleotideMenuItem);
\r
504 colourMenu.add(userDefinedColour);
\r
505 colourMenu.addSeparator();
\r
506 colourMenu.add(abovePIDColour);
\r
507 colourMenu.add(conservationMenuItem);
\r
509 noColourmenuItem.setLabel("None");
\r
510 noColourmenuItem.addActionListener(this);
\r
512 clustalColour.setLabel("Clustalx colours");
\r
513 clustalColour.addActionListener(this);
\r
514 zappoColour.setLabel("Zappo");
\r
515 zappoColour.addActionListener(this);
\r
516 taylorColour.setLabel("Taylor");
\r
517 taylorColour.addActionListener(this);
\r
518 hydrophobicityColour.setLabel("Hydrophobicity");
\r
519 hydrophobicityColour.addActionListener(this);
\r
520 helixColour.setLabel("Helix propensity");
\r
521 helixColour.addActionListener(this);
\r
522 strandColour.setLabel("Strand propensity");
\r
523 strandColour.addActionListener(this);
\r
524 turnColour.setLabel("Turn propensity");
\r
525 turnColour.addActionListener(this);
\r
526 buriedColour.setLabel("Buried Index");
\r
527 buriedColour.addActionListener(this);
\r
528 abovePIDColour.setLabel("Above % Identity");
\r
530 userDefinedColour.setLabel("User Defined");
\r
531 userDefinedColour.addActionListener(this);
\r
532 PIDColour.setLabel("Percentage Identity");
\r
533 PIDColour.addActionListener(this);
\r
534 BLOSUM62Colour.setLabel("BLOSUM62");
\r
535 BLOSUM62Colour.addActionListener(this);
\r
536 conservationMenuItem.setLabel("Conservation");
\r
538 editMenu.add(copy);
\r
539 copy.addActionListener(this);
\r
541 cut.addActionListener(this);
\r
542 editMenu.add(toUpper);
\r
543 toUpper.addActionListener(this);
\r
544 editMenu.add(toLower);
\r
545 toLower.addActionListener(this);
\r
546 editMenu.add(toggleCase);
\r
547 seqMenu.add(sequenceName);
\r
549 seqMenu.add(repGroup);
\r
550 menu1.add(unGroupMenuItem);
\r
551 menu1.add(colourMenu);
\r
552 menu1.add(showBoxes);
\r
553 menu1.add(showText);
\r
554 menu1.add(showColourText);
\r
555 toggleCase.addActionListener(this);
\r
556 pdb.addActionListener(this);
\r
557 hideSeqs.addActionListener(this);
\r
558 repGroup.addActionListener(this);
\r
559 revealAll.addActionListener(this);
\r
564 ap.paintAlignment(true);
\r
567 protected void clustalColour_actionPerformed()
\r
569 SequenceGroup sg = getGroup();
\r
570 sg.cs = new ClustalxColourScheme(sg.getSequences(ap.av.hiddenRepSequences),
\r
571 ap.av.alignment.getWidth());
\r
575 protected void zappoColour_actionPerformed()
\r
577 getGroup().cs = new ZappoColourScheme();
\r
581 protected void taylorColour_actionPerformed()
\r
583 getGroup().cs = new TaylorColourScheme();
\r
587 protected void hydrophobicityColour_actionPerformed()
\r
589 getGroup().cs = new HydrophobicColourScheme();
\r
593 protected void helixColour_actionPerformed()
\r
595 getGroup().cs = new HelixColourScheme();
\r
599 protected void strandColour_actionPerformed()
\r
601 getGroup().cs = new StrandColourScheme();
\r
605 protected void turnColour_actionPerformed()
\r
607 getGroup().cs = new TurnColourScheme();
\r
611 protected void buriedColour_actionPerformed()
\r
613 getGroup().cs = new BuriedColourScheme();
\r
617 public void nucleotideMenuItem_actionPerformed()
\r
619 getGroup().cs = new NucleotideColourScheme();
\r
623 protected void abovePIDColour_itemStateChanged()
\r
625 SequenceGroup sg = getGroup();
\r
631 if (abovePIDColour.getState())
\r
633 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av.
\r
634 hiddenRepSequences), 0,
\r
635 ap.av.alignment.getWidth()));
\r
636 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs,
\r
637 getGroup().getName());
\r
639 sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus());
\r
641 SliderPanel.showPIDSlider();
\r
644 else // remove PIDColouring
\r
646 sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
\r
653 protected void userDefinedColour_actionPerformed()
\r
655 new UserDefinedColours(ap, getGroup());
\r
658 protected void PIDColour_actionPerformed()
\r
660 SequenceGroup sg = getGroup();
\r
661 sg.cs = new PIDColourScheme();
\r
662 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av.
\r
663 hiddenRepSequences), 0,
\r
664 ap.av.alignment.getWidth()));
\r
668 protected void BLOSUM62Colour_actionPerformed()
\r
670 SequenceGroup sg = getGroup();
\r
672 sg.cs = new Blosum62ColourScheme();
\r
674 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(ap.av.
\r
675 hiddenRepSequences), 0,
\r
676 ap.av.alignment.getWidth()));
\r
681 protected void noColourmenuItem_actionPerformed()
\r
683 getGroup().cs = null;
\r
687 protected void conservationMenuItem_itemStateChanged()
\r
689 SequenceGroup sg = getGroup();
\r
695 if (conservationMenuItem.getState())
\r
698 Conservation c = new Conservation("Group",
\r
699 ResidueProperties.propHash, 3,
\r
700 sg.getSequences(ap.av.
\r
701 hiddenRepSequences), 0,
\r
702 ap.av.alignment.getWidth());
\r
705 c.verdict(false, ap.av.ConsPercGaps);
\r
707 sg.cs.setConservation(c);
\r
709 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
\r
710 SliderPanel.showConservationSlider();
\r
712 else // remove ConservationColouring
\r
714 sg.cs.setConservation(null);
\r
720 SequenceGroup getGroup()
\r
722 SequenceGroup sg = ap.av.getSelectionGroup();
\r
724 // this method won't add a new group if it already exists
\r
727 ap.av.alignment.addGroup(sg);
\r
733 void unGroupMenuItem_actionPerformed()
\r
735 SequenceGroup sg = ap.av.getSelectionGroup();
\r
736 ap.av.alignment.deleteGroup(sg);
\r
737 ap.av.setSelectionGroup(null);
\r
738 ap.paintAlignment(true);
\r
741 public void showColourText_itemStateChanged()
\r
743 getGroup().setColourText(showColourText.getState());
\r
747 public void showText_itemStateChanged()
\r
749 getGroup().setDisplayText(showText.getState());
\r
753 public void showBoxes_itemStateChanged()
\r
755 getGroup().setDisplayBoxes(showBoxes.getState());
\r
759 void hideSequences(boolean representGroup)
\r
761 SequenceGroup sg = ap.av.getSelectionGroup();
\r
762 if (sg == null || sg.getSize() < 1)
\r
764 ap.av.hideSequence(new SequenceI[]
\r
769 ap.av.setSelectionGroup(null);
\r
771 if (representGroup)
\r
773 ap.av.hideRepSequences(seq, sg);
\r
778 int gsize = sg.getSize();
\r
781 hseqs = new SequenceI[gsize];
\r
784 for (int i = 0; i < gsize; i++)
\r
786 hseqs[index++] = sg.getSequenceAt(i);
\r
789 ap.av.hideSequence(hseqs);
\r