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
63 public APopupMenu(AlignmentPanel apanel, final Sequence seq, Vector links)
\r
65 ///////////////////////////////////////////////////////////
\r
66 // If this is activated from the sequence panel, the user may want to
\r
67 // edit or annotate a particular residue. Therefore display the residue menu
\r
69 // If from the IDPanel, we must display the sequence menu
\r
70 //////////////////////////////////////////////////////////
\r
80 e.printStackTrace();
\r
83 SequenceGroup sg = ap.av.getSelectionGroup();
\r
85 if (sg != null && sg.getSize(false)>0)
\r
87 showText.setState(sg.getDisplayText());
\r
88 showColourText.setState(sg.getColourText());
\r
89 showBoxes.setState(sg.getDisplayBoxes());
\r
90 if (!ap.av.alignment.getGroups().contains(sg))
\r
92 groupMenu.remove(unGroupMenuItem);
\r
104 Menu linkMenu = new Menu("Link");
\r
107 for(int i=0; i<links.size(); i++)
\r
109 link = links.elementAt(i).toString();
\r
110 final String target = link.substring(0, link.indexOf("|"));
\r
111 item = new MenuItem(target);
\r
115 if (link.indexOf("$SEQUENCE_ID$") > -1)
\r
117 String id = seq.getName();
\r
118 if (id.indexOf("|") > -1)
\r
119 id = id.substring(id.lastIndexOf("|") + 1);
\r
121 url = link.substring(link.indexOf("|") + 1,
\r
122 link.indexOf("$SEQUENCE_ID$"))
\r
124 link.substring(link.indexOf("$SEQUENCE_ID$") + 13);
\r
127 url = link.substring(link.lastIndexOf("|")+1);
\r
129 item.addActionListener(new java.awt.event.ActionListener()
\r
131 public void actionPerformed(ActionEvent e)
\r
133 ap.alignFrame.showURL(url, target);
\r
136 linkMenu.add(item);
\r
142 item = new MenuItem("Show PDB Structure");
\r
143 item.addActionListener(new java.awt.event.ActionListener()
\r
145 public void actionPerformed(ActionEvent e)
\r
156 public void itemStateChanged(ItemEvent evt)
\r
158 if(evt.getSource()==abovePIDColour)
\r
159 abovePIDColour_itemStateChanged();
\r
160 else if(evt.getSource()==showColourText)
\r
161 showColourText_itemStateChanged();
\r
162 else if(evt.getSource()==showText)
\r
163 showText_itemStateChanged();
\r
164 else if(evt.getSource()==showBoxes)
\r
165 showBoxes_itemStateChanged() ;
\r
168 public void actionPerformed(ActionEvent evt)
\r
170 Object source = evt.getSource();
\r
171 if(source==clustalColour)
\r
172 clustalColour_actionPerformed();
\r
173 else if(source==zappoColour)
\r
174 zappoColour_actionPerformed();
\r
175 else if(source==taylorColour)
\r
176 taylorColour_actionPerformed();
\r
177 else if(source==hydrophobicityColour)
\r
178 hydrophobicityColour_actionPerformed();
\r
179 else if(source==helixColour)
\r
180 helixColour_actionPerformed();
\r
181 else if(source==strandColour)
\r
182 strandColour_actionPerformed();
\r
183 else if(source==clustalColour)
\r
184 turnColour_actionPerformed();
\r
185 else if(source==buriedColour)
\r
186 buriedColour_actionPerformed();
\r
187 else if(source==nucleotideMenuItem)
\r
188 nucleotideMenuItem_actionPerformed();
\r
190 else if(source==userDefinedColour)
\r
191 userDefinedColour_actionPerformed();
\r
192 else if(source==PIDColour)
\r
193 PIDColour_actionPerformed();
\r
194 else if(source==BLOSUM62Colour)
\r
195 BLOSUM62Colour_actionPerformed();
\r
196 else if(source==noColourmenuItem)
\r
197 noColourmenuItem_actionPerformed();
\r
198 else if(source==conservationMenuItem)
\r
199 conservationMenuItem_itemStateChanged();
\r
200 else if(source==unGroupMenuItem)
\r
201 unGroupMenuItem_actionPerformed();
\r
203 else if(source==copy)
\r
204 ap.alignFrame.copy_actionPerformed();
\r
205 else if(source==cut)
\r
206 ap.alignFrame.cut_actionPerformed();
\r
207 else if(source==toUpper || source==toLower || source==toggleCase)
\r
209 SequenceGroup sg = ap.av.getSelectionGroup();
\r
212 for (int g = 0; g < sg.getSize(true); g++)
\r
214 if (source == toggleCase)
\r
215 ((SequenceI) sg.getSequences(true).elementAt(g))
\r
216 .toggleCase(sg.getStartRes(), sg.getEndRes() + 1);
\r
218 ((SequenceI) sg.getSequences(true).elementAt(g))
\r
219 .changeCase(source == toUpper, sg.getStartRes(),
\r
220 sg.getEndRes() + 1);
\r
222 ap.seqPanel.seqCanvas.repaint();
\r
228 void addPDB(Sequence seq)
\r
230 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, ap.alignFrame);
\r
231 cap.setText("Paste your PDB file here.");
\r
232 cap.setPDBImport(seq);
\r
233 Frame frame = new Frame();
\r
235 jalview.bin.JalviewLite.addFrame(frame, "Paste PDB file ", 400, 300);
\r
238 private void jbInit()
\r
241 groupMenu.setLabel("Group");
\r
242 groupMenu.setLabel("Define");
\r
244 unGroupMenuItem.setLabel("Remove Group");
\r
245 unGroupMenuItem.addActionListener(this);
\r
247 nucleotideMenuItem.setLabel("Nucleotide");
\r
248 nucleotideMenuItem.addActionListener(this);
\r
249 conservationMenuItem.addItemListener(this);
\r
250 abovePIDColour.addItemListener(this);
\r
251 colourMenu.setLabel("Group Colour");
\r
252 showBoxes.setLabel("Boxes");
\r
253 showBoxes.setState(true);
\r
254 showBoxes.addItemListener(this);
\r
256 showText.setLabel("Text");
\r
257 showText.addItemListener(this);
\r
258 showColourText.setLabel("Colour Text");
\r
259 showColourText.addItemListener(this);
\r
262 groupMenu.add(unGroupMenuItem);
\r
263 groupMenu.add(colourMenu);
\r
264 groupMenu.addSeparator();
\r
265 groupMenu.add(showBoxes);
\r
266 groupMenu.add(showText);
\r
267 groupMenu.add(showColourText);
\r
268 colourMenu.add(noColourmenuItem);
\r
269 colourMenu.add(clustalColour);
\r
270 colourMenu.add(BLOSUM62Colour);
\r
271 colourMenu.add(PIDColour);
\r
272 colourMenu.add(zappoColour);
\r
273 colourMenu.add(taylorColour);
\r
274 colourMenu.add(hydrophobicityColour);
\r
275 colourMenu.add(helixColour);
\r
276 colourMenu.add(strandColour);
\r
277 colourMenu.add(turnColour);
\r
278 colourMenu.add(buriedColour);
\r
279 colourMenu.add(nucleotideMenuItem);
\r
280 colourMenu.add(userDefinedColour);
\r
281 colourMenu.addSeparator();
\r
282 colourMenu.add(abovePIDColour);
\r
283 colourMenu.add(conservationMenuItem);
\r
285 noColourmenuItem.setLabel("None");
\r
286 noColourmenuItem.addActionListener(this);
\r
288 clustalColour.setLabel("Clustalx colours");
\r
289 clustalColour.addActionListener(this);
\r
290 zappoColour.setLabel("Zappo");
\r
291 zappoColour.addActionListener(this);
\r
292 taylorColour.setLabel("Taylor");
\r
293 taylorColour.addActionListener(this);
\r
294 hydrophobicityColour.setLabel("Hydrophobicity");
\r
295 hydrophobicityColour.addActionListener(this);
\r
296 helixColour.setLabel("Helix propensity");
\r
297 helixColour.addActionListener(this);
\r
298 strandColour.setLabel("Strand propensity");
\r
299 strandColour.addActionListener(this);
\r
300 turnColour.setLabel("Turn propensity");
\r
301 turnColour.addActionListener(this);
\r
302 buriedColour.setLabel("Buried Index");
\r
303 buriedColour.addActionListener(this);
\r
304 abovePIDColour.setLabel("Above % Identity");
\r
306 userDefinedColour.setLabel("User Defined");
\r
307 userDefinedColour.addActionListener(this);
\r
308 PIDColour.setLabel("Percentage Identity");
\r
309 PIDColour.addActionListener(this);
\r
310 BLOSUM62Colour.setLabel("BLOSUM62");
\r
311 BLOSUM62Colour.addActionListener(this);
\r
312 conservationMenuItem.setLabel("Conservation");
\r
315 editMenu.add(copy);
\r
316 copy.addActionListener(this);
\r
318 cut.addActionListener(this);
\r
319 editMenu.add(toUpper);
\r
320 toUpper.addActionListener(this);
\r
321 editMenu.add(toLower);
\r
322 toLower.addActionListener(this);
\r
323 editMenu.add(toggleCase);
\r
324 toggleCase.addActionListener(this);
\r
330 ap.seqPanel.seqCanvas.repaint();
\r
331 if(ap.overviewPanel!=null)
\r
332 ap.overviewPanel.updateOverviewImage();
\r
335 protected void clustalColour_actionPerformed()
\r
337 SequenceGroup sg = getGroup();
\r
338 sg.cs = new ClustalxColourScheme(sg.getSequences(true), ap.av.alignment.getWidth());
\r
342 protected void zappoColour_actionPerformed()
\r
344 getGroup().cs = new ZappoColourScheme();
\r
348 protected void taylorColour_actionPerformed()
\r
350 getGroup().cs = new TaylorColourScheme();
\r
354 protected void hydrophobicityColour_actionPerformed()
\r
356 getGroup().cs = new HydrophobicColourScheme();
\r
360 protected void helixColour_actionPerformed()
\r
362 getGroup().cs = new HelixColourScheme();
\r
366 protected void strandColour_actionPerformed()
\r
368 getGroup().cs = new StrandColourScheme();
\r
372 protected void turnColour_actionPerformed()
\r
374 getGroup().cs = new TurnColourScheme();
\r
378 protected void buriedColour_actionPerformed()
\r
380 getGroup().cs = new BuriedColourScheme();
\r
384 public void nucleotideMenuItem_actionPerformed()
\r
386 getGroup().cs = new NucleotideColourScheme();
\r
390 protected void abovePIDColour_itemStateChanged()
\r
392 SequenceGroup sg = getGroup();
\r
396 if (abovePIDColour.getState())
\r
398 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(true), 0,
\r
399 ap.av.alignment.getWidth()));
\r
400 int threshold = SliderPanel.setPIDSliderSource(ap, sg.cs,
\r
401 getGroup().getName());
\r
403 sg.cs.setThreshold(threshold, ap.av.getIgnoreGapsConsensus());
\r
405 SliderPanel.showPIDSlider();
\r
408 else // remove PIDColouring
\r
410 sg.cs.setThreshold(0, ap.av.getIgnoreGapsConsensus());
\r
417 protected void userDefinedColour_actionPerformed()
\r
419 new UserDefinedColours(ap, getGroup());
\r
422 protected void PIDColour_actionPerformed()
\r
424 SequenceGroup sg = getGroup();
\r
425 sg.cs = new PIDColourScheme();
\r
426 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(true), 0,
\r
427 ap.av.alignment.getWidth()));
\r
431 protected void BLOSUM62Colour_actionPerformed()
\r
433 SequenceGroup sg = getGroup();
\r
435 sg.cs = new Blosum62ColourScheme();
\r
437 sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(true), 0,
\r
438 ap.av.alignment.getWidth()));
\r
443 protected void noColourmenuItem_actionPerformed()
\r
445 getGroup().cs = null;
\r
449 protected void conservationMenuItem_itemStateChanged()
\r
451 SequenceGroup sg = getGroup();
\r
455 if (conservationMenuItem.getState())
\r
458 Conservation c = new Conservation("Group",
\r
459 ResidueProperties.propHash, 3,
\r
460 sg.getSequences(true), 0,
\r
461 ap.av.alignment.getWidth());
\r
464 c.verdict(false, ap.av.ConsPercGaps);
\r
466 sg.cs.setConservation(c);
\r
468 SliderPanel.setConservationSlider(ap, sg.cs, sg.getName());
\r
469 SliderPanel.showConservationSlider();
\r
471 else // remove ConservationColouring
\r
473 sg.cs.setConservation(null);
\r
480 SequenceGroup getGroup()
\r
482 SequenceGroup sg = ap.av.getSelectionGroup();
\r
484 // this method won't add a new group if it already exists
\r
486 ap.av.alignment.addGroup(sg);
\r
491 void unGroupMenuItem_actionPerformed()
\r
493 SequenceGroup sg = ap.av.getSelectionGroup();
\r
494 ap.av.alignment.deleteGroup(sg);
\r
495 ap.av.setSelectionGroup(null);
\r
499 public void showColourText_itemStateChanged()
\r
501 getGroup().setColourText(showColourText.getState());
\r
505 public void showText_itemStateChanged()
\r
507 getGroup().setDisplayText(showText.getState());
\r
511 public void showBoxes_itemStateChanged()
\r
513 getGroup().setDisplayBoxes(showBoxes.getState());
\r