2 * Jalview - A Sequence Alignment Editor and Viewer
\r
3 * Copyright (C) 2005 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
30 public class APopupMenu
\r
31 extends java.awt.PopupMenu implements ActionListener, ItemListener
\r
33 Menu groupMenu = new Menu();
\r
34 protected MenuItem clustalColour = new MenuItem();
\r
35 protected MenuItem zappoColour = new MenuItem();
\r
36 protected MenuItem taylorColour = new MenuItem();
\r
37 protected MenuItem hydrophobicityColour = new MenuItem();
\r
38 protected MenuItem helixColour = new MenuItem();
\r
39 protected MenuItem strandColour = new MenuItem();
\r
40 protected MenuItem turnColour = new MenuItem();
\r
41 protected MenuItem buriedColour = new MenuItem();
\r
42 protected CheckboxMenuItem abovePIDColour = new CheckboxMenuItem();
\r
43 protected MenuItem userDefinedColour = new MenuItem();
\r
44 protected MenuItem PIDColour = new MenuItem();
\r
45 protected MenuItem BLOSUM62Colour = new MenuItem();
\r
46 MenuItem noColourmenuItem = new MenuItem();
\r
47 protected CheckboxMenuItem conservationMenuItem = new CheckboxMenuItem();
\r
49 final AlignmentPanel ap;
\r
50 MenuItem unGroupMenuItem = new MenuItem();
\r
51 MenuItem nucleotideMenuItem = new MenuItem();
\r
52 Menu colourMenu = new Menu();
\r
53 CheckboxMenuItem showBoxes = new CheckboxMenuItem();
\r
54 CheckboxMenuItem showText = new CheckboxMenuItem();
\r
55 CheckboxMenuItem showColourText = new CheckboxMenuItem();
\r
56 Menu editMenu = new Menu("Edit");
\r
57 MenuItem copy = new MenuItem("Copy (Jalview Only)");
\r
58 MenuItem cut = new MenuItem("Cut (Jalview Only)");
\r
59 MenuItem toUpper = new MenuItem("To Upper Case");
\r
60 MenuItem toLower = new MenuItem("To Lower Case");
\r
61 MenuItem toggleCase = new MenuItem("Toggle Case");
\r
62 Menu outputmenu = new Menu();
\r
63 Menu seqMenu = new Menu();
\r
64 MenuItem pdb = new MenuItem();
\r
65 MenuItem hideSeqs = new MenuItem();
\r
66 MenuItem repGroup = new MenuItem();
\r
69 MenuItem revealAll = new MenuItem();
\r
71 public APopupMenu(AlignmentPanel apanel, final Sequence seq, Vector links)
\r
73 ///////////////////////////////////////////////////////////
\r
74 // If this is activated from the sequence panel, the user may want to
\r
75 // edit or annotate a particular residue. Therefore display the residue menu
\r
77 // If from the IDPanel, we must display the sequence menu
\r
78 //////////////////////////////////////////////////////////
\r
89 e.printStackTrace();
\r
92 for (int i = 0; i < jalview.io.AppletFormatAdapter.formats.size()-1; i++)
\r
94 MenuItem item = new MenuItem( (String) jalview.io.AppletFormatAdapter.formats.
\r
97 item.addActionListener(this);
\r
98 outputmenu.add(item);
\r
101 SequenceGroup sg = ap.av.getSelectionGroup();
\r
103 if (sg != null && sg.getSize(false)>0)
\r
105 showText.setState(sg.getDisplayText());
\r
106 showColourText.setState(sg.getColourText());
\r
107 showBoxes.setState(sg.getDisplayBoxes());
\r
108 if (!ap.av.alignment.getGroups().contains(sg))
\r
110 groupMenu.remove(unGroupMenuItem);
\r
122 Menu linkMenu = new Menu("Link");
\r
125 for(int i=0; i<links.size(); i++)
\r
127 link = links.elementAt(i).toString();
\r
128 final String target = link.substring(0, link.indexOf("|"));
\r
129 item = new MenuItem(target);
\r
133 if (link.indexOf("$SEQUENCE_ID$") > -1)
\r
135 String id = seq.getName();
\r
136 if (id.indexOf("|") > -1)
\r
137 id = id.substring(id.lastIndexOf("|") + 1);
\r
139 url = link.substring(link.indexOf("|") + 1,
\r
140 link.indexOf("$SEQUENCE_ID$"))
\r
142 link.substring(link.indexOf("$SEQUENCE_ID$") + 13);
\r
145 url = link.substring(link.lastIndexOf("|")+1);
\r
147 System.out.println("add "+url +" "+target);
\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==clustalColour)
\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
233 else if(source==copy)
\r
234 ap.alignFrame.copy_actionPerformed();
\r
235 else if(source==cut)
\r
236 ap.alignFrame.cut_actionPerformed();
\r
237 else if(source==toUpper || source==toLower || source==toggleCase)
\r
239 SequenceGroup sg = ap.av.getSelectionGroup();
\r
242 for (int g = 0; g < sg.getSize(true); g++)
\r
244 if (source == toggleCase)
\r
245 ((SequenceI) sg.getSequences(true).elementAt(g))
\r
246 .toggleCase(sg.getStartRes(), sg.getEndRes() + 1);
\r
248 ((SequenceI) sg.getSequences(true).elementAt(g))
\r
249 .changeCase(source == toUpper, sg.getStartRes(),
\r
250 sg.getEndRes() + 1);
\r
252 ap.seqPanel.seqCanvas.repaint();
\r
260 void outputText(ActionEvent e)
\r
262 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, ap.alignFrame);
\r
263 Vector vseqs = new Vector();
\r
265 String [] selection = ap.av.getViewAsString(true);
\r
266 SequenceI [] seqs = ap.av.getSelectionAsNewSequence();
\r
267 if (selection != null)
\r
269 for (int i = 0; i < selection.length; i++)
\r
271 Sequence seq = new Sequence(
\r
274 seqs[i].getStart(), seqs[i].getEnd());
\r
275 seq.setDescription(seqs[i].getDescription());
\r
276 vseqs.addElement( seq );
\r
280 Frame frame = new Frame();
\r
282 jalview.bin.JalviewLite.addFrame(frame,
\r
283 "Selection output - " + e.getActionCommand(),
\r
286 cap.setText(new jalview.io.AppletFormatAdapter().formatSequences(
\r
287 e.getActionCommand(),
\r
289 ap.av.showJVSuffix));
\r
295 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
\r
296 cap.setText("Paste your PDB file here.");
\r
297 cap.setPDBImport(seq);
\r
298 Frame frame = new Frame();
\r
300 jalview.bin.JalviewLite.addFrame(frame, "Paste PDB file ", 400, 300);
\r
303 private void jbInit()
\r
306 groupMenu.setLabel("Group");
\r
307 groupMenu.setLabel("Selection");
\r
309 unGroupMenuItem.setLabel("Remove Group");
\r
310 unGroupMenuItem.addActionListener(this);
\r
312 nucleotideMenuItem.setLabel("Nucleotide");
\r
313 nucleotideMenuItem.addActionListener(this);
\r
314 conservationMenuItem.addItemListener(this);
\r
315 abovePIDColour.addItemListener(this);
\r
316 colourMenu.setLabel("Group Colour");
\r
317 showBoxes.setLabel("Boxes");
\r
318 showBoxes.setState(true);
\r
319 showBoxes.addItemListener(this);
\r
321 showText.setLabel("Text");
\r
322 showText.addItemListener(this);
\r
323 showColourText.setLabel("Colour Text");
\r
324 showColourText.addItemListener(this);
\r
325 outputmenu.setLabel("Output to Textbox...");
\r
326 seqMenu.setLabel("Sequence");
\r
327 pdb.setLabel("View PDB Structure");
\r
328 hideSeqs.setLabel("Hide Sequences");
\r
329 repGroup.setLabel("Represent Group with");
\r
330 revealAll.setLabel("Reveal All");
\r
334 this.add(hideSeqs);
\r
335 this.add(revealAll);
\r
336 groupMenu.add(editMenu);
\r
337 groupMenu.add(outputmenu);
\r
338 groupMenu.addSeparator();
\r
339 groupMenu.add(unGroupMenuItem);
\r
340 groupMenu.add(colourMenu);
\r
341 groupMenu.add(showBoxes);
\r
342 groupMenu.add(showText);
\r
343 groupMenu.add(showColourText);
\r
344 colourMenu.add(noColourmenuItem);
\r
345 colourMenu.add(clustalColour);
\r
346 colourMenu.add(BLOSUM62Colour);
\r
347 colourMenu.add(PIDColour);
\r
348 colourMenu.add(zappoColour);
\r
349 colourMenu.add(taylorColour);
\r
350 colourMenu.add(hydrophobicityColour);
\r
351 colourMenu.add(helixColour);
\r
352 colourMenu.add(strandColour);
\r
353 colourMenu.add(turnColour);
\r
354 colourMenu.add(buriedColour);
\r
355 colourMenu.add(nucleotideMenuItem);
\r
356 colourMenu.add(userDefinedColour);
\r
357 colourMenu.addSeparator();
\r
358 colourMenu.add(abovePIDColour);
\r
359 colourMenu.add(conservationMenuItem);
\r
361 noColourmenuItem.setLabel("None");
\r
362 noColourmenuItem.addActionListener(this);
\r
364 clustalColour.setLabel("Clustalx colours");
\r
365 clustalColour.addActionListener(this);
\r
366 zappoColour.setLabel("Zappo");
\r
367 zappoColour.addActionListener(this);
\r
368 taylorColour.setLabel("Taylor");
\r
369 taylorColour.addActionListener(this);
\r
370 hydrophobicityColour.setLabel("Hydrophobicity");
\r
371 hydrophobicityColour.addActionListener(this);
\r
372 helixColour.setLabel("Helix propensity");
\r
373 helixColour.addActionListener(this);
\r
374 strandColour.setLabel("Strand propensity");
\r
375 strandColour.addActionListener(this);
\r
376 turnColour.setLabel("Turn propensity");
\r
377 turnColour.addActionListener(this);
\r
378 buriedColour.setLabel("Buried Index");
\r
379 buriedColour.addActionListener(this);
\r
380 abovePIDColour.setLabel("Above % Identity");
\r
382 userDefinedColour.setLabel("User Defined");
\r
383 userDefinedColour.addActionListener(this);
\r
384 PIDColour.setLabel("Percentage Identity");
\r
385 PIDColour.addActionListener(this);
\r
386 BLOSUM62Colour.setLabel("BLOSUM62");
\r
387 BLOSUM62Colour.addActionListener(this);
\r
388 conservationMenuItem.setLabel("Conservation");
\r
390 editMenu.add(copy);
\r
391 copy.addActionListener(this);
\r
393 cut.addActionListener(this);
\r
394 editMenu.add(toUpper);
\r
395 toUpper.addActionListener(this);
\r
396 editMenu.add(toLower);
\r
397 toLower.addActionListener(this);
\r
398 editMenu.add(toggleCase);
\r
400 seqMenu.add(repGroup);
\r
401 toggleCase.addActionListener(this);
\r
402 pdb.addActionListener(this);
\r
403 hideSeqs.addActionListener(this);
\r
404 repGroup.addActionListener(this);
\r
405 revealAll.addActionListener(this);
\r
411 ap.seqPanel.seqCanvas.repaint();
\r
412 if(ap.overviewPanel!=null)
\r
413 ap.overviewPanel.updateOverviewImage();
\r
416 protected void clustalColour_actionPerformed()
\r
418 SequenceGroup sg = getGroup();
\r
419 sg.cs = new ClustalxColourScheme(sg.getSequences(true), ap.av.alignment.getWidth());
\r
423 protected void zappoColour_actionPerformed()
\r
425 getGroup().cs = new ZappoColourScheme();
\r
429 protected void taylorColour_actionPerformed()
\r
431 getGroup().cs = new TaylorColourScheme();
\r
435 protected void hydrophobicityColour_actionPerformed()
\r
437 getGroup().cs = new HydrophobicColourScheme();
\r
441 protected void helixColour_actionPerformed()
\r
443 getGroup().cs = new HelixColourScheme();
\r
447 protected void strandColour_actionPerformed()
\r
449 getGroup().cs = new StrandColourScheme();
\r
453 protected void turnColour_actionPerformed()
\r
455 getGroup().cs = new TurnColourScheme();
\r
459 protected void buriedColour_actionPerformed()
\r
461 getGroup().cs = new BuriedColourScheme();
\r
465 public void nucleotideMenuItem_actionPerformed()
\r
467 getGroup().cs = new NucleotideColourScheme();
\r
471 protected void abovePIDColour_itemStateChanged()
\r
473 SequenceGroup sg = getGroup();
\r
477 if (abovePIDColour.getState())
\r
479 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(true), 0,
\r
480 ap.av.alignment.getWidth()));
\r
481 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs,
\r
482 getGroup().getName());
\r
484 sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus());
\r
486 SliderPanel.showPIDSlider();
\r
489 else // remove PIDColouring
\r
491 sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
\r
498 protected void userDefinedColour_actionPerformed()
\r
500 new UserDefinedColours(ap, getGroup());
\r
503 protected void PIDColour_actionPerformed()
\r
505 SequenceGroup sg = getGroup();
\r
506 sg.cs = new PIDColourScheme();
\r
507 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(true), 0,
\r
508 ap.av.alignment.getWidth()));
\r
512 protected void BLOSUM62Colour_actionPerformed()
\r
514 SequenceGroup sg = getGroup();
\r
516 sg.cs = new Blosum62ColourScheme();
\r
518 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(true), 0,
\r
519 ap.av.alignment.getWidth()));
\r
524 protected void noColourmenuItem_actionPerformed()
\r
526 getGroup().cs = null;
\r
530 protected void conservationMenuItem_itemStateChanged()
\r
532 SequenceGroup sg = getGroup();
\r
536 if (conservationMenuItem.getState())
\r
539 Conservation c = new Conservation("Group",
\r
540 ResidueProperties.propHash, 3,
\r
541 sg.getSequences(true), 0,
\r
542 ap.av.alignment.getWidth());
\r
545 c.verdict(false, ap.av.ConsPercGaps);
\r
547 sg.cs.setConservation(c);
\r
549 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
\r
550 SliderPanel.showConservationSlider();
\r
552 else // remove ConservationColouring
\r
554 sg.cs.setConservation(null);
\r
561 SequenceGroup getGroup()
\r
563 SequenceGroup sg = ap.av.getSelectionGroup();
\r
565 // this method won't add a new group if it already exists
\r
567 ap.av.alignment.addGroup(sg);
\r
572 void unGroupMenuItem_actionPerformed()
\r
574 SequenceGroup sg = ap.av.getSelectionGroup();
\r
575 ap.av.alignment.deleteGroup(sg);
\r
576 ap.av.setSelectionGroup(null);
\r
580 public void showColourText_itemStateChanged()
\r
582 getGroup().setColourText(showColourText.getState());
\r
586 public void showText_itemStateChanged()
\r
588 getGroup().setDisplayText(showText.getState());
\r
592 public void showBoxes_itemStateChanged()
\r
594 getGroup().setDisplayBoxes(showBoxes.getState());
\r
598 void hideSequences(boolean representGroup)
\r
600 SequenceGroup sg = ap.av.getSelectionGroup();
\r
601 if(sg==null || sg.getSize(false)<1)
\r
603 ap.av.hideSequence(seq);
\r
608 while(index < sg.getSize(false))
\r
610 if(representGroup && sg.getSequenceAt(index)!=seq)
\r
612 seq.addHiddenSequence(sg.getSequenceAt(index));
\r
613 ap.av.hideSequence(sg.getSequenceAt(index));
\r
615 else if(!representGroup)
\r
617 ap.av.hideSequence(sg.getSequenceAt(index));
\r
622 ap.av.setSelectionGroup(null);
\r