2 * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.0b1)
3 * Copyright (C) 2014 The Jalview Authors
5 * This file is part of Jalview.
7 * Jalview is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
11 * Jalview is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty
13 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14 * PURPOSE. See the GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License along with Jalview. If not, see <http://www.gnu.org/licenses/>.
17 * The Jalview Authors are detailed in the 'AUTHORS' file.
19 package jalview.appletgui;
21 import jalview.analysis.AlignmentSorter;
22 import jalview.analysis.Conservation;
23 import jalview.api.AlignViewControllerGuiI;
24 import jalview.api.AlignViewControllerI;
25 import jalview.api.SequenceStructureBinding;
26 import jalview.bin.JalviewLite;
27 import jalview.commands.CommandI;
28 import jalview.commands.EditCommand;
29 import jalview.commands.OrderCommand;
30 import jalview.commands.RemoveGapColCommand;
31 import jalview.commands.RemoveGapsCommand;
32 import jalview.commands.SlideSequencesCommand;
33 import jalview.commands.TrimRegionCommand;
34 import jalview.datamodel.Alignment;
35 import jalview.datamodel.AlignmentI;
36 import jalview.datamodel.AlignmentOrder;
37 import jalview.datamodel.ColumnSelection;
38 import jalview.datamodel.PDBEntry;
39 import jalview.datamodel.Sequence;
40 import jalview.datamodel.SequenceGroup;
41 import jalview.datamodel.SequenceI;
42 import jalview.io.AnnotationFile;
43 import jalview.io.AppletFormatAdapter;
44 import jalview.io.FeaturesFile;
45 import jalview.io.TCoffeeScoreFile;
46 import jalview.schemes.Blosum62ColourScheme;
47 import jalview.schemes.BuriedColourScheme;
48 import jalview.schemes.ClustalxColourScheme;
49 import jalview.schemes.ColourSchemeI;
50 import jalview.schemes.HelixColourScheme;
51 import jalview.schemes.HydrophobicColourScheme;
52 import jalview.schemes.NucleotideColourScheme;
53 import jalview.schemes.PIDColourScheme;
54 import jalview.schemes.PurinePyrimidineColourScheme;
55 import jalview.schemes.RNAHelicesColourChooser;
56 import jalview.schemes.ResidueProperties;
57 import jalview.schemes.StrandColourScheme;
58 import jalview.schemes.TCoffeeColourScheme;
59 import jalview.schemes.TaylorColourScheme;
60 import jalview.schemes.TurnColourScheme;
61 import jalview.schemes.ZappoColourScheme;
62 import jalview.structure.StructureSelectionManager;
63 import jalview.util.MessageManager;
65 import java.awt.BorderLayout;
66 import java.awt.Canvas;
67 import java.awt.CheckboxMenuItem;
68 import java.awt.Color;
70 import java.awt.FontMetrics;
71 import java.awt.Frame;
72 import java.awt.Graphics;
73 import java.awt.Label;
75 import java.awt.MenuBar;
76 import java.awt.MenuItem;
77 import java.awt.event.ActionEvent;
78 import java.awt.event.ActionListener;
79 import java.awt.event.FocusEvent;
80 import java.awt.event.FocusListener;
81 import java.awt.event.ItemEvent;
82 import java.awt.event.ItemListener;
83 import java.awt.event.KeyEvent;
84 import java.awt.event.KeyListener;
85 import java.awt.event.WindowAdapter;
86 import java.awt.event.WindowEvent;
87 import java.io.IOException;
89 import java.net.URLEncoder;
90 import java.util.Enumeration;
91 import java.util.Hashtable;
92 import java.util.List;
93 import java.util.StringTokenizer;
94 import java.util.Vector;
96 public class AlignFrame extends EmbmenuFrame implements ActionListener,
97 ItemListener, KeyListener, AlignViewControllerGuiI
99 public AlignViewControllerI avc;
100 public AlignmentPanel alignPanel;
102 public AlignViewport viewport;
104 int DEFAULT_WIDTH = 700;
106 int DEFAULT_HEIGHT = 500;
108 String jalviewServletURL;
110 public AlignFrame(AlignmentI al, jalview.bin.JalviewLite applet,
111 String title, boolean embedded)
115 jalviewServletURL = applet.getParameter("APPLICATION_URL");
121 } catch (Exception ex)
123 ex.printStackTrace();
126 viewport = new AlignViewport(al, applet);
127 alignPanel = new AlignmentPanel(this, viewport);
128 avc = new jalview.controller.AlignViewController(this, viewport, alignPanel);
129 viewport.updateConservation(alignPanel);
130 viewport.updateConsensus(alignPanel);
132 annotationPanelMenuItem.setState(viewport.showAnnotation);
133 displayNonconservedMenuItem.setState(viewport.getShowUnconserved());
134 followMouseOverFlag.setState(viewport.getFollowHighlight());
135 showGroupConsensus.setState(viewport.isShowGroupConsensus());
136 showGroupConservation.setState(viewport.isShowGroupConservation());
137 showConsensusHistogram.setState(viewport.isShowConsensusHistogram());
138 showSequenceLogo.setState(viewport.isShowSequenceLogo());
139 normSequenceLogo.setState(viewport.isNormaliseSequenceLogo());
141 seqLimits.setState(viewport.showJVSuffix);
145 String param = applet.getParameter("sortBy");
148 if (param.equalsIgnoreCase("Id"))
150 sortIDMenuItem_actionPerformed();
152 else if (param.equalsIgnoreCase("Pairwise Identity"))
154 sortPairwiseMenuItem_actionPerformed();
156 else if (param.equalsIgnoreCase("Length"))
158 sortLengthMenuItem_actionPerformed();
162 param = applet.getParameter("wrap");
165 if (param.equalsIgnoreCase("true"))
167 wrapMenuItem.setState(true);
168 wrapMenuItem_actionPerformed();
171 param = applet.getParameter("centrecolumnlabels");
174 centreColumnLabelFlag.setState(true);
175 centreColumnLabelFlag_stateChanged();
179 param = applet.getParameter("windowWidth");
182 int width = Integer.parseInt(param);
183 DEFAULT_WIDTH = width;
185 param = applet.getParameter("windowHeight");
188 int height = Integer.parseInt(param);
189 DEFAULT_HEIGHT = height;
191 } catch (Exception ex)
196 if (viewport.getAlignment().isNucleotide())
198 viewport.updateStrucConsensus(alignPanel);
199 if (viewport.getAlignment().hasRNAStructure())
201 RNAHelixColour.setEnabled(true);
205 RNAHelixColour.setEnabled(false);
210 RNAHelixColour.setEnabled(false);
211 purinePyrimidineColour.setEnabled(false);
213 // Some JVMS send keyevents to Top frame or lowest panel,
214 // Havent worked out why yet. So add to both this frame and seqCanvas for
216 this.addKeyListener(this);
217 alignPanel.seqPanel.seqCanvas.addKeyListener(this);
218 alignPanel.idPanel.idCanvas.addKeyListener(this);
219 alignPanel.scalePanel.addKeyListener(this);
220 alignPanel.annotationPanel.addKeyListener(this);
221 alignPanel.annotationPanelHolder.addKeyListener(this);
222 alignPanel.annotationSpaceFillerHolder.addKeyListener(this);
223 alignPanel.alabels.addKeyListener(this);
224 createAlignFrameWindow(embedded, title);
227 alignPanel.adjustAnnotationHeight();
228 alignPanel.paintAlignment(true);
231 public AlignViewport getAlignViewport()
236 public SeqCanvas getSeqcanvas()
238 return alignPanel.seqPanel.seqCanvas;
242 * Load a features file onto the alignment
245 * file URL, content, or other resolvable path
247 * is protocol for accessing data referred to by file
250 public boolean parseFeaturesFile(String file, String type)
252 return parseFeaturesFile(file, type, true);
256 * Load a features file onto the alignment
259 * file URL, content, or other resolvable path
261 * is protocol for accessing data referred to by file
262 * @param autoenabledisplay
263 * when true, display features flag will be automatically enabled if
264 * features are loaded
265 * @return true if data parsed as a features file
267 public boolean parseFeaturesFile(String file, String type,
268 boolean autoenabledisplay)
270 // TODO: test if importing a features file onto an alignment which already
271 // has features with links overwrites the original links.
273 Hashtable featureLinks = new Hashtable();
274 boolean featuresFile = false;
277 featuresFile = new jalview.io.FeaturesFile(file, type)
278 .parse(viewport.getAlignment(), alignPanel.seqPanel.seqCanvas
279 .getFeatureRenderer().featureColours, featureLinks,
280 true, viewport.applet.getDefaultParameter(
281 "relaxedidmatch", false));
282 } catch (Exception ex)
284 ex.printStackTrace();
289 if (featureLinks.size() > 0)
291 alignPanel.seqPanel.seqCanvas.getFeatureRenderer().featureLinks = featureLinks;
293 if (autoenabledisplay)
295 viewport.showSequenceFeatures = true;
296 sequenceFeatures.setState(true);
298 if (viewport.featureSettings != null)
300 viewport.featureSettings.refreshTable();
302 alignPanel.paintAlignment(true);
303 statusBar.setText(MessageManager.getString("label.successfully_added_features_alignment"));
309 public void keyPressed(KeyEvent evt)
311 if (viewport.cursorMode
312 && ((evt.getKeyCode() >= KeyEvent.VK_0 && evt.getKeyCode() <= KeyEvent.VK_9) || (evt
313 .getKeyCode() >= KeyEvent.VK_NUMPAD0 && evt
314 .getKeyCode() <= KeyEvent.VK_NUMPAD9))
315 && Character.isDigit(evt.getKeyChar()))
316 alignPanel.seqPanel.numberPressed(evt.getKeyChar());
318 switch (evt.getKeyCode())
320 case 27: // escape key
321 deselectAllSequenceMenuItem_actionPerformed();
323 alignPanel.alabels.cancelDrag();
326 if (evt.isControlDown() || evt.isMetaDown())
328 cut_actionPerformed();
332 if (viewport.cursorMode && !evt.isControlDown())
334 alignPanel.seqPanel.setCursorColumn();
336 if (evt.isControlDown() || evt.isMetaDown())
338 copy_actionPerformed();
342 if (evt.isControlDown())
344 paste(evt.isShiftDown());
348 if (evt.isControlDown() || evt.isMetaDown())
350 selectAllSequenceMenuItem_actionPerformed();
353 case KeyEvent.VK_DOWN:
354 if (viewport.cursorMode)
356 alignPanel.seqPanel.moveCursor(0, 1);
360 moveSelectedSequences(false);
365 if (viewport.cursorMode)
367 alignPanel.seqPanel.moveCursor(0, -1);
371 moveSelectedSequences(true);
375 case KeyEvent.VK_LEFT:
376 if (evt.isAltDown() || !viewport.cursorMode)
377 slideSequences(false, alignPanel.seqPanel.getKeyboardNo1());
379 alignPanel.seqPanel.moveCursor(-1, 0);
382 case KeyEvent.VK_RIGHT:
383 if (evt.isAltDown() || !viewport.cursorMode)
384 slideSequences(true, alignPanel.seqPanel.getKeyboardNo1());
386 alignPanel.seqPanel.moveCursor(1, 0);
389 case KeyEvent.VK_SPACE:
390 if (viewport.cursorMode)
392 alignPanel.seqPanel.insertGapAtCursor(evt.isControlDown()
393 || evt.isShiftDown() || evt.isAltDown());
397 case KeyEvent.VK_DELETE:
398 case KeyEvent.VK_BACK_SPACE:
399 if (viewport.cursorMode)
401 alignPanel.seqPanel.deleteGapAtCursor(evt.isControlDown()
402 || evt.isShiftDown() || evt.isAltDown());
406 cut_actionPerformed();
407 alignPanel.seqPanel.seqCanvas.repaint();
412 if (viewport.cursorMode)
414 alignPanel.seqPanel.setCursorRow();
418 if (viewport.cursorMode)
420 alignPanel.seqPanel.setCursorPosition();
424 case KeyEvent.VK_ENTER:
425 case KeyEvent.VK_COMMA:
426 if (viewport.cursorMode)
428 alignPanel.seqPanel.setCursorRowAndColumn();
433 if (viewport.cursorMode)
435 alignPanel.seqPanel.setSelectionAreaAtCursor(true);
439 if (viewport.cursorMode)
441 alignPanel.seqPanel.setSelectionAreaAtCursor(false);
446 viewport.cursorMode = !viewport.cursorMode;
447 statusBar.setText(MessageManager.formatMessage("label.keyboard_editing_mode", new String[]{(viewport.cursorMode ? "on" : "off")}));
448 if (viewport.cursorMode)
450 alignPanel.seqPanel.seqCanvas.cursorX = viewport.startRes;
451 alignPanel.seqPanel.seqCanvas.cursorY = viewport.startSeq;
456 if (evt.isControlDown())
458 findMenuItem_actionPerformed();
464 boolean toggleSeqs = !evt.isControlDown();
465 boolean toggleCols = !evt.isShiftDown();
466 toggleHiddenRegions(toggleSeqs, toggleCols);
470 case KeyEvent.VK_PAGE_UP:
471 if (viewport.wrapAlignment)
473 alignPanel.scrollUp(true);
477 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
478 - viewport.endSeq + viewport.startSeq);
482 case KeyEvent.VK_PAGE_DOWN:
483 if (viewport.wrapAlignment)
485 alignPanel.scrollUp(false);
489 alignPanel.setScrollValues(viewport.startRes, viewport.startSeq
490 + viewport.endSeq - viewport.startSeq);
495 if (evt.isControlDown())
497 undoMenuItem_actionPerformed();
502 if (evt.isControlDown())
504 redoMenuItem_actionPerformed();
509 if (evt.isControlDown())
516 if (evt.isControlDown())
518 trimAlignment(false);
523 if (evt.isControlDown())
525 if (evt.isShiftDown())
527 this.removeAllGapsMenuItem_actionPerformed();
531 removeGappedColumnMenuItem_actionPerformed();
536 if (evt.isControlDown())
540 invertColSel_actionPerformed();
544 invertSequenceMenuItem_actionPerformed();
550 if (evt.isControlDown())
552 if (evt.isShiftDown())
554 this.unGroup_actionPerformed();
558 this.createGroup_actionPerformed();
564 if (evt.isControlDown())
566 this.deleteGroups_actionPerformed();
571 if (evt.isControlDown())
578 alignPanel.paintAlignment(true);
582 * called by key handler and the hide all/show all menu items
587 private void toggleHiddenRegions(boolean toggleSeqs, boolean toggleCols)
589 boolean hide = false;
590 SequenceGroup sg = viewport.getSelectionGroup();
591 if (!toggleSeqs && !toggleCols)
593 // Hide everything by the current selection - this is a hack - we do the
594 // invert and then hide
595 // first check that there will be visible columns after the invert.
596 if ((viewport.getColumnSelection() != null
597 && viewport.getColumnSelection().getSelected() != null && viewport
598 .getColumnSelection().getSelected().size() > 0)
599 || (sg != null && sg.getSize() > 0 && sg.getStartRes() <= sg
602 // now invert the sequence set, if required - empty selection implies
603 // that no hiding is required.
606 invertSequenceMenuItem_actionPerformed();
607 sg = viewport.getSelectionGroup();
611 viewport.expandColSelection(sg, true);
612 // finally invert the column selection and get the new sequence
613 // selection and indicate it should be hidden.
614 invertColSel_actionPerformed();
621 if (sg != null && sg.getSize() != viewport.getAlignment().getHeight())
624 viewport.hideAllSelectedSeqs();
626 else if (!(toggleCols && viewport.getColumnSelection().getSelected()
629 viewport.showAllHiddenSeqs();
635 if (viewport.getColumnSelection().getSelected().size() > 0)
637 viewport.hideSelectedColumns();
640 viewport.setSelectionGroup(sg);
645 viewport.showAllHiddenColumns();
651 public void keyReleased(KeyEvent evt)
656 public void keyTyped(KeyEvent evt)
661 public void itemStateChanged(ItemEvent evt)
663 if (evt.getSource() == displayNonconservedMenuItem)
665 displayNonconservedMenuItem_actionPerformed();
667 else if (evt.getSource() == colourTextMenuItem)
669 colourTextMenuItem_actionPerformed();
671 else if (evt.getSource() == wrapMenuItem)
673 wrapMenuItem_actionPerformed();
675 else if (evt.getSource() == scaleAbove)
677 viewport.setScaleAboveWrapped(scaleAbove.getState());
679 else if (evt.getSource() == scaleLeft)
681 viewport.setScaleLeftWrapped(scaleLeft.getState());
683 else if (evt.getSource() == scaleRight)
685 viewport.setScaleRightWrapped(scaleRight.getState());
687 else if (evt.getSource() == seqLimits)
689 seqLimits_itemStateChanged();
691 else if (evt.getSource() == viewBoxesMenuItem)
693 viewport.setShowBoxes(viewBoxesMenuItem.getState());
695 else if (evt.getSource() == viewTextMenuItem)
697 viewport.setShowText(viewTextMenuItem.getState());
699 else if (evt.getSource() == renderGapsMenuItem)
701 viewport.setRenderGaps(renderGapsMenuItem.getState());
703 else if (evt.getSource() == annotationPanelMenuItem)
705 viewport.setShowAnnotation(annotationPanelMenuItem.getState());
706 alignPanel.setAnnotationVisible(annotationPanelMenuItem.getState());
708 else if (evt.getSource() == sequenceFeatures)
710 viewport.showSequenceFeatures(sequenceFeatures.getState());
711 alignPanel.seqPanel.seqCanvas.repaint();
713 else if (evt.getSource() == conservationMenuItem)
715 conservationMenuItem_actionPerformed();
717 else if (evt.getSource() == abovePIDThreshold)
719 abovePIDThreshold_actionPerformed();
721 else if (evt.getSource() == applyToAllGroups)
723 viewport.setColourAppliesToAllGroups(applyToAllGroups.getState());
725 else if (evt.getSource() == autoCalculate)
727 viewport.autoCalculateConsensus = autoCalculate.getState();
729 else if (evt.getSource() == sortByTree)
731 viewport.sortByTree = sortByTree.getState();
733 else if (evt.getSource() == this.centreColumnLabelFlag)
735 centreColumnLabelFlag_stateChanged();
737 else if (evt.getSource() == this.followMouseOverFlag)
739 mouseOverFlag_stateChanged();
741 else if (evt.getSource() == showGroupConsensus)
743 showGroupConsensus_actionPerformed();
745 else if (evt.getSource() == showGroupConservation)
747 showGroupConservation_actionPerformed();
749 else if (evt.getSource() == showSequenceLogo)
751 showSequenceLogo_actionPerformed();
753 else if (evt.getSource() == normSequenceLogo)
755 normSequenceLogo_actionPerformed();
757 else if (evt.getSource() == showConsensusHistogram)
759 showConsensusHistogram_actionPerformed();
761 else if (evt.getSource() == applyAutoAnnotationSettings)
763 applyAutoAnnotationSettings_actionPerformed();
765 alignPanel.paintAlignment(true);
768 private void mouseOverFlag_stateChanged()
770 viewport.followHighlight = followMouseOverFlag.getState();
771 // TODO: could kick the scrollTo mechanism to reset view for current
775 private void centreColumnLabelFlag_stateChanged()
777 viewport.centreColumnLabels = centreColumnLabelFlag.getState();
778 this.alignPanel.annotationPanel.repaint();
782 public void actionPerformed(ActionEvent evt)
784 Object source = evt.getSource();
786 if (source == inputText)
788 inputText_actionPerformed();
790 else if (source == loadTree)
792 loadTree_actionPerformed();
794 else if (source == loadApplication)
796 launchFullApplication();
798 else if (source == loadAnnotations)
802 else if (source == outputAnnotations)
804 outputAnnotations(true);
806 else if (source == outputFeatures)
808 outputFeatures(true, "Jalview");
810 else if (source == closeMenuItem)
812 closeMenuItem_actionPerformed();
814 else if (source == copy)
816 copy_actionPerformed();
818 else if (source == undoMenuItem)
820 undoMenuItem_actionPerformed();
822 else if (source == redoMenuItem)
824 redoMenuItem_actionPerformed();
826 else if (source == inputText)
828 inputText_actionPerformed();
830 else if (source == closeMenuItem)
832 closeMenuItem_actionPerformed();
834 else if (source == undoMenuItem)
836 undoMenuItem_actionPerformed();
838 else if (source == redoMenuItem)
840 redoMenuItem_actionPerformed();
842 else if (source == copy)
844 copy_actionPerformed();
846 else if (source == pasteNew)
848 pasteNew_actionPerformed();
850 else if (source == pasteThis)
852 pasteThis_actionPerformed();
854 else if (source == cut)
856 cut_actionPerformed();
858 else if (source == delete)
860 delete_actionPerformed();
862 else if (source == grpsFromSelection)
864 makeGrpsFromSelection_actionPerformed();
866 else if (source == deleteGroups)
868 deleteGroups_actionPerformed();
870 else if (source == selectAllSequenceMenuItem)
872 selectAllSequenceMenuItem_actionPerformed();
874 else if (source == deselectAllSequenceMenuItem)
876 deselectAllSequenceMenuItem_actionPerformed();
878 else if (source == invertSequenceMenuItem)
880 invertSequenceMenuItem_actionPerformed();
882 else if (source == invertColSel)
884 viewport.invertColumnSelection();
885 alignPanel.paintAlignment(true);
887 else if (source == remove2LeftMenuItem)
891 else if (source == remove2RightMenuItem)
893 trimAlignment(false);
895 else if (source == removeGappedColumnMenuItem)
897 removeGappedColumnMenuItem_actionPerformed();
899 else if (source == removeAllGapsMenuItem)
901 removeAllGapsMenuItem_actionPerformed();
903 else if (source == findMenuItem)
905 findMenuItem_actionPerformed();
907 else if (source == font)
909 new FontChooser(alignPanel);
911 else if (source == newView)
915 else if (source == showColumns)
917 viewport.showAllHiddenColumns();
918 alignPanel.paintAlignment(true);
920 else if (source == showSeqs)
922 viewport.showAllHiddenSeqs();
923 alignPanel.paintAlignment(true);
925 else if (source == hideColumns)
927 viewport.hideSelectedColumns();
928 alignPanel.paintAlignment(true);
930 else if (source == hideSequences
931 && viewport.getSelectionGroup() != null)
933 viewport.hideAllSelectedSeqs();
934 alignPanel.paintAlignment(true);
936 else if (source == hideAllButSelection)
938 toggleHiddenRegions(false, false);
939 alignPanel.paintAlignment(true);
941 else if (source == hideAllSelection)
943 SequenceGroup sg = viewport.getSelectionGroup();
944 viewport.expandColSelection(sg, false);
945 viewport.hideAllSelectedSeqs();
946 viewport.hideSelectedColumns();
947 alignPanel.paintAlignment(true);
949 else if (source == showAllHidden)
951 viewport.showAllHiddenColumns();
952 viewport.showAllHiddenSeqs();
953 alignPanel.paintAlignment(true);
955 else if (source == showGroupConsensus)
957 showGroupConsensus_actionPerformed();
959 else if (source == showGroupConservation)
961 showGroupConservation_actionPerformed();
963 else if (source == showSequenceLogo)
965 showSequenceLogo_actionPerformed();
967 else if (source == normSequenceLogo)
969 normSequenceLogo_actionPerformed();
971 else if (source == showConsensusHistogram)
973 showConsensusHistogram_actionPerformed();
975 else if (source == applyAutoAnnotationSettings)
977 applyAutoAnnotationSettings_actionPerformed();
979 else if (source == featureSettings)
981 new FeatureSettings(alignPanel);
983 else if (source == alProperties)
985 StringBuffer contents = new jalview.io.AlignmentProperties(
986 viewport.getAlignment()).formatAsString();
987 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, this);
988 cap.setText(contents.toString());
989 Frame frame = new Frame();
991 jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage("label.alignment_properties", new String[]{getTitle()}),
994 else if (source == overviewMenuItem)
996 overviewMenuItem_actionPerformed();
998 else if (source == noColourmenuItem)
1002 else if (source == clustalColour)
1004 abovePIDThreshold.setState(false);
1005 changeColour(new ClustalxColourScheme(viewport.getAlignment(), null));
1007 else if (source == zappoColour)
1009 changeColour(new ZappoColourScheme());
1011 else if (source == taylorColour)
1013 changeColour(new TaylorColourScheme());
1015 else if (source == hydrophobicityColour)
1017 changeColour(new HydrophobicColourScheme());
1019 else if (source == helixColour)
1021 changeColour(new HelixColourScheme());
1023 else if (source == strandColour)
1025 changeColour(new StrandColourScheme());
1027 else if (source == turnColour)
1029 changeColour(new TurnColourScheme());
1031 else if (source == buriedColour)
1033 changeColour(new BuriedColourScheme());
1035 else if (source == nucleotideColour)
1037 changeColour(new NucleotideColourScheme());
1039 else if (source == purinePyrimidineColour)
1041 changeColour(new PurinePyrimidineColourScheme());
1043 else if (source == RNAHelixColour)
1045 new RNAHelicesColourChooser(viewport, alignPanel);
1047 else if (source == modifyPID)
1049 modifyPID_actionPerformed();
1051 else if (source == modifyConservation)
1053 modifyConservation_actionPerformed();
1055 else if (source == userDefinedColour)
1057 new UserDefinedColours(alignPanel, null);
1059 else if (source == PIDColour)
1061 changeColour(new PIDColourScheme());
1063 else if (source == BLOSUM62Colour)
1065 changeColour(new Blosum62ColourScheme());
1067 else if (source == tcoffeeColour)
1069 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
1071 else if (source == annotationColour)
1073 new AnnotationColourChooser(viewport, alignPanel);
1075 else if (source == sortPairwiseMenuItem)
1077 sortPairwiseMenuItem_actionPerformed();
1079 else if (source == sortIDMenuItem)
1081 sortIDMenuItem_actionPerformed();
1083 else if (source == sortLengthMenuItem)
1085 sortLengthMenuItem_actionPerformed();
1087 else if (source == sortGroupMenuItem)
1089 sortGroupMenuItem_actionPerformed();
1091 else if (source == removeRedundancyMenuItem)
1093 removeRedundancyMenuItem_actionPerformed();
1095 else if (source == pairwiseAlignmentMenuItem)
1097 pairwiseAlignmentMenuItem_actionPerformed();
1099 else if (source == PCAMenuItem)
1101 PCAMenuItem_actionPerformed();
1103 else if (source == averageDistanceTreeMenuItem)
1105 averageDistanceTreeMenuItem_actionPerformed();
1107 else if (source == neighbourTreeMenuItem)
1109 neighbourTreeMenuItem_actionPerformed();
1111 else if (source == njTreeBlosumMenuItem)
1113 njTreeBlosumMenuItem_actionPerformed();
1115 else if (source == avDistanceTreeBlosumMenuItem)
1117 avTreeBlosumMenuItem_actionPerformed();
1119 else if (source == documentation)
1121 documentation_actionPerformed();
1123 else if (source == about)
1125 about_actionPerformed();
1130 public void inputText_actionPerformed()
1132 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
1133 Frame frame = new Frame();
1135 jalview.bin.JalviewLite.addFrame(frame, MessageManager.getString("label.input_cut_paste"), 500, 500);
1138 protected void outputText_actionPerformed(ActionEvent e)
1140 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
1141 Frame frame = new Frame();
1143 jalview.bin.JalviewLite.addFrame(frame,
1144 MessageManager.formatMessage("label.alignment_output_command", new String[]{e.getActionCommand()}),600, 500);
1145 cap.setText(new AppletFormatAdapter().formatSequences(
1146 e.getActionCommand(), viewport.getAlignment(),
1147 viewport.showJVSuffix));
1150 public void loadAnnotations()
1152 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
1153 cap.setText(MessageManager.getString("label.paste_features_annotations_Tcoffee_here"));
1154 cap.setAnnotationImport();
1155 Frame frame = new Frame();
1157 jalview.bin.JalviewLite.addFrame(frame, MessageManager.getString("action.paste_annotations"), 400, 300);
1161 public String outputAnnotations(boolean displayTextbox)
1163 String annotation = new AnnotationFile().printAnnotations(
1164 viewport.showAnnotation ? viewport.getAlignment()
1165 .getAlignmentAnnotation() : null, viewport
1166 .getAlignment().getGroups(), ((Alignment) viewport
1167 .getAlignment()).alignmentProperties);
1171 CutAndPasteTransfer cap = new CutAndPasteTransfer(false, this);
1172 Frame frame = new Frame();
1174 jalview.bin.JalviewLite.addFrame(frame, MessageManager.getString("label.annotations"), 600, 500);
1175 cap.setText(annotation);
1181 private Hashtable getDisplayedFeatureCols()
1183 if (alignPanel.getFeatureRenderer() != null
1184 && viewport.featuresDisplayed != null)
1186 FeatureRenderer fr = alignPanel.getFeatureRenderer();
1187 Hashtable fcols = new Hashtable();
1188 Enumeration en = viewport.featuresDisplayed.keys();
1189 while (en.hasMoreElements())
1191 Object col = en.nextElement();
1192 fcols.put(col, fr.featureColours.get(col));
1199 public String outputFeatures(boolean displayTextbox, String format)
1202 if (format.equalsIgnoreCase("Jalview"))
1204 features = new FeaturesFile().printJalviewFormat(viewport
1205 .getAlignment().getSequencesArray(),
1206 getDisplayedFeatureCols());
1210 features = new FeaturesFile().printGFFFormat(viewport.getAlignment()
1211 .getSequencesArray(), getDisplayedFeatureCols());
1216 boolean frimport = false;
1217 if (features == null || features.equals("No Features Visible"))
1219 features = "# No features visible - paste some and import them here.";
1223 CutAndPasteTransfer cap = new CutAndPasteTransfer(frimport, this);
1226 cap.setAnnotationImport();
1228 Frame frame = new Frame();
1230 jalview.bin.JalviewLite.addFrame(frame, MessageManager.getString("label.features"), 600, 500);
1231 cap.setText(features);
1235 if (features == null)
1242 void launchFullApplication()
1244 StringBuffer url = new StringBuffer(jalviewServletURL);
1247 + appendProtocol(viewport.applet.getParameter("file")));
1249 if (viewport.applet.getParameter("features") != null)
1251 url.append("&features=");
1252 url.append(appendProtocol(viewport.applet.getParameter("features")));
1255 if (viewport.applet.getParameter("annotations") != null)
1257 url.append("&annotations=");
1258 url.append(appendProtocol(viewport.applet.getParameter("annotations")));
1261 if (viewport.applet.getParameter("jnetfile") != null)
1263 url.append("&annotations=");
1264 url.append(appendProtocol(viewport.applet.getParameter("jnetfile")));
1267 if (viewport.applet.getParameter("defaultColour") != null)
1269 url.append("&colour="
1270 + removeWhiteSpace(viewport.applet
1271 .getParameter("defaultColour")));
1274 if (viewport.applet.getParameter("userDefinedColour") != null)
1276 url.append("&colour="
1277 + removeWhiteSpace(viewport.applet
1278 .getParameter("userDefinedColour")));
1280 if (viewport.applet.getParameter("tree") != null)
1283 + appendProtocol(viewport.applet.getParameter("tree")));
1285 if (viewport.applet.getParameter("treeFile") != null)
1288 + appendProtocol(viewport.applet.getParameter("treeFile")));
1291 showURL(url.toString(), "FULL_APP");
1294 String removeWhiteSpace(String colour)
1296 StringBuffer sb = new StringBuffer();
1297 for (int i = 0; i < colour.length(); i++)
1299 if (Character.isWhitespace(colour.charAt(i)))
1305 sb.append(colour.charAt(i));
1309 return sb.toString();
1312 String appendProtocol(String url)
1317 url = URLEncoder.encode(url);
1320 * When we finally deprecate 1.1 compatibility, we can start to use
1321 * URLEncoder.encode(url,"UTF-8") and then we'll need this catch: catch
1322 * (UnsupportedEncodingException ex) { System.err.println("WARNING -
1323 * IMPLEMENTATION ERROR - UNSUPPORTED ENCODING EXCEPTION FOR "+url);
1324 * ex.printStackTrace(); }
1326 catch (java.net.MalformedURLException ex)
1328 url = viewport.applet.getCodeBase() + url;
1333 public void closeMenuItem_actionPerformed()
1335 PaintRefresher.RemoveComponent(alignPanel);
1336 if (alignPanel.seqPanel != null
1337 && alignPanel.seqPanel.seqCanvas != null)
1339 PaintRefresher.RemoveComponent(alignPanel.seqPanel.seqCanvas);
1341 if (alignPanel.idPanel != null && alignPanel.idPanel.idCanvas != null)
1343 PaintRefresher.RemoveComponent(alignPanel.idPanel.idCanvas);
1346 if (PaintRefresher.components.size() == 0 && viewport.applet == null)
1361 void updateEditMenuBar()
1364 if (viewport.historyList.size() > 0)
1366 undoMenuItem.setEnabled(true);
1367 CommandI command = (CommandI) viewport.historyList.peek();
1368 undoMenuItem.setLabel(MessageManager.formatMessage("label.undo_command", new String[]{command.getDescription()}));
1372 undoMenuItem.setEnabled(false);
1373 undoMenuItem.setLabel(MessageManager.getString("action.undo"));
1376 if (viewport.redoList.size() > 0)
1378 redoMenuItem.setEnabled(true);
1380 CommandI command = (CommandI) viewport.redoList.peek();
1381 redoMenuItem.setLabel(MessageManager.formatMessage("label.redo_command", new String[]{command.getDescription()}));
1385 redoMenuItem.setEnabled(false);
1386 redoMenuItem.setLabel(MessageManager.getString("action.redo"));
1393 public void addHistoryItem(CommandI command)
1395 if (command.getSize() > 0)
1397 viewport.historyList.push(command);
1398 viewport.redoList.removeAllElements();
1399 updateEditMenuBar();
1400 viewport.updateHiddenColumns();
1405 * TODO: JAL-1104 DOCUMENT ME!
1410 protected void undoMenuItem_actionPerformed()
1412 if (viewport.historyList.size() < 1)
1417 CommandI command = (CommandI) viewport.historyList.pop();
1418 viewport.redoList.push(command);
1419 command.undoCommand(null);
1421 AlignViewport originalSource = getOriginatingSource(command);
1423 if (originalSource != viewport)
1426 .println("Warning: Viewport object mismatch whilst undoing");
1428 originalSource.updateHiddenColumns(); // originalSource.hasHiddenColumns =
1429 // viewport.getColumnSelection().getHiddenColumns()
1431 updateEditMenuBar();
1432 originalSource.firePropertyChange("alignment", null, originalSource
1433 .getAlignment().getSequences());
1437 * TODO: JAL-1104 DOCUMENT ME!
1442 protected void redoMenuItem_actionPerformed()
1444 if (viewport.redoList.size() < 1)
1449 CommandI command = (CommandI) viewport.redoList.pop();
1450 viewport.historyList.push(command);
1451 command.doCommand(null);
1453 AlignViewport originalSource = getOriginatingSource(command);
1455 if (originalSource != viewport)
1458 .println("Warning: Viewport object mismatch whilst re-doing");
1460 originalSource.updateHiddenColumns(); // sethasHiddenColumns(); =
1461 // viewport.getColumnSelection().getHiddenColumns()
1464 updateEditMenuBar();
1465 originalSource.firePropertyChange("alignment", null, originalSource
1466 .getAlignment().getSequences());
1469 AlignViewport getOriginatingSource(CommandI command)
1471 AlignViewport originalSource = null;
1472 // For sequence removal and addition, we need to fire
1473 // the property change event FROM the viewport where the
1474 // original alignment was altered
1475 AlignmentI al = null;
1476 if (command instanceof EditCommand)
1478 EditCommand editCommand = (EditCommand) command;
1479 al = editCommand.getAlignment();
1480 Vector comps = (Vector) PaintRefresher.components.get(viewport
1481 .getSequenceSetId());
1482 for (int i = 0; i < comps.size(); i++)
1484 if (comps.elementAt(i) instanceof AlignmentPanel)
1486 if (al == ((AlignmentPanel) comps.elementAt(i)).av.getAlignment())
1488 originalSource = ((AlignmentPanel) comps.elementAt(i)).av;
1495 if (originalSource == null)
1497 // The original view is closed, we must validate
1498 // the current view against the closed view first
1501 PaintRefresher.validateSequences(al, viewport.getAlignment());
1504 originalSource = viewport;
1507 return originalSource;
1510 public void moveSelectedSequences(boolean up)
1512 SequenceGroup sg = viewport.getSelectionGroup();
1517 viewport.getAlignment().moveSelectedSequencesByOne(sg,
1518 up ? null : viewport.getHiddenRepSequences(), up);
1519 alignPanel.paintAlignment(true);
1522 synchronized void slideSequences(boolean right, int size)
1524 List<SequenceI> sg = new Vector<SequenceI>();
1525 if (viewport.cursorMode)
1527 sg.add(viewport.getAlignment().getSequenceAt(
1528 alignPanel.seqPanel.seqCanvas.cursorY));
1530 else if (viewport.getSelectionGroup() != null
1531 && viewport.getSelectionGroup().getSize() != viewport
1532 .getAlignment().getHeight())
1534 sg = viewport.getSelectionGroup().getSequences(
1535 viewport.getHiddenRepSequences());
1543 Vector<SequenceI> invertGroup = new Vector();
1545 for (int i = 0; i < viewport.getAlignment().getHeight(); i++)
1547 if (!sg.contains(viewport.getAlignment().getSequenceAt(i)))
1548 invertGroup.addElement(viewport.getAlignment().getSequenceAt(i));
1551 SequenceI[] seqs1 = sg.toArray(new SequenceI[sg.size()]);
1553 SequenceI[] seqs2 = invertGroup.toArray(new SequenceI[invertGroup
1555 for (int i = 0; i < invertGroup.size(); i++)
1556 seqs2[i] = invertGroup.elementAt(i);
1558 SlideSequencesCommand ssc;
1560 ssc = new SlideSequencesCommand("Slide Sequences", seqs2, seqs1,
1561 size, viewport.getGapCharacter());
1563 ssc = new SlideSequencesCommand("Slide Sequences", seqs1, seqs2,
1564 size, viewport.getGapCharacter());
1566 int groupAdjustment = 0;
1567 if (ssc.getGapsInsertedBegin() && right)
1569 if (viewport.cursorMode)
1570 alignPanel.seqPanel.moveCursor(size, 0);
1572 groupAdjustment = size;
1574 else if (!ssc.getGapsInsertedBegin() && !right)
1576 if (viewport.cursorMode)
1577 alignPanel.seqPanel.moveCursor(-size, 0);
1579 groupAdjustment = -size;
1582 if (groupAdjustment != 0)
1584 viewport.getSelectionGroup().setStartRes(
1585 viewport.getSelectionGroup().getStartRes() + groupAdjustment);
1586 viewport.getSelectionGroup().setEndRes(
1587 viewport.getSelectionGroup().getEndRes() + groupAdjustment);
1590 boolean appendHistoryItem = false;
1591 if (viewport.historyList != null && viewport.historyList.size() > 0
1592 && viewport.historyList.peek() instanceof SlideSequencesCommand)
1594 appendHistoryItem = ssc
1595 .appendSlideCommand((SlideSequencesCommand) viewport.historyList
1599 if (!appendHistoryItem)
1600 addHistoryItem(ssc);
1605 static StringBuffer copiedSequences;
1607 static Vector copiedHiddenColumns;
1609 protected void copy_actionPerformed()
1611 if (viewport.getSelectionGroup() == null)
1616 SequenceGroup sg = viewport.getSelectionGroup();
1617 copiedSequences = new StringBuffer();
1618 Hashtable orderedSeqs = new Hashtable();
1619 for (int i = 0; i < sg.getSize(); i++)
1621 SequenceI seq = sg.getSequenceAt(i);
1622 int index = viewport.getAlignment().findIndex(seq);
1623 orderedSeqs.put(index + "", seq);
1626 int index = 0, startRes, endRes;
1629 if (viewport.hasHiddenColumns() && viewport.getSelectionGroup() != null)
1631 copiedHiddenColumns = new Vector();
1632 int hiddenOffset = viewport.getSelectionGroup().getStartRes();
1633 for (int i = 0; i < viewport.getColumnSelection().getHiddenColumns()
1636 int[] region = (int[]) viewport.getColumnSelection()
1637 .getHiddenColumns().elementAt(i);
1639 copiedHiddenColumns.addElement(new int[]
1640 { region[0] - hiddenOffset, region[1] - hiddenOffset });
1645 copiedHiddenColumns = null;
1648 for (int i = 0; i < sg.getSize(); i++)
1650 SequenceI seq = null;
1654 if (orderedSeqs.containsKey(index + ""))
1656 seq = (SequenceI) orderedSeqs.get(index + "");
1668 // Returns residue following index if gap
1669 startRes = seq.findPosition(sg.getStartRes());
1672 // Need to find the residue preceeding index if gap
1675 for (int j = 0; j < sg.getEndRes() + 1 && j < seq.getLength(); j++)
1677 ch = seq.getCharAt(j);
1678 if (!jalview.util.Comparison.isGap((ch)))
1686 endRes += seq.getStart() - 1;
1689 copiedSequences.append(seq.getName()
1695 + seq.getSequenceAsString(sg.getStartRes(),
1696 sg.getEndRes() + 1) + "\n");
1701 protected void pasteNew_actionPerformed()
1706 protected void pasteThis_actionPerformed()
1711 void paste(boolean newAlignment)
1716 if (copiedSequences == null)
1721 StringTokenizer st = new StringTokenizer(copiedSequences.toString());
1722 Vector seqs = new Vector();
1723 while (st.hasMoreElements())
1725 String name = st.nextToken();
1726 int start = Integer.parseInt(st.nextToken());
1727 int end = Integer.parseInt(st.nextToken());
1728 seqs.addElement(new Sequence(name, st.nextToken(), start, end));
1730 SequenceI[] newSeqs = new SequenceI[seqs.size()];
1731 for (int i = 0; i < seqs.size(); i++)
1733 newSeqs[i] = (SequenceI) seqs.elementAt(i);
1738 String newtitle = new String("Copied sequences");
1739 if (getTitle().startsWith("Copied sequences"))
1741 newtitle = getTitle();
1745 newtitle = newtitle.concat("- from " + getTitle());
1747 AlignFrame af = new AlignFrame(new Alignment(newSeqs),
1748 viewport.applet, newtitle, false);
1749 if (copiedHiddenColumns != null)
1751 for (int i = 0; i < copiedHiddenColumns.size(); i++)
1753 int[] region = (int[]) copiedHiddenColumns.elementAt(i);
1754 af.viewport.hideColumns(region[0], region[1]);
1758 jalview.bin.JalviewLite.addFrame(af, newtitle, DEFAULT_WIDTH,
1763 addSequences(newSeqs);
1766 } catch (Exception ex)
1768 } // could be anything being pasted in here
1772 void addSequences(SequenceI[] seqs)
1774 for (int i = 0; i < seqs.length; i++)
1776 viewport.getAlignment().addSequence(seqs[i]);
1780 addHistoryItem(new EditCommand("Add sequences", EditCommand.PASTE,
1781 seqs, 0, viewport.getAlignment().getWidth(),
1782 viewport.getAlignment()));
1784 viewport.setEndSeq(viewport.getAlignment().getHeight());
1785 viewport.getAlignment().getWidth();
1786 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
1791 protected void cut_actionPerformed()
1793 copy_actionPerformed();
1794 delete_actionPerformed();
1797 protected void delete_actionPerformed()
1800 SequenceGroup sg = viewport.getSelectionGroup();
1806 Vector seqs = new Vector();
1808 for (int i = 0; i < sg.getSize(); i++)
1810 seq = sg.getSequenceAt(i);
1811 seqs.addElement(seq);
1814 // If the cut affects all sequences, remove highlighted columns
1815 if (sg.getSize() == viewport.getAlignment().getHeight())
1817 viewport.getColumnSelection().removeElements(sg.getStartRes(),
1818 sg.getEndRes() + 1);
1821 SequenceI[] cut = new SequenceI[seqs.size()];
1822 for (int i = 0; i < seqs.size(); i++)
1824 cut[i] = (SequenceI) seqs.elementAt(i);
1828 * //ADD HISTORY ITEM
1830 addHistoryItem(new EditCommand("Cut Sequences", EditCommand.CUT, cut,
1831 sg.getStartRes(), sg.getEndRes() - sg.getStartRes() + 1,
1832 viewport.getAlignment()));
1834 viewport.setSelectionGroup(null);
1835 viewport.getAlignment().deleteGroup(sg);
1837 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
1840 if (viewport.getAlignment().getHeight() < 1)
1842 this.setVisible(false);
1844 viewport.sendSelection();
1848 * group consensus toggled
1851 protected void showGroupConsensus_actionPerformed()
1853 viewport.setShowGroupConsensus(showGroupConsensus.getState());
1854 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
1859 * group conservation toggled.
1861 protected void showGroupConservation_actionPerformed()
1863 viewport.setShowGroupConservation(showGroupConservation.getState());
1864 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
1871 * jalview.jbgui.GAlignFrame#showConsensusHistogram_actionPerformed(java.awt
1872 * .event.ActionEvent)
1874 protected void showConsensusHistogram_actionPerformed()
1876 viewport.setShowConsensusHistogram(showConsensusHistogram.getState());
1877 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
1884 * jalview.jbgui.GAlignFrame#showConsensusProfile_actionPerformed(java.awt
1885 * .event.ActionEvent)
1887 protected void showSequenceLogo_actionPerformed()
1889 viewport.setShowSequenceLogo(showSequenceLogo.getState());
1890 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
1893 protected void normSequenceLogo_actionPerformed()
1895 showSequenceLogo.setState(true);
1896 viewport.setShowSequenceLogo(true);
1897 viewport.setNormaliseSequenceLogo(normSequenceLogo.getState());
1898 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
1901 protected void applyAutoAnnotationSettings_actionPerformed()
1903 alignPanel.updateAnnotation(applyAutoAnnotationSettings.getState());
1906 protected void makeGrpsFromSelection_actionPerformed()
1908 if (avc.makeGroupsFromSelection()) {
1909 PaintRefresher.Refresh(this, viewport.getSequenceSetId());
1910 alignPanel.updateAnnotation();
1911 alignPanel.paintAlignment(true);
1915 protected void createGroup_actionPerformed()
1919 protected void unGroup_actionPerformed()
1923 alignPanel.alignmentChanged();
1926 protected void deleteGroups_actionPerformed()
1928 if (avc.deleteGroups())
1930 alignPanel.alignmentChanged();
1934 public void selectAllSequenceMenuItem_actionPerformed()
1936 SequenceGroup sg = new SequenceGroup();
1937 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
1939 sg.addSequence(viewport.getAlignment().getSequenceAt(i), false);
1941 sg.setEndRes(viewport.getAlignment().getWidth() - 1);
1942 viewport.setSelectionGroup(sg);
1943 alignPanel.paintAlignment(true);
1944 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1945 viewport.sendSelection();
1948 public void deselectAllSequenceMenuItem_actionPerformed()
1950 if (viewport.cursorMode)
1952 alignPanel.seqPanel.keyboardNo1 = null;
1953 alignPanel.seqPanel.keyboardNo2 = null;
1955 viewport.setSelectionGroup(null);
1956 viewport.getColumnSelection().clear();
1957 viewport.setSelectionGroup(null);
1958 alignPanel.idPanel.idCanvas.searchResults = null;
1959 alignPanel.seqPanel.seqCanvas.highlightSearchResults(null);
1960 alignPanel.paintAlignment(true);
1961 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1962 viewport.sendSelection();
1965 public void invertSequenceMenuItem_actionPerformed()
1967 SequenceGroup sg = viewport.getSelectionGroup();
1968 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
1970 sg.addOrRemove(viewport.getAlignment().getSequenceAt(i), false);
1973 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1974 viewport.sendSelection();
1977 public void invertColSel_actionPerformed()
1979 viewport.invertColumnSelection();
1980 alignPanel.paintAlignment(true);
1981 PaintRefresher.Refresh(alignPanel, viewport.getSequenceSetId());
1982 viewport.sendSelection();
1985 void trimAlignment(boolean trimLeft)
1987 ColumnSelection colSel = viewport.getColumnSelection();
1990 if (colSel.size() > 0)
1994 column = colSel.getMin();
1998 column = colSel.getMax();
2002 if (viewport.getSelectionGroup() != null)
2004 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2005 viewport.getHiddenRepSequences());
2009 seqs = viewport.getAlignment().getSequencesArray();
2012 TrimRegionCommand trimRegion;
2015 trimRegion = new TrimRegionCommand("Remove Left",
2016 TrimRegionCommand.TRIM_LEFT, seqs, column,
2017 viewport.getAlignment(), viewport.getColumnSelection(),
2018 viewport.getSelectionGroup());
2019 viewport.setStartRes(0);
2023 trimRegion = new TrimRegionCommand("Remove Right",
2024 TrimRegionCommand.TRIM_RIGHT, seqs, column,
2025 viewport.getAlignment(), viewport.getColumnSelection(),
2026 viewport.getSelectionGroup());
2029 statusBar.setText(MessageManager.formatMessage("label.removed_columns", new String[]{Integer.valueOf(trimRegion.getSize()).toString()}));
2030 addHistoryItem(trimRegion);
2032 for (SequenceGroup sg : viewport.getAlignment().getGroups())
2034 if ((trimLeft && !sg.adjustForRemoveLeft(column))
2035 || (!trimLeft && !sg.adjustForRemoveRight(column)))
2037 viewport.getAlignment().deleteGroup(sg);
2041 viewport.firePropertyChange("alignment", null, viewport
2042 .getAlignment().getSequences());
2046 public void removeGappedColumnMenuItem_actionPerformed()
2048 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2051 if (viewport.getSelectionGroup() != null)
2053 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2054 viewport.getHiddenRepSequences());
2055 start = viewport.getSelectionGroup().getStartRes();
2056 end = viewport.getSelectionGroup().getEndRes();
2060 seqs = viewport.getAlignment().getSequencesArray();
2063 RemoveGapColCommand removeGapCols = new RemoveGapColCommand(
2064 "Remove Gapped Columns", seqs, start, end,
2065 viewport.getAlignment());
2067 addHistoryItem(removeGapCols);
2069 statusBar.setText(MessageManager.formatMessage("label.removed_empty_columns", new String[]{Integer.valueOf(removeGapCols.getSize()).toString()}));
2071 // This is to maintain viewport position on first residue
2072 // of first sequence
2073 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2074 int startRes = seq.findPosition(viewport.startRes);
2075 // ShiftList shifts;
2076 // viewport.getAlignment().removeGaps(shifts=new ShiftList());
2077 // edit.alColumnChanges=shifts.getInverse();
2078 // if (viewport.hasHiddenColumns)
2079 // viewport.getColumnSelection().compensateForEdits(shifts);
2080 viewport.setStartRes(seq.findIndex(startRes) - 1);
2081 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2086 public void removeAllGapsMenuItem_actionPerformed()
2088 int start = 0, end = viewport.getAlignment().getWidth() - 1;
2091 if (viewport.getSelectionGroup() != null)
2093 seqs = viewport.getSelectionGroup().getSequencesAsArray(
2094 viewport.getHiddenRepSequences());
2095 start = viewport.getSelectionGroup().getStartRes();
2096 end = viewport.getSelectionGroup().getEndRes();
2100 seqs = viewport.getAlignment().getSequencesArray();
2103 // This is to maintain viewport position on first residue
2104 // of first sequence
2105 SequenceI seq = viewport.getAlignment().getSequenceAt(0);
2106 int startRes = seq.findPosition(viewport.startRes);
2108 addHistoryItem(new RemoveGapsCommand("Remove Gaps", seqs, start, end,
2109 viewport.getAlignment()));
2111 viewport.setStartRes(seq.findIndex(startRes) - 1);
2113 viewport.firePropertyChange("alignment", null, viewport.getAlignment()
2118 public void findMenuItem_actionPerformed()
2120 new Finder(alignPanel);
2124 * create a new view derived from the current view
2127 * @return frame for the new view
2129 public AlignFrame newView(String viewtitle)
2132 if (viewport.hasHiddenRows())
2134 newal = new Alignment(viewport.getAlignment().getHiddenSequences()
2135 .getFullAlignment().getSequencesArray());
2139 newal = new Alignment(viewport.getAlignment().getSequencesArray());
2142 if (viewport.getAlignment().getAlignmentAnnotation() != null)
2144 for (int i = 0; i < viewport.getAlignment().getAlignmentAnnotation().length; i++)
2146 if (!viewport.getAlignment().getAlignmentAnnotation()[i].autoCalculated)
2148 newal.addAnnotation(viewport.getAlignment()
2149 .getAlignmentAnnotation()[i]);
2154 AlignFrame newaf = new AlignFrame(newal, viewport.applet, "", false);
2156 newaf.viewport.setSequenceSetId(alignPanel.av.getSequenceSetId());
2157 PaintRefresher.Register(alignPanel, alignPanel.av.getSequenceSetId());
2158 PaintRefresher.Register(newaf.alignPanel,
2159 newaf.alignPanel.av.getSequenceSetId());
2161 PaintRefresher.Register(newaf.alignPanel.idPanel.idCanvas,
2162 newaf.alignPanel.av.getSequenceSetId());
2163 PaintRefresher.Register(newaf.alignPanel.seqPanel.seqCanvas,
2164 newaf.alignPanel.av.getSequenceSetId());
2166 Vector comps = (Vector) PaintRefresher.components.get(viewport
2167 .getSequenceSetId());
2169 for (int i = 0; i < comps.size(); i++)
2171 if (comps.elementAt(i) instanceof AlignmentPanel)
2177 String title = new String(this.getTitle());
2178 if (viewtitle != null)
2180 title = viewtitle + " ( " + title + ")";
2184 if (title.indexOf("(View") > -1)
2186 title = title.substring(0, title.indexOf("(View"));
2188 title += "(View " + viewSize + ")";
2191 newaf.setTitle(title.toString());
2193 newaf.viewport.historyList = viewport.historyList;
2194 newaf.viewport.redoList = viewport.redoList;
2200 * @return list of feature groups on the view
2202 public String[] getFeatureGroups()
2204 FeatureRenderer fr = null;
2205 if (alignPanel != null
2206 && (fr = alignPanel.getFeatureRenderer()) != null)
2208 return fr.getGroups();
2214 * get sequence feature groups that are hidden or shown
2220 public String[] getFeatureGroupsOfState(boolean visible)
2222 FeatureRenderer fr = null;
2223 if (alignPanel != null
2224 && (fr = alignPanel.getFeatureRenderer()) != null)
2226 return fr.getGroups(visible);
2232 * Change the display state for the given feature groups
2235 * list of group strings
2237 * visible or invisible
2239 public void setFeatureGroupState(String[] groups, boolean state)
2241 FeatureRenderer fr = null;
2242 this.sequenceFeatures.setState(true);
2243 viewport.showSequenceFeatures(true);
2244 if (alignPanel != null
2245 && (fr = alignPanel.getFeatureRenderer()) != null)
2247 fr.setGroupState(groups, state);
2248 alignPanel.seqPanel.seqCanvas.repaint();
2249 if (alignPanel.overviewPanel != null)
2251 alignPanel.overviewPanel.updateOverviewImage();
2256 public void seqLimits_itemStateChanged()
2258 viewport.setShowJVSuffix(seqLimits.getState());
2259 alignPanel.fontChanged();
2260 alignPanel.paintAlignment(true);
2263 protected void colourTextMenuItem_actionPerformed()
2265 viewport.setColourText(colourTextMenuItem.getState());
2266 alignPanel.paintAlignment(true);
2269 protected void displayNonconservedMenuItem_actionPerformed()
2271 viewport.setShowunconserved(displayNonconservedMenuItem.getState());
2272 alignPanel.paintAlignment(true);
2275 protected void wrapMenuItem_actionPerformed()
2277 viewport.setWrapAlignment(wrapMenuItem.getState());
2278 alignPanel.setWrapAlignment(wrapMenuItem.getState());
2279 scaleAbove.setEnabled(wrapMenuItem.getState());
2280 scaleLeft.setEnabled(wrapMenuItem.getState());
2281 scaleRight.setEnabled(wrapMenuItem.getState());
2282 alignPanel.paintAlignment(true);
2285 public void overviewMenuItem_actionPerformed()
2287 if (alignPanel.overviewPanel != null)
2292 Frame frame = new Frame();
2293 OverviewPanel overview = new OverviewPanel(alignPanel);
2294 frame.add(overview);
2295 // +50 must allow for applet frame window
2296 jalview.bin.JalviewLite.addFrame(frame, MessageManager.formatMessage("label.overview_params", new String[]{this.getTitle()}),
2297 overview.getPreferredSize().width,
2298 overview.getPreferredSize().height + 50);
2301 final AlignmentPanel ap = alignPanel;
2302 frame.addWindowListener(new WindowAdapter()
2305 public void windowClosing(WindowEvent e)
2309 ap.setOverviewPanel(null);
2314 alignPanel.setOverviewPanel(overview);
2318 void changeColour(ColourSchemeI cs)
2324 if (viewport.getAbovePIDThreshold())
2326 threshold = SliderPanel.setPIDSliderSource(alignPanel, cs,
2329 cs.setThreshold(threshold, viewport.getIgnoreGapsConsensus());
2331 viewport.setGlobalColourScheme(cs);
2335 cs.setThreshold(0, viewport.getIgnoreGapsConsensus());
2338 if (viewport.getConservationSelected())
2341 Alignment al = (Alignment) viewport.getAlignment();
2342 Conservation c = new Conservation("All",
2343 ResidueProperties.propHash, 3, al.getSequences(), 0,
2347 c.verdict(false, viewport.getConsPercGaps());
2349 cs.setConservation(c);
2351 cs.setConservationInc(SliderPanel.setConservationSlider(alignPanel,
2357 cs.setConservation(null);
2360 cs.setConsensus(viewport.getSequenceConsensusHash());
2363 viewport.setGlobalColourScheme(cs);
2365 if (alignPanel.getOverviewPanel() != null)
2367 alignPanel.getOverviewPanel().updateOverviewImage();
2370 jalview.structure.StructureSelectionManager
2371 .getStructureSelectionManager(viewport.applet)
2372 .sequenceColoursChanged(alignPanel);
2374 alignPanel.paintAlignment(true);
2377 protected void modifyPID_actionPerformed()
2379 if (viewport.getAbovePIDThreshold()
2380 && viewport.getGlobalColourScheme() != null)
2382 SliderPanel.setPIDSliderSource(alignPanel,
2383 viewport.getGlobalColourScheme(), "Background");
2384 SliderPanel.showPIDSlider();
2388 protected void modifyConservation_actionPerformed()
2390 if (viewport.getConservationSelected()
2391 && viewport.getGlobalColourScheme() != null)
2393 SliderPanel.setConservationSlider(alignPanel,
2394 viewport.getGlobalColourScheme(), "Background");
2395 SliderPanel.showConservationSlider();
2399 protected void conservationMenuItem_actionPerformed()
2401 viewport.setConservationSelected(conservationMenuItem.getState());
2403 viewport.setAbovePIDThreshold(false);
2404 abovePIDThreshold.setState(false);
2406 changeColour(viewport.getGlobalColourScheme());
2408 modifyConservation_actionPerformed();
2411 public void abovePIDThreshold_actionPerformed()
2413 viewport.setAbovePIDThreshold(abovePIDThreshold.getState());
2415 conservationMenuItem.setState(false);
2416 viewport.setConservationSelected(false);
2418 changeColour(viewport.getGlobalColourScheme());
2420 modifyPID_actionPerformed();
2423 public void sortPairwiseMenuItem_actionPerformed()
2425 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2426 AlignmentSorter.sortByPID(viewport.getAlignment(), viewport
2427 .getAlignment().getSequenceAt(0), null);
2429 addHistoryItem(new OrderCommand("Pairwise Sort", oldOrder,
2430 viewport.getAlignment()));
2431 alignPanel.paintAlignment(true);
2434 public void sortIDMenuItem_actionPerformed()
2436 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2437 AlignmentSorter.sortByID(viewport.getAlignment());
2438 addHistoryItem(new OrderCommand("ID Sort", oldOrder,
2439 viewport.getAlignment()));
2440 alignPanel.paintAlignment(true);
2443 public void sortLengthMenuItem_actionPerformed()
2445 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2446 AlignmentSorter.sortByLength(viewport.getAlignment());
2447 addHistoryItem(new OrderCommand("Length Sort", oldOrder,
2448 viewport.getAlignment()));
2449 alignPanel.paintAlignment(true);
2452 public void sortGroupMenuItem_actionPerformed()
2454 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2455 AlignmentSorter.sortByGroup(viewport.getAlignment());
2456 addHistoryItem(new OrderCommand("Group Sort", oldOrder,
2457 viewport.getAlignment()));
2458 alignPanel.paintAlignment(true);
2462 public void removeRedundancyMenuItem_actionPerformed()
2464 new RedundancyPanel(alignPanel);
2467 public void pairwiseAlignmentMenuItem_actionPerformed()
2469 if (viewport.getSelectionGroup() != null
2470 && viewport.getSelectionGroup().getSize() > 1)
2472 Frame frame = new Frame();
2473 frame.add(new PairwiseAlignPanel(alignPanel));
2474 jalview.bin.JalviewLite.addFrame(frame, MessageManager.getString("action.pairwise_alignment"), 600,
2479 public void PCAMenuItem_actionPerformed()
2481 // are the sequences aligned?
2482 if (!viewport.getAlignment().isAligned(false))
2485 int Width = viewport.getAlignment().getWidth();
2487 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2489 current = viewport.getAlignment().getSequenceAt(i);
2491 if (current.getLength() < Width)
2493 current.insertCharAt(Width - 1, viewport.getGapCharacter());
2496 alignPanel.paintAlignment(true);
2499 if ((viewport.getSelectionGroup() != null
2500 && viewport.getSelectionGroup().getSize() < 4 && viewport
2501 .getSelectionGroup().getSize() > 0)
2502 || viewport.getAlignment().getHeight() < 4)
2509 new PCAPanel(viewport);
2510 } catch (java.lang.OutOfMemoryError ex)
2516 public void averageDistanceTreeMenuItem_actionPerformed()
2518 NewTreePanel("AV", "PID", "Average distance tree using PID");
2521 public void neighbourTreeMenuItem_actionPerformed()
2523 NewTreePanel("NJ", "PID", "Neighbour joining tree using PID");
2526 protected void njTreeBlosumMenuItem_actionPerformed()
2528 NewTreePanel("NJ", "BL", "Neighbour joining tree using BLOSUM62");
2531 protected void avTreeBlosumMenuItem_actionPerformed()
2533 NewTreePanel("AV", "BL", "Average distance tree using BLOSUM62");
2536 void NewTreePanel(String type, String pwType, String title)
2538 // are the sequences aligned?
2539 if (!viewport.getAlignment().isAligned(false))
2542 int Width = viewport.getAlignment().getWidth();
2544 for (int i = 0; i < viewport.getAlignment().getSequences().size(); i++)
2546 current = viewport.getAlignment().getSequenceAt(i);
2548 if (current.getLength() < Width)
2550 current.insertCharAt(Width - 1, viewport.getGapCharacter());
2553 alignPanel.paintAlignment(true);
2557 if ((viewport.getSelectionGroup() != null && viewport
2558 .getSelectionGroup().getSize() > 1)
2559 || (viewport.getAlignment().getHeight() > 1))
2561 final TreePanel tp = new TreePanel(alignPanel, type, pwType);
2563 addTreeMenuItem(tp, title);
2565 jalview.bin.JalviewLite.addFrame(tp, title, 600, 500);
2569 void loadTree_actionPerformed()
2571 CutAndPasteTransfer cap = new CutAndPasteTransfer(true, this);
2572 cap.setText(MessageManager.getString("label.paste_newick_tree_file"));
2573 cap.setTreeImport();
2574 Frame frame = new Frame();
2576 jalview.bin.JalviewLite.addFrame(frame, MessageManager.getString("label.paste_newick_file"), 400, 300);
2579 public void loadTree(jalview.io.NewickFile tree, String treeFile)
2581 TreePanel tp = new TreePanel(alignPanel, treeFile, MessageManager.getString("label.load_tree_from_file"), tree);
2582 jalview.bin.JalviewLite.addFrame(tp, treeFile, 600, 500);
2583 addTreeMenuItem(tp, treeFile);
2587 * sort the alignment using the given treePanel
2590 * tree used to sort view
2592 * string used for undo event name
2594 public void sortByTree(TreePanel treePanel, String title)
2596 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2598 .sortByTree(viewport.getAlignment(), treePanel.getTree());
2599 // addHistoryItem(new HistoryItem("Sort", viewport.alignment,
2600 // HistoryItem.SORT));
2601 addHistoryItem(new OrderCommand(MessageManager.formatMessage("label.order_by_params", new String[]{title}), oldOrder,
2602 viewport.getAlignment()));
2603 alignPanel.paintAlignment(true);
2607 * Do any automatic reordering of the alignment and add the necessary bits to
2608 * the menu structure for the new tree
2613 protected void addTreeMenuItem(final TreePanel treePanel,
2616 final MenuItem item = new MenuItem(title);
2617 sortByTreeMenu.add(item);
2618 item.addActionListener(new java.awt.event.ActionListener()
2621 public void actionPerformed(ActionEvent evt)
2623 sortByTree(treePanel, title); // treePanel.getTitle());
2627 treePanel.addWindowListener(new WindowAdapter()
2630 public void windowOpened(WindowEvent e)
2632 if (viewport.sortByTree)
2634 sortByTree(treePanel, title);
2636 super.windowOpened(e);
2640 public void windowClosing(WindowEvent e)
2642 sortByTreeMenu.remove(item);
2647 public boolean sortBy(AlignmentOrder alorder, String undoname)
2649 SequenceI[] oldOrder = viewport.getAlignment().getSequencesArray();
2650 if (viewport.applet.debug)
2652 System.err.println("Sorting " + alorder.getOrder().size()
2653 + " in alignment '" + getTitle() + "'");
2655 AlignmentSorter.sortBy(viewport.getAlignment(), alorder);
2656 if (undoname != null)
2658 addHistoryItem(new OrderCommand(undoname, oldOrder,
2659 viewport.getAlignment()));
2661 alignPanel.paintAlignment(true);
2665 protected void documentation_actionPerformed()
2667 alignPanel.av.applet.openJalviewHelpUrl();
2670 protected void about_actionPerformed()
2673 class AboutPanel extends Canvas
2679 public AboutPanel(String version, String builddate)
2681 this.version = version;
2682 this.builddate = builddate;
2686 public void paint(Graphics g)
2688 g.setColor(Color.white);
2689 g.fillRect(0, 0, getSize().width, getSize().height);
2690 g.setFont(new Font("Helvetica", Font.PLAIN, 12));
2691 FontMetrics fm = g.getFontMetrics();
2692 int fh = fm.getHeight();
2694 g.setColor(Color.black);
2695 // TODO: update this text for each release or centrally store it for
2696 // lite and application
2697 g.setFont(new Font("Helvetica", Font.BOLD, 14));
2698 g.drawString(MessageManager.formatMessage("label.jalviewLite_release", new String[]{version}), x, y += fh);
2699 g.setFont(new Font("Helvetica", Font.BOLD, 12));
2700 g.drawString(MessageManager.formatMessage("label.jaview_build_date", new String[]{builddate}), x, y += fh);
2701 g.setFont(new Font("Helvetica", Font.PLAIN, 12));
2703 MessageManager.getString("label.jalview_authors_1"),
2705 g.drawString(MessageManager.getString("label.jalview_authors_2"), x + 50, y += fh+8);
2707 MessageManager.getString("label.jalview_dev_managers"),
2710 MessageManager.getString("label.jalview_distribution_lists"),
2712 g.drawString(MessageManager.getString("label.jalview_please_cite"), x, y += fh + 8);
2714 MessageManager.getString("label.jalview_cite_1_authors"),
2717 MessageManager.getString("label.jalview_cite_1_title"),
2719 g.drawString(MessageManager.getString("label.jalview_cite_1_ref"),
2724 Frame frame = new Frame();
2725 frame.add(new AboutPanel(JalviewLite.getVersion(), JalviewLite
2727 jalview.bin.JalviewLite.addFrame(frame, MessageManager.getString("label.jalview"), 580, 220);
2731 public void showURL(String url, String target)
2733 if (viewport.applet == null)
2735 System.out.println("Not running as applet - no browser available.");
2739 viewport.applet.showURL(url, target);
2743 // ////////////////////////////////////////////////////////////////////////////////
2744 // JBuilder Graphics here
2746 MenuBar alignFrameMenuBar = new MenuBar();
2748 Menu fileMenu = new Menu(MessageManager.getString("action.file"));
2750 MenuItem loadApplication = new MenuItem(MessageManager.getString("label.view_full_application"));
2752 MenuItem loadTree = new MenuItem(MessageManager.getString("label.load_associated_tree"));
2754 MenuItem loadAnnotations = new MenuItem(MessageManager.getString("label.load_features_annotations"));
2756 MenuItem outputFeatures = new MenuItem(MessageManager.getString("label.export_features"));
2758 MenuItem outputAnnotations = new MenuItem(MessageManager.getString("label.export_annotations"));
2760 MenuItem closeMenuItem = new MenuItem(MessageManager.getString("action.close"));
2762 Menu editMenu = new Menu(MessageManager.getString("action.edit"));
2764 Menu viewMenu = new Menu(MessageManager.getString("action.view"));
2766 Menu colourMenu = new Menu(MessageManager.getString("action.colour"));
2768 Menu calculateMenu = new Menu(MessageManager.getString("action.calculate"));
2770 MenuItem selectAllSequenceMenuItem = new MenuItem(MessageManager.getString("action.select_all"));
2772 MenuItem deselectAllSequenceMenuItem = new MenuItem(MessageManager.getString("action.deselect_all"));
2774 MenuItem invertSequenceMenuItem = new MenuItem(MessageManager.getString("action.invert_selection"));
2776 MenuItem remove2LeftMenuItem = new MenuItem();
2778 MenuItem remove2RightMenuItem = new MenuItem();
2780 MenuItem removeGappedColumnMenuItem = new MenuItem();
2782 MenuItem removeAllGapsMenuItem = new MenuItem();
2784 CheckboxMenuItem viewBoxesMenuItem = new CheckboxMenuItem();
2786 CheckboxMenuItem viewTextMenuItem = new CheckboxMenuItem();
2788 MenuItem sortPairwiseMenuItem = new MenuItem();
2790 MenuItem sortIDMenuItem = new MenuItem();
2792 MenuItem sortLengthMenuItem = new MenuItem();
2794 MenuItem sortGroupMenuItem = new MenuItem();
2796 MenuItem removeRedundancyMenuItem = new MenuItem();
2798 MenuItem pairwiseAlignmentMenuItem = new MenuItem();
2800 MenuItem PCAMenuItem = new MenuItem();
2802 MenuItem averageDistanceTreeMenuItem = new MenuItem();
2804 MenuItem neighbourTreeMenuItem = new MenuItem();
2806 BorderLayout borderLayout1 = new BorderLayout();
2808 public Label statusBar = new Label();
2810 Menu outputTextboxMenu = new Menu();
2812 MenuItem clustalColour = new MenuItem();
2814 MenuItem zappoColour = new MenuItem();
2816 MenuItem taylorColour = new MenuItem();
2818 MenuItem hydrophobicityColour = new MenuItem();
2820 MenuItem helixColour = new MenuItem();
2822 MenuItem strandColour = new MenuItem();
2824 MenuItem turnColour = new MenuItem();
2826 MenuItem buriedColour = new MenuItem();
2828 MenuItem purinePyrimidineColour = new MenuItem();
2830 MenuItem RNAHelixColour = new MenuItem();
2832 MenuItem userDefinedColour = new MenuItem();
2834 MenuItem PIDColour = new MenuItem();
2836 MenuItem BLOSUM62Colour = new MenuItem();
2838 MenuItem tcoffeeColour = new MenuItem();
2840 MenuItem njTreeBlosumMenuItem = new MenuItem();
2842 MenuItem avDistanceTreeBlosumMenuItem = new MenuItem();
2844 CheckboxMenuItem annotationPanelMenuItem = new CheckboxMenuItem();
2846 CheckboxMenuItem colourTextMenuItem = new CheckboxMenuItem();
2848 CheckboxMenuItem displayNonconservedMenuItem = new CheckboxMenuItem();
2850 MenuItem alProperties = new MenuItem(MessageManager.getString("label.alignment_props"));
2852 MenuItem overviewMenuItem = new MenuItem();
2854 MenuItem undoMenuItem = new MenuItem();
2856 MenuItem redoMenuItem = new MenuItem();
2858 CheckboxMenuItem conservationMenuItem = new CheckboxMenuItem();
2860 MenuItem noColourmenuItem = new MenuItem();
2862 CheckboxMenuItem wrapMenuItem = new CheckboxMenuItem();
2864 CheckboxMenuItem renderGapsMenuItem = new CheckboxMenuItem();
2866 MenuItem findMenuItem = new MenuItem();
2868 CheckboxMenuItem abovePIDThreshold = new CheckboxMenuItem();
2870 MenuItem nucleotideColour = new MenuItem();
2872 MenuItem deleteGroups = new MenuItem();
2874 MenuItem grpsFromSelection = new MenuItem();
2876 MenuItem createGroup = new MenuItem();
2878 MenuItem unGroup = new MenuItem();
2880 MenuItem delete = new MenuItem();
2882 MenuItem copy = new MenuItem();
2884 MenuItem cut = new MenuItem();
2886 Menu pasteMenu = new Menu();
2888 MenuItem pasteNew = new MenuItem();
2890 MenuItem pasteThis = new MenuItem();
2892 CheckboxMenuItem applyToAllGroups = new CheckboxMenuItem();
2894 MenuItem font = new MenuItem();
2896 CheckboxMenuItem scaleAbove = new CheckboxMenuItem();
2898 CheckboxMenuItem scaleLeft = new CheckboxMenuItem();
2900 CheckboxMenuItem scaleRight = new CheckboxMenuItem();
2902 MenuItem modifyPID = new MenuItem();
2904 MenuItem modifyConservation = new MenuItem();
2906 CheckboxMenuItem autoCalculate = new CheckboxMenuItem(
2907 "Autocalculate Consensus", true);
2909 CheckboxMenuItem sortByTree = new CheckboxMenuItem(
2910 "Sort Alignment With New Tree", true);
2912 Menu sortByTreeMenu = new Menu();
2914 Menu sort = new Menu();
2916 Menu calculate = new Menu();
2918 MenuItem inputText = new MenuItem();
2920 Menu helpMenu = new Menu();
2922 MenuItem documentation = new MenuItem();
2924 MenuItem about = new MenuItem();
2926 CheckboxMenuItem seqLimits = new CheckboxMenuItem();
2928 CheckboxMenuItem centreColumnLabelFlag = new CheckboxMenuItem();
2930 CheckboxMenuItem followMouseOverFlag = new CheckboxMenuItem();
2932 Menu autoAnnMenu = new Menu();
2934 CheckboxMenuItem showSequenceLogo = new CheckboxMenuItem();
2936 CheckboxMenuItem applyAutoAnnotationSettings = new CheckboxMenuItem();
2938 CheckboxMenuItem showConsensusHistogram = new CheckboxMenuItem();
2940 CheckboxMenuItem showGroupConsensus = new CheckboxMenuItem();
2942 CheckboxMenuItem showGroupConservation = new CheckboxMenuItem();
2944 CheckboxMenuItem normSequenceLogo = new CheckboxMenuItem();
2946 private void jbInit() throws Exception
2949 setMenuBar(alignFrameMenuBar);
2953 // dynamically fill save as menu with available formats
2954 for (int i = 0; i < jalview.io.AppletFormatAdapter.WRITEABLE_FORMATS.length; i++)
2957 item = new MenuItem(
2958 jalview.io.AppletFormatAdapter.WRITEABLE_FORMATS[i]);
2960 item.addActionListener(new java.awt.event.ActionListener()
2963 public void actionPerformed(ActionEvent e)
2965 outputText_actionPerformed(e);
2969 outputTextboxMenu.add(item);
2971 closeMenuItem.addActionListener(this);
2972 loadApplication.addActionListener(this);
2974 loadTree.addActionListener(this);
2975 loadAnnotations.addActionListener(this);
2976 outputFeatures.addActionListener(this);
2977 outputAnnotations.addActionListener(this);
2978 selectAllSequenceMenuItem.addActionListener(this);
2979 deselectAllSequenceMenuItem.addActionListener(this);
2980 invertSequenceMenuItem.addActionListener(this);
2981 remove2LeftMenuItem.setLabel(MessageManager.getString("action.remove_left"));
2982 remove2LeftMenuItem.addActionListener(this);
2983 remove2RightMenuItem.setLabel(MessageManager.getString("action.remove_right"));
2984 remove2RightMenuItem.addActionListener(this);
2985 removeGappedColumnMenuItem.setLabel(MessageManager.getString("action.remove_empty_columns"));
2986 removeGappedColumnMenuItem.addActionListener(this);
2987 removeAllGapsMenuItem.setLabel(MessageManager.getString("action.remove_all_gaps"));
2988 removeAllGapsMenuItem.addActionListener(this);
2989 viewBoxesMenuItem.setLabel(MessageManager.getString("action.boxes"));
2990 viewBoxesMenuItem.setState(true);
2991 viewBoxesMenuItem.addItemListener(this);
2992 viewTextMenuItem.setLabel(MessageManager.getString("action.text"));
2993 viewTextMenuItem.setState(true);
2994 viewTextMenuItem.addItemListener(this);
2995 sortPairwiseMenuItem.setLabel(MessageManager.getString("action.by_pairwise_id"));
2996 sortPairwiseMenuItem.addActionListener(this);
2997 sortIDMenuItem.setLabel(MessageManager.getString("action.by_id"));
2998 sortIDMenuItem.addActionListener(this);
2999 sortLengthMenuItem.setLabel(MessageManager.getString("action.by_length"));
3000 sortLengthMenuItem.addActionListener(this);
3001 sortGroupMenuItem.setLabel(MessageManager.getString("action.by_group"));
3002 sortGroupMenuItem.addActionListener(this);
3003 removeRedundancyMenuItem.setLabel(MessageManager.getString("action.remove_redundancy"));
3004 removeRedundancyMenuItem.addActionListener(this);
3005 pairwiseAlignmentMenuItem.setLabel(MessageManager.getString("action.pairwise_alignment"));
3006 pairwiseAlignmentMenuItem.addActionListener(this);
3007 PCAMenuItem.setLabel(MessageManager.getString("label.principal_component_analysis"));
3008 PCAMenuItem.addActionListener(this);
3009 averageDistanceTreeMenuItem
3010 .setLabel(MessageManager.getString("label.average_distance_identity"));
3011 averageDistanceTreeMenuItem.addActionListener(this);
3012 neighbourTreeMenuItem.setLabel(MessageManager.getString("label.neighbour_joining_identity"));
3013 neighbourTreeMenuItem.addActionListener(this);
3014 statusBar.setBackground(Color.white);
3015 statusBar.setFont(new java.awt.Font("Verdana", 0, 11));
3016 statusBar.setText(MessageManager.getString("label.status_bar"));
3017 outputTextboxMenu.setLabel(MessageManager.getString("label.out_to_textbox"));
3018 clustalColour.setLabel(MessageManager.getString("label.clustalx"));
3020 clustalColour.addActionListener(this);
3021 zappoColour.setLabel(MessageManager.getString("label.zappo"));
3022 zappoColour.addActionListener(this);
3023 taylorColour.setLabel(MessageManager.getString("label.taylor"));
3024 taylorColour.addActionListener(this);
3025 hydrophobicityColour.setLabel(MessageManager.getString("label.hydrophobicity"));
3026 hydrophobicityColour.addActionListener(this);
3027 helixColour.setLabel(MessageManager.getString("label.helix_propensity"));
3028 helixColour.addActionListener(this);
3029 strandColour.setLabel(MessageManager.getString("label.strand_propensity"));
3030 strandColour.addActionListener(this);
3031 turnColour.setLabel(MessageManager.getString("label.turn_propensity"));
3032 turnColour.addActionListener(this);
3033 buriedColour.setLabel(MessageManager.getString("label.buried_index"));
3034 buriedColour.addActionListener(this);
3035 purinePyrimidineColour.setLabel(MessageManager.getString("label.purine_pyrimidine"));
3036 purinePyrimidineColour.addActionListener(this);
3037 RNAHelixColour.setLabel(MessageManager.getString("action.by_rna_helixes"));
3038 RNAHelixColour.addActionListener(this);
3039 userDefinedColour.setLabel(MessageManager.getString("action.user_defined"));
3040 userDefinedColour.addActionListener(this);
3041 PIDColour.setLabel(MessageManager.getString("label.percentage_identity"));
3042 PIDColour.addActionListener(this);
3043 BLOSUM62Colour.setLabel(MessageManager.getString("label.blosum62_score"));
3044 BLOSUM62Colour.addActionListener(this);
3045 tcoffeeColour.setLabel(MessageManager.getString("label.tcoffee_scores"));
3046 tcoffeeColour.setEnabled(false); // it will enabled only if a score file is
3048 tcoffeeColour.addActionListener(this);
3049 avDistanceTreeBlosumMenuItem
3050 .setLabel(MessageManager.getString("label.average_distance_bloslum62"));
3051 avDistanceTreeBlosumMenuItem.addActionListener(this);
3052 njTreeBlosumMenuItem.setLabel(MessageManager.getString("label.neighbour_blosum62"));
3053 njTreeBlosumMenuItem.addActionListener(this);
3054 annotationPanelMenuItem.setLabel(MessageManager.getString("label.show_annotations"));
3055 annotationPanelMenuItem.addItemListener(this);
3056 colourTextMenuItem.setLabel(MessageManager.getString("label.colour_text"));
3057 colourTextMenuItem.addItemListener(this);
3058 displayNonconservedMenuItem.setLabel(MessageManager.getString("label.show_non_conversed"));
3059 displayNonconservedMenuItem.addItemListener(this);
3060 alProperties.addActionListener(this);
3061 overviewMenuItem.setLabel(MessageManager.getString("label.overview_window"));
3062 overviewMenuItem.addActionListener(this);
3063 undoMenuItem.setEnabled(false);
3064 undoMenuItem.setLabel(MessageManager.getString("action.undo"));
3065 undoMenuItem.addActionListener(this);
3066 redoMenuItem.setEnabled(false);
3067 redoMenuItem.setLabel(MessageManager.getString("action.redo"));
3068 redoMenuItem.addActionListener(this);
3069 conservationMenuItem.setLabel(MessageManager.getString("action.by_conservation"));
3070 conservationMenuItem.addItemListener(this);
3071 noColourmenuItem.setLabel(MessageManager.getString("label.none"));
3072 noColourmenuItem.addActionListener(this);
3073 wrapMenuItem.setLabel(MessageManager.getString("action.wrap"));
3074 wrapMenuItem.addItemListener(this);
3075 renderGapsMenuItem.setLabel(MessageManager.getString("action.show_gaps"));
3076 renderGapsMenuItem.setState(true);
3077 renderGapsMenuItem.addItemListener(this);
3078 findMenuItem.setLabel(MessageManager.getString("action.find"));
3079 findMenuItem.addActionListener(this);
3080 abovePIDThreshold.setLabel(MessageManager.getString("label.above_identity_threshold"));
3081 abovePIDThreshold.addItemListener(this);
3082 nucleotideColour.setLabel(MessageManager.getString("label.nucleotide"));
3083 nucleotideColour.addActionListener(this);
3084 deleteGroups.setLabel(MessageManager.getString("action.undefine_groups"));
3085 deleteGroups.addActionListener(this);
3086 grpsFromSelection.setLabel(MessageManager.getString("action.make_groups_selection"));
3087 grpsFromSelection.addActionListener(this);
3088 createGroup.setLabel(MessageManager.getString("action.create_group"));
3089 unGroup.setLabel(MessageManager.getString("action.remove_group"));
3090 copy.setLabel(MessageManager.getString("action.copy"));
3091 copy.addActionListener(this);
3092 cut.setLabel(MessageManager.getString("action.cut"));
3093 cut.addActionListener(this);
3094 delete.setLabel(MessageManager.getString("action.delete"));
3095 delete.addActionListener(this);
3096 pasteMenu.setLabel(MessageManager.getString("action.paste"));
3097 pasteNew.setLabel(MessageManager.getString("label.to_new_alignment"));
3098 pasteNew.addActionListener(this);
3099 pasteThis.setLabel(MessageManager.getString("label.to_this_alignment"));
3100 pasteThis.addActionListener(this);
3101 applyToAllGroups.setLabel(MessageManager.getString("label.apply_colour_to_all_groups"));
3102 applyToAllGroups.setState(true);
3103 applyToAllGroups.addItemListener(this);
3104 font.setLabel(MessageManager.getString("action.font"));
3105 font.addActionListener(this);
3106 scaleAbove.setLabel(MessageManager.getString("action.scale_above"));
3107 scaleAbove.setState(true);
3108 scaleAbove.setEnabled(false);
3109 scaleAbove.addItemListener(this);
3110 scaleLeft.setEnabled(false);
3111 scaleLeft.setState(true);
3112 scaleLeft.setLabel(MessageManager.getString("action.scale_left"));
3113 scaleLeft.addItemListener(this);
3114 scaleRight.setEnabled(false);
3115 scaleRight.setState(true);
3116 scaleRight.setLabel(MessageManager.getString("action.scale_right"));
3117 scaleRight.addItemListener(this);
3118 modifyPID.setLabel(MessageManager.getString("label.modify_identity_thereshold"));
3119 modifyPID.addActionListener(this);
3120 modifyConservation.setLabel(MessageManager.getString("label.modify_conservation_thereshold"));
3121 modifyConservation.addActionListener(this);
3122 sortByTreeMenu.setLabel(MessageManager.getString("action.by_tree_order"));
3123 sort.setLabel(MessageManager.getString("action.sort"));
3124 calculate.setLabel(MessageManager.getString("action.calculate_tree"));
3125 autoCalculate.addItemListener(this);
3126 sortByTree.addItemListener(this);
3127 inputText.setLabel(MessageManager.getString("label.input_from_textbox"));
3128 inputText.addActionListener(this);
3129 centreColumnLabelFlag.setLabel(MessageManager.getString("label.centre_column_labels"));
3130 centreColumnLabelFlag.addItemListener(this);
3131 followMouseOverFlag.setLabel(MessageManager.getString("label.automatic_scrolling"));
3132 followMouseOverFlag.addItemListener(this);
3133 helpMenu.setLabel(MessageManager.getString("action.help"));
3134 documentation.setLabel(MessageManager.getString("label.documentation"));
3135 documentation.addActionListener(this);
3137 about.setLabel(MessageManager.getString("label.about"));
3138 about.addActionListener(this);
3139 seqLimits.setState(true);
3140 seqLimits.setLabel(MessageManager.getString("label.show_sequence_limits"));
3141 seqLimits.addItemListener(this);
3142 featureSettings.setLabel(MessageManager.getString("label.feature_settings"));
3143 featureSettings.addActionListener(this);
3144 sequenceFeatures.setLabel(MessageManager.getString("label.sequence_features"));
3145 sequenceFeatures.addItemListener(this);
3146 sequenceFeatures.setState(false);
3147 annotationColour.setLabel(MessageManager.getString("action.by_annotation"));
3148 annotationColour.addActionListener(this);
3149 invertSequenceMenuItem.setLabel(MessageManager.getString("action.invert_sequence_selection"));
3150 invertColSel.setLabel(MessageManager.getString("action.invert_column_selection"));
3151 menu1.setLabel(MessageManager.getString("action.show"));
3152 showColumns.setLabel(MessageManager.getString("label.all_columns"));
3153 showSeqs.setLabel(MessageManager.getString("label.all_sequences"));
3154 menu2.setLabel(MessageManager.getString("aciton.hide"));
3155 hideColumns.setLabel(MessageManager.getString("label.selected_columns"));
3156 hideSequences.setLabel(MessageManager.getString("label.selected_sequences"));
3157 hideAllButSelection.setLabel(MessageManager.getString("label.all_but_selected_region"));
3158 hideAllSelection.setLabel(MessageManager.getString("label.selected_region"));
3159 showAllHidden.setLabel(MessageManager.getString("label.all_sequences_columns"));
3160 showGroupConsensus.setLabel(MessageManager.getString("label.group_consensus"));
3161 showGroupConservation.setLabel(MessageManager.getString("label.group_conservation"));
3162 showConsensusHistogram.setLabel(MessageManager.getString("label.show_consensus_histogram"));
3163 showSequenceLogo.setLabel(MessageManager.getString("label.show_consensus_logo"));
3164 normSequenceLogo.setLabel(MessageManager.getString("label.norm_consensus_logo"));
3165 applyAutoAnnotationSettings.setLabel(MessageManager.getString("label.apply_all_groups"));
3166 applyAutoAnnotationSettings.setState(true);
3167 autoAnnMenu.setLabel(MessageManager.getString("label.autocalculated_annotation"));
3169 invertColSel.addActionListener(this);
3170 showColumns.addActionListener(this);
3171 showSeqs.addActionListener(this);
3172 hideColumns.addActionListener(this);
3173 hideSequences.addActionListener(this);
3174 hideAllButSelection.addActionListener(this);
3175 hideAllSelection.addActionListener(this);
3176 showAllHidden.addActionListener(this);
3177 showGroupConsensus.addItemListener(this);
3178 showGroupConservation.addItemListener(this);
3179 showConsensusHistogram.addItemListener(this);
3180 showSequenceLogo.addItemListener(this);
3181 normSequenceLogo.addItemListener(this);
3183 applyAutoAnnotationSettings.addItemListener(this);
3184 formatMenu.setLabel(MessageManager.getString("action.format"));
3185 selectMenu.setLabel(MessageManager.getString("action.select"));
3186 newView.setLabel(MessageManager.getString("action.new_view"));
3187 newView.addActionListener(this);
3188 alignFrameMenuBar.add(fileMenu);
3189 alignFrameMenuBar.add(editMenu);
3190 alignFrameMenuBar.add(selectMenu);
3191 alignFrameMenuBar.add(viewMenu);
3192 alignFrameMenuBar.add(formatMenu);
3193 alignFrameMenuBar.add(colourMenu);
3194 alignFrameMenuBar.add(calculateMenu);
3195 alignFrameMenuBar.add(helpMenu);
3197 fileMenu.add(inputText);
3198 fileMenu.add(loadTree);
3199 fileMenu.add(loadAnnotations);
3201 fileMenu.addSeparator();
3202 fileMenu.add(outputTextboxMenu);
3203 fileMenu.add(outputFeatures);
3204 fileMenu.add(outputAnnotations);
3206 if (jalviewServletURL != null)
3208 fileMenu.add(loadApplication);
3211 fileMenu.addSeparator();
3212 fileMenu.add(closeMenuItem);
3214 editMenu.add(undoMenuItem);
3215 editMenu.add(redoMenuItem);
3218 editMenu.add(pasteMenu);
3219 editMenu.add(delete);
3220 editMenu.addSeparator();
3221 editMenu.add(remove2LeftMenuItem);
3222 editMenu.add(remove2RightMenuItem);
3223 editMenu.add(removeGappedColumnMenuItem);
3224 editMenu.add(removeAllGapsMenuItem);
3225 editMenu.add(removeRedundancyMenuItem);
3226 viewMenu.add(newView);
3227 viewMenu.addSeparator();
3228 viewMenu.add(menu1);
3229 viewMenu.add(menu2);
3230 viewMenu.addSeparator();
3231 viewMenu.add(followMouseOverFlag);
3232 viewMenu.add(annotationPanelMenuItem);
3233 autoAnnMenu.add(applyAutoAnnotationSettings);
3234 autoAnnMenu.add(showConsensusHistogram);
3235 autoAnnMenu.add(showSequenceLogo);
3236 autoAnnMenu.add(normSequenceLogo);
3237 autoAnnMenu.addSeparator();
3238 autoAnnMenu.add(showGroupConservation);
3239 autoAnnMenu.add(showGroupConsensus);
3240 viewMenu.add(autoAnnMenu);
3241 viewMenu.addSeparator();
3242 viewMenu.add(sequenceFeatures);
3243 viewMenu.add(featureSettings);
3244 viewMenu.addSeparator();
3245 viewMenu.add(alProperties);
3246 viewMenu.addSeparator();
3247 viewMenu.add(overviewMenuItem);
3248 colourMenu.add(applyToAllGroups);
3249 colourMenu.addSeparator();
3250 colourMenu.add(noColourmenuItem);
3251 colourMenu.add(clustalColour);
3252 colourMenu.add(BLOSUM62Colour);
3253 colourMenu.add(PIDColour);
3254 colourMenu.add(zappoColour);
3255 colourMenu.add(taylorColour);
3256 colourMenu.add(hydrophobicityColour);
3257 colourMenu.add(helixColour);
3258 colourMenu.add(strandColour);
3259 colourMenu.add(turnColour);
3260 colourMenu.add(buriedColour);
3261 colourMenu.add(nucleotideColour);
3262 colourMenu.add(purinePyrimidineColour);
3263 colourMenu.add(tcoffeeColour);
3264 colourMenu.add(userDefinedColour);
3265 colourMenu.addSeparator();
3266 colourMenu.add(conservationMenuItem);
3267 colourMenu.add(modifyConservation);
3268 colourMenu.add(abovePIDThreshold);
3269 colourMenu.add(modifyPID);
3270 colourMenu.add(annotationColour);
3271 colourMenu.add(RNAHelixColour);
3272 calculateMenu.add(sort);
3273 calculateMenu.add(calculate);
3274 calculateMenu.addSeparator();
3275 calculateMenu.add(pairwiseAlignmentMenuItem);
3276 calculateMenu.add(PCAMenuItem);
3277 calculateMenu.add(autoCalculate);
3278 calculateMenu.add(sortByTree);
3279 this.add(statusBar, BorderLayout.SOUTH);
3280 pasteMenu.add(pasteNew);
3281 pasteMenu.add(pasteThis);
3282 sort.add(sortIDMenuItem);
3283 sort.add(sortLengthMenuItem);
3284 sort.add(sortByTreeMenu);
3285 sort.add(sortGroupMenuItem);
3286 sort.add(sortPairwiseMenuItem);
3287 calculate.add(averageDistanceTreeMenuItem);
3288 calculate.add(neighbourTreeMenuItem);
3289 calculate.add(avDistanceTreeBlosumMenuItem);
3290 calculate.add(njTreeBlosumMenuItem);
3291 helpMenu.add(documentation);
3292 helpMenu.add(about);
3293 menu1.add(showColumns);
3294 menu1.add(showSeqs);
3295 menu1.add(showAllHidden);
3296 menu2.add(hideColumns);
3297 menu2.add(hideSequences);
3298 menu2.add(hideAllSelection);
3299 menu2.add(hideAllButSelection);
3300 formatMenu.add(font);
3301 formatMenu.add(seqLimits);
3302 formatMenu.add(wrapMenuItem);
3303 formatMenu.add(scaleAbove);
3304 formatMenu.add(scaleLeft);
3305 formatMenu.add(scaleRight);
3306 formatMenu.add(viewBoxesMenuItem);
3307 formatMenu.add(viewTextMenuItem);
3308 formatMenu.add(colourTextMenuItem);
3309 formatMenu.add(displayNonconservedMenuItem);
3310 formatMenu.add(renderGapsMenuItem);
3311 formatMenu.add(centreColumnLabelFlag);
3312 selectMenu.add(findMenuItem);
3313 selectMenu.addSeparator();
3314 selectMenu.add(selectAllSequenceMenuItem);
3315 selectMenu.add(deselectAllSequenceMenuItem);
3316 selectMenu.add(invertSequenceMenuItem);
3317 selectMenu.add(invertColSel);
3318 selectMenu.add(createGroup);
3319 selectMenu.add(unGroup);
3320 selectMenu.add(grpsFromSelection);
3321 selectMenu.add(deleteGroups);
3326 public void setStatus(String string) {
3327 statusBar.setText(string);
3330 MenuItem featureSettings = new MenuItem();
3332 CheckboxMenuItem sequenceFeatures = new CheckboxMenuItem();
3334 MenuItem annotationColour = new MenuItem();
3336 MenuItem invertColSel = new MenuItem();
3338 Menu menu1 = new Menu();
3340 MenuItem showColumns = new MenuItem();
3342 MenuItem showSeqs = new MenuItem();
3344 Menu menu2 = new Menu();
3346 MenuItem hideColumns = new MenuItem();
3348 MenuItem hideSequences = new MenuItem();
3350 MenuItem hideAllButSelection = new MenuItem();
3352 MenuItem hideAllSelection = new MenuItem();
3354 MenuItem showAllHidden = new MenuItem();
3356 Menu formatMenu = new Menu();
3358 Menu selectMenu = new Menu();
3360 MenuItem newView = new MenuItem();
3363 * Attach the alignFrame panels after embedding menus, if necessary. This used
3364 * to be called setEmbedded, but is now creates the dropdown menus in a
3365 * platform independent manner to avoid OSX/Mac menu appendage daftness.
3367 * @param reallyEmbedded
3368 * true to attach the view to the applet area on the page rather than
3371 public void createAlignFrameWindow(boolean reallyEmbedded, String title)
3376 // Explicly build the embedded menu panel for the on-page applet
3378 // view cannot be closed if its actually on the page
3379 fileMenu.remove(closeMenuItem);
3380 fileMenu.remove(3); // Remove Seperator
3381 embeddedMenu = makeEmbeddedPopupMenu(alignFrameMenuBar, "Arial",
3382 Font.PLAIN, 10, false); // use our own fonts.
3383 // and actually add the components to the applet area
3384 viewport.applet.setLayout(new BorderLayout());
3385 viewport.applet.add(embeddedMenu, BorderLayout.NORTH);
3386 viewport.applet.add(statusBar, BorderLayout.SOUTH);
3387 alignPanel.setSize(viewport.applet.getSize().width,
3388 viewport.applet.getSize().height - embeddedMenu.HEIGHT
3389 - statusBar.HEIGHT);
3390 viewport.applet.add(alignPanel, BorderLayout.CENTER);
3391 final AlignFrame me = this;
3392 viewport.applet.addFocusListener(new FocusListener()
3396 public void focusLost(FocusEvent e)
3398 if (me.viewport.applet.currentAlignFrame == me)
3400 me.viewport.applet.currentAlignFrame = null;
3405 public void focusGained(FocusEvent e)
3407 me.viewport.applet.currentAlignFrame = me;
3410 viewport.applet.validate();
3415 // test and embed menu bar if necessary.
3417 if (embedMenuIfNeeded(alignPanel))
3419 // adjust for status bar height too
3420 alignPanel.setSize(getSize().width, getSize().height
3421 - statusBar.HEIGHT);
3423 add(statusBar, BorderLayout.SOUTH);
3424 add(alignPanel, BorderLayout.CENTER);
3425 // and register with the applet so it can pass external API calls to us
3426 jalview.bin.JalviewLite.addFrame(this, title, DEFAULT_WIDTH,
3432 * create a new binding between structures in an existing jmol viewer instance
3433 * and an alignpanel with sequences that have existing PDBFile entries. Note,
3434 * this does not open a new Jmol window, or modify the display of the
3435 * structures in the original jmol window. Note This method doesn't work
3436 * without an additional javascript library to exchange messages between the
3437 * distinct applets. See http://issues.jalview.org/browse/JAL-621
3440 * JmolViewer instance
3441 * @param sequenceIds
3442 * - sequence Ids to search for associations
3444 public SequenceStructureBinding addStructureViewInstance(
3445 Object jmolviewer, String[] sequenceIds)
3447 org.jmol.api.JmolViewer viewer = null;
3450 viewer = (org.jmol.api.JmolViewer) jmolviewer;
3451 } catch (ClassCastException ex)
3453 System.err.println("Unsupported viewer object :"
3454 + jmolviewer.getClass());
3458 System.err.println("Can't use this object as a structure viewer:"
3459 + jmolviewer.getClass());
3462 SequenceI[] seqs = null;
3463 if (sequenceIds == null || sequenceIds.length == 0)
3465 seqs = viewport.getAlignment().getSequencesArray();
3469 Vector sqi = new Vector();
3470 AlignmentI al = viewport.getAlignment();
3471 for (int sid = 0; sid < sequenceIds.length; sid++)
3473 SequenceI sq = al.findName(sequenceIds[sid]);
3481 seqs = new SequenceI[sqi.size()];
3482 for (int sid = 0, sSize = sqi.size(); sid < sSize; sid++)
3484 seqs[sid] = (SequenceI) sqi.elementAt(sid);
3493 // TODO: search for a jmv that involves viewer
3495 { // create a new viewer/jalview binding.
3496 jmv = new ExtJmol(viewer, alignPanel, new SequenceI[][]
3504 * bind a pdb file to a sequence in the current view
3507 * - sequenceId within the dataset.
3508 * @param pdbEntryString
3509 * - the short name for the PDB file
3511 * - pdb file - either a URL or a valid PDB file.
3512 * @return true if binding was as success TODO: consider making an exception
3513 * structure for indicating when PDB parsing or sequenceId location
3516 public boolean addPdbFile(String sequenceId, String pdbEntryString,
3519 SequenceI toaddpdb = viewport.getAlignment().findName(sequenceId);
3520 boolean needtoadd = false;
3521 if (toaddpdb != null)
3523 Vector pdbe = toaddpdb.getPDBId();
3524 PDBEntry pdbentry = null;
3525 if (pdbe != null && pdbe.size() > 0)
3527 for (int pe = 0, peSize = pdbe.size(); pe < peSize; pe++)
3529 pdbentry = (PDBEntry) pdbe.elementAt(pe);
3530 if (!pdbentry.getId().equals(pdbEntryString)
3531 && !pdbentry.getFile().equals(pdbFile))
3541 if (pdbentry == null)
3543 pdbentry = new PDBEntry();
3544 pdbentry.setId(pdbEntryString);
3545 pdbentry.setFile(pdbFile);
3546 needtoadd = true; // add this new entry to sequence.
3548 // resolve data source
3549 // TODO: this code should be a refactored to an io package
3550 String protocol = AppletFormatAdapter.resolveProtocol(pdbFile, "PDB");
3551 if (protocol == null)
3557 // make a note of the access mode and add
3558 if (pdbentry.getProperty() == null)
3560 pdbentry.setProperty(new Hashtable());
3562 pdbentry.getProperty().put("protocol", protocol);
3563 toaddpdb.addPDBId(pdbentry);
3569 private Object[] cleanSeqChainArrays(SequenceI[] seqs, String[] chains)
3573 Vector sequences = new Vector();
3574 for (int i = 0; i < seqs.length; i++)
3576 if (seqs[i] != null)
3578 sequences.addElement(new Object[]
3579 { seqs[i], (chains != null) ? chains[i] : null });
3582 seqs = new SequenceI[sequences.size()];
3583 chains = new String[sequences.size()];
3584 for (int i = 0, isize = sequences.size(); i < isize; i++)
3586 Object[] oj = (Object[]) sequences.elementAt(i);
3588 seqs[i] = (SequenceI) oj[0];
3589 chains[i] = (String) oj[1];
3597 public void newStructureView(JalviewLite applet, PDBEntry pdb,
3598 SequenceI[] seqs, String[] chains, String protocol)
3600 // Scrub any null sequences from the array
3601 Object[] sqch = cleanSeqChainArrays(seqs, chains);
3602 seqs = (SequenceI[]) sqch[0];
3603 chains = (String[]) sqch[1];
3604 if (seqs == null || seqs.length == 0)
3607 .println("JalviewLite.AlignFrame:newStructureView: No sequence to bind structure to.");
3609 if (protocol == null || protocol.trim().length() == 0
3610 || protocol.equals("null"))
3612 protocol = (String) pdb.getProperty().get("protocol");
3613 if (protocol == null)
3615 System.err.println("Couldn't work out protocol to open structure: "
3620 if (applet.useXtrnalSviewer)
3622 // register the association(s) and quit, don't create any windows.
3623 if (StructureSelectionManager.getStructureSelectionManager(applet)
3624 .setMapping(seqs, chains, pdb.getFile(), protocol) == null)
3626 System.err.println("Failed to map " + pdb.getFile() + " ("
3627 + protocol + ") to any sequences");
3631 if (applet.isAlignPdbStructures() && applet.jmolAvailable)
3633 // can only do alignments with Jmol
3634 // find the last jmol window assigned to this alignment
3635 jalview.appletgui.AppletJmol ajm = null, tajm;
3636 Vector jmols = applet
3637 .getAppletWindow(jalview.appletgui.AppletJmol.class);
3638 for (int i = 0, iSize = jmols.size(); i < iSize; i++)
3640 tajm = (jalview.appletgui.AppletJmol) jmols.elementAt(i);
3641 if (tajm.ap.alignFrame == this)
3650 .println("Incremental adding and aligning structure to existing Jmol view not yet implemented.");
3651 // try and add the pdb structure
3656 // otherwise, create a new window
3657 if (applet.jmolAvailable)
3659 new jalview.appletgui.AppletJmol(pdb, seqs, chains, alignPanel,
3661 applet.lastFrameX += 40;
3662 applet.lastFrameY += 40;
3666 new MCview.AppletPDBViewer(pdb, seqs, chains, alignPanel, protocol);
3671 public void alignedStructureView(JalviewLite applet, PDBEntry[] pdb,
3672 SequenceI[][] seqs, String[][] chains, String[] protocols)
3674 // TODO Auto-generated method stub
3675 System.err.println("Aligned Structure View: Not yet implemented.");
3679 * modify the current selection, providing the user has not made a selection
3683 * - sequences from this alignment
3685 * - columns to be selected on the alignment
3687 public void select(SequenceGroup sel, ColumnSelection csel)
3689 alignPanel.seqPanel.selection(sel, csel, null);
3692 public void scrollTo(int row, int column)
3694 alignPanel.seqPanel.scrollTo(row, column);
3697 public void scrollToRow(int row)
3699 alignPanel.seqPanel.scrollToRow(row);
3702 public void scrollToColumn(int column)
3704 alignPanel.seqPanel.scrollToColumn(column);
3708 * @return the alignments unique ID.
3710 public String getSequenceSetId()
3712 return viewport.getSequenceSetId();
3716 * Load the (T-Coffee) score file from the specified url
3719 * File/URL/T-COFFEE score file contents
3720 * @throws IOException
3721 * @return true if alignment was annotated with data from source
3723 public boolean loadScoreFile(String source) throws IOException
3726 TCoffeeScoreFile file = new TCoffeeScoreFile(source,
3727 AppletFormatAdapter.checkProtocol(source));
3728 if (!file.isValid())
3730 // TODO: raise dialog for gui
3731 System.err.println("Problems parsing T-Coffee scores: "
3732 + file.getWarningMessage());
3733 System.err.println("Origin was:\n" + source);
3738 * check that the score matrix matches the alignment dimensions
3741 if ((aln = viewport.getAlignment()) != null
3742 && (aln.getHeight() != file.getHeight() || aln.getWidth() != file
3745 // TODO: raise a dialog box here rather than bomb out.
3747 .println("The scores matrix does not match the alignment dimensions");
3751 // TODO add parameter to indicate if matching should be done
3752 if (file.annotateAlignment(alignPanel.getAlignment(), false))
3754 alignPanel.fontChanged();
3755 tcoffeeColour.setEnabled(true);
3756 // switch to this color
3757 changeColour(new TCoffeeColourScheme(alignPanel.getAlignment()));
3762 System.err.println("Problems resolving T-Coffee scores:");
3763 if (file.getWarningMessage() != null)
3765 System.err.println(file.getWarningMessage());