2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2006 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
23 import java.awt.event.*;
\r
24 import java.util.Vector;
\r
26 import jalview.analysis.*;
\r
27 import jalview.datamodel.*;
\r
28 import jalview.schemes.*;
\r
29 import jalview.commands.ChangeCaseCommand;
\r
31 public class APopupMenu
\r
32 extends java.awt.PopupMenu implements ActionListener, ItemListener
\r
34 Menu groupMenu = new Menu();
\r
35 protected MenuItem clustalColour = new MenuItem();
\r
36 protected MenuItem zappoColour = new MenuItem();
\r
37 protected MenuItem taylorColour = new MenuItem();
\r
38 protected MenuItem hydrophobicityColour = new MenuItem();
\r
39 protected MenuItem helixColour = new MenuItem();
\r
40 protected MenuItem strandColour = new MenuItem();
\r
41 protected MenuItem turnColour = new MenuItem();
\r
42 protected MenuItem buriedColour = new MenuItem();
\r
43 protected CheckboxMenuItem abovePIDColour = new CheckboxMenuItem();
\r
44 protected MenuItem userDefinedColour = new MenuItem();
\r
45 protected MenuItem PIDColour = new MenuItem();
\r
46 protected MenuItem BLOSUM62Colour = new MenuItem();
\r
47 MenuItem noColourmenuItem = new MenuItem();
\r
48 protected CheckboxMenuItem conservationMenuItem = new CheckboxMenuItem();
\r
50 final AlignmentPanel ap;
\r
51 MenuItem unGroupMenuItem = new MenuItem();
\r
52 MenuItem nucleotideMenuItem = new MenuItem();
\r
53 Menu colourMenu = new Menu();
\r
54 CheckboxMenuItem showBoxes = new CheckboxMenuItem();
\r
55 CheckboxMenuItem showText = new CheckboxMenuItem();
\r
56 CheckboxMenuItem showColourText = new CheckboxMenuItem();
\r
57 Menu editMenu = new Menu("Edit");
\r
58 MenuItem copy = new MenuItem("Copy (Jalview Only)");
\r
59 MenuItem cut = new MenuItem("Cut (Jalview Only)");
\r
60 MenuItem toUpper = new MenuItem("To Upper Case");
\r
61 MenuItem toLower = new MenuItem("To Lower Case");
\r
62 MenuItem toggleCase = new MenuItem("Toggle Case");
\r
63 Menu outputmenu = new Menu();
\r
64 Menu seqMenu = new Menu();
\r
65 MenuItem pdb = new MenuItem();
\r
66 MenuItem hideSeqs = new MenuItem();
\r
67 MenuItem repGroup = new MenuItem();
\r
70 MenuItem revealAll = new MenuItem();
\r
71 Menu menu1 = new Menu();
\r
73 public APopupMenu(AlignmentPanel apanel, final Sequence seq, Vector links)
\r
75 ///////////////////////////////////////////////////////////
\r
76 // If this is activated from the sequence panel, the user may want to
\r
77 // edit or annotate a particular residue. Therefore display the residue menu
\r
79 // If from the IDPanel, we must display the sequence menu
\r
80 //////////////////////////////////////////////////////////
\r
91 e.printStackTrace();
\r
94 for (int i = 0; i < jalview.io.AppletFormatAdapter.WRITEABLE_FORMATS.length; i++)
\r
96 MenuItem item = new MenuItem( jalview.io.AppletFormatAdapter.WRITEABLE_FORMATS[i] );
\r
98 item.addActionListener(this);
\r
99 outputmenu.add(item);
\r
102 SequenceGroup sg = ap.av.getSelectionGroup();
\r
104 if (sg != null && sg.getSize(false)>0)
\r
106 showText.setState(sg.getDisplayText());
\r
107 showColourText.setState(sg.getColourText());
\r
108 showBoxes.setState(sg.getDisplayBoxes());
\r
109 if (!ap.av.alignment.getGroups().contains(sg))
\r
111 groupMenu.remove(unGroupMenuItem);
\r
123 Menu linkMenu = new Menu("Link");
\r
126 for(int i=0; i<links.size(); i++)
\r
128 link = links.elementAt(i).toString();
\r
129 final String target = link.substring(0, link.indexOf("|"));
\r
130 item = new MenuItem(target);
\r
134 if (link.indexOf("$SEQUENCE_ID$") > -1)
\r
136 String id = seq.getName();
\r
137 if (id.indexOf("|") > -1)
\r
138 id = id.substring(id.lastIndexOf("|") + 1);
\r
140 url = link.substring(link.indexOf("|") + 1,
\r
141 link.indexOf("$SEQUENCE_ID$"))
\r
143 link.substring(link.indexOf("$SEQUENCE_ID$") + 13);
\r
146 url = link.substring(link.lastIndexOf("|")+1);
\r
148 item.addActionListener(new java.awt.event.ActionListener()
\r
150 public void actionPerformed(ActionEvent e)
\r
152 ap.alignFrame.showURL(url, target);
\r
155 linkMenu.add(item);
\r
158 seqMenu.add(linkMenu);
\r
164 seqMenu.setLabel(seq.getName());
\r
165 repGroup.setLabel("Represent Group with " + seq.getName());
\r
170 if(!ap.av.hasHiddenRows)
\r
174 public void itemStateChanged(ItemEvent evt)
\r
176 if(evt.getSource()==abovePIDColour)
\r
177 abovePIDColour_itemStateChanged();
\r
178 else if(evt.getSource()==showColourText)
\r
179 showColourText_itemStateChanged();
\r
180 else if(evt.getSource()==showText)
\r
181 showText_itemStateChanged();
\r
182 else if(evt.getSource()==showBoxes)
\r
183 showBoxes_itemStateChanged() ;
\r
186 public void actionPerformed(ActionEvent evt)
\r
188 Object source = evt.getSource();
\r
189 if(source==clustalColour)
\r
190 clustalColour_actionPerformed();
\r
191 else if(source==zappoColour)
\r
192 zappoColour_actionPerformed();
\r
193 else if(source==taylorColour)
\r
194 taylorColour_actionPerformed();
\r
195 else if(source==hydrophobicityColour)
\r
196 hydrophobicityColour_actionPerformed();
\r
197 else if(source==helixColour)
\r
198 helixColour_actionPerformed();
\r
199 else if(source==strandColour)
\r
200 strandColour_actionPerformed();
\r
201 else if(source==turnColour)
\r
202 turnColour_actionPerformed();
\r
203 else if(source==buriedColour)
\r
204 buriedColour_actionPerformed();
\r
205 else if(source==nucleotideMenuItem)
\r
206 nucleotideMenuItem_actionPerformed();
\r
208 else if (source == userDefinedColour)
\r
209 userDefinedColour_actionPerformed();
\r
210 else if (source == PIDColour)
\r
211 PIDColour_actionPerformed();
\r
212 else if (source == BLOSUM62Colour)
\r
213 BLOSUM62Colour_actionPerformed();
\r
214 else if (source == noColourmenuItem)
\r
215 noColourmenuItem_actionPerformed();
\r
216 else if (source == conservationMenuItem)
\r
217 conservationMenuItem_itemStateChanged();
\r
218 else if (source == unGroupMenuItem)
\r
219 unGroupMenuItem_actionPerformed();
\r
221 else if(source == pdb)
\r
223 else if(source == hideSeqs)
\r
224 hideSequences(false);
\r
225 else if(source == repGroup)
\r
226 hideSequences(true);
\r
227 else if(source == revealAll)
\r
229 ap.av.showAllHiddenSeqs();
\r
232 else if(source==copy)
\r
233 ap.alignFrame.copy_actionPerformed();
\r
234 else if(source==cut)
\r
235 ap.alignFrame.cut_actionPerformed();
\r
236 else if(source==toUpper || source==toLower || source==toggleCase)
\r
238 SequenceGroup sg = ap.av.getSelectionGroup();
\r
239 Vector regions = new Vector();
\r
242 int start = sg.getStartRes();
\r
243 int end = sg.getEndRes() + 1;
\r
247 if (ap.av.hasHiddenColumns)
\r
250 start = ap.av.colSel.adjustForHiddenColumns(start);
\r
252 end = ap.av.colSel.getHiddenBoundaryRight(start);
\r
254 end = sg.getEndRes() + 1;
\r
255 if (end > sg.getEndRes())
\r
256 end = sg.getEndRes() + 1;
\r
259 regions.addElement(new int[]
\r
262 if (ap.av.hasHiddenColumns)
\r
264 start = ap.av.colSel.adjustForHiddenColumns(end);
\r
265 start = ap.av.colSel.getHiddenBoundaryLeft(start) + 1;
\r
268 while (end < sg.getEndRes());
\r
270 int[][] startEnd = new int[regions.size()][2];
\r
271 for (int i = 0; i < regions.size(); i++)
\r
273 startEnd[i] = (int[]) regions.elementAt(i);
\r
277 String description;
\r
280 if(source==toggleCase)
\r
282 description = "Toggle Case";
\r
283 caseChange = ChangeCaseCommand.TOGGLE_CASE;
\r
285 else if(source==toUpper)
\r
287 description = "To Upper Case";
\r
288 caseChange = ChangeCaseCommand.TO_UPPER;
\r
292 description = "To Lower Case";
\r
293 caseChange = ChangeCaseCommand.TO_LOWER;
\r
296 ChangeCaseCommand caseCommand = new ChangeCaseCommand(
\r
297 description, sg.getSequencesAsArray(true), startEnd, caseChange
\r
300 ap.alignFrame.addHistoryItem(caseCommand);
\r
303 ap.av.firePropertyChange("alignment", null,
\r
304 ap.av.getAlignment().getSequences());
\r
313 void outputText(ActionEvent e)
\r
315 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
\r
316 Vector vseqs = new Vector();
\r
318 String [] selection = ap.av.getViewAsString(true);
\r
319 SequenceI [] seqs = ap.av.getSelectionAsNewSequence();
\r
320 if (selection != null)
\r
322 for (int i = 0; i < selection.length; i++)
\r
324 Sequence seq = new Sequence(
\r
327 seqs[i].getStart(), seqs[i].getEnd());
\r
328 seq.setDescription(seqs[i].getDescription());
\r
329 vseqs.addElement( seq );
\r
333 Frame frame = new Frame();
\r
335 jalview.bin.JalviewLite.addFrame(frame,
\r
336 "Selection output - " + e.getActionCommand(),
\r
339 cap.setText(new jalview.io.AppletFormatAdapter().formatSequences(
\r
340 e.getActionCommand(),
\r
342 ap.av.showJVSuffix));
\r
348 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
\r
349 cap.setText("Paste your PDB file here.");
\r
350 cap.setPDBImport(seq);
\r
351 Frame frame = new Frame();
\r
353 jalview.bin.JalviewLite.addFrame(frame, "Paste PDB file ", 400, 300);
\r
356 private void jbInit()
\r
359 groupMenu.setLabel("Group");
\r
360 groupMenu.setLabel("Selection");
\r
362 unGroupMenuItem.setLabel("Remove Group");
\r
363 unGroupMenuItem.addActionListener(this);
\r
365 nucleotideMenuItem.setLabel("Nucleotide");
\r
366 nucleotideMenuItem.addActionListener(this);
\r
367 conservationMenuItem.addItemListener(this);
\r
368 abovePIDColour.addItemListener(this);
\r
369 colourMenu.setLabel("Group Colour");
\r
370 showBoxes.setLabel("Boxes");
\r
371 showBoxes.setState(true);
\r
372 showBoxes.addItemListener(this);
\r
374 showText.setLabel("Text");
\r
375 showText.addItemListener(this);
\r
376 showColourText.setLabel("Colour Text");
\r
377 showColourText.addItemListener(this);
\r
378 outputmenu.setLabel("Output to Textbox...");
\r
379 seqMenu.setLabel("Sequence");
\r
380 pdb.setLabel("View PDB Structure");
\r
381 hideSeqs.setLabel("Hide Sequences");
\r
382 repGroup.setLabel("Represent Group with");
\r
383 revealAll.setLabel("Reveal All");
\r
384 menu1.setLabel("Group");
\r
387 this.add(hideSeqs);
\r
388 this.add(revealAll);
\r
389 groupMenu.add(editMenu);
\r
390 groupMenu.add(outputmenu);
\r
391 groupMenu.add(menu1);
\r
392 colourMenu.add(noColourmenuItem);
\r
393 colourMenu.add(clustalColour);
\r
394 colourMenu.add(BLOSUM62Colour);
\r
395 colourMenu.add(PIDColour);
\r
396 colourMenu.add(zappoColour);
\r
397 colourMenu.add(taylorColour);
\r
398 colourMenu.add(hydrophobicityColour);
\r
399 colourMenu.add(helixColour);
\r
400 colourMenu.add(strandColour);
\r
401 colourMenu.add(turnColour);
\r
402 colourMenu.add(buriedColour);
\r
403 colourMenu.add(nucleotideMenuItem);
\r
404 colourMenu.add(userDefinedColour);
\r
405 colourMenu.addSeparator();
\r
406 colourMenu.add(abovePIDColour);
\r
407 colourMenu.add(conservationMenuItem);
\r
409 noColourmenuItem.setLabel("None");
\r
410 noColourmenuItem.addActionListener(this);
\r
412 clustalColour.setLabel("Clustalx colours");
\r
413 clustalColour.addActionListener(this);
\r
414 zappoColour.setLabel("Zappo");
\r
415 zappoColour.addActionListener(this);
\r
416 taylorColour.setLabel("Taylor");
\r
417 taylorColour.addActionListener(this);
\r
418 hydrophobicityColour.setLabel("Hydrophobicity");
\r
419 hydrophobicityColour.addActionListener(this);
\r
420 helixColour.setLabel("Helix propensity");
\r
421 helixColour.addActionListener(this);
\r
422 strandColour.setLabel("Strand propensity");
\r
423 strandColour.addActionListener(this);
\r
424 turnColour.setLabel("Turn propensity");
\r
425 turnColour.addActionListener(this);
\r
426 buriedColour.setLabel("Buried Index");
\r
427 buriedColour.addActionListener(this);
\r
428 abovePIDColour.setLabel("Above % Identity");
\r
430 userDefinedColour.setLabel("User Defined");
\r
431 userDefinedColour.addActionListener(this);
\r
432 PIDColour.setLabel("Percentage Identity");
\r
433 PIDColour.addActionListener(this);
\r
434 BLOSUM62Colour.setLabel("BLOSUM62");
\r
435 BLOSUM62Colour.addActionListener(this);
\r
436 conservationMenuItem.setLabel("Conservation");
\r
438 editMenu.add(copy);
\r
439 copy.addActionListener(this);
\r
441 cut.addActionListener(this);
\r
442 editMenu.add(toUpper);
\r
443 toUpper.addActionListener(this);
\r
444 editMenu.add(toLower);
\r
445 toLower.addActionListener(this);
\r
446 editMenu.add(toggleCase);
\r
448 seqMenu.add(repGroup);
\r
449 menu1.add(unGroupMenuItem);
\r
450 menu1.add(colourMenu);
\r
451 menu1.add(showBoxes);
\r
452 menu1.add(showText);
\r
453 menu1.add(showColourText);
\r
454 toggleCase.addActionListener(this);
\r
455 pdb.addActionListener(this);
\r
456 hideSeqs.addActionListener(this);
\r
457 repGroup.addActionListener(this);
\r
458 revealAll.addActionListener(this);
\r
464 ap.seqPanel.seqCanvas.repaint();
\r
465 if(ap.overviewPanel!=null)
\r
466 ap.overviewPanel.updateOverviewImage();
\r
469 protected void clustalColour_actionPerformed()
\r
471 SequenceGroup sg = getGroup();
\r
472 sg.cs = new ClustalxColourScheme(sg.getSequences(true), ap.av.alignment.getWidth());
\r
476 protected void zappoColour_actionPerformed()
\r
478 getGroup().cs = new ZappoColourScheme();
\r
482 protected void taylorColour_actionPerformed()
\r
484 getGroup().cs = new TaylorColourScheme();
\r
488 protected void hydrophobicityColour_actionPerformed()
\r
490 getGroup().cs = new HydrophobicColourScheme();
\r
494 protected void helixColour_actionPerformed()
\r
496 getGroup().cs = new HelixColourScheme();
\r
500 protected void strandColour_actionPerformed()
\r
502 getGroup().cs = new StrandColourScheme();
\r
506 protected void turnColour_actionPerformed()
\r
508 getGroup().cs = new TurnColourScheme();
\r
512 protected void buriedColour_actionPerformed()
\r
514 getGroup().cs = new BuriedColourScheme();
\r
518 public void nucleotideMenuItem_actionPerformed()
\r
520 getGroup().cs = new NucleotideColourScheme();
\r
524 protected void abovePIDColour_itemStateChanged()
\r
526 SequenceGroup sg = getGroup();
\r
530 if (abovePIDColour.getState())
\r
532 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(true), 0,
\r
533 ap.av.alignment.getWidth()));
\r
534 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs,
\r
535 getGroup().getName());
\r
537 sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus());
\r
539 SliderPanel.showPIDSlider();
\r
542 else // remove PIDColouring
\r
544 sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
\r
551 protected void userDefinedColour_actionPerformed()
\r
553 new UserDefinedColours(ap, getGroup());
\r
556 protected void PIDColour_actionPerformed()
\r
558 SequenceGroup sg = getGroup();
\r
559 sg.cs = new PIDColourScheme();
\r
560 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(true), 0,
\r
561 ap.av.alignment.getWidth()));
\r
565 protected void BLOSUM62Colour_actionPerformed()
\r
567 SequenceGroup sg = getGroup();
\r
569 sg.cs = new Blosum62ColourScheme();
\r
571 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(true), 0,
\r
572 ap.av.alignment.getWidth()));
\r
577 protected void noColourmenuItem_actionPerformed()
\r
579 getGroup().cs = null;
\r
583 protected void conservationMenuItem_itemStateChanged()
\r
585 SequenceGroup sg = getGroup();
\r
589 if (conservationMenuItem.getState())
\r
592 Conservation c = new Conservation("Group",
\r
593 ResidueProperties.propHash, 3,
\r
594 sg.getSequences(true), 0,
\r
595 ap.av.alignment.getWidth());
\r
598 c.verdict(false, ap.av.ConsPercGaps);
\r
600 sg.cs.setConservation(c);
\r
602 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
\r
603 SliderPanel.showConservationSlider();
\r
605 else // remove ConservationColouring
\r
607 sg.cs.setConservation(null);
\r
614 SequenceGroup getGroup()
\r
616 SequenceGroup sg = ap.av.getSelectionGroup();
\r
618 // this method won't add a new group if it already exists
\r
620 ap.av.alignment.addGroup(sg);
\r
625 void unGroupMenuItem_actionPerformed()
\r
627 SequenceGroup sg = ap.av.getSelectionGroup();
\r
628 ap.av.alignment.deleteGroup(sg);
\r
629 ap.av.setSelectionGroup(null);
\r
633 public void showColourText_itemStateChanged()
\r
635 getGroup().setColourText(showColourText.getState());
\r
639 public void showText_itemStateChanged()
\r
641 getGroup().setDisplayText(showText.getState());
\r
645 public void showBoxes_itemStateChanged()
\r
647 getGroup().setDisplayBoxes(showBoxes.getState());
\r
651 void hideSequences(boolean representGroup)
\r
653 SequenceGroup sg = ap.av.getSelectionGroup();
\r
654 if(sg==null || sg.getSize(false)<1)
\r
656 ap.av.hideSequence(new SequenceI[]{seq});
\r
660 int gsize = sg.getSize(false);
\r
661 SequenceI [] hseqs;
\r
663 hseqs = new SequenceI[ representGroup ? gsize-1 : gsize ];
\r
666 for(int i=0; i<gsize; i++)
\r
668 if(representGroup && sg.getSequenceAt(i)!=seq)
\r
670 seq.addHiddenSequence(sg.getSequenceAt(i));
\r
671 hseqs[index++] = sg.getSequenceAt(i);
\r
673 else if(!representGroup)
\r
675 hseqs[index++] = sg.getSequenceAt(i);
\r
679 ap.av.hideSequence(hseqs);
\r
681 ap.av.setSelectionGroup(null);
\r