Show hide cols and rows
[jalview.git] / src / jalview / appletgui / AlignFrame.java
1 /*\r
2  * Jalview - A Sequence Alignment Editor and Viewer\r
3  * Copyright (C) 2005 AM Waterhouse, J Procter, G Barton, M Clamp, S Searle\r
4  *\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
9  *\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
14  *\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
18  */\r
19 \r
20 package jalview.appletgui;\r
21 \r
22 import jalview.schemes.*;\r
23 import jalview.datamodel.*;\r
24 import jalview.analysis.*;\r
25 import jalview.io.*;\r
26 import java.awt.*;\r
27 import java.awt.event.*;\r
28 import java.util.*;\r
29 import java.io.InputStreamReader;\r
30 import java.io.BufferedReader;\r
31 import java.net.URL;\r
32 \r
33 \r
34 public class AlignFrame extends Frame implements ActionListener,\r
35     ItemListener, KeyListener, MouseListener\r
36 {\r
37   public AlignmentPanel alignPanel;\r
38   public AlignViewport viewport;\r
39   int NEW_WINDOW_WIDTH = 700;\r
40   int NEW_WINDOW_HEIGHT = 500;\r
41   jalview.bin.JalviewLite applet;\r
42 \r
43   String jalviewServletURL;\r
44 \r
45 \r
46    public AlignFrame(AlignmentI al,\r
47                      jalview.bin.JalviewLite applet,\r
48                      String title,\r
49                      boolean embedded)\r
50   {\r
51 \r
52     jalviewServletURL = applet.getParameter("APPLICATION_URL");\r
53 \r
54     try{\r
55       jbInit();\r
56     }catch(Exception ex)\r
57     {\r
58       ex.printStackTrace();\r
59     }\r
60 \r
61     this.applet = applet;\r
62     viewport = new AlignViewport(al, applet);\r
63     alignPanel = new AlignmentPanel(this, viewport);\r
64 \r
65     annotationPanelMenuItem.setState(viewport.showAnnotation);\r
66 \r
67     seqLimits.setState(viewport.showJVSuffix);\r
68 \r
69     if(applet!=null)\r
70     {\r
71       String param = applet.getParameter("sortBy");\r
72       if (param != null)\r
73       {\r
74         if (param.equalsIgnoreCase("Id"))\r
75           sortIDMenuItem_actionPerformed();\r
76         else if (param.equalsIgnoreCase("Pairwise Identity"))\r
77           sortPairwiseMenuItem_actionPerformed();\r
78       }\r
79 \r
80       param = applet.getParameter("wrap");\r
81       if (param != null)\r
82       {\r
83         if (param.equalsIgnoreCase("true"))\r
84         {\r
85           wrapMenuItem.setState(true);\r
86           wrapMenuItem_actionPerformed();\r
87         }\r
88       }\r
89 \r
90       try\r
91       {\r
92         param = applet.getParameter("windowWidth");\r
93         if (param != null)\r
94         {\r
95           int width = Integer.parseInt(param);\r
96           NEW_WINDOW_WIDTH = width;\r
97         }\r
98         param = applet.getParameter("windowHeight");\r
99         if (param != null)\r
100         {\r
101           int height = Integer.parseInt(param);\r
102           NEW_WINDOW_HEIGHT = height;\r
103         }\r
104       }\r
105       catch (Exception ex)\r
106       {}\r
107 \r
108     }\r
109 \r
110    //Some JVMS send keyevents to Top frame or lowest panel,\r
111    //Havent worked out why yet. So add to both this frame and seqCanvas for now\r
112    this.addKeyListener(this);\r
113    alignPanel.seqPanel.seqCanvas.addKeyListener(this);\r
114    alignPanel.idPanel.idCanvas.addKeyListener(this);\r
115 \r
116     viewport.addPropertyChangeListener(new java.beans.PropertyChangeListener()\r
117     {\r
118      public void propertyChange(java.beans.PropertyChangeEvent evt)\r
119      {\r
120        if (evt.getPropertyName().equals("alignment"))\r
121        {\r
122          alignmentChanged();\r
123        }\r
124      }\r
125    });\r
126 \r
127 \r
128    if(embedded)\r
129    {\r
130      setEmbedded();\r
131    }\r
132    else\r
133    {\r
134      add(alignPanel, BorderLayout.CENTER);\r
135      jalview.bin.JalviewLite.addFrame(this, title, NEW_WINDOW_WIDTH,\r
136                                       NEW_WINDOW_HEIGHT);\r
137    }\r
138    alignPanel.validate();\r
139    alignPanel.repaint();\r
140   }\r
141   public AlignViewport getAlignViewport()\r
142   {\r
143     return viewport;\r
144   }\r
145 \r
146   public SeqCanvas getSeqcanvas()\r
147   {\r
148     return alignPanel.seqPanel.seqCanvas;\r
149   }\r
150 \r
151 \r
152   /**\r
153    * DOCUMENT ME!\r
154    *\r
155    * @param String DOCUMENT ME!\r
156    */\r
157 \r
158   public void parseFeaturesFile(String file, String type)\r
159   {\r
160     Hashtable featureLinks = new Hashtable();\r
161     boolean featuresFile = false;\r
162     try{\r
163       featuresFile = new jalview.io.FeaturesFile(file, type).parse(viewport.alignment,\r
164                                          alignPanel.seqPanel.seqCanvas.\r
165                                          getFeatureRenderer().featureColours,\r
166                                          featureLinks,\r
167                                          true);\r
168     }\r
169     catch(Exception ex)\r
170     {\r
171       ex.printStackTrace();\r
172     }\r
173 \r
174     if(featuresFile)\r
175     {\r
176       if(featureLinks.size()>0)\r
177         alignPanel.seqPanel.seqCanvas\r
178             .getFeatureRenderer().featureLinks = featureLinks;\r
179       viewport.showSequenceFeatures = true;\r
180       sequenceFeatures.setState(true);\r
181       alignPanel.repaint();\r
182     }\r
183 \r
184   }\r
185 \r
186 \r
187   public void keyPressed(KeyEvent evt)\r
188   {\r
189     if (viewport.cursorMode\r
190         && evt.getKeyCode() >= KeyEvent.VK_0\r
191         && evt.getKeyCode() <= KeyEvent.VK_9)\r
192     {\r
193       alignPanel.seqPanel.numberPressed(evt.getKeyChar());\r
194     }\r
195 \r
196     switch (evt.getKeyCode())\r
197     {\r
198       case 27: // escape key\r
199         deselectAllSequenceMenuItem_actionPerformed();\r
200         break;\r
201       case KeyEvent.VK_X:\r
202         if (evt.isControlDown() || evt.isMetaDown())\r
203         {\r
204           cut_actionPerformed();\r
205         }\r
206         break;\r
207       case KeyEvent.VK_C:\r
208         if (viewport.cursorMode && !evt.isControlDown())\r
209         {\r
210           alignPanel.seqPanel.setCursorColumn();\r
211         }\r
212         if (evt.isControlDown() || evt.isMetaDown())\r
213         {\r
214           copy_actionPerformed();\r
215         }\r
216         break;\r
217       case KeyEvent.VK_V:\r
218         if (evt.isControlDown() || evt.isMetaDown())\r
219         {\r
220           paste(true);\r
221         }\r
222         break;\r
223       case KeyEvent.VK_A:\r
224         if (evt.isControlDown() || evt.isMetaDown())\r
225         {\r
226           selectAllSequenceMenuItem_actionPerformed();\r
227         }\r
228         break;\r
229       case KeyEvent.VK_DOWN:\r
230         if(viewport.cursorMode)\r
231         {\r
232           alignPanel.seqPanel.moveCursor(0,1);\r
233         }\r
234         else\r
235           moveSelectedSequences(false);\r
236         break;\r
237 \r
238       case KeyEvent.VK_UP:\r
239         if (viewport.cursorMode)\r
240         {\r
241           alignPanel.seqPanel.moveCursor(0,-1);\r
242         }\r
243         else\r
244           moveSelectedSequences(true);\r
245         break;\r
246 \r
247       case KeyEvent.VK_LEFT:\r
248         if(viewport.cursorMode)\r
249         {\r
250           alignPanel.seqPanel.moveCursor(-1,0);\r
251         }\r
252         break;\r
253 \r
254       case KeyEvent.VK_RIGHT:\r
255         if (viewport.cursorMode)\r
256         {\r
257           alignPanel.seqPanel.moveCursor(1,0);\r
258         }\r
259         break;\r
260       case KeyEvent.VK_SPACE:\r
261         if(viewport.cursorMode)\r
262         {\r
263           alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown());\r
264         }\r
265         break;\r
266 \r
267       case KeyEvent.VK_DELETE:\r
268       case KeyEvent.VK_BACK_SPACE:\r
269         if(viewport.cursorMode)\r
270         {\r
271           alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown());\r
272         }\r
273        else\r
274         {\r
275           cut_actionPerformed();\r
276           alignPanel.seqPanel.seqCanvas.repaint();\r
277         }\r
278         break;\r
279 \r
280       case KeyEvent.VK_S:\r
281         if(viewport.cursorMode)\r
282         {\r
283           alignPanel.seqPanel.setCursorRow();\r
284         }\r
285         break;\r
286       case KeyEvent.VK_P:\r
287         if(viewport.cursorMode)\r
288         {\r
289           alignPanel.seqPanel.setCursorPosition();\r
290         }\r
291         break;\r
292 \r
293       case KeyEvent.VK_ENTER:\r
294       case KeyEvent.VK_COMMA:\r
295         if(viewport.cursorMode)\r
296         {\r
297           alignPanel.seqPanel.setCursorRowAndColumn();\r
298         }\r
299         break;\r
300 \r
301       case KeyEvent.VK_Q:\r
302         if(viewport.cursorMode)\r
303         {\r
304           alignPanel.seqPanel.setSelectionAreaAtCursor(true);\r
305         }\r
306         break;\r
307       case KeyEvent.VK_M:\r
308         if(viewport.cursorMode)\r
309         {\r
310           alignPanel.seqPanel.setSelectionAreaAtCursor(false);\r
311         }\r
312         break;\r
313 \r
314      case KeyEvent.VK_F2:\r
315        viewport.cursorMode = ! viewport.cursorMode;\r
316        statusBar.setText("Keyboard editing mode is "+\r
317            (viewport.cursorMode ? "on" : "off"));\r
318        if(viewport.cursorMode)\r
319        {\r
320          alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;\r
321          alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;\r
322        }\r
323        alignPanel.seqPanel.seqCanvas.repaint();\r
324        break;\r
325 \r
326       case KeyEvent.VK_F:\r
327         if (evt.isControlDown())\r
328         {\r
329           findMenuItem_actionPerformed();\r
330         }\r
331         break;\r
332     }\r
333   }\r
334   public void keyReleased(KeyEvent evt)\r
335   {}\r
336   public void keyTyped(KeyEvent evt)\r
337   {}\r
338 \r
339 public void itemStateChanged(ItemEvent evt)\r
340   {\r
341     if(evt.getSource()==colourTextMenuItem)\r
342             colourTextMenuItem_actionPerformed();\r
343     else if(evt.getSource()==wrapMenuItem)\r
344             wrapMenuItem_actionPerformed();\r
345     else if(evt.getSource()==scaleAbove)\r
346             scaleAbove_actionPerformed();\r
347     else if(evt.getSource()==scaleLeft)\r
348             scaleLeft_actionPerformed();\r
349     else if(evt.getSource()==scaleRight)\r
350             scaleRight_actionPerformed();\r
351      else if(evt.getSource()==seqLimits)\r
352       seqLimits_itemStateChanged();\r
353     else if(evt.getSource()==viewBoxesMenuItem)\r
354             viewBoxesMenuItem_actionPerformed();\r
355     else if(evt.getSource()==viewTextMenuItem)\r
356             viewTextMenuItem_actionPerformed();\r
357     else if(evt.getSource()==renderGapsMenuItem)\r
358             renderGapsMenuItem_actionPerformed();\r
359     else if(evt.getSource()==annotationPanelMenuItem)\r
360             annotationPanelMenuItem_actionPerformed();\r
361       else if(evt.getSource()==sequenceFeatures)\r
362       {\r
363            viewport.showSequenceFeatures(sequenceFeatures.getState());\r
364             alignPanel.seqPanel.seqCanvas.repaint();\r
365       }\r
366       else if(evt.getSource()==conservationMenuItem)\r
367             conservationMenuItem_actionPerformed();\r
368       else if(evt.getSource()==abovePIDThreshold)\r
369             abovePIDThreshold_actionPerformed();\r
370           else if(evt.getSource()==applyToAllGroups)\r
371             applyToAllGroups_actionPerformed();\r
372       else if(evt.getSource()==autoCalculate)\r
373           viewport.autocalculateConsensus = autoCalculate.getState();\r
374   }\r
375  public void actionPerformed(ActionEvent evt)\r
376  {\r
377     if(evt.getSource()==inputText)\r
378       inputText_actionPerformed();\r
379     else if(evt.getSource()==loadTree)\r
380       loadTree_actionPerformed();\r
381     else if(evt.getSource()==loadApplication)\r
382       launchFullApplication();\r
383     else if(evt.getSource()==closeMenuItem)\r
384       closeMenuItem_actionPerformed();\r
385     else if(evt.getSource()==copy)\r
386       copy_actionPerformed();\r
387     else if(evt.getSource()==undoMenuItem)\r
388       undoMenuItem_actionPerformed();\r
389     else if(evt.getSource()==redoMenuItem)\r
390       redoMenuItem_actionPerformed();\r
391     else if(evt.getSource()==inputText)\r
392             inputText_actionPerformed();\r
393     else if(evt.getSource()==closeMenuItem)\r
394             closeMenuItem_actionPerformed();\r
395     else if(evt.getSource()==undoMenuItem)\r
396             undoMenuItem_actionPerformed();\r
397     else if(evt.getSource()==redoMenuItem)\r
398             redoMenuItem_actionPerformed();\r
399     else if(evt.getSource()==copy)\r
400             copy_actionPerformed();\r
401     else if(evt.getSource()==pasteNew)\r
402             pasteNew_actionPerformed();\r
403     else if(evt.getSource()==pasteThis)\r
404             pasteThis_actionPerformed();\r
405     else if(evt.getSource()==cut)\r
406             cut_actionPerformed();\r
407     else if(evt.getSource()==delete)\r
408             delete_actionPerformed();\r
409     else if(evt.getSource()==deleteGroups)\r
410             deleteGroups_actionPerformed();\r
411     else if(evt.getSource()==selectAllSequenceMenuItem)\r
412             selectAllSequenceMenuItem_actionPerformed();\r
413     else if(evt.getSource()==deselectAllSequenceMenuItem)\r
414             deselectAllSequenceMenuItem_actionPerformed();\r
415     else if(evt.getSource()==invertSequenceMenuItem)\r
416             invertSequenceMenuItem_actionPerformed();\r
417     else if(evt.getSource()==remove2LeftMenuItem)\r
418             remove2LeftMenuItem_actionPerformed();\r
419     else if(evt.getSource()==remove2RightMenuItem)\r
420             remove2RightMenuItem_actionPerformed();\r
421     else if(evt.getSource()==removeGappedColumnMenuItem)\r
422             removeGappedColumnMenuItem_actionPerformed();\r
423     else if(evt.getSource()==removeAllGapsMenuItem)\r
424             removeAllGapsMenuItem_actionPerformed();\r
425     else if(evt.getSource()==findMenuItem)\r
426             findMenuItem_actionPerformed();\r
427     else if(evt.getSource()==font)\r
428             font_actionPerformed();\r
429     else if(evt.getSource()==featureSettings)\r
430             featureSettings_actionPerformed();\r
431     else if(evt.getSource()==overviewMenuItem)\r
432             overviewMenuItem_actionPerformed();\r
433     else if(evt.getSource()==noColourmenuItem)\r
434             noColourmenuItem_actionPerformed();\r
435     else if(evt.getSource()==clustalColour)\r
436             clustalColour_actionPerformed();\r
437     else if(evt.getSource()==zappoColour)\r
438             zappoColour_actionPerformed();\r
439     else if(evt.getSource()==taylorColour)\r
440             taylorColour_actionPerformed();\r
441     else if(evt.getSource()==hydrophobicityColour)\r
442             hydrophobicityColour_actionPerformed();\r
443     else if(evt.getSource()==helixColour)\r
444             helixColour_actionPerformed();\r
445     else if(evt.getSource()==strandColour)\r
446             strandColour_actionPerformed();\r
447     else if(evt.getSource()==turnColour)\r
448             turnColour_actionPerformed();\r
449     else if(evt.getSource()==buriedColour)\r
450             buriedColour_actionPerformed();\r
451     else if(evt.getSource()==nucleotideColour)\r
452             nucleotideColour_actionPerformed();\r
453     else if(evt.getSource()==modifyPID)\r
454             modifyPID_actionPerformed();\r
455     else if(evt.getSource()==modifyConservation)\r
456             modifyConservation_actionPerformed();\r
457     else if(evt.getSource()==userDefinedColour)\r
458             userDefinedColour_actionPerformed();\r
459     else if(evt.getSource()==PIDColour)\r
460             PIDColour_actionPerformed();\r
461     else if(evt.getSource()==BLOSUM62Colour)\r
462             BLOSUM62Colour_actionPerformed();\r
463     else if(evt.getSource()==annotationColour)\r
464            new AnnotationColourChooser(viewport, alignPanel);\r
465     else if(evt.getSource()==sortPairwiseMenuItem)\r
466             sortPairwiseMenuItem_actionPerformed();\r
467     else if(evt.getSource()==sortIDMenuItem)\r
468             sortIDMenuItem_actionPerformed();\r
469     else if(evt.getSource()==sortGroupMenuItem)\r
470             sortGroupMenuItem_actionPerformed();\r
471     else if(evt.getSource()==removeRedundancyMenuItem)\r
472             removeRedundancyMenuItem_actionPerformed();\r
473     else if(evt.getSource()==pairwiseAlignmentMenuItem)\r
474             pairwiseAlignmentMenuItem_actionPerformed();\r
475     else if(evt.getSource()==PCAMenuItem)\r
476             PCAMenuItem_actionPerformed();\r
477     else if(evt.getSource()==averageDistanceTreeMenuItem)\r
478             averageDistanceTreeMenuItem_actionPerformed();\r
479     else if(evt.getSource()==neighbourTreeMenuItem)\r
480             neighbourTreeMenuItem_actionPerformed();\r
481     else if(evt.getSource()==njTreeBlosumMenuItem)\r
482             njTreeBlosumMenuItem_actionPerformed();\r
483     else if(evt.getSource()==avDistanceTreeBlosumMenuItem)\r
484             avTreeBlosumMenuItem_actionPerformed();\r
485     else if(evt.getSource()==documentation)\r
486             documentation_actionPerformed();\r
487     else if(evt.getSource()==about)\r
488             about_actionPerformed();\r
489 \r
490  }\r
491 \r
492   public void inputText_actionPerformed()\r
493   {\r
494     CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);\r
495     Frame frame = new Frame();\r
496     frame.add(cap);\r
497     jalview.bin.JalviewLite.addFrame(frame, "Cut & Paste Input", 500, 500);\r
498   }\r
499 \r
500   protected void outputText_actionPerformed(ActionEvent e)\r
501   {\r
502     CutAndPasteTransfer cap = new CutAndPasteTransfer(false, this);\r
503     Frame frame = new Frame();\r
504     frame.add(cap);\r
505     jalview.bin.JalviewLite.addFrame(frame,\r
506                                      "Alignment output - " + e.getActionCommand(),\r
507                                      600, 500);\r
508     cap.setText(new AppletFormatAdapter().formatSequences(e.getActionCommand(),\r
509                                               viewport.getAlignment().getSequences(),\r
510                                                       viewport.showJVSuffix));\r
511   }\r
512 \r
513   void launchFullApplication()\r
514   {\r
515     StringBuffer url = new StringBuffer(jalviewServletURL);\r
516 \r
517     url.append("?open="+\r
518                appendProtocol( applet.getParameter("file") ) );\r
519 \r
520     if(applet.getParameter("features")!=null)\r
521     {\r
522       url.append( "&features=" );\r
523       url.append( appendProtocol( applet.getParameter("features") ) );\r
524     }\r
525 \r
526     if(applet.getParameter("defaultColour")!=null)\r
527     {\r
528       url.append("&colour=" +\r
529                  removeWhiteSpace(applet.getParameter("defaultColour"))\r
530           );\r
531     }\r
532 \r
533     if(applet.getParameter("userDefinedColour")!=null)\r
534     {\r
535       url.append( "&colour=" +\r
536                  removeWhiteSpace( applet.getParameter("userDefinedColour") )\r
537          );\r
538     }\r
539 \r
540     showURL(url.toString(), "FULL_APP");\r
541   }\r
542 \r
543 \r
544   String removeWhiteSpace(String colour)\r
545   {\r
546     StringBuffer sb = new StringBuffer();\r
547     for (int i = 0; i < colour.length(); i++)\r
548     {\r
549       if (Character.isWhitespace(colour.charAt(i)))\r
550         sb.append("%20");\r
551       else\r
552         sb.append(colour.charAt(i));\r
553     }\r
554 \r
555     return sb.toString();\r
556   }\r
557 \r
558 \r
559   String appendProtocol(String url)\r
560   {\r
561     try{\r
562        new URL(url);\r
563     }catch(java.net.MalformedURLException ex)\r
564     {\r
565       url = applet.getCodeBase()+url;\r
566     }\r
567     return url;\r
568   }\r
569 \r
570   public void closeMenuItem_actionPerformed()\r
571   {\r
572     PaintRefresher.components.remove(viewport.alignment);\r
573     if(PaintRefresher.components.size()==0 && applet==null)\r
574       System.exit(0);\r
575 \r
576     this.dispose();\r
577   }\r
578 \r
579   Stack historyList = new Stack();\r
580   Stack redoList = new Stack();\r
581 \r
582   void updateEditMenuBar()\r
583   {\r
584     if (historyList.size() > 0)\r
585     {\r
586       undoMenuItem.setEnabled(true);\r
587       HistoryItem hi = (HistoryItem) historyList.peek();\r
588       undoMenuItem.setLabel("Undo " + hi.getDescription());\r
589     }\r
590     else\r
591     {\r
592       undoMenuItem.setEnabled(false);\r
593       undoMenuItem.setLabel("Undo");\r
594     }\r
595 \r
596     if (redoList.size() > 0)\r
597     {\r
598       redoMenuItem.setEnabled(true);\r
599       HistoryItem hi = (HistoryItem) redoList.peek();\r
600       redoMenuItem.setLabel("Redo " + hi.getDescription());\r
601     }\r
602     else\r
603     {\r
604       redoMenuItem.setEnabled(false);\r
605       redoMenuItem.setLabel("Redo");\r
606     }\r
607   }\r
608 \r
609   public void addHistoryItem(HistoryItem hi)\r
610   {\r
611     historyList.push(hi);\r
612     updateEditMenuBar();\r
613   }\r
614 \r
615   protected void undoMenuItem_actionPerformed()\r
616   {\r
617     HistoryItem hi = (HistoryItem) historyList.pop();\r
618     redoList.push(new HistoryItem(hi.getDescription(), viewport.alignment,\r
619                                   HistoryItem.HIDE));\r
620     restoreHistoryItem(hi);\r
621     viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());\r
622   }\r
623 \r
624   protected void redoMenuItem_actionPerformed()\r
625   {\r
626     HistoryItem hi = (HistoryItem) redoList.pop();\r
627     restoreHistoryItem(hi);\r
628     updateEditMenuBar();\r
629     viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());\r
630   }\r
631 \r
632   // used by undo and redo\r
633   void restoreHistoryItem(HistoryItem hi)\r
634   {\r
635     hi.restore();\r
636 \r
637     updateEditMenuBar();\r
638 \r
639     viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());\r
640   }\r
641 \r
642   public void moveSelectedSequences(boolean up)\r
643   {\r
644     SequenceGroup sg = viewport.getSelectionGroup();\r
645     if (sg == null)\r
646     {\r
647       return;\r
648     }\r
649 \r
650     if (up)\r
651     {\r
652       for (int i = 1; i < viewport.alignment.getHeight(); i++)\r
653       {\r
654         SequenceI seq = viewport.alignment.getSequenceAt(i);\r
655         if (!sg.getSequences(false).contains(seq))\r
656         {\r
657           continue;\r
658         }\r
659 \r
660         SequenceI temp = viewport.alignment.getSequenceAt(i - 1);\r
661         if (sg.getSequences(false).contains(temp))\r
662         {\r
663           continue;\r
664         }\r
665 \r
666         viewport.alignment.getSequences().setElementAt(temp, i);\r
667         viewport.alignment.getSequences().setElementAt(seq, i - 1);\r
668       }\r
669     }\r
670     else\r
671     {\r
672       for (int i = viewport.alignment.getHeight() - 2; i > -1; i--)\r
673       {\r
674         SequenceI seq = viewport.alignment.getSequenceAt(i);\r
675         if (!sg.getSequences(true).contains(seq))\r
676         {\r
677           continue;\r
678         }\r
679 \r
680         SequenceI temp = viewport.alignment.getSequenceAt(i + 1);\r
681         if (sg.getSequences(true).contains(temp))\r
682         {\r
683           continue;\r
684         }\r
685 \r
686         viewport.alignment.getSequences().setElementAt(temp, i);\r
687         viewport.alignment.getSequences().setElementAt(seq, i + 1);\r
688       }\r
689     }\r
690 \r
691     alignPanel.repaint();\r
692   }\r
693 \r
694   StringBuffer copiedSequences;\r
695   protected void copy_actionPerformed()\r
696   {\r
697     if (viewport.getSelectionGroup() == null)\r
698     {\r
699       return;\r
700     }\r
701 \r
702     SequenceGroup sg = viewport.getSelectionGroup();\r
703     copiedSequences = new StringBuffer();\r
704     Hashtable orderedSeqs = new Hashtable();\r
705     for (int i = 0; i < sg.getSize(false); i++)\r
706     {\r
707       SequenceI seq = sg.getSequenceAt(i);\r
708       int index = viewport.alignment.findIndex(seq);\r
709       orderedSeqs.put(index + "", seq);\r
710     }\r
711 \r
712     int index = 0, startRes, endRes;\r
713     char ch;\r
714 \r
715     for (int i = 0; i < sg.getSize(false); i++)\r
716     {\r
717         SequenceI seq = null;\r
718 \r
719         while (seq == null)\r
720         {\r
721             if (orderedSeqs.containsKey(index + ""))\r
722             {\r
723                 seq = (SequenceI) orderedSeqs.get(index + "");\r
724                 index++;\r
725 \r
726                 break;\r
727             }\r
728             else\r
729             {\r
730                 index++;\r
731             }\r
732         }\r
733 \r
734         //FIND START RES\r
735         //Returns residue following index if gap\r
736         startRes = seq.findPosition(sg.getStartRes());\r
737 \r
738         //FIND END RES\r
739         //Need to find the residue preceeding index if gap\r
740         endRes = 0;\r
741 \r
742         for (int j = 0; j < sg.getEndRes()+1 && j < seq.getLength(); j++)\r
743         {\r
744           ch = seq.getCharAt(j);\r
745           if (!jalview.util.Comparison.isGap( (ch)))\r
746           {\r
747             endRes++;\r
748           }\r
749         }\r
750 \r
751         if(endRes>0)\r
752         {\r
753           endRes += seq.getStart() -1;\r
754         }\r
755 \r
756         copiedSequences.append(seq.getName() + "\t" +\r
757             startRes + "\t" +\r
758             endRes + "\t" +\r
759             seq.getSequence(sg.getStartRes(),\r
760                 sg.getEndRes() + 1) + "\n");\r
761     }\r
762 \r
763   }\r
764 \r
765   protected void pasteNew_actionPerformed()\r
766   {\r
767     paste(true);\r
768   }\r
769 \r
770   protected void pasteThis_actionPerformed()\r
771   {\r
772     addHistoryItem(new HistoryItem("Paste Sequences", viewport.alignment,\r
773                                    HistoryItem.PASTE));\r
774     paste(false);\r
775   }\r
776 \r
777   void paste(boolean newAlignment)\r
778   {\r
779     try\r
780     {\r
781       if (copiedSequences == null)\r
782       {\r
783         return;\r
784       }\r
785 \r
786       StringTokenizer st = new StringTokenizer(copiedSequences.toString());\r
787       Vector seqs = new Vector();\r
788       while (st.hasMoreElements())\r
789       {\r
790         String name = st.nextToken();\r
791         int start = Integer.parseInt(st.nextToken());\r
792         int end = Integer.parseInt(st.nextToken());\r
793         Sequence sequence = new Sequence(name, st.nextToken(), start, end);\r
794 \r
795         if (!newAlignment)\r
796         {\r
797           viewport.alignment.addSequence(sequence);\r
798         }\r
799         else\r
800         {\r
801           seqs.addElement(sequence);\r
802         }\r
803       }\r
804 \r
805       if (newAlignment)\r
806       {\r
807         SequenceI[] newSeqs = new SequenceI[seqs.size()];\r
808         for (int i = 0; i < seqs.size(); i++)\r
809         {\r
810           newSeqs[i] = (SequenceI) seqs.elementAt(i);\r
811         }\r
812 \r
813         String newtitle = new String("Copied sequences");\r
814         if (getTitle().startsWith("Copied sequences"))\r
815         {\r
816           newtitle = getTitle();\r
817         }\r
818         else\r
819         {\r
820           newtitle = newtitle.concat("- from " + getTitle());\r
821         }\r
822         AlignFrame af = new AlignFrame(new Alignment(newSeqs),\r
823                                        applet,\r
824                                        newtitle,\r
825                                        false);\r
826 \r
827         jalview.bin.JalviewLite.addFrame(af, newtitle, NEW_WINDOW_WIDTH,\r
828                                          NEW_WINDOW_HEIGHT);\r
829       }\r
830       else\r
831       {\r
832         viewport.setEndSeq(viewport.alignment.getHeight());\r
833         viewport.alignment.getWidth();\r
834         viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());\r
835       }\r
836 \r
837     }\r
838     catch (Exception ex)\r
839     {} // could be anything being pasted in here\r
840 \r
841   }\r
842 \r
843   protected void cut_actionPerformed()\r
844   {\r
845     copy_actionPerformed();\r
846     delete_actionPerformed();\r
847   }\r
848 \r
849   protected void delete_actionPerformed()\r
850   {\r
851     addHistoryItem(new HistoryItem("Delete Sequences", viewport.alignment,\r
852                                    HistoryItem.HIDE));\r
853     if (viewport.getSelectionGroup() == null)\r
854     {\r
855       return;\r
856     }\r
857 \r
858 \r
859     SequenceGroup sg = viewport.getSelectionGroup();\r
860     boolean allSequences = false;\r
861     if(sg.getSize(false)==viewport.alignment.getHeight())\r
862           allSequences = true;\r
863 \r
864     for (int i = 0; i < sg.getSize(false); i++)\r
865     {\r
866       SequenceI seq = sg.getSequenceAt(i);\r
867       int index = viewport.getAlignment().findIndex(seq);\r
868       seq.deleteChars(sg.getStartRes(), sg.getEndRes() + 1);\r
869 \r
870       // If the cut affects all sequences, remove highlighted columns\r
871       if (allSequences)\r
872       {\r
873         viewport.getColumnSelection().removeElements(sg.getStartRes(),\r
874                                                      sg.getEndRes() + 1);\r
875       }\r
876 \r
877 \r
878       if (seq.getSequence().length() < 1)\r
879       {\r
880         viewport.getAlignment().deleteSequence(seq);\r
881       }\r
882       else\r
883       {\r
884         viewport.getAlignment().getSequences().setElementAt(seq, index);\r
885       }\r
886     }\r
887 \r
888     viewport.setSelectionGroup(null);\r
889     viewport.alignment.deleteGroup(sg);\r
890     viewport.resetSeqLimits(alignPanel.seqPanel.seqCanvas.getSize().height);\r
891     if (viewport.getAlignment().getHeight() < 1)\r
892     {\r
893       try\r
894       {\r
895         this.setVisible(false);\r
896       }\r
897       catch (Exception ex)\r
898       {}\r
899     }\r
900     viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());\r
901 \r
902   }\r
903 \r
904   protected void deleteGroups_actionPerformed()\r
905   {\r
906     viewport.alignment.deleteAllGroups();\r
907     viewport.setSelectionGroup(null);\r
908 \r
909     alignPanel.repaint();\r
910   }\r
911 \r
912   public void selectAllSequenceMenuItem_actionPerformed()\r
913   {\r
914     SequenceGroup sg = new SequenceGroup();\r
915     for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)\r
916     {\r
917       sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);\r
918     }\r
919     sg.setEndRes(viewport.alignment.getWidth()-1);\r
920     viewport.setSelectionGroup(sg);\r
921     alignPanel.repaint();\r
922     PaintRefresher.Refresh(null, viewport.alignment);\r
923   }\r
924 \r
925   public void deselectAllSequenceMenuItem_actionPerformed()\r
926   {\r
927     if(viewport.cursorMode)\r
928     {\r
929       alignPanel.seqPanel.keyboardNo1=null;\r
930       alignPanel.seqPanel.keyboardNo2=null;\r
931     }\r
932     viewport.setSelectionGroup(null);\r
933     viewport.getColumnSelection().clear();\r
934     viewport.setSelectionGroup(null);\r
935     alignPanel.idPanel.idCanvas.searchResults = null;\r
936     alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);\r
937     alignPanel.repaint();\r
938     PaintRefresher.Refresh(null, viewport.alignment);\r
939   }\r
940 \r
941   public void invertSequenceMenuItem_actionPerformed()\r
942   {\r
943     SequenceGroup sg = viewport.getSelectionGroup();\r
944     for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)\r
945     {\r
946       sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);\r
947     }\r
948 \r
949     PaintRefresher.Refresh(null, viewport.alignment);\r
950   }\r
951 \r
952   public void remove2LeftMenuItem_actionPerformed()\r
953   {\r
954     ColumnSelection colSel = viewport.getColumnSelection();\r
955     if (colSel.size() > 0)\r
956     {\r
957       addHistoryItem(new HistoryItem("Remove Left", viewport.alignment,\r
958                                      HistoryItem.HIDE));\r
959       int min = colSel.getMin();\r
960       viewport.getAlignment().trimLeft(min);\r
961       colSel.compensateForEdit(0, min);\r
962 \r
963       if (viewport.getSelectionGroup() != null)\r
964       {\r
965         viewport.getSelectionGroup().adjustForRemoveLeft(min);\r
966       }\r
967 \r
968       Vector groups = viewport.alignment.getGroups();\r
969       for (int i = 0; i < groups.size(); i++)\r
970       {\r
971         SequenceGroup sg = (SequenceGroup) groups.elementAt(i);\r
972         if (!sg.adjustForRemoveLeft(min))\r
973         {\r
974           viewport.alignment.deleteGroup(sg);\r
975         }\r
976       }\r
977       viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());\r
978     }\r
979   }\r
980 \r
981   public void remove2RightMenuItem_actionPerformed()\r
982   {\r
983     ColumnSelection colSel = viewport.getColumnSelection();\r
984     if (colSel.size() > 0)\r
985     {\r
986       addHistoryItem(new HistoryItem("Remove Right", viewport.alignment,\r
987                                      HistoryItem.HIDE));\r
988       int max = colSel.getMax();\r
989       viewport.getAlignment().trimRight(max);\r
990       if (viewport.getSelectionGroup() != null)\r
991       {\r
992         viewport.getSelectionGroup().adjustForRemoveRight(max);\r
993       }\r
994 \r
995       Vector groups = viewport.alignment.getGroups();\r
996       for (int i = 0; i < groups.size(); i++)\r
997       {\r
998         SequenceGroup sg = (SequenceGroup) groups.elementAt(i);\r
999         if (!sg.adjustForRemoveRight(max))\r
1000         {\r
1001           viewport.alignment.deleteGroup(sg);\r
1002         }\r
1003       }\r
1004       viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());\r
1005     }\r
1006 \r
1007   }\r
1008 \r
1009   public void removeGappedColumnMenuItem_actionPerformed()\r
1010   {\r
1011     addHistoryItem(new HistoryItem("Remove Gapped Columns",\r
1012                                    viewport.alignment,\r
1013                                    HistoryItem.HIDE));\r
1014 \r
1015     //This is to maintain viewport position on first residue\r
1016     //of first sequence\r
1017     SequenceI seq = viewport.alignment.getSequenceAt(0);\r
1018     int startRes = seq.findPosition(viewport.startRes);\r
1019 \r
1020     viewport.getAlignment().removeGaps();\r
1021 \r
1022     viewport.setStartRes(seq.findIndex(startRes)-1);\r
1023 \r
1024     viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());\r
1025   }\r
1026 \r
1027   public void removeAllGapsMenuItem_actionPerformed()\r
1028   {\r
1029     addHistoryItem(new HistoryItem("Remove Gaps", viewport.alignment,\r
1030                                    HistoryItem.HIDE));\r
1031 \r
1032     //This is to maintain viewport position on first residue\r
1033     //of first sequence\r
1034     SequenceI seq = viewport.alignment.getSequenceAt(0);\r
1035     int startRes = seq.findPosition(viewport.startRes);\r
1036 \r
1037     SequenceI current;\r
1038     int jSize;\r
1039 \r
1040     Vector seqs=null;\r
1041 \r
1042     int start=0, end = viewport.alignment.getWidth();\r
1043 \r
1044     if (viewport.getSelectionGroup() != null\r
1045         && viewport.getSelectionGroup().getSequences(false) != null\r
1046         && viewport.getSelectionGroup().getSize(false)>0)\r
1047     {\r
1048       seqs = viewport.getSelectionGroup().getSequences(true);\r
1049       start = viewport.getSelectionGroup().getStartRes();\r
1050       end = viewport.getSelectionGroup().getEndRes()+1;\r
1051     }\r
1052     else\r
1053       seqs = viewport.alignment.getSequences();\r
1054 \r
1055     for (int i = 0; i < seqs.size(); i++)\r
1056     {\r
1057       current = (SequenceI) seqs.elementAt(i);\r
1058       jSize = current.getLength();\r
1059 \r
1060       // Removing a range is much quicker than removing gaps\r
1061       // one by one for long sequences\r
1062       int j = start;\r
1063       int rangeStart=-1, rangeEnd=-1;\r
1064 \r
1065       do\r
1066       {\r
1067         if (jalview.util.Comparison.isGap(current.getCharAt(j)))\r
1068         {\r
1069           if(rangeStart==-1)\r
1070            {\r
1071              rangeStart = j;\r
1072              rangeEnd = j+1;\r
1073            }\r
1074            else\r
1075            {\r
1076              rangeEnd++;\r
1077            }\r
1078            j++;\r
1079         }\r
1080         else\r
1081         {\r
1082           if(rangeStart>-1)\r
1083           {\r
1084             current.deleteChars(rangeStart, rangeEnd);\r
1085             j-=rangeEnd-rangeStart;\r
1086             jSize-=rangeEnd-rangeStart;\r
1087             rangeStart = -1;\r
1088             rangeEnd = -1;\r
1089           }\r
1090           else\r
1091             j++;\r
1092         }\r
1093       }\r
1094       while (j < end && j < jSize);\r
1095       if(rangeStart>-1)\r
1096       {\r
1097        current.deleteChars(rangeStart, rangeEnd);\r
1098       }\r
1099     }\r
1100     viewport.setStartRes(seq.findIndex(startRes)-1);\r
1101     viewport.firePropertyChange("alignment", null, viewport.getAlignment().getSequences());\r
1102   }\r
1103 \r
1104   public void alignmentChanged()\r
1105   {\r
1106     viewport.alignment.padGaps();\r
1107     if(viewport.autocalculateConsensus)\r
1108     {\r
1109       viewport.updateConsensus();\r
1110       viewport.updateConservation();\r
1111     }\r
1112 \r
1113     resetAllColourSchemes();\r
1114     if(alignPanel.overviewPanel!=null)\r
1115       alignPanel.overviewPanel.updateOverviewImage();\r
1116 \r
1117     viewport.alignment.adjustSequenceAnnotations();\r
1118     alignPanel.repaint();\r
1119   }\r
1120 \r
1121   void resetAllColourSchemes()\r
1122   {\r
1123     ColourSchemeI cs = viewport.globalColourScheme;\r
1124     if(cs!=null)\r
1125     {\r
1126       if (cs instanceof ClustalxColourScheme)\r
1127       {\r
1128         ( (ClustalxColourScheme) viewport.getGlobalColourScheme()).\r
1129             resetClustalX(viewport.alignment.getSequences(),\r
1130                           viewport.alignment.getWidth());\r
1131       }\r
1132 \r
1133       cs.setConsensus(viewport.vconsensus);\r
1134       if (cs.conservationApplied())\r
1135       {\r
1136         Alignment al = (Alignment) viewport.alignment;\r
1137         Conservation c = new Conservation("All",\r
1138                                           ResidueProperties.propHash, 3,\r
1139                                           al.getSequences(), 0,\r
1140                                           al.getWidth() - 1);\r
1141         c.calculate();\r
1142         c.verdict(false, viewport.ConsPercGaps);\r
1143 \r
1144         cs.setConservation(c);\r
1145       }\r
1146     }\r
1147 \r
1148     int s, sSize = viewport.alignment.getGroups().size();\r
1149     for(s=0; s<sSize; s++)\r
1150     {\r
1151       SequenceGroup sg = (SequenceGroup)viewport.alignment.getGroups().elementAt(s);\r
1152       if(sg.cs!=null && sg.cs instanceof ClustalxColourScheme)\r
1153       {\r
1154         ((ClustalxColourScheme)sg.cs).resetClustalX(\r
1155             sg.getSequences(true), sg.getWidth());\r
1156       }\r
1157       sg.recalcConservation();\r
1158     }\r
1159   }\r
1160 \r
1161 \r
1162 \r
1163   public void findMenuItem_actionPerformed()\r
1164   {\r
1165     new Finder(alignPanel);\r
1166   }\r
1167 \r
1168   public void font_actionPerformed()\r
1169   {\r
1170     new FontChooser(alignPanel);\r
1171   }\r
1172 \r
1173 \r
1174   public void seqLimits_itemStateChanged()\r
1175   {\r
1176     viewport.setShowJVSuffix(seqLimits.getState());\r
1177     alignPanel.fontChanged();\r
1178     alignPanel.repaint();\r
1179   }\r
1180 \r
1181 \r
1182   protected void colourTextMenuItem_actionPerformed()\r
1183   {\r
1184     viewport.setColourText(colourTextMenuItem.getState());\r
1185     alignPanel.repaint();\r
1186   }\r
1187 \r
1188   protected void wrapMenuItem_actionPerformed()\r
1189   {\r
1190     viewport.setWrapAlignment(wrapMenuItem.getState());\r
1191     alignPanel.setWrapAlignment(wrapMenuItem.getState());\r
1192     scaleAbove.setEnabled(wrapMenuItem.getState());\r
1193     scaleLeft.setEnabled(wrapMenuItem.getState());\r
1194     scaleRight.setEnabled(wrapMenuItem.getState());\r
1195     alignPanel.repaint();\r
1196   }\r
1197 \r
1198   protected void scaleAbove_actionPerformed()\r
1199   {\r
1200     viewport.setScaleAboveWrapped(scaleAbove.getState());\r
1201     alignPanel.repaint();\r
1202   }\r
1203 \r
1204   protected void scaleLeft_actionPerformed()\r
1205   {\r
1206     viewport.setScaleLeftWrapped(scaleLeft.getState());\r
1207     alignPanel.repaint();\r
1208   }\r
1209 \r
1210   protected void scaleRight_actionPerformed()\r
1211   {\r
1212     viewport.setScaleRightWrapped(scaleRight.getState());\r
1213     alignPanel.repaint();\r
1214   }\r
1215 \r
1216   public void viewBoxesMenuItem_actionPerformed()\r
1217   {\r
1218     viewport.setShowBoxes(viewBoxesMenuItem.getState());\r
1219     alignPanel.repaint();\r
1220   }\r
1221 \r
1222   public void viewTextMenuItem_actionPerformed()\r
1223   {\r
1224     viewport.setShowText(viewTextMenuItem.getState());\r
1225     alignPanel.repaint();\r
1226   }\r
1227 \r
1228   protected void renderGapsMenuItem_actionPerformed()\r
1229   {\r
1230     viewport.setRenderGaps(renderGapsMenuItem.getState());\r
1231     alignPanel.repaint();\r
1232   }\r
1233 \r
1234   public void annotationPanelMenuItem_actionPerformed()\r
1235   {\r
1236     viewport.setShowAnnotation(annotationPanelMenuItem.getState());\r
1237     alignPanel.setAnnotationVisible(annotationPanelMenuItem.getState());\r
1238   }\r
1239 \r
1240   public void featureSettings_actionPerformed()\r
1241   {\r
1242     new FeatureSettings(viewport, alignPanel);\r
1243   }\r
1244 \r
1245   public void overviewMenuItem_actionPerformed()\r
1246   {\r
1247     if (alignPanel.overviewPanel != null)\r
1248     {\r
1249       return;\r
1250     }\r
1251 \r
1252     Frame frame = new Frame();\r
1253     OverviewPanel overview = new OverviewPanel(alignPanel);\r
1254     frame.add(overview);\r
1255     // +50 must allow for applet frame window\r
1256     jalview.bin.JalviewLite.addFrame(frame, "Overview " + this.getTitle(),\r
1257                                      overview.preferredSize().width,\r
1258                                      overview.preferredSize().height + 50);\r
1259 \r
1260     frame.pack();\r
1261     frame.addWindowListener(new WindowAdapter()\r
1262     {\r
1263       public void windowClosing(WindowEvent e)\r
1264       {\r
1265         alignPanel.setOverviewPanel(null);\r
1266       };\r
1267     });\r
1268 \r
1269     alignPanel.setOverviewPanel(overview);\r
1270 \r
1271   }\r
1272 \r
1273   protected void noColourmenuItem_actionPerformed()\r
1274   {\r
1275     changeColour(null);\r
1276   }\r
1277 \r
1278   public void clustalColour_actionPerformed()\r
1279   {\r
1280     abovePIDThreshold.setState(false);\r
1281     changeColour(new ClustalxColourScheme(viewport.alignment.getSequences(),\r
1282                                           viewport.alignment.getWidth()));\r
1283   }\r
1284 \r
1285   public void zappoColour_actionPerformed()\r
1286   {\r
1287     changeColour(new ZappoColourScheme());\r
1288   }\r
1289 \r
1290   public void taylorColour_actionPerformed()\r
1291   {\r
1292     changeColour(new TaylorColourScheme());\r
1293   }\r
1294 \r
1295   public void hydrophobicityColour_actionPerformed()\r
1296   {\r
1297     changeColour(new HydrophobicColourScheme());\r
1298   }\r
1299 \r
1300   public void helixColour_actionPerformed()\r
1301   {\r
1302     changeColour(new HelixColourScheme());\r
1303   }\r
1304 \r
1305   public void strandColour_actionPerformed()\r
1306   {\r
1307     changeColour(new StrandColourScheme());\r
1308   }\r
1309 \r
1310   public void turnColour_actionPerformed()\r
1311   {\r
1312     changeColour(new TurnColourScheme());\r
1313   }\r
1314 \r
1315   public void buriedColour_actionPerformed()\r
1316   {\r
1317     changeColour(new BuriedColourScheme());\r
1318   }\r
1319 \r
1320   public void nucleotideColour_actionPerformed()\r
1321   {\r
1322     changeColour(new NucleotideColourScheme());\r
1323   }\r
1324 \r
1325   protected void applyToAllGroups_actionPerformed()\r
1326   {\r
1327     viewport.setColourAppliesToAllGroups(applyToAllGroups.getState());\r
1328   }\r
1329 \r
1330   void changeColour(ColourSchemeI cs)\r
1331   {\r
1332     int threshold = 0;\r
1333 \r
1334     if(cs!=null)\r
1335     {\r
1336       if (viewport.getAbovePIDThreshold())\r
1337       {\r
1338         threshold = SliderPanel.setPIDSliderSource(alignPanel, cs, "Background");\r
1339 \r
1340         cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());\r
1341 \r
1342         viewport.setGlobalColourScheme(cs);\r
1343       }\r
1344       else\r
1345       {\r
1346         cs.setThreshold(0, viewport.getIgnoreGapsConsensus());\r
1347       }\r
1348 \r
1349       if (viewport.getConservationSelected())\r
1350       {\r
1351 \r
1352         Alignment al = (Alignment) viewport.alignment;\r
1353         Conservation c = new Conservation("All",\r
1354                                           ResidueProperties.propHash, 3,\r
1355                                           al.getSequences(), 0,\r
1356                                           al.getWidth() - 1);\r
1357 \r
1358         c.calculate();\r
1359         c.verdict(false, viewport.ConsPercGaps);\r
1360 \r
1361         cs.setConservation(c);\r
1362 \r
1363         cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel, cs,\r
1364             "Background"));\r
1365 \r
1366       }\r
1367       else\r
1368       {\r
1369         cs.setConservation(null);\r
1370       }\r
1371 \r
1372       cs.setConsensus(viewport.vconsensus);\r
1373 \r
1374     }\r
1375     viewport.setGlobalColourScheme(cs);\r
1376 \r
1377     if (viewport.getColourAppliesToAllGroups())\r
1378     {\r
1379       Vector groups = viewport.alignment.getGroups();\r
1380       for (int i = 0; i < groups.size(); i++)\r
1381       {\r
1382         SequenceGroup sg = (SequenceGroup) groups.elementAt(i);\r
1383 \r
1384         if(cs==null)\r
1385         {\r
1386           sg.cs = null;\r
1387           continue;\r
1388         }\r
1389         if (cs instanceof ClustalxColourScheme)\r
1390         {\r
1391           sg.cs = new ClustalxColourScheme(sg.getSequences(true), sg.getWidth());\r
1392         }\r
1393         else\r
1394         {\r
1395           try\r
1396           {\r
1397             sg.cs = (ColourSchemeI) cs.getClass().newInstance();\r
1398           }\r
1399           catch (Exception ex)\r
1400           {\r
1401             ex.printStackTrace();\r
1402             sg.cs = cs;\r
1403           }\r
1404         }\r
1405 \r
1406         if (viewport.getAbovePIDThreshold()\r
1407             || cs instanceof PIDColourScheme\r
1408             || cs instanceof Blosum62ColourScheme)\r
1409         {\r
1410           sg.cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());\r
1411           sg.cs.setConsensus(AAFrequency.calculate(sg.getSequences(true), 0, sg.getWidth()));\r
1412         }\r
1413         else\r
1414           sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());\r
1415 \r
1416         if (viewport.getConservationSelected())\r
1417         {\r
1418           Conservation c = new Conservation("Group",\r
1419                                             ResidueProperties.propHash, 3,\r
1420                                             sg.getSequences(true), 0,\r
1421                                             viewport.alignment.getWidth() - 1);\r
1422           c.calculate();\r
1423           c.verdict(false, viewport.ConsPercGaps);\r
1424           sg.cs.setConservation(c);\r
1425         }\r
1426         else\r
1427         {\r
1428           sg.cs.setConservation(null);\r
1429           sg.cs.setThreshold(0, viewport.getIgnoreGapsConsensus());\r
1430         }\r
1431 \r
1432       }\r
1433     }\r
1434 \r
1435 \r
1436     if (alignPanel.getOverviewPanel() != null)\r
1437     {\r
1438       alignPanel.getOverviewPanel().updateOverviewImage();\r
1439     }\r
1440 \r
1441     alignPanel.repaint();\r
1442   }\r
1443 \r
1444 \r
1445 \r
1446   protected void modifyPID_actionPerformed()\r
1447   {\r
1448     if (viewport.getAbovePIDThreshold() && viewport.globalColourScheme!=null)\r
1449     {\r
1450       SliderPanel.setPIDSliderSource(alignPanel, viewport.getGlobalColourScheme(),\r
1451                                      "Background");\r
1452       SliderPanel.showPIDSlider();\r
1453     }\r
1454   }\r
1455 \r
1456   protected void modifyConservation_actionPerformed()\r
1457   {\r
1458     if (viewport.getConservationSelected() && viewport.globalColourScheme!=null)\r
1459     {\r
1460       SliderPanel.setConservationSlider(alignPanel, viewport.globalColourScheme,\r
1461                                         "Background");\r
1462       SliderPanel.showConservationSlider();\r
1463     }\r
1464   }\r
1465 \r
1466   protected void conservationMenuItem_actionPerformed()\r
1467   {\r
1468     viewport.setConservationSelected(conservationMenuItem.getState());\r
1469 \r
1470     viewport.setAbovePIDThreshold(false);\r
1471     abovePIDThreshold.setState(false);\r
1472 \r
1473     changeColour(viewport.getGlobalColourScheme());\r
1474 \r
1475     modifyConservation_actionPerformed();\r
1476   }\r
1477 \r
1478   public void abovePIDThreshold_actionPerformed()\r
1479   {\r
1480     viewport.setAbovePIDThreshold(abovePIDThreshold.getState());\r
1481 \r
1482     conservationMenuItem.setState(false);\r
1483     viewport.setConservationSelected(false);\r
1484 \r
1485     changeColour(viewport.getGlobalColourScheme());\r
1486 \r
1487     modifyPID_actionPerformed();\r
1488   }\r
1489 \r
1490   public void userDefinedColour_actionPerformed()\r
1491   {\r
1492     new UserDefinedColours(alignPanel, null);\r
1493   }\r
1494 \r
1495   public void PIDColour_actionPerformed()\r
1496   {\r
1497     changeColour(new PIDColourScheme());\r
1498   }\r
1499 \r
1500   public void BLOSUM62Colour_actionPerformed()\r
1501   {\r
1502     changeColour(new Blosum62ColourScheme());\r
1503   }\r
1504 \r
1505   public void sortPairwiseMenuItem_actionPerformed()\r
1506   {\r
1507     addHistoryItem(new HistoryItem("Pairwise Sort", viewport.alignment,\r
1508                                    HistoryItem.SORT));\r
1509     AlignmentSorter.sortByPID(viewport.getAlignment(),\r
1510                               viewport.getAlignment().getSequenceAt(0));\r
1511     alignPanel.repaint();\r
1512   }\r
1513 \r
1514   public void sortIDMenuItem_actionPerformed()\r
1515   {\r
1516     addHistoryItem(new HistoryItem("ID Sort", viewport.alignment,\r
1517                                    HistoryItem.SORT));\r
1518     AlignmentSorter.sortByID(viewport.getAlignment());\r
1519     alignPanel.repaint();\r
1520   }\r
1521 \r
1522   public void sortGroupMenuItem_actionPerformed()\r
1523   {\r
1524     addHistoryItem(new HistoryItem("Group Sort", viewport.alignment,\r
1525                                    HistoryItem.SORT));\r
1526     AlignmentSorter.sortByGroup(viewport.getAlignment());\r
1527     alignPanel.repaint();\r
1528 \r
1529   }\r
1530 \r
1531   public void removeRedundancyMenuItem_actionPerformed()\r
1532   {\r
1533      new RedundancyPanel(alignPanel);\r
1534   }\r
1535 \r
1536   public void pairwiseAlignmentMenuItem_actionPerformed()\r
1537   {\r
1538     if (viewport.getSelectionGroup().getSize(false) > 1)\r
1539     {\r
1540       Frame frame = new Frame();\r
1541       frame.add(new PairwiseAlignPanel(alignPanel));\r
1542       jalview.bin.JalviewLite.addFrame(frame, "Pairwise Alignment", 600, 500);\r
1543     }\r
1544   }\r
1545 \r
1546   public void PCAMenuItem_actionPerformed()\r
1547   {\r
1548     //are the sequences aligned?\r
1549     if (!viewport.alignment.isAligned())\r
1550     {\r
1551       SequenceI current;\r
1552       int Width = viewport.getAlignment().getWidth();\r
1553 \r
1554       for (int i = 0; i < viewport.getAlignment().getSequences().size();\r
1555            i++)\r
1556       {\r
1557         current = viewport.getAlignment().getSequenceAt(i);\r
1558 \r
1559         if (current.getLength() < Width)\r
1560         {\r
1561           current.insertCharAt(Width - 1, viewport.getGapCharacter());\r
1562         }\r
1563       }\r
1564       alignPanel.repaint();\r
1565     }\r
1566 \r
1567     if ( (viewport.getSelectionGroup() != null &&\r
1568           viewport.getSelectionGroup().getSize(false) < 4 &&\r
1569           viewport.getSelectionGroup().getSize(false) > 0)\r
1570         || viewport.getAlignment().getHeight() < 4)\r
1571     {\r
1572       return;\r
1573     }\r
1574 \r
1575     try\r
1576     {\r
1577       new PCAPanel(viewport);\r
1578     }\r
1579     catch (java.lang.OutOfMemoryError ex)\r
1580     {\r
1581     }\r
1582 \r
1583   }\r
1584 \r
1585   public void averageDistanceTreeMenuItem_actionPerformed()\r
1586   {\r
1587     NewTreePanel("AV", "PID", "Average distance tree using PID");\r
1588   }\r
1589 \r
1590   public void neighbourTreeMenuItem_actionPerformed()\r
1591   {\r
1592     NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");\r
1593   }\r
1594 \r
1595   protected void njTreeBlosumMenuItem_actionPerformed()\r
1596   {\r
1597     NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");\r
1598   }\r
1599 \r
1600   protected void avTreeBlosumMenuItem_actionPerformed()\r
1601   {\r
1602     NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62PID");\r
1603   }\r
1604 \r
1605   void NewTreePanel(String type, String pwType, String title)\r
1606   {\r
1607     //are the sequences aligned?\r
1608     if (!viewport.alignment.isAligned())\r
1609     {\r
1610       SequenceI current;\r
1611       int Width = viewport.getAlignment().getWidth();\r
1612 \r
1613       for (int i = 0; i < viewport.getAlignment().getSequences().size();\r
1614            i++)\r
1615       {\r
1616         current = viewport.getAlignment().getSequenceAt(i);\r
1617 \r
1618         if (current.getLength() < Width)\r
1619         {\r
1620           current.insertCharAt(Width - 1, viewport.getGapCharacter());\r
1621         }\r
1622       }\r
1623       alignPanel.repaint();\r
1624 \r
1625     }\r
1626 \r
1627     final TreePanel tp = new TreePanel(viewport,\r
1628                          type,\r
1629                          pwType);\r
1630 \r
1631     addTreeMenuItem(tp, title);\r
1632 \r
1633     jalview.bin.JalviewLite.addFrame(tp, title, 600, 500);\r
1634   }\r
1635 \r
1636   void loadTree_actionPerformed()\r
1637   {\r
1638       CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);\r
1639       cap.setText("Paste your Newick tree file here.");\r
1640       cap.treeImport = true;\r
1641       Frame frame = new Frame();\r
1642       frame.add(cap);\r
1643       jalview.bin.JalviewLite.addFrame(frame, "Paste Newick file ", 400, 300);\r
1644   }\r
1645 \r
1646   public void loadTree(jalview.io.NewickFile tree, String treeFile)\r
1647   {\r
1648     TreePanel tp = new TreePanel(viewport,\r
1649                                  treeFile,\r
1650                                  "From File - ",\r
1651                                  tree);\r
1652     jalview.bin.JalviewLite.addFrame(tp, treeFile, 600, 500);\r
1653     addTreeMenuItem(tp, treeFile);\r
1654   }\r
1655 \r
1656   void addTreeMenuItem(final TreePanel treePanel, String title)\r
1657   {\r
1658     final MenuItem item = new MenuItem(title);\r
1659     sortByTreeMenu.add(item);\r
1660     item.addActionListener(new java.awt.event.ActionListener()\r
1661     {\r
1662       public void actionPerformed(ActionEvent evt)\r
1663       {\r
1664         addHistoryItem(new HistoryItem("Sort", viewport.alignment,\r
1665                                        HistoryItem.SORT));\r
1666         AlignmentSorter.sortByTree(viewport.getAlignment(), treePanel.getTree());\r
1667         alignPanel.repaint();\r
1668       }\r
1669     });\r
1670 \r
1671     treePanel.addWindowListener(new WindowAdapter()\r
1672     {\r
1673       public void windowClosing(WindowEvent e)\r
1674       {\r
1675         sortByTreeMenu.remove(item);\r
1676       };\r
1677     });\r
1678   }\r
1679 \r
1680   protected void documentation_actionPerformed()\r
1681   {\r
1682     showURL("http://www.jalview.org/help.html", "HELP");\r
1683   }\r
1684 \r
1685   protected void about_actionPerformed()\r
1686   {\r
1687 \r
1688     class AboutPanel extends Canvas\r
1689     {\r
1690       String version;\r
1691       public AboutPanel(String version)\r
1692       { this.version = version; }\r
1693 \r
1694       public void paint(Graphics g)\r
1695       {\r
1696         g.setColor(Color.white);\r
1697         g.fillRect(0, 0, getSize().width, getSize().height);\r
1698         g.setFont(new Font("Helvetica", Font.PLAIN, 12));\r
1699         FontMetrics fm = g.getFontMetrics();\r
1700         int fh = fm.getHeight();\r
1701         int y = 5, x = 7;\r
1702         g.setColor(Color.black);\r
1703         g.setFont(new Font("Helvetica", Font.BOLD, 14));\r
1704         g.drawString("Jalview - Release "+version, 200, y += fh);\r
1705         g.setFont(new Font("Helvetica", Font.PLAIN, 12));\r
1706         g.drawString("Authors:  Michele Clamp, James Cuff, Steve Searle, Andrew Waterhouse, Jim Procter & Geoff Barton.",\r
1707                      x, y += fh * 2);\r
1708         g.drawString("Current development managed by Andrew Waterhouse; Barton Group, University of Dundee.",\r
1709                      x, y += fh);\r
1710         g.drawString(\r
1711             "For any issues relating to Jalview, email help@jalview.org", x,\r
1712             y += fh);\r
1713         g.drawString("If  you use JalView, please cite:", x, y += fh + 8);\r
1714         g.drawString("\"Clamp, M., Cuff, J., Searle, S. M. and Barton, G. J. (2004), The Jalview Java Alignment Editor\"",\r
1715                      x, y += fh);\r
1716         g.drawString("Bioinformatics,  2004 20;426-7.", x, y += fh);\r
1717       }\r
1718     }\r
1719 \r
1720     String version = "test";\r
1721     java.net.URL url = getClass().getResource("/.build_properties");\r
1722     if (url != null)\r
1723     {\r
1724       try\r
1725       {\r
1726         BufferedReader reader = new BufferedReader(new InputStreamReader(\r
1727             url.openStream()));\r
1728         String line;\r
1729         while ( (line = reader.readLine()) != null)\r
1730         {\r
1731           if (line.indexOf("VERSION") > -1)\r
1732           {\r
1733             version = line.substring(line.indexOf("=") + 1);\r
1734           }\r
1735         }\r
1736       }\r
1737       catch (Exception ex)\r
1738       {\r
1739         ex.printStackTrace();\r
1740       }\r
1741     }\r
1742 \r
1743 \r
1744     Frame frame = new Frame();\r
1745     frame.add(new AboutPanel(version));\r
1746     jalview.bin.JalviewLite.addFrame(frame, "Jalview", 580, 200);\r
1747 \r
1748   }\r
1749 \r
1750   public void showURL(String url, String target)\r
1751   {\r
1752     if (applet == null)\r
1753     {\r
1754       System.out.println("Not running as applet - no browser available.");\r
1755     }\r
1756     else\r
1757     {\r
1758       try\r
1759       {\r
1760         System.out.println("Show url: "+url);\r
1761         applet.getAppletContext().showDocument(new java.net.URL(url),\r
1762                                                target);\r
1763       }\r
1764       catch (Exception ex)\r
1765       {\r
1766         ex.printStackTrace();\r
1767       }\r
1768     }\r
1769   }\r
1770 \r
1771 \r
1772   //////////////////////////////////////////////////////////////////////////////////\r
1773   //JBuilder Graphics here\r
1774 \r
1775     protected MenuBar alignFrameMenuBar = new MenuBar();\r
1776     protected Menu fileMenu = new Menu("File");\r
1777     protected MenuItem loadApplication = new MenuItem("View in Full Application");\r
1778     protected MenuItem loadTree = new MenuItem("Load Associated Tree");\r
1779     protected MenuItem closeMenuItem = new MenuItem("Close");\r
1780     protected Menu editMenu = new Menu("Edit");\r
1781     protected Menu viewMenu = new Menu("View");\r
1782     protected Menu colourMenu = new Menu("Colour");\r
1783     protected Menu calculateMenu = new Menu("Calculate");\r
1784     protected MenuItem selectAllSequenceMenuItem = new MenuItem("Select all");\r
1785     protected MenuItem deselectAllSequenceMenuItem = new MenuItem("Deselect All");\r
1786     protected MenuItem invertSequenceMenuItem = new MenuItem("Invert Selection");\r
1787     protected MenuItem remove2LeftMenuItem = new MenuItem();\r
1788     protected MenuItem remove2RightMenuItem = new MenuItem();\r
1789     protected MenuItem removeGappedColumnMenuItem = new MenuItem();\r
1790     protected MenuItem removeAllGapsMenuItem = new MenuItem();\r
1791     protected CheckboxMenuItem viewBoxesMenuItem = new CheckboxMenuItem();\r
1792     protected CheckboxMenuItem viewTextMenuItem = new CheckboxMenuItem();\r
1793     protected MenuItem sortPairwiseMenuItem = new MenuItem();\r
1794     protected MenuItem sortIDMenuItem = new MenuItem();\r
1795     protected MenuItem sortGroupMenuItem = new MenuItem();\r
1796     protected MenuItem removeRedundancyMenuItem = new MenuItem();\r
1797     protected MenuItem pairwiseAlignmentMenuItem = new MenuItem();\r
1798     protected MenuItem PCAMenuItem = new MenuItem();\r
1799     protected MenuItem averageDistanceTreeMenuItem = new MenuItem();\r
1800     protected MenuItem neighbourTreeMenuItem = new MenuItem();\r
1801     BorderLayout borderLayout1 = new BorderLayout();\r
1802     public Label statusBar = new Label();\r
1803     protected Menu outputTextboxMenu = new Menu();\r
1804     protected MenuItem clustalColour = new MenuItem();\r
1805     protected MenuItem zappoColour = new MenuItem();\r
1806     protected MenuItem taylorColour = new MenuItem();\r
1807     protected MenuItem hydrophobicityColour = new MenuItem();\r
1808     protected MenuItem helixColour = new MenuItem();\r
1809     protected MenuItem strandColour = new MenuItem();\r
1810     protected MenuItem turnColour = new MenuItem();\r
1811     protected MenuItem buriedColour = new MenuItem();\r
1812     protected MenuItem userDefinedColour = new MenuItem();\r
1813     protected MenuItem PIDColour = new MenuItem();\r
1814     protected MenuItem BLOSUM62Colour = new MenuItem();\r
1815     MenuItem njTreeBlosumMenuItem = new MenuItem();\r
1816     MenuItem avDistanceTreeBlosumMenuItem = new MenuItem();\r
1817     protected CheckboxMenuItem annotationPanelMenuItem = new CheckboxMenuItem();\r
1818     protected CheckboxMenuItem colourTextMenuItem = new CheckboxMenuItem();\r
1819     MenuItem overviewMenuItem = new MenuItem();\r
1820     protected MenuItem undoMenuItem = new MenuItem();\r
1821     protected MenuItem redoMenuItem = new MenuItem();\r
1822     protected CheckboxMenuItem conservationMenuItem = new CheckboxMenuItem();\r
1823     MenuItem noColourmenuItem = new MenuItem();\r
1824     protected CheckboxMenuItem wrapMenuItem = new CheckboxMenuItem();\r
1825     protected CheckboxMenuItem renderGapsMenuItem = new CheckboxMenuItem();\r
1826     MenuItem findMenuItem = new MenuItem();\r
1827     Menu searchMenu = new Menu();\r
1828     protected CheckboxMenuItem abovePIDThreshold = new CheckboxMenuItem();\r
1829     protected MenuItem nucleotideColour = new MenuItem();\r
1830     MenuItem deleteGroups = new MenuItem();\r
1831     MenuItem delete = new MenuItem();\r
1832     MenuItem copy = new MenuItem();\r
1833     MenuItem cut = new MenuItem();\r
1834     Menu pasteMenu = new Menu();\r
1835     MenuItem pasteNew = new MenuItem();\r
1836     MenuItem pasteThis = new MenuItem();\r
1837     protected CheckboxMenuItem applyToAllGroups = new CheckboxMenuItem();\r
1838     protected MenuItem font = new MenuItem();\r
1839     protected CheckboxMenuItem scaleAbove = new CheckboxMenuItem();\r
1840     protected CheckboxMenuItem scaleLeft = new CheckboxMenuItem();\r
1841     protected CheckboxMenuItem scaleRight = new CheckboxMenuItem();\r
1842     MenuItem modifyPID = new MenuItem();\r
1843     MenuItem modifyConservation = new MenuItem();\r
1844     protected CheckboxMenuItem autoCalculate\r
1845         = new CheckboxMenuItem("Autocalculate Consensus", true);\r
1846     protected Menu sortByTreeMenu = new Menu();\r
1847     Menu sort = new Menu();\r
1848     Menu calculate = new Menu();\r
1849     MenuItem inputText = new MenuItem();\r
1850     Menu helpMenu = new Menu();\r
1851     MenuItem documentation = new MenuItem();\r
1852     MenuItem about = new MenuItem();\r
1853     protected CheckboxMenuItem seqLimits = new CheckboxMenuItem();\r
1854   Panel embeddedMenu;\r
1855   Label embeddedEdit;\r
1856   Label embeddedSearch;\r
1857   Label embeddedView;\r
1858   Label embeddedColour;\r
1859   Label embeddedFile;\r
1860   Label embeddedHelp;\r
1861   Label embeddedCalculate;\r
1862   FlowLayout flowLayout1;\r
1863 \r
1864   private void jbInit() throws Exception {\r
1865 \r
1866       setMenuBar(alignFrameMenuBar);\r
1867 \r
1868       MenuItem item;\r
1869 \r
1870       // dynamically fill save as menu with available formats\r
1871       for (int i = 0; i < jalview.io.AppletFormatAdapter.formats.size(); i++)\r
1872       {\r
1873 \r
1874         item = new MenuItem( (String) jalview.io.AppletFormatAdapter.formats.\r
1875                             elementAt(\r
1876                                 i));\r
1877         item.addActionListener(new java.awt.event.ActionListener()\r
1878         {\r
1879           public void actionPerformed(ActionEvent e)\r
1880           {\r
1881             outputText_actionPerformed(e);\r
1882           }\r
1883         });\r
1884 \r
1885         outputTextboxMenu.add(item);\r
1886       }\r
1887         closeMenuItem.addActionListener(this);\r
1888         loadApplication.addActionListener(this);\r
1889 \r
1890         loadTree.addActionListener(this);\r
1891         selectAllSequenceMenuItem.addActionListener(this);\r
1892         deselectAllSequenceMenuItem.addActionListener(this);\r
1893         invertSequenceMenuItem.addActionListener(this);\r
1894         remove2LeftMenuItem.setLabel("Remove Left");\r
1895         remove2LeftMenuItem.addActionListener(this);\r
1896         remove2RightMenuItem.setLabel("Remove Right");\r
1897         remove2RightMenuItem.addActionListener(this);\r
1898         removeGappedColumnMenuItem.setLabel("Remove Empty Columns");\r
1899         removeGappedColumnMenuItem.addActionListener(this);\r
1900         removeAllGapsMenuItem.setLabel("Remove All Gaps");\r
1901         removeAllGapsMenuItem.addActionListener(this);\r
1902         viewBoxesMenuItem.setLabel("Boxes");\r
1903         viewBoxesMenuItem.setState(true);\r
1904         viewBoxesMenuItem.addItemListener(this);\r
1905         viewTextMenuItem.setLabel("Text");\r
1906         viewTextMenuItem.setState(true);\r
1907         viewTextMenuItem.addItemListener(this);\r
1908         sortPairwiseMenuItem.setLabel("by Pairwise Identity");\r
1909         sortPairwiseMenuItem.addActionListener(this);\r
1910         sortIDMenuItem.setLabel("by ID");\r
1911         sortIDMenuItem.addActionListener(this);\r
1912         sortGroupMenuItem.setLabel("by Group");\r
1913         sortGroupMenuItem.addActionListener(this);\r
1914         removeRedundancyMenuItem.setLabel("Remove Redundancy...");\r
1915         removeRedundancyMenuItem.addActionListener(this);\r
1916         pairwiseAlignmentMenuItem.setLabel("Pairwise Alignments...");\r
1917         pairwiseAlignmentMenuItem.addActionListener(this);\r
1918         PCAMenuItem.setLabel("Principal Component Analysis");\r
1919         PCAMenuItem.addActionListener(this);\r
1920         averageDistanceTreeMenuItem.setLabel(\r
1921             "Average Distance Using % Identity");\r
1922         averageDistanceTreeMenuItem.addActionListener(this);\r
1923         neighbourTreeMenuItem.setLabel("Neighbour Joining Using % Identity");\r
1924         neighbourTreeMenuItem.addActionListener(this);\r
1925         alignFrameMenuBar.setFont(new java.awt.Font("Verdana", 0, 11));\r
1926         statusBar.setBackground(Color.white);\r
1927         statusBar.setFont(new java.awt.Font("Verdana", 0, 11));\r
1928         statusBar.setText("Status bar");\r
1929         outputTextboxMenu.setLabel("Output to Textbox");\r
1930         clustalColour.setLabel("Clustalx");\r
1931 \r
1932         clustalColour.addActionListener(this);\r
1933         zappoColour.setLabel("Zappo");\r
1934         zappoColour.addActionListener(this);\r
1935         taylorColour.setLabel("Taylor");\r
1936         taylorColour.addActionListener(this);\r
1937         hydrophobicityColour.setLabel("Hydrophobicity");\r
1938         hydrophobicityColour.addActionListener(this);\r
1939         helixColour.setLabel("Helix Propensity");\r
1940         helixColour.addActionListener(this);\r
1941         strandColour.setLabel("Strand Propensity");\r
1942         strandColour.addActionListener(this);\r
1943         turnColour.setLabel("Turn Propensity");\r
1944         turnColour.addActionListener(this);\r
1945         buriedColour.setLabel("Buried Index");\r
1946         buriedColour.addActionListener(this);\r
1947         userDefinedColour.setLabel("User Defined...");\r
1948         userDefinedColour.addActionListener(this);\r
1949         PIDColour.setLabel("Percentage Identity");\r
1950         PIDColour.addActionListener(this);\r
1951         BLOSUM62Colour.setLabel("BLOSUM62 Score");\r
1952         BLOSUM62Colour.addActionListener(this);\r
1953         avDistanceTreeBlosumMenuItem.setLabel(\r
1954             "Average Distance Using BLOSUM62");\r
1955         avDistanceTreeBlosumMenuItem.addActionListener(this);\r
1956         njTreeBlosumMenuItem.setLabel("Neighbour Joining Using BLOSUM62");\r
1957         njTreeBlosumMenuItem.addActionListener(this);\r
1958         annotationPanelMenuItem.setLabel("Show Annotations");\r
1959         annotationPanelMenuItem.addItemListener(this);\r
1960         colourTextMenuItem.setLabel("Colour Text");\r
1961         colourTextMenuItem.addItemListener(this);\r
1962         overviewMenuItem.setLabel("Overview Window");\r
1963         overviewMenuItem.addActionListener(this);\r
1964         undoMenuItem.setEnabled(false);\r
1965         undoMenuItem.setLabel("Undo");\r
1966         undoMenuItem.addActionListener(this);\r
1967         redoMenuItem.setEnabled(false);\r
1968         redoMenuItem.setLabel("Redo");\r
1969         redoMenuItem.addActionListener(this);\r
1970         conservationMenuItem.setLabel("by Conservation");\r
1971         conservationMenuItem.addItemListener(this);\r
1972         noColourmenuItem.setLabel("None");\r
1973         noColourmenuItem.addActionListener(this);\r
1974         wrapMenuItem.setLabel("Wrap");\r
1975         wrapMenuItem.addItemListener(this);\r
1976         renderGapsMenuItem.setLabel("Show Gaps");\r
1977         renderGapsMenuItem.setState(true);\r
1978         renderGapsMenuItem.addItemListener(this);\r
1979         findMenuItem.setLabel("Find...");\r
1980         findMenuItem.addActionListener(this);\r
1981         searchMenu.setLabel("Search");\r
1982 \r
1983         abovePIDThreshold.setLabel("Above Identity Threshold");\r
1984         abovePIDThreshold.addItemListener(this);\r
1985         nucleotideColour.setLabel("Nucleotide");\r
1986         nucleotideColour.addActionListener(this);\r
1987         deleteGroups.setLabel("Undefine Groups");\r
1988         deleteGroups.addActionListener(this);\r
1989         copy.setLabel("Copy");\r
1990         copy.addActionListener(this);\r
1991         cut.setLabel("Cut");\r
1992         cut.addActionListener(this);\r
1993         delete.setLabel("Delete");\r
1994         delete.addActionListener(this);\r
1995         pasteMenu.setLabel("Paste");\r
1996         pasteNew.setLabel("To New Alignment");\r
1997         pasteNew.addActionListener(this);\r
1998         pasteThis.setLabel("Add To This Alignment");\r
1999         pasteThis.addActionListener(this);\r
2000         applyToAllGroups.setLabel("Apply Colour To All Groups");\r
2001         applyToAllGroups.setState(true);\r
2002         applyToAllGroups.addItemListener(this);\r
2003         font.setLabel("Font...");\r
2004         font.addActionListener(this);\r
2005         scaleAbove.setLabel("Scale Above");\r
2006         scaleAbove.setState(true);\r
2007         scaleAbove.setEnabled(false);\r
2008         scaleAbove.addItemListener(this);\r
2009         scaleLeft.setEnabled(false);\r
2010         scaleLeft.setState(true);\r
2011         scaleLeft.setLabel("Scale Left");\r
2012         scaleLeft.addItemListener(this);\r
2013         scaleRight.setEnabled(false);\r
2014         scaleRight.setState(true);\r
2015         scaleRight.setLabel("Scale Right");\r
2016         scaleRight.addItemListener(this);\r
2017         modifyPID.setLabel("Modify Identity Threshold...");\r
2018         modifyPID.addActionListener(this);\r
2019         modifyConservation.setLabel("Modify Conservation Threshold...");\r
2020         modifyConservation.addActionListener(this);\r
2021         sortByTreeMenu.setLabel("By Tree Order");\r
2022         sort.setLabel("Sort");\r
2023         calculate.setLabel("Calculate Tree");\r
2024         autoCalculate.addItemListener(this);\r
2025         inputText.setLabel("Input from textbox");\r
2026         inputText.addActionListener(this);\r
2027 \r
2028         helpMenu.setLabel("Help");\r
2029         documentation.setLabel("Documentation");\r
2030         documentation.addActionListener(this);\r
2031 \r
2032         about.setLabel("About...");\r
2033         about.addActionListener(this);\r
2034           seqLimits.setState(true);\r
2035     seqLimits.setLabel("Show Sequence Limits");\r
2036     seqLimits.addItemListener(this);\r
2037     featureSettings.setLabel("Feature Settings...");\r
2038     featureSettings.addActionListener(this);\r
2039     sequenceFeatures.setLabel("Sequence Features");\r
2040     sequenceFeatures.addItemListener(this);\r
2041     sequenceFeatures.setState(false);\r
2042     annotationColour.setLabel("by Annotation...");\r
2043     annotationColour.addActionListener(this);\r
2044 \r
2045     alignFrameMenuBar.add(fileMenu);\r
2046         alignFrameMenuBar.add(editMenu);\r
2047         alignFrameMenuBar.add(searchMenu);\r
2048         alignFrameMenuBar.add(viewMenu);\r
2049         alignFrameMenuBar.add(colourMenu);\r
2050         alignFrameMenuBar.add(calculateMenu);\r
2051         alignFrameMenuBar.add(helpMenu);\r
2052         fileMenu.add(inputText);\r
2053         fileMenu.add(outputTextboxMenu);\r
2054         if(jalviewServletURL!=null)\r
2055           fileMenu.add(loadApplication);\r
2056         fileMenu.addSeparator();\r
2057         fileMenu.add(loadTree);\r
2058         fileMenu.add(closeMenuItem);\r
2059         editMenu.add(undoMenuItem);\r
2060         editMenu.add(redoMenuItem);\r
2061         editMenu.add(cut);\r
2062         editMenu.add(copy);\r
2063         editMenu.add(pasteMenu);\r
2064         editMenu.add(delete);\r
2065         editMenu.addSeparator();\r
2066         editMenu.add(selectAllSequenceMenuItem);\r
2067         editMenu.add(deselectAllSequenceMenuItem);\r
2068         editMenu.add(invertSequenceMenuItem);\r
2069         editMenu.add(deleteGroups);\r
2070         editMenu.addSeparator();\r
2071         editMenu.add(remove2LeftMenuItem);\r
2072         editMenu.add(remove2RightMenuItem);\r
2073         editMenu.add(removeGappedColumnMenuItem);\r
2074         editMenu.add(removeAllGapsMenuItem);\r
2075         editMenu.add(removeRedundancyMenuItem);\r
2076         searchMenu.add(findMenuItem);\r
2077         viewMenu.add(font);\r
2078         viewMenu.addSeparator();\r
2079     viewMenu.add(seqLimits);\r
2080         viewMenu.addSeparator();\r
2081     viewMenu.add(wrapMenuItem);\r
2082         viewMenu.add(scaleAbove);\r
2083         viewMenu.add(scaleLeft);\r
2084         viewMenu.add(scaleRight);\r
2085         viewMenu.addSeparator();\r
2086     viewMenu.add(viewBoxesMenuItem);\r
2087         viewMenu.add(viewTextMenuItem);\r
2088         viewMenu.add(colourTextMenuItem);\r
2089         viewMenu.add(renderGapsMenuItem);\r
2090         viewMenu.add(annotationPanelMenuItem);\r
2091     viewMenu.addSeparator();\r
2092         viewMenu.add(sequenceFeatures);\r
2093         viewMenu.add(featureSettings);\r
2094     viewMenu.addSeparator();\r
2095         viewMenu.add(overviewMenuItem);\r
2096         colourMenu.add(applyToAllGroups);\r
2097         colourMenu.addSeparator();\r
2098         colourMenu.add(noColourmenuItem);\r
2099         colourMenu.add(clustalColour);\r
2100         colourMenu.add(BLOSUM62Colour);\r
2101         colourMenu.add(PIDColour);\r
2102         colourMenu.add(zappoColour);\r
2103         colourMenu.add(taylorColour);\r
2104         colourMenu.add(hydrophobicityColour);\r
2105         colourMenu.add(helixColour);\r
2106         colourMenu.add(strandColour);\r
2107         colourMenu.add(turnColour);\r
2108         colourMenu.add(buriedColour);\r
2109         colourMenu.add(nucleotideColour);\r
2110         colourMenu.add(userDefinedColour);\r
2111         colourMenu.addSeparator();\r
2112         colourMenu.add(conservationMenuItem);\r
2113         colourMenu.add(modifyConservation);\r
2114         colourMenu.add(abovePIDThreshold);\r
2115         colourMenu.add(modifyPID);\r
2116     colourMenu.add(annotationColour);\r
2117     calculateMenu.add(sort);\r
2118         calculateMenu.add(calculate);\r
2119         calculateMenu.addSeparator();\r
2120         calculateMenu.add(pairwiseAlignmentMenuItem);\r
2121         calculateMenu.add(PCAMenuItem);\r
2122         calculateMenu.add(autoCalculate);\r
2123         this.add(statusBar, BorderLayout.SOUTH);\r
2124         pasteMenu.add(pasteNew);\r
2125         pasteMenu.add(pasteThis);\r
2126         sort.add(sortIDMenuItem);\r
2127         sort.add(sortByTreeMenu);\r
2128         sort.add(sortGroupMenuItem);\r
2129         sort.add(sortPairwiseMenuItem);\r
2130         calculate.add(averageDistanceTreeMenuItem);\r
2131         calculate.add(neighbourTreeMenuItem);\r
2132         calculate.add(avDistanceTreeBlosumMenuItem);\r
2133         calculate.add(njTreeBlosumMenuItem);\r
2134         helpMenu.add(documentation);\r
2135         helpMenu.add(about);\r
2136   }\r
2137 \r
2138   public void setEmbedded()\r
2139   {\r
2140 \r
2141     embeddedMenu = new Panel();\r
2142     embeddedEdit = new Label();\r
2143     embeddedSearch = new Label();\r
2144     embeddedView = new Label();\r
2145     embeddedColour = new Label();\r
2146     embeddedFile = new Label();\r
2147     embeddedHelp = new Label();\r
2148     embeddedCalculate = new Label();\r
2149     flowLayout1 = new FlowLayout();\r
2150     embeddedMenu.setBackground(Color.lightGray);\r
2151     embeddedMenu.setLayout(flowLayout1);\r
2152     embeddedEdit.setText("Edit");\r
2153     embeddedEdit.setFont(new java.awt.Font("Arial", Font.PLAIN, 10));\r
2154     embeddedSearch.setText("Search");\r
2155     embeddedSearch.setFont(new java.awt.Font("Arial", Font.PLAIN, 10));\r
2156     embeddedView.setText("View");\r
2157     embeddedView.setFont(new java.awt.Font("Arial", Font.PLAIN, 10));\r
2158     embeddedColour.setText("Colour");\r
2159     embeddedColour.setFont(new java.awt.Font("Arial", Font.PLAIN, 10));\r
2160     embeddedFile.setFont(new java.awt.Font("Arial", Font.PLAIN, 10));\r
2161     embeddedFile.setText("File");\r
2162     embeddedHelp.setFont(new java.awt.Font("Arial", Font.PLAIN, 10));\r
2163     embeddedHelp.setText("Help");\r
2164     embeddedCalculate.setFont(new java.awt.Font("Arial", Font.PLAIN, 10));\r
2165     embeddedCalculate.setText("Calculate");\r
2166     embeddedMenu.add(embeddedFile);\r
2167     embeddedMenu.add(embeddedEdit);\r
2168     embeddedMenu.add(embeddedSearch);\r
2169     embeddedMenu.add(embeddedView);\r
2170     embeddedMenu.add(embeddedColour);\r
2171     embeddedMenu.add(embeddedCalculate);\r
2172     embeddedMenu.add(embeddedHelp);\r
2173     flowLayout1.setAlignment(FlowLayout.LEFT);\r
2174     flowLayout1.setHgap(2);\r
2175     flowLayout1.setVgap(0);\r
2176     embeddedFile.addMouseListener(this);\r
2177     embeddedEdit.addMouseListener(this);\r
2178     embeddedSearch.addMouseListener(this);\r
2179     embeddedView.addMouseListener(this);\r
2180     embeddedColour.addMouseListener(this);\r
2181     embeddedCalculate.addMouseListener(this);\r
2182     embeddedHelp.addMouseListener(this);\r
2183 \r
2184    // setVisible(false);\r
2185     fileMenu.remove(closeMenuItem);\r
2186     fileMenu.remove(3); // Seperator\r
2187 \r
2188     applet.setLayout(new BorderLayout());\r
2189     applet.add(embeddedMenu, BorderLayout.NORTH);\r
2190     applet.add(statusBar, BorderLayout.SOUTH);\r
2191    // applet.validate();\r
2192 \r
2193     alignPanel.setSize(applet.size().width, applet.size().height\r
2194                        - embeddedMenu.HEIGHT - statusBar.HEIGHT);\r
2195 \r
2196      applet.add(alignPanel, BorderLayout.CENTER);\r
2197      applet.validate();\r
2198 \r
2199   }\r
2200 \r
2201 \r
2202 \r
2203   PopupMenu filePopup, editPopup, searchPopup,\r
2204       viewPopup, colourPopup, calculatePopup, helpPopup;\r
2205   MenuItem featureSettings = new MenuItem();\r
2206   CheckboxMenuItem sequenceFeatures = new CheckboxMenuItem();\r
2207   MenuItem annotationColour = new MenuItem();\r
2208 \r
2209   public void mousePressed(MouseEvent evt)\r
2210   {\r
2211     PopupMenu popup = null;\r
2212     Label source = (Label)evt.getSource();\r
2213     if(source==embeddedFile)\r
2214     {\r
2215       popup = filePopup = genPopupMenu(filePopup, fileMenu);\r
2216     }\r
2217     else if(source==embeddedEdit)\r
2218     {\r
2219       popup = editPopup = genPopupMenu(editPopup, editMenu);\r
2220     }\r
2221     else if(source==embeddedSearch)\r
2222     {\r
2223       popup = searchPopup = genPopupMenu(searchPopup, searchMenu);\r
2224     }\r
2225     else if(source==embeddedView)\r
2226     {\r
2227       popup = viewPopup = genPopupMenu(viewPopup, viewMenu);\r
2228     }\r
2229     else if(source==embeddedColour)\r
2230     {\r
2231       popup = colourPopup = genPopupMenu(colourPopup, colourMenu);\r
2232     }\r
2233     else if(source==embeddedCalculate)\r
2234     {\r
2235       popup = calculatePopup = genPopupMenu(calculatePopup, calculateMenu);\r
2236     }\r
2237     else if(source==embeddedHelp)\r
2238     {\r
2239       popup = helpPopup = genPopupMenu(helpPopup, helpMenu);\r
2240     }\r
2241 \r
2242     embeddedMenu.add(popup);\r
2243     popup.show(embeddedMenu,\r
2244                source.getBounds().x,\r
2245                source.getBounds().y + source.getBounds().getSize().height);\r
2246   }\r
2247 \r
2248   PopupMenu genPopupMenu(PopupMenu popup, Menu original)\r
2249   {\r
2250     if(popup!=null)\r
2251     {\r
2252       return popup;\r
2253     }\r
2254     popup = new PopupMenu();\r
2255     int m, mSize = original.getItemCount();\r
2256     for(m=0; m<mSize; m++)\r
2257     {\r
2258       popup.add(original.getItem(m));\r
2259       mSize--;\r
2260       m--;\r
2261     }\r
2262 \r
2263     return popup;\r
2264   }\r
2265   public void mouseClicked(MouseEvent evt)\r
2266   {}\r
2267   public void mouseReleased(MouseEvent evt)\r
2268   {}\r
2269   public void mouseEntered(MouseEvent evt)\r
2270   {}\r
2271   public void mouseExited(MouseEvent evt)\r
2272   {}\r
2273 \r
2274 }\r
2275 \r