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